hextimator 0.9.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 +16 -0
- package/README.md +3 -3
- package/dist/{HextimatePaletteBuilder-doYcUGMD.d.ts → HextimatePaletteBuilder-CPteKnVL.d.ts} +42 -105
- package/dist/{chunk-NTF3K3U3.js → chunk-TEZ2I4CJ.js} +3 -2
- package/dist/{chunk-PJSNOIIB.js → chunk-ZUOHHUCY.js} +335 -91
- package/dist/cli.js +373 -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,180 @@ 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
|
+
}
|
|
1014
1142
|
function expandColorToScale(color, themeType, options) {
|
|
1015
1143
|
const {
|
|
1016
1144
|
baselineLValueDark,
|
|
1017
1145
|
baselineLValueLight,
|
|
1018
|
-
minContrastRatio: minContrastRatioOption,
|
|
1019
1146
|
foregroundLValueDark = FOREGROUND_DARK_L_VALUE,
|
|
1020
1147
|
foregroundLValueLight = FOREGROUND_LIGHT_L_VALUE,
|
|
1021
|
-
foregroundMaxChroma: foregroundMaxChromaOption = FOREGROUND_MAX_CHROMA,
|
|
1022
1148
|
strongDeltaDark,
|
|
1023
1149
|
strongDeltaLight,
|
|
1024
1150
|
weakDeltaDark,
|
|
1025
1151
|
weakDeltaLight
|
|
1026
1152
|
} = options ?? {};
|
|
1027
|
-
const themeAdjustments =
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
themeAdjustments?.minContrastRatio ?? minContrastRatioOption
|
|
1153
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1154
|
+
themeType,
|
|
1155
|
+
options ?? {}
|
|
1031
1156
|
);
|
|
1157
|
+
const foregroundMaxChroma = themeAdjustments.foregroundMaxChroma ?? FOREGROUND_MAX_CHROMA;
|
|
1158
|
+
const minContrast = resolveContrastRatio(themeAdjustments.minContrastRatio);
|
|
1032
1159
|
const contrastTarget = minContrast + CONTRAST_MARGIN;
|
|
1033
1160
|
const hasExplicitDeltas = strongDeltaDark !== void 0 || strongDeltaLight !== void 0 || weakDeltaDark !== void 0 || weakDeltaLight !== void 0;
|
|
1034
1161
|
const themeLightness = resolveThemeLightness(themeType, options);
|
|
1035
1162
|
const colorOKLCH = convert(color, "oklch");
|
|
1036
|
-
const maxChroma =
|
|
1037
|
-
const
|
|
1163
|
+
const maxChroma = themeAdjustments.maxChroma;
|
|
1164
|
+
const chipOKLCH = {
|
|
1038
1165
|
...colorOKLCH,
|
|
1039
|
-
l: themeType === "light" ? baselineLValueLight ?? themeLightness : baselineLValueDark ?? themeLightness,
|
|
1040
1166
|
c: maxChroma !== void 0 ? Math.min(colorOKLCH.c, maxChroma) : colorOKLCH.c
|
|
1041
1167
|
};
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1168
|
+
const isSurfaceScale = baselineLValueLight !== void 0 || baselineLValueDark !== void 0;
|
|
1169
|
+
const rawHueShift = themeAdjustments.hueShift ?? 0;
|
|
1170
|
+
let useExactChip = false;
|
|
1171
|
+
if (!isSurfaceScale && !hasExplicitDeltas && rawHueShift === 0) {
|
|
1172
|
+
const range = resolveBaseLightnessClampRange(themeType, options);
|
|
1173
|
+
if (chipOKLCH.l >= range[0] && chipOKLCH.l <= range[1]) {
|
|
1174
|
+
const chipFg = pickAccentForegroundPair(
|
|
1175
|
+
chipOKLCH,
|
|
1176
|
+
themeType,
|
|
1177
|
+
foregroundLValueLight,
|
|
1178
|
+
foregroundLValueDark,
|
|
1179
|
+
foregroundMaxChroma,
|
|
1180
|
+
minContrast
|
|
1181
|
+
).foreground;
|
|
1182
|
+
if (calculateContrast(chipOKLCH, chipFg) >= contrastTarget) {
|
|
1183
|
+
const chipBoundaryL = findContrastBoundaryLightness(
|
|
1184
|
+
chipOKLCH,
|
|
1185
|
+
chipFg,
|
|
1186
|
+
contrastTarget
|
|
1187
|
+
);
|
|
1188
|
+
const chipDistToBoundary = chipBoundaryL !== null ? Math.abs(chipOKLCH.l - chipBoundaryL) : 0;
|
|
1189
|
+
const chipStrongDelta = Math.min(VARIANT_DELTA, chipDistToBoundary);
|
|
1190
|
+
if (chipStrongDelta >= EXACT_CHIP_MIN_STRONG_DELTA_OKLCH) {
|
|
1191
|
+
const { strong: strongSim, weak: weakSim } = computeStrongWeakWithoutBoundaryShift(
|
|
1192
|
+
chipOKLCH,
|
|
1193
|
+
chipFg,
|
|
1194
|
+
themeType,
|
|
1195
|
+
contrastTarget
|
|
1196
|
+
);
|
|
1197
|
+
const defF = constrainAccentVariantVsSurface(
|
|
1198
|
+
themeType,
|
|
1199
|
+
chipOKLCH,
|
|
1200
|
+
chipFg,
|
|
1201
|
+
contrastTarget,
|
|
1202
|
+
false
|
|
1203
|
+
);
|
|
1204
|
+
const sF = constrainAccentVariantVsSurface(
|
|
1205
|
+
themeType,
|
|
1206
|
+
strongSim,
|
|
1207
|
+
chipFg,
|
|
1208
|
+
contrastTarget,
|
|
1209
|
+
false
|
|
1210
|
+
);
|
|
1211
|
+
const wF = constrainAccentVariantVsSurface(
|
|
1212
|
+
themeType,
|
|
1213
|
+
weakSim,
|
|
1214
|
+
chipFg,
|
|
1215
|
+
contrastTarget,
|
|
1216
|
+
false
|
|
1217
|
+
);
|
|
1218
|
+
useExactChip = oklchBodyClose(defF, chipOKLCH) && calculateContrast(defF, chipFg) >= contrastTarget && calculateContrast(sF, chipFg) >= contrastTarget && calculateContrast(wF, chipFg) >= contrastTarget;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
let normalizedColorOKLCH = useExactChip ? { ...chipOKLCH } : {
|
|
1224
|
+
...colorOKLCH,
|
|
1225
|
+
l: themeType === "light" ? baselineLValueLight ?? themeLightness : baselineLValueDark ?? themeLightness,
|
|
1226
|
+
c: chipOKLCH.c
|
|
1227
|
+
};
|
|
1228
|
+
let { foreground: foregroundColorOKLCH, preferred } = pickAccentForegroundPair(
|
|
1229
|
+
normalizedColorOKLCH,
|
|
1230
|
+
themeType,
|
|
1231
|
+
foregroundLValueLight,
|
|
1232
|
+
foregroundLValueDark,
|
|
1233
|
+
foregroundMaxChroma,
|
|
1234
|
+
minContrast
|
|
1235
|
+
);
|
|
1236
|
+
if (!useExactChip && calculateContrast(normalizedColorOKLCH, foregroundColorOKLCH) < contrastTarget) {
|
|
1053
1237
|
const direction = preferred.l < normalizedColorOKLCH.l ? 1 : -1;
|
|
1054
1238
|
let lo = direction === 1 ? normalizedColorOKLCH.l : 0;
|
|
1055
1239
|
let hi = direction === 1 ? 1 : normalizedColorOKLCH.l;
|
|
@@ -1064,7 +1248,10 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1064
1248
|
else hi = mid;
|
|
1065
1249
|
}
|
|
1066
1250
|
}
|
|
1067
|
-
normalizedColorOKLCH
|
|
1251
|
+
normalizedColorOKLCH = {
|
|
1252
|
+
...normalizedColorOKLCH,
|
|
1253
|
+
l: (lo + hi) / 2
|
|
1254
|
+
};
|
|
1068
1255
|
foregroundColorOKLCH = preferred;
|
|
1069
1256
|
}
|
|
1070
1257
|
let strongColorOKLCH;
|
|
@@ -1088,13 +1275,16 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1088
1275
|
contrastTarget
|
|
1089
1276
|
);
|
|
1090
1277
|
let distToBoundary = boundaryL !== null ? Math.abs(normalizedColorOKLCH.l - boundaryL) : 0;
|
|
1091
|
-
if (distToBoundary < VARIANT_DELTA) {
|
|
1278
|
+
if (!useExactChip && distToBoundary < VARIANT_DELTA) {
|
|
1092
1279
|
const shift = Math.min(VARIANT_DELTA - distToBoundary, VARIANT_DELTA / 2);
|
|
1093
1280
|
const awayFromForeground = foregroundColorOKLCH.l < normalizedColorOKLCH.l ? 1 : -1;
|
|
1094
|
-
normalizedColorOKLCH
|
|
1095
|
-
|
|
1096
|
-
Math.
|
|
1097
|
-
|
|
1281
|
+
normalizedColorOKLCH = {
|
|
1282
|
+
...normalizedColorOKLCH,
|
|
1283
|
+
l: Math.max(
|
|
1284
|
+
0,
|
|
1285
|
+
Math.min(1, normalizedColorOKLCH.l + shift * awayFromForeground)
|
|
1286
|
+
)
|
|
1287
|
+
};
|
|
1098
1288
|
boundaryL = findContrastBoundaryLightness(
|
|
1099
1289
|
normalizedColorOKLCH,
|
|
1100
1290
|
foregroundColorOKLCH,
|
|
@@ -1140,7 +1330,7 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1140
1330
|
)
|
|
1141
1331
|
};
|
|
1142
1332
|
}
|
|
1143
|
-
const
|
|
1333
|
+
const skipSurfaceCap = baselineLValueLight !== void 0;
|
|
1144
1334
|
if (rawHueShift !== 0) {
|
|
1145
1335
|
const clamped = clampHueShift(rawHueShift, 2);
|
|
1146
1336
|
strongColorOKLCH = {
|
|
@@ -1162,6 +1352,27 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1162
1352
|
contrastTarget
|
|
1163
1353
|
);
|
|
1164
1354
|
}
|
|
1355
|
+
normalizedColorOKLCH = constrainAccentVariantVsSurface(
|
|
1356
|
+
themeType,
|
|
1357
|
+
normalizedColorOKLCH,
|
|
1358
|
+
foregroundColorOKLCH,
|
|
1359
|
+
contrastTarget,
|
|
1360
|
+
skipSurfaceCap
|
|
1361
|
+
);
|
|
1362
|
+
strongColorOKLCH = constrainAccentVariantVsSurface(
|
|
1363
|
+
themeType,
|
|
1364
|
+
strongColorOKLCH,
|
|
1365
|
+
foregroundColorOKLCH,
|
|
1366
|
+
contrastTarget,
|
|
1367
|
+
skipSurfaceCap
|
|
1368
|
+
);
|
|
1369
|
+
weakColorOKLCH = constrainAccentVariantVsSurface(
|
|
1370
|
+
themeType,
|
|
1371
|
+
weakColorOKLCH,
|
|
1372
|
+
foregroundColorOKLCH,
|
|
1373
|
+
contrastTarget,
|
|
1374
|
+
skipSurfaceCap
|
|
1375
|
+
);
|
|
1165
1376
|
return {
|
|
1166
1377
|
DEFAULT: { ...normalizedColorOKLCH },
|
|
1167
1378
|
strong: { ...strongColorOKLCH },
|
|
@@ -1169,14 +1380,41 @@ function expandColorToScale(color, themeType, options) {
|
|
|
1169
1380
|
foreground: { ...foregroundColorOKLCH }
|
|
1170
1381
|
};
|
|
1171
1382
|
}
|
|
1172
|
-
var LIGHT_THEME_LIGHTNESS_RANGE = [0.4, 0.99];
|
|
1173
|
-
var DARK_THEME_LIGHTNESS_RANGE = [0.2, 0.8];
|
|
1174
1383
|
var warnedLegacyLightness = false;
|
|
1175
|
-
function
|
|
1384
|
+
function normalizeBaseLightnessRange(custom) {
|
|
1385
|
+
let lo = Number(custom[0]);
|
|
1386
|
+
let hi = Number(custom[1]);
|
|
1387
|
+
if (!Number.isFinite(lo) || !Number.isFinite(hi)) return void 0;
|
|
1388
|
+
if (lo > hi) [lo, hi] = [hi, lo];
|
|
1389
|
+
lo = Math.max(0, Math.min(1, lo));
|
|
1390
|
+
hi = Math.max(0, Math.min(1, hi));
|
|
1391
|
+
if (lo > hi) return void 0;
|
|
1392
|
+
return [lo, hi];
|
|
1393
|
+
}
|
|
1394
|
+
function resolveBaseLightnessClampRange(themeType, options) {
|
|
1176
1395
|
const themeAdjustments = themeType === "light" ? options?.light : options?.dark;
|
|
1177
|
-
const
|
|
1178
|
-
const
|
|
1179
|
-
if (
|
|
1396
|
+
const fallback = themeType === "light" ? LIGHT_THEME_LIGHTNESS_RANGE : DARK_THEME_LIGHTNESS_RANGE;
|
|
1397
|
+
const fromTheme = themeAdjustments?.baseLightnessRange;
|
|
1398
|
+
if (fromTheme && fromTheme.length === 2) {
|
|
1399
|
+
const t = normalizeBaseLightnessRange(fromTheme);
|
|
1400
|
+
if (t) return t;
|
|
1401
|
+
}
|
|
1402
|
+
const global = options?.baseLightnessRange;
|
|
1403
|
+
if (global && global.length === 2) {
|
|
1404
|
+
const g = normalizeBaseLightnessRange(global);
|
|
1405
|
+
if (g) return g;
|
|
1406
|
+
}
|
|
1407
|
+
return fallback;
|
|
1408
|
+
}
|
|
1409
|
+
function resolveThemeLightness(themeType, options) {
|
|
1410
|
+
const branch = themeType === "light" ? options?.light : options?.dark;
|
|
1411
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1412
|
+
themeType,
|
|
1413
|
+
options ?? {}
|
|
1414
|
+
);
|
|
1415
|
+
const range = resolveBaseLightnessClampRange(themeType, options);
|
|
1416
|
+
const value = themeAdjustments.baseLightness ?? themeAdjustments.lightness;
|
|
1417
|
+
if (branch?.baseLightness === void 0 && branch?.lightness !== void 0 && !warnedLegacyLightness && typeof console !== "undefined") {
|
|
1180
1418
|
warnedLegacyLightness = true;
|
|
1181
1419
|
console.warn(
|
|
1182
1420
|
"[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 +1423,9 @@ function resolveThemeLightness(themeType, options) {
|
|
|
1185
1423
|
if (value !== void 0) {
|
|
1186
1424
|
return Math.min(Math.max(value, range[0]), range[1]);
|
|
1187
1425
|
}
|
|
1426
|
+
if (options?.inputLightness !== void 0) {
|
|
1427
|
+
return Math.min(Math.max(options.inputLightness, range[0]), range[1]);
|
|
1428
|
+
}
|
|
1188
1429
|
return themeType === "light" ? DEFAULT_LIGHT_THEME_LIGHTNESS : DEFAULT_DARK_THEME_LIGHTNESS;
|
|
1189
1430
|
}
|
|
1190
1431
|
function findContrastBoundaryLightness(defaultColor, foregroundColor, targetContrast = 7) {
|
|
@@ -1250,15 +1491,20 @@ function generateAccent(accent, themeType, options) {
|
|
|
1250
1491
|
const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
|
|
1251
1492
|
if (invertSurfaceAndAccent) {
|
|
1252
1493
|
const accentOklch = convert(accent, "oklch");
|
|
1253
|
-
const
|
|
1254
|
-
|
|
1255
|
-
|
|
1494
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1495
|
+
"dark",
|
|
1496
|
+
options ?? {}
|
|
1497
|
+
);
|
|
1498
|
+
const surfaceHueShift = themeAdjustments.surfaceHueShift ?? 0;
|
|
1499
|
+
const effectiveSurface = themeAdjustments.surfaceColor;
|
|
1500
|
+
let surfaceOklch = effectiveSurface ? convert(parse(effectiveSurface), "oklch") : convert(accent, "oklch");
|
|
1501
|
+
if (surfaceHueShift !== 0 && !effectiveSurface) {
|
|
1256
1502
|
surfaceOklch = {
|
|
1257
1503
|
...surfaceOklch,
|
|
1258
1504
|
h: wrapHue(accentOklch.h + surfaceHueShift)
|
|
1259
1505
|
};
|
|
1260
1506
|
}
|
|
1261
|
-
const maxChroma =
|
|
1507
|
+
const maxChroma = themeAdjustments.maxChroma;
|
|
1262
1508
|
const invertedAccent = {
|
|
1263
1509
|
...surfaceOklch,
|
|
1264
1510
|
c: maxChroma !== void 0 ? Math.min(accentOklch.c, maxChroma) : accentOklch.c
|
|
@@ -1271,53 +1517,52 @@ function generateAccent(accent, themeType, options) {
|
|
|
1271
1517
|
// src/generate/generateSemanticColors.ts
|
|
1272
1518
|
var POSITIVE_RANGE = [120, 160];
|
|
1273
1519
|
var NEGATIVE_RANGE = [5, 30];
|
|
1274
|
-
var
|
|
1520
|
+
var CAUTION_RANGE = [45, 70];
|
|
1275
1521
|
function generateSemanticColors(color, themeType, options) {
|
|
1522
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1523
|
+
themeType,
|
|
1524
|
+
options ?? {}
|
|
1525
|
+
);
|
|
1526
|
+
const semanticColors = {
|
|
1527
|
+
positive: themeAdjustments.semanticColors?.positive,
|
|
1528
|
+
negative: themeAdjustments.semanticColors?.negative,
|
|
1529
|
+
caution: themeAdjustments.semanticColors?.caution
|
|
1530
|
+
};
|
|
1531
|
+
const semanticColorRanges = {
|
|
1532
|
+
positive: themeAdjustments.semanticColorRanges?.positive ?? POSITIVE_RANGE,
|
|
1533
|
+
negative: themeAdjustments.semanticColorRanges?.negative ?? NEGATIVE_RANGE,
|
|
1534
|
+
caution: themeAdjustments.semanticColorRanges?.caution ?? CAUTION_RANGE
|
|
1535
|
+
};
|
|
1276
1536
|
const positiveBaseColor = parse(
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
{ includeInputAsCandidate: true }
|
|
1281
|
-
)
|
|
1537
|
+
semanticColors.positive ?? _determineBaseColorFromRange(color, semanticColorRanges.positive, {
|
|
1538
|
+
includeInputAsCandidate: true
|
|
1539
|
+
})
|
|
1282
1540
|
);
|
|
1283
1541
|
const negativeBaseColor = parse(
|
|
1284
|
-
|
|
1285
|
-
color,
|
|
1286
|
-
options?.semanticColorRanges?.negative ?? NEGATIVE_RANGE
|
|
1287
|
-
)
|
|
1542
|
+
semanticColors.negative ?? _determineBaseColorFromRange(color, semanticColorRanges.negative)
|
|
1288
1543
|
);
|
|
1289
|
-
const
|
|
1290
|
-
|
|
1291
|
-
color,
|
|
1292
|
-
options?.semanticColorRanges?.warning ?? WARNING_RANGE
|
|
1293
|
-
)
|
|
1544
|
+
const cautionBaseColor = parse(
|
|
1545
|
+
semanticColors.caution ?? _determineBaseColorFromRange(color, semanticColorRanges.caution)
|
|
1294
1546
|
);
|
|
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
1547
|
const positiveColorScale = expandColorToScale(
|
|
1303
1548
|
positiveBaseColor,
|
|
1304
1549
|
themeType,
|
|
1305
|
-
|
|
1550
|
+
options
|
|
1306
1551
|
);
|
|
1307
1552
|
const negativeColorScale = expandColorToScale(
|
|
1308
1553
|
negativeBaseColor,
|
|
1309
1554
|
themeType,
|
|
1310
|
-
|
|
1555
|
+
options
|
|
1311
1556
|
);
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1557
|
+
const cautionColorScale = expandColorToScale(
|
|
1558
|
+
cautionBaseColor,
|
|
1314
1559
|
themeType,
|
|
1315
|
-
|
|
1560
|
+
options
|
|
1316
1561
|
);
|
|
1317
1562
|
return {
|
|
1318
1563
|
positive: positiveColorScale,
|
|
1319
1564
|
negative: negativeColorScale,
|
|
1320
|
-
|
|
1565
|
+
caution: cautionColorScale
|
|
1321
1566
|
};
|
|
1322
1567
|
}
|
|
1323
1568
|
function _determineBaseColorFromRange(color, range, options) {
|
|
@@ -1370,55 +1615,54 @@ function _getSplitComplementaryColors(color) {
|
|
|
1370
1615
|
}
|
|
1371
1616
|
|
|
1372
1617
|
// src/generate/generateSurface.ts
|
|
1373
|
-
var BASELINE_DARK_L_VALUE = 0.2;
|
|
1374
|
-
var BASELINE_LIGHT_L_VALUE = 0.97;
|
|
1375
1618
|
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
1619
|
function generateSurface(color, themeType, options) {
|
|
1381
1620
|
const invertSurfaceAndAccent = themeType === "dark" && options?.invertDarkModeSurfaceAccent;
|
|
1382
|
-
const
|
|
1383
|
-
|
|
1384
|
-
|
|
1621
|
+
const themeAdjustments = resolveMergedThemeAdjustments(
|
|
1622
|
+
themeType,
|
|
1623
|
+
options ?? {}
|
|
1624
|
+
);
|
|
1625
|
+
const effectiveSurfaceColor = themeAdjustments.surfaceColor;
|
|
1626
|
+
const preferredSurfaceColorInput = invertSurfaceAndAccent ? color ?? effectiveSurfaceColor : effectiveSurfaceColor ?? color;
|
|
1627
|
+
const surfaceMaxChroma = themeAdjustments.surfaceMaxChroma ?? BASELINE_MAX_CHROMA;
|
|
1385
1628
|
const preferredSurfaceColor = convert(
|
|
1386
1629
|
parse(preferredSurfaceColorInput),
|
|
1387
1630
|
"oklch"
|
|
1388
1631
|
);
|
|
1389
1632
|
let surfaceHue = preferredSurfaceColor.h;
|
|
1390
1633
|
const surfaceChroma = Math.min(preferredSurfaceColor.c, surfaceMaxChroma);
|
|
1391
|
-
const surfaceHueShift =
|
|
1392
|
-
if (surfaceHueShift !== 0 && !
|
|
1634
|
+
const surfaceHueShift = themeAdjustments.surfaceHueShift ?? 0;
|
|
1635
|
+
if (surfaceHueShift !== 0 && !effectiveSurfaceColor && !invertSurfaceAndAccent) {
|
|
1393
1636
|
surfaceHue = wrapHue(convert(color, "oklch").h + surfaceHueShift);
|
|
1394
1637
|
}
|
|
1638
|
+
const s = themeType === "light" ? SURFACE_SCALE.light : SURFACE_SCALE.dark;
|
|
1395
1639
|
const normalizedPreferredSurfaceColor = {
|
|
1396
1640
|
...preferredSurfaceColor,
|
|
1397
1641
|
h: surfaceHue,
|
|
1398
1642
|
c: surfaceChroma,
|
|
1399
|
-
l:
|
|
1643
|
+
l: s.L
|
|
1400
1644
|
};
|
|
1401
1645
|
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
|
|
1646
|
+
...options ?? {},
|
|
1647
|
+
baselineLValueLight: SURFACE_SCALE.light.L,
|
|
1648
|
+
baselineLValueDark: SURFACE_SCALE.dark.L,
|
|
1649
|
+
strongDeltaLight: SURFACE_SCALE.light.strong,
|
|
1650
|
+
strongDeltaDark: SURFACE_SCALE.dark.strong,
|
|
1651
|
+
weakDeltaLight: SURFACE_SCALE.light.weak,
|
|
1652
|
+
weakDeltaDark: SURFACE_SCALE.dark.weak
|
|
1413
1653
|
});
|
|
1414
1654
|
}
|
|
1415
1655
|
|
|
1416
1656
|
// src/generate/generate.ts
|
|
1417
1657
|
function generate(color, themeType, options) {
|
|
1658
|
+
const resolvedOptions = {
|
|
1659
|
+
...options ?? {},
|
|
1660
|
+
inputLightness: convert(color, "oklch").l
|
|
1661
|
+
};
|
|
1418
1662
|
return {
|
|
1419
|
-
surface: generateSurface(color, themeType,
|
|
1420
|
-
accent: generateAccent(color, themeType,
|
|
1421
|
-
...generateSemanticColors(color, themeType,
|
|
1663
|
+
surface: generateSurface(color, themeType, resolvedOptions),
|
|
1664
|
+
accent: generateAccent(color, themeType, resolvedOptions),
|
|
1665
|
+
...generateSemanticColors(color, themeType, resolvedOptions)
|
|
1422
1666
|
};
|
|
1423
1667
|
}
|
|
1424
1668
|
|