hextimator 0.11.0 → 0.12.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,3 +1,15 @@
1
+ ## 0.12.0
2
+
3
+ ### Minor Changes
4
+
5
+ - [#150](https://github.com/fgrgic/hextimator/pull/150) [`b7800b9`](https://github.com/fgrgic/hextimator/commit/b7800b9fac32fe3ef245f60ed39c954c63e73785) Thanks [@fgrgic](https://github.com/fgrgic)! - Adds foreground anchored variants
6
+
7
+ You can add a new variant from foreground now. By default it will be the one that has the lowest still in rangecontrast ratio with its surface.
8
+
9
+ The generation logic can also be overwritten by providing custom `emphasis` value (e.g. `emphasis: -0.1`)
10
+
11
+ If more than one variant is 'foreground-anchored', by default it will be the same as the one it's branching from. You'll need to provide custom emphasis value to make them distinct.
12
+
1
13
  ## 0.11.0
2
14
 
3
15
  ### Minor Changes
@@ -343,8 +343,10 @@ interface HextimateResult<F = FormatResult> {
343
343
  }
344
344
  /**
345
345
  * Where to place a new variant relative to existing ones.
346
- * - `{ from: "strong" }` — one step past the named variant (redistributes to respect contrast)
346
+ * - `{ from: "strong" }` — one step past strong, redistributed
347
347
  * - `{ from: "weak", chroma: -0.02 }` — one step past weak, with a chroma offset
348
+ * - `{ from: "foreground" }` — softest foreground that still meets contrast
349
+ * - `{ from: "foreground", emphasis: -0.1 }` — foreground, placed 0.1 weaker (theme-aware: positive = more contrast)
348
350
  * - `{ between: ["DEFAULT", "weak"] }` — midpoint between two variants
349
351
  */
350
352
  type VariantPlacement = {
@@ -397,6 +399,7 @@ declare class HextimatePaletteBuilder {
397
399
  private readonly standaloneTokens;
398
400
  private readonly weakSideVariants;
399
401
  private readonly strongSideVariants;
402
+ private readonly foregroundAnchoredVariants;
400
403
  private readonly betweenVariants;
401
404
  private presetFormatDefaults?;
402
405
  constructor(color: Color);
@@ -535,6 +538,7 @@ declare class HextimatePaletteBuilder {
535
538
  private buildInvertedEntries;
536
539
  private applyRole;
537
540
  private applyVariant;
541
+ private applyAnchoredVariant;
538
542
  private applyToken;
539
543
  private resolveStandaloneTokens;
540
544
  private resolveTokenValue;
@@ -1708,6 +1708,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1708
1708
  standaloneTokens = [];
1709
1709
  weakSideVariants = ["weak"];
1710
1710
  strongSideVariants = ["strong"];
1711
+ foregroundAnchoredVariants = /* @__PURE__ */ new Set();
1711
1712
  betweenVariants = [];
1712
1713
  presetFormatDefaults;
1713
1714
  constructor(color) {
@@ -1742,6 +1743,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1742
1743
  this.weakSideVariants.push("weak");
1743
1744
  this.strongSideVariants.length = 0;
1744
1745
  this.strongSideVariants.push("strong");
1746
+ this.foregroundAnchoredVariants.clear();
1745
1747
  this.betweenVariants.length = 0;
1746
1748
  this.presetFormatDefaults = void 0;
1747
1749
  this.applyToken("brand-exact", this.inputColor);
@@ -2078,6 +2080,50 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2078
2080
  applyVariant(name, placement) {
2079
2081
  if ("from" in placement) {
2080
2082
  const edge = placement.from;
2083
+ const chromaOffset = placement.chroma ?? 0;
2084
+ const hueOffset = placement.hue ?? 0;
2085
+ const edgeIsForegroundAnchored = edge === "foreground" || this.foregroundAnchoredVariants.has(edge);
2086
+ if (placement.emphasis !== void 0) {
2087
+ this.applyAnchoredVariant(
2088
+ name,
2089
+ edge,
2090
+ placement.emphasis,
2091
+ chromaOffset,
2092
+ hueOffset,
2093
+ edgeIsForegroundAnchored
2094
+ );
2095
+ if (edgeIsForegroundAnchored) {
2096
+ this.foregroundAnchoredVariants.add(name);
2097
+ }
2098
+ return;
2099
+ }
2100
+ if (edge === "foreground") {
2101
+ const contrastTarget = resolveContrastRatio(this.options.minContrastRatio) + 0.15;
2102
+ for (const palette of [this.lightPalette, this.darkPalette]) {
2103
+ for (const role of Object.keys(palette)) {
2104
+ const scale = palette[role];
2105
+ const foreground = convert(parse(scale.foreground), "oklch");
2106
+ const boundaryL = findContrastBoundaryLightness(
2107
+ parse(scale.foreground),
2108
+ parse(scale.DEFAULT),
2109
+ contrastTarget
2110
+ );
2111
+ scale[name] = {
2112
+ ...foreground,
2113
+ l: boundaryL ?? foreground.l,
2114
+ c: Math.max(0, foreground.c + chromaOffset),
2115
+ h: wrapHue(foreground.h + hueOffset)
2116
+ };
2117
+ }
2118
+ }
2119
+ this.foregroundAnchoredVariants.add(name);
2120
+ return;
2121
+ }
2122
+ if (this.foregroundAnchoredVariants.has(edge)) {
2123
+ this.applyAnchoredVariant(name, edge, 0, chromaOffset, hueOffset, true);
2124
+ this.foregroundAnchoredVariants.add(name);
2125
+ return;
2126
+ }
2081
2127
  for (const palette of [this.lightPalette, this.darkPalette]) {
2082
2128
  for (const role of Object.keys(palette)) {
2083
2129
  const scale = palette[role];
@@ -2090,15 +2136,15 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2090
2136
  this.redistributeAllScales(sideVariants);
2091
2137
  this.recomputeBetweenVariants();
2092
2138
  }
2093
- if (placement.chroma || placement.hue) {
2139
+ if (chromaOffset || hueOffset) {
2094
2140
  for (const palette of [this.lightPalette, this.darkPalette]) {
2095
2141
  for (const role of Object.keys(palette)) {
2096
2142
  const scale = palette[role];
2097
2143
  const oklch = convert(parse(scale[name]), "oklch");
2098
2144
  scale[name] = {
2099
2145
  ...oklch,
2100
- c: Math.max(0, oklch.c + (placement.chroma ?? 0)),
2101
- h: wrapHue(oklch.h + (placement.hue ?? 0))
2146
+ c: Math.max(0, oklch.c + chromaOffset),
2147
+ h: wrapHue(oklch.h + hueOffset)
2102
2148
  };
2103
2149
  }
2104
2150
  }
@@ -2117,6 +2163,32 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2117
2163
  }
2118
2164
  }
2119
2165
  }
2166
+ applyAnchoredVariant(name, edge, emphasis, chromaOffset, hueOffset, anchorIsForeground) {
2167
+ for (const [palette, themeType] of [
2168
+ [this.lightPalette, "light"],
2169
+ [this.darkPalette, "dark"]
2170
+ ]) {
2171
+ const themeDirection = themeType === "light" ? -1 : 1;
2172
+ for (const role of Object.keys(palette)) {
2173
+ const scale = palette[role];
2174
+ const anchor = convert(parse(scale[edge]), "oklch");
2175
+ let contrastDirection = themeDirection;
2176
+ if (anchorIsForeground) {
2177
+ const baseL = convert(parse(scale.DEFAULT), "oklch").l;
2178
+ contrastDirection = anchor.l >= baseL ? 1 : -1;
2179
+ }
2180
+ scale[name] = {
2181
+ ...anchor,
2182
+ l: Math.max(
2183
+ 0,
2184
+ Math.min(1, anchor.l + emphasis * contrastDirection)
2185
+ ),
2186
+ c: Math.max(0, anchor.c + chromaOffset),
2187
+ h: wrapHue(anchor.h + hueOffset)
2188
+ };
2189
+ }
2190
+ }
2191
+ }
2120
2192
  applyToken(name, value) {
2121
2193
  this.standaloneTokens.push({ name, value });
2122
2194
  }
package/dist/cli.js CHANGED
@@ -1716,6 +1716,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1716
1716
  standaloneTokens = [];
1717
1717
  weakSideVariants = ["weak"];
1718
1718
  strongSideVariants = ["strong"];
1719
+ foregroundAnchoredVariants = /* @__PURE__ */ new Set();
1719
1720
  betweenVariants = [];
1720
1721
  presetFormatDefaults;
1721
1722
  constructor(color) {
@@ -1750,6 +1751,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1750
1751
  this.weakSideVariants.push("weak");
1751
1752
  this.strongSideVariants.length = 0;
1752
1753
  this.strongSideVariants.push("strong");
1754
+ this.foregroundAnchoredVariants.clear();
1753
1755
  this.betweenVariants.length = 0;
1754
1756
  this.presetFormatDefaults = void 0;
1755
1757
  this.applyToken("brand-exact", this.inputColor);
@@ -2086,6 +2088,50 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2086
2088
  applyVariant(name, placement) {
2087
2089
  if ("from" in placement) {
2088
2090
  const edge = placement.from;
2091
+ const chromaOffset = placement.chroma ?? 0;
2092
+ const hueOffset = placement.hue ?? 0;
2093
+ const edgeIsForegroundAnchored = edge === "foreground" || this.foregroundAnchoredVariants.has(edge);
2094
+ if (placement.emphasis !== void 0) {
2095
+ this.applyAnchoredVariant(
2096
+ name,
2097
+ edge,
2098
+ placement.emphasis,
2099
+ chromaOffset,
2100
+ hueOffset,
2101
+ edgeIsForegroundAnchored
2102
+ );
2103
+ if (edgeIsForegroundAnchored) {
2104
+ this.foregroundAnchoredVariants.add(name);
2105
+ }
2106
+ return;
2107
+ }
2108
+ if (edge === "foreground") {
2109
+ const contrastTarget = resolveContrastRatio(this.options.minContrastRatio) + 0.15;
2110
+ for (const palette of [this.lightPalette, this.darkPalette]) {
2111
+ for (const role of Object.keys(palette)) {
2112
+ const scale = palette[role];
2113
+ const foreground = convert(parse(scale.foreground), "oklch");
2114
+ const boundaryL = findContrastBoundaryLightness(
2115
+ parse(scale.foreground),
2116
+ parse(scale.DEFAULT),
2117
+ contrastTarget
2118
+ );
2119
+ scale[name] = {
2120
+ ...foreground,
2121
+ l: boundaryL ?? foreground.l,
2122
+ c: Math.max(0, foreground.c + chromaOffset),
2123
+ h: wrapHue(foreground.h + hueOffset)
2124
+ };
2125
+ }
2126
+ }
2127
+ this.foregroundAnchoredVariants.add(name);
2128
+ return;
2129
+ }
2130
+ if (this.foregroundAnchoredVariants.has(edge)) {
2131
+ this.applyAnchoredVariant(name, edge, 0, chromaOffset, hueOffset, true);
2132
+ this.foregroundAnchoredVariants.add(name);
2133
+ return;
2134
+ }
2089
2135
  for (const palette of [this.lightPalette, this.darkPalette]) {
2090
2136
  for (const role of Object.keys(palette)) {
2091
2137
  const scale = palette[role];
@@ -2098,15 +2144,15 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2098
2144
  this.redistributeAllScales(sideVariants);
2099
2145
  this.recomputeBetweenVariants();
2100
2146
  }
2101
- if (placement.chroma || placement.hue) {
2147
+ if (chromaOffset || hueOffset) {
2102
2148
  for (const palette of [this.lightPalette, this.darkPalette]) {
2103
2149
  for (const role of Object.keys(palette)) {
2104
2150
  const scale = palette[role];
2105
2151
  const oklch = convert(parse(scale[name]), "oklch");
2106
2152
  scale[name] = {
2107
2153
  ...oklch,
2108
- c: Math.max(0, oklch.c + (placement.chroma ?? 0)),
2109
- h: wrapHue(oklch.h + (placement.hue ?? 0))
2154
+ c: Math.max(0, oklch.c + chromaOffset),
2155
+ h: wrapHue(oklch.h + hueOffset)
2110
2156
  };
2111
2157
  }
2112
2158
  }
@@ -2125,6 +2171,32 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2125
2171
  }
2126
2172
  }
2127
2173
  }
2174
+ applyAnchoredVariant(name, edge, emphasis, chromaOffset, hueOffset, anchorIsForeground) {
2175
+ for (const [palette, themeType] of [
2176
+ [this.lightPalette, "light"],
2177
+ [this.darkPalette, "dark"]
2178
+ ]) {
2179
+ const themeDirection = themeType === "light" ? -1 : 1;
2180
+ for (const role of Object.keys(palette)) {
2181
+ const scale = palette[role];
2182
+ const anchor = convert(parse(scale[edge]), "oklch");
2183
+ let contrastDirection = themeDirection;
2184
+ if (anchorIsForeground) {
2185
+ const baseL = convert(parse(scale.DEFAULT), "oklch").l;
2186
+ contrastDirection = anchor.l >= baseL ? 1 : -1;
2187
+ }
2188
+ scale[name] = {
2189
+ ...anchor,
2190
+ l: Math.max(
2191
+ 0,
2192
+ Math.min(1, anchor.l + emphasis * contrastDirection)
2193
+ ),
2194
+ c: Math.max(0, anchor.c + chromaOffset),
2195
+ h: wrapHue(anchor.h + hueOffset)
2196
+ };
2197
+ }
2198
+ }
2199
+ }
2128
2200
  applyToken(name, value) {
2129
2201
  this.standaloneTokens.push({ name, value });
2130
2202
  }
@@ -1,4 +1,4 @@
1
- import { g as HextimatePreset } from './HextimatePaletteBuilder-CPteKnVL.js';
1
+ import { g as HextimatePreset } from './HextimatePaletteBuilder-REeEsEOu.js';
2
2
 
3
3
  /**
4
4
  * Darker accents on light themes, lighter accents on dark themes.
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-CPteKnVL.js';
2
- export { D as DerivedToken, F as FlatTokenMap, e as FormatResult, f as HextimateFormatOptions, g as HextimatePreset, h as HextimateResult, i as HextimateStyleOptions, N as NestedTokenMap, T as ThemeAdjustments, j as TokenValue, V as VariantPlacement } from './HextimatePaletteBuilder-CPteKnVL.js';
3
- export { i as presets } from './index-doqaWzrz.js';
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-REeEsEOu.js';
2
+ export { D as DerivedToken, F as FlatTokenMap, e as FormatResult, f as HextimateFormatOptions, g as HextimatePreset, h as HextimateResult, i as HextimateStyleOptions, N as NestedTokenMap, T as ThemeAdjustments, j as TokenValue, V as VariantPlacement } from './HextimatePaletteBuilder-REeEsEOu.js';
3
+ export { i as presets } from './index-DSfF_JsR.js';
4
4
 
5
5
  /**
6
6
  * Daltonize a color for a specific type of color vision deficiency (CVD).
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  hextimate,
7
7
  parse,
8
8
  simulateColor
9
- } from "./chunk-TF34PRUI.js";
9
+ } from "./chunk-SG5HNU7M.js";
10
10
  import {
11
11
  presets_exports
12
12
  } from "./chunk-TEZ2I4CJ.js";
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-doqaWzrz.js';
2
- export { g as HextimatePreset } from './HextimatePaletteBuilder-CPteKnVL.js';
1
+ export { b as bold, m as mui, a as muted, s as shadcn, t as tinted, v as vibrant } from './index-DSfF_JsR.js';
2
+ export { g as HextimatePreset } from './HextimatePaletteBuilder-REeEsEOu.js';
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as HextimateStyleOptions, g as HextimatePreset, H as HextimatePaletteBuilder, h as HextimateResult, F as FlatTokenMap, f as HextimateFormatOptions } from './HextimatePaletteBuilder-CPteKnVL.js';
1
+ import { i as HextimateStyleOptions, g as HextimatePreset, H as HextimatePaletteBuilder, h as HextimateResult, F as FlatTokenMap, f as HextimateFormatOptions } from './HextimatePaletteBuilder-REeEsEOu.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
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  hextimate
3
- } from "./chunk-TF34PRUI.js";
3
+ } from "./chunk-SG5HNU7M.js";
4
4
  import "./chunk-TEZ2I4CJ.js";
5
5
 
6
6
  // src/react/hextimator-provider.tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hextimator",
3
- "version": "0.11.0",
3
+ "version": "0.12.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",