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

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 6.4 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RGBComponent = RGBComponent;
4exports.alphaComponent = alphaComponent;
5exports.getNumberValidator = getNumberValidator;
6exports.getNumberOrArrayOfNumbersValidator = getNumberOrArrayOfNumbersValidator;
7exports.getNumberOrAutoValidator = getNumberOrAutoValidator;
8exports.getStringValidator = getStringValidator;
9exports.getStringOrGradientValidator = getStringOrGradientValidator;
10exports.getFunctionValidator = getFunctionValidator;
11exports.getNumberArrayValidator = getNumberArrayValidator;
12exports.getBooleanValidator = getBooleanValidator;
13exports.getComponentValidator = getComponentValidator;
14const Global_1 = require("./Global");
15const Util_1 = require("./Util");
16function _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}
28function 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}
37function 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}
46function 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}
59function getNumberOrArrayOfNumbersValidator(noOfElements) {
60 if (Global_1.Konva.isUnminified) {
61 return function (val, attr) {
62 const isNumber = Util_1.Util._isNumber(val);
63 const isValidArray = Util_1.Util._isArray(val) && val.length == noOfElements;
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}
76function getNumberOrAutoValidator() {
77 if (Global_1.Konva.isUnminified) {
78 return function (val, attr) {
79 const isNumber = Util_1.Util._isNumber(val);
80 const isAuto = val === 'auto';
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}
91function 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}
104function 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}
120function 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}
133function 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}
161function getBooleanValidator() {
162 if (Global_1.Konva.isUnminified) {
163 return function (val, attr) {
164 const isBool = val === true || val === false;
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}
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}
Note: See TracBrowser for help on using the repository browser.