Skip to content
Next Next commit
Resolve canvasgradient is not defined in node
  • Loading branch information
LeeLenaleee authored Apr 29, 2022
commit 2e1e0280af3a64cada919e658d30b509a6fb8df2
9 changes: 8 additions & 1 deletion src/helpers/helpers.color.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import colorLib from '@kurkle/color';

const isPatternOrGradient = (value) => value instanceof CanvasGradient || value instanceof CanvasPattern;
const isPatternOrGradient = (value) => {
if (value && typeof value === 'object') {
const type = value.toString();
return type === '[object CanvasPattern]' || type === '[object CanvasGradient]';
}

return false;
};

export function color(value) {
return isPatternOrGradient(value) ? value : colorLib(value);
Expand Down