mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
move ui & assets to package directory
This commit is contained in:
28
hyperglass/ui/util.js
Normal file
28
hyperglass/ui/util.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import chroma from "chroma-js";
|
||||
|
||||
const isDark = color => {
|
||||
// YIQ equation from http://24ways.org/2010/calculating-color-contrast
|
||||
const rgb = chroma(color).rgb();
|
||||
const yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
|
||||
return yiq < 128;
|
||||
};
|
||||
|
||||
const isLight = color => isDark(color);
|
||||
|
||||
const opposingColor = (theme, color) => {
|
||||
const opposing = isDark(color) ? theme.colors.white : theme.colors.black;
|
||||
return opposing;
|
||||
};
|
||||
|
||||
const googleFontUrl = (fontFamily, weights = [300, 400, 700]) => {
|
||||
const urlWeights = weights.join(",");
|
||||
const fontName = fontFamily
|
||||
.split(/, /)[0]
|
||||
.trim()
|
||||
.replace(/'|"/g, "");
|
||||
const urlFont = fontName.split(/ /).join("+");
|
||||
const urlBase = `https://fonts.googleapis.com/css?family=${urlFont}:${urlWeights}&display=swap`;
|
||||
return urlBase;
|
||||
};
|
||||
|
||||
export { isDark, isLight, opposingColor, googleFontUrl };
|
Reference in New Issue
Block a user