UNPKG

konva

Version:

<p align="center"> <img src="https://raw.githubusercontent.com/konvajs/konvajs.github.io/master/apple-touch-icon-180x180.png" alt="Konva logo" height="180" /> </p>

150 lines (149 loc) 4.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Global_1 = require("./Global"); var Util_1 = require("./Util"); function _formatValue(val) { if (Util_1.Util._isString(val)) { return '"' + val + '"'; } if (Object.prototype.toString.call(val) === '[object Number]') { return val; } if (Util_1.Util._isBoolean(val)) { return val; } return Object.prototype.toString.call(val); } function RGBComponent(val) { if (val > 255) { return 255; } else if (val < 0) { return 0; } return Math.round(val); } exports.RGBComponent = RGBComponent; function alphaComponent(val) { if (val > 1) { return 1; } else if (val < 0.0001) { return 0.0001; } return val; } exports.alphaComponent = alphaComponent; function getNumberValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { if (!Util_1.Util._isNumber(val)) { Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a number.'); } return val; }; } } exports.getNumberValidator = getNumberValidator; function getNumberOrAutoValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { var isNumber = Util_1.Util._isNumber(val); var isAuto = val === 'auto'; if (!(isNumber || isAuto)) { Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a number or "auto".'); } return val; }; } } exports.getNumberOrAutoValidator = getNumberOrAutoValidator; function getStringValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { if (!Util_1.Util._isString(val)) { Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a string.'); } return val; }; } } exports.getStringValidator = getStringValidator; function getFunctionValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { if (!Util_1.Util._isFunction(val)) { Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a function.'); } return val; }; } } exports.getFunctionValidator = getFunctionValidator; function getNumberArrayValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { if (!Util_1.Util._isArray(val)) { Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a array of numbers.'); } else { val.forEach(function (item) { if (!Util_1.Util._isNumber(item)) { Util_1.Util.warn('"' + attr + '" attribute has non numeric element ' + item + '. Make sure that all elements are numbers.'); } }); } return val; }; } } exports.getNumberArrayValidator = getNumberArrayValidator; function getBooleanValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { var isBool = val === true || val === false; if (!isBool) { Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a boolean.'); } return val; }; } } exports.getBooleanValidator = getBooleanValidator; function getComponentValidator(components) { if (Global_1.Konva.isUnminified) { return function (val, attr) { if (!Util_1.Util.isObject(val)) { Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be an object with properties ' + components); } return val; }; } } exports.getComponentValidator = getComponentValidator;