]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Resolve canvasGradient is undefined in node (#10328)
authorJacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
Tue, 3 May 2022 12:21:43 +0000 (14:21 +0200)
committerGitHub <noreply@github.com>
Tue, 3 May 2022 12:21:43 +0000 (08:21 -0400)
* Resolve canvasgradient is not defined in node

* Remove trailing white space

* export isPaternOrGradient helper with typings

* fix lint failure, single qoute

* Allow for string inputs too to function

src/helpers/helpers.color.js
types/helpers/helpers.color.d.ts

index 62e66716153e4ddde1662891b4d19d19ae7b5523..9394751de85d0c2275a842bf18610a84887fcca4 100644 (file)
@@ -1,6 +1,13 @@
 import colorLib from '@kurkle/color';
 
-const isPatternOrGradient = (value) => value instanceof CanvasGradient || value instanceof CanvasPattern;
+export function 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);
index 3cfc20ea77fa746869013741f3a75e6af62f5f4e..460b8d1fe1a1328d807ee2a8c0395f6a3c887f6d 100644 (file)
@@ -1,3 +1,5 @@
+import { AnyObject } from '../basic';
+
 export function color(value: CanvasGradient): CanvasGradient;
 export function color(value: CanvasPattern): CanvasPattern;
 export function color(
@@ -8,6 +10,8 @@ export function color(
   | [number, number, number, number]
 ): ColorModel;
 
+export function isPatternOrGradient(value: string | AnyObject): boolean;
+
 export interface ColorModel {
   rgbString(): string;
   hexString(): string;