updates
This commit is contained in:
parent
7b657fcccd
commit
1723f427f5
21 changed files with 145 additions and 113 deletions
|
@ -81,29 +81,27 @@ const getContrastRatio = (a, b) => {
|
|||
|
||||
/**
|
||||
* This generates what "worst case" color would look like for transparent
|
||||
* segments. I.e. black with .2 alpha and pure-white background image
|
||||
* could make white text unreadable
|
||||
* segments. I.e. transparent black with yellow text over yellow background.
|
||||
*
|
||||
* @param {Object} srgb - transparent color
|
||||
* @param {Number} alpha - color's opacity/alpha channel
|
||||
* @param {Boolean} white - use white "background" if true, black otherwise
|
||||
* @param {Object} textSrgb - text color (considered as worst case scenario for transparent background)
|
||||
* @returns {Object} sRGB of resulting color
|
||||
*/
|
||||
const transparentWorstCase = (srgb, alpha, white = false) => {
|
||||
const bg = 'rgb'.split('').reduce((acc, c) => { acc[c] = Number(white) * 255; return acc }, {})
|
||||
const transparentWorstCase = (srgb, alpha, textSrgb) => {
|
||||
return 'rgb'.split('').reduce((acc, c) => {
|
||||
// Simplified https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
|
||||
// for opaque bg and transparent fg
|
||||
acc[c] = (srgb[c] * alpha + bg[c] * (1 - alpha))
|
||||
acc[c] = (srgb[c] * alpha + textSrgb[c] * (1 - alpha))
|
||||
return acc
|
||||
}, {})
|
||||
}
|
||||
|
||||
const worstCase = (bg, bga, text) => {
|
||||
console.log(bg)
|
||||
console.log(text)
|
||||
if (bga === 1 || typeof bga === 'undefined') return bg
|
||||
// taken from https://github.com/toish/chromatism/blob/master/src/operations/contrastRatio.js
|
||||
const blackWorse = ((text.r * 299) + (text.g * 587) + (text.b * 114)) / 1000 <= 128
|
||||
return transparentWorstCase(bg, bga, !blackWorse)
|
||||
return transparentWorstCase(bg, bga, text)
|
||||
}
|
||||
|
||||
const hex2rgb = (hex) => {
|
||||
|
|
|
@ -155,12 +155,14 @@ const generatePreset = (input) => {
|
|||
colors.cGreen = col.cGreen
|
||||
colors.cOrange = col.cOrange
|
||||
|
||||
colors.cAlertRed = col.cAlertRed || Object.assign({}, col.cRed)
|
||||
colors.alertError = col.alertError || Object.assign({}, col.cRed)
|
||||
colors.badgeNotification = col.badgeNotification || Object.assign({}, col.cRed)
|
||||
colors.badgeNotificationText = col.badgeNotification || Object.assign({}, col.cRed)
|
||||
|
||||
Object.entries(opacity).forEach(([ k, v ]) => {
|
||||
if (typeof v === 'undefined') return
|
||||
if (k === 'alert') {
|
||||
colors.cAlertRed.a = v
|
||||
colors.alertError.a = v
|
||||
return
|
||||
}
|
||||
if (k === 'faint') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue