--- /dev/null
+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();
+}
/* 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';
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,
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
};