hextimator 0.5.0 → 0.6.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.
@@ -1,9 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
1
  // src/convert/matrices.ts
8
2
  var M1 = [
9
3
  [0.4122214708, 0.5363325363, 0.0514459929],
@@ -1238,20 +1232,20 @@ function calculateContrast(colorA, colorB) {
1238
1232
 
1239
1233
  // src/generate/generateAccent.ts
1240
1234
  function generateAccent(accent, themeType, options) {
1241
- const invertBaseAndAccent = themeType === "dark" && options?.invertDarkModeBaseAccent;
1242
- if (invertBaseAndAccent) {
1235
+ const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
1236
+ if (invertSurfaceAndAccent) {
1243
1237
  const accentOklch = convert(accent, "oklch");
1244
- const baseHueShift = options?.baseHueShift ?? 0;
1245
- let baseOklch = options?.baseColor ? convert(parse(options.baseColor), "oklch") : convert(accent, "oklch");
1246
- if (baseHueShift !== 0 && !options?.baseColor) {
1247
- baseOklch = {
1248
- ...baseOklch,
1249
- h: wrapHue(accentOklch.h + baseHueShift)
1238
+ const surfaceHueShift = options?.surfaceHueShift ?? 0;
1239
+ let surfaceOklch = options?.surfaceColor ? convert(parse(options.surfaceColor), "oklch") : convert(accent, "oklch");
1240
+ if (surfaceHueShift !== 0 && !options?.surfaceColor) {
1241
+ surfaceOklch = {
1242
+ ...surfaceOklch,
1243
+ h: wrapHue(accentOklch.h + surfaceHueShift)
1250
1244
  };
1251
1245
  }
1252
1246
  const maxChroma = options?.dark?.maxChroma;
1253
1247
  const invertedAccent = {
1254
- ...baseOklch,
1248
+ ...surfaceOklch,
1255
1249
  c: maxChroma !== void 0 ? Math.min(accentOklch.c, maxChroma) : accentOklch.c
1256
1250
  };
1257
1251
  return expandColorToScale(invertedAccent, themeType, options);
@@ -1259,47 +1253,6 @@ function generateAccent(accent, themeType, options) {
1259
1253
  return expandColorToScale(accent, themeType, options);
1260
1254
  }
1261
1255
 
1262
- // src/generate/generateBase.ts
1263
- var BASELINE_DARK_L_VALUE = 0.2;
1264
- var BASELINE_LIGHT_L_VALUE = 0.97;
1265
- var BASELINE_MAX_CHROMA = 0.01;
1266
- var STRONG_DELTA_DARK = -0.1;
1267
- var STRONG_DELTA_LIGHT = 0.02;
1268
- var WEAK_DELTA_DARK = 0.1;
1269
- var WEAK_DELTA_LIGHT = -0.03;
1270
- function generateBase(color, themeType, options) {
1271
- const invertBaseAndAccent = themeType === "dark" && options?.invertDarkModeBaseAccent;
1272
- const preferredBaseColorInput = invertBaseAndAccent ? color ?? options?.baseColor : options?.baseColor ?? color;
1273
- const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
1274
- const baselineMaxChroma = themeAdjustments?.baseMaxChroma ?? options?.baseMaxChroma ?? BASELINE_MAX_CHROMA;
1275
- const preferredBaseColor = convert(parse(preferredBaseColorInput), "oklch");
1276
- let baseHue = preferredBaseColor.h;
1277
- const baseChroma = Math.min(preferredBaseColor.c, baselineMaxChroma);
1278
- const baseHueShift = options?.baseHueShift ?? 0;
1279
- if (baseHueShift !== 0 && !options?.baseColor && !invertBaseAndAccent) {
1280
- baseHue = wrapHue(convert(color, "oklch").h + baseHueShift);
1281
- }
1282
- const normalizedPreferredBaseColor = {
1283
- ...preferredBaseColor,
1284
- h: baseHue,
1285
- c: baseChroma,
1286
- l: themeType === "light" ? BASELINE_LIGHT_L_VALUE : BASELINE_DARK_L_VALUE
1287
- };
1288
- return expandColorToScale(normalizedPreferredBaseColor, themeType, {
1289
- baselineLValueDark: BASELINE_DARK_L_VALUE,
1290
- baselineLValueLight: BASELINE_LIGHT_L_VALUE,
1291
- strongDeltaDark: STRONG_DELTA_DARK,
1292
- strongDeltaLight: STRONG_DELTA_LIGHT,
1293
- weakDeltaDark: WEAK_DELTA_DARK,
1294
- weakDeltaLight: WEAK_DELTA_LIGHT,
1295
- minContrastRatio: options?.minContrastRatio,
1296
- hueShift: options?.hueShift,
1297
- foregroundMaxChroma: options?.foregroundMaxChroma,
1298
- light: options?.light,
1299
- dark: options?.dark
1300
- });
1301
- }
1302
-
1303
1256
  // src/generate/generateSemanticColors.ts
1304
1257
  var POSITIVE_RANGE = [135, 160];
1305
1258
  var NEGATIVE_RANGE = [5, 25];
@@ -1401,10 +1354,54 @@ function _getSplitComplementaryColors(color) {
1401
1354
  ];
1402
1355
  }
1403
1356
 
1357
+ // src/generate/generateSurface.ts
1358
+ var BASELINE_DARK_L_VALUE = 0.2;
1359
+ var BASELINE_LIGHT_L_VALUE = 0.97;
1360
+ var BASELINE_MAX_CHROMA = 0.01;
1361
+ var STRONG_DELTA_DARK = -0.1;
1362
+ var STRONG_DELTA_LIGHT = 0.02;
1363
+ var WEAK_DELTA_DARK = 0.1;
1364
+ var WEAK_DELTA_LIGHT = -0.03;
1365
+ function generateSurface(color, themeType, options) {
1366
+ const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
1367
+ const preferredSurfaceColorInput = invertSurfaceAndAccent ? color ?? options?.surfaceColor : options?.surfaceColor ?? color;
1368
+ const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
1369
+ const surfaceMaxChroma = themeAdjustments?.surfaceMaxChroma ?? options?.surfaceMaxChroma ?? BASELINE_MAX_CHROMA;
1370
+ const preferredSurfaceColor = convert(
1371
+ parse(preferredSurfaceColorInput),
1372
+ "oklch"
1373
+ );
1374
+ let surfaceHue = preferredSurfaceColor.h;
1375
+ const surfaceChroma = Math.min(preferredSurfaceColor.c, surfaceMaxChroma);
1376
+ const surfaceHueShift = options?.surfaceHueShift ?? 0;
1377
+ if (surfaceHueShift !== 0 && !options?.surfaceColor && !invertSurfaceAndAccent) {
1378
+ surfaceHue = wrapHue(convert(color, "oklch").h + surfaceHueShift);
1379
+ }
1380
+ const normalizedPreferredSurfaceColor = {
1381
+ ...preferredSurfaceColor,
1382
+ h: surfaceHue,
1383
+ c: surfaceChroma,
1384
+ l: themeType === "light" ? BASELINE_LIGHT_L_VALUE : BASELINE_DARK_L_VALUE
1385
+ };
1386
+ return expandColorToScale(normalizedPreferredSurfaceColor, themeType, {
1387
+ baselineLValueDark: BASELINE_DARK_L_VALUE,
1388
+ baselineLValueLight: BASELINE_LIGHT_L_VALUE,
1389
+ strongDeltaDark: STRONG_DELTA_DARK,
1390
+ strongDeltaLight: STRONG_DELTA_LIGHT,
1391
+ weakDeltaDark: WEAK_DELTA_DARK,
1392
+ weakDeltaLight: WEAK_DELTA_LIGHT,
1393
+ minContrastRatio: options?.minContrastRatio,
1394
+ hueShift: options?.hueShift,
1395
+ foregroundMaxChroma: options?.foregroundMaxChroma,
1396
+ light: options?.light,
1397
+ dark: options?.dark
1398
+ });
1399
+ }
1400
+
1404
1401
  // src/generate/generate.ts
1405
1402
  function generate(color, themeType, options) {
1406
1403
  return {
1407
- base: generateBase(color, themeType, options),
1404
+ surface: generateSurface(color, themeType, options),
1408
1405
  accent: generateAccent(color, themeType, options),
1409
1406
  ...generateSemanticColors(color, themeType, options)
1410
1407
  };
@@ -1449,7 +1446,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1449
1446
  this.seedOptionsForFork({});
1450
1447
  }
1451
1448
  /**
1452
- * Merges style options into the builder and regenerates the base palettes,
1449
+ * Merges style options into the builder and regenerates the palettes,
1453
1450
  * then replays recorded operations so roles and variants reflect the new style.
1454
1451
  */
1455
1452
  style(partial) {
@@ -1538,7 +1535,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1538
1535
  *
1539
1536
  * The color can be a direct color value or a derived token referencing an existing role.
1540
1537
  *
1541
- * e.g. `addRole('cta', '#ff0066')` adds a "cta" role with the specified hue as the base.
1538
+ * e.g. `addRole('cta', '#ff0066')` adds a "cta" role with the specified color.
1542
1539
  * `addRole('cta', { from: 'accent', hue: 180 })` adds a "cta" role with a complementary hue to accent.
1543
1540
  *
1544
1541
  * @param name Role name (e.g. "cta", "banner")
@@ -1571,7 +1568,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1571
1568
  * `addToken('brand', { light: '#3a86ff', dark: '#ff0066' })` adds a "brand" token with different colors in light and dark themes.
1572
1569
  *
1573
1570
  * It can also be used to override specific tokens after generation.
1574
- * `addToken('base-strong', '#ff0066')` overrides the automatically generated "base-strong" variant with a custom color.
1571
+ * `addToken('surface-strong', '#ff0066')` overrides the automatically generated "surface-strong" variant with a custom color.
1575
1572
  *
1576
1573
  * @param name Token name (e.g. "brand", "logo")
1577
1574
  * @param value Token value, which can be an exact color, or derived from an existing role+variant.
@@ -1585,7 +1582,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1585
1582
  * Applies a preset that configures roles, tokens, and format defaults
1586
1583
  * for a specific framework or convention (e.g. shadcn/ui).
1587
1584
  *
1588
- * Preset format defaults are used as a base in `.format()` — any options
1585
+ * Preset format defaults are used as defaults in `.format()` — any options
1589
1586
  * you pass to `.format()` will override the preset's defaults.
1590
1587
  *
1591
1588
  * @example
@@ -1626,7 +1623,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1626
1623
  this.operations.push({ method: "preset", args: [preset] });
1627
1624
  this.applyPresetRolesTokensFormat(preset);
1628
1625
  }
1629
- /** Roles, variants, tokens, and format only — `this.options` and base palettes are already correct. */
1626
+ /** Roles, variants, tokens, and format only — `this.options` and palettes are already correct. */
1630
1627
  applyPresetRolesTokensFormat(preset) {
1631
1628
  for (const role of preset.roles ?? []) {
1632
1629
  this.applyRole(role.name, role.color);
@@ -1695,7 +1692,7 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1695
1692
  return this;
1696
1693
  }
1697
1694
  /**
1698
- * Creates a new builder instance with the same operations history, optionally from a different base color.
1695
+ * Creates a new builder instance with the same operations history, optionally from a different accent color.
1699
1696
  * To change style options on the fork, chain `.style()` after `.fork()`.
1700
1697
  *
1701
1698
  * @param color Optional new accent/brand color. If omitted, the fork uses the same color as this builder.
@@ -1936,7 +1933,9 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
1936
1933
  if (this.strongSideVariants.includes(variantName)) {
1937
1934
  return this.strongSideVariants;
1938
1935
  }
1939
- const sampleRole = Object.keys(this.lightPalette).find((r) => r !== "base");
1936
+ const sampleRole = Object.keys(this.lightPalette).find(
1937
+ (r) => r !== "surface"
1938
+ );
1940
1939
  if (!sampleRole) return null;
1941
1940
  const scale = this.lightPalette[sampleRole];
1942
1941
  if (!scale[variantName]) return null;
@@ -2092,174 +2091,6 @@ var HextimatePaletteBuilder = class _HextimatePaletteBuilder {
2092
2091
  }
2093
2092
  };
2094
2093
 
2095
- // src/presets/index.ts
2096
- var presets_exports = {};
2097
- __export(presets_exports, {
2098
- bold: () => bold,
2099
- mui: () => mui,
2100
- muted: () => muted,
2101
- shadcn: () => shadcn,
2102
- tinted: () => tinted,
2103
- vibrant: () => vibrant
2104
- });
2105
-
2106
- // src/presets/bold.ts
2107
- var bold = {
2108
- style: {
2109
- light: { lightness: 0.5 },
2110
- dark: { lightness: 0.8 },
2111
- baseMaxChroma: 0.06,
2112
- foregroundMaxChroma: 0.02
2113
- }
2114
- };
2115
-
2116
- // src/presets/mui.ts
2117
- var mui = {
2118
- roles: [
2119
- { name: "info", color: "#0288d1" },
2120
- { name: "secondary", color: { from: "accent", hue: 180 } }
2121
- ],
2122
- tokens: [
2123
- // background
2124
- { name: "background-default", value: { from: "base" } },
2125
- {
2126
- name: "background-paper",
2127
- value: { from: "base", emphasis: -0.025 }
2128
- },
2129
- // text
2130
- { name: "text-primary", value: { from: "base.foreground" } },
2131
- {
2132
- name: "text-secondary",
2133
- value: { from: "base.foreground", emphasis: -0.2 }
2134
- },
2135
- {
2136
- name: "text-disabled",
2137
- value: { from: "base.foreground", emphasis: -0.4 }
2138
- },
2139
- // divider
2140
- { name: "divider", value: { from: "base", emphasis: 0.12 } },
2141
- // action tokens
2142
- { name: "action-hover", value: { from: "base", emphasis: 0.04 } },
2143
- { name: "action-selected", value: { from: "base", emphasis: 0.08 } },
2144
- { name: "action-disabled", value: { from: "base", emphasis: 0.15 } },
2145
- {
2146
- name: "action-disabledBackground",
2147
- value: { from: "base", emphasis: 0.06 }
2148
- },
2149
- { name: "action-focus", value: { from: "base", emphasis: 0.06 } }
2150
- ],
2151
- format: {
2152
- as: "object",
2153
- colors: "hex",
2154
- separator: "-",
2155
- roleNames: {
2156
- accent: "primary",
2157
- negative: "error",
2158
- positive: "success"
2159
- },
2160
- variantNames: {
2161
- DEFAULT: "main",
2162
- weak: "light",
2163
- strong: "dark",
2164
- foreground: "contrastText"
2165
- },
2166
- excludeRoles: ["base"]
2167
- }
2168
- };
2169
-
2170
- // src/presets/muted.ts
2171
- var muted = {
2172
- style: {
2173
- light: { maxChroma: 0.08 },
2174
- dark: { maxChroma: 0.07 },
2175
- baseMaxChroma: 5e-3,
2176
- foregroundMaxChroma: 5e-3
2177
- }
2178
- };
2179
-
2180
- // src/presets/shadcn.ts
2181
- var shadcn = {
2182
- tokens: [
2183
- // shadcn uses bare --foreground (not --background-foreground)
2184
- { name: "foreground", value: { from: "base.foreground" } },
2185
- // card / popover — same as background
2186
- { name: "card", value: { from: "base" } },
2187
- { name: "card-foreground", value: { from: "base.foreground" } },
2188
- { name: "popover", value: { from: "base" } },
2189
- { name: "popover-foreground", value: { from: "base.foreground" } },
2190
- // secondary — subtle contrast from background
2191
- { name: "secondary", value: { from: "base" } },
2192
- { name: "secondary-foreground", value: { from: "base.foreground" } },
2193
- // muted — similar to secondary, but with dimmer foreground
2194
- { name: "muted", value: { from: "base" } },
2195
- {
2196
- name: "muted-foreground",
2197
- value: {
2198
- from: "base.foreground",
2199
- emphasis: -0.25
2200
- }
2201
- },
2202
- // accent (shadcn meaning: subtle hover highlight, not the brand color)
2203
- { name: "accent", value: { from: "base" } },
2204
- { name: "accent-foreground", value: { from: "base.foreground" } },
2205
- // border / input
2206
- {
2207
- name: "border",
2208
- value: { from: "base", emphasis: 0.8 }
2209
- },
2210
- {
2211
- name: "input",
2212
- value: {
2213
- from: "base",
2214
- emphasis: 0.8
2215
- }
2216
- },
2217
- // ring — uses the brand/primary color
2218
- { name: "ring", value: { from: "accent" } },
2219
- // chart tokens colors use brand/priamry color
2220
- { name: "chart-1", value: { from: "accent" } },
2221
- { name: "chart-2", value: { from: "chart-1", emphasis: -0.04 } },
2222
- { name: "chart-3", value: { from: "chart-2", emphasis: -0.04 } },
2223
- { name: "chart-4", value: { from: "chart-3", emphasis: -0.04 } },
2224
- { name: "chart-5", value: { from: "chart-4", emphasis: -0.04 } }
2225
- ],
2226
- format: {
2227
- as: "css",
2228
- colors: "oklch",
2229
- roleNames: {
2230
- base: "background",
2231
- accent: "primary",
2232
- negative: "destructive",
2233
- positive: "success"
2234
- },
2235
- variantNames: {
2236
- foreground: "foreground"
2237
- },
2238
- excludeRoles: ["warning"],
2239
- excludeVariants: ["strong", "weak"]
2240
- }
2241
- };
2242
-
2243
- // src/presets/tinted.ts
2244
- var tinted = {
2245
- style: {
2246
- baseMaxChroma: 0.05,
2247
- baseHueShift: 0,
2248
- foregroundMaxChroma: 0.015
2249
- }
2250
- };
2251
-
2252
- // src/presets/vibrant.ts
2253
- var vibrant = {
2254
- style: {
2255
- light: { maxChroma: 0.2, lightness: 0.6 },
2256
- dark: { maxChroma: 0.18, lightness: 0.65 },
2257
- hueShift: 5,
2258
- baseHueShift: 180,
2259
- baseMaxChroma: 0.08
2260
- }
2261
- };
2262
-
2263
2094
  // src/index.ts
2264
2095
  var HextimateError = class extends Error {
2265
2096
  constructor(input, message) {
@@ -2289,7 +2120,6 @@ export {
2289
2120
  daltonizeColor,
2290
2121
  simulateColor,
2291
2122
  HextimatePaletteBuilder,
2292
- presets_exports,
2293
2123
  HextimateError,
2294
2124
  hextimate
2295
2125
  };