"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RGBComponent = RGBComponent; exports.alphaComponent = alphaComponent; exports.getNumberValidator = getNumberValidator; exports.getNumberOrArrayOfNumbersValidator = getNumberOrArrayOfNumbersValidator; exports.getNumberOrAutoValidator = getNumberOrAutoValidator; exports.getStringValidator = getStringValidator; exports.getStringOrGradientValidator = getStringOrGradientValidator; exports.getFunctionValidator = getFunctionValidator; exports.getNumberArrayValidator = getNumberArrayValidator; exports.getBooleanValidator = getBooleanValidator; exports.getComponentValidator = getComponentValidator; const Global_1 = require("./Global"); const 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); } function alphaComponent(val) { if (val > 1) { return 1; } else if (val < 0.0001) { return 0.0001; } return val; } 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; }; } } function getNumberOrArrayOfNumbersValidator(noOfElements) { if (Global_1.Konva.isUnminified) { return function (val, attr) { const isNumber = Util_1.Util._isNumber(val); const isValidArray = Util_1.Util._isArray(val) && val.length == noOfElements; if (!isNumber && !isValidArray) { Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a number or Array(' + noOfElements + ')'); } return val; }; } } function getNumberOrAutoValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { const isNumber = Util_1.Util._isNumber(val); const 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; }; } } 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; }; } } function getStringOrGradientValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { const isString = Util_1.Util._isString(val); const isGradient = Object.prototype.toString.call(val) === '[object CanvasGradient]' || (val && val.addColorStop); if (!(isString || isGradient)) { Util_1.Util.warn(_formatValue(val) + ' is a not valid value for "' + attr + '" attribute. The value should be a string or a native gradient.'); } return val; }; } } 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; }; } } function getNumberArrayValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null; if (TypedArray && val instanceof TypedArray) { return val; } 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; }; } } function getBooleanValidator() { if (Global_1.Konva.isUnminified) { return function (val, attr) { const 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; }; } } function getComponentValidator(components) { if (Global_1.Konva.isUnminified) { return function (val, attr) { if (val === undefined || val === null) { return val; } 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; }; } }