hextimator 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -991,9 +991,47 @@ function formatStylesheet(lightPalette, darkPalette, options, lightStandalone, d
991
991
  return formatCSSStylesheet(lightEntries, darkEntries, sep, stylesheetOpts);
992
992
  }
993
993
 
994
+ // src/generate/mergeThemeAdjustments.ts
995
+ function extractGlobalThemeAdjustments(options) {
996
+ const {
997
+ light: _l,
998
+ dark: _d,
999
+ invertDarkModeSurfaceAccent: _i,
1000
+ inputLightness: _inp,
1001
+ ...global
1002
+ } = options;
1003
+ return global;
1004
+ }
1005
+ function mergeThemeAdjustments(base, override) {
1006
+ if (!override) return { ...base };
1007
+ return {
1008
+ ...base,
1009
+ ...override,
1010
+ semanticColors: base.semanticColors || override.semanticColors ? {
1011
+ ...base.semanticColors,
1012
+ ...override.semanticColors
1013
+ } : void 0,
1014
+ semanticColorRanges: base.semanticColorRanges || override.semanticColorRanges ? {
1015
+ ...base.semanticColorRanges,
1016
+ ...override.semanticColorRanges
1017
+ } : void 0
1018
+ };
1019
+ }
1020
+ function resolveMergedThemeAdjustments(themeType, options) {
1021
+ const global = extractGlobalThemeAdjustments(
1022
+ options
1023
+ );
1024
+ const branch = themeType === "light" ? options.light : options.dark;
1025
+ return mergeThemeAdjustments(global, branch);
1026
+ }
1027
+
994
1028
  // src/generate/consts.ts
995
1029
  var DEFAULT_LIGHT_THEME_LIGHTNESS = 0.7;
996
1030
  var DEFAULT_DARK_THEME_LIGHTNESS = 0.6;
1031
+ var SURFACE_SCALE = {
1032
+ light: { L: 0.97, strong: 0.02, weak: -0.03 },
1033
+ dark: { L: 0.2, strong: -0.1, weak: 0.1 }
1034
+ };
997
1035
 
998
1036
  // src/generate/utils.ts
999
1037
  var FOREGROUND_DARK_L_VALUE = 0.97;
@@ -1004,6 +1042,17 @@ var FALLBACK_STRONG_DELTA_LIGHT = -0.05;
1004
1042
  var FALLBACK_WEAK_DELTA_DARK = -0.05;
1005
1043
  var FALLBACK_WEAK_DELTA_LIGHT = 0.05;
1006
1044
  var VARIANT_DELTA = 0.1;
1045
+ var EXACT_CHIP_MIN_STRONG_DELTA_OKLCH = VARIANT_DELTA / 2;
1046
+ var LIGHT_THEME_LIGHTNESS_RANGE = [0.4, 0.9];
1047
+ var DARK_THEME_LIGHTNESS_RANGE = [0.2, 0.8];
1048
+ var ACCENT_VS_SURFACE_L_GAP = 0.045;
1049
+ function surfaceLightnessBand(themeType) {
1050
+ const x = themeType === "light" ? SURFACE_SCALE.light : SURFACE_SCALE.dark;
1051
+ const a = x.L;
1052
+ const b = x.L + x.strong;
1053
+ const c = x.L + x.weak;
1054
+ return { min: Math.min(a, b, c), max: Math.max(a, b, c) };
1055
+ }
1007
1056
  var CONTRAST_MARGIN = 0.15;
1008
1057
  function resolveContrastRatio(value) {
1009
1058
  if (value === void 0 || value === "AAA") return 7;
@@ -1019,45 +1068,191 @@ function clampHueShift(hueShift, totalVariants) {
1019
1068
  function wrapHue(h) {
1020
1069
  return (h % 360 + 360) % 360;
1021
1070
  }
1071
+ function oklchBodyClose(a, b) {
1072
+ const eps = 1e-5;
1073
+ let dh = Math.abs(a.h - b.h) % 360;
1074
+ if (dh > 180) dh = 360 - dh;
1075
+ return Math.abs(a.l - b.l) < eps && Math.abs(a.c - b.c) < eps && dh < 0.05;
1076
+ }
1077
+ function pickAccentForegroundPair(base, themeType, foregroundLValueLight, foregroundLValueDark, foregroundMaxChroma, minContrast) {
1078
+ const candidates = [foregroundLValueLight, foregroundLValueDark].map((l) => ({
1079
+ ...base,
1080
+ l,
1081
+ c: Math.min(base.c, foregroundMaxChroma)
1082
+ }));
1083
+ const [candidateA, candidateB] = themeType === "light" ? candidates : [...candidates].reverse();
1084
+ const contrastA = calculateContrast(base, candidateA);
1085
+ const contrastB = calculateContrast(base, candidateB);
1086
+ const [preferred, fallback] = contrastA >= contrastB ? [candidateA, candidateB] : [candidateB, candidateA];
1087
+ const foreground = calculateContrast(base, preferred) > minContrast ? preferred : fallback;
1088
+ return { foreground, preferred };
1089
+ }
1090
+ function computeStrongWeakWithoutBoundaryShift(base, foreground, themeType, contrastTarget) {
1091
+ const contrastDirection = themeType === "light" ? -1 : 1;
1092
+ const boundaryL = findContrastBoundaryLightness(
1093
+ base,
1094
+ foreground,
1095
+ contrastTarget
1096
+ );
1097
+ const distToBoundary = boundaryL !== null ? Math.abs(base.l - boundaryL) : 0;
1098
+ const strongDelta = Math.min(VARIANT_DELTA, distToBoundary);
1099
+ const weakCandidateColor = {
1100
+ ...base,
1101
+ l: base.l - VARIANT_DELTA * contrastDirection
1102
+ };
1103
+ let weakDelta = VARIANT_DELTA;
1104
+ if (calculateContrast(weakCandidateColor, foreground) < contrastTarget) {
1105
+ let lo = 0;
1106
+ let hi = VARIANT_DELTA;
1107
+ for (let i = 0; i < 20; i++) {
1108
+ const mid = (lo + hi) / 2;
1109
+ const testL = base.l - mid * contrastDirection;
1110
+ const testColor = { ...base, l: testL };
1111
+ if (calculateContrast(testColor, foreground) > contrastTarget) {
1112
+ lo = mid;
1113
+ } else {
1114
+ hi = mid;
1115
+ }
1116
+ }
1117
+ weakDelta = lo;
1118
+ }
1119
+ const strong = {
1120
+ ...base,
1121
+ l: Math.max(0, Math.min(1, base.l + strongDelta * contrastDirection))
1122
+ };
1123
+ const weak = {
1124
+ ...base,
1125
+ l: Math.max(0, Math.min(1, base.l - weakDelta * contrastDirection))
1126
+ };
1127
+ return { strong, weak };
1128
+ }
1129
+ function constrainAccentVariantVsSurface(themeType, variant, foreground, contrastTarget, skipSurfaceCap) {
1130
+ if (skipSurfaceCap) return variant;
1131
+ const { min: sMin, max: sMax } = surfaceLightnessBand(themeType);
1132
+ let v = { ...variant };
1133
+ if (themeType === "light") {
1134
+ const hi = sMax - ACCENT_VS_SURFACE_L_GAP;
1135
+ if (v.l > hi) v = { ...v, l: hi };
1136
+ } else {
1137
+ const lo = sMin + ACCENT_VS_SURFACE_L_GAP;
1138
+ if (v.l < lo) v = { ...v, l: lo };
1139
+ }
1140
+ v = ensureContrast(v, foreground, contrastTarget);
1141
+ if (themeType === "light") {
1142
+ const hi = sMax - ACCENT_VS_SURFACE_L_GAP;
1143
+ if (v.l > hi) v = { ...v, l: hi };
1144
+ } else {
1145
+ const lo = sMin + ACCENT_VS_SURFACE_L_GAP;
1146
+ if (v.l < lo) v = { ...v, l: lo };
1147
+ }
1148
+ return v;
1149
+ }
1150
+ function hasExplicitBaseLightnessAnchor(themeType, options) {
1151
+ if (!options) return false;
1152
+ const global = extractGlobalThemeAdjustments(
1153
+ options
1154
+ );
1155
+ if (global.baseLightness !== void 0 || global.lightness !== void 0) {
1156
+ return true;
1157
+ }
1158
+ const branch = themeType === "light" ? options.light : options.dark;
1159
+ return branch?.baseLightness !== void 0 || branch?.lightness !== void 0;
1160
+ }
1022
1161
  function expandColorToScale(color, themeType, options) {
1023
1162
  const {
1024
1163
  baselineLValueDark,
1025
1164
  baselineLValueLight,
1026
- minContrastRatio: minContrastRatioOption,
1027
1165
  foregroundLValueDark = FOREGROUND_DARK_L_VALUE,
1028
1166
  foregroundLValueLight = FOREGROUND_LIGHT_L_VALUE,
1029
- foregroundMaxChroma: foregroundMaxChromaOption = FOREGROUND_MAX_CHROMA,
1030
1167
  strongDeltaDark,
1031
1168
  strongDeltaLight,
1032
1169
  weakDeltaDark,
1033
1170
  weakDeltaLight
1034
1171
  } = options ?? {};
1035
- const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
1036
- const foregroundMaxChroma = themeAdjustments?.foregroundMaxChroma ?? foregroundMaxChromaOption;
1037
- const minContrast = resolveContrastRatio(
1038
- themeAdjustments?.minContrastRatio ?? minContrastRatioOption
1172
+ const themeAdjustments = resolveMergedThemeAdjustments(
1173
+ themeType,
1174
+ options ?? {}
1039
1175
  );
1176
+ const foregroundMaxChroma = themeAdjustments.foregroundMaxChroma ?? FOREGROUND_MAX_CHROMA;
1177
+ const minContrast = resolveContrastRatio(themeAdjustments.minContrastRatio);
1040
1178
  const contrastTarget = minContrast + CONTRAST_MARGIN;
1041
1179
  const hasExplicitDeltas = strongDeltaDark !== void 0 || strongDeltaLight !== void 0 || weakDeltaDark !== void 0 || weakDeltaLight !== void 0;
1042
1180
  const themeLightness = resolveThemeLightness(themeType, options);
1043
1181
  const colorOKLCH = convert(color, "oklch");
1044
- const maxChroma = themeType === "light" ? options?.light?.maxChroma : options?.dark?.maxChroma;
1045
- const normalizedColorOKLCH = {
1182
+ const maxChroma = themeAdjustments.maxChroma;
1183
+ const chipOKLCH = {
1046
1184
  ...colorOKLCH,
1047
- l: themeType === "light" ? baselineLValueLight ?? themeLightness : baselineLValueDark ?? themeLightness,
1048
1185
  c: maxChroma !== void 0 ? Math.min(colorOKLCH.c, maxChroma) : colorOKLCH.c
1049
1186
  };
1050
- const candidates = [foregroundLValueLight, foregroundLValueDark].map((l) => ({
1051
- ...normalizedColorOKLCH,
1052
- l,
1053
- c: Math.min(normalizedColorOKLCH.c, foregroundMaxChroma)
1054
- }));
1055
- const [candidateA, candidateB] = themeType === "light" ? candidates : [...candidates].reverse();
1056
- const contrastA = calculateContrast(normalizedColorOKLCH, candidateA);
1057
- const contrastB = calculateContrast(normalizedColorOKLCH, candidateB);
1058
- const [preferred, fallback] = contrastA >= contrastB ? [candidateA, candidateB] : [candidateB, candidateA];
1059
- let foregroundColorOKLCH = calculateContrast(normalizedColorOKLCH, preferred) > minContrast ? preferred : fallback;
1060
- if (calculateContrast(normalizedColorOKLCH, foregroundColorOKLCH) < contrastTarget) {
1187
+ const isSurfaceScale = baselineLValueLight !== void 0 || baselineLValueDark !== void 0;
1188
+ const rawHueShift = themeAdjustments.hueShift ?? 0;
1189
+ let useExactChip = false;
1190
+ if (!isSurfaceScale && !hasExplicitDeltas && rawHueShift === 0 && !hasExplicitBaseLightnessAnchor(themeType, options)) {
1191
+ const range = resolveBaseLightnessClampRange(themeType, options);
1192
+ if (chipOKLCH.l >= range[0] && chipOKLCH.l <= range[1]) {
1193
+ const chipFg = pickAccentForegroundPair(
1194
+ chipOKLCH,
1195
+ themeType,
1196
+ foregroundLValueLight,
1197
+ foregroundLValueDark,
1198
+ foregroundMaxChroma,
1199
+ minContrast
1200
+ ).foreground;
1201
+ if (calculateContrast(chipOKLCH, chipFg) >= contrastTarget) {
1202
+ const chipBoundaryL = findContrastBoundaryLightness(
1203
+ chipOKLCH,
1204
+ chipFg,
1205
+ contrastTarget
1206
+ );
1207
+ const chipDistToBoundary = chipBoundaryL !== null ? Math.abs(chipOKLCH.l - chipBoundaryL) : 0;
1208
+ const chipStrongDelta = Math.min(VARIANT_DELTA, chipDistToBoundary);
1209
+ if (chipStrongDelta >= EXACT_CHIP_MIN_STRONG_DELTA_OKLCH) {
1210
+ const { strong: strongSim, weak: weakSim } = computeStrongWeakWithoutBoundaryShift(
1211
+ chipOKLCH,
1212
+ chipFg,
1213
+ themeType,
1214
+ contrastTarget
1215
+ );
1216
+ const defF = constrainAccentVariantVsSurface(
1217
+ themeType,
1218
+ chipOKLCH,
1219
+ chipFg,
1220
+ contrastTarget,
1221
+ false
1222
+ );
1223
+ const sF = constrainAccentVariantVsSurface(
1224
+ themeType,
1225
+ strongSim,
1226
+ chipFg,
1227
+ contrastTarget,
1228
+ false
1229
+ );
1230
+ const wF = constrainAccentVariantVsSurface(
1231
+ themeType,
1232
+ weakSim,
1233
+ chipFg,
1234
+ contrastTarget,
1235
+ false
1236
+ );
1237
+ useExactChip = oklchBodyClose(defF, chipOKLCH) && calculateContrast(defF, chipFg) >= contrastTarget && calculateContrast(sF, chipFg) >= contrastTarget && calculateContrast(wF, chipFg) >= contrastTarget;
1238
+ }
1239
+ }
1240
+ }
1241
+ }
1242
+ let normalizedColorOKLCH = useExactChip ? { ...chipOKLCH } : {
1243
+ ...colorOKLCH,
1244
+ l: themeType === "light" ? baselineLValueLight ?? themeLightness : baselineLValueDark ?? themeLightness,
1245
+ c: chipOKLCH.c
1246
+ };
1247
+ let { foreground: foregroundColorOKLCH, preferred } = pickAccentForegroundPair(
1248
+ normalizedColorOKLCH,
1249
+ themeType,
1250
+ foregroundLValueLight,
1251
+ foregroundLValueDark,
1252
+ foregroundMaxChroma,
1253
+ minContrast
1254
+ );
1255
+ if (!useExactChip && calculateContrast(normalizedColorOKLCH, foregroundColorOKLCH) < contrastTarget) {
1061
1256
  const direction = preferred.l < normalizedColorOKLCH.l ? 1 : -1;
1062
1257
  let lo = direction === 1 ? normalizedColorOKLCH.l : 0;
1063
1258
  let hi = direction === 1 ? 1 : normalizedColorOKLCH.l;
@@ -1072,7 +1267,10 @@ function expandColorToScale(color, themeType, options) {
1072
1267
  else hi = mid;
1073
1268
  }
1074
1269
  }
1075
- normalizedColorOKLCH.l = (lo + hi) / 2;
1270
+ normalizedColorOKLCH = {
1271
+ ...normalizedColorOKLCH,
1272
+ l: (lo + hi) / 2
1273
+ };
1076
1274
  foregroundColorOKLCH = preferred;
1077
1275
  }
1078
1276
  let strongColorOKLCH;
@@ -1096,13 +1294,16 @@ function expandColorToScale(color, themeType, options) {
1096
1294
  contrastTarget
1097
1295
  );
1098
1296
  let distToBoundary = boundaryL !== null ? Math.abs(normalizedColorOKLCH.l - boundaryL) : 0;
1099
- if (distToBoundary < VARIANT_DELTA) {
1297
+ if (!useExactChip && distToBoundary < VARIANT_DELTA) {
1100
1298
  const shift = Math.min(VARIANT_DELTA - distToBoundary, VARIANT_DELTA / 2);
1101
1299
  const awayFromForeground = foregroundColorOKLCH.l < normalizedColorOKLCH.l ? 1 : -1;
1102
- normalizedColorOKLCH.l = Math.max(
1103
- 0,
1104
- Math.min(1, normalizedColorOKLCH.l + shift * awayFromForeground)
1105
- );
1300
+ normalizedColorOKLCH = {
1301
+ ...normalizedColorOKLCH,
1302
+ l: Math.max(
1303
+ 0,
1304
+ Math.min(1, normalizedColorOKLCH.l + shift * awayFromForeground)
1305
+ )
1306
+ };
1106
1307
  boundaryL = findContrastBoundaryLightness(
1107
1308
  normalizedColorOKLCH,
1108
1309
  foregroundColorOKLCH,
@@ -1148,7 +1349,7 @@ function expandColorToScale(color, themeType, options) {
1148
1349
  )
1149
1350
  };
1150
1351
  }
1151
- const rawHueShift = options?.hueShift ?? 0;
1352
+ const skipSurfaceCap = baselineLValueLight !== void 0;
1152
1353
  if (rawHueShift !== 0) {
1153
1354
  const clamped = clampHueShift(rawHueShift, 2);
1154
1355
  strongColorOKLCH = {
@@ -1170,6 +1371,27 @@ function expandColorToScale(color, themeType, options) {
1170
1371
  contrastTarget
1171
1372
  );
1172
1373
  }
1374
+ normalizedColorOKLCH = constrainAccentVariantVsSurface(
1375
+ themeType,
1376
+ normalizedColorOKLCH,
1377
+ foregroundColorOKLCH,
1378
+ contrastTarget,
1379
+ skipSurfaceCap
1380
+ );
1381
+ strongColorOKLCH = constrainAccentVariantVsSurface(
1382
+ themeType,
1383
+ strongColorOKLCH,
1384
+ foregroundColorOKLCH,
1385
+ contrastTarget,
1386
+ skipSurfaceCap
1387
+ );
1388
+ weakColorOKLCH = constrainAccentVariantVsSurface(
1389
+ themeType,
1390
+ weakColorOKLCH,
1391
+ foregroundColorOKLCH,
1392
+ contrastTarget,
1393
+ skipSurfaceCap
1394
+ );
1173
1395
  return {
1174
1396
  DEFAULT: { ...normalizedColorOKLCH },
1175
1397
  strong: { ...strongColorOKLCH },
@@ -1177,14 +1399,41 @@ function expandColorToScale(color, themeType, options) {
1177
1399
  foreground: { ...foregroundColorOKLCH }
1178
1400
  };
1179
1401
  }
1180
- var LIGHT_THEME_LIGHTNESS_RANGE = [0.4, 0.99];
1181
- var DARK_THEME_LIGHTNESS_RANGE = [0.2, 0.8];
1182
1402
  var warnedLegacyLightness = false;
1183
- function resolveThemeLightness(themeType, options) {
1403
+ function normalizeBaseLightnessRange(custom) {
1404
+ let lo = Number(custom[0]);
1405
+ let hi = Number(custom[1]);
1406
+ if (!Number.isFinite(lo) || !Number.isFinite(hi)) return void 0;
1407
+ if (lo > hi) [lo, hi] = [hi, lo];
1408
+ lo = Math.max(0, Math.min(1, lo));
1409
+ hi = Math.max(0, Math.min(1, hi));
1410
+ if (lo > hi) return void 0;
1411
+ return [lo, hi];
1412
+ }
1413
+ function resolveBaseLightnessClampRange(themeType, options) {
1184
1414
  const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
1185
- const range = themeType === "light" ? LIGHT_THEME_LIGHTNESS_RANGE : DARK_THEME_LIGHTNESS_RANGE;
1186
- const value = themeAdjustments?.baseLightness ?? themeAdjustments?.lightness;
1187
- if (themeAdjustments?.baseLightness === void 0 && themeAdjustments?.lightness !== void 0 && !warnedLegacyLightness && typeof console !== "undefined") {
1415
+ const fallback = themeType === "light" ? LIGHT_THEME_LIGHTNESS_RANGE : DARK_THEME_LIGHTNESS_RANGE;
1416
+ const fromTheme = themeAdjustments?.baseLightnessRange;
1417
+ if (fromTheme && fromTheme.length === 2) {
1418
+ const t = normalizeBaseLightnessRange(fromTheme);
1419
+ if (t) return t;
1420
+ }
1421
+ const global = options?.baseLightnessRange;
1422
+ if (global && global.length === 2) {
1423
+ const g = normalizeBaseLightnessRange(global);
1424
+ if (g) return g;
1425
+ }
1426
+ return fallback;
1427
+ }
1428
+ function resolveThemeLightness(themeType, options) {
1429
+ const branch = themeType === "light" ? options?.light : options?.dark;
1430
+ const themeAdjustments = resolveMergedThemeAdjustments(
1431
+ themeType,
1432
+ options ?? {}
1433
+ );
1434
+ const range = resolveBaseLightnessClampRange(themeType, options);
1435
+ const value = themeAdjustments.baseLightness ?? themeAdjustments.lightness;
1436
+ if (branch?.baseLightness === void 0 && branch?.lightness !== void 0 && !warnedLegacyLightness && typeof console !== "undefined") {
1188
1437
  warnedLegacyLightness = true;
1189
1438
  console.warn(
1190
1439
  "[hextimator] `style({ light/dark: { lightness } })` is deprecated. Rename to `baseLightness` to disambiguate from the relative `lightness` offset used by `addToken({ from, lightness })`. Will be removed in a future release."
@@ -1193,6 +1442,9 @@ function resolveThemeLightness(themeType, options) {
1193
1442
  if (value !== void 0) {
1194
1443
  return Math.min(Math.max(value, range[0]), range[1]);
1195
1444
  }
1445
+ if (options?.inputLightness !== void 0) {
1446
+ return Math.min(Math.max(options.inputLightness, range[0]), range[1]);
1447
+ }
1196
1448
  return themeType === "light" ? DEFAULT_LIGHT_THEME_LIGHTNESS : DEFAULT_DARK_THEME_LIGHTNESS;
1197
1449
  }
1198
1450
  function findContrastBoundaryLightness(defaultColor, foregroundColor, targetContrast = 7) {
@@ -1258,15 +1510,20 @@ function generateAccent(accent, themeType, options) {
1258
1510
  const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
1259
1511
  if (invertSurfaceAndAccent) {
1260
1512
  const accentOklch = convert(accent, "oklch");
1261
- const surfaceHueShift = options?.surfaceHueShift ?? 0;
1262
- let surfaceOklch = options?.surfaceColor ? convert(parse(options.surfaceColor), "oklch") : convert(accent, "oklch");
1263
- if (surfaceHueShift !== 0 && !options?.surfaceColor) {
1513
+ const themeAdjustments = resolveMergedThemeAdjustments(
1514
+ "dark",
1515
+ options ?? {}
1516
+ );
1517
+ const surfaceHueShift = themeAdjustments.surfaceHueShift ?? 0;
1518
+ const effectiveSurface = themeAdjustments.surfaceColor;
1519
+ let surfaceOklch = effectiveSurface ? convert(parse(effectiveSurface), "oklch") : convert(accent, "oklch");
1520
+ if (surfaceHueShift !== 0 && !effectiveSurface) {
1264
1521
  surfaceOklch = {
1265
1522
  ...surfaceOklch,
1266
1523
  h: wrapHue(accentOklch.h + surfaceHueShift)
1267
1524
  };
1268
1525
  }
1269
- const maxChroma = options?.dark?.maxChroma;
1526
+ const maxChroma = themeAdjustments.maxChroma;
1270
1527
  const invertedAccent = {
1271
1528
  ...surfaceOklch,
1272
1529
  c: maxChroma !== void 0 ? Math.min(accentOklch.c, maxChroma) : accentOklch.c
@@ -1279,53 +1536,52 @@ function generateAccent(accent, themeType, options) {
1279
1536
  // src/generate/generateSemanticColors.ts
1280
1537
  var POSITIVE_RANGE = [120, 160];
1281
1538
  var NEGATIVE_RANGE = [5, 30];
1282
- var WARNING_RANGE = [45, 70];
1539
+ var CAUTION_RANGE = [45, 70];
1283
1540
  function generateSemanticColors(color, themeType, options) {
1541
+ const themeAdjustments = resolveMergedThemeAdjustments(
1542
+ themeType,
1543
+ options ?? {}
1544
+ );
1545
+ const semanticColors = {
1546
+ positive: themeAdjustments.semanticColors?.positive,
1547
+ negative: themeAdjustments.semanticColors?.negative,
1548
+ caution: themeAdjustments.semanticColors?.caution
1549
+ };
1550
+ const semanticColorRanges = {
1551
+ positive: themeAdjustments.semanticColorRanges?.positive ?? POSITIVE_RANGE,
1552
+ negative: themeAdjustments.semanticColorRanges?.negative ?? NEGATIVE_RANGE,
1553
+ caution: themeAdjustments.semanticColorRanges?.caution ?? CAUTION_RANGE
1554
+ };
1284
1555
  const positiveBaseColor = parse(
1285
- options?.semanticColors?.positive ?? _determineBaseColorFromRange(
1286
- color,
1287
- options?.semanticColorRanges?.positive ?? POSITIVE_RANGE,
1288
- { includeInputAsCandidate: true }
1289
- )
1556
+ semanticColors.positive ?? _determineBaseColorFromRange(color, semanticColorRanges.positive, {
1557
+ includeInputAsCandidate: true
1558
+ })
1290
1559
  );
1291
1560
  const negativeBaseColor = parse(
1292
- options?.semanticColors?.negative ?? _determineBaseColorFromRange(
1293
- color,
1294
- options?.semanticColorRanges?.negative ?? NEGATIVE_RANGE
1295
- )
1561
+ semanticColors.negative ?? _determineBaseColorFromRange(color, semanticColorRanges.negative)
1296
1562
  );
1297
- const warningBaseColor = parse(
1298
- options?.semanticColors?.warning ?? _determineBaseColorFromRange(
1299
- color,
1300
- options?.semanticColorRanges?.warning ?? WARNING_RANGE
1301
- )
1563
+ const cautionBaseColor = parse(
1564
+ semanticColors.caution ?? _determineBaseColorFromRange(color, semanticColorRanges.caution)
1302
1565
  );
1303
- const scaleOptions = {
1304
- light: options?.light,
1305
- dark: options?.dark,
1306
- minContrastRatio: options?.minContrastRatio,
1307
- hueShift: options?.hueShift,
1308
- foregroundMaxChroma: options?.foregroundMaxChroma
1309
- };
1310
1566
  const positiveColorScale = expandColorToScale(
1311
1567
  positiveBaseColor,
1312
1568
  themeType,
1313
- scaleOptions
1569
+ options
1314
1570
  );
1315
1571
  const negativeColorScale = expandColorToScale(
1316
1572
  negativeBaseColor,
1317
1573
  themeType,
1318
- scaleOptions
1574
+ options
1319
1575
  );
1320
- const warningColorScale = expandColorToScale(
1321
- warningBaseColor,
1576
+ const cautionColorScale = expandColorToScale(
1577
+ cautionBaseColor,
1322
1578
  themeType,
1323
- scaleOptions
1579
+ options
1324
1580
  );
1325
1581
  return {
1326
1582
  positive: positiveColorScale,
1327
1583
  negative: negativeColorScale,
1328
- warning: warningColorScale
1584
+ caution: cautionColorScale
1329
1585
  };
1330
1586
  }
1331
1587
  function _determineBaseColorFromRange(color, range, options) {
@@ -1378,55 +1634,54 @@ function _getSplitComplementaryColors(color) {
1378
1634
  }
1379
1635
 
1380
1636
  // src/generate/generateSurface.ts
1381
- var BASELINE_DARK_L_VALUE = 0.2;
1382
- var BASELINE_LIGHT_L_VALUE = 0.97;
1383
1637
  var BASELINE_MAX_CHROMA = 0.01;
1384
- var STRONG_DELTA_DARK = -0.1;
1385
- var STRONG_DELTA_LIGHT = 0.02;
1386
- var WEAK_DELTA_DARK = 0.1;
1387
- var WEAK_DELTA_LIGHT = -0.03;
1388
1638
  function generateSurface(color, themeType, options) {
1389
1639
  const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
1390
- const preferredSurfaceColorInput = invertSurfaceAndAccent ? color ?? options?.surfaceColor : options?.surfaceColor ?? color;
1391
- const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
1392
- const surfaceMaxChroma = themeAdjustments?.surfaceMaxChroma ?? options?.surfaceMaxChroma ?? BASELINE_MAX_CHROMA;
1640
+ const themeAdjustments = resolveMergedThemeAdjustments(
1641
+ themeType,
1642
+ options ?? {}
1643
+ );
1644
+ const effectiveSurfaceColor = themeAdjustments.surfaceColor;
1645
+ const preferredSurfaceColorInput = invertSurfaceAndAccent ? color ?? effectiveSurfaceColor : effectiveSurfaceColor ?? color;
1646
+ const surfaceMaxChroma = themeAdjustments.surfaceMaxChroma ?? BASELINE_MAX_CHROMA;
1393
1647
  const preferredSurfaceColor = convert(
1394
1648
  parse(preferredSurfaceColorInput),
1395
1649
  "oklch"
1396
1650
  );
1397
1651
  let surfaceHue = preferredSurfaceColor.h;
1398
1652
  const surfaceChroma = Math.min(preferredSurfaceColor.c, surfaceMaxChroma);
1399
- const surfaceHueShift = options?.surfaceHueShift ?? 0;
1400
- if (surfaceHueShift !== 0 && !options?.surfaceColor && !invertSurfaceAndAccent) {
1653
+ const surfaceHueShift = themeAdjustments.surfaceHueShift ?? 0;
1654
+ if (surfaceHueShift !== 0 && !effectiveSurfaceColor && !invertSurfaceAndAccent) {
1401
1655
  surfaceHue = wrapHue(convert(color, "oklch").h + surfaceHueShift);
1402
1656
  }
1657
+ const s = themeType === "light" ? SURFACE_SCALE.light : SURFACE_SCALE.dark;
1403
1658
  const normalizedPreferredSurfaceColor = {
1404
1659
  ...preferredSurfaceColor,
1405
1660
  h: surfaceHue,
1406
1661
  c: surfaceChroma,
1407
- l: themeType === "light" ? BASELINE_LIGHT_L_VALUE : BASELINE_DARK_L_VALUE
1662
+ l: s.L
1408
1663
  };
1409
1664
  return expandColorToScale(normalizedPreferredSurfaceColor, themeType, {
1410
- baselineLValueDark: BASELINE_DARK_L_VALUE,
1411
- baselineLValueLight: BASELINE_LIGHT_L_VALUE,
1412
- strongDeltaDark: STRONG_DELTA_DARK,
1413
- strongDeltaLight: STRONG_DELTA_LIGHT,
1414
- weakDeltaDark: WEAK_DELTA_DARK,
1415
- weakDeltaLight: WEAK_DELTA_LIGHT,
1416
- minContrastRatio: options?.minContrastRatio,
1417
- hueShift: options?.hueShift,
1418
- foregroundMaxChroma: options?.foregroundMaxChroma,
1419
- light: options?.light,
1420
- dark: options?.dark
1665
+ ...options ?? {},
1666
+ baselineLValueLight: SURFACE_SCALE.light.L,
1667
+ baselineLValueDark: SURFACE_SCALE.dark.L,
1668
+ strongDeltaLight: SURFACE_SCALE.light.strong,
1669
+ strongDeltaDark: SURFACE_SCALE.dark.strong,
1670
+ weakDeltaLight: SURFACE_SCALE.light.weak,
1671
+ weakDeltaDark: SURFACE_SCALE.dark.weak
1421
1672
  });
1422
1673
  }
1423
1674
 
1424
1675
  // src/generate/generate.ts
1425
1676
  function generate(color, themeType, options) {
1677
+ const resolvedOptions = {
1678
+ ...options ?? {},
1679
+ inputLightness: convert(color, "oklch").l
1680
+ };
1426
1681
  return {
1427
- surface: generateSurface(color, themeType, options),
1428
- accent: generateAccent(color, themeType, options),
1429
- ...generateSemanticColors(color, themeType, options)
1682
+ surface: generateSurface(color, themeType, resolvedOptions),
1683
+ accent: generateAccent(color, themeType, resolvedOptions),
1684
+ ...generateSemanticColors(color, themeType, resolvedOptions)
1430
1685
  };
1431
1686
  }
1432
1687
 
@@ -2180,7 +2435,8 @@ var mui = {
2180
2435
  roleNames: {
2181
2436
  accent: "primary",
2182
2437
  negative: "error",
2183
- positive: "success"
2438
+ positive: "success",
2439
+ caution: "warning"
2184
2440
  },
2185
2441
  variantNames: {
2186
2442
  DEFAULT: "main",
@@ -2260,7 +2516,7 @@ var shadcn = {
2260
2516
  variantNames: {
2261
2517
  foreground: "foreground"
2262
2518
  },
2263
- excludeRoles: ["warning"],
2519
+ excludeRoles: ["caution"],
2264
2520
  excludeVariants: ["strong", "weak"]
2265
2521
  }
2266
2522
  };
@@ -2350,17 +2606,20 @@ Style options:
2350
2606
  --hue-shift <deg> Per-variant hue shift in degrees
2351
2607
  --surface-max-chroma <n> Max chroma for surface colors (default: 0.01)
2352
2608
  --fg-max-chroma <n> Max chroma for foreground colors (default: 0.01)
2353
- --light-lightness <n> Light theme lightness 0-1 (default: 0.7)
2609
+ --light-lightness <n> Light theme lightness 0-1 (default: from input OKLCH L)
2610
+ --light-base-lightness-range <min,max> Clamp input/base L for light theme (default: 0.4,0.9)
2354
2611
  --light-max-chroma <n> Light theme max chroma
2355
- --dark-lightness <n> Dark theme lightness 0-1 (default: 0.6)
2612
+ --dark-lightness <n> Dark theme lightness 0-1 (default: from input OKLCH L)
2613
+ --dark-base-lightness-range <min,max> Clamp input/base L for dark theme (default: 0.2,0.8)
2356
2614
  --dark-max-chroma <n> Dark theme max chroma
2615
+ --base-lightness-range <min,max> Default clamp for both themes (overridden by per-theme flags)
2357
2616
  --min-contrast <value> AAA | AA | <number> (default: AAA)
2358
2617
  --invert-dark Swap surface/accent hues in dark mode (requires --surface-color)
2359
2618
 
2360
2619
  Semantic colors:
2361
2620
  --positive <color> Override positive/success color (default: auto green)
2362
2621
  --negative <color> Override negative/error color (default: auto red)
2363
- --warning <color> Override warning color (default: auto amber)
2622
+ --caution <color> Override caution color (default: auto amber)
2364
2623
 
2365
2624
  CVD (color vision deficiency):
2366
2625
  --simulate <type> Simulate CVD: protanopia | deuteranopia | tritanopia | achromatopsia
@@ -2389,6 +2648,14 @@ Examples:
2389
2648
  hextimator '#ff6600' --simulate deuteranopia
2390
2649
  hextimator '#ff6600' --adapt deuteranopia --cvd-severity 0.8
2391
2650
  `.trim();
2651
+ function parseBaseLightnessRange(raw) {
2652
+ const parts = raw.trim().split(/\s*,\s*/);
2653
+ if (parts.length !== 2) return void 0;
2654
+ const lo = Number(parts[0]);
2655
+ const hi = Number(parts[1]);
2656
+ if (!Number.isFinite(lo) || !Number.isFinite(hi)) return void 0;
2657
+ return [lo, hi];
2658
+ }
2392
2659
  function run() {
2393
2660
  const { values, positionals } = parseArgs({
2394
2661
  allowPositionals: true,
@@ -2409,14 +2676,17 @@ function run() {
2409
2676
  "surface-max-chroma": { type: "string" },
2410
2677
  "fg-max-chroma": { type: "string" },
2411
2678
  "light-lightness": { type: "string" },
2679
+ "light-base-lightness-range": { type: "string" },
2412
2680
  "light-max-chroma": { type: "string" },
2413
2681
  "dark-lightness": { type: "string" },
2682
+ "dark-base-lightness-range": { type: "string" },
2414
2683
  "dark-max-chroma": { type: "string" },
2684
+ "base-lightness-range": { type: "string" },
2415
2685
  "min-contrast": { type: "string" },
2416
2686
  "invert-dark": { type: "boolean" },
2417
2687
  positive: { type: "string" },
2418
2688
  negative: { type: "string" },
2419
- warning: { type: "string" },
2689
+ caution: { type: "string" },
2420
2690
  simulate: { type: "string" },
2421
2691
  adapt: { type: "string" },
2422
2692
  "cvd-severity": { type: "string" },
@@ -2450,19 +2720,33 @@ function run() {
2450
2720
  styleOptions.surfaceMaxChroma = Number(values["surface-max-chroma"]);
2451
2721
  if (values["fg-max-chroma"])
2452
2722
  styleOptions.foregroundMaxChroma = Number(values["fg-max-chroma"]);
2453
- if (values["light-lightness"] || values["light-max-chroma"]) {
2723
+ if (values["light-lightness"] || values["light-max-chroma"] || values["light-base-lightness-range"]) {
2454
2724
  styleOptions.light = {};
2455
2725
  if (values["light-lightness"])
2456
2726
  styleOptions.light.baseLightness = Number(values["light-lightness"]);
2457
2727
  if (values["light-max-chroma"])
2458
2728
  styleOptions.light.maxChroma = Number(values["light-max-chroma"]);
2729
+ if (values["light-base-lightness-range"]) {
2730
+ const pair = parseBaseLightnessRange(
2731
+ values["light-base-lightness-range"]
2732
+ );
2733
+ if (pair) styleOptions.light.baseLightnessRange = pair;
2734
+ }
2459
2735
  }
2460
- if (values["dark-lightness"] || values["dark-max-chroma"]) {
2736
+ if (values["dark-lightness"] || values["dark-max-chroma"] || values["dark-base-lightness-range"]) {
2461
2737
  styleOptions.dark = {};
2462
2738
  if (values["dark-lightness"])
2463
2739
  styleOptions.dark.baseLightness = Number(values["dark-lightness"]);
2464
2740
  if (values["dark-max-chroma"])
2465
2741
  styleOptions.dark.maxChroma = Number(values["dark-max-chroma"]);
2742
+ if (values["dark-base-lightness-range"]) {
2743
+ const pair = parseBaseLightnessRange(values["dark-base-lightness-range"]);
2744
+ if (pair) styleOptions.dark.baseLightnessRange = pair;
2745
+ }
2746
+ }
2747
+ if (values["base-lightness-range"]) {
2748
+ const pair = parseBaseLightnessRange(values["base-lightness-range"]);
2749
+ if (pair) styleOptions.baseLightnessRange = pair;
2466
2750
  }
2467
2751
  if (values["min-contrast"]) {
2468
2752
  const mc = values["min-contrast"];
@@ -2478,7 +2762,7 @@ function run() {
2478
2762
  const semanticColors = {};
2479
2763
  if (values.positive) semanticColors.positive = values.positive;
2480
2764
  if (values.negative) semanticColors.negative = values.negative;
2481
- if (values.warning) semanticColors.warning = values.warning;
2765
+ if (values.caution) semanticColors.caution = values.caution;
2482
2766
  if (Object.keys(semanticColors).length > 0) {
2483
2767
  styleOptions.semanticColors = semanticColors;
2484
2768
  }