Ghost/ghost/admin/app/helpers/hex-adjust.js
Kevin Ansfield eed299d1f6 Matched Portal's contrast threshold for white/black text on background color
refs https://github.com/TryGhost/Team/issues/928

- switched to using `color` for color conversion and adjustments rather than maintaining our own limited utils (preparation to extract our own utils to separate library)
- changed contrast threshold for yiq-based contrast adjustment from `128` to `186` to match Portal's current behaviour
2021-07-28 17:14:33 +01:00

19 lines
470 B
JavaScript

import Color from 'color';
import {helper} from '@ember/component/helper';
export default helper(function hexAdjuster([hex], {s: sDiff = 0, l: lDiff = 0} = {}) {
const originalColor = Color(hex);
let newColor = originalColor;
if (sDiff !== 0) {
newColor = newColor.saturationl(newColor.saturationl() + sDiff);
}
if (lDiff !== 0) {
newColor = newColor.lightness(newColor.lightness() + lDiff);
}
return newColor.hex();
});