hextimator 0.8.0 → 0.10.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 +23 -2
- package/README.md +3 -3
- package/dist/{HextimatePaletteBuilder-CNjOKwbY.d.ts → HextimatePaletteBuilder-CPteKnVL.d.ts} +42 -105
- package/dist/{chunk-NTF3K3U3.js → chunk-TEZ2I4CJ.js} +3 -2
- package/dist/{chunk-KFH2N7CF.js → chunk-ZUOHHUCY.js} +337 -93
- package/dist/cli.js +375 -102
- package/dist/{index-kecVj5cB.d.ts → index-doqaWzrz.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +2 -2
- package/fallback.css +48 -48
- package/llms.txt +16 -9
- package/package.json +1 -1
- package/tailwind-inverted.css +4 -4
- package/tailwind.css +4 -4
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,180 @@ 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
|
+
}
|
|
1022
1150
|
function expandColorToScale(color, themeType, options) {
|
|
1023
1151
|
const {
|
|
1024
1152
|
baselineLValueDark,
|
|
1025
1153
|
baselineLValueLight,
|
|
1026
|
-
minContrastRatio: minContrastRatioOption,
|
|
1027
1154
|
foregroundLValueDark = FOREGROUND_DARK_L_VALUE,
|
|
1028
1155
|
foregroundLValueLight = FOREGROUND_LIGHT_L_VALUE,
|
|
1029
|
-
foregroundMaxChroma: foregroundMaxChromaOption = FOREGROUND_MAX_CHROMA,
|
|
1030
1156
|
strongDeltaDark,
|
|
1031
1157
|
strongDeltaLight,
|
|
1032
1158
|
weakDeltaDark,
|
|
1033
1159
|
weakDeltaLight
|
|
1034
1160
|
} = options ?? {};
|
|
1035
|
-
const themeAdjustments =
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
themeAdjustments?.minContrastRatio ?? minContrastRatioOption
|
|
1161
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1162
|
+
themeType,
|
|
1163
|
+
options ?? {}
|
|
1039
1164
|
);
|
|
1165
|
+
const foregroundMaxChroma = themeAdjustments.foregroundMaxChroma ?? FOREGROUND_MAX_CHROMA;
|
|
1166
|
+
const minContrast = resolveContrastRatio(themeAdjustments.minContrastRatio);
|
|
1040
1167
|
const contrastTarget = minContrast + CONTRAST_MARGIN;
|
|
1041
1168
|
const hasExplicitDeltas = strongDeltaDark !== void 0 || strongDeltaLight !== void 0 || weakDeltaDark !== void 0 || weakDeltaLight !== void 0;
|
|
1042
1169
|
const themeLightness = resolveThemeLightness(themeType, options);
|
|
1043
1170
|
const colorOKLCH = convert(color, "oklch");
|
|
1044
|
-
const maxChroma =
|
|
1045
|
-
const
|
|
1171
|
+
const maxChroma = themeAdjustments.maxChroma;
|
|
1172
|
+
const chipOKLCH = {
|
|
1046
1173
|
...colorOKLCH,
|
|
1047
|
-
l: themeType === "light" ? baselineLValueLight ?? themeLightness : baselineLValueDark ?? themeLightness,
|
|
1048
1174
|
c: maxChroma !== void 0 ? Math.min(colorOKLCH.c, maxChroma) : colorOKLCH.c
|
|
1049
1175
|
};
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1176
|
+
const isSurfaceScale = baselineLValueLight !== void 0 || baselineLValueDark !== void 0;
|
|
1177
|
+
const rawHueShift = themeAdjustments.hueShift ?? 0;
|
|
1178
|
+
let useExactChip = false;
|
|
1179
|
+
if (!isSurfaceScale && !hasExplicitDeltas && rawHueShift === 0) {
|
|
1180
|
+
const range = resolveBaseLightnessClampRange(themeType, options);
|
|
1181
|
+
if (chipOKLCH.l >= range[0] && chipOKLCH.l <= range[1]) {
|
|
1182
|
+
const chipFg = pickAccentForegroundPair(
|
|
1183
|
+
chipOKLCH,
|
|
1184
|
+
themeType,
|
|
1185
|
+
foregroundLValueLight,
|
|
1186
|
+
foregroundLValueDark,
|
|
1187
|
+
foregroundMaxChroma,
|
|
1188
|
+
minContrast
|
|
1189
|
+
).foreground;
|
|
1190
|
+
if (calculateContrast(chipOKLCH, chipFg) >= contrastTarget) {
|
|
1191
|
+
const chipBoundaryL = findContrastBoundaryLightness(
|
|
1192
|
+
chipOKLCH,
|
|
1193
|
+
chipFg,
|
|
1194
|
+
contrastTarget
|
|
1195
|
+
);
|
|
1196
|
+
const chipDistToBoundary = chipBoundaryL !== null ? Math.abs(chipOKLCH.l - chipBoundaryL) : 0;
|
|
1197
|
+
const chipStrongDelta = Math.min(VARIANT_DELTA, chipDistToBoundary);
|
|
1198
|
+
if (chipStrongDelta >= EXACT_CHIP_MIN_STRONG_DELTA_OKLCH) {
|
|
1199
|
+
const { strong: strongSim, weak: weakSim } = computeStrongWeakWithoutBoundaryShift(
|
|
1200
|
+
chipOKLCH,
|
|
1201
|
+
chipFg,
|
|
1202
|
+
themeType,
|
|
1203
|
+
contrastTarget
|
|
1204
|
+
);
|
|
1205
|
+
const defF = constrainAccentVariantVsSurface(
|
|
1206
|
+
themeType,
|
|
1207
|
+
chipOKLCH,
|
|
1208
|
+
chipFg,
|
|
1209
|
+
contrastTarget,
|
|
1210
|
+
false
|
|
1211
|
+
);
|
|
1212
|
+
const sF = constrainAccentVariantVsSurface(
|
|
1213
|
+
themeType,
|
|
1214
|
+
strongSim,
|
|
1215
|
+
chipFg,
|
|
1216
|
+
contrastTarget,
|
|
1217
|
+
false
|
|
1218
|
+
);
|
|
1219
|
+
const wF = constrainAccentVariantVsSurface(
|
|
1220
|
+
themeType,
|
|
1221
|
+
weakSim,
|
|
1222
|
+
chipFg,
|
|
1223
|
+
contrastTarget,
|
|
1224
|
+
false
|
|
1225
|
+
);
|
|
1226
|
+
useExactChip = oklchBodyClose(defF, chipOKLCH) && calculateContrast(defF, chipFg) >= contrastTarget && calculateContrast(sF, chipFg) >= contrastTarget && calculateContrast(wF, chipFg) >= contrastTarget;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
let normalizedColorOKLCH = useExactChip ? { ...chipOKLCH } : {
|
|
1232
|
+
...colorOKLCH,
|
|
1233
|
+
l: themeType === "light" ? baselineLValueLight ?? themeLightness : baselineLValueDark ?? themeLightness,
|
|
1234
|
+
c: chipOKLCH.c
|
|
1235
|
+
};
|
|
1236
|
+
let { foreground: foregroundColorOKLCH, preferred } = pickAccentForegroundPair(
|
|
1237
|
+
normalizedColorOKLCH,
|
|
1238
|
+
themeType,
|
|
1239
|
+
foregroundLValueLight,
|
|
1240
|
+
foregroundLValueDark,
|
|
1241
|
+
foregroundMaxChroma,
|
|
1242
|
+
minContrast
|
|
1243
|
+
);
|
|
1244
|
+
if (!useExactChip && calculateContrast(normalizedColorOKLCH, foregroundColorOKLCH) < contrastTarget) {
|
|
1061
1245
|
const direction = preferred.l < normalizedColorOKLCH.l ? 1 : -1;
|
|
1062
1246
|
let lo = direction === 1 ? normalizedColorOKLCH.l : 0;
|
|
1063
1247
|
let hi = direction === 1 ? 1 : normalizedColorOKLCH.l;
|
|
@@ -1072,7 +1256,10 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1072
1256
|
else hi = mid;
|
|
1073
1257
|
}
|
|
1074
1258
|
}
|
|
1075
|
-
normalizedColorOKLCH
|
|
1259
|
+
normalizedColorOKLCH = {
|
|
1260
|
+
...normalizedColorOKLCH,
|
|
1261
|
+
l: (lo + hi) / 2
|
|
1262
|
+
};
|
|
1076
1263
|
foregroundColorOKLCH = preferred;
|
|
1077
1264
|
}
|
|
1078
1265
|
let strongColorOKLCH;
|
|
@@ -1096,13 +1283,16 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1096
1283
|
contrastTarget
|
|
1097
1284
|
);
|
|
1098
1285
|
let distToBoundary = boundaryL !== null ? Math.abs(normalizedColorOKLCH.l - boundaryL) : 0;
|
|
1099
|
-
if (distToBoundary < VARIANT_DELTA) {
|
|
1286
|
+
if (!useExactChip && distToBoundary < VARIANT_DELTA) {
|
|
1100
1287
|
const shift = Math.min(VARIANT_DELTA - distToBoundary, VARIANT_DELTA / 2);
|
|
1101
1288
|
const awayFromForeground = foregroundColorOKLCH.l < normalizedColorOKLCH.l ? 1 : -1;
|
|
1102
|
-
normalizedColorOKLCH
|
|
1103
|
-
|
|
1104
|
-
Math.
|
|
1105
|
-
|
|
1289
|
+
normalizedColorOKLCH = {
|
|
1290
|
+
...normalizedColorOKLCH,
|
|
1291
|
+
l: Math.max(
|
|
1292
|
+
0,
|
|
1293
|
+
Math.min(1, normalizedColorOKLCH.l + shift * awayFromForeground)
|
|
1294
|
+
)
|
|
1295
|
+
};
|
|
1106
1296
|
boundaryL = findContrastBoundaryLightness(
|
|
1107
1297
|
normalizedColorOKLCH,
|
|
1108
1298
|
foregroundColorOKLCH,
|
|
@@ -1148,7 +1338,7 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1148
1338
|
)
|
|
1149
1339
|
};
|
|
1150
1340
|
}
|
|
1151
|
-
const
|
|
1341
|
+
const skipSurfaceCap = baselineLValueLight !== void 0;
|
|
1152
1342
|
if (rawHueShift !== 0) {
|
|
1153
1343
|
const clamped = clampHueShift(rawHueShift, 2);
|
|
1154
1344
|
strongColorOKLCH = {
|
|
@@ -1170,6 +1360,27 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1170
1360
|
contrastTarget
|
|
1171
1361
|
);
|
|
1172
1362
|
}
|
|
1363
|
+
normalizedColorOKLCH = constrainAccentVariantVsSurface(
|
|
1364
|
+
themeType,
|
|
1365
|
+
normalizedColorOKLCH,
|
|
1366
|
+
foregroundColorOKLCH,
|
|
1367
|
+
contrastTarget,
|
|
1368
|
+
skipSurfaceCap
|
|
1369
|
+
);
|
|
1370
|
+
strongColorOKLCH = constrainAccentVariantVsSurface(
|
|
1371
|
+
themeType,
|
|
1372
|
+
strongColorOKLCH,
|
|
1373
|
+
foregroundColorOKLCH,
|
|
1374
|
+
contrastTarget,
|
|
1375
|
+
skipSurfaceCap
|
|
1376
|
+
);
|
|
1377
|
+
weakColorOKLCH = constrainAccentVariantVsSurface(
|
|
1378
|
+
themeType,
|
|
1379
|
+
weakColorOKLCH,
|
|
1380
|
+
foregroundColorOKLCH,
|
|
1381
|
+
contrastTarget,
|
|
1382
|
+
skipSurfaceCap
|
|
1383
|
+
);
|
|
1173
1384
|
return {
|
|
1174
1385
|
DEFAULT: { ...normalizedColorOKLCH },
|
|
1175
1386
|
strong: { ...strongColorOKLCH },
|
|
@@ -1177,14 +1388,41 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1177
1388
|
foreground: { ...foregroundColorOKLCH }
|
|
1178
1389
|
};
|
|
1179
1390
|
}
|
|
1180
|
-
var LIGHT_THEME_LIGHTNESS_RANGE = [0.4, 0.99];
|
|
1181
|
-
var DARK_THEME_LIGHTNESS_RANGE = [0.2, 0.8];
|
|
1182
1391
|
var warnedLegacyLightness = false;
|
|
1183
|
-
function
|
|
1392
|
+
function normalizeBaseLightnessRange(custom) {
|
|
1393
|
+
let lo = Number(custom[0]);
|
|
1394
|
+
let hi = Number(custom[1]);
|
|
1395
|
+
if (!Number.isFinite(lo) || !Number.isFinite(hi)) return void 0;
|
|
1396
|
+
if (lo > hi) [lo, hi] = [hi, lo];
|
|
1397
|
+
lo = Math.max(0, Math.min(1, lo));
|
|
1398
|
+
hi = Math.max(0, Math.min(1, hi));
|
|
1399
|
+
if (lo > hi) return void 0;
|
|
1400
|
+
return [lo, hi];
|
|
1401
|
+
}
|
|
1402
|
+
function resolveBaseLightnessClampRange(themeType, options) {
|
|
1184
1403
|
const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
|
|
1185
|
-
const
|
|
1186
|
-
const
|
|
1187
|
-
if (
|
|
1404
|
+
const fallback = themeType === "light" ? LIGHT_THEME_LIGHTNESS_RANGE : DARK_THEME_LIGHTNESS_RANGE;
|
|
1405
|
+
const fromTheme = themeAdjustments?.baseLightnessRange;
|
|
1406
|
+
if (fromTheme && fromTheme.length === 2) {
|
|
1407
|
+
const t = normalizeBaseLightnessRange(fromTheme);
|
|
1408
|
+
if (t) return t;
|
|
1409
|
+
}
|
|
1410
|
+
const global = options?.baseLightnessRange;
|
|
1411
|
+
if (global && global.length === 2) {
|
|
1412
|
+
const g = normalizeBaseLightnessRange(global);
|
|
1413
|
+
if (g) return g;
|
|
1414
|
+
}
|
|
1415
|
+
return fallback;
|
|
1416
|
+
}
|
|
1417
|
+
function resolveThemeLightness(themeType, options) {
|
|
1418
|
+
const branch = themeType === "light" ? options?.light : options?.dark;
|
|
1419
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1420
|
+
themeType,
|
|
1421
|
+
options ?? {}
|
|
1422
|
+
);
|
|
1423
|
+
const range = resolveBaseLightnessClampRange(themeType, options);
|
|
1424
|
+
const value = themeAdjustments.baseLightness ?? themeAdjustments.lightness;
|
|
1425
|
+
if (branch?.baseLightness === void 0 && branch?.lightness !== void 0 && !warnedLegacyLightness && typeof console !== "undefined") {
|
|
1188
1426
|
warnedLegacyLightness = true;
|
|
1189
1427
|
console.warn(
|
|
1190
1428
|
"[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 +1431,9 @@ function resolveThemeLightness(themeType, options) {
|
|
|
1193
1431
|
if (value !== void 0) {
|
|
1194
1432
|
return Math.min(Math.max(value, range[0]), range[1]);
|
|
1195
1433
|
}
|
|
1434
|
+
if (options?.inputLightness !== void 0) {
|
|
1435
|
+
return Math.min(Math.max(options.inputLightness, range[0]), range[1]);
|
|
1436
|
+
}
|
|
1196
1437
|
return themeType === "light" ? DEFAULT_LIGHT_THEME_LIGHTNESS : DEFAULT_DARK_THEME_LIGHTNESS;
|
|
1197
1438
|
}
|
|
1198
1439
|
function findContrastBoundaryLightness(defaultColor, foregroundColor, targetContrast = 7) {
|
|
@@ -1258,15 +1499,20 @@ function generateAccent(accent, themeType, options) {
|
|
|
1258
1499
|
const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
|
|
1259
1500
|
if (invertSurfaceAndAccent) {
|
|
1260
1501
|
const accentOklch = convert(accent, "oklch");
|
|
1261
|
-
const
|
|
1262
|
-
|
|
1263
|
-
|
|
1502
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1503
|
+
"dark",
|
|
1504
|
+
options ?? {}
|
|
1505
|
+
);
|
|
1506
|
+
const surfaceHueShift = themeAdjustments.surfaceHueShift ?? 0;
|
|
1507
|
+
const effectiveSurface = themeAdjustments.surfaceColor;
|
|
1508
|
+
let surfaceOklch = effectiveSurface ? convert(parse(effectiveSurface), "oklch") : convert(accent, "oklch");
|
|
1509
|
+
if (surfaceHueShift !== 0 && !effectiveSurface) {
|
|
1264
1510
|
surfaceOklch = {
|
|
1265
1511
|
...surfaceOklch,
|
|
1266
1512
|
h: wrapHue(accentOklch.h + surfaceHueShift)
|
|
1267
1513
|
};
|
|
1268
1514
|
}
|
|
1269
|
-
const maxChroma =
|
|
1515
|
+
const maxChroma = themeAdjustments.maxChroma;
|
|
1270
1516
|
const invertedAccent = {
|
|
1271
1517
|
...surfaceOklch,
|
|
1272
1518
|
c: maxChroma !== void 0 ? Math.min(accentOklch.c, maxChroma) : accentOklch.c
|
|
@@ -1277,55 +1523,54 @@ function generateAccent(accent, themeType, options) {
|
|
|
1277
1523
|
}
|
|
1278
1524
|
|
|
1279
1525
|
// src/generate/generateSemanticColors.ts
|
|
1280
|
-
var POSITIVE_RANGE = [
|
|
1281
|
-
var NEGATIVE_RANGE = [5,
|
|
1282
|
-
var
|
|
1526
|
+
var POSITIVE_RANGE = [120, 160];
|
|
1527
|
+
var NEGATIVE_RANGE = [5, 30];
|
|
1528
|
+
var CAUTION_RANGE = [45, 70];
|
|
1283
1529
|
function generateSemanticColors(color, themeType, options) {
|
|
1530
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1531
|
+
themeType,
|
|
1532
|
+
options ?? {}
|
|
1533
|
+
);
|
|
1534
|
+
const semanticColors = {
|
|
1535
|
+
positive: themeAdjustments.semanticColors?.positive,
|
|
1536
|
+
negative: themeAdjustments.semanticColors?.negative,
|
|
1537
|
+
caution: themeAdjustments.semanticColors?.caution
|
|
1538
|
+
};
|
|
1539
|
+
const semanticColorRanges = {
|
|
1540
|
+
positive: themeAdjustments.semanticColorRanges?.positive ?? POSITIVE_RANGE,
|
|
1541
|
+
negative: themeAdjustments.semanticColorRanges?.negative ?? NEGATIVE_RANGE,
|
|
1542
|
+
caution: themeAdjustments.semanticColorRanges?.caution ?? CAUTION_RANGE
|
|
1543
|
+
};
|
|
1284
1544
|
const positiveBaseColor = parse(
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
{ includeInputAsCandidate: true }
|
|
1289
|
-
)
|
|
1545
|
+
semanticColors.positive ?? _determineBaseColorFromRange(color, semanticColorRanges.positive, {
|
|
1546
|
+
includeInputAsCandidate: true
|
|
1547
|
+
})
|
|
1290
1548
|
);
|
|
1291
1549
|
const negativeBaseColor = parse(
|
|
1292
|
-
|
|
1293
|
-
color,
|
|
1294
|
-
options?.semanticColorRanges?.negative ?? NEGATIVE_RANGE
|
|
1295
|
-
)
|
|
1550
|
+
semanticColors.negative ?? _determineBaseColorFromRange(color, semanticColorRanges.negative)
|
|
1296
1551
|
);
|
|
1297
|
-
const
|
|
1298
|
-
|
|
1299
|
-
color,
|
|
1300
|
-
options?.semanticColorRanges?.warning ?? WARNING_RANGE
|
|
1301
|
-
)
|
|
1552
|
+
const cautionBaseColor = parse(
|
|
1553
|
+
semanticColors.caution ?? _determineBaseColorFromRange(color, semanticColorRanges.caution)
|
|
1302
1554
|
);
|
|
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
1555
|
const positiveColorScale = expandColorToScale(
|
|
1311
1556
|
positiveBaseColor,
|
|
1312
1557
|
themeType,
|
|
1313
|
-
|
|
1558
|
+
options
|
|
1314
1559
|
);
|
|
1315
1560
|
const negativeColorScale = expandColorToScale(
|
|
1316
1561
|
negativeBaseColor,
|
|
1317
1562
|
themeType,
|
|
1318
|
-
|
|
1563
|
+
options
|
|
1319
1564
|
);
|
|
1320
|
-
const
|
|
1321
|
-
|
|
1565
|
+
const cautionColorScale = expandColorToScale(
|
|
1566
|
+
cautionBaseColor,
|
|
1322
1567
|
themeType,
|
|
1323
|
-
|
|
1568
|
+
options
|
|
1324
1569
|
);
|
|
1325
1570
|
return {
|
|
1326
1571
|
positive: positiveColorScale,
|
|
1327
1572
|
negative: negativeColorScale,
|
|
1328
|
-
|
|
1573
|
+
caution: cautionColorScale
|
|
1329
1574
|
};
|
|
1330
1575
|
}
|
|
1331
1576
|
function _determineBaseColorFromRange(color, range, options) {
|
|
@@ -1378,55 +1623,54 @@ function _getSplitComplementaryColors(color) {
|
|
|
1378
1623
|
}
|
|
1379
1624
|
|
|
1380
1625
|
// src/generate/generateSurface.ts
|
|
1381
|
-
var BASELINE_DARK_L_VALUE = 0.2;
|
|
1382
|
-
var BASELINE_LIGHT_L_VALUE = 0.97;
|
|
1383
1626
|
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
1627
|
function generateSurface(color, themeType, options) {
|
|
1389
1628
|
const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1392
|
-
|
|
1629
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1630
|
+
themeType,
|
|
1631
|
+
options ?? {}
|
|
1632
|
+
);
|
|
1633
|
+
const effectiveSurfaceColor = themeAdjustments.surfaceColor;
|
|
1634
|
+
const preferredSurfaceColorInput = invertSurfaceAndAccent ? color ?? effectiveSurfaceColor : effectiveSurfaceColor ?? color;
|
|
1635
|
+
const surfaceMaxChroma = themeAdjustments.surfaceMaxChroma ?? BASELINE_MAX_CHROMA;
|
|
1393
1636
|
const preferredSurfaceColor = convert(
|
|
1394
1637
|
parse(preferredSurfaceColorInput),
|
|
1395
1638
|
"oklch"
|
|
1396
1639
|
);
|
|
1397
1640
|
let surfaceHue = preferredSurfaceColor.h;
|
|
1398
1641
|
const surfaceChroma = Math.min(preferredSurfaceColor.c, surfaceMaxChroma);
|
|
1399
|
-
const surfaceHueShift =
|
|
1400
|
-
if (surfaceHueShift !== 0 && !
|
|
1642
|
+
const surfaceHueShift = themeAdjustments.surfaceHueShift ?? 0;
|
|
1643
|
+
if (surfaceHueShift !== 0 && !effectiveSurfaceColor && !invertSurfaceAndAccent) {
|
|
1401
1644
|
surfaceHue = wrapHue(convert(color, "oklch").h + surfaceHueShift);
|
|
1402
1645
|
}
|
|
1646
|
+
const s = themeType === "light" ? SURFACE_SCALE.light : SURFACE_SCALE.dark;
|
|
1403
1647
|
const normalizedPreferredSurfaceColor = {
|
|
1404
1648
|
...preferredSurfaceColor,
|
|
1405
1649
|
h: surfaceHue,
|
|
1406
1650
|
c: surfaceChroma,
|
|
1407
|
-
l:
|
|
1651
|
+
l: s.L
|
|
1408
1652
|
};
|
|
1409
1653
|
return expandColorToScale(normalizedPreferredSurfaceColor, themeType, {
|
|
1410
|
-
|
|
1411
|
-
baselineLValueLight:
|
|
1412
|
-
|
|
1413
|
-
strongDeltaLight:
|
|
1414
|
-
|
|
1415
|
-
weakDeltaLight:
|
|
1416
|
-
|
|
1417
|
-
hueShift: options?.hueShift,
|
|
1418
|
-
foregroundMaxChroma: options?.foregroundMaxChroma,
|
|
1419
|
-
light: options?.light,
|
|
1420
|
-
dark: options?.dark
|
|
1654
|
+
...options ?? {},
|
|
1655
|
+
baselineLValueLight: SURFACE_SCALE.light.L,
|
|
1656
|
+
baselineLValueDark: SURFACE_SCALE.dark.L,
|
|
1657
|
+
strongDeltaLight: SURFACE_SCALE.light.strong,
|
|
1658
|
+
strongDeltaDark: SURFACE_SCALE.dark.strong,
|
|
1659
|
+
weakDeltaLight: SURFACE_SCALE.light.weak,
|
|
1660
|
+
weakDeltaDark: SURFACE_SCALE.dark.weak
|
|
1421
1661
|
});
|
|
1422
1662
|
}
|
|
1423
1663
|
|
|
1424
1664
|
// src/generate/generate.ts
|
|
1425
1665
|
function generate(color, themeType, options) {
|
|
1666
|
+
const resolvedOptions = {
|
|
1667
|
+
...options ?? {},
|
|
1668
|
+
inputLightness: convert(color, "oklch").l
|
|
1669
|
+
};
|
|
1426
1670
|
return {
|
|
1427
|
-
surface: generateSurface(color, themeType,
|
|
1428
|
-
accent: generateAccent(color, themeType,
|
|
1429
|
-
...generateSemanticColors(color, themeType,
|
|
1671
|
+
surface: generateSurface(color, themeType, resolvedOptions),
|
|
1672
|
+
accent: generateAccent(color, themeType, resolvedOptions),
|
|
1673
|
+
...generateSemanticColors(color, themeType, resolvedOptions)
|
|
1430
1674
|
};
|
|
1431
1675
|
}
|
|
1432
1676
|
|
|
@@ -2180,7 +2424,8 @@ var mui = {
|
|
|
2180
2424
|
roleNames: {
|
|
2181
2425
|
accent: "primary",
|
|
2182
2426
|
negative: "error",
|
|
2183
|
-
positive: "success"
|
|
2427
|
+
positive: "success",
|
|
2428
|
+
caution: "warning"
|
|
2184
2429
|
},
|
|
2185
2430
|
variantNames: {
|
|
2186
2431
|
DEFAULT: "main",
|
|
@@ -2260,7 +2505,7 @@ var shadcn = {
|
|
|
2260
2505
|
variantNames: {
|
|
2261
2506
|
foreground: "foreground"
|
|
2262
2507
|
},
|
|
2263
|
-
excludeRoles: ["
|
|
2508
|
+
excludeRoles: ["caution"],
|
|
2264
2509
|
excludeVariants: ["strong", "weak"]
|
|
2265
2510
|
}
|
|
2266
2511
|
};
|
|
@@ -2350,17 +2595,20 @@ Style options:
|
|
|
2350
2595
|
--hue-shift <deg> Per-variant hue shift in degrees
|
|
2351
2596
|
--surface-max-chroma <n> Max chroma for surface colors (default: 0.01)
|
|
2352
2597
|
--fg-max-chroma <n> Max chroma for foreground colors (default: 0.01)
|
|
2353
|
-
--light-lightness <n> Light theme lightness 0-1 (default:
|
|
2598
|
+
--light-lightness <n> Light theme lightness 0-1 (default: from input OKLCH L)
|
|
2599
|
+
--light-base-lightness-range <min,max> Clamp input/base L for light theme (default: 0.4,0.9)
|
|
2354
2600
|
--light-max-chroma <n> Light theme max chroma
|
|
2355
|
-
--dark-lightness <n> Dark theme lightness 0-1 (default:
|
|
2601
|
+
--dark-lightness <n> Dark theme lightness 0-1 (default: from input OKLCH L)
|
|
2602
|
+
--dark-base-lightness-range <min,max> Clamp input/base L for dark theme (default: 0.2,0.8)
|
|
2356
2603
|
--dark-max-chroma <n> Dark theme max chroma
|
|
2604
|
+
--base-lightness-range <min,max> Default clamp for both themes (overridden by per-theme flags)
|
|
2357
2605
|
--min-contrast <value> AAA | AA | <number> (default: AAA)
|
|
2358
2606
|
--invert-dark Swap surface/accent hues in dark mode (requires --surface-color)
|
|
2359
2607
|
|
|
2360
2608
|
Semantic colors:
|
|
2361
2609
|
--positive <color> Override positive/success color (default: auto green)
|
|
2362
2610
|
--negative <color> Override negative/error color (default: auto red)
|
|
2363
|
-
--
|
|
2611
|
+
--caution <color> Override caution color (default: auto amber)
|
|
2364
2612
|
|
|
2365
2613
|
CVD (color vision deficiency):
|
|
2366
2614
|
--simulate <type> Simulate CVD: protanopia | deuteranopia | tritanopia | achromatopsia
|
|
@@ -2389,6 +2637,14 @@ Examples:
|
|
|
2389
2637
|
hextimator '#ff6600' --simulate deuteranopia
|
|
2390
2638
|
hextimator '#ff6600' --adapt deuteranopia --cvd-severity 0.8
|
|
2391
2639
|
`.trim();
|
|
2640
|
+
function parseBaseLightnessRange(raw) {
|
|
2641
|
+
const parts = raw.trim().split(/\s*,\s*/);
|
|
2642
|
+
if (parts.length !== 2) return void 0;
|
|
2643
|
+
const lo = Number(parts[0]);
|
|
2644
|
+
const hi = Number(parts[1]);
|
|
2645
|
+
if (!Number.isFinite(lo) || !Number.isFinite(hi)) return void 0;
|
|
2646
|
+
return [lo, hi];
|
|
2647
|
+
}
|
|
2392
2648
|
function run() {
|
|
2393
2649
|
const { values, positionals } = parseArgs({
|
|
2394
2650
|
allowPositionals: true,
|
|
@@ -2409,14 +2665,17 @@ function run() {
|
|
|
2409
2665
|
"surface-max-chroma": { type: "string" },
|
|
2410
2666
|
"fg-max-chroma": { type: "string" },
|
|
2411
2667
|
"light-lightness": { type: "string" },
|
|
2668
|
+
"light-base-lightness-range": { type: "string" },
|
|
2412
2669
|
"light-max-chroma": { type: "string" },
|
|
2413
2670
|
"dark-lightness": { type: "string" },
|
|
2671
|
+
"dark-base-lightness-range": { type: "string" },
|
|
2414
2672
|
"dark-max-chroma": { type: "string" },
|
|
2673
|
+
"base-lightness-range": { type: "string" },
|
|
2415
2674
|
"min-contrast": { type: "string" },
|
|
2416
2675
|
"invert-dark": { type: "boolean" },
|
|
2417
2676
|
positive: { type: "string" },
|
|
2418
2677
|
negative: { type: "string" },
|
|
2419
|
-
|
|
2678
|
+
caution: { type: "string" },
|
|
2420
2679
|
simulate: { type: "string" },
|
|
2421
2680
|
adapt: { type: "string" },
|
|
2422
2681
|
"cvd-severity": { type: "string" },
|
|
@@ -2450,19 +2709,33 @@ function run() {
|
|
|
2450
2709
|
styleOptions.surfaceMaxChroma = Number(values["surface-max-chroma"]);
|
|
2451
2710
|
if (values["fg-max-chroma"])
|
|
2452
2711
|
styleOptions.foregroundMaxChroma = Number(values["fg-max-chroma"]);
|
|
2453
|
-
if (values["light-lightness"] || values["light-max-chroma"]) {
|
|
2712
|
+
if (values["light-lightness"] || values["light-max-chroma"] || values["light-base-lightness-range"]) {
|
|
2454
2713
|
styleOptions.light = {};
|
|
2455
2714
|
if (values["light-lightness"])
|
|
2456
2715
|
styleOptions.light.baseLightness = Number(values["light-lightness"]);
|
|
2457
2716
|
if (values["light-max-chroma"])
|
|
2458
2717
|
styleOptions.light.maxChroma = Number(values["light-max-chroma"]);
|
|
2718
|
+
if (values["light-base-lightness-range"]) {
|
|
2719
|
+
const pair = parseBaseLightnessRange(
|
|
2720
|
+
values["light-base-lightness-range"]
|
|
2721
|
+
);
|
|
2722
|
+
if (pair) styleOptions.light.baseLightnessRange = pair;
|
|
2723
|
+
}
|
|
2459
2724
|
}
|
|
2460
|
-
if (values["dark-lightness"] || values["dark-max-chroma"]) {
|
|
2725
|
+
if (values["dark-lightness"] || values["dark-max-chroma"] || values["dark-base-lightness-range"]) {
|
|
2461
2726
|
styleOptions.dark = {};
|
|
2462
2727
|
if (values["dark-lightness"])
|
|
2463
2728
|
styleOptions.dark.baseLightness = Number(values["dark-lightness"]);
|
|
2464
2729
|
if (values["dark-max-chroma"])
|
|
2465
2730
|
styleOptions.dark.maxChroma = Number(values["dark-max-chroma"]);
|
|
2731
|
+
if (values["dark-base-lightness-range"]) {
|
|
2732
|
+
const pair = parseBaseLightnessRange(values["dark-base-lightness-range"]);
|
|
2733
|
+
if (pair) styleOptions.dark.baseLightnessRange = pair;
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
if (values["base-lightness-range"]) {
|
|
2737
|
+
const pair = parseBaseLightnessRange(values["base-lightness-range"]);
|
|
2738
|
+
if (pair) styleOptions.baseLightnessRange = pair;
|
|
2466
2739
|
}
|
|
2467
2740
|
if (values["min-contrast"]) {
|
|
2468
2741
|
const mc = values["min-contrast"];
|
|
@@ -2478,7 +2751,7 @@ function run() {
|
|
|
2478
2751
|
const semanticColors = {};
|
|
2479
2752
|
if (values.positive) semanticColors.positive = values.positive;
|
|
2480
2753
|
if (values.negative) semanticColors.negative = values.negative;
|
|
2481
|
-
if (values.
|
|
2754
|
+
if (values.caution) semanticColors.caution = values.caution;
|
|
2482
2755
|
if (Object.keys(semanticColors).length > 0) {
|
|
2483
2756
|
styleOptions.semanticColors = semanticColors;
|
|
2484
2757
|
}
|