mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 04:09:08 +02:00
Resolve canvasGradient is undefined in node (#10328)
* 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
This commit is contained in:
parent
a9765042f1
commit
2c268f0943
@ -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);
|
||||
|
4
types/helpers/helpers.color.d.ts
vendored
4
types/helpers/helpers.color.d.ts
vendored
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user