mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
string
and fill
properties validation can accept CanvasGradient
as valid value. close #965
This commit is contained in:
15
src/Shape.ts
15
src/Shape.ts
@@ -6,6 +6,7 @@ import {
|
||||
getNumberOrAutoValidator,
|
||||
getStringValidator,
|
||||
getBooleanValidator,
|
||||
getStringOrGradientValidator,
|
||||
} from './Validators';
|
||||
|
||||
import { Context, SceneContext } from './Context';
|
||||
@@ -849,7 +850,12 @@ Shape.prototype.on.call(
|
||||
);
|
||||
|
||||
// add getters and setters
|
||||
Factory.addGetterSetter(Shape, 'stroke', undefined, getStringValidator());
|
||||
Factory.addGetterSetter(
|
||||
Shape,
|
||||
'stroke',
|
||||
undefined,
|
||||
getStringOrGradientValidator()
|
||||
);
|
||||
|
||||
/**
|
||||
* get/set stroke color
|
||||
@@ -1220,7 +1226,12 @@ Factory.addGetterSetter(Shape, 'fillPatternImage');
|
||||
* imageObj.src = 'path/to/image/jpg';
|
||||
*/
|
||||
|
||||
Factory.addGetterSetter(Shape, 'fill', undefined, getStringValidator());
|
||||
Factory.addGetterSetter(
|
||||
Shape,
|
||||
'fill',
|
||||
undefined,
|
||||
getStringOrGradientValidator()
|
||||
);
|
||||
|
||||
/**
|
||||
* get/set fill color
|
||||
|
@@ -66,6 +66,7 @@ export function getNumberOrAutoValidator() {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function getStringValidator() {
|
||||
if (Konva.isUnminified) {
|
||||
return function (val: any, attr: string) {
|
||||
@@ -81,6 +82,26 @@ export function getStringValidator() {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function getStringOrGradientValidator() {
|
||||
if (Konva.isUnminified) {
|
||||
return function (val: any, attr: string) {
|
||||
const isString = Util._isString(val);
|
||||
const isGradient =
|
||||
Object.prototype.toString.call(val) === '[object CanvasGradient]';
|
||||
if (!(isString || isGradient)) {
|
||||
Util.warn(
|
||||
_formatValue(val) +
|
||||
' is a not valid value for "' +
|
||||
attr +
|
||||
'" attribute. The value should be a string or a native gradient.'
|
||||
);
|
||||
}
|
||||
return val;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function getFunctionValidator() {
|
||||
if (Konva.isUnminified) {
|
||||
return function (val: any, attr: string) {
|
||||
|
@@ -84,6 +84,6 @@ export const Konva = Core.Util._assign(Core, {
|
||||
RGBA,
|
||||
Sepia,
|
||||
Solarize,
|
||||
Threshold
|
||||
}
|
||||
Threshold,
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user