hextimator 0.14.3 → 0.15.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/cli.js CHANGED
@@ -900,10 +900,15 @@ function darkSelectorFor(mode) {
900
900
  function formatCSSStylesheet(lightEntries, darkEntries, sep, opts = {}) {
901
901
  const selector = opts.selector ?? ":root";
902
902
  const darkMode = opts.darkMode ?? "media";
903
+ const theme = opts.theme === "dark" ? "dark" : darkMode === false ? "light" : opts.theme ?? "both";
903
904
  const lightBlock = `${selector} {
904
905
  ${declsFromEntries(lightEntries, sep, "--", " ")}
905
906
  }`;
906
- if (darkMode === false) return lightBlock;
907
+ const rootDarkBlock = `${selector} {
908
+ ${declsFromEntries(darkEntries, sep, "--", " ")}
909
+ }`;
910
+ if (theme === "dark") return rootDarkBlock;
911
+ if (theme === "light" || darkMode === false) return lightBlock;
907
912
  if (darkMode === "media") {
908
913
  const darkInner = declsFromEntries(darkEntries, sep, "--", " ");
909
914
  return `${lightBlock}
@@ -922,10 +927,12 @@ ${darkBlock}`;
922
927
  }
923
928
  function formatTailwindStylesheet(lightEntries, darkEntries, sep, opts = {}) {
924
929
  const darkMode = opts.darkMode ?? "media";
930
+ const selectedTheme = opts.theme === "dark" ? "dark" : darkMode === false ? "light" : opts.theme ?? "both";
931
+ const themeEntries = selectedTheme === "dark" ? darkEntries : lightEntries;
925
932
  const theme = `@theme {
926
- ${declsFromEntries(lightEntries, sep, "--color-", " ")}
933
+ ${declsFromEntries(themeEntries, sep, "--color-", " ")}
927
934
  }`;
928
- if (darkMode === false) return theme;
935
+ if (selectedTheme !== "both" || darkMode === false) return theme;
929
936
  if (darkMode === "media") {
930
937
  const darkInner = declsFromEntries(darkEntries, sep, "--color-", " ");
931
938
  return `${theme}
@@ -968,7 +975,8 @@ function formatStylesheet(lightPalette, darkPalette, options, lightStandalone, d
968
975
  const sep = options?.separator ?? "-";
969
976
  const stylesheetOpts = {
970
977
  selector: options?.selector,
971
- darkMode: options?.darkMode
978
+ darkMode: options?.darkMode,
979
+ theme: options?.theme
972
980
  };
973
981
  if (options?.as === "tailwind-css") {
974
982
  return formatTailwindStylesheet(
@@ -1677,16 +1685,113 @@ function generateSurface(color, themeType, options) {
1677
1685
  }
1678
1686
 
1679
1687
  // src/generate/generate.ts
1680
- 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
+ }
1681
1707
  const resolvedOptions = {
1682
1708
  ...options ?? {},
1683
1709
  inputLightness: convert(color, "oklch").l
1684
1710
  };
1685
- return {
1686
- surface: generateSurface(color, themeType, resolvedOptions),
1687
- accent: generateAccent(color, themeType, resolvedOptions),
1688
- ...generateSemanticColors(color, themeType, resolvedOptions)
1689
- };
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
+ );
1690
1795
  }
1691
1796
 
1692
1797
  // src/HextimatePaletteBuilder.ts
@@ -1715,22 +1820,28 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1715
1820
  lightPalette;
1716
1821
  darkPalette;
1717
1822
  inputColor;
1823
+ theme;
1718
1824
  options;
1719
1825
  operations = [];
1720
1826
  standaloneTokens = [];
1827
+ foregroundOverrides = /* @__PURE__ */ new Map();
1721
1828
  weakSideVariants = ["weak"];
1722
1829
  strongSideVariants = ["strong"];
1723
1830
  foregroundAnchoredVariants = /* @__PURE__ */ new Set();
1724
1831
  betweenVariants = [];
1725
1832
  presetFormatDefaults;
1726
- constructor(color) {
1833
+ constructor(color, theme = baseTheme) {
1727
1834
  this.inputColor = color;
1835
+ this.theme = theme;
1728
1836
  this.options = {};
1729
- this.seedOptionsForFork({});
1837
+ this.seedOptionsForFork(mergeStyleOptions(theme.style));
1730
1838
  }
1731
1839
  /**
1732
1840
  * Merges style options into the builder and regenerates the palettes,
1733
1841
  * then replays recorded operations so roles and variants reflect the new style.
1842
+ *
1843
+ * @deprecated Set `style` on a `ThemeDefinition`: `hextimate(accent, { ...theme, style })`.
1844
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1734
1845
  */
1735
1846
  style(partial) {
1736
1847
  this.operations.push({ method: "style", args: [partial] });
@@ -1740,17 +1851,21 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1740
1851
  }
1741
1852
  seedOptionsForFork(seededOptions) {
1742
1853
  this.options = { ...seededOptions };
1854
+ const roles = generatedRoles(this.theme);
1743
1855
  this.lightPalette = generate(
1744
1856
  this.inputColor,
1745
1857
  "light",
1746
- this.resolvedOptions()
1858
+ this.resolvedOptions(),
1859
+ roles
1747
1860
  );
1748
1861
  this.darkPalette = generate(
1749
1862
  this.inputColor,
1750
1863
  "dark",
1751
- this.resolvedOptions()
1864
+ this.resolvedOptions(),
1865
+ roles
1752
1866
  );
1753
1867
  this.standaloneTokens.length = 0;
1868
+ this.foregroundOverrides.clear();
1754
1869
  this.weakSideVariants.length = 0;
1755
1870
  this.weakSideVariants.push("weak");
1756
1871
  this.strongSideVariants.length = 0;
@@ -1758,12 +1873,45 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1758
1873
  this.foregroundAnchoredVariants.clear();
1759
1874
  this.betweenVariants.length = 0;
1760
1875
  this.presetFormatDefaults = void 0;
1761
- this.applyToken("brand-exact", this.inputColor);
1876
+ this.applyTheme();
1877
+ }
1878
+ /** Custom roles, variants, tokens, and format defaults from the theme. Generated roles already exist. */
1879
+ applyTheme() {
1880
+ const theme = this.theme;
1881
+ for (const [name, role] of Object.entries(theme.roles ?? {})) {
1882
+ if (isGeneratedRole(role)) continue;
1883
+ this.applyRole(name, "color" in role ? role.color : role);
1884
+ }
1885
+ for (const variant of theme.variants ?? []) {
1886
+ this.applyVariant(variant.name, variant.placement);
1887
+ }
1888
+ for (const token of theme.tokens ?? []) {
1889
+ this.applyToken(token.name, this.resolveThemeToken(token.value));
1890
+ }
1891
+ if (theme.format || theme.variantNames) {
1892
+ this.presetFormatDefaults = {
1893
+ ...theme.format,
1894
+ variantNames: { ...theme.format?.variantNames, ...theme.variantNames }
1895
+ };
1896
+ }
1897
+ }
1898
+ resolveThemeToken(value) {
1899
+ if (!isGeneratedToken(value)) return value;
1900
+ if (value.generate === "brand-exact") return this.inputColor;
1762
1901
  const colorOKLCH = convert(this.inputColor, "oklch");
1763
1902
  const lightFg = { ...colorOKLCH, l: 0.97, c: Math.min(colorOKLCH.c, 0.01) };
1764
1903
  const darkFg = { ...colorOKLCH, l: 0.1, c: Math.min(colorOKLCH.c, 0.01) };
1765
- const brandForeground = calculateContrast(this.inputColor, lightFg) >= calculateContrast(this.inputColor, darkFg) ? lightFg : darkFg;
1766
- this.applyToken("brand-exact-foreground", brandForeground);
1904
+ return calculateContrast(this.inputColor, lightFg) >= calculateContrast(this.inputColor, darkFg) ? lightFg : darkFg;
1905
+ }
1906
+ /** Every role the theme declares gets colored text on its surface role. */
1907
+ surfaceForegroundRoles() {
1908
+ const surface = generatedRoles(this.theme).find(
1909
+ (r) => r.generate === "surface"
1910
+ )?.name;
1911
+ return {
1912
+ surface,
1913
+ roles: Object.keys(this.theme.roles ?? {}).filter((r) => r !== surface)
1914
+ };
1767
1915
  }
1768
1916
  rebuildFromOperations() {
1769
1917
  this.seedOptionsForFork(this.options);
@@ -1824,6 +1972,8 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1824
1972
  *
1825
1973
  * @param name Role name (e.g. "cta", "banner")
1826
1974
  * @param color Base color or derived token for the role
1975
+ * @deprecated Declare the role in a `ThemeDefinition`: `roles: { cta: { color: '#ff0066' } }`.
1976
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1827
1977
  */
1828
1978
  addRole(name, color) {
1829
1979
  this.operations.push({ method: "addRole", args: [name, color] });
@@ -1838,6 +1988,8 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1838
1988
  *
1839
1989
  * @param name Variant name (e.g. "placeholder", "highlight")
1840
1990
  * @param placement Placement of the variant, either `{ from: 'weak' }` or `{ between: ['DEFAULT', 'strong'] }`
1991
+ * @deprecated Declare the variant in a `ThemeDefinition`: `variants: [{ name, placement }]`.
1992
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1841
1993
  */
1842
1994
  addVariant(name, placement) {
1843
1995
  this.operations.push({ method: "addVariant", args: [name, placement] });
@@ -1849,6 +2001,9 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1849
2001
  *
1850
2002
  * Override with a dotted key: `surface.weak`, `surface.DEFAULT` (not `surface-weak`).
1851
2003
  * A kebab key that matches a generated label throws at format time.
2004
+ *
2005
+ * @deprecated Declare the token in a `ThemeDefinition`: `tokens: [{ name, value }]`.
2006
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1852
2007
  */
1853
2008
  addToken(name, value) {
1854
2009
  this.operations.push({ method: "addToken", args: [name, value] });
@@ -1873,21 +2028,16 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1873
2028
  * const theme = hextimate('#6366F1')
1874
2029
  * .preset(presets.shadcn)
1875
2030
  * .format({ colors: 'hsl-raw' });
2031
+ *
2032
+ * @deprecated Pass a `ThemeDefinition`: `hextimate(accent, themes.shadcn)`.
2033
+ * See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
1876
2034
  */
1877
2035
  preset(preset) {
1878
2036
  this.operations.push({ method: "preset", args: [preset] });
1879
2037
  if (preset.style) {
1880
2038
  this.options = mergeStyleOptions(this.options, preset.style);
1881
- this.lightPalette = generate(
1882
- this.inputColor,
1883
- "light",
1884
- this.resolvedOptions()
1885
- );
1886
- this.darkPalette = generate(
1887
- this.inputColor,
1888
- "dark",
1889
- this.resolvedOptions()
1890
- );
2039
+ this.rebuildFromOperations();
2040
+ return this;
1891
2041
  }
1892
2042
  this.applyPresetRolesTokensFormat(preset);
1893
2043
  return this;
@@ -1976,7 +2126,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1976
2126
  */
1977
2127
  fork(color) {
1978
2128
  const newColor = color !== void 0 ? parse(color) : this.inputColor;
1979
- const builder = new _HextimatePaletteBuilder(newColor);
2129
+ const builder = new _HextimatePaletteBuilder(newColor, this.theme);
1980
2130
  builder.seedOptionsForFork({ ...this.options });
1981
2131
  for (const op of this.operations) {
1982
2132
  switch (op.method) {
@@ -2017,43 +2167,51 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2017
2167
  ...options?.variantNames
2018
2168
  }
2019
2169
  } : options;
2170
+ const lightPalette = this.outputPalette("light");
2171
+ const darkPalette = this.outputPalette("dark");
2020
2172
  const colorFormat = mergedOptions?.colors ?? "hex";
2021
- this.assertNoPaletteLabelCollisions(mergedOptions);
2173
+ this.assertNoPaletteLabelCollisions(mergedOptions, lightPalette);
2022
2174
  const lightTokens = this.resolveStandaloneTokens(
2023
2175
  "light",
2024
- this.lightPalette,
2176
+ lightPalette,
2025
2177
  colorFormat
2026
2178
  );
2027
2179
  const darkTokens = this.resolveStandaloneTokens(
2028
2180
  "dark",
2029
- this.darkPalette,
2181
+ darkPalette,
2030
2182
  colorFormat
2031
2183
  );
2032
- const inverted = mergedOptions?.invertedVariants ? this.buildInvertedEntries(mergedOptions, lightTokens, darkTokens) : { lightBlock: [], darkBlock: [] };
2184
+ const inverted = mergedOptions?.invertedVariants ? this.buildInvertedEntries(
2185
+ mergedOptions,
2186
+ lightTokens,
2187
+ darkTokens,
2188
+ lightPalette,
2189
+ darkPalette
2190
+ ) : { lightBlock: [], darkBlock: [] };
2033
2191
  if (mergedOptions?.as === "css" || mergedOptions?.as === "tailwind-css") {
2034
2192
  return formatStylesheet(
2035
- this.lightPalette,
2036
- this.darkPalette,
2193
+ lightPalette,
2194
+ darkPalette,
2037
2195
  mergedOptions,
2038
2196
  [...lightTokens, ...inverted.lightBlock],
2039
2197
  [...darkTokens, ...inverted.darkBlock]
2040
2198
  );
2041
2199
  }
2042
2200
  return {
2043
- light: format(this.lightPalette, mergedOptions, [
2201
+ light: format(lightPalette, mergedOptions, [
2044
2202
  ...lightTokens,
2045
2203
  ...inverted.lightBlock
2046
2204
  ]),
2047
- dark: format(this.darkPalette, mergedOptions, [
2205
+ dark: format(darkPalette, mergedOptions, [
2048
2206
  ...darkTokens,
2049
2207
  ...inverted.darkBlock
2050
2208
  ])
2051
2209
  };
2052
2210
  }
2053
- buildInvertedEntries(options, lightStandalone, darkStandalone) {
2211
+ buildInvertedEntries(options, lightStandalone, darkStandalone, lightPalette, darkPalette) {
2054
2212
  const sep = options.separator ?? "-";
2055
- const lightBase = buildTokenEntries(this.lightPalette, options);
2056
- const darkBase = buildTokenEntries(this.darkPalette, options);
2213
+ const lightBase = buildTokenEntries(lightPalette, options);
2214
+ const darkBase = buildTokenEntries(darkPalette, options);
2057
2215
  return {
2058
2216
  // Light block carries dark values under -inverted suffix.
2059
2217
  lightBlock: [
@@ -2067,6 +2225,22 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2067
2225
  ]
2068
2226
  };
2069
2227
  }
2228
+ outputPalette(theme) {
2229
+ const palette = surfaceForegrounds(
2230
+ theme === "light" ? this.lightPalette : this.darkPalette,
2231
+ theme,
2232
+ this.resolvedOptions(),
2233
+ this.surfaceForegroundRoles()
2234
+ );
2235
+ for (const [coordinate, value] of this.foregroundOverrides) {
2236
+ const [role, variant] = coordinate.split(".");
2237
+ palette[role][variant] = convert(
2238
+ this.resolveTokenValue(value, theme, palette),
2239
+ "oklch"
2240
+ );
2241
+ }
2242
+ return palette;
2243
+ }
2070
2244
  applyRole(name, color) {
2071
2245
  const parsedColor = this.isDerivedToken(color) ? this.resolveDerivedToken(color, this.lightPalette, "light") : parse(color);
2072
2246
  const opts = this.resolvedOptions();
@@ -2191,6 +2365,11 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2191
2365
  }
2192
2366
  }
2193
2367
  applyToken(name, value) {
2368
+ const [role, variant] = name.split(".");
2369
+ if (name === `${role}.${variant}` && isRoleForeground(this.surfaceForegroundRoles(), role, variant)) {
2370
+ this.foregroundOverrides.set(name, value);
2371
+ return;
2372
+ }
2194
2373
  if (name.includes(".")) {
2195
2374
  this.applyPalettePin(name, value);
2196
2375
  return;
@@ -2232,15 +2411,15 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2232
2411
  * Standalone token names must not squash palette flat keys after
2233
2412
  * roleNames / variantNames / separator / excludes are applied.
2234
2413
  */
2235
- assertNoPaletteLabelCollisions(options) {
2414
+ assertNoPaletteLabelCollisions(options, palette) {
2236
2415
  if (this.standaloneTokens.length === 0) return;
2237
2416
  const sep = options?.separator ?? "-";
2238
2417
  const excludeRoles = new Set(options?.excludeRoles ?? []);
2239
2418
  const excludeVariants = new Set(options?.excludeVariants ?? []);
2240
2419
  const labelToCoord = /* @__PURE__ */ new Map();
2241
- for (const role of Object.keys(this.lightPalette)) {
2420
+ for (const role of Object.keys(palette)) {
2242
2421
  if (excludeRoles.has(role)) continue;
2243
- const scale = this.lightPalette[role];
2422
+ const scale = palette[role];
2244
2423
  for (const variant of Object.keys(scale)) {
2245
2424
  if (excludeVariants.has(variant)) continue;
2246
2425
  const raw = scale[variant];
@@ -2378,8 +2557,9 @@ Did you mean addToken("${suggestion}") to change the palette?`
2378
2557
  if (this.strongSideVariants.includes(variantName)) {
2379
2558
  return this.strongSideVariants;
2380
2559
  }
2560
+ const surface = this.surfaceForegroundRoles().surface;
2381
2561
  const sampleRole = Object.keys(this.lightPalette).find(
2382
- (r) => r !== "surface"
2562
+ (r) => r !== surface
2383
2563
  );
2384
2564
  if (!sampleRole) return null;
2385
2565
  const scale = this.lightPalette[sampleRole];
@@ -2544,10 +2724,10 @@ var HextimateError = class extends Error {
2544
2724
  this.name = "HextimateError";
2545
2725
  }
2546
2726
  };
2547
- function hextimate(color) {
2727
+ function hextimate(color, theme) {
2548
2728
  try {
2549
2729
  const parsedColor = parse(color);
2550
- return new HextimatePaletteBuilder(parsedColor);
2730
+ return new HextimatePaletteBuilder(parsedColor, theme);
2551
2731
  } catch (e) {
2552
2732
  if (e instanceof HextimateError) {
2553
2733
  throw e;
@@ -2560,7 +2740,8 @@ function hextimate(color) {
2560
2740
  }
2561
2741
 
2562
2742
  // src/presets/bold.ts
2563
- var bold = {
2743
+ var boldTheme = {
2744
+ ...baseTheme,
2564
2745
  style: {
2565
2746
  light: { baseLightness: 0.5 },
2566
2747
  dark: { baseLightness: 0.8 },
@@ -2568,64 +2749,77 @@ var bold = {
2568
2749
  foregroundMaxChroma: 0.02
2569
2750
  }
2570
2751
  };
2752
+ var bold = { style: boldTheme.style };
2571
2753
 
2572
2754
  // src/presets/mui.ts
2755
+ var variantNames = {
2756
+ DEFAULT: "main",
2757
+ weak: "light",
2758
+ strong: "dark",
2759
+ foreground: "contrastText"
2760
+ };
2761
+ var info = { color: "#0288d1" };
2762
+ var secondary = { from: "accent", hue: 180 };
2763
+ var format2 = {
2764
+ as: "object",
2765
+ colors: "hex",
2766
+ separator: "-",
2767
+ roleNames: {
2768
+ accent: "primary",
2769
+ negative: "error",
2770
+ positive: "success",
2771
+ caution: "warning"
2772
+ },
2773
+ excludeRoles: ["surface"]
2774
+ };
2775
+ var tokens = [
2776
+ // background
2777
+ { name: "background-default", value: { from: "surface" } },
2778
+ {
2779
+ name: "background-paper",
2780
+ value: { from: "surface", emphasis: -0.025 }
2781
+ },
2782
+ // text
2783
+ { name: "text-primary", value: { from: "surface.foreground" } },
2784
+ {
2785
+ name: "text-secondary",
2786
+ value: { from: "surface.foreground", emphasis: -0.2 }
2787
+ },
2788
+ {
2789
+ name: "text-disabled",
2790
+ value: { from: "surface.foreground", emphasis: -0.4 }
2791
+ },
2792
+ // divider
2793
+ { name: "divider", value: { from: "surface", emphasis: 0.12 } },
2794
+ // action tokens
2795
+ { name: "action-hover", value: { from: "surface", emphasis: 0.04 } },
2796
+ { name: "action-selected", value: { from: "surface", emphasis: 0.08 } },
2797
+ { name: "action-disabled", value: { from: "surface", emphasis: 0.15 } },
2798
+ {
2799
+ name: "action-disabledBackground",
2800
+ value: { from: "surface", emphasis: 0.06 }
2801
+ },
2802
+ { name: "action-focus", value: { from: "surface", emphasis: 0.06 } }
2803
+ ];
2573
2804
  var mui = {
2574
2805
  roles: [
2575
- { name: "info", color: "#0288d1" },
2576
- { name: "secondary", color: { from: "accent", hue: 180 } }
2577
- ],
2578
- tokens: [
2579
- // background
2580
- { name: "background-default", value: { from: "surface" } },
2581
- {
2582
- name: "background-paper",
2583
- value: { from: "surface", emphasis: -0.025 }
2584
- },
2585
- // text
2586
- { name: "text-primary", value: { from: "surface.foreground" } },
2587
- {
2588
- name: "text-secondary",
2589
- value: { from: "surface.foreground", emphasis: -0.2 }
2590
- },
2591
- {
2592
- name: "text-disabled",
2593
- value: { from: "surface.foreground", emphasis: -0.4 }
2594
- },
2595
- // divider
2596
- { name: "divider", value: { from: "surface", emphasis: 0.12 } },
2597
- // action tokens
2598
- { name: "action-hover", value: { from: "surface", emphasis: 0.04 } },
2599
- { name: "action-selected", value: { from: "surface", emphasis: 0.08 } },
2600
- { name: "action-disabled", value: { from: "surface", emphasis: 0.15 } },
2601
- {
2602
- name: "action-disabledBackground",
2603
- value: { from: "surface", emphasis: 0.06 }
2604
- },
2605
- { name: "action-focus", value: { from: "surface", emphasis: 0.06 } }
2806
+ { name: "info", color: info.color },
2807
+ { name: "secondary", color: secondary }
2606
2808
  ],
2607
- format: {
2608
- as: "object",
2609
- colors: "hex",
2610
- separator: "-",
2611
- roleNames: {
2612
- accent: "primary",
2613
- negative: "error",
2614
- positive: "success",
2615
- caution: "warning"
2616
- },
2617
- variantNames: {
2618
- DEFAULT: "main",
2619
- weak: "light",
2620
- strong: "dark",
2621
- foreground: "contrastText"
2622
- },
2623
- excludeRoles: ["surface"]
2624
- }
2809
+ tokens,
2810
+ format: { ...format2, variantNames }
2811
+ };
2812
+ var muiTheme = {
2813
+ ...baseTheme,
2814
+ roles: { ...baseTheme.roles, info, secondary },
2815
+ tokens: [...baseTheme.tokens, ...tokens],
2816
+ variantNames,
2817
+ format: format2
2625
2818
  };
2626
2819
 
2627
2820
  // src/presets/muted.ts
2628
- var muted = {
2821
+ var mutedTheme = {
2822
+ ...baseTheme,
2629
2823
  style: {
2630
2824
  light: { maxChroma: 0.08 },
2631
2825
  dark: { maxChroma: 0.07 },
@@ -2633,81 +2827,93 @@ var muted = {
2633
2827
  foregroundMaxChroma: 5e-3
2634
2828
  }
2635
2829
  };
2830
+ var muted = { style: mutedTheme.style };
2636
2831
 
2637
2832
  // src/presets/shadcn.ts
2833
+ var variantNames2 = {
2834
+ foreground: "foreground"
2835
+ };
2836
+ var format3 = {
2837
+ as: "css",
2838
+ colors: "oklch",
2839
+ roleNames: {
2840
+ surface: "background",
2841
+ accent: "primary",
2842
+ negative: "destructive",
2843
+ positive: "success"
2844
+ },
2845
+ excludeRoles: ["caution"],
2846
+ excludeVariants: ["strong", "weak", "foreground-weak"]
2847
+ };
2848
+ var tokens2 = [
2849
+ // shadcn uses bare --foreground (not --background-foreground)
2850
+ { name: "foreground", value: { from: "surface.foreground" } },
2851
+ // card / popover — same as background
2852
+ { name: "card", value: { from: "surface" } },
2853
+ { name: "card-foreground", value: { from: "surface.foreground" } },
2854
+ { name: "popover", value: { from: "surface" } },
2855
+ { name: "popover-foreground", value: { from: "surface.foreground" } },
2856
+ // secondary — subtle contrast from background
2857
+ { name: "secondary", value: { from: "surface" } },
2858
+ { name: "secondary-foreground", value: { from: "surface.foreground" } },
2859
+ // muted — similar to secondary, but with dimmer foreground
2860
+ { name: "muted", value: { from: "surface" } },
2861
+ {
2862
+ name: "muted-foreground",
2863
+ value: {
2864
+ from: "surface.foreground",
2865
+ emphasis: -0.25
2866
+ }
2867
+ },
2868
+ // accent (shadcn meaning: subtle hover highlight, not the brand color)
2869
+ { name: "accent", value: { from: "surface" } },
2870
+ { name: "accent-foreground", value: { from: "surface.foreground" } },
2871
+ // border / input
2872
+ {
2873
+ name: "border",
2874
+ value: { from: "surface", emphasis: 0.8 }
2875
+ },
2876
+ {
2877
+ name: "input",
2878
+ value: {
2879
+ from: "surface",
2880
+ emphasis: 0.8
2881
+ }
2882
+ },
2883
+ // ring — uses the brand/primary color
2884
+ { name: "ring", value: { from: "accent" } },
2885
+ // chart tokens colors use brand/priamry color
2886
+ { name: "chart-1", value: { from: "accent" } },
2887
+ { name: "chart-2", value: { from: "chart-1", emphasis: -0.04 } },
2888
+ { name: "chart-3", value: { from: "chart-2", emphasis: -0.04 } },
2889
+ { name: "chart-4", value: { from: "chart-3", emphasis: -0.04 } },
2890
+ { name: "chart-5", value: { from: "chart-4", emphasis: -0.04 } }
2891
+ ];
2638
2892
  var shadcn = {
2639
- tokens: [
2640
- // shadcn uses bare --foreground (not --background-foreground)
2641
- { name: "foreground", value: { from: "surface.foreground" } },
2642
- // card / popover — same as background
2643
- { name: "card", value: { from: "surface" } },
2644
- { name: "card-foreground", value: { from: "surface.foreground" } },
2645
- { name: "popover", value: { from: "surface" } },
2646
- { name: "popover-foreground", value: { from: "surface.foreground" } },
2647
- // secondary — subtle contrast from background
2648
- { name: "secondary", value: { from: "surface" } },
2649
- { name: "secondary-foreground", value: { from: "surface.foreground" } },
2650
- // muted — similar to secondary, but with dimmer foreground
2651
- { name: "muted", value: { from: "surface" } },
2652
- {
2653
- name: "muted-foreground",
2654
- value: {
2655
- from: "surface.foreground",
2656
- emphasis: -0.25
2657
- }
2658
- },
2659
- // accent (shadcn meaning: subtle hover highlight, not the brand color)
2660
- { name: "accent", value: { from: "surface" } },
2661
- { name: "accent-foreground", value: { from: "surface.foreground" } },
2662
- // border / input
2663
- {
2664
- name: "border",
2665
- value: { from: "surface", emphasis: 0.8 }
2666
- },
2667
- {
2668
- name: "input",
2669
- value: {
2670
- from: "surface",
2671
- emphasis: 0.8
2672
- }
2673
- },
2674
- // ring — uses the brand/primary color
2675
- { name: "ring", value: { from: "accent" } },
2676
- // chart tokens colors use brand/priamry color
2677
- { name: "chart-1", value: { from: "accent" } },
2678
- { name: "chart-2", value: { from: "chart-1", emphasis: -0.04 } },
2679
- { name: "chart-3", value: { from: "chart-2", emphasis: -0.04 } },
2680
- { name: "chart-4", value: { from: "chart-3", emphasis: -0.04 } },
2681
- { name: "chart-5", value: { from: "chart-4", emphasis: -0.04 } }
2682
- ],
2683
- format: {
2684
- as: "css",
2685
- colors: "oklch",
2686
- roleNames: {
2687
- surface: "background",
2688
- accent: "primary",
2689
- negative: "destructive",
2690
- positive: "success"
2691
- },
2692
- variantNames: {
2693
- foreground: "foreground"
2694
- },
2695
- excludeRoles: ["caution"],
2696
- excludeVariants: ["strong", "weak", "foreground-weak"]
2697
- }
2893
+ tokens: tokens2,
2894
+ format: { ...format3, variantNames: variantNames2 }
2895
+ };
2896
+ var shadcnTheme = {
2897
+ ...baseTheme,
2898
+ tokens: [...baseTheme.tokens, ...tokens2],
2899
+ variantNames: variantNames2,
2900
+ format: format3
2698
2901
  };
2699
2902
 
2700
2903
  // src/presets/tinted.ts
2701
- var tinted = {
2904
+ var tintedTheme = {
2905
+ ...baseTheme,
2702
2906
  style: {
2703
2907
  surfaceMaxChroma: 0.05,
2704
2908
  surfaceHueShift: 0,
2705
2909
  foregroundMaxChroma: 0.015
2706
2910
  }
2707
2911
  };
2912
+ var tinted = { style: tintedTheme.style };
2708
2913
 
2709
2914
  // src/presets/vibrant.ts
2710
- var vibrant = {
2915
+ var vibrantTheme = {
2916
+ ...baseTheme,
2711
2917
  style: {
2712
2918
  light: { maxChroma: 0.2, baseLightness: 0.6 },
2713
2919
  dark: { maxChroma: 0.18, baseLightness: 0.65 },
@@ -2716,6 +2922,7 @@ var vibrant = {
2716
2922
  surfaceMaxChroma: 0.08
2717
2923
  }
2718
2924
  };
2925
+ var vibrant = { style: vibrantTheme.style };
2719
2926
 
2720
2927
  // src/cli.ts
2721
2928
  var __dirname = dirname(fileURLToPath(import.meta.url));
@@ -2746,7 +2953,7 @@ Presets:
2746
2953
  Format options:
2747
2954
  -f, --format <type> css | object | tailwind | tailwind-css | scss | json (default: css)
2748
2955
  -c, --colors <type> hex | rgb | hsl | oklch | p3 and -raw variants (default: hex)
2749
- -t, --theme <type> light | dark | both (ignored for css/tailwind-css) (default: both)
2956
+ -t, --theme <type> light | dark | both (default: both)
2750
2957
  --dark-mode <strategy> media | class | data-attribute | off (css/tailwind-css only, default: media)
2751
2958
  --selector <css> Root selector for css output (default: :root)
2752
2959
  --separator <char> Token separator (default: -)
@@ -2994,6 +3201,7 @@ function runCli() {
2994
3201
  }
2995
3202
  const hasPreset = values.preset && values.preset.length > 0;
2996
3203
  const formatOptions = {};
3204
+ formatOptions.theme = values.theme;
2997
3205
  if (values.format) {
2998
3206
  formatOptions.as = values.format;
2999
3207
  } else if (!hasPreset) {