Move color helpers to helpers.color (#7130)

Move color helpers to helpers.color
This commit is contained in:
Jukka Kurkela
2020-02-20 01:14:22 +02:00
committed by GitHub
parent 9ddda713e4
commit 4a737729d5
2 changed files with 27 additions and 18 deletions

View File

@@ -0,0 +1,24 @@
import colorLib from '@kurkle/color';
/**
* @param {string | CanvasGradient | CanvasPattern} value
*/
const isPatternOrGradient = (value) => value instanceof CanvasGradient || value instanceof CanvasPattern;
/**
* @param {string|CanvasGradient|CanvasPattern} value
* @return {CanvasGradient|CanvasPattern|colorLib}
*/
export function color(value) {
return isPatternOrGradient(value) ? value : colorLib(value);
}
/**
* @param {string|CanvasGradient|CanvasPattern} value
* @return {string|CanvasGradient|CanvasPattern}
*/
export function getHoverColor(value) {
return isPatternOrGradient(value)
? value
: colorLib(value).saturate(0.5).darken(0.1).hexString();
}

View File

@@ -1,7 +1,5 @@
/* eslint-disable import/no-namespace */
import color from '@kurkle/color';
import * as coreHelpers from './helpers.core';
import * as canvas from './helpers.canvas';
import * as curve from './helpers.curve';
@@ -11,16 +9,7 @@ import * as options from './helpers.options';
import * as math from './helpers.math';
import * as rtl from './helpers.rtl';
const colorHelper =
function(value) {
if (value instanceof CanvasGradient || value instanceof CanvasPattern) {
// TODO: figure out what this should be. Previously returned
// the default color
return value;
}
return color(value);
};
import {color, getHoverColor} from './helpers.color';
export default {
...coreHelpers,
@@ -45,10 +34,6 @@ export default {
fontString(pixelSize, fontStyle, fontFamily) {
return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
},
color: colorHelper,
getHoverColor(colorValue) {
return (colorValue instanceof CanvasPattern || colorValue instanceof CanvasGradient) ?
colorValue :
colorHelper(colorValue).saturate(0.5).darken(0.1).hexString();
}
color,
getHoverColor
};