@tryghost/color-utils 0.1.21 → 0.1.23
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/es/color-utils.js +24 -31
- package/es/color-utils.js.map +1 -1
- package/package.json +5 -5
- package/umd/color-utils.min.js +1 -1
- package/umd/color-utils.min.js.map +1 -1
package/es/color-utils.js
CHANGED
|
@@ -2128,67 +2128,60 @@ function zeroArray(arr, length) {
|
|
|
2128
2128
|
var color = Color;
|
|
2129
2129
|
|
|
2130
2130
|
function lightenToContrastThreshold(foreground, background, contrastThreshold) {
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
var newColor = foregroundColor;
|
|
2139
|
-
|
|
2131
|
+
const foregroundColor = color(foreground);
|
|
2132
|
+
const backgroundColor = color(background);
|
|
2133
|
+
const {
|
|
2134
|
+
h,
|
|
2135
|
+
s
|
|
2136
|
+
} = foregroundColor.hsl().object();
|
|
2137
|
+
let newColor = foregroundColor;
|
|
2140
2138
|
while (newColor.contrast(backgroundColor) < contrastThreshold) {
|
|
2141
2139
|
if (newColor.lightness() >= 100) {
|
|
2142
2140
|
break;
|
|
2143
2141
|
}
|
|
2144
|
-
|
|
2145
2142
|
newColor = color({
|
|
2146
|
-
h
|
|
2147
|
-
s
|
|
2143
|
+
h,
|
|
2144
|
+
s,
|
|
2148
2145
|
l: newColor.lightness() + 5
|
|
2149
2146
|
});
|
|
2150
2147
|
}
|
|
2151
|
-
|
|
2152
2148
|
return newColor;
|
|
2153
2149
|
}
|
|
2154
2150
|
function darkenToContrastThreshold(foreground, background, contrastThreshold) {
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
var newColor = foregroundColor;
|
|
2163
|
-
|
|
2151
|
+
const foregroundColor = color(foreground);
|
|
2152
|
+
const backgroundColor = color(background);
|
|
2153
|
+
const {
|
|
2154
|
+
h,
|
|
2155
|
+
s
|
|
2156
|
+
} = foregroundColor.hsl().object();
|
|
2157
|
+
let newColor = foregroundColor;
|
|
2164
2158
|
while (newColor.contrast(backgroundColor) < contrastThreshold) {
|
|
2165
2159
|
if (newColor.lightness() <= 0) {
|
|
2166
2160
|
break;
|
|
2167
2161
|
}
|
|
2168
|
-
|
|
2169
2162
|
newColor = color({
|
|
2170
|
-
h
|
|
2171
|
-
s
|
|
2163
|
+
h,
|
|
2164
|
+
s,
|
|
2172
2165
|
l: newColor.lightness() - 5
|
|
2173
2166
|
});
|
|
2174
2167
|
}
|
|
2175
|
-
|
|
2176
2168
|
return newColor;
|
|
2177
2169
|
}
|
|
2178
2170
|
function textColorForBackgroundColor(background) {
|
|
2179
|
-
|
|
2180
|
-
|
|
2171
|
+
const backgroundColor = color(background);
|
|
2172
|
+
const white = color({
|
|
2181
2173
|
r: 255,
|
|
2182
2174
|
g: 255,
|
|
2183
2175
|
b: 255
|
|
2184
2176
|
});
|
|
2185
|
-
|
|
2177
|
+
const black = color({
|
|
2186
2178
|
r: 0,
|
|
2187
2179
|
g: 0,
|
|
2188
2180
|
b: 0
|
|
2189
|
-
});
|
|
2181
|
+
});
|
|
2190
2182
|
|
|
2191
|
-
|
|
2183
|
+
// shared with Portal https://github.com/TryGhost/Portal/blob/317876f20d22431df15e655ea6cc197fe636615e/src/utils/contrast-color.js#L26-L29
|
|
2184
|
+
const yiq = backgroundColor.red() * 0.299 + backgroundColor.green() * 0.587 + backgroundColor.b() * 0.114;
|
|
2192
2185
|
return yiq >= 186 ? black : white;
|
|
2193
2186
|
}
|
|
2194
2187
|
|