hextimator 0.14.4 → 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/CHANGELOG.md +14 -0
- package/README.md +84 -39
- package/dist/{HextimatePaletteBuilder-Cb3ElknQ.d.ts → HextimatePaletteBuilder-2hj-zvnW.d.ts} +95 -3
- package/dist/{chunk-HYJCQDLO.js → chunk-3JIC7LRE.js} +239 -44
- package/dist/chunk-Q6KJLMLM.js +251 -0
- package/dist/cli.js +354 -155
- package/dist/index-B1LYbLO5.d.ts +365 -0
- package/dist/index.d.ts +28 -15
- package/dist/index.js +10 -4
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +1 -1
- package/dist/react.d.ts +26 -11
- package/dist/react.js +24 -9
- package/fallback.css +12 -0
- package/llms.txt +43 -19
- package/package.json +2 -2
- package/tailwind-inverted.css +17 -0
- package/tailwind.css +5 -0
- package/dist/chunk-23UBW2KU.js +0 -184
- package/dist/index-J9z52Ypz.d.ts +0 -93
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export,
|
|
3
|
+
baseTheme,
|
|
4
|
+
boldTheme,
|
|
5
|
+
generatedRoles,
|
|
6
|
+
isGeneratedRole,
|
|
7
|
+
isGeneratedToken,
|
|
8
|
+
muiTheme,
|
|
9
|
+
mutedTheme,
|
|
10
|
+
shadcnTheme,
|
|
11
|
+
tintedTheme,
|
|
12
|
+
vibrantTheme
|
|
13
|
+
} from "./chunk-Q6KJLMLM.js";
|
|
14
|
+
|
|
1
15
|
// src/convert/matrices.ts
|
|
2
16
|
var M1 = [
|
|
3
17
|
[0.4122214708, 0.5363325363, 0.0514459929],
|
|
@@ -899,8 +913,8 @@ ${declsFromEntries(lightEntries, sep, "--", " ")}
|
|
|
899
913
|
const rootDarkBlock = `${selector} {
|
|
900
914
|
${declsFromEntries(darkEntries, sep, "--", " ")}
|
|
901
915
|
}`;
|
|
902
|
-
if (theme === "light") return lightBlock;
|
|
903
916
|
if (theme === "dark") return rootDarkBlock;
|
|
917
|
+
if (theme === "light" || darkMode === false) return lightBlock;
|
|
904
918
|
if (darkMode === "media") {
|
|
905
919
|
const darkInner = declsFromEntries(darkEntries, sep, "--", " ");
|
|
906
920
|
return `${lightBlock}
|
|
@@ -924,7 +938,7 @@ function formatTailwindStylesheet(lightEntries, darkEntries, sep, opts = {}) {
|
|
|
924
938
|
const theme = `@theme {
|
|
925
939
|
${declsFromEntries(themeEntries, sep, "--color-", " ")}
|
|
926
940
|
}`;
|
|
927
|
-
if (selectedTheme !== "both") return theme;
|
|
941
|
+
if (selectedTheme !== "both" || darkMode === false) return theme;
|
|
928
942
|
if (darkMode === "media") {
|
|
929
943
|
const darkInner = declsFromEntries(darkEntries, sep, "--color-", " ");
|
|
930
944
|
return `${theme}
|
|
@@ -1677,16 +1691,84 @@ function generateSurface(color, themeType, options) {
|
|
|
1677
1691
|
}
|
|
1678
1692
|
|
|
1679
1693
|
// src/generate/generate.ts
|
|
1680
|
-
|
|
1694
|
+
var GeneratePaletteError = class extends Error {
|
|
1695
|
+
constructor(message) {
|
|
1696
|
+
super(message);
|
|
1697
|
+
this.name = "GeneratePaletteError";
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
var DEFAULT_ROLES = [
|
|
1701
|
+
{ name: "surface", generate: "surface" },
|
|
1702
|
+
{ name: "accent", generate: "accent" },
|
|
1703
|
+
{ name: "positive", generate: "positive" },
|
|
1704
|
+
{ name: "negative", generate: "negative" },
|
|
1705
|
+
{ name: "caution", generate: "caution" }
|
|
1706
|
+
];
|
|
1707
|
+
function generate(color, themeType, options, roles = DEFAULT_ROLES) {
|
|
1708
|
+
if (roles.filter((r) => r.generate === "surface").length > 1) {
|
|
1709
|
+
throw new GeneratePaletteError(
|
|
1710
|
+
"A theme can declare only one surface role."
|
|
1711
|
+
);
|
|
1712
|
+
}
|
|
1681
1713
|
const resolvedOptions = {
|
|
1682
1714
|
...options ?? {},
|
|
1683
1715
|
inputLightness: convert(color, "oklch").l
|
|
1684
1716
|
};
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1717
|
+
let semantic;
|
|
1718
|
+
const palette = {};
|
|
1719
|
+
for (const { name, generate: kind } of roles) {
|
|
1720
|
+
if (kind === "surface") {
|
|
1721
|
+
palette[name] = generateSurface(color, themeType, resolvedOptions);
|
|
1722
|
+
} else if (kind === "accent") {
|
|
1723
|
+
palette[name] = generateAccent(color, themeType, resolvedOptions);
|
|
1724
|
+
} else {
|
|
1725
|
+
semantic ??= generateSemanticColors(color, themeType, resolvedOptions);
|
|
1726
|
+
palette[name] = { ...semantic[kind] };
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
return palette;
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
// src/generate/surfaceForegrounds.ts
|
|
1733
|
+
var SURFACE_VARIANTS = ["DEFAULT", "weak", "strong"];
|
|
1734
|
+
function isRoleForeground({ surface, roles }, role, variant) {
|
|
1735
|
+
return role === surface && roles.some((r) => variant === `foreground-${r}`);
|
|
1736
|
+
}
|
|
1737
|
+
function solveContrast(base, surfaces, target) {
|
|
1738
|
+
const withL = (l) => ({ ...base, l, alpha: 1 });
|
|
1739
|
+
const contrast = (color) => Math.min(...surfaces.map((surface) => calculateContrast(color, surface)));
|
|
1740
|
+
const endpointL = contrast(withL(0)) >= contrast(withL(1)) ? 0 : 1;
|
|
1741
|
+
const bufferedTarget = Math.min(
|
|
1742
|
+
target + CONTRAST_MARGIN,
|
|
1743
|
+
contrast(withL(endpointL))
|
|
1744
|
+
);
|
|
1745
|
+
let fail = 1 - endpointL;
|
|
1746
|
+
let pass = endpointL;
|
|
1747
|
+
for (let i = 0; i < 24; i++) {
|
|
1748
|
+
const mid = (fail + pass) / 2;
|
|
1749
|
+
if (contrast(withL(mid)) >= bufferedTarget) pass = mid;
|
|
1750
|
+
else fail = mid;
|
|
1751
|
+
}
|
|
1752
|
+
return convert(convert(withL(pass), "srgb"), "oklch");
|
|
1753
|
+
}
|
|
1754
|
+
function surfaceForegrounds(palette, theme, options, { surface: surfaceRole, roles }) {
|
|
1755
|
+
if (!surfaceRole || !palette[surfaceRole]) return palette;
|
|
1756
|
+
const target = resolveContrastRatio(
|
|
1757
|
+
resolveMergedThemeAdjustments(theme, options).minContrastRatio
|
|
1758
|
+
);
|
|
1759
|
+
const surfaces = SURFACE_VARIANTS.map(
|
|
1760
|
+
(variant) => parse(palette[surfaceRole][variant])
|
|
1761
|
+
);
|
|
1762
|
+
const surface = { ...palette[surfaceRole] };
|
|
1763
|
+
for (const role of roles) {
|
|
1764
|
+
if (!palette[role]) continue;
|
|
1765
|
+
surface[`foreground-${role}`] = solveContrast(
|
|
1766
|
+
convert(parse(palette[role].DEFAULT), "oklch"),
|
|
1767
|
+
surfaces,
|
|
1768
|
+
target
|
|
1769
|
+
);
|
|
1770
|
+
}
|
|
1771
|
+
return { ...palette, [surfaceRole]: surface };
|
|
1690
1772
|
}
|
|
1691
1773
|
|
|
1692
1774
|
// src/HextimatePaletteBuilder.ts
|
|
@@ -1715,22 +1797,28 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1715
1797
|
lightPalette;
|
|
1716
1798
|
darkPalette;
|
|
1717
1799
|
inputColor;
|
|
1800
|
+
theme;
|
|
1718
1801
|
options;
|
|
1719
1802
|
operations = [];
|
|
1720
1803
|
standaloneTokens = [];
|
|
1804
|
+
foregroundOverrides = /* @__PURE__ */ new Map();
|
|
1721
1805
|
weakSideVariants = ["weak"];
|
|
1722
1806
|
strongSideVariants = ["strong"];
|
|
1723
1807
|
foregroundAnchoredVariants = /* @__PURE__ */ new Set();
|
|
1724
1808
|
betweenVariants = [];
|
|
1725
1809
|
presetFormatDefaults;
|
|
1726
|
-
constructor(color) {
|
|
1810
|
+
constructor(color, theme = baseTheme) {
|
|
1727
1811
|
this.inputColor = color;
|
|
1812
|
+
this.theme = theme;
|
|
1728
1813
|
this.options = {};
|
|
1729
|
-
this.seedOptionsForFork(
|
|
1814
|
+
this.seedOptionsForFork(mergeStyleOptions(theme.style));
|
|
1730
1815
|
}
|
|
1731
1816
|
/**
|
|
1732
1817
|
* Merges style options into the builder and regenerates the palettes,
|
|
1733
1818
|
* then replays recorded operations so roles and variants reflect the new style.
|
|
1819
|
+
*
|
|
1820
|
+
* @deprecated Set `style` on a `ThemeDefinition`: `hextimate(accent, { ...theme, style })`.
|
|
1821
|
+
* See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
|
|
1734
1822
|
*/
|
|
1735
1823
|
style(partial) {
|
|
1736
1824
|
this.operations.push({ method: "style", args: [partial] });
|
|
@@ -1740,17 +1828,21 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1740
1828
|
}
|
|
1741
1829
|
seedOptionsForFork(seededOptions) {
|
|
1742
1830
|
this.options = { ...seededOptions };
|
|
1831
|
+
const roles = generatedRoles(this.theme);
|
|
1743
1832
|
this.lightPalette = generate(
|
|
1744
1833
|
this.inputColor,
|
|
1745
1834
|
"light",
|
|
1746
|
-
this.resolvedOptions()
|
|
1835
|
+
this.resolvedOptions(),
|
|
1836
|
+
roles
|
|
1747
1837
|
);
|
|
1748
1838
|
this.darkPalette = generate(
|
|
1749
1839
|
this.inputColor,
|
|
1750
1840
|
"dark",
|
|
1751
|
-
this.resolvedOptions()
|
|
1841
|
+
this.resolvedOptions(),
|
|
1842
|
+
roles
|
|
1752
1843
|
);
|
|
1753
1844
|
this.standaloneTokens.length = 0;
|
|
1845
|
+
this.foregroundOverrides.clear();
|
|
1754
1846
|
this.weakSideVariants.length = 0;
|
|
1755
1847
|
this.weakSideVariants.push("weak");
|
|
1756
1848
|
this.strongSideVariants.length = 0;
|
|
@@ -1758,12 +1850,45 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1758
1850
|
this.foregroundAnchoredVariants.clear();
|
|
1759
1851
|
this.betweenVariants.length = 0;
|
|
1760
1852
|
this.presetFormatDefaults = void 0;
|
|
1761
|
-
this.
|
|
1853
|
+
this.applyTheme();
|
|
1854
|
+
}
|
|
1855
|
+
/** Custom roles, variants, tokens, and format defaults from the theme. Generated roles already exist. */
|
|
1856
|
+
applyTheme() {
|
|
1857
|
+
const theme = this.theme;
|
|
1858
|
+
for (const [name, role] of Object.entries(theme.roles ?? {})) {
|
|
1859
|
+
if (isGeneratedRole(role)) continue;
|
|
1860
|
+
this.applyRole(name, "color" in role ? role.color : role);
|
|
1861
|
+
}
|
|
1862
|
+
for (const variant of theme.variants ?? []) {
|
|
1863
|
+
this.applyVariant(variant.name, variant.placement);
|
|
1864
|
+
}
|
|
1865
|
+
for (const token of theme.tokens ?? []) {
|
|
1866
|
+
this.applyToken(token.name, this.resolveThemeToken(token.value));
|
|
1867
|
+
}
|
|
1868
|
+
if (theme.format || theme.variantNames) {
|
|
1869
|
+
this.presetFormatDefaults = {
|
|
1870
|
+
...theme.format,
|
|
1871
|
+
variantNames: { ...theme.format?.variantNames, ...theme.variantNames }
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
resolveThemeToken(value) {
|
|
1876
|
+
if (!isGeneratedToken(value)) return value;
|
|
1877
|
+
if (value.generate === "brand-exact") return this.inputColor;
|
|
1762
1878
|
const colorOKLCH = convert(this.inputColor, "oklch");
|
|
1763
1879
|
const lightFg = { ...colorOKLCH, l: 0.97, c: Math.min(colorOKLCH.c, 0.01) };
|
|
1764
1880
|
const darkFg = { ...colorOKLCH, l: 0.1, c: Math.min(colorOKLCH.c, 0.01) };
|
|
1765
|
-
|
|
1766
|
-
|
|
1881
|
+
return calculateContrast(this.inputColor, lightFg) >= calculateContrast(this.inputColor, darkFg) ? lightFg : darkFg;
|
|
1882
|
+
}
|
|
1883
|
+
/** Every role the theme declares gets colored text on its surface role. */
|
|
1884
|
+
surfaceForegroundRoles() {
|
|
1885
|
+
const surface = generatedRoles(this.theme).find(
|
|
1886
|
+
(r) => r.generate === "surface"
|
|
1887
|
+
)?.name;
|
|
1888
|
+
return {
|
|
1889
|
+
surface,
|
|
1890
|
+
roles: Object.keys(this.theme.roles ?? {}).filter((r) => r !== surface)
|
|
1891
|
+
};
|
|
1767
1892
|
}
|
|
1768
1893
|
rebuildFromOperations() {
|
|
1769
1894
|
this.seedOptionsForFork(this.options);
|
|
@@ -1824,6 +1949,8 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1824
1949
|
*
|
|
1825
1950
|
* @param name Role name (e.g. "cta", "banner")
|
|
1826
1951
|
* @param color Base color or derived token for the role
|
|
1952
|
+
* @deprecated Declare the role in a `ThemeDefinition`: `roles: { cta: { color: '#ff0066' } }`.
|
|
1953
|
+
* See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
|
|
1827
1954
|
*/
|
|
1828
1955
|
addRole(name, color) {
|
|
1829
1956
|
this.operations.push({ method: "addRole", args: [name, color] });
|
|
@@ -1838,6 +1965,8 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1838
1965
|
*
|
|
1839
1966
|
* @param name Variant name (e.g. "placeholder", "highlight")
|
|
1840
1967
|
* @param placement Placement of the variant, either `{ from: 'weak' }` or `{ between: ['DEFAULT', 'strong'] }`
|
|
1968
|
+
* @deprecated Declare the variant in a `ThemeDefinition`: `variants: [{ name, placement }]`.
|
|
1969
|
+
* See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
|
|
1841
1970
|
*/
|
|
1842
1971
|
addVariant(name, placement) {
|
|
1843
1972
|
this.operations.push({ method: "addVariant", args: [name, placement] });
|
|
@@ -1849,6 +1978,9 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1849
1978
|
*
|
|
1850
1979
|
* Override with a dotted key: `surface.weak`, `surface.DEFAULT` (not `surface-weak`).
|
|
1851
1980
|
* A kebab key that matches a generated label throws at format time.
|
|
1981
|
+
*
|
|
1982
|
+
* @deprecated Declare the token in a `ThemeDefinition`: `tokens: [{ name, value }]`.
|
|
1983
|
+
* See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
|
|
1852
1984
|
*/
|
|
1853
1985
|
addToken(name, value) {
|
|
1854
1986
|
this.operations.push({ method: "addToken", args: [name, value] });
|
|
@@ -1873,21 +2005,16 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1873
2005
|
* const theme = hextimate('#6366F1')
|
|
1874
2006
|
* .preset(presets.shadcn)
|
|
1875
2007
|
* .format({ colors: 'hsl-raw' });
|
|
2008
|
+
*
|
|
2009
|
+
* @deprecated Pass a `ThemeDefinition`: `hextimate(accent, themes.shadcn)`.
|
|
2010
|
+
* See the {@link https://github.com/fgrgic/hextimator/blob/main/packages/hextimator/docs/migration.md#014x--0150-themes | Migration guide}.
|
|
1876
2011
|
*/
|
|
1877
2012
|
preset(preset) {
|
|
1878
2013
|
this.operations.push({ method: "preset", args: [preset] });
|
|
1879
2014
|
if (preset.style) {
|
|
1880
2015
|
this.options = mergeStyleOptions(this.options, preset.style);
|
|
1881
|
-
this.
|
|
1882
|
-
|
|
1883
|
-
"light",
|
|
1884
|
-
this.resolvedOptions()
|
|
1885
|
-
);
|
|
1886
|
-
this.darkPalette = generate(
|
|
1887
|
-
this.inputColor,
|
|
1888
|
-
"dark",
|
|
1889
|
-
this.resolvedOptions()
|
|
1890
|
-
);
|
|
2016
|
+
this.rebuildFromOperations();
|
|
2017
|
+
return this;
|
|
1891
2018
|
}
|
|
1892
2019
|
this.applyPresetRolesTokensFormat(preset);
|
|
1893
2020
|
return this;
|
|
@@ -1976,7 +2103,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1976
2103
|
*/
|
|
1977
2104
|
fork(color) {
|
|
1978
2105
|
const newColor = color !== void 0 ? parse(color) : this.inputColor;
|
|
1979
|
-
const builder = new _HextimatePaletteBuilder(newColor);
|
|
2106
|
+
const builder = new _HextimatePaletteBuilder(newColor, this.theme);
|
|
1980
2107
|
builder.seedOptionsForFork({ ...this.options });
|
|
1981
2108
|
for (const op of this.operations) {
|
|
1982
2109
|
switch (op.method) {
|
|
@@ -2017,43 +2144,51 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
2017
2144
|
...options?.variantNames
|
|
2018
2145
|
}
|
|
2019
2146
|
} : options;
|
|
2147
|
+
const lightPalette = this.outputPalette("light");
|
|
2148
|
+
const darkPalette = this.outputPalette("dark");
|
|
2020
2149
|
const colorFormat = mergedOptions?.colors ?? "hex";
|
|
2021
|
-
this.assertNoPaletteLabelCollisions(mergedOptions);
|
|
2150
|
+
this.assertNoPaletteLabelCollisions(mergedOptions, lightPalette);
|
|
2022
2151
|
const lightTokens = this.resolveStandaloneTokens(
|
|
2023
2152
|
"light",
|
|
2024
|
-
|
|
2153
|
+
lightPalette,
|
|
2025
2154
|
colorFormat
|
|
2026
2155
|
);
|
|
2027
2156
|
const darkTokens = this.resolveStandaloneTokens(
|
|
2028
2157
|
"dark",
|
|
2029
|
-
|
|
2158
|
+
darkPalette,
|
|
2030
2159
|
colorFormat
|
|
2031
2160
|
);
|
|
2032
|
-
const inverted = mergedOptions?.invertedVariants ? this.buildInvertedEntries(
|
|
2161
|
+
const inverted = mergedOptions?.invertedVariants ? this.buildInvertedEntries(
|
|
2162
|
+
mergedOptions,
|
|
2163
|
+
lightTokens,
|
|
2164
|
+
darkTokens,
|
|
2165
|
+
lightPalette,
|
|
2166
|
+
darkPalette
|
|
2167
|
+
) : { lightBlock: [], darkBlock: [] };
|
|
2033
2168
|
if (mergedOptions?.as === "css" || mergedOptions?.as === "tailwind-css") {
|
|
2034
2169
|
return formatStylesheet(
|
|
2035
|
-
|
|
2036
|
-
|
|
2170
|
+
lightPalette,
|
|
2171
|
+
darkPalette,
|
|
2037
2172
|
mergedOptions,
|
|
2038
2173
|
[...lightTokens, ...inverted.lightBlock],
|
|
2039
2174
|
[...darkTokens, ...inverted.darkBlock]
|
|
2040
2175
|
);
|
|
2041
2176
|
}
|
|
2042
2177
|
return {
|
|
2043
|
-
light: format(
|
|
2178
|
+
light: format(lightPalette, mergedOptions, [
|
|
2044
2179
|
...lightTokens,
|
|
2045
2180
|
...inverted.lightBlock
|
|
2046
2181
|
]),
|
|
2047
|
-
dark: format(
|
|
2182
|
+
dark: format(darkPalette, mergedOptions, [
|
|
2048
2183
|
...darkTokens,
|
|
2049
2184
|
...inverted.darkBlock
|
|
2050
2185
|
])
|
|
2051
2186
|
};
|
|
2052
2187
|
}
|
|
2053
|
-
buildInvertedEntries(options, lightStandalone, darkStandalone) {
|
|
2188
|
+
buildInvertedEntries(options, lightStandalone, darkStandalone, lightPalette, darkPalette) {
|
|
2054
2189
|
const sep = options.separator ?? "-";
|
|
2055
|
-
const lightBase = buildTokenEntries(
|
|
2056
|
-
const darkBase = buildTokenEntries(
|
|
2190
|
+
const lightBase = buildTokenEntries(lightPalette, options);
|
|
2191
|
+
const darkBase = buildTokenEntries(darkPalette, options);
|
|
2057
2192
|
return {
|
|
2058
2193
|
// Light block carries dark values under -inverted suffix.
|
|
2059
2194
|
lightBlock: [
|
|
@@ -2067,6 +2202,22 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
2067
2202
|
]
|
|
2068
2203
|
};
|
|
2069
2204
|
}
|
|
2205
|
+
outputPalette(theme) {
|
|
2206
|
+
const palette = surfaceForegrounds(
|
|
2207
|
+
theme === "light" ? this.lightPalette : this.darkPalette,
|
|
2208
|
+
theme,
|
|
2209
|
+
this.resolvedOptions(),
|
|
2210
|
+
this.surfaceForegroundRoles()
|
|
2211
|
+
);
|
|
2212
|
+
for (const [coordinate, value] of this.foregroundOverrides) {
|
|
2213
|
+
const [role, variant] = coordinate.split(".");
|
|
2214
|
+
palette[role][variant] = convert(
|
|
2215
|
+
this.resolveTokenValue(value, theme, palette),
|
|
2216
|
+
"oklch"
|
|
2217
|
+
);
|
|
2218
|
+
}
|
|
2219
|
+
return palette;
|
|
2220
|
+
}
|
|
2070
2221
|
applyRole(name, color) {
|
|
2071
2222
|
const parsedColor = this.isDerivedToken(color) ? this.resolveDerivedToken(color, this.lightPalette, "light") : parse(color);
|
|
2072
2223
|
const opts = this.resolvedOptions();
|
|
@@ -2191,6 +2342,11 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
2191
2342
|
}
|
|
2192
2343
|
}
|
|
2193
2344
|
applyToken(name, value) {
|
|
2345
|
+
const [role, variant] = name.split(".");
|
|
2346
|
+
if (name === `${role}.${variant}` && isRoleForeground(this.surfaceForegroundRoles(), role, variant)) {
|
|
2347
|
+
this.foregroundOverrides.set(name, value);
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2194
2350
|
if (name.includes(".")) {
|
|
2195
2351
|
this.applyPalettePin(name, value);
|
|
2196
2352
|
return;
|
|
@@ -2232,15 +2388,15 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
2232
2388
|
* Standalone token names must not squash palette flat keys after
|
|
2233
2389
|
* roleNames / variantNames / separator / excludes are applied.
|
|
2234
2390
|
*/
|
|
2235
|
-
assertNoPaletteLabelCollisions(options) {
|
|
2391
|
+
assertNoPaletteLabelCollisions(options, palette) {
|
|
2236
2392
|
if (this.standaloneTokens.length === 0) return;
|
|
2237
2393
|
const sep = options?.separator ?? "-";
|
|
2238
2394
|
const excludeRoles = new Set(options?.excludeRoles ?? []);
|
|
2239
2395
|
const excludeVariants = new Set(options?.excludeVariants ?? []);
|
|
2240
2396
|
const labelToCoord = /* @__PURE__ */ new Map();
|
|
2241
|
-
for (const role of Object.keys(
|
|
2397
|
+
for (const role of Object.keys(palette)) {
|
|
2242
2398
|
if (excludeRoles.has(role)) continue;
|
|
2243
|
-
const scale =
|
|
2399
|
+
const scale = palette[role];
|
|
2244
2400
|
for (const variant of Object.keys(scale)) {
|
|
2245
2401
|
if (excludeVariants.has(variant)) continue;
|
|
2246
2402
|
const raw = scale[variant];
|
|
@@ -2378,8 +2534,9 @@ Did you mean addToken("${suggestion}") to change the palette?`
|
|
|
2378
2534
|
if (this.strongSideVariants.includes(variantName)) {
|
|
2379
2535
|
return this.strongSideVariants;
|
|
2380
2536
|
}
|
|
2537
|
+
const surface = this.surfaceForegroundRoles().surface;
|
|
2381
2538
|
const sampleRole = Object.keys(this.lightPalette).find(
|
|
2382
|
-
(r) => r !==
|
|
2539
|
+
(r) => r !== surface
|
|
2383
2540
|
);
|
|
2384
2541
|
if (!sampleRole) return null;
|
|
2385
2542
|
const scale = this.lightPalette[sampleRole];
|
|
@@ -2544,10 +2701,10 @@ var HextimateError = class extends Error {
|
|
|
2544
2701
|
this.name = "HextimateError";
|
|
2545
2702
|
}
|
|
2546
2703
|
};
|
|
2547
|
-
function hextimate(color) {
|
|
2704
|
+
function hextimate(color, theme) {
|
|
2548
2705
|
try {
|
|
2549
2706
|
const parsedColor = parse(color);
|
|
2550
|
-
return new HextimatePaletteBuilder(parsedColor);
|
|
2707
|
+
return new HextimatePaletteBuilder(parsedColor, theme);
|
|
2551
2708
|
} catch (e) {
|
|
2552
2709
|
if (e instanceof HextimateError) {
|
|
2553
2710
|
throw e;
|
|
@@ -2566,6 +2723,42 @@ function fromConfig(c) {
|
|
|
2566
2723
|
return b;
|
|
2567
2724
|
}
|
|
2568
2725
|
|
|
2726
|
+
// src/tailwindAliases.ts
|
|
2727
|
+
function tailwindAliases(theme, { as: runtimeFormat, inverted = false, ...names } = {}) {
|
|
2728
|
+
const as = runtimeFormat ?? theme.format?.as ?? "object";
|
|
2729
|
+
if (as !== "object" && as !== "css") {
|
|
2730
|
+
throw new Error("Tailwind aliases require object or css runtime output.");
|
|
2731
|
+
}
|
|
2732
|
+
const { light, dark } = hextimate(
|
|
2733
|
+
theme.defaultAccent ?? "#737373",
|
|
2734
|
+
theme
|
|
2735
|
+
).format({
|
|
2736
|
+
...names,
|
|
2737
|
+
as: "object",
|
|
2738
|
+
...as === "css" && { keyPrefix: "" },
|
|
2739
|
+
invertedVariants: false
|
|
2740
|
+
});
|
|
2741
|
+
const separator = { separator: theme.format?.separator, ...names }.separator ?? "-";
|
|
2742
|
+
const suffix = inverted ? `${separator}inverted` : "";
|
|
2743
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(light), ...Object.keys(dark)]);
|
|
2744
|
+
const aliases = Array.from(keys, (name) => {
|
|
2745
|
+
const key = `${as === "object" ? name.replace(/^--/, "") : name}${suffix}`;
|
|
2746
|
+
return ` --color-${key}: var(--${key});`;
|
|
2747
|
+
});
|
|
2748
|
+
return ["@theme inline {", ...aliases, "}", ""].join("\n");
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
// src/themes.ts
|
|
2752
|
+
var themes_exports = {};
|
|
2753
|
+
__export(themes_exports, {
|
|
2754
|
+
bold: () => boldTheme,
|
|
2755
|
+
mui: () => muiTheme,
|
|
2756
|
+
muted: () => mutedTheme,
|
|
2757
|
+
shadcn: () => shadcnTheme,
|
|
2758
|
+
tinted: () => tintedTheme,
|
|
2759
|
+
vibrant: () => vibrantTheme
|
|
2760
|
+
});
|
|
2761
|
+
|
|
2569
2762
|
export {
|
|
2570
2763
|
convert,
|
|
2571
2764
|
parse,
|
|
@@ -2574,5 +2767,7 @@ export {
|
|
|
2574
2767
|
HextimatePaletteBuilder,
|
|
2575
2768
|
HextimateError,
|
|
2576
2769
|
hextimate,
|
|
2577
|
-
fromConfig
|
|
2770
|
+
fromConfig,
|
|
2771
|
+
tailwindAliases,
|
|
2772
|
+
themes_exports
|
|
2578
2773
|
};
|