source: imaps-frontend/node_modules/konva/lib/Validators.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

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