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/CHANGELOG.md +22 -0
- package/README.md +3 -3
- package/dist/{HextimatePaletteBuilder-doYcUGMD.d.ts → HextimatePaletteBuilder-CPteKnVL.d.ts} +42 -105
- package/dist/{chunk-PJSNOIIB.js → chunk-64DBUA5U.js} +346 -91
- package/dist/{chunk-NTF3K3U3.js → chunk-TEZ2I4CJ.js} +3 -2
- package/dist/cli.js +384 -100
- package/dist/{index-rFqBuFuF.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 +12 -9
- package/package.json +1 -1
- package/tailwind-inverted.css +4 -4
- package/tailwind.css +4 -4
|
@@ -983,9 +983,47 @@ function formatStylesheet(lightPalette, darkPalette, options, lightStandalone, d
|
|
|
983
983
|
return formatCSSStylesheet(lightEntries, darkEntries, sep, stylesheetOpts);
|
|
984
984
|
}
|
|
985
985
|
|
|
986
|
+
// src/generate/mergeThemeAdjustments.ts
|
|
987
|
+
function extractGlobalThemeAdjustments(options) {
|
|
988
|
+
const {
|
|
989
|
+
light: _l,
|
|
990
|
+
dark: _d,
|
|
991
|
+
invertDarkModeSurfaceAccent: _i,
|
|
992
|
+
inputLightness: _inp,
|
|
993
|
+
...global
|
|
994
|
+
} = options;
|
|
995
|
+
return global;
|
|
996
|
+
}
|
|
997
|
+
function mergeThemeAdjustments(base, override) {
|
|
998
|
+
if (!override) return { ...base };
|
|
999
|
+
return {
|
|
1000
|
+
...base,
|
|
1001
|
+
...override,
|
|
1002
|
+
semanticColors: base.semanticColors || override.semanticColors ? {
|
|
1003
|
+
...base.semanticColors,
|
|
1004
|
+
...override.semanticColors
|
|
1005
|
+
} : void 0,
|
|
1006
|
+
semanticColorRanges: base.semanticColorRanges || override.semanticColorRanges ? {
|
|
1007
|
+
...base.semanticColorRanges,
|
|
1008
|
+
...override.semanticColorRanges
|
|
1009
|
+
} : void 0
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
function resolveMergedThemeAdjustments(themeType, options) {
|
|
1013
|
+
const global = extractGlobalThemeAdjustments(
|
|
1014
|
+
options
|
|
1015
|
+
);
|
|
1016
|
+
const branch = themeType === "light" ? options.light : options.dark;
|
|
1017
|
+
return mergeThemeAdjustments(global, branch);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
986
1020
|
// src/generate/consts.ts
|
|
987
1021
|
var DEFAULT_LIGHT_THEME_LIGHTNESS = 0.7;
|
|
988
1022
|
var DEFAULT_DARK_THEME_LIGHTNESS = 0.6;
|
|
1023
|
+
var SURFACE_SCALE = {
|
|
1024
|
+
light: { L: 0.97, strong: 0.02, weak: -0.03 },
|
|
1025
|
+
dark: { L: 0.2, strong: -0.1, weak: 0.1 }
|
|
1026
|
+
};
|
|
989
1027
|
|
|
990
1028
|
// src/generate/utils.ts
|
|
991
1029
|
var FOREGROUND_DARK_L_VALUE = 0.97;
|
|
@@ -996,6 +1034,17 @@ var FALLBACK_STRONG_DELTA_LIGHT = -0.05;
|
|
|
996
1034
|
var FALLBACK_WEAK_DELTA_DARK = -0.05;
|
|
997
1035
|
var FALLBACK_WEAK_DELTA_LIGHT = 0.05;
|
|
998
1036
|
var VARIANT_DELTA = 0.1;
|
|
1037
|
+
var EXACT_CHIP_MIN_STRONG_DELTA_OKLCH = VARIANT_DELTA / 2;
|
|
1038
|
+
var LIGHT_THEME_LIGHTNESS_RANGE = [0.4, 0.9];
|
|
1039
|
+
var DARK_THEME_LIGHTNESS_RANGE = [0.2, 0.8];
|
|
1040
|
+
var ACCENT_VS_SURFACE_L_GAP = 0.045;
|
|
1041
|
+
function surfaceLightnessBand(themeType) {
|
|
1042
|
+
const x = themeType === "light" ? SURFACE_SCALE.light : SURFACE_SCALE.dark;
|
|
1043
|
+
const a = x.L;
|
|
1044
|
+
const b = x.L + x.strong;
|
|
1045
|
+
const c = x.L + x.weak;
|
|
1046
|
+
return { min: Math.min(a, b, c), max: Math.max(a, b, c) };
|
|
1047
|
+
}
|
|
999
1048
|
var CONTRAST_MARGIN = 0.15;
|
|
1000
1049
|
function resolveContrastRatio(value) {
|
|
1001
1050
|
if (value === void 0 || value === "AAA") return 7;
|
|
@@ -1011,45 +1060,191 @@ function clampHueShift(hueShift, totalVariants) {
|
|
|
1011
1060
|
function wrapHue(h) {
|
|
1012
1061
|
return (h % 360 + 360) % 360;
|
|
1013
1062
|
}
|
|
1063
|
+
function oklchBodyClose(a, b) {
|
|
1064
|
+
const eps = 1e-5;
|
|
1065
|
+
let dh = Math.abs(a.h - b.h) % 360;
|
|
1066
|
+
if (dh > 180) dh = 360 - dh;
|
|
1067
|
+
return Math.abs(a.l - b.l) < eps && Math.abs(a.c - b.c) < eps && dh < 0.05;
|
|
1068
|
+
}
|
|
1069
|
+
function pickAccentForegroundPair(base, themeType, foregroundLValueLight, foregroundLValueDark, foregroundMaxChroma, minContrast) {
|
|
1070
|
+
const candidates = [foregroundLValueLight, foregroundLValueDark].map((l) => ({
|
|
1071
|
+
...base,
|
|
1072
|
+
l,
|
|
1073
|
+
c: Math.min(base.c, foregroundMaxChroma)
|
|
1074
|
+
}));
|
|
1075
|
+
const [candidateA, candidateB] = themeType === "light" ? candidates : [...candidates].reverse();
|
|
1076
|
+
const contrastA = calculateContrast(base, candidateA);
|
|
1077
|
+
const contrastB = calculateContrast(base, candidateB);
|
|
1078
|
+
const [preferred, fallback] = contrastA >= contrastB ? [candidateA, candidateB] : [candidateB, candidateA];
|
|
1079
|
+
const foreground = calculateContrast(base, preferred) > minContrast ? preferred : fallback;
|
|
1080
|
+
return { foreground, preferred };
|
|
1081
|
+
}
|
|
1082
|
+
function computeStrongWeakWithoutBoundaryShift(base, foreground, themeType, contrastTarget) {
|
|
1083
|
+
const contrastDirection = themeType === "light" ? -1 : 1;
|
|
1084
|
+
const boundaryL = findContrastBoundaryLightness(
|
|
1085
|
+
base,
|
|
1086
|
+
foreground,
|
|
1087
|
+
contrastTarget
|
|
1088
|
+
);
|
|
1089
|
+
const distToBoundary = boundaryL !== null ? Math.abs(base.l - boundaryL) : 0;
|
|
1090
|
+
const strongDelta = Math.min(VARIANT_DELTA, distToBoundary);
|
|
1091
|
+
const weakCandidateColor = {
|
|
1092
|
+
...base,
|
|
1093
|
+
l: base.l - VARIANT_DELTA * contrastDirection
|
|
1094
|
+
};
|
|
1095
|
+
let weakDelta = VARIANT_DELTA;
|
|
1096
|
+
if (calculateContrast(weakCandidateColor, foreground) < contrastTarget) {
|
|
1097
|
+
let lo = 0;
|
|
1098
|
+
let hi = VARIANT_DELTA;
|
|
1099
|
+
for (let i = 0; i < 20; i++) {
|
|
1100
|
+
const mid = (lo + hi) / 2;
|
|
1101
|
+
const testL = base.l - mid * contrastDirection;
|
|
1102
|
+
const testColor = { ...base, l: testL };
|
|
1103
|
+
if (calculateContrast(testColor, foreground) > contrastTarget) {
|
|
1104
|
+
lo = mid;
|
|
1105
|
+
} else {
|
|
1106
|
+
hi = mid;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
weakDelta = lo;
|
|
1110
|
+
}
|
|
1111
|
+
const strong = {
|
|
1112
|
+
...base,
|
|
1113
|
+
l: Math.max(0, Math.min(1, base.l + strongDelta * contrastDirection))
|
|
1114
|
+
};
|
|
1115
|
+
const weak = {
|
|
1116
|
+
...base,
|
|
1117
|
+
l: Math.max(0, Math.min(1, base.l - weakDelta * contrastDirection))
|
|
1118
|
+
};
|
|
1119
|
+
return { strong, weak };
|
|
1120
|
+
}
|
|
1121
|
+
function constrainAccentVariantVsSurface(themeType, variant, foreground, contrastTarget, skipSurfaceCap) {
|
|
1122
|
+
if (skipSurfaceCap) return variant;
|
|
1123
|
+
const { min: sMin, max: sMax } = surfaceLightnessBand(themeType);
|
|
1124
|
+
let v = { ...variant };
|
|
1125
|
+
if (themeType === "light") {
|
|
1126
|
+
const hi = sMax - ACCENT_VS_SURFACE_L_GAP;
|
|
1127
|
+
if (v.l > hi) v = { ...v, l: hi };
|
|
1128
|
+
} else {
|
|
1129
|
+
const lo = sMin + ACCENT_VS_SURFACE_L_GAP;
|
|
1130
|
+
if (v.l < lo) v = { ...v, l: lo };
|
|
1131
|
+
}
|
|
1132
|
+
v = ensureContrast(v, foreground, contrastTarget);
|
|
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
|
+
return v;
|
|
1141
|
+
}
|
|
1142
|
+
function hasExplicitBaseLightnessAnchor(themeType, options) {
|
|
1143
|
+
if (!options) return false;
|
|
1144
|
+
const global = extractGlobalThemeAdjustments(
|
|
1145
|
+
options
|
|
1146
|
+
);
|
|
1147
|
+
if (global.baseLightness !== void 0 || global.lightness !== void 0) {
|
|
1148
|
+
return true;
|
|
1149
|
+
}
|
|
1150
|
+
const branch = themeType === "light" ? options.light : options.dark;
|
|
1151
|
+
return branch?.baseLightness !== void 0 || branch?.lightness !== void 0;
|
|
1152
|
+
}
|
|
1014
1153
|
function expandColorToScale(color, themeType, options) {
|
|
1015
1154
|
const {
|
|
1016
1155
|
baselineLValueDark,
|
|
1017
1156
|
baselineLValueLight,
|
|
1018
|
-
minContrastRatio: minContrastRatioOption,
|
|
1019
1157
|
foregroundLValueDark = FOREGROUND_DARK_L_VALUE,
|
|
1020
1158
|
foregroundLValueLight = FOREGROUND_LIGHT_L_VALUE,
|
|
1021
|
-
foregroundMaxChroma: foregroundMaxChromaOption = FOREGROUND_MAX_CHROMA,
|
|
1022
1159
|
strongDeltaDark,
|
|
1023
1160
|
strongDeltaLight,
|
|
1024
1161
|
weakDeltaDark,
|
|
1025
1162
|
weakDeltaLight
|
|
1026
1163
|
} = options ?? {};
|
|
1027
|
-
const themeAdjustments =
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
themeAdjustments?.minContrastRatio ?? minContrastRatioOption
|
|
1164
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1165
|
+
themeType,
|
|
1166
|
+
options ?? {}
|
|
1031
1167
|
);
|
|
1168
|
+
const foregroundMaxChroma = themeAdjustments.foregroundMaxChroma ?? FOREGROUND_MAX_CHROMA;
|
|
1169
|
+
const minContrast = resolveContrastRatio(themeAdjustments.minContrastRatio);
|
|
1032
1170
|
const contrastTarget = minContrast + CONTRAST_MARGIN;
|
|
1033
1171
|
const hasExplicitDeltas = strongDeltaDark !== void 0 || strongDeltaLight !== void 0 || weakDeltaDark !== void 0 || weakDeltaLight !== void 0;
|
|
1034
1172
|
const themeLightness = resolveThemeLightness(themeType, options);
|
|
1035
1173
|
const colorOKLCH = convert(color, "oklch");
|
|
1036
|
-
const maxChroma =
|
|
1037
|
-
const
|
|
1174
|
+
const maxChroma = themeAdjustments.maxChroma;
|
|
1175
|
+
const chipOKLCH = {
|
|
1038
1176
|
...colorOKLCH,
|
|
1039
|
-
l: themeType === "light" ? baselineLValueLight ?? themeLightness : baselineLValueDark ?? themeLightness,
|
|
1040
1177
|
c: maxChroma !== void 0 ? Math.min(colorOKLCH.c, maxChroma) : colorOKLCH.c
|
|
1041
1178
|
};
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1179
|
+
const isSurfaceScale = baselineLValueLight !== void 0 || baselineLValueDark !== void 0;
|
|
1180
|
+
const rawHueShift = themeAdjustments.hueShift ?? 0;
|
|
1181
|
+
let useExactChip = false;
|
|
1182
|
+
if (!isSurfaceScale && !hasExplicitDeltas && rawHueShift === 0 && !hasExplicitBaseLightnessAnchor(themeType, options)) {
|
|
1183
|
+
const range = resolveBaseLightnessClampRange(themeType, options);
|
|
1184
|
+
if (chipOKLCH.l >= range[0] && chipOKLCH.l <= range[1]) {
|
|
1185
|
+
const chipFg = pickAccentForegroundPair(
|
|
1186
|
+
chipOKLCH,
|
|
1187
|
+
themeType,
|
|
1188
|
+
foregroundLValueLight,
|
|
1189
|
+
foregroundLValueDark,
|
|
1190
|
+
foregroundMaxChroma,
|
|
1191
|
+
minContrast
|
|
1192
|
+
).foreground;
|
|
1193
|
+
if (calculateContrast(chipOKLCH, chipFg) >= contrastTarget) {
|
|
1194
|
+
const chipBoundaryL = findContrastBoundaryLightness(
|
|
1195
|
+
chipOKLCH,
|
|
1196
|
+
chipFg,
|
|
1197
|
+
contrastTarget
|
|
1198
|
+
);
|
|
1199
|
+
const chipDistToBoundary = chipBoundaryL !== null ? Math.abs(chipOKLCH.l - chipBoundaryL) : 0;
|
|
1200
|
+
const chipStrongDelta = Math.min(VARIANT_DELTA, chipDistToBoundary);
|
|
1201
|
+
if (chipStrongDelta >= EXACT_CHIP_MIN_STRONG_DELTA_OKLCH) {
|
|
1202
|
+
const { strong: strongSim, weak: weakSim } = computeStrongWeakWithoutBoundaryShift(
|
|
1203
|
+
chipOKLCH,
|
|
1204
|
+
chipFg,
|
|
1205
|
+
themeType,
|
|
1206
|
+
contrastTarget
|
|
1207
|
+
);
|
|
1208
|
+
const defF = constrainAccentVariantVsSurface(
|
|
1209
|
+
themeType,
|
|
1210
|
+
chipOKLCH,
|
|
1211
|
+
chipFg,
|
|
1212
|
+
contrastTarget,
|
|
1213
|
+
false
|
|
1214
|
+
);
|
|
1215
|
+
const sF = constrainAccentVariantVsSurface(
|
|
1216
|
+
themeType,
|
|
1217
|
+
strongSim,
|
|
1218
|
+
chipFg,
|
|
1219
|
+
contrastTarget,
|
|
1220
|
+
false
|
|
1221
|
+
);
|
|
1222
|
+
const wF = constrainAccentVariantVsSurface(
|
|
1223
|
+
themeType,
|
|
1224
|
+
weakSim,
|
|
1225
|
+
chipFg,
|
|
1226
|
+
contrastTarget,
|
|
1227
|
+
false
|
|
1228
|
+
);
|
|
1229
|
+
useExactChip = oklchBodyClose(defF, chipOKLCH) && calculateContrast(defF, chipFg) >= contrastTarget && calculateContrast(sF, chipFg) >= contrastTarget && calculateContrast(wF, chipFg) >= contrastTarget;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
let normalizedColorOKLCH = useExactChip ? { ...chipOKLCH } : {
|
|
1235
|
+
...colorOKLCH,
|
|
1236
|
+
l: themeType === "light" ? baselineLValueLight ?? themeLightness : baselineLValueDark ?? themeLightness,
|
|
1237
|
+
c: chipOKLCH.c
|
|
1238
|
+
};
|
|
1239
|
+
let { foreground: foregroundColorOKLCH, preferred } = pickAccentForegroundPair(
|
|
1240
|
+
normalizedColorOKLCH,
|
|
1241
|
+
themeType,
|
|
1242
|
+
foregroundLValueLight,
|
|
1243
|
+
foregroundLValueDark,
|
|
1244
|
+
foregroundMaxChroma,
|
|
1245
|
+
minContrast
|
|
1246
|
+
);
|
|
1247
|
+
if (!useExactChip && calculateContrast(normalizedColorOKLCH, foregroundColorOKLCH) < contrastTarget) {
|
|
1053
1248
|
const direction = preferred.l < normalizedColorOKLCH.l ? 1 : -1;
|
|
1054
1249
|
let lo = direction === 1 ? normalizedColorOKLCH.l : 0;
|
|
1055
1250
|
let hi = direction === 1 ? 1 : normalizedColorOKLCH.l;
|
|
@@ -1064,7 +1259,10 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1064
1259
|
else hi = mid;
|
|
1065
1260
|
}
|
|
1066
1261
|
}
|
|
1067
|
-
normalizedColorOKLCH
|
|
1262
|
+
normalizedColorOKLCH = {
|
|
1263
|
+
...normalizedColorOKLCH,
|
|
1264
|
+
l: (lo + hi) / 2
|
|
1265
|
+
};
|
|
1068
1266
|
foregroundColorOKLCH = preferred;
|
|
1069
1267
|
}
|
|
1070
1268
|
let strongColorOKLCH;
|
|
@@ -1088,13 +1286,16 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1088
1286
|
contrastTarget
|
|
1089
1287
|
);
|
|
1090
1288
|
let distToBoundary = boundaryL !== null ? Math.abs(normalizedColorOKLCH.l - boundaryL) : 0;
|
|
1091
|
-
if (distToBoundary < VARIANT_DELTA) {
|
|
1289
|
+
if (!useExactChip && distToBoundary < VARIANT_DELTA) {
|
|
1092
1290
|
const shift = Math.min(VARIANT_DELTA - distToBoundary, VARIANT_DELTA / 2);
|
|
1093
1291
|
const awayFromForeground = foregroundColorOKLCH.l < normalizedColorOKLCH.l ? 1 : -1;
|
|
1094
|
-
normalizedColorOKLCH
|
|
1095
|
-
|
|
1096
|
-
Math.
|
|
1097
|
-
|
|
1292
|
+
normalizedColorOKLCH = {
|
|
1293
|
+
...normalizedColorOKLCH,
|
|
1294
|
+
l: Math.max(
|
|
1295
|
+
0,
|
|
1296
|
+
Math.min(1, normalizedColorOKLCH.l + shift * awayFromForeground)
|
|
1297
|
+
)
|
|
1298
|
+
};
|
|
1098
1299
|
boundaryL = findContrastBoundaryLightness(
|
|
1099
1300
|
normalizedColorOKLCH,
|
|
1100
1301
|
foregroundColorOKLCH,
|
|
@@ -1140,7 +1341,7 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1140
1341
|
)
|
|
1141
1342
|
};
|
|
1142
1343
|
}
|
|
1143
|
-
const
|
|
1344
|
+
const skipSurfaceCap = baselineLValueLight !== void 0;
|
|
1144
1345
|
if (rawHueShift !== 0) {
|
|
1145
1346
|
const clamped = clampHueShift(rawHueShift, 2);
|
|
1146
1347
|
strongColorOKLCH = {
|
|
@@ -1162,6 +1363,27 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1162
1363
|
contrastTarget
|
|
1163
1364
|
);
|
|
1164
1365
|
}
|
|
1366
|
+
normalizedColorOKLCH = constrainAccentVariantVsSurface(
|
|
1367
|
+
themeType,
|
|
1368
|
+
normalizedColorOKLCH,
|
|
1369
|
+
foregroundColorOKLCH,
|
|
1370
|
+
contrastTarget,
|
|
1371
|
+
skipSurfaceCap
|
|
1372
|
+
);
|
|
1373
|
+
strongColorOKLCH = constrainAccentVariantVsSurface(
|
|
1374
|
+
themeType,
|
|
1375
|
+
strongColorOKLCH,
|
|
1376
|
+
foregroundColorOKLCH,
|
|
1377
|
+
contrastTarget,
|
|
1378
|
+
skipSurfaceCap
|
|
1379
|
+
);
|
|
1380
|
+
weakColorOKLCH = constrainAccentVariantVsSurface(
|
|
1381
|
+
themeType,
|
|
1382
|
+
weakColorOKLCH,
|
|
1383
|
+
foregroundColorOKLCH,
|
|
1384
|
+
contrastTarget,
|
|
1385
|
+
skipSurfaceCap
|
|
1386
|
+
);
|
|
1165
1387
|
return {
|
|
1166
1388
|
DEFAULT: { ...normalizedColorOKLCH },
|
|
1167
1389
|
strong: { ...strongColorOKLCH },
|
|
@@ -1169,14 +1391,41 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1169
1391
|
foreground: { ...foregroundColorOKLCH }
|
|
1170
1392
|
};
|
|
1171
1393
|
}
|
|
1172
|
-
var LIGHT_THEME_LIGHTNESS_RANGE = [0.4, 0.99];
|
|
1173
|
-
var DARK_THEME_LIGHTNESS_RANGE = [0.2, 0.8];
|
|
1174
1394
|
var warnedLegacyLightness = false;
|
|
1175
|
-
function
|
|
1395
|
+
function normalizeBaseLightnessRange(custom) {
|
|
1396
|
+
let lo = Number(custom[0]);
|
|
1397
|
+
let hi = Number(custom[1]);
|
|
1398
|
+
if (!Number.isFinite(lo) || !Number.isFinite(hi)) return void 0;
|
|
1399
|
+
if (lo > hi) [lo, hi] = [hi, lo];
|
|
1400
|
+
lo = Math.max(0, Math.min(1, lo));
|
|
1401
|
+
hi = Math.max(0, Math.min(1, hi));
|
|
1402
|
+
if (lo > hi) return void 0;
|
|
1403
|
+
return [lo, hi];
|
|
1404
|
+
}
|
|
1405
|
+
function resolveBaseLightnessClampRange(themeType, options) {
|
|
1176
1406
|
const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
|
|
1177
|
-
const
|
|
1178
|
-
const
|
|
1179
|
-
if (
|
|
1407
|
+
const fallback = themeType === "light" ? LIGHT_THEME_LIGHTNESS_RANGE : DARK_THEME_LIGHTNESS_RANGE;
|
|
1408
|
+
const fromTheme = themeAdjustments?.baseLightnessRange;
|
|
1409
|
+
if (fromTheme && fromTheme.length === 2) {
|
|
1410
|
+
const t = normalizeBaseLightnessRange(fromTheme);
|
|
1411
|
+
if (t) return t;
|
|
1412
|
+
}
|
|
1413
|
+
const global = options?.baseLightnessRange;
|
|
1414
|
+
if (global && global.length === 2) {
|
|
1415
|
+
const g = normalizeBaseLightnessRange(global);
|
|
1416
|
+
if (g) return g;
|
|
1417
|
+
}
|
|
1418
|
+
return fallback;
|
|
1419
|
+
}
|
|
1420
|
+
function resolveThemeLightness(themeType, options) {
|
|
1421
|
+
const branch = themeType === "light" ? options?.light : options?.dark;
|
|
1422
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1423
|
+
themeType,
|
|
1424
|
+
options ?? {}
|
|
1425
|
+
);
|
|
1426
|
+
const range = resolveBaseLightnessClampRange(themeType, options);
|
|
1427
|
+
const value = themeAdjustments.baseLightness ?? themeAdjustments.lightness;
|
|
1428
|
+
if (branch?.baseLightness === void 0 && branch?.lightness !== void 0 && !warnedLegacyLightness && typeof console !== "undefined") {
|
|
1180
1429
|
warnedLegacyLightness = true;
|
|
1181
1430
|
console.warn(
|
|
1182
1431
|
"[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."
|
|
@@ -1185,6 +1434,9 @@ function resolveThemeLightness(themeType, options) {
|
|
|
1185
1434
|
if (value !== void 0) {
|
|
1186
1435
|
return Math.min(Math.max(value, range[0]), range[1]);
|
|
1187
1436
|
}
|
|
1437
|
+
if (options?.inputLightness !== void 0) {
|
|
1438
|
+
return Math.min(Math.max(options.inputLightness, range[0]), range[1]);
|
|
1439
|
+
}
|
|
1188
1440
|
return themeType === "light" ? DEFAULT_LIGHT_THEME_LIGHTNESS : DEFAULT_DARK_THEME_LIGHTNESS;
|
|
1189
1441
|
}
|
|
1190
1442
|
function findContrastBoundaryLightness(defaultColor, foregroundColor, targetContrast = 7) {
|
|
@@ -1250,15 +1502,20 @@ function generateAccent(accent, themeType, options) {
|
|
|
1250
1502
|
const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
|
|
1251
1503
|
if (invertSurfaceAndAccent) {
|
|
1252
1504
|
const accentOklch = convert(accent, "oklch");
|
|
1253
|
-
const
|
|
1254
|
-
|
|
1255
|
-
|
|
1505
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1506
|
+
"dark",
|
|
1507
|
+
options ?? {}
|
|
1508
|
+
);
|
|
1509
|
+
const surfaceHueShift = themeAdjustments.surfaceHueShift ?? 0;
|
|
1510
|
+
const effectiveSurface = themeAdjustments.surfaceColor;
|
|
1511
|
+
let surfaceOklch = effectiveSurface ? convert(parse(effectiveSurface), "oklch") : convert(accent, "oklch");
|
|
1512
|
+
if (surfaceHueShift !== 0 && !effectiveSurface) {
|
|
1256
1513
|
surfaceOklch = {
|
|
1257
1514
|
...surfaceOklch,
|
|
1258
1515
|
h: wrapHue(accentOklch.h + surfaceHueShift)
|
|
1259
1516
|
};
|
|
1260
1517
|
}
|
|
1261
|
-
const maxChroma =
|
|
1518
|
+
const maxChroma = themeAdjustments.maxChroma;
|
|
1262
1519
|
const invertedAccent = {
|
|
1263
1520
|
...surfaceOklch,
|
|
1264
1521
|
c: maxChroma !== void 0 ? Math.min(accentOklch.c, maxChroma) : accentOklch.c
|
|
@@ -1271,53 +1528,52 @@ function generateAccent(accent, themeType, options) {
|
|
|
1271
1528
|
// src/generate/generateSemanticColors.ts
|
|
1272
1529
|
var POSITIVE_RANGE = [120, 160];
|
|
1273
1530
|
var NEGATIVE_RANGE = [5, 30];
|
|
1274
|
-
var
|
|
1531
|
+
var CAUTION_RANGE = [45, 70];
|
|
1275
1532
|
function generateSemanticColors(color, themeType, options) {
|
|
1533
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1534
|
+
themeType,
|
|
1535
|
+
options ?? {}
|
|
1536
|
+
);
|
|
1537
|
+
const semanticColors = {
|
|
1538
|
+
positive: themeAdjustments.semanticColors?.positive,
|
|
1539
|
+
negative: themeAdjustments.semanticColors?.negative,
|
|
1540
|
+
caution: themeAdjustments.semanticColors?.caution
|
|
1541
|
+
};
|
|
1542
|
+
const semanticColorRanges = {
|
|
1543
|
+
positive: themeAdjustments.semanticColorRanges?.positive ?? POSITIVE_RANGE,
|
|
1544
|
+
negative: themeAdjustments.semanticColorRanges?.negative ?? NEGATIVE_RANGE,
|
|
1545
|
+
caution: themeAdjustments.semanticColorRanges?.caution ?? CAUTION_RANGE
|
|
1546
|
+
};
|
|
1276
1547
|
const positiveBaseColor = parse(
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
{ includeInputAsCandidate: true }
|
|
1281
|
-
)
|
|
1548
|
+
semanticColors.positive ?? _determineBaseColorFromRange(color, semanticColorRanges.positive, {
|
|
1549
|
+
includeInputAsCandidate: true
|
|
1550
|
+
})
|
|
1282
1551
|
);
|
|
1283
1552
|
const negativeBaseColor = parse(
|
|
1284
|
-
|
|
1285
|
-
color,
|
|
1286
|
-
options?.semanticColorRanges?.negative ?? NEGATIVE_RANGE
|
|
1287
|
-
)
|
|
1553
|
+
semanticColors.negative ?? _determineBaseColorFromRange(color, semanticColorRanges.negative)
|
|
1288
1554
|
);
|
|
1289
|
-
const
|
|
1290
|
-
|
|
1291
|
-
color,
|
|
1292
|
-
options?.semanticColorRanges?.warning ?? WARNING_RANGE
|
|
1293
|
-
)
|
|
1555
|
+
const cautionBaseColor = parse(
|
|
1556
|
+
semanticColors.caution ?? _determineBaseColorFromRange(color, semanticColorRanges.caution)
|
|
1294
1557
|
);
|
|
1295
|
-
const scaleOptions = {
|
|
1296
|
-
light: options?.light,
|
|
1297
|
-
dark: options?.dark,
|
|
1298
|
-
minContrastRatio: options?.minContrastRatio,
|
|
1299
|
-
hueShift: options?.hueShift,
|
|
1300
|
-
foregroundMaxChroma: options?.foregroundMaxChroma
|
|
1301
|
-
};
|
|
1302
1558
|
const positiveColorScale = expandColorToScale(
|
|
1303
1559
|
positiveBaseColor,
|
|
1304
1560
|
themeType,
|
|
1305
|
-
|
|
1561
|
+
options
|
|
1306
1562
|
);
|
|
1307
1563
|
const negativeColorScale = expandColorToScale(
|
|
1308
1564
|
negativeBaseColor,
|
|
1309
1565
|
themeType,
|
|
1310
|
-
|
|
1566
|
+
options
|
|
1311
1567
|
);
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1568
|
+
const cautionColorScale = expandColorToScale(
|
|
1569
|
+
cautionBaseColor,
|
|
1314
1570
|
themeType,
|
|
1315
|
-
|
|
1571
|
+
options
|
|
1316
1572
|
);
|
|
1317
1573
|
return {
|
|
1318
1574
|
positive: positiveColorScale,
|
|
1319
1575
|
negative: negativeColorScale,
|
|
1320
|
-
|
|
1576
|
+
caution: cautionColorScale
|
|
1321
1577
|
};
|
|
1322
1578
|
}
|
|
1323
1579
|
function _determineBaseColorFromRange(color, range, options) {
|
|
@@ -1370,55 +1626,54 @@ function _getSplitComplementaryColors(color) {
|
|
|
1370
1626
|
}
|
|
1371
1627
|
|
|
1372
1628
|
// src/generate/generateSurface.ts
|
|
1373
|
-
var BASELINE_DARK_L_VALUE = 0.2;
|
|
1374
|
-
var BASELINE_LIGHT_L_VALUE = 0.97;
|
|
1375
1629
|
var BASELINE_MAX_CHROMA = 0.01;
|
|
1376
|
-
var STRONG_DELTA_DARK = -0.1;
|
|
1377
|
-
var STRONG_DELTA_LIGHT = 0.02;
|
|
1378
|
-
var WEAK_DELTA_DARK = 0.1;
|
|
1379
|
-
var WEAK_DELTA_LIGHT = -0.03;
|
|
1380
1630
|
function generateSurface(color, themeType, options) {
|
|
1381
1631
|
const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
|
|
1382
|
-
const
|
|
1383
|
-
|
|
1384
|
-
|
|
1632
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1633
|
+
themeType,
|
|
1634
|
+
options ?? {}
|
|
1635
|
+
);
|
|
1636
|
+
const effectiveSurfaceColor = themeAdjustments.surfaceColor;
|
|
1637
|
+
const preferredSurfaceColorInput = invertSurfaceAndAccent ? color ?? effectiveSurfaceColor : effectiveSurfaceColor ?? color;
|
|
1638
|
+
const surfaceMaxChroma = themeAdjustments.surfaceMaxChroma ?? BASELINE_MAX_CHROMA;
|
|
1385
1639
|
const preferredSurfaceColor = convert(
|
|
1386
1640
|
parse(preferredSurfaceColorInput),
|
|
1387
1641
|
"oklch"
|
|
1388
1642
|
);
|
|
1389
1643
|
let surfaceHue = preferredSurfaceColor.h;
|
|
1390
1644
|
const surfaceChroma = Math.min(preferredSurfaceColor.c, surfaceMaxChroma);
|
|
1391
|
-
const surfaceHueShift =
|
|
1392
|
-
if (surfaceHueShift !== 0 && !
|
|
1645
|
+
const surfaceHueShift = themeAdjustments.surfaceHueShift ?? 0;
|
|
1646
|
+
if (surfaceHueShift !== 0 && !effectiveSurfaceColor && !invertSurfaceAndAccent) {
|
|
1393
1647
|
surfaceHue = wrapHue(convert(color, "oklch").h + surfaceHueShift);
|
|
1394
1648
|
}
|
|
1649
|
+
const s = themeType === "light" ? SURFACE_SCALE.light : SURFACE_SCALE.dark;
|
|
1395
1650
|
const normalizedPreferredSurfaceColor = {
|
|
1396
1651
|
...preferredSurfaceColor,
|
|
1397
1652
|
h: surfaceHue,
|
|
1398
1653
|
c: surfaceChroma,
|
|
1399
|
-
l:
|
|
1654
|
+
l: s.L
|
|
1400
1655
|
};
|
|
1401
1656
|
return expandColorToScale(normalizedPreferredSurfaceColor, themeType, {
|
|
1402
|
-
|
|
1403
|
-
baselineLValueLight:
|
|
1404
|
-
|
|
1405
|
-
strongDeltaLight:
|
|
1406
|
-
|
|
1407
|
-
weakDeltaLight:
|
|
1408
|
-
|
|
1409
|
-
hueShift: options?.hueShift,
|
|
1410
|
-
foregroundMaxChroma: options?.foregroundMaxChroma,
|
|
1411
|
-
light: options?.light,
|
|
1412
|
-
dark: options?.dark
|
|
1657
|
+
...options ?? {},
|
|
1658
|
+
baselineLValueLight: SURFACE_SCALE.light.L,
|
|
1659
|
+
baselineLValueDark: SURFACE_SCALE.dark.L,
|
|
1660
|
+
strongDeltaLight: SURFACE_SCALE.light.strong,
|
|
1661
|
+
strongDeltaDark: SURFACE_SCALE.dark.strong,
|
|
1662
|
+
weakDeltaLight: SURFACE_SCALE.light.weak,
|
|
1663
|
+
weakDeltaDark: SURFACE_SCALE.dark.weak
|
|
1413
1664
|
});
|
|
1414
1665
|
}
|
|
1415
1666
|
|
|
1416
1667
|
// src/generate/generate.ts
|
|
1417
1668
|
function generate(color, themeType, options) {
|
|
1669
|
+
const resolvedOptions = {
|
|
1670
|
+
...options ?? {},
|
|
1671
|
+
inputLightness: convert(color, "oklch").l
|
|
1672
|
+
};
|
|
1418
1673
|
return {
|
|
1419
|
-
surface: generateSurface(color, themeType,
|
|
1420
|
-
accent: generateAccent(color, themeType,
|
|
1421
|
-
...generateSemanticColors(color, themeType,
|
|
1674
|
+
surface: generateSurface(color, themeType, resolvedOptions),
|
|
1675
|
+
accent: generateAccent(color, themeType, resolvedOptions),
|
|
1676
|
+
...generateSemanticColors(color, themeType, resolvedOptions)
|
|
1422
1677
|
};
|
|
1423
1678
|
}
|
|
1424
1679
|
|
|
@@ -67,7 +67,8 @@ var mui = {
|
|
|
67
67
|
roleNames: {
|
|
68
68
|
accent: "primary",
|
|
69
69
|
negative: "error",
|
|
70
|
-
positive: "success"
|
|
70
|
+
positive: "success",
|
|
71
|
+
caution: "warning"
|
|
71
72
|
},
|
|
72
73
|
variantNames: {
|
|
73
74
|
DEFAULT: "main",
|
|
@@ -147,7 +148,7 @@ var shadcn = {
|
|
|
147
148
|
variantNames: {
|
|
148
149
|
foreground: "foreground"
|
|
149
150
|
},
|
|
150
|
-
excludeRoles: ["
|
|
151
|
+
excludeRoles: ["caution"],
|
|
151
152
|
excludeVariants: ["strong", "weak"]
|
|
152
153
|
}
|
|
153
154
|
};
|