@tenphi/glaze 0.0.0-snapshot.709df23 → 0.0.0-snapshot.75f81fa
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/README.md +20 -12
- package/dist/index.cjs +39 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +39 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -812,6 +812,7 @@ let globalConfig = {
|
|
|
812
812
|
lightLightness: [10, 100],
|
|
813
813
|
darkLightness: [15, 95],
|
|
814
814
|
darkDesaturation: .1,
|
|
815
|
+
darkCurve: .5,
|
|
815
816
|
states: {
|
|
816
817
|
dark: "@dark",
|
|
817
818
|
highContrast: "@high-contrast"
|
|
@@ -959,24 +960,42 @@ function topoSort(defs) {
|
|
|
959
960
|
for (const name of Object.keys(defs)) visit(name);
|
|
960
961
|
return result;
|
|
961
962
|
}
|
|
962
|
-
function
|
|
963
|
+
function lightnessWindow(isHighContrast, kind) {
|
|
964
|
+
if (isHighContrast) return [0, 100];
|
|
965
|
+
return kind === "dark" ? globalConfig.darkLightness : globalConfig.lightLightness;
|
|
966
|
+
}
|
|
967
|
+
function mapLightnessLight(l, mode, isHighContrast) {
|
|
963
968
|
if (mode === "static") return l;
|
|
964
|
-
const [lo, hi] =
|
|
969
|
+
const [lo, hi] = lightnessWindow(isHighContrast, "light");
|
|
965
970
|
return l * (hi - lo) / 100 + lo;
|
|
966
971
|
}
|
|
967
|
-
function
|
|
972
|
+
function mobiusCurve(t, beta) {
|
|
973
|
+
if (beta >= 1) return t;
|
|
974
|
+
return t / (t + beta * (1 - t));
|
|
975
|
+
}
|
|
976
|
+
function mapLightnessDark(l, mode, isHighContrast) {
|
|
968
977
|
if (mode === "static") return l;
|
|
969
|
-
const
|
|
970
|
-
|
|
971
|
-
|
|
978
|
+
const beta = globalConfig.darkCurve;
|
|
979
|
+
const [darkLo, darkHi] = lightnessWindow(isHighContrast, "dark");
|
|
980
|
+
if (mode === "fixed") return l * (darkHi - darkLo) / 100 + darkLo;
|
|
981
|
+
const [lightLo, lightHi] = lightnessWindow(isHighContrast, "light");
|
|
982
|
+
const t = (lightHi - (l * (lightHi - lightLo) / 100 + lightLo)) / (lightHi - lightLo);
|
|
983
|
+
return darkLo + (darkHi - darkLo) * mobiusCurve(t, beta);
|
|
984
|
+
}
|
|
985
|
+
function lightMappedToDark(lightL, isHighContrast) {
|
|
986
|
+
const beta = globalConfig.darkCurve;
|
|
987
|
+
const [lightLo, lightHi] = lightnessWindow(isHighContrast, "light");
|
|
988
|
+
const [darkLo, darkHi] = lightnessWindow(isHighContrast, "dark");
|
|
989
|
+
const t = (lightHi - clamp(lightL, lightLo, lightHi)) / (lightHi - lightLo);
|
|
990
|
+
return darkLo + (darkHi - darkLo) * mobiusCurve(t, beta);
|
|
972
991
|
}
|
|
973
992
|
function mapSaturationDark(s, mode) {
|
|
974
993
|
if (mode === "static") return s;
|
|
975
994
|
return s * (1 - globalConfig.darkDesaturation);
|
|
976
995
|
}
|
|
977
|
-
function schemeLightnessRange(isDark, mode) {
|
|
996
|
+
function schemeLightnessRange(isDark, mode, isHighContrast) {
|
|
978
997
|
if (mode === "static") return [0, 1];
|
|
979
|
-
const [lo, hi] = isDark ?
|
|
998
|
+
const [lo, hi] = lightnessWindow(isHighContrast, isDark ? "dark" : "light");
|
|
980
999
|
return [lo / 100, hi / 100];
|
|
981
1000
|
}
|
|
982
1001
|
function clamp(v, min, max) {
|
|
@@ -1035,26 +1054,26 @@ function resolveDependentColor(name, def, ctx, isHighContrast, isDark, effective
|
|
|
1035
1054
|
else {
|
|
1036
1055
|
const parsed = parseRelativeOrAbsolute(isHighContrast ? pairHC(rawLightness) : pairNormal(rawLightness));
|
|
1037
1056
|
if (parsed.relative) {
|
|
1038
|
-
|
|
1039
|
-
if (isDark && mode === "auto")
|
|
1040
|
-
preferredL = clamp(baseL + delta, 0, 100);
|
|
1041
|
-
} else if (isDark) preferredL = mapLightnessDark(parsed.value, mode);
|
|
1042
|
-
else preferredL = mapLightnessLight(parsed.value, mode);
|
|
1057
|
+
const delta = parsed.value;
|
|
1058
|
+
if (isDark && mode === "auto") preferredL = lightMappedToDark(clamp(getSchemeVariant(baseResolved, false, isHighContrast).l * 100 + delta, 0, 100), isHighContrast);
|
|
1059
|
+
else preferredL = clamp(baseL + delta, 0, 100);
|
|
1060
|
+
} else if (isDark) preferredL = mapLightnessDark(parsed.value, mode, isHighContrast);
|
|
1061
|
+
else preferredL = mapLightnessLight(parsed.value, mode, isHighContrast);
|
|
1043
1062
|
}
|
|
1044
1063
|
const rawContrast = def.contrast;
|
|
1045
1064
|
if (rawContrast !== void 0) {
|
|
1046
1065
|
const minCr = isHighContrast ? pairHC(rawContrast) : pairNormal(rawContrast);
|
|
1047
1066
|
const effectiveSat = isDark ? mapSaturationDark(satFactor * ctx.saturation / 100, mode) : satFactor * ctx.saturation / 100;
|
|
1048
1067
|
const baseLinearRgb = okhslToLinearSrgb(baseVariant.h, baseVariant.s, baseVariant.l);
|
|
1049
|
-
const
|
|
1068
|
+
const windowRange = schemeLightnessRange(isDark, mode, isHighContrast);
|
|
1050
1069
|
return {
|
|
1051
1070
|
l: findLightnessForContrast({
|
|
1052
1071
|
hue: effectiveHue,
|
|
1053
1072
|
saturation: effectiveSat,
|
|
1054
|
-
preferredLightness: clamp(preferredL / 100,
|
|
1073
|
+
preferredLightness: clamp(preferredL / 100, windowRange[0], windowRange[1]),
|
|
1055
1074
|
baseLinearRgb,
|
|
1056
1075
|
contrast: minCr,
|
|
1057
|
-
lightnessRange
|
|
1076
|
+
lightnessRange: [0, 1]
|
|
1058
1077
|
}).lightness * 100,
|
|
1059
1078
|
satFactor
|
|
1060
1079
|
};
|
|
@@ -1091,13 +1110,13 @@ function resolveColorForScheme(name, def, ctx, isDark, isHighContrast) {
|
|
|
1091
1110
|
let finalL;
|
|
1092
1111
|
let finalSat;
|
|
1093
1112
|
if (isDark && isRoot) {
|
|
1094
|
-
finalL = mapLightnessDark(lightL, mode);
|
|
1113
|
+
finalL = mapLightnessDark(lightL, mode, isHighContrast);
|
|
1095
1114
|
finalSat = mapSaturationDark(satFactor * ctx.saturation / 100, mode);
|
|
1096
1115
|
} else if (isDark && !isRoot) {
|
|
1097
1116
|
finalL = lightL;
|
|
1098
1117
|
finalSat = mapSaturationDark(satFactor * ctx.saturation / 100, mode);
|
|
1099
1118
|
} else if (isRoot) {
|
|
1100
|
-
finalL = mapLightnessLight(lightL, mode);
|
|
1119
|
+
finalL = mapLightnessLight(lightL, mode, isHighContrast);
|
|
1101
1120
|
finalSat = satFactor * ctx.saturation / 100;
|
|
1102
1121
|
} else {
|
|
1103
1122
|
finalL = lightL;
|
|
@@ -1563,6 +1582,7 @@ glaze.configure = function configure(config) {
|
|
|
1563
1582
|
lightLightness: config.lightLightness ?? globalConfig.lightLightness,
|
|
1564
1583
|
darkLightness: config.darkLightness ?? globalConfig.darkLightness,
|
|
1565
1584
|
darkDesaturation: config.darkDesaturation ?? globalConfig.darkDesaturation,
|
|
1585
|
+
darkCurve: config.darkCurve ?? globalConfig.darkCurve,
|
|
1566
1586
|
states: {
|
|
1567
1587
|
dark: config.states?.dark ?? globalConfig.states.dark,
|
|
1568
1588
|
highContrast: config.states?.highContrast ?? globalConfig.states.highContrast
|
|
@@ -1662,6 +1682,7 @@ glaze.resetConfig = function resetConfig() {
|
|
|
1662
1682
|
lightLightness: [10, 100],
|
|
1663
1683
|
darkLightness: [15, 95],
|
|
1664
1684
|
darkDesaturation: .1,
|
|
1685
|
+
darkCurve: .5,
|
|
1665
1686
|
states: {
|
|
1666
1687
|
dark: "@dark",
|
|
1667
1688
|
highContrast: "@high-contrast"
|