hextimator 0.14.4 → 0.15.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/dist/cli.js CHANGED
@@ -907,8 +907,8 @@ ${declsFromEntries(lightEntries, sep, "--", " ")}
907
907
  const rootDarkBlock = `${selector} {
908
908
  ${declsFromEntries(darkEntries, sep, "--", " ")}
909
909
  }`;
910
- if (theme === "light") return lightBlock;
911
910
  if (theme === "dark") return rootDarkBlock;
911
+ if (theme === "light" || darkMode === false) return lightBlock;
912
912
  if (darkMode === "media") {
913
913
  const darkInner = declsFromEntries(darkEntries, sep, "--", " ");
914
914
  return `${lightBlock}
@@ -932,7 +932,7 @@ function formatTailwindStylesheet(lightEntries, darkEntries, sep, opts = {}) {
932
932
  const theme = `@theme {
933
933
  ${declsFromEntries(themeEntries, sep, "--color-", " ")}
934
934
  }`;
935
- if (selectedTheme !== "both") return theme;
935
+ if (selectedTheme !== "both" || darkMode === false) return theme;
936
936
  if (darkMode === "media") {
937
937
  const darkInner = declsFromEntries(darkEntries, sep, "--color-", " ");
938
938
  return `${theme}
@@ -1685,16 +1685,113 @@ function generateSurface(color, themeType, options) {
1685
1685
  }
1686
1686
 
1687
1687
  // src/generate/generate.ts
1688
- function generate(color, themeType, options) {
1688
+ var GeneratePaletteError = class extends Error {
1689
+ constructor(message) {
1690
+ super(message);
1691
+ this.name = "GeneratePaletteError";
1692
+ }
1693
+ };
1694
+ var DEFAULT_ROLES = [
1695
+ { name: "surface", generate: "surface" },
1696
+ { name: "accent", generate: "accent" },
1697
+ { name: "positive", generate: "positive" },
1698
+ { name: "negative", generate: "negative" },
1699
+ { name: "caution", generate: "caution" }
1700
+ ];
1701
+ function generate(color, themeType, options, roles = DEFAULT_ROLES) {
1702
+ if (roles.filter((r) => r.generate === "surface").length > 1) {
1703
+ throw new GeneratePaletteError(
1704
+ "A theme can declare only one surface role."
1705
+ );
1706
+ }
1689
1707
  const resolvedOptions = {
1690
1708
  ...options ?? {},
1691
1709
  inputLightness: convert(color, "oklch").l
1692
1710
  };
1693
- return {
1694
- surface: generateSurface(color, themeType, resolvedOptions),
1695
- accent: generateAccent(color, themeType, resolvedOptions),
1696
- ...generateSemanticColors(color, themeType, resolvedOptions)
1697
- };
1711
+ let semantic;
1712
+ const palette = {};
1713
+ for (const { name, generate: kind } of roles) {
1714
+ if (kind === "surface") {
1715
+ palette[name] = generateSurface(color, themeType, resolvedOptions);
1716
+ } else if (kind === "accent") {
1717
+ palette[name] = generateAccent(color, themeType, resolvedOptions);
1718
+ } else {
1719
+ semantic ??= generateSemanticColors(color, themeType, resolvedOptions);
1720
+ palette[name] = { ...semantic[kind] };
1721
+ }
1722
+ }
1723
+ return palette;
1724
+ }
1725
+
1726
+ // src/generate/surfaceForegrounds.ts
1727
+ var SURFACE_VARIANTS = ["DEFAULT", "weak", "strong"];
1728
+ function isRoleForeground({ surface, roles }, role, variant) {
1729
+ return role === surface && roles.some((r) => variant === `foreground-${r}`);
1730
+ }
1731
+ function solveContrast(base, surfaces, target) {
1732
+ const withL = (l) => ({ ...base, l, alpha: 1 });
1733
+ const contrast = (color) => Math.min(...surfaces.map((surface) => calculateContrast(color, surface)));
1734
+ const endpointL = contrast(withL(0)) >= contrast(withL(1)) ? 0 : 1;
1735
+ const bufferedTarget = Math.min(
1736
+ target + CONTRAST_MARGIN,
1737
+ contrast(withL(endpointL))
1738
+ );
1739
+ let fail = 1 - endpointL;
1740
+ let pass = endpointL;
1741
+ for (let i = 0; i < 24; i++) {
1742
+ const mid = (fail + pass) / 2;
1743
+ if (contrast(withL(mid)) >= bufferedTarget) pass = mid;
1744
+ else fail = mid;
1745
+ }
1746
+ return convert(convert(withL(pass), "srgb"), "oklch");
1747
+ }
1748
+ function surfaceForegrounds(palette, theme, options, { surface: surfaceRole, roles }) {
1749
+ if (!surfaceRole || !palette[surfaceRole]) return palette;
1750
+ const target = resolveContrastRatio(
1751
+ resolveMergedThemeAdjustments(theme, options).minContrastRatio
1752
+ );
1753
+ const surfaces = SURFACE_VARIANTS.map(
1754
+ (variant) => parse(palette[surfaceRole][variant])
1755
+ );
1756
+ const surface = { ...palette[surfaceRole] };
1757
+ for (const role of roles) {
1758
+ if (!palette[role]) continue;
1759
+ surface[`foreground-${role}`] = solveContrast(
1760
+ convert(parse(palette[role].DEFAULT), "oklch"),
1761
+ surfaces,
1762
+ target
1763
+ );
1764
+ }
1765
+ return { ...palette, [surfaceRole]: surface };
1766
+ }
1767
+
1768
+ // src/theme.ts
1769
+ var baseTheme = {
1770
+ roles: {
1771
+ surface: { generate: "surface" },
1772
+ accent: { generate: "accent" },
1773
+ positive: { generate: "positive" },
1774
+ negative: { generate: "negative" },
1775
+ caution: { generate: "caution" }
1776
+ },
1777
+ tokens: [
1778
+ { name: "brand-exact", value: { generate: "brand-exact" } },
1779
+ {
1780
+ name: "brand-exact-foreground",
1781
+ value: { generate: "brand-exact-foreground" }
1782
+ }
1783
+ ]
1784
+ };
1785
+ function isGeneratedRole(role) {
1786
+ return "generate" in role;
1787
+ }
1788
+ function isGeneratedToken(value) {
1789
+ return typeof value === "object" && value !== null && !Array.isArray(value) && "generate" in value;
1790
+ }
1791
+ function generatedRoles(theme) {
1792
+ return Object.entries(theme.roles ?? {}).flatMap(
1793
+ ([name, role]) => isGeneratedRole(role) ? [{ name, generate: role.generate }] : []
1794
+ );
1698
1795
  }
1699
1796
 
1700
1797
  // src/HextimatePaletteBuilder.ts
@@ -1723,22 +1820,29 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1723
1820
  lightPalette;
1724
1821
  darkPalette;
1725
1822
  inputColor;
1823
+ theme;
1726
1824
  options;
1727
1825
  operations = [];
1728
1826
  standaloneTokens = [];
1827
+ foregroundOverrides = /* @__PURE__ */ new Map();
1828
+ pinnedCoordinates = /* @__PURE__ */ new Set();
1729
1829
  weakSideVariants = ["weak"];
1730
1830
  strongSideVariants = ["strong"];
1731
1831
  foregroundAnchoredVariants = /* @__PURE__ */ new Set();
1732
1832
  betweenVariants = [];
1733
1833
  presetFormatDefaults;
1734
- constructor(color) {
1834
+ constructor(color, theme = baseTheme) {
1735
1835
  this.inputColor = color;
1836
+ this.theme = theme;
1736
1837
  this.options = {};
1737
- this.seedOptionsForFork({});
1838
+ this.seedOptionsForFork(mergeStyleOptions(theme.style));
1738
1839
  }
1739
1840
  /**
1740
1841
  * Merges style options into the builder and regenerates the palettes,
1741
1842
  * then replays recorded operations so roles and variants reflect the new style.
1843
+ *
1844
+ * @deprecated Set `style` on a `ThemeDefinition`: `hextimate(accent, { ...theme, style })`.
1845
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1742
1846
  */
1743
1847
  style(partial) {
1744
1848
  this.operations.push({ method: "style", args: [partial] });
@@ -1748,17 +1852,22 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1748
1852
  }
1749
1853
  seedOptionsForFork(seededOptions) {
1750
1854
  this.options = { ...seededOptions };
1855
+ const roles = generatedRoles(this.theme);
1751
1856
  this.lightPalette = generate(
1752
1857
  this.inputColor,
1753
1858
  "light",
1754
- this.resolvedOptions()
1859
+ this.resolvedOptions(),
1860
+ roles
1755
1861
  );
1756
1862
  this.darkPalette = generate(
1757
1863
  this.inputColor,
1758
1864
  "dark",
1759
- this.resolvedOptions()
1865
+ this.resolvedOptions(),
1866
+ roles
1760
1867
  );
1761
1868
  this.standaloneTokens.length = 0;
1869
+ this.foregroundOverrides.clear();
1870
+ this.pinnedCoordinates.clear();
1762
1871
  this.weakSideVariants.length = 0;
1763
1872
  this.weakSideVariants.push("weak");
1764
1873
  this.strongSideVariants.length = 0;
@@ -1766,12 +1875,45 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1766
1875
  this.foregroundAnchoredVariants.clear();
1767
1876
  this.betweenVariants.length = 0;
1768
1877
  this.presetFormatDefaults = void 0;
1769
- this.applyToken("brand-exact", this.inputColor);
1878
+ this.applyTheme();
1879
+ }
1880
+ /** Custom roles, variants, tokens, and format defaults from the theme. Generated roles already exist. */
1881
+ applyTheme() {
1882
+ const theme = this.theme;
1883
+ for (const [name, role] of Object.entries(theme.roles ?? {})) {
1884
+ if (isGeneratedRole(role)) continue;
1885
+ this.applyRole(name, "color" in role ? role.color : role);
1886
+ }
1887
+ for (const variant of theme.variants ?? []) {
1888
+ this.applyVariant(variant.name, variant.placement);
1889
+ }
1890
+ for (const token of theme.tokens ?? []) {
1891
+ this.applyToken(token.name, this.resolveThemeToken(token.value));
1892
+ }
1893
+ if (theme.format || theme.variantNames) {
1894
+ this.presetFormatDefaults = {
1895
+ ...theme.format,
1896
+ variantNames: { ...theme.format?.variantNames, ...theme.variantNames }
1897
+ };
1898
+ }
1899
+ }
1900
+ resolveThemeToken(value) {
1901
+ if (!isGeneratedToken(value)) return value;
1902
+ if (value.generate === "brand-exact") return this.inputColor;
1770
1903
  const colorOKLCH = convert(this.inputColor, "oklch");
1771
1904
  const lightFg = { ...colorOKLCH, l: 0.97, c: Math.min(colorOKLCH.c, 0.01) };
1772
1905
  const darkFg = { ...colorOKLCH, l: 0.1, c: Math.min(colorOKLCH.c, 0.01) };
1773
- const brandForeground = calculateContrast(this.inputColor, lightFg) >= calculateContrast(this.inputColor, darkFg) ? lightFg : darkFg;
1774
- this.applyToken("brand-exact-foreground", brandForeground);
1906
+ return calculateContrast(this.inputColor, lightFg) >= calculateContrast(this.inputColor, darkFg) ? lightFg : darkFg;
1907
+ }
1908
+ /** Every role the theme declares gets colored text on its surface role. */
1909
+ surfaceForegroundRoles() {
1910
+ const surface = generatedRoles(this.theme).find(
1911
+ (r) => r.generate === "surface"
1912
+ )?.name;
1913
+ return {
1914
+ surface,
1915
+ roles: Object.keys(this.theme.roles ?? {}).filter((r) => r !== surface)
1916
+ };
1775
1917
  }
1776
1918
  rebuildFromOperations() {
1777
1919
  this.seedOptionsForFork(this.options);
@@ -1832,6 +1974,8 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1832
1974
  *
1833
1975
  * @param name Role name (e.g. "cta", "banner")
1834
1976
  * @param color Base color or derived token for the role
1977
+ * @deprecated Declare the role in a `ThemeDefinition`: `roles: { cta: { color: '#ff0066' } }`.
1978
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1835
1979
  */
1836
1980
  addRole(name, color) {
1837
1981
  this.operations.push({ method: "addRole", args: [name, color] });
@@ -1846,6 +1990,8 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1846
1990
  *
1847
1991
  * @param name Variant name (e.g. "placeholder", "highlight")
1848
1992
  * @param placement Placement of the variant, either `{ from: 'weak' }` or `{ between: ['DEFAULT', 'strong'] }`
1993
+ * @deprecated Declare the variant in a `ThemeDefinition`: `variants: [{ name, placement }]`.
1994
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1849
1995
  */
1850
1996
  addVariant(name, placement) {
1851
1997
  this.operations.push({ method: "addVariant", args: [name, placement] });
@@ -1857,6 +2003,9 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1857
2003
  *
1858
2004
  * Override with a dotted key: `surface.weak`, `surface.DEFAULT` (not `surface-weak`).
1859
2005
  * A kebab key that matches a generated label throws at format time.
2006
+ *
2007
+ * @deprecated Declare the token in a `ThemeDefinition`: `tokens: [{ name, value }]`.
2008
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1860
2009
  */
1861
2010
  addToken(name, value) {
1862
2011
  this.operations.push({ method: "addToken", args: [name, value] });
@@ -1881,21 +2030,16 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1881
2030
  * const theme = hextimate('#6366F1')
1882
2031
  * .preset(presets.shadcn)
1883
2032
  * .format({ colors: 'hsl-raw' });
2033
+ *
2034
+ * @deprecated Pass a `ThemeDefinition`: `hextimate(accent, themes.shadcn)`.
2035
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1884
2036
  */
1885
2037
  preset(preset) {
1886
2038
  this.operations.push({ method: "preset", args: [preset] });
1887
2039
  if (preset.style) {
1888
2040
  this.options = mergeStyleOptions(this.options, preset.style);
1889
- this.lightPalette = generate(
1890
- this.inputColor,
1891
- "light",
1892
- this.resolvedOptions()
1893
- );
1894
- this.darkPalette = generate(
1895
- this.inputColor,
1896
- "dark",
1897
- this.resolvedOptions()
1898
- );
2041
+ this.rebuildFromOperations();
2042
+ return this;
1899
2043
  }
1900
2044
  this.applyPresetRolesTokensFormat(preset);
1901
2045
  return this;
@@ -1984,7 +2128,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1984
2128
  */
1985
2129
  fork(color) {
1986
2130
  const newColor = color !== void 0 ? parse(color) : this.inputColor;
1987
- const builder = new _HextimatePaletteBuilder(newColor);
2131
+ const builder = new _HextimatePaletteBuilder(newColor, this.theme);
1988
2132
  builder.seedOptionsForFork({ ...this.options });
1989
2133
  for (const op of this.operations) {
1990
2134
  switch (op.method) {
@@ -2025,43 +2169,51 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2025
2169
  ...options?.variantNames
2026
2170
  }
2027
2171
  } : options;
2172
+ const lightPalette = this.outputPalette("light");
2173
+ const darkPalette = this.outputPalette("dark");
2028
2174
  const colorFormat = mergedOptions?.colors ?? "hex";
2029
- this.assertNoPaletteLabelCollisions(mergedOptions);
2175
+ this.assertNoPaletteLabelCollisions(mergedOptions, lightPalette);
2030
2176
  const lightTokens = this.resolveStandaloneTokens(
2031
2177
  "light",
2032
- this.lightPalette,
2178
+ lightPalette,
2033
2179
  colorFormat
2034
2180
  );
2035
2181
  const darkTokens = this.resolveStandaloneTokens(
2036
2182
  "dark",
2037
- this.darkPalette,
2183
+ darkPalette,
2038
2184
  colorFormat
2039
2185
  );
2040
- const inverted = mergedOptions?.invertedVariants ? this.buildInvertedEntries(mergedOptions, lightTokens, darkTokens) : { lightBlock: [], darkBlock: [] };
2186
+ const inverted = mergedOptions?.invertedVariants ? this.buildInvertedEntries(
2187
+ mergedOptions,
2188
+ lightTokens,
2189
+ darkTokens,
2190
+ lightPalette,
2191
+ darkPalette
2192
+ ) : { lightBlock: [], darkBlock: [] };
2041
2193
  if (mergedOptions?.as === "css" || mergedOptions?.as === "tailwind-css") {
2042
2194
  return formatStylesheet(
2043
- this.lightPalette,
2044
- this.darkPalette,
2195
+ lightPalette,
2196
+ darkPalette,
2045
2197
  mergedOptions,
2046
2198
  [...lightTokens, ...inverted.lightBlock],
2047
2199
  [...darkTokens, ...inverted.darkBlock]
2048
2200
  );
2049
2201
  }
2050
2202
  return {
2051
- light: format(this.lightPalette, mergedOptions, [
2203
+ light: format(lightPalette, mergedOptions, [
2052
2204
  ...lightTokens,
2053
2205
  ...inverted.lightBlock
2054
2206
  ]),
2055
- dark: format(this.darkPalette, mergedOptions, [
2207
+ dark: format(darkPalette, mergedOptions, [
2056
2208
  ...darkTokens,
2057
2209
  ...inverted.darkBlock
2058
2210
  ])
2059
2211
  };
2060
2212
  }
2061
- buildInvertedEntries(options, lightStandalone, darkStandalone) {
2213
+ buildInvertedEntries(options, lightStandalone, darkStandalone, lightPalette, darkPalette) {
2062
2214
  const sep = options.separator ?? "-";
2063
- const lightBase = buildTokenEntries(this.lightPalette, options);
2064
- const darkBase = buildTokenEntries(this.darkPalette, options);
2215
+ const lightBase = buildTokenEntries(lightPalette, options);
2216
+ const darkBase = buildTokenEntries(darkPalette, options);
2065
2217
  return {
2066
2218
  // Light block carries dark values under -inverted suffix.
2067
2219
  lightBlock: [
@@ -2075,6 +2227,22 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2075
2227
  ]
2076
2228
  };
2077
2229
  }
2230
+ outputPalette(theme) {
2231
+ const palette = surfaceForegrounds(
2232
+ theme === "light" ? this.lightPalette : this.darkPalette,
2233
+ theme,
2234
+ this.resolvedOptions(),
2235
+ this.surfaceForegroundRoles()
2236
+ );
2237
+ for (const [coordinate, value] of this.foregroundOverrides) {
2238
+ const [role, variant] = coordinate.split(".");
2239
+ palette[role][variant] = convert(
2240
+ this.resolveTokenValue(value, theme, palette),
2241
+ "oklch"
2242
+ );
2243
+ }
2244
+ return palette;
2245
+ }
2078
2246
  applyRole(name, color) {
2079
2247
  const parsedColor = this.isDerivedToken(color) ? this.resolveDerivedToken(color, this.lightPalette, "light") : parse(color);
2080
2248
  const opts = this.resolvedOptions();
@@ -2199,6 +2367,11 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2199
2367
  }
2200
2368
  }
2201
2369
  applyToken(name, value) {
2370
+ const [role, variant] = name.split(".");
2371
+ if (name === `${role}.${variant}` && isRoleForeground(this.surfaceForegroundRoles(), role, variant)) {
2372
+ this.foregroundOverrides.set(name, value);
2373
+ return;
2374
+ }
2202
2375
  if (name.includes(".")) {
2203
2376
  this.applyPalettePin(name, value);
2204
2377
  return;
@@ -2235,20 +2408,45 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2235
2408
  this.resolveTokenValue(value, "dark", this.darkPalette),
2236
2409
  "oklch"
2237
2410
  );
2411
+ this.pinnedCoordinates.add(coordinate);
2412
+ if (variant !== "DEFAULT" && variant !== "foreground") return;
2413
+ const repickForeground = variant === "DEFAULT" && !this.pinnedCoordinates.has(`${role}.foreground`);
2414
+ const recomputeWeak = !this.pinnedCoordinates.has(
2415
+ `${role}.foreground-weak`
2416
+ );
2417
+ const contrastTarget = resolveContrastRatio(this.options.minContrastRatio) + CONTRAST_MARGIN;
2418
+ for (const palette of [this.lightPalette, this.darkPalette]) {
2419
+ const scale = palette[role];
2420
+ if (scale.foreground === void 0) continue;
2421
+ const base = convert(parse(scale.DEFAULT), "oklch");
2422
+ let foreground = convert(parse(scale.foreground), "oklch");
2423
+ if (repickForeground && calculateContrast(foreground, base) < contrastTarget) {
2424
+ const [dark, light] = [0.1, 0.97].map((l) => ({ ...foreground, l }));
2425
+ foreground = calculateContrast(dark, base) >= calculateContrast(light, base) ? dark : light;
2426
+ scale.foreground = foreground;
2427
+ }
2428
+ if (recomputeWeak && scale["foreground-weak"] !== void 0) {
2429
+ scale["foreground-weak"] = computeSoftestForeground(
2430
+ foreground,
2431
+ base,
2432
+ contrastTarget
2433
+ );
2434
+ }
2435
+ }
2238
2436
  }
2239
2437
  /**
2240
2438
  * Standalone token names must not squash palette flat keys after
2241
2439
  * roleNames / variantNames / separator / excludes are applied.
2242
2440
  */
2243
- assertNoPaletteLabelCollisions(options) {
2441
+ assertNoPaletteLabelCollisions(options, palette) {
2244
2442
  if (this.standaloneTokens.length === 0) return;
2245
2443
  const sep = options?.separator ?? "-";
2246
2444
  const excludeRoles = new Set(options?.excludeRoles ?? []);
2247
2445
  const excludeVariants = new Set(options?.excludeVariants ?? []);
2248
2446
  const labelToCoord = /* @__PURE__ */ new Map();
2249
- for (const role of Object.keys(this.lightPalette)) {
2447
+ for (const role of Object.keys(palette)) {
2250
2448
  if (excludeRoles.has(role)) continue;
2251
- const scale = this.lightPalette[role];
2449
+ const scale = palette[role];
2252
2450
  for (const variant of Object.keys(scale)) {
2253
2451
  if (excludeVariants.has(variant)) continue;
2254
2452
  const raw = scale[variant];
@@ -2386,8 +2584,9 @@ Did you mean addToken("${suggestion}") to change the palette?`
2386
2584
  if (this.strongSideVariants.includes(variantName)) {
2387
2585
  return this.strongSideVariants;
2388
2586
  }
2587
+ const surface = this.surfaceForegroundRoles().surface;
2389
2588
  const sampleRole = Object.keys(this.lightPalette).find(
2390
- (r) => r !== "surface"
2589
+ (r) => r !== surface
2391
2590
  );
2392
2591
  if (!sampleRole) return null;
2393
2592
  const scale = this.lightPalette[sampleRole];
@@ -2552,10 +2751,10 @@ var HextimateError = class extends Error {
2552
2751
  this.name = "HextimateError";
2553
2752
  }
2554
2753
  };
2555
- function hextimate(color) {
2754
+ function hextimate(color, theme) {
2556
2755
  try {
2557
2756
  const parsedColor = parse(color);
2558
- return new HextimatePaletteBuilder(parsedColor);
2757
+ return new HextimatePaletteBuilder(parsedColor, theme);
2559
2758
  } catch (e) {
2560
2759
  if (e instanceof HextimateError) {
2561
2760
  throw e;
@@ -2568,7 +2767,8 @@ function hextimate(color) {
2568
2767
  }
2569
2768
 
2570
2769
  // src/presets/bold.ts
2571
- var bold = {
2770
+ var boldTheme = {
2771
+ ...baseTheme,
2572
2772
  style: {
2573
2773
  light: { baseLightness: 0.5 },
2574
2774
  dark: { baseLightness: 0.8 },
@@ -2576,64 +2776,77 @@ var bold = {
2576
2776
  foregroundMaxChroma: 0.02
2577
2777
  }
2578
2778
  };
2779
+ var bold = { style: boldTheme.style };
2579
2780
 
2580
2781
  // src/presets/mui.ts
2782
+ var variantNames = {
2783
+ DEFAULT: "main",
2784
+ weak: "light",
2785
+ strong: "dark",
2786
+ foreground: "contrastText"
2787
+ };
2788
+ var info = { color: "#0288d1" };
2789
+ var secondary = { from: "accent", hue: 180 };
2790
+ var format2 = {
2791
+ as: "object",
2792
+ colors: "hex",
2793
+ separator: "-",
2794
+ roleNames: {
2795
+ accent: "primary",
2796
+ negative: "error",
2797
+ positive: "success",
2798
+ caution: "warning"
2799
+ },
2800
+ excludeRoles: ["surface"]
2801
+ };
2802
+ var tokens = [
2803
+ // background
2804
+ { name: "background-default", value: { from: "surface" } },
2805
+ {
2806
+ name: "background-paper",
2807
+ value: { from: "surface", emphasis: -0.025 }
2808
+ },
2809
+ // text
2810
+ { name: "text-primary", value: { from: "surface.foreground" } },
2811
+ {
2812
+ name: "text-secondary",
2813
+ value: { from: "surface.foreground", emphasis: -0.2 }
2814
+ },
2815
+ {
2816
+ name: "text-disabled",
2817
+ value: { from: "surface.foreground", emphasis: -0.4 }
2818
+ },
2819
+ // divider
2820
+ { name: "divider", value: { from: "surface", emphasis: 0.12 } },
2821
+ // action tokens
2822
+ { name: "action-hover", value: { from: "surface", emphasis: 0.04 } },
2823
+ { name: "action-selected", value: { from: "surface", emphasis: 0.08 } },
2824
+ { name: "action-disabled", value: { from: "surface", emphasis: 0.15 } },
2825
+ {
2826
+ name: "action-disabledBackground",
2827
+ value: { from: "surface", emphasis: 0.06 }
2828
+ },
2829
+ { name: "action-focus", value: { from: "surface", emphasis: 0.06 } }
2830
+ ];
2581
2831
  var mui = {
2582
2832
  roles: [
2583
- { name: "info", color: "#0288d1" },
2584
- { name: "secondary", color: { from: "accent", hue: 180 } }
2585
- ],
2586
- tokens: [
2587
- // background
2588
- { name: "background-default", value: { from: "surface" } },
2589
- {
2590
- name: "background-paper",
2591
- value: { from: "surface", emphasis: -0.025 }
2592
- },
2593
- // text
2594
- { name: "text-primary", value: { from: "surface.foreground" } },
2595
- {
2596
- name: "text-secondary",
2597
- value: { from: "surface.foreground", emphasis: -0.2 }
2598
- },
2599
- {
2600
- name: "text-disabled",
2601
- value: { from: "surface.foreground", emphasis: -0.4 }
2602
- },
2603
- // divider
2604
- { name: "divider", value: { from: "surface", emphasis: 0.12 } },
2605
- // action tokens
2606
- { name: "action-hover", value: { from: "surface", emphasis: 0.04 } },
2607
- { name: "action-selected", value: { from: "surface", emphasis: 0.08 } },
2608
- { name: "action-disabled", value: { from: "surface", emphasis: 0.15 } },
2609
- {
2610
- name: "action-disabledBackground",
2611
- value: { from: "surface", emphasis: 0.06 }
2612
- },
2613
- { name: "action-focus", value: { from: "surface", emphasis: 0.06 } }
2833
+ { name: "info", color: info.color },
2834
+ { name: "secondary", color: secondary }
2614
2835
  ],
2615
- format: {
2616
- as: "object",
2617
- colors: "hex",
2618
- separator: "-",
2619
- roleNames: {
2620
- accent: "primary",
2621
- negative: "error",
2622
- positive: "success",
2623
- caution: "warning"
2624
- },
2625
- variantNames: {
2626
- DEFAULT: "main",
2627
- weak: "light",
2628
- strong: "dark",
2629
- foreground: "contrastText"
2630
- },
2631
- excludeRoles: ["surface"]
2632
- }
2836
+ tokens,
2837
+ format: { ...format2, variantNames }
2838
+ };
2839
+ var muiTheme = {
2840
+ ...baseTheme,
2841
+ roles: { ...baseTheme.roles, info, secondary },
2842
+ tokens: [...baseTheme.tokens, ...tokens],
2843
+ variantNames,
2844
+ format: format2
2633
2845
  };
2634
2846
 
2635
2847
  // src/presets/muted.ts
2636
- var muted = {
2848
+ var mutedTheme = {
2849
+ ...baseTheme,
2637
2850
  style: {
2638
2851
  light: { maxChroma: 0.08 },
2639
2852
  dark: { maxChroma: 0.07 },
@@ -2641,81 +2854,93 @@ var muted = {
2641
2854
  foregroundMaxChroma: 5e-3
2642
2855
  }
2643
2856
  };
2857
+ var muted = { style: mutedTheme.style };
2644
2858
 
2645
2859
  // src/presets/shadcn.ts
2860
+ var variantNames2 = {
2861
+ foreground: "foreground"
2862
+ };
2863
+ var format3 = {
2864
+ as: "css",
2865
+ colors: "oklch",
2866
+ roleNames: {
2867
+ surface: "background",
2868
+ accent: "primary",
2869
+ negative: "destructive",
2870
+ positive: "success"
2871
+ },
2872
+ excludeRoles: ["caution"],
2873
+ excludeVariants: ["strong", "weak", "foreground-weak"]
2874
+ };
2875
+ var tokens2 = [
2876
+ // shadcn uses bare --foreground (not --background-foreground)
2877
+ { name: "foreground", value: { from: "surface.foreground" } },
2878
+ // card / popover — same as background
2879
+ { name: "card", value: { from: "surface" } },
2880
+ { name: "card-foreground", value: { from: "surface.foreground" } },
2881
+ { name: "popover", value: { from: "surface" } },
2882
+ { name: "popover-foreground", value: { from: "surface.foreground" } },
2883
+ // secondary — subtle contrast from background
2884
+ { name: "secondary", value: { from: "surface" } },
2885
+ { name: "secondary-foreground", value: { from: "surface.foreground" } },
2886
+ // muted — similar to secondary, but with dimmer foreground
2887
+ { name: "muted", value: { from: "surface" } },
2888
+ {
2889
+ name: "muted-foreground",
2890
+ value: {
2891
+ from: "surface.foreground",
2892
+ emphasis: -0.25
2893
+ }
2894
+ },
2895
+ // accent (shadcn meaning: subtle hover highlight, not the brand color)
2896
+ { name: "accent", value: { from: "surface" } },
2897
+ { name: "accent-foreground", value: { from: "surface.foreground" } },
2898
+ // border / input
2899
+ {
2900
+ name: "border",
2901
+ value: { from: "surface", emphasis: 0.8 }
2902
+ },
2903
+ {
2904
+ name: "input",
2905
+ value: {
2906
+ from: "surface",
2907
+ emphasis: 0.8
2908
+ }
2909
+ },
2910
+ // ring — uses the brand/primary color
2911
+ { name: "ring", value: { from: "accent" } },
2912
+ // chart tokens colors use brand/priamry color
2913
+ { name: "chart-1", value: { from: "accent" } },
2914
+ { name: "chart-2", value: { from: "chart-1", emphasis: -0.04 } },
2915
+ { name: "chart-3", value: { from: "chart-2", emphasis: -0.04 } },
2916
+ { name: "chart-4", value: { from: "chart-3", emphasis: -0.04 } },
2917
+ { name: "chart-5", value: { from: "chart-4", emphasis: -0.04 } }
2918
+ ];
2646
2919
  var shadcn = {
2647
- tokens: [
2648
- // shadcn uses bare --foreground (not --background-foreground)
2649
- { name: "foreground", value: { from: "surface.foreground" } },
2650
- // card / popover — same as background
2651
- { name: "card", value: { from: "surface" } },
2652
- { name: "card-foreground", value: { from: "surface.foreground" } },
2653
- { name: "popover", value: { from: "surface" } },
2654
- { name: "popover-foreground", value: { from: "surface.foreground" } },
2655
- // secondary — subtle contrast from background
2656
- { name: "secondary", value: { from: "surface" } },
2657
- { name: "secondary-foreground", value: { from: "surface.foreground" } },
2658
- // muted — similar to secondary, but with dimmer foreground
2659
- { name: "muted", value: { from: "surface" } },
2660
- {
2661
- name: "muted-foreground",
2662
- value: {
2663
- from: "surface.foreground",
2664
- emphasis: -0.25
2665
- }
2666
- },
2667
- // accent (shadcn meaning: subtle hover highlight, not the brand color)
2668
- { name: "accent", value: { from: "surface" } },
2669
- { name: "accent-foreground", value: { from: "surface.foreground" } },
2670
- // border / input
2671
- {
2672
- name: "border",
2673
- value: { from: "surface", emphasis: 0.8 }
2674
- },
2675
- {
2676
- name: "input",
2677
- value: {
2678
- from: "surface",
2679
- emphasis: 0.8
2680
- }
2681
- },
2682
- // ring — uses the brand/primary color
2683
- { name: "ring", value: { from: "accent" } },
2684
- // chart tokens colors use brand/priamry color
2685
- { name: "chart-1", value: { from: "accent" } },
2686
- { name: "chart-2", value: { from: "chart-1", emphasis: -0.04 } },
2687
- { name: "chart-3", value: { from: "chart-2", emphasis: -0.04 } },
2688
- { name: "chart-4", value: { from: "chart-3", emphasis: -0.04 } },
2689
- { name: "chart-5", value: { from: "chart-4", emphasis: -0.04 } }
2690
- ],
2691
- format: {
2692
- as: "css",
2693
- colors: "oklch",
2694
- roleNames: {
2695
- surface: "background",
2696
- accent: "primary",
2697
- negative: "destructive",
2698
- positive: "success"
2699
- },
2700
- variantNames: {
2701
- foreground: "foreground"
2702
- },
2703
- excludeRoles: ["caution"],
2704
- excludeVariants: ["strong", "weak", "foreground-weak"]
2705
- }
2920
+ tokens: tokens2,
2921
+ format: { ...format3, variantNames: variantNames2 }
2922
+ };
2923
+ var shadcnTheme = {
2924
+ ...baseTheme,
2925
+ tokens: [...baseTheme.tokens, ...tokens2],
2926
+ variantNames: variantNames2,
2927
+ format: format3
2706
2928
  };
2707
2929
 
2708
2930
  // src/presets/tinted.ts
2709
- var tinted = {
2931
+ var tintedTheme = {
2932
+ ...baseTheme,
2710
2933
  style: {
2711
2934
  surfaceMaxChroma: 0.05,
2712
2935
  surfaceHueShift: 0,
2713
2936
  foregroundMaxChroma: 0.015
2714
2937
  }
2715
2938
  };
2939
+ var tinted = { style: tintedTheme.style };
2716
2940
 
2717
2941
  // src/presets/vibrant.ts
2718
- var vibrant = {
2942
+ var vibrantTheme = {
2943
+ ...baseTheme,
2719
2944
  style: {
2720
2945
  light: { maxChroma: 0.2, baseLightness: 0.6 },
2721
2946
  dark: { maxChroma: 0.18, baseLightness: 0.65 },
@@ -2724,6 +2949,7 @@ var vibrant = {
2724
2949
  surfaceMaxChroma: 0.08
2725
2950
  }
2726
2951
  };
2952
+ var vibrant = { style: vibrantTheme.style };
2727
2953
 
2728
2954
  // src/cli.ts
2729
2955
  var __dirname = dirname(fileURLToPath(import.meta.url));