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/CHANGELOG.md +20 -0
- package/README.md +84 -39
- package/dist/{HextimatePaletteBuilder-CPmTYcEY.d.ts → HextimatePaletteBuilder-2hj-zvnW.d.ts} +105 -4
- package/dist/{chunk-FEOOTCAG.js → chunk-3JIC7LRE.js} +249 -46
- package/dist/chunk-Q6KJLMLM.js +251 -0
- package/dist/cli.js +366 -158
- 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 +44 -20
- 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-An21acU4.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],
|
|
@@ -892,10 +906,15 @@ function darkSelectorFor(mode) {
|
|
|
892
906
|
function formatCSSStylesheet(lightEntries, darkEntries, sep, opts = {}) {
|
|
893
907
|
const selector = opts.selector ?? ":root";
|
|
894
908
|
const darkMode = opts.darkMode ?? "media";
|
|
909
|
+
const theme = opts.theme === "dark" ? "dark" : darkMode === false ? "light" : opts.theme ?? "both";
|
|
895
910
|
const lightBlock = `${selector} {
|
|
896
911
|
${declsFromEntries(lightEntries, sep, "--", " ")}
|
|
897
912
|
}`;
|
|
898
|
-
|
|
913
|
+
const rootDarkBlock = `${selector} {
|
|
914
|
+
${declsFromEntries(darkEntries, sep, "--", " ")}
|
|
915
|
+
}`;
|
|
916
|
+
if (theme === "dark") return rootDarkBlock;
|
|
917
|
+
if (theme === "light" || darkMode === false) return lightBlock;
|
|
899
918
|
if (darkMode === "media") {
|
|
900
919
|
const darkInner = declsFromEntries(darkEntries, sep, "--", " ");
|
|
901
920
|
return `${lightBlock}
|
|
@@ -914,10 +933,12 @@ ${darkBlock}`;
|
|
|
914
933
|
}
|
|
915
934
|
function formatTailwindStylesheet(lightEntries, darkEntries, sep, opts = {}) {
|
|
916
935
|
const darkMode = opts.darkMode ?? "media";
|
|
936
|
+
const selectedTheme = opts.theme === "dark" ? "dark" : darkMode === false ? "light" : opts.theme ?? "both";
|
|
937
|
+
const themeEntries = selectedTheme === "dark" ? darkEntries : lightEntries;
|
|
917
938
|
const theme = `@theme {
|
|
918
|
-
${declsFromEntries(
|
|
939
|
+
${declsFromEntries(themeEntries, sep, "--color-", " ")}
|
|
919
940
|
}`;
|
|
920
|
-
if (darkMode === false) return theme;
|
|
941
|
+
if (selectedTheme !== "both" || darkMode === false) return theme;
|
|
921
942
|
if (darkMode === "media") {
|
|
922
943
|
const darkInner = declsFromEntries(darkEntries, sep, "--color-", " ");
|
|
923
944
|
return `${theme}
|
|
@@ -960,7 +981,8 @@ function formatStylesheet(lightPalette, darkPalette, options, lightStandalone, d
|
|
|
960
981
|
const sep = options?.separator ?? "-";
|
|
961
982
|
const stylesheetOpts = {
|
|
962
983
|
selector: options?.selector,
|
|
963
|
-
darkMode: options?.darkMode
|
|
984
|
+
darkMode: options?.darkMode,
|
|
985
|
+
theme: options?.theme
|
|
964
986
|
};
|
|
965
987
|
if (options?.as === "tailwind-css") {
|
|
966
988
|
return formatTailwindStylesheet(
|
|
@@ -1669,16 +1691,84 @@ function generateSurface(color, themeType, options) {
|
|
|
1669
1691
|
}
|
|
1670
1692
|
|
|
1671
1693
|
// src/generate/generate.ts
|
|
1672
|
-
|
|
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
|
+
}
|
|
1673
1713
|
const resolvedOptions = {
|
|
1674
1714
|
...options ?? {},
|
|
1675
1715
|
inputLightness: convert(color, "oklch").l
|
|
1676
1716
|
};
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
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 };
|
|
1682
1772
|
}
|
|
1683
1773
|
|
|
1684
1774
|
// src/HextimatePaletteBuilder.ts
|
|
@@ -1707,22 +1797,28 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1707
1797
|
lightPalette;
|
|
1708
1798
|
darkPalette;
|
|
1709
1799
|
inputColor;
|
|
1800
|
+
theme;
|
|
1710
1801
|
options;
|
|
1711
1802
|
operations = [];
|
|
1712
1803
|
standaloneTokens = [];
|
|
1804
|
+
foregroundOverrides = /* @__PURE__ */ new Map();
|
|
1713
1805
|
weakSideVariants = ["weak"];
|
|
1714
1806
|
strongSideVariants = ["strong"];
|
|
1715
1807
|
foregroundAnchoredVariants = /* @__PURE__ */ new Set();
|
|
1716
1808
|
betweenVariants = [];
|
|
1717
1809
|
presetFormatDefaults;
|
|
1718
|
-
constructor(color) {
|
|
1810
|
+
constructor(color, theme = baseTheme) {
|
|
1719
1811
|
this.inputColor = color;
|
|
1812
|
+
this.theme = theme;
|
|
1720
1813
|
this.options = {};
|
|
1721
|
-
this.seedOptionsForFork(
|
|
1814
|
+
this.seedOptionsForFork(mergeStyleOptions(theme.style));
|
|
1722
1815
|
}
|
|
1723
1816
|
/**
|
|
1724
1817
|
* Merges style options into the builder and regenerates the palettes,
|
|
1725
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}.
|
|
1726
1822
|
*/
|
|
1727
1823
|
style(partial) {
|
|
1728
1824
|
this.operations.push({ method: "style", args: [partial] });
|
|
@@ -1732,17 +1828,21 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1732
1828
|
}
|
|
1733
1829
|
seedOptionsForFork(seededOptions) {
|
|
1734
1830
|
this.options = { ...seededOptions };
|
|
1831
|
+
const roles = generatedRoles(this.theme);
|
|
1735
1832
|
this.lightPalette = generate(
|
|
1736
1833
|
this.inputColor,
|
|
1737
1834
|
"light",
|
|
1738
|
-
this.resolvedOptions()
|
|
1835
|
+
this.resolvedOptions(),
|
|
1836
|
+
roles
|
|
1739
1837
|
);
|
|
1740
1838
|
this.darkPalette = generate(
|
|
1741
1839
|
this.inputColor,
|
|
1742
1840
|
"dark",
|
|
1743
|
-
this.resolvedOptions()
|
|
1841
|
+
this.resolvedOptions(),
|
|
1842
|
+
roles
|
|
1744
1843
|
);
|
|
1745
1844
|
this.standaloneTokens.length = 0;
|
|
1845
|
+
this.foregroundOverrides.clear();
|
|
1746
1846
|
this.weakSideVariants.length = 0;
|
|
1747
1847
|
this.weakSideVariants.push("weak");
|
|
1748
1848
|
this.strongSideVariants.length = 0;
|
|
@@ -1750,12 +1850,45 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1750
1850
|
this.foregroundAnchoredVariants.clear();
|
|
1751
1851
|
this.betweenVariants.length = 0;
|
|
1752
1852
|
this.presetFormatDefaults = void 0;
|
|
1753
|
-
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;
|
|
1754
1878
|
const colorOKLCH = convert(this.inputColor, "oklch");
|
|
1755
1879
|
const lightFg = { ...colorOKLCH, l: 0.97, c: Math.min(colorOKLCH.c, 0.01) };
|
|
1756
1880
|
const darkFg = { ...colorOKLCH, l: 0.1, c: Math.min(colorOKLCH.c, 0.01) };
|
|
1757
|
-
|
|
1758
|
-
|
|
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
|
+
};
|
|
1759
1892
|
}
|
|
1760
1893
|
rebuildFromOperations() {
|
|
1761
1894
|
this.seedOptionsForFork(this.options);
|
|
@@ -1816,6 +1949,8 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1816
1949
|
*
|
|
1817
1950
|
* @param name Role name (e.g. "cta", "banner")
|
|
1818
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}.
|
|
1819
1954
|
*/
|
|
1820
1955
|
addRole(name, color) {
|
|
1821
1956
|
this.operations.push({ method: "addRole", args: [name, color] });
|
|
@@ -1830,6 +1965,8 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1830
1965
|
*
|
|
1831
1966
|
* @param name Variant name (e.g. "placeholder", "highlight")
|
|
1832
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}.
|
|
1833
1970
|
*/
|
|
1834
1971
|
addVariant(name, placement) {
|
|
1835
1972
|
this.operations.push({ method: "addVariant", args: [name, placement] });
|
|
@@ -1841,6 +1978,9 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1841
1978
|
*
|
|
1842
1979
|
* Override with a dotted key: `surface.weak`, `surface.DEFAULT` (not `surface-weak`).
|
|
1843
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}.
|
|
1844
1984
|
*/
|
|
1845
1985
|
addToken(name, value) {
|
|
1846
1986
|
this.operations.push({ method: "addToken", args: [name, value] });
|
|
@@ -1865,21 +2005,16 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1865
2005
|
* const theme = hextimate('#6366F1')
|
|
1866
2006
|
* .preset(presets.shadcn)
|
|
1867
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}.
|
|
1868
2011
|
*/
|
|
1869
2012
|
preset(preset) {
|
|
1870
2013
|
this.operations.push({ method: "preset", args: [preset] });
|
|
1871
2014
|
if (preset.style) {
|
|
1872
2015
|
this.options = mergeStyleOptions(this.options, preset.style);
|
|
1873
|
-
this.
|
|
1874
|
-
|
|
1875
|
-
"light",
|
|
1876
|
-
this.resolvedOptions()
|
|
1877
|
-
);
|
|
1878
|
-
this.darkPalette = generate(
|
|
1879
|
-
this.inputColor,
|
|
1880
|
-
"dark",
|
|
1881
|
-
this.resolvedOptions()
|
|
1882
|
-
);
|
|
2016
|
+
this.rebuildFromOperations();
|
|
2017
|
+
return this;
|
|
1883
2018
|
}
|
|
1884
2019
|
this.applyPresetRolesTokensFormat(preset);
|
|
1885
2020
|
return this;
|
|
@@ -1968,7 +2103,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
1968
2103
|
*/
|
|
1969
2104
|
fork(color) {
|
|
1970
2105
|
const newColor = color !== void 0 ? parse(color) : this.inputColor;
|
|
1971
|
-
const builder = new _HextimatePaletteBuilder(newColor);
|
|
2106
|
+
const builder = new _HextimatePaletteBuilder(newColor, this.theme);
|
|
1972
2107
|
builder.seedOptionsForFork({ ...this.options });
|
|
1973
2108
|
for (const op of this.operations) {
|
|
1974
2109
|
switch (op.method) {
|
|
@@ -2009,43 +2144,51 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
2009
2144
|
...options?.variantNames
|
|
2010
2145
|
}
|
|
2011
2146
|
} : options;
|
|
2147
|
+
const lightPalette = this.outputPalette("light");
|
|
2148
|
+
const darkPalette = this.outputPalette("dark");
|
|
2012
2149
|
const colorFormat = mergedOptions?.colors ?? "hex";
|
|
2013
|
-
this.assertNoPaletteLabelCollisions(mergedOptions);
|
|
2150
|
+
this.assertNoPaletteLabelCollisions(mergedOptions, lightPalette);
|
|
2014
2151
|
const lightTokens = this.resolveStandaloneTokens(
|
|
2015
2152
|
"light",
|
|
2016
|
-
|
|
2153
|
+
lightPalette,
|
|
2017
2154
|
colorFormat
|
|
2018
2155
|
);
|
|
2019
2156
|
const darkTokens = this.resolveStandaloneTokens(
|
|
2020
2157
|
"dark",
|
|
2021
|
-
|
|
2158
|
+
darkPalette,
|
|
2022
2159
|
colorFormat
|
|
2023
2160
|
);
|
|
2024
|
-
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: [] };
|
|
2025
2168
|
if (mergedOptions?.as === "css" || mergedOptions?.as === "tailwind-css") {
|
|
2026
2169
|
return formatStylesheet(
|
|
2027
|
-
|
|
2028
|
-
|
|
2170
|
+
lightPalette,
|
|
2171
|
+
darkPalette,
|
|
2029
2172
|
mergedOptions,
|
|
2030
2173
|
[...lightTokens, ...inverted.lightBlock],
|
|
2031
2174
|
[...darkTokens, ...inverted.darkBlock]
|
|
2032
2175
|
);
|
|
2033
2176
|
}
|
|
2034
2177
|
return {
|
|
2035
|
-
light: format(
|
|
2178
|
+
light: format(lightPalette, mergedOptions, [
|
|
2036
2179
|
...lightTokens,
|
|
2037
2180
|
...inverted.lightBlock
|
|
2038
2181
|
]),
|
|
2039
|
-
dark: format(
|
|
2182
|
+
dark: format(darkPalette, mergedOptions, [
|
|
2040
2183
|
...darkTokens,
|
|
2041
2184
|
...inverted.darkBlock
|
|
2042
2185
|
])
|
|
2043
2186
|
};
|
|
2044
2187
|
}
|
|
2045
|
-
buildInvertedEntries(options, lightStandalone, darkStandalone) {
|
|
2188
|
+
buildInvertedEntries(options, lightStandalone, darkStandalone, lightPalette, darkPalette) {
|
|
2046
2189
|
const sep = options.separator ?? "-";
|
|
2047
|
-
const lightBase = buildTokenEntries(
|
|
2048
|
-
const darkBase = buildTokenEntries(
|
|
2190
|
+
const lightBase = buildTokenEntries(lightPalette, options);
|
|
2191
|
+
const darkBase = buildTokenEntries(darkPalette, options);
|
|
2049
2192
|
return {
|
|
2050
2193
|
// Light block carries dark values under -inverted suffix.
|
|
2051
2194
|
lightBlock: [
|
|
@@ -2059,6 +2202,22 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
2059
2202
|
]
|
|
2060
2203
|
};
|
|
2061
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
|
+
}
|
|
2062
2221
|
applyRole(name, color) {
|
|
2063
2222
|
const parsedColor = this.isDerivedToken(color) ? this.resolveDerivedToken(color, this.lightPalette, "light") : parse(color);
|
|
2064
2223
|
const opts = this.resolvedOptions();
|
|
@@ -2183,6 +2342,11 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
2183
2342
|
}
|
|
2184
2343
|
}
|
|
2185
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
|
+
}
|
|
2186
2350
|
if (name.includes(".")) {
|
|
2187
2351
|
this.applyPalettePin(name, value);
|
|
2188
2352
|
return;
|
|
@@ -2224,15 +2388,15 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
|
|
|
2224
2388
|
* Standalone token names must not squash palette flat keys after
|
|
2225
2389
|
* roleNames / variantNames / separator / excludes are applied.
|
|
2226
2390
|
*/
|
|
2227
|
-
assertNoPaletteLabelCollisions(options) {
|
|
2391
|
+
assertNoPaletteLabelCollisions(options, palette) {
|
|
2228
2392
|
if (this.standaloneTokens.length === 0) return;
|
|
2229
2393
|
const sep = options?.separator ?? "-";
|
|
2230
2394
|
const excludeRoles = new Set(options?.excludeRoles ?? []);
|
|
2231
2395
|
const excludeVariants = new Set(options?.excludeVariants ?? []);
|
|
2232
2396
|
const labelToCoord = /* @__PURE__ */ new Map();
|
|
2233
|
-
for (const role of Object.keys(
|
|
2397
|
+
for (const role of Object.keys(palette)) {
|
|
2234
2398
|
if (excludeRoles.has(role)) continue;
|
|
2235
|
-
const scale =
|
|
2399
|
+
const scale = palette[role];
|
|
2236
2400
|
for (const variant of Object.keys(scale)) {
|
|
2237
2401
|
if (excludeVariants.has(variant)) continue;
|
|
2238
2402
|
const raw = scale[variant];
|
|
@@ -2370,8 +2534,9 @@ Did you mean addToken("${suggestion}") to change the palette?`
|
|
|
2370
2534
|
if (this.strongSideVariants.includes(variantName)) {
|
|
2371
2535
|
return this.strongSideVariants;
|
|
2372
2536
|
}
|
|
2537
|
+
const surface = this.surfaceForegroundRoles().surface;
|
|
2373
2538
|
const sampleRole = Object.keys(this.lightPalette).find(
|
|
2374
|
-
(r) => r !==
|
|
2539
|
+
(r) => r !== surface
|
|
2375
2540
|
);
|
|
2376
2541
|
if (!sampleRole) return null;
|
|
2377
2542
|
const scale = this.lightPalette[sampleRole];
|
|
@@ -2536,10 +2701,10 @@ var HextimateError = class extends Error {
|
|
|
2536
2701
|
this.name = "HextimateError";
|
|
2537
2702
|
}
|
|
2538
2703
|
};
|
|
2539
|
-
function hextimate(color) {
|
|
2704
|
+
function hextimate(color, theme) {
|
|
2540
2705
|
try {
|
|
2541
2706
|
const parsedColor = parse(color);
|
|
2542
|
-
return new HextimatePaletteBuilder(parsedColor);
|
|
2707
|
+
return new HextimatePaletteBuilder(parsedColor, theme);
|
|
2543
2708
|
} catch (e) {
|
|
2544
2709
|
if (e instanceof HextimateError) {
|
|
2545
2710
|
throw e;
|
|
@@ -2558,6 +2723,42 @@ function fromConfig(c) {
|
|
|
2558
2723
|
return b;
|
|
2559
2724
|
}
|
|
2560
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
|
+
|
|
2561
2762
|
export {
|
|
2562
2763
|
convert,
|
|
2563
2764
|
parse,
|
|
@@ -2566,5 +2767,7 @@ export {
|
|
|
2566
2767
|
HextimatePaletteBuilder,
|
|
2567
2768
|
HextimateError,
|
|
2568
2769
|
hextimate,
|
|
2569
|
-
fromConfig
|
|
2770
|
+
fromConfig,
|
|
2771
|
+
tailwindAliases,
|
|
2772
|
+
themes_exports
|
|
2570
2773
|
};
|