Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve canvasGradient is undefined in node #10328

Merged
merged 5 commits into from May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/helpers/helpers.color.js
@@ -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);
Expand Down
4 changes: 4 additions & 0 deletions types/helpers/helpers.color.d.ts
@@ -1,3 +1,5 @@
import { AnyObject } from '../basic';

export function color(value: CanvasGradient): CanvasGradient;
export function color(value: CanvasPattern): CanvasPattern;
export function color(
Expand All @@ -8,6 +10,8 @@ export function color(
| [number, number, number, number]
): ColorModel;

export function isPatternOrGradient(value: AnyObject): boolean;
LeeLenaleee marked this conversation as resolved.
Show resolved Hide resolved

export interface ColorModel {
rgbString(): string;
hexString(): string;
Expand Down