@progress/kendo-charts 1.20.1 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cdn/js/kendo-charts.js +1 -1
  2. package/dist/cdn/main.js +1 -1
  3. package/dist/es/barcode/barcode-validator.js +50 -0
  4. package/dist/es/barcode/barcode.js +13 -4
  5. package/dist/es/barcode/encodings/code39.js +3 -3
  6. package/dist/es/barcode/encodings/code93.js +4 -3
  7. package/dist/es/barcode/encodings/encoding.js +1 -1
  8. package/dist/es/barcode/encodings/postnet.js +1 -1
  9. package/dist/es/barcode.js +1 -0
  10. package/dist/es/common/default-error-handler.js +3 -0
  11. package/dist/es/common/get-template.js +2 -2
  12. package/dist/es/common.js +1 -0
  13. package/dist/es/qrcode/encodings/data-modes/byte-data-mode.js +1 -1
  14. package/dist/es/qrcode/qrcode-validator.js +24 -0
  15. package/dist/es/qrcode/qrcode.js +30 -21
  16. package/dist/es/qrcode.js +1 -0
  17. package/dist/es2015/barcode/barcode-validator.js +48 -0
  18. package/dist/es2015/barcode/barcode.js +11 -4
  19. package/dist/es2015/barcode/encodings/code39.js +3 -3
  20. package/dist/es2015/barcode/encodings/code93.js +4 -3
  21. package/dist/es2015/barcode/encodings/encoding.js +1 -1
  22. package/dist/es2015/barcode/encodings/postnet.js +1 -1
  23. package/dist/es2015/barcode.js +1 -0
  24. package/dist/es2015/common/default-error-handler.js +3 -0
  25. package/dist/es2015/common/get-template.js +2 -2
  26. package/dist/es2015/common.js +1 -0
  27. package/dist/es2015/qrcode/encodings/data-modes/byte-data-mode.js +1 -1
  28. package/dist/es2015/qrcode/qrcode-validator.js +22 -0
  29. package/dist/es2015/qrcode/qrcode.js +28 -21
  30. package/dist/es2015/qrcode.js +1 -0
  31. package/dist/npm/barcode.d.ts +5 -2
  32. package/dist/npm/main.d.ts +1 -0
  33. package/dist/npm/main.js +256 -164
  34. package/dist/npm/qrcode.d.ts +4 -1
  35. package/dist/npm/validation.d.ts +9 -0
  36. package/dist/systemjs/kendo-charts.js +1 -1
  37. package/package.json +3 -3
@@ -0,0 +1,50 @@
1
+ import { Encodings } from './encodings/main';
2
+
3
+ var validate = function (encoding, size, prefix) { return function (value) {
4
+ try {
5
+ encoding.encode(
6
+ prefix + value,
7
+ size.width,
8
+ size.height
9
+ );
10
+ } catch (error) {
11
+ return {
12
+ valid: false,
13
+ error: error
14
+ };
15
+ }
16
+
17
+ return {
18
+ valid: true
19
+ };
20
+ }; };
21
+
22
+ // A default size for encodings, so the validator can check only the value if no size is provided.
23
+ var fallbackSize = { width: 500, height: 100 };
24
+
25
+ function barcodeValidator(type, size) {
26
+ if ( size === void 0 ) size = fallbackSize;
27
+
28
+ if (!type) {
29
+ throw new Error("Please specify barcode type to validate.");
30
+ }
31
+
32
+ var resolvedType = type.toLowerCase();
33
+ var prefix = '';
34
+ if (resolvedType === 'upca') {
35
+ resolvedType = 'ean13';
36
+ prefix = '0';
37
+ } else if (resolvedType === 'upce') {
38
+ resolvedType = 'ean8';
39
+ prefix = '0';
40
+ }
41
+
42
+ if (!Encodings[resolvedType]) {
43
+ throw new Error(("Encoding '" + type + "' is not supported."));
44
+ }
45
+
46
+ var encoding = new Encodings[resolvedType]();
47
+ return validate(encoding, size, prefix);
48
+ }
49
+
50
+ export default barcodeValidator;
@@ -10,7 +10,8 @@ import {
10
10
  setDefaultOptions,
11
11
  deepExtend,
12
12
  getSpacing,
13
- isObject
13
+ isObject,
14
+ defaultErrorHandler
14
15
  } from '../common';
15
16
 
16
17
  import {
@@ -24,11 +25,14 @@ var DEFAULT_BARCODE_WIDTH = 300;
24
25
  var DEFAULT_BARCODE_HEIGHT = 100;
25
26
 
26
27
  var Barcode = (function (Class) {
27
- function Barcode(element, options) {
28
+ function Barcode(element, options, errorHandler) {
29
+ if ( errorHandler === void 0 ) errorHandler = defaultErrorHandler;
30
+
28
31
  Class.call(this);
29
32
 
30
33
  this.options = deepExtend({}, this.options, options);
31
34
  this.element = element;
35
+ this.onError = errorHandler;
32
36
 
33
37
  this._initElement();
34
38
  this._initSurface();
@@ -150,7 +154,12 @@ var Barcode = (function (Class) {
150
154
  barHeight -= textHeight + textMargin.top + textMargin.bottom;
151
155
  }
152
156
 
153
- encodedValue = encoding.encode(value, contentBox.width(), barHeight);
157
+ try {
158
+ encodedValue = encoding.encode(value, contentBox.width(), barHeight);
159
+ } catch (error) {
160
+ this.onError(error);
161
+ return visual;
162
+ }
154
163
 
155
164
  if (textOptions.visible) {
156
165
  textToDisplay = value;
@@ -295,7 +304,7 @@ var Barcode = (function (Class) {
295
304
  }
296
305
 
297
306
  if (!Encodings[this.type]) {
298
- throw new Error("Encoding " + this.type + " is not supported.");
307
+ throw new Error(("Encoding '" + (this.type) + "' is not supported."));
299
308
  }
300
309
 
301
310
  this.encoding = new Encodings[this.type]();
@@ -142,12 +142,12 @@ export var Code39 = (function (Code39Base) {
142
142
 
143
143
  var minBaseUnit = this.minBaseUnitLength;
144
144
  var minRatio = this.minRatio;
145
- var minHeight = Math.max(0.15 * this.width, 24);
145
+ var minHeight = Math.ceil(Math.max(0.15 * this.width, 24));
146
146
  var baseUnit;
147
147
  var ratio = this.maxRatio;
148
148
 
149
149
  if (this.height < minHeight) {
150
- throw new Error("Insufficient Height. The minimum height for value: " + this.value + " is: " + minHeight);
150
+ throw new Error(("Insufficient height for Code39 encoding: the current height is " + (this.height) + "px and the minimum height is " + minHeight + "px."));
151
151
  }
152
152
 
153
153
  baseUnit = this.getBaseUnit(ratio);
@@ -159,7 +159,7 @@ export var Code39 = (function (Code39Base) {
159
159
 
160
160
  if (baseUnit < minBaseUnit) {
161
161
  var minWidth = Math.ceil(this.getBaseWidth(minRatio) * minBaseUnit);
162
- throw new Error("Insufficient width. The minimum width for value: " + this.value + " is: " + minWidth);
162
+ throw new Error(("Insufficient width for Code39 encoding: the current width is " + (this.width) + "px and the minimum width for value \"" + (this.value) + "\" is " + minWidth + "px."));
163
163
  }
164
164
 
165
165
  this.ratio = ratio;
@@ -83,16 +83,17 @@ export var Code93 = (function (Code39Base) {
83
83
  };
84
84
 
85
85
  Code93.prototype.prepareValues = function prepareValues () {
86
- var minHeight = Math.max(0.15 * this.width, 24);
86
+ var minHeight = Math.ceil(Math.max(0.15 * this.width, 24));
87
87
 
88
88
  if (this.height < minHeight) {
89
- throw new Error("Insufficient Height");
89
+ throw new Error(("Insufficient height for Code93 encoding: the current height is " + (this.height) + "px, the minimum required height is " + minHeight + "px."));
90
90
  }
91
91
 
92
92
  this.setBaseUnit();
93
93
 
94
94
  if (this.baseUnit < this.minBaseUnitLength) {
95
- throw new Error("Insufficient Width");
95
+ var minWidth = Math.ceil(this.minBaseUnitLength * (this.width / this.baseUnit));
96
+ throw new Error(("Insufficient width for Code93 encoding: the current width is " + (this.width) + "px and the minimum required width for value \"" + (this.value) + "\" is " + minWidth + "px."));
96
97
  }
97
98
  };
98
99
 
@@ -54,7 +54,7 @@ export var Encoding = (function (Class) {
54
54
  Encoding.prototype.addData = function addData () { };
55
55
 
56
56
  Encoding.prototype.invalidCharacterError = function invalidCharacterError (character) {
57
- throw new Error("Character '" + character + "' is not valid for symbology " + this.name);
57
+ throw new Error(("Character \"" + character + "\" is not valid for symbology " + (this.name) + "."));
58
58
  };
59
59
 
60
60
  return Encoding;
@@ -78,7 +78,7 @@ export var Postnet = (function (Encoding) {
78
78
  }
79
79
 
80
80
  if (!inArray(value.length, this.VALID_CODE_LENGTHS)) {
81
- throw new Error("Invalid value length. Valid lengths for the Postnet symbology are " + this.VALID_CODE_LENGTHS.join(","));
81
+ throw new Error("Invalid value length. Valid lengths for the Postnet symbology are " + this.VALID_CODE_LENGTHS.join(",") + ".");
82
82
  }
83
83
  };
84
84
 
@@ -1 +1,2 @@
1
1
  export { default as Barcode } from './barcode/barcode';
2
+ export { default as barcodeValidator } from './barcode/barcode-validator';
@@ -0,0 +1,3 @@
1
+ export default function defaultErrorHandler(error) {
2
+ throw error;
3
+ }
@@ -1,4 +1,4 @@
1
- import { TemplateService } from '../services';
1
+ import TemplateService from '../services/template-service';
2
2
  import isFunction from './is-function';
3
3
 
4
4
  export default function getTemplate(options) {
@@ -12,4 +12,4 @@ export default function getTemplate(options) {
12
12
  }
13
13
 
14
14
  return template;
15
- }
15
+ }
package/dist/es/common.js CHANGED
@@ -29,5 +29,6 @@ export { default as find } from './common/find';
29
29
  export { default as elementScale } from './common/element-scale';
30
30
  export { default as autoTextColor } from './common/auto-text-color';
31
31
  export { default as createHashSet } from './common/create-hash-set';
32
+ export { default as defaultErrorHandler } from './common/default-error-handler';
32
33
 
33
34
  export * from './drawing-utils';
@@ -29,7 +29,7 @@ export var ByteQRDataMode = (function (QRDataMode) {
29
29
  return code;
30
30
  }
31
31
 
32
- throw new Error("Unsupported character: " + character);
32
+ throw new Error(("Unsupported character in QR Code: \"" + character + "\"."));
33
33
  };
34
34
 
35
35
  ByteQRDataMode.prototype.encode = function encode (str, version) {
@@ -0,0 +1,24 @@
1
+ import { encodeData } from './encodings/encoding';
2
+
3
+ var ISO = 'ISO_8859_1';
4
+
5
+ function qrcodeValidator(encoding) {
6
+ if ( encoding === void 0 ) encoding = ISO;
7
+
8
+ return function(value) {
9
+ try {
10
+ encodeData(value, 'L', encoding);
11
+ } catch (error) {
12
+ return {
13
+ valid: false,
14
+ error: error
15
+ };
16
+ }
17
+
18
+ return {
19
+ valid: true
20
+ };
21
+ };
22
+ }
23
+
24
+ export default qrcodeValidator;
@@ -7,7 +7,8 @@ import {
7
7
  Class,
8
8
  addClass,
9
9
  setDefaultOptions,
10
- deepExtend
10
+ deepExtend,
11
+ defaultErrorHandler
11
12
  } from '../common';
12
13
 
13
14
  import { Box } from '../core';
@@ -29,12 +30,15 @@ var QRCodeDefaults = {
29
30
  };
30
31
 
31
32
  var QRCode = (function (Class) {
32
- function QRCode(element, options) {
33
+ function QRCode(element, options, errorHandler) {
34
+ if ( errorHandler === void 0 ) errorHandler = defaultErrorHandler;
35
+
33
36
  Class.call(this);
34
37
 
35
38
  this.options = deepExtend({}, this.options, options);
36
39
  this.element = element;
37
40
  this.wrapper = this.element;
41
+ this.onError = errorHandler;
38
42
 
39
43
  this._initElement();
40
44
  this._initSurface();
@@ -155,22 +159,26 @@ var QRCode = (function (Class) {
155
159
 
156
160
  var visual = new draw.Group();
157
161
 
158
- if (value) {
159
- matrix = encodeData(value, this.options.errorCorrection, this.options.encoding);
160
- size = this._getSize();
161
- contentSize = size - 2 * (borderWidth + padding);
162
- baseUnit = this._calculateBaseUnit(contentSize, matrix.length);
163
- dataSize = matrix.length * baseUnit;
164
- quietZoneSize = borderWidth + padding + (contentSize - dataSize) / 2;
165
-
166
- visual.append(this._renderBackground(size, border));
167
- visual.append(this._renderMatrix(matrix, baseUnit, quietZoneSize));
168
-
169
- if (this._hasCustomLogo()) {
170
- visual.append(this._renderLogo(size, baseUnit));
171
- } else if (this._isSwiss()) {
172
- visual.append(this._renderSwissCode(size, baseUnit));
162
+ try {
163
+ if (value) {
164
+ matrix = encodeData(value, this.options.errorCorrection, this.options.encoding);
165
+ size = this._getSize();
166
+ contentSize = size - 2 * (borderWidth + padding);
167
+ baseUnit = this._calculateBaseUnit(contentSize, matrix.length);
168
+ dataSize = matrix.length * baseUnit;
169
+ quietZoneSize = borderWidth + padding + (contentSize - dataSize) / 2;
170
+
171
+ visual.append(this._renderBackground(size, border));
172
+ visual.append(this._renderMatrix(matrix, baseUnit, quietZoneSize));
173
+
174
+ if (this._hasCustomLogo()) {
175
+ visual.append(this._renderLogo(size, baseUnit));
176
+ } else if (this._isSwiss()) {
177
+ visual.append(this._renderSwissCode(size, baseUnit));
178
+ }
173
179
  }
180
+ } catch (error) {
181
+ this.onError(error);
174
182
  }
175
183
 
176
184
  return visual;
@@ -261,10 +269,11 @@ var QRCode = (function (Class) {
261
269
  var baseUnit = Math.floor(size / matrixSize);
262
270
 
263
271
  if (baseUnit < QRCodeDefaults.MIN_BASE_UNIT_SIZE) {
264
- throw new Error("Insufficient size.");
265
- }
266
-
267
- if (baseUnit * matrixSize >= size &&
272
+ var minSize = Math.ceil(matrixSize * QRCodeDefaults.MIN_BASE_UNIT_SIZE);
273
+ this.onError(new Error(
274
+ ("Insufficient size for QR Code: the current size is " + size + "px and the minimum size is " + minSize + "px.")
275
+ ));
276
+ } else if (baseUnit * matrixSize >= size &&
268
277
  baseUnit - 1 >= QRCodeDefaults.MIN_BASE_UNIT_SIZE) {
269
278
  baseUnit--;
270
279
  }
package/dist/es/qrcode.js CHANGED
@@ -1 +1,2 @@
1
1
  export { default as QRCode } from './qrcode/qrcode';
2
+ export { default as qrcodeValidator } from './qrcode/qrcode-validator';
@@ -0,0 +1,48 @@
1
+ import { Encodings } from './encodings/main';
2
+
3
+ const validate = (encoding, size, prefix) => (value) => {
4
+ try {
5
+ encoding.encode(
6
+ prefix + value,
7
+ size.width,
8
+ size.height
9
+ );
10
+ } catch (error) {
11
+ return {
12
+ valid: false,
13
+ error
14
+ };
15
+ }
16
+
17
+ return {
18
+ valid: true
19
+ };
20
+ };
21
+
22
+ // A default size for encodings, so the validator can check only the value if no size is provided.
23
+ const fallbackSize = { width: 500, height: 100 };
24
+
25
+ function barcodeValidator(type, size = fallbackSize) {
26
+ if (!type) {
27
+ throw new Error(`Please specify barcode type to validate.`);
28
+ }
29
+
30
+ let resolvedType = type.toLowerCase();
31
+ let prefix = '';
32
+ if (resolvedType === 'upca') {
33
+ resolvedType = 'ean13';
34
+ prefix = '0';
35
+ } else if (resolvedType === 'upce') {
36
+ resolvedType = 'ean8';
37
+ prefix = '0';
38
+ }
39
+
40
+ if (!Encodings[resolvedType]) {
41
+ throw new Error(`Encoding '${type}' is not supported.`);
42
+ }
43
+
44
+ const encoding = new Encodings[resolvedType]();
45
+ return validate(encoding, size, prefix);
46
+ }
47
+
48
+ export default barcodeValidator;
@@ -10,7 +10,8 @@ import {
10
10
  setDefaultOptions,
11
11
  deepExtend,
12
12
  getSpacing,
13
- isObject
13
+ isObject,
14
+ defaultErrorHandler
14
15
  } from '../common';
15
16
 
16
17
  import {
@@ -24,11 +25,12 @@ const DEFAULT_BARCODE_WIDTH = 300;
24
25
  const DEFAULT_BARCODE_HEIGHT = 100;
25
26
 
26
27
  class Barcode extends Class {
27
- constructor(element, options) {
28
+ constructor(element, options, errorHandler = defaultErrorHandler) {
28
29
  super();
29
30
 
30
31
  this.options = deepExtend({}, this.options, options);
31
32
  this.element = element;
33
+ this.onError = errorHandler;
32
34
 
33
35
  this._initElement();
34
36
  this._initSurface();
@@ -144,7 +146,12 @@ class Barcode extends Class {
144
146
  barHeight -= textHeight + textMargin.top + textMargin.bottom;
145
147
  }
146
148
 
147
- encodedValue = encoding.encode(value, contentBox.width(), barHeight);
149
+ try {
150
+ encodedValue = encoding.encode(value, contentBox.width(), barHeight);
151
+ } catch (error) {
152
+ this.onError(error);
153
+ return visual;
154
+ }
148
155
 
149
156
  if (textOptions.visible) {
150
157
  textToDisplay = value;
@@ -287,7 +294,7 @@ class Barcode extends Class {
287
294
  }
288
295
 
289
296
  if (!Encodings[this.type]) {
290
- throw new Error("Encoding " + this.type + " is not supported.");
297
+ throw new Error(`Encoding '${this.type}' is not supported.`);
291
298
  }
292
299
 
293
300
  this.encoding = new Encodings[this.type]();
@@ -120,12 +120,12 @@ export class Code39 extends Code39Base {
120
120
  prepareValues() {
121
121
  const minBaseUnit = this.minBaseUnitLength;
122
122
  const minRatio = this.minRatio;
123
- const minHeight = Math.max(0.15 * this.width, 24);
123
+ const minHeight = Math.ceil(Math.max(0.15 * this.width, 24));
124
124
  let baseUnit;
125
125
  let ratio = this.maxRatio;
126
126
 
127
127
  if (this.height < minHeight) {
128
- throw new Error("Insufficient Height. The minimum height for value: " + this.value + " is: " + minHeight);
128
+ throw new Error(`Insufficient height for Code39 encoding: the current height is ${this.height}px and the minimum height is ${minHeight}px.`);
129
129
  }
130
130
 
131
131
  baseUnit = this.getBaseUnit(ratio);
@@ -137,7 +137,7 @@ export class Code39 extends Code39Base {
137
137
 
138
138
  if (baseUnit < minBaseUnit) {
139
139
  let minWidth = Math.ceil(this.getBaseWidth(minRatio) * minBaseUnit);
140
- throw new Error("Insufficient width. The minimum width for value: " + this.value + " is: " + minWidth);
140
+ throw new Error(`Insufficient width for Code39 encoding: the current width is ${this.width}px and the minimum width for value "${this.value}" is ${minWidth}px.`);
141
141
  }
142
142
 
143
143
  this.ratio = ratio;
@@ -75,16 +75,17 @@ export class Code93 extends Code39Base {
75
75
  }
76
76
 
77
77
  prepareValues() {
78
- let minHeight = Math.max(0.15 * this.width, 24);
78
+ let minHeight = Math.ceil(Math.max(0.15 * this.width, 24));
79
79
 
80
80
  if (this.height < minHeight) {
81
- throw new Error("Insufficient Height");
81
+ throw new Error(`Insufficient height for Code93 encoding: the current height is ${this.height}px, the minimum required height is ${minHeight}px.`);
82
82
  }
83
83
 
84
84
  this.setBaseUnit();
85
85
 
86
86
  if (this.baseUnit < this.minBaseUnitLength) {
87
- throw new Error("Insufficient Width");
87
+ const minWidth = Math.ceil(this.minBaseUnitLength * (this.width / this.baseUnit));
88
+ throw new Error(`Insufficient width for Code93 encoding: the current width is ${this.width}px and the minimum required width for value "${this.value}" is ${minWidth}px.`);
88
89
  }
89
90
  }
90
91
 
@@ -50,7 +50,7 @@ export class Encoding extends Class {
50
50
  addData() { }
51
51
 
52
52
  invalidCharacterError(character) {
53
- throw new Error("Character '" + character + "' is not valid for symbology " + this.name);
53
+ throw new Error(`Character "${character}" is not valid for symbology ${this.name}.`);
54
54
  }
55
55
  }
56
56
 
@@ -68,7 +68,7 @@ export class Postnet extends Encoding {
68
68
  }
69
69
 
70
70
  if (!inArray(value.length, this.VALID_CODE_LENGTHS)) {
71
- throw new Error("Invalid value length. Valid lengths for the Postnet symbology are " + this.VALID_CODE_LENGTHS.join(","));
71
+ throw new Error("Invalid value length. Valid lengths for the Postnet symbology are " + this.VALID_CODE_LENGTHS.join(",") + ".");
72
72
  }
73
73
  }
74
74
 
@@ -1 +1,2 @@
1
1
  export { default as Barcode } from './barcode/barcode';
2
+ export { default as barcodeValidator } from './barcode/barcode-validator';
@@ -0,0 +1,3 @@
1
+ export default function defaultErrorHandler(error) {
2
+ throw error;
3
+ }
@@ -1,4 +1,4 @@
1
- import { TemplateService } from '../services';
1
+ import TemplateService from '../services/template-service';
2
2
  import isFunction from './is-function';
3
3
 
4
4
  export default function getTemplate(options = {}) {
@@ -10,4 +10,4 @@ export default function getTemplate(options = {}) {
10
10
  }
11
11
 
12
12
  return template;
13
- }
13
+ }
@@ -29,5 +29,6 @@ export { default as find } from './common/find';
29
29
  export { default as elementScale } from './common/element-scale';
30
30
  export { default as autoTextColor } from './common/auto-text-color';
31
31
  export { default as createHashSet } from './common/create-hash-set';
32
+ export { default as defaultErrorHandler } from './common/default-error-handler';
32
33
 
33
34
  export * from './drawing-utils';
@@ -21,7 +21,7 @@ export class ByteQRDataMode extends QRDataMode {
21
21
  return code;
22
22
  }
23
23
 
24
- throw new Error("Unsupported character: " + character);
24
+ throw new Error(`Unsupported character in QR Code: "${character}".`);
25
25
  }
26
26
 
27
27
  encode(str, version) {
@@ -0,0 +1,22 @@
1
+ import { encodeData } from './encodings/encoding';
2
+
3
+ const ISO = 'ISO_8859_1';
4
+
5
+ function qrcodeValidator(encoding = ISO) {
6
+ return function(value) {
7
+ try {
8
+ encodeData(value, 'L', encoding);
9
+ } catch (error) {
10
+ return {
11
+ valid: false,
12
+ error
13
+ };
14
+ }
15
+
16
+ return {
17
+ valid: true
18
+ };
19
+ };
20
+ }
21
+
22
+ export default qrcodeValidator;
@@ -7,7 +7,8 @@ import {
7
7
  Class,
8
8
  addClass,
9
9
  setDefaultOptions,
10
- deepExtend
10
+ deepExtend,
11
+ defaultErrorHandler
11
12
  } from '../common';
12
13
 
13
14
  import { Box } from '../core';
@@ -29,12 +30,13 @@ const QRCodeDefaults = {
29
30
  };
30
31
 
31
32
  class QRCode extends Class {
32
- constructor(element, options) {
33
+ constructor(element, options, errorHandler = defaultErrorHandler) {
33
34
  super();
34
35
 
35
36
  this.options = deepExtend({}, this.options, options);
36
37
  this.element = element;
37
38
  this.wrapper = this.element;
39
+ this.onError = errorHandler;
38
40
 
39
41
  this._initElement();
40
42
  this._initSurface();
@@ -149,22 +151,26 @@ class QRCode extends Class {
149
151
 
150
152
  let visual = new draw.Group();
151
153
 
152
- if (value) {
153
- matrix = encodeData(value, this.options.errorCorrection, this.options.encoding);
154
- size = this._getSize();
155
- contentSize = size - 2 * (borderWidth + padding);
156
- baseUnit = this._calculateBaseUnit(contentSize, matrix.length);
157
- dataSize = matrix.length * baseUnit;
158
- quietZoneSize = borderWidth + padding + (contentSize - dataSize) / 2;
159
-
160
- visual.append(this._renderBackground(size, border));
161
- visual.append(this._renderMatrix(matrix, baseUnit, quietZoneSize));
162
-
163
- if (this._hasCustomLogo()) {
164
- visual.append(this._renderLogo(size, baseUnit));
165
- } else if (this._isSwiss()) {
166
- visual.append(this._renderSwissCode(size, baseUnit));
154
+ try {
155
+ if (value) {
156
+ matrix = encodeData(value, this.options.errorCorrection, this.options.encoding);
157
+ size = this._getSize();
158
+ contentSize = size - 2 * (borderWidth + padding);
159
+ baseUnit = this._calculateBaseUnit(contentSize, matrix.length);
160
+ dataSize = matrix.length * baseUnit;
161
+ quietZoneSize = borderWidth + padding + (contentSize - dataSize) / 2;
162
+
163
+ visual.append(this._renderBackground(size, border));
164
+ visual.append(this._renderMatrix(matrix, baseUnit, quietZoneSize));
165
+
166
+ if (this._hasCustomLogo()) {
167
+ visual.append(this._renderLogo(size, baseUnit));
168
+ } else if (this._isSwiss()) {
169
+ visual.append(this._renderSwissCode(size, baseUnit));
170
+ }
167
171
  }
172
+ } catch (error) {
173
+ this.onError(error);
168
174
  }
169
175
 
170
176
  return visual;
@@ -255,10 +261,11 @@ class QRCode extends Class {
255
261
  let baseUnit = Math.floor(size / matrixSize);
256
262
 
257
263
  if (baseUnit < QRCodeDefaults.MIN_BASE_UNIT_SIZE) {
258
- throw new Error("Insufficient size.");
259
- }
260
-
261
- if (baseUnit * matrixSize >= size &&
264
+ const minSize = Math.ceil(matrixSize * QRCodeDefaults.MIN_BASE_UNIT_SIZE);
265
+ this.onError(new Error(
266
+ `Insufficient size for QR Code: the current size is ${size}px and the minimum size is ${minSize}px.`
267
+ ));
268
+ } else if (baseUnit * matrixSize >= size &&
262
269
  baseUnit - 1 >= QRCodeDefaults.MIN_BASE_UNIT_SIZE) {
263
270
  baseUnit--;
264
271
  }
@@ -1 +1,2 @@
1
1
  export { default as QRCode } from './qrcode/qrcode';
2
+ export { default as qrcodeValidator } from './qrcode/qrcode-validator';
@@ -1,5 +1,6 @@
1
- import { Group } from '@progress/kendo-drawing';
1
+ import { Group, geometry } from '@progress/kendo-drawing';
2
2
  import { Border, Margin, Padding, RenderMode } from './field-types';
3
+ import { ValidationResult } from './validation';
3
4
 
4
5
  /**
5
6
  * Supported symbologies (encodings) for the Barcode component.
@@ -124,9 +125,11 @@ export interface BarcodeOptions {
124
125
  }
125
126
 
126
127
  export class Barcode {
127
- constructor(element: Element, options: BarcodeOptions);
128
+ constructor(element: Element, options: BarcodeOptions, errorHandler?: (error: Error) => void);
128
129
 
129
130
  public redraw(): void;
130
131
  public setOptions(options: BarcodeOptions): void;
131
132
  public exportVisual(): Group;
132
133
  }
134
+
135
+ export function barcodeValidator(type: BarcodeType, size: geometry.Size): (value: number | string) => ValidationResult;