@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.
- package/dist/cdn/js/kendo-charts.js +1 -1
- package/dist/cdn/main.js +1 -1
- package/dist/es/barcode/barcode-validator.js +50 -0
- package/dist/es/barcode/barcode.js +13 -4
- package/dist/es/barcode/encodings/code39.js +3 -3
- package/dist/es/barcode/encodings/code93.js +4 -3
- package/dist/es/barcode/encodings/encoding.js +1 -1
- package/dist/es/barcode/encodings/postnet.js +1 -1
- package/dist/es/barcode.js +1 -0
- package/dist/es/common/default-error-handler.js +3 -0
- package/dist/es/common/get-template.js +2 -2
- package/dist/es/common.js +1 -0
- package/dist/es/qrcode/encodings/data-modes/byte-data-mode.js +1 -1
- package/dist/es/qrcode/qrcode-validator.js +24 -0
- package/dist/es/qrcode/qrcode.js +30 -21
- package/dist/es/qrcode.js +1 -0
- package/dist/es2015/barcode/barcode-validator.js +48 -0
- package/dist/es2015/barcode/barcode.js +11 -4
- package/dist/es2015/barcode/encodings/code39.js +3 -3
- package/dist/es2015/barcode/encodings/code93.js +4 -3
- package/dist/es2015/barcode/encodings/encoding.js +1 -1
- package/dist/es2015/barcode/encodings/postnet.js +1 -1
- package/dist/es2015/barcode.js +1 -0
- package/dist/es2015/common/default-error-handler.js +3 -0
- package/dist/es2015/common/get-template.js +2 -2
- package/dist/es2015/common.js +1 -0
- package/dist/es2015/qrcode/encodings/data-modes/byte-data-mode.js +1 -1
- package/dist/es2015/qrcode/qrcode-validator.js +22 -0
- package/dist/es2015/qrcode/qrcode.js +28 -21
- package/dist/es2015/qrcode.js +1 -0
- package/dist/npm/barcode.d.ts +5 -2
- package/dist/npm/main.d.ts +1 -0
- package/dist/npm/main.js +256 -164
- package/dist/npm/qrcode.d.ts +4 -1
- package/dist/npm/validation.d.ts +9 -0
- package/dist/systemjs/kendo-charts.js +1 -1
- 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
|
-
|
|
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
|
|
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.
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
package/dist/es/barcode.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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;
|
package/dist/es/qrcode/qrcode.js
CHANGED
|
@@ -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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
@@ -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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
|
package/dist/es2015/barcode.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
+
}
|
package/dist/es2015/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';
|
|
@@ -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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
}
|
package/dist/es2015/qrcode.js
CHANGED
package/dist/npm/barcode.d.ts
CHANGED
|
@@ -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;
|