[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
[0c6b92a] | 3 | exports.RGBComponent = RGBComponent;
|
---|
| 4 | exports.alphaComponent = alphaComponent;
|
---|
| 5 | exports.getNumberValidator = getNumberValidator;
|
---|
| 6 | exports.getNumberOrArrayOfNumbersValidator = getNumberOrArrayOfNumbersValidator;
|
---|
| 7 | exports.getNumberOrAutoValidator = getNumberOrAutoValidator;
|
---|
| 8 | exports.getStringValidator = getStringValidator;
|
---|
| 9 | exports.getStringOrGradientValidator = getStringOrGradientValidator;
|
---|
| 10 | exports.getFunctionValidator = getFunctionValidator;
|
---|
| 11 | exports.getNumberArrayValidator = getNumberArrayValidator;
|
---|
| 12 | exports.getBooleanValidator = getBooleanValidator;
|
---|
| 13 | exports.getComponentValidator = getComponentValidator;
|
---|
[d565449] | 14 | const Global_1 = require("./Global");
|
---|
| 15 | const Util_1 = require("./Util");
|
---|
| 16 | function _formatValue(val) {
|
---|
| 17 | if (Util_1.Util._isString(val)) {
|
---|
| 18 | return '"' + val + '"';
|
---|
| 19 | }
|
---|
| 20 | if (Object.prototype.toString.call(val) === '[object Number]') {
|
---|
| 21 | return val;
|
---|
| 22 | }
|
---|
| 23 | if (Util_1.Util._isBoolean(val)) {
|
---|
| 24 | return val;
|
---|
| 25 | }
|
---|
| 26 | return Object.prototype.toString.call(val);
|
---|
| 27 | }
|
---|
| 28 | function RGBComponent(val) {
|
---|
| 29 | if (val > 255) {
|
---|
| 30 | return 255;
|
---|
| 31 | }
|
---|
| 32 | else if (val < 0) {
|
---|
| 33 | return 0;
|
---|
| 34 | }
|
---|
| 35 | return Math.round(val);
|
---|
| 36 | }
|
---|
| 37 | function alphaComponent(val) {
|
---|
| 38 | if (val > 1) {
|
---|
| 39 | return 1;
|
---|
| 40 | }
|
---|
| 41 | else if (val < 0.0001) {
|
---|
| 42 | return 0.0001;
|
---|
| 43 | }
|
---|
| 44 | return val;
|
---|
| 45 | }
|
---|
| 46 | function getNumberValidator() {
|
---|
| 47 | if (Global_1.Konva.isUnminified) {
|
---|
| 48 | return function (val, attr) {
|
---|
| 49 | if (!Util_1.Util._isNumber(val)) {
|
---|
| 50 | Util_1.Util.warn(_formatValue(val) +
|
---|
| 51 | ' is a not valid value for "' +
|
---|
| 52 | attr +
|
---|
| 53 | '" attribute. The value should be a number.');
|
---|
| 54 | }
|
---|
| 55 | return val;
|
---|
| 56 | };
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | function getNumberOrArrayOfNumbersValidator(noOfElements) {
|
---|
| 60 | if (Global_1.Konva.isUnminified) {
|
---|
| 61 | return function (val, attr) {
|
---|
[0c6b92a] | 62 | const isNumber = Util_1.Util._isNumber(val);
|
---|
| 63 | const isValidArray = Util_1.Util._isArray(val) && val.length == noOfElements;
|
---|
[d565449] | 64 | if (!isNumber && !isValidArray) {
|
---|
| 65 | Util_1.Util.warn(_formatValue(val) +
|
---|
| 66 | ' is a not valid value for "' +
|
---|
| 67 | attr +
|
---|
| 68 | '" attribute. The value should be a number or Array<number>(' +
|
---|
| 69 | noOfElements +
|
---|
| 70 | ')');
|
---|
| 71 | }
|
---|
| 72 | return val;
|
---|
| 73 | };
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | function getNumberOrAutoValidator() {
|
---|
| 77 | if (Global_1.Konva.isUnminified) {
|
---|
| 78 | return function (val, attr) {
|
---|
[0c6b92a] | 79 | const isNumber = Util_1.Util._isNumber(val);
|
---|
| 80 | const isAuto = val === 'auto';
|
---|
[d565449] | 81 | if (!(isNumber || isAuto)) {
|
---|
| 82 | Util_1.Util.warn(_formatValue(val) +
|
---|
| 83 | ' is a not valid value for "' +
|
---|
| 84 | attr +
|
---|
| 85 | '" attribute. The value should be a number or "auto".');
|
---|
| 86 | }
|
---|
| 87 | return val;
|
---|
| 88 | };
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | function getStringValidator() {
|
---|
| 92 | if (Global_1.Konva.isUnminified) {
|
---|
| 93 | return function (val, attr) {
|
---|
| 94 | if (!Util_1.Util._isString(val)) {
|
---|
| 95 | Util_1.Util.warn(_formatValue(val) +
|
---|
| 96 | ' is a not valid value for "' +
|
---|
| 97 | attr +
|
---|
| 98 | '" attribute. The value should be a string.');
|
---|
| 99 | }
|
---|
| 100 | return val;
|
---|
| 101 | };
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | function getStringOrGradientValidator() {
|
---|
| 105 | if (Global_1.Konva.isUnminified) {
|
---|
| 106 | return function (val, attr) {
|
---|
| 107 | const isString = Util_1.Util._isString(val);
|
---|
| 108 | const isGradient = Object.prototype.toString.call(val) === '[object CanvasGradient]' ||
|
---|
| 109 | (val && val.addColorStop);
|
---|
| 110 | if (!(isString || isGradient)) {
|
---|
| 111 | Util_1.Util.warn(_formatValue(val) +
|
---|
| 112 | ' is a not valid value for "' +
|
---|
| 113 | attr +
|
---|
| 114 | '" attribute. The value should be a string or a native gradient.');
|
---|
| 115 | }
|
---|
| 116 | return val;
|
---|
| 117 | };
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | function getFunctionValidator() {
|
---|
| 121 | if (Global_1.Konva.isUnminified) {
|
---|
| 122 | return function (val, attr) {
|
---|
| 123 | if (!Util_1.Util._isFunction(val)) {
|
---|
| 124 | Util_1.Util.warn(_formatValue(val) +
|
---|
| 125 | ' is a not valid value for "' +
|
---|
| 126 | attr +
|
---|
| 127 | '" attribute. The value should be a function.');
|
---|
| 128 | }
|
---|
| 129 | return val;
|
---|
| 130 | };
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | function getNumberArrayValidator() {
|
---|
| 134 | if (Global_1.Konva.isUnminified) {
|
---|
| 135 | return function (val, attr) {
|
---|
| 136 | const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
|
---|
| 137 | if (TypedArray && val instanceof TypedArray) {
|
---|
| 138 | return val;
|
---|
| 139 | }
|
---|
| 140 | if (!Util_1.Util._isArray(val)) {
|
---|
| 141 | Util_1.Util.warn(_formatValue(val) +
|
---|
| 142 | ' is a not valid value for "' +
|
---|
| 143 | attr +
|
---|
| 144 | '" attribute. The value should be a array of numbers.');
|
---|
| 145 | }
|
---|
| 146 | else {
|
---|
| 147 | val.forEach(function (item) {
|
---|
| 148 | if (!Util_1.Util._isNumber(item)) {
|
---|
| 149 | Util_1.Util.warn('"' +
|
---|
| 150 | attr +
|
---|
| 151 | '" attribute has non numeric element ' +
|
---|
| 152 | item +
|
---|
| 153 | '. Make sure that all elements are numbers.');
|
---|
| 154 | }
|
---|
| 155 | });
|
---|
| 156 | }
|
---|
| 157 | return val;
|
---|
| 158 | };
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 | function getBooleanValidator() {
|
---|
| 162 | if (Global_1.Konva.isUnminified) {
|
---|
| 163 | return function (val, attr) {
|
---|
[0c6b92a] | 164 | const isBool = val === true || val === false;
|
---|
[d565449] | 165 | if (!isBool) {
|
---|
| 166 | Util_1.Util.warn(_formatValue(val) +
|
---|
| 167 | ' is a not valid value for "' +
|
---|
| 168 | attr +
|
---|
| 169 | '" attribute. The value should be a boolean.');
|
---|
| 170 | }
|
---|
| 171 | return val;
|
---|
| 172 | };
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | function getComponentValidator(components) {
|
---|
| 176 | if (Global_1.Konva.isUnminified) {
|
---|
| 177 | return function (val, attr) {
|
---|
| 178 | if (val === undefined || val === null) {
|
---|
| 179 | return val;
|
---|
| 180 | }
|
---|
| 181 | if (!Util_1.Util.isObject(val)) {
|
---|
| 182 | Util_1.Util.warn(_formatValue(val) +
|
---|
| 183 | ' is a not valid value for "' +
|
---|
| 184 | attr +
|
---|
| 185 | '" attribute. The value should be an object with properties ' +
|
---|
| 186 | components);
|
---|
| 187 | }
|
---|
| 188 | return val;
|
---|
| 189 | };
|
---|
| 190 | }
|
---|
| 191 | }
|
---|