react-jsbarcode 0.1.2 → 0.2.3-beta.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.
@@ -0,0 +1,3350 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+
4
+ var barcodes = {};
5
+
6
+ var CODE39$1 = {};
7
+
8
+ var Barcode$1 = {};
9
+
10
+ Object.defineProperty(Barcode$1, "__esModule", {
11
+ value: true
12
+ });
13
+
14
+ function _classCallCheck$s(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+
16
+ var Barcode = function Barcode(data, options) {
17
+ _classCallCheck$s(this, Barcode);
18
+
19
+ this.data = data;
20
+ this.text = options.text || data;
21
+ this.options = options;
22
+ };
23
+
24
+ Barcode$1.default = Barcode;
25
+
26
+ Object.defineProperty(CODE39$1, "__esModule", {
27
+ value: true
28
+ });
29
+ CODE39$1.CODE39 = undefined;
30
+
31
+ var _createClass$l = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
32
+
33
+ var _Barcode2$b = Barcode$1;
34
+
35
+ var _Barcode3$b = _interopRequireDefault$x(_Barcode2$b);
36
+
37
+ function _interopRequireDefault$x(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
+
39
+ function _classCallCheck$r(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
40
+
41
+ function _possibleConstructorReturn$n(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
42
+
43
+ function _inherits$n(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
44
+ // https://en.wikipedia.org/wiki/Code_39#Encoding
45
+
46
+ var CODE39 = function (_Barcode) {
47
+ _inherits$n(CODE39, _Barcode);
48
+
49
+ function CODE39(data, options) {
50
+ _classCallCheck$r(this, CODE39);
51
+
52
+ data = data.toUpperCase();
53
+
54
+ // Calculate mod43 checksum if enabled
55
+ if (options.mod43) {
56
+ data += getCharacter(mod43checksum(data));
57
+ }
58
+
59
+ return _possibleConstructorReturn$n(this, (CODE39.__proto__ || Object.getPrototypeOf(CODE39)).call(this, data, options));
60
+ }
61
+
62
+ _createClass$l(CODE39, [{
63
+ key: "encode",
64
+ value: function encode() {
65
+ // First character is always a *
66
+ var result = getEncoding("*");
67
+
68
+ // Take every character and add the binary representation to the result
69
+ for (var i = 0; i < this.data.length; i++) {
70
+ result += getEncoding(this.data[i]) + "0";
71
+ }
72
+
73
+ // Last character is always a *
74
+ result += getEncoding("*");
75
+
76
+ return {
77
+ data: result,
78
+ text: this.text
79
+ };
80
+ }
81
+ }, {
82
+ key: "valid",
83
+ value: function valid() {
84
+ return this.data.search(/^[0-9A-Z\-\.\ \$\/\+\%]+$/) !== -1;
85
+ }
86
+ }]);
87
+
88
+ return CODE39;
89
+ }(_Barcode3$b.default);
90
+
91
+ // All characters. The position in the array is the (checksum) value
92
+
93
+
94
+ var characters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "-", ".", " ", "$", "/", "+", "%", "*"];
95
+
96
+ // The decimal representation of the characters, is converted to the
97
+ // corresponding binary with the getEncoding function
98
+ var encodings = [20957, 29783, 23639, 30485, 20951, 29813, 23669, 20855, 29789, 23645, 29975, 23831, 30533, 22295, 30149, 24005, 21623, 29981, 23837, 22301, 30023, 23879, 30545, 22343, 30161, 24017, 21959, 30065, 23921, 22385, 29015, 18263, 29141, 17879, 29045, 18293, 17783, 29021, 18269, 17477, 17489, 17681, 20753, 35770];
99
+
100
+ // Get the binary representation of a character by converting the encodings
101
+ // from decimal to binary
102
+ function getEncoding(character) {
103
+ return getBinary(characterValue(character));
104
+ }
105
+
106
+ function getBinary(characterValue) {
107
+ return encodings[characterValue].toString(2);
108
+ }
109
+
110
+ function getCharacter(characterValue) {
111
+ return characters[characterValue];
112
+ }
113
+
114
+ function characterValue(character) {
115
+ return characters.indexOf(character);
116
+ }
117
+
118
+ function mod43checksum(data) {
119
+ var checksum = 0;
120
+ for (var i = 0; i < data.length; i++) {
121
+ checksum += characterValue(data[i]);
122
+ }
123
+
124
+ checksum = checksum % 43;
125
+ return checksum;
126
+ }
127
+
128
+ CODE39$1.CODE39 = CODE39;
129
+
130
+ var CODE128$2 = {};
131
+
132
+ var CODE128_AUTO = {};
133
+
134
+ var CODE128$1 = {};
135
+
136
+ var constants$2 = {};
137
+
138
+ Object.defineProperty(constants$2, "__esModule", {
139
+ value: true
140
+ });
141
+
142
+ var _SET_BY_CODE;
143
+
144
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
145
+
146
+ // constants for internal usage
147
+ var SET_A = constants$2.SET_A = 0;
148
+ var SET_B = constants$2.SET_B = 1;
149
+ var SET_C = constants$2.SET_C = 2;
150
+
151
+ // Special characters
152
+ constants$2.SHIFT = 98;
153
+ var START_A = constants$2.START_A = 103;
154
+ var START_B = constants$2.START_B = 104;
155
+ var START_C = constants$2.START_C = 105;
156
+ constants$2.MODULO = 103;
157
+ constants$2.STOP = 106;
158
+ constants$2.FNC1 = 207;
159
+
160
+ // Get set by start code
161
+ constants$2.SET_BY_CODE = (_SET_BY_CODE = {}, _defineProperty(_SET_BY_CODE, START_A, SET_A), _defineProperty(_SET_BY_CODE, START_B, SET_B), _defineProperty(_SET_BY_CODE, START_C, SET_C), _SET_BY_CODE);
162
+
163
+ // Get next set by code
164
+ constants$2.SWAP = {
165
+ 101: SET_A,
166
+ 100: SET_B,
167
+ 99: SET_C
168
+ };
169
+
170
+ constants$2.A_START_CHAR = String.fromCharCode(208); // START_A + 105
171
+ constants$2.B_START_CHAR = String.fromCharCode(209); // START_B + 105
172
+ constants$2.C_START_CHAR = String.fromCharCode(210); // START_C + 105
173
+
174
+ // 128A (Code Set A)
175
+ // ASCII characters 00 to 95 (0–9, A–Z and control codes), special characters, and FNC 1–4
176
+ constants$2.A_CHARS = "[\x00-\x5F\xC8-\xCF]";
177
+
178
+ // 128B (Code Set B)
179
+ // ASCII characters 32 to 127 (0–9, A–Z, a–z), special characters, and FNC 1–4
180
+ constants$2.B_CHARS = "[\x20-\x7F\xC8-\xCF]";
181
+
182
+ // 128C (Code Set C)
183
+ // 00–99 (encodes two digits with a single code point) and FNC1
184
+ constants$2.C_CHARS = "(\xCF*[0-9]{2}\xCF*)";
185
+
186
+ // CODE128 includes 107 symbols:
187
+ // 103 data symbols, 3 start symbols (A, B and C), and 1 stop symbol (the last one)
188
+ // Each symbol consist of three black bars (1) and three white spaces (0).
189
+ constants$2.BARS = [11011001100, 11001101100, 11001100110, 10010011000, 10010001100, 10001001100, 10011001000, 10011000100, 10001100100, 11001001000, 11001000100, 11000100100, 10110011100, 10011011100, 10011001110, 10111001100, 10011101100, 10011100110, 11001110010, 11001011100, 11001001110, 11011100100, 11001110100, 11101101110, 11101001100, 11100101100, 11100100110, 11101100100, 11100110100, 11100110010, 11011011000, 11011000110, 11000110110, 10100011000, 10001011000, 10001000110, 10110001000, 10001101000, 10001100010, 11010001000, 11000101000, 11000100010, 10110111000, 10110001110, 10001101110, 10111011000, 10111000110, 10001110110, 11101110110, 11010001110, 11000101110, 11011101000, 11011100010, 11011101110, 11101011000, 11101000110, 11100010110, 11101101000, 11101100010, 11100011010, 11101111010, 11001000010, 11110001010, 10100110000, 10100001100, 10010110000, 10010000110, 10000101100, 10000100110, 10110010000, 10110000100, 10011010000, 10011000010, 10000110100, 10000110010, 11000010010, 11001010000, 11110111010, 11000010100, 10001111010, 10100111100, 10010111100, 10010011110, 10111100100, 10011110100, 10011110010, 11110100100, 11110010100, 11110010010, 11011011110, 11011110110, 11110110110, 10101111000, 10100011110, 10001011110, 10111101000, 10111100010, 11110101000, 11110100010, 10111011110, 10111101110, 11101011110, 11110101110, 11010000100, 11010010000, 11010011100, 1100011101011];
190
+
191
+ Object.defineProperty(CODE128$1, "__esModule", {
192
+ value: true
193
+ });
194
+
195
+ var _createClass$k = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
196
+
197
+ var _Barcode2$a = Barcode$1;
198
+
199
+ var _Barcode3$a = _interopRequireDefault$w(_Barcode2$a);
200
+
201
+ var _constants$a = constants$2;
202
+
203
+ function _interopRequireDefault$w(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
204
+
205
+ function _classCallCheck$q(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
206
+
207
+ function _possibleConstructorReturn$m(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
208
+
209
+ function _inherits$m(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
210
+
211
+ // This is the master class,
212
+ // it does require the start code to be included in the string
213
+ var CODE128 = function (_Barcode) {
214
+ _inherits$m(CODE128, _Barcode);
215
+
216
+ function CODE128(data, options) {
217
+ _classCallCheck$q(this, CODE128);
218
+
219
+ // Get array of ascii codes from data
220
+ var _this = _possibleConstructorReturn$m(this, (CODE128.__proto__ || Object.getPrototypeOf(CODE128)).call(this, data.substring(1), options));
221
+
222
+ _this.bytes = data.split('').map(function (char) {
223
+ return char.charCodeAt(0);
224
+ });
225
+ return _this;
226
+ }
227
+
228
+ _createClass$k(CODE128, [{
229
+ key: 'valid',
230
+ value: function valid() {
231
+ // ASCII value ranges 0-127, 200-211
232
+ return (/^[\x00-\x7F\xC8-\xD3]+$/.test(this.data)
233
+ );
234
+ }
235
+
236
+ // The public encoding function
237
+
238
+ }, {
239
+ key: 'encode',
240
+ value: function encode() {
241
+ var bytes = this.bytes;
242
+ // Remove the start code from the bytes and set its index
243
+ var startIndex = bytes.shift() - 105;
244
+ // Get start set by index
245
+ var startSet = _constants$a.SET_BY_CODE[startIndex];
246
+
247
+ if (startSet === undefined) {
248
+ throw new RangeError('The encoding does not start with a start character.');
249
+ }
250
+
251
+ if (this.shouldEncodeAsEan128() === true) {
252
+ bytes.unshift(_constants$a.FNC1);
253
+ }
254
+
255
+ // Start encode with the right type
256
+ var encodingResult = CODE128.next(bytes, 1, startSet);
257
+
258
+ return {
259
+ text: this.text === this.data ? this.text.replace(/[^\x20-\x7E]/g, '') : this.text,
260
+ data:
261
+ // Add the start bits
262
+ CODE128.getBar(startIndex) +
263
+ // Add the encoded bits
264
+ encodingResult.result +
265
+ // Add the checksum
266
+ CODE128.getBar((encodingResult.checksum + startIndex) % _constants$a.MODULO) +
267
+ // Add the end bits
268
+ CODE128.getBar(_constants$a.STOP)
269
+ };
270
+ }
271
+
272
+ // GS1-128/EAN-128
273
+
274
+ }, {
275
+ key: 'shouldEncodeAsEan128',
276
+ value: function shouldEncodeAsEan128() {
277
+ var isEAN128 = this.options.ean128 || false;
278
+ if (typeof isEAN128 === 'string') {
279
+ isEAN128 = isEAN128.toLowerCase() === 'true';
280
+ }
281
+ return isEAN128;
282
+ }
283
+
284
+ // Get a bar symbol by index
285
+
286
+ }], [{
287
+ key: 'getBar',
288
+ value: function getBar(index) {
289
+ return _constants$a.BARS[index] ? _constants$a.BARS[index].toString() : '';
290
+ }
291
+
292
+ // Correct an index by a set and shift it from the bytes array
293
+
294
+ }, {
295
+ key: 'correctIndex',
296
+ value: function correctIndex(bytes, set) {
297
+ if (set === _constants$a.SET_A) {
298
+ var charCode = bytes.shift();
299
+ return charCode < 32 ? charCode + 64 : charCode - 32;
300
+ } else if (set === _constants$a.SET_B) {
301
+ return bytes.shift() - 32;
302
+ } else {
303
+ return (bytes.shift() - 48) * 10 + bytes.shift() - 48;
304
+ }
305
+ }
306
+ }, {
307
+ key: 'next',
308
+ value: function next(bytes, pos, set) {
309
+ if (!bytes.length) {
310
+ return { result: '', checksum: 0 };
311
+ }
312
+
313
+ var nextCode = void 0,
314
+ index = void 0;
315
+
316
+ // Special characters
317
+ if (bytes[0] >= 200) {
318
+ index = bytes.shift() - 105;
319
+ var nextSet = _constants$a.SWAP[index];
320
+
321
+ // Swap to other set
322
+ if (nextSet !== undefined) {
323
+ nextCode = CODE128.next(bytes, pos + 1, nextSet);
324
+ }
325
+ // Continue on current set but encode a special character
326
+ else {
327
+ // Shift
328
+ if ((set === _constants$a.SET_A || set === _constants$a.SET_B) && index === _constants$a.SHIFT) {
329
+ // Convert the next character so that is encoded correctly
330
+ bytes[0] = set === _constants$a.SET_A ? bytes[0] > 95 ? bytes[0] - 96 : bytes[0] : bytes[0] < 32 ? bytes[0] + 96 : bytes[0];
331
+ }
332
+ nextCode = CODE128.next(bytes, pos + 1, set);
333
+ }
334
+ }
335
+ // Continue encoding
336
+ else {
337
+ index = CODE128.correctIndex(bytes, set);
338
+ nextCode = CODE128.next(bytes, pos + 1, set);
339
+ }
340
+
341
+ // Get the correct binary encoding and calculate the weight
342
+ var enc = CODE128.getBar(index);
343
+ var weight = index * pos;
344
+
345
+ return {
346
+ result: enc + nextCode.result,
347
+ checksum: weight + nextCode.checksum
348
+ };
349
+ }
350
+ }]);
351
+
352
+ return CODE128;
353
+ }(_Barcode3$a.default);
354
+
355
+ CODE128$1.default = CODE128;
356
+
357
+ var auto = {};
358
+
359
+ Object.defineProperty(auto, "__esModule", {
360
+ value: true
361
+ });
362
+
363
+ var _constants$9 = constants$2;
364
+
365
+ // Match Set functions
366
+ var matchSetALength = function matchSetALength(string) {
367
+ return string.match(new RegExp('^' + _constants$9.A_CHARS + '*'))[0].length;
368
+ };
369
+ var matchSetBLength = function matchSetBLength(string) {
370
+ return string.match(new RegExp('^' + _constants$9.B_CHARS + '*'))[0].length;
371
+ };
372
+ var matchSetC = function matchSetC(string) {
373
+ return string.match(new RegExp('^' + _constants$9.C_CHARS + '*'))[0];
374
+ };
375
+
376
+ // CODE128A or CODE128B
377
+ function autoSelectFromAB(string, isA) {
378
+ var ranges = isA ? _constants$9.A_CHARS : _constants$9.B_CHARS;
379
+ var untilC = string.match(new RegExp('^(' + ranges + '+?)(([0-9]{2}){2,})([^0-9]|$)'));
380
+
381
+ if (untilC) {
382
+ return untilC[1] + String.fromCharCode(204) + autoSelectFromC(string.substring(untilC[1].length));
383
+ }
384
+
385
+ var chars = string.match(new RegExp('^' + ranges + '+'))[0];
386
+
387
+ if (chars.length === string.length) {
388
+ return string;
389
+ }
390
+
391
+ return chars + String.fromCharCode(isA ? 205 : 206) + autoSelectFromAB(string.substring(chars.length), !isA);
392
+ }
393
+
394
+ // CODE128C
395
+ function autoSelectFromC(string) {
396
+ var cMatch = matchSetC(string);
397
+ var length = cMatch.length;
398
+
399
+ if (length === string.length) {
400
+ return string;
401
+ }
402
+
403
+ string = string.substring(length);
404
+
405
+ // Select A/B depending on the longest match
406
+ var isA = matchSetALength(string) >= matchSetBLength(string);
407
+ return cMatch + String.fromCharCode(isA ? 206 : 205) + autoSelectFromAB(string, isA);
408
+ }
409
+
410
+ // Detect Code Set (A, B or C) and format the string
411
+
412
+ auto.default = function (string) {
413
+ var newString = void 0;
414
+ var cLength = matchSetC(string).length;
415
+
416
+ // Select 128C if the string start with enough digits
417
+ if (cLength >= 2) {
418
+ newString = _constants$9.C_START_CHAR + autoSelectFromC(string);
419
+ } else {
420
+ // Select A/B depending on the longest match
421
+ var isA = matchSetALength(string) > matchSetBLength(string);
422
+ newString = (isA ? _constants$9.A_START_CHAR : _constants$9.B_START_CHAR) + autoSelectFromAB(string, isA);
423
+ }
424
+
425
+ return newString.replace(/[\xCD\xCE]([^])[\xCD\xCE]/, // Any sequence between 205 and 206 characters
426
+ function (match, char) {
427
+ return String.fromCharCode(203) + char;
428
+ });
429
+ };
430
+
431
+ Object.defineProperty(CODE128_AUTO, "__esModule", {
432
+ value: true
433
+ });
434
+
435
+ var _CODE2$4 = CODE128$1;
436
+
437
+ var _CODE3$3 = _interopRequireDefault$v(_CODE2$4);
438
+
439
+ var _auto = auto;
440
+
441
+ var _auto2 = _interopRequireDefault$v(_auto);
442
+
443
+ function _interopRequireDefault$v(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
444
+
445
+ function _classCallCheck$p(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
446
+
447
+ function _possibleConstructorReturn$l(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
448
+
449
+ function _inherits$l(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
450
+
451
+ var CODE128AUTO = function (_CODE) {
452
+ _inherits$l(CODE128AUTO, _CODE);
453
+
454
+ function CODE128AUTO(data, options) {
455
+ _classCallCheck$p(this, CODE128AUTO);
456
+
457
+ // ASCII value ranges 0-127, 200-211
458
+ if (/^[\x00-\x7F\xC8-\xD3]+$/.test(data)) {
459
+ var _this = _possibleConstructorReturn$l(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, (0, _auto2.default)(data), options));
460
+ } else {
461
+ var _this = _possibleConstructorReturn$l(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, data, options));
462
+ }
463
+ return _possibleConstructorReturn$l(_this);
464
+ }
465
+
466
+ return CODE128AUTO;
467
+ }(_CODE3$3.default);
468
+
469
+ CODE128_AUTO.default = CODE128AUTO;
470
+
471
+ var CODE128A$1 = {};
472
+
473
+ Object.defineProperty(CODE128A$1, "__esModule", {
474
+ value: true
475
+ });
476
+
477
+ var _createClass$j = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
478
+
479
+ var _CODE2$3 = CODE128$1;
480
+
481
+ var _CODE3$2 = _interopRequireDefault$u(_CODE2$3);
482
+
483
+ var _constants$8 = constants$2;
484
+
485
+ function _interopRequireDefault$u(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
486
+
487
+ function _classCallCheck$o(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
488
+
489
+ function _possibleConstructorReturn$k(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
490
+
491
+ function _inherits$k(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
492
+
493
+ var CODE128A = function (_CODE) {
494
+ _inherits$k(CODE128A, _CODE);
495
+
496
+ function CODE128A(string, options) {
497
+ _classCallCheck$o(this, CODE128A);
498
+
499
+ return _possibleConstructorReturn$k(this, (CODE128A.__proto__ || Object.getPrototypeOf(CODE128A)).call(this, _constants$8.A_START_CHAR + string, options));
500
+ }
501
+
502
+ _createClass$j(CODE128A, [{
503
+ key: 'valid',
504
+ value: function valid() {
505
+ return new RegExp('^' + _constants$8.A_CHARS + '+$').test(this.data);
506
+ }
507
+ }]);
508
+
509
+ return CODE128A;
510
+ }(_CODE3$2.default);
511
+
512
+ CODE128A$1.default = CODE128A;
513
+
514
+ var CODE128B$1 = {};
515
+
516
+ Object.defineProperty(CODE128B$1, "__esModule", {
517
+ value: true
518
+ });
519
+
520
+ var _createClass$i = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
521
+
522
+ var _CODE2$2 = CODE128$1;
523
+
524
+ var _CODE3$1 = _interopRequireDefault$t(_CODE2$2);
525
+
526
+ var _constants$7 = constants$2;
527
+
528
+ function _interopRequireDefault$t(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
529
+
530
+ function _classCallCheck$n(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
531
+
532
+ function _possibleConstructorReturn$j(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
533
+
534
+ function _inherits$j(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
535
+
536
+ var CODE128B = function (_CODE) {
537
+ _inherits$j(CODE128B, _CODE);
538
+
539
+ function CODE128B(string, options) {
540
+ _classCallCheck$n(this, CODE128B);
541
+
542
+ return _possibleConstructorReturn$j(this, (CODE128B.__proto__ || Object.getPrototypeOf(CODE128B)).call(this, _constants$7.B_START_CHAR + string, options));
543
+ }
544
+
545
+ _createClass$i(CODE128B, [{
546
+ key: 'valid',
547
+ value: function valid() {
548
+ return new RegExp('^' + _constants$7.B_CHARS + '+$').test(this.data);
549
+ }
550
+ }]);
551
+
552
+ return CODE128B;
553
+ }(_CODE3$1.default);
554
+
555
+ CODE128B$1.default = CODE128B;
556
+
557
+ var CODE128C$1 = {};
558
+
559
+ Object.defineProperty(CODE128C$1, "__esModule", {
560
+ value: true
561
+ });
562
+
563
+ var _createClass$h = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
564
+
565
+ var _CODE2$1 = CODE128$1;
566
+
567
+ var _CODE3 = _interopRequireDefault$s(_CODE2$1);
568
+
569
+ var _constants$6 = constants$2;
570
+
571
+ function _interopRequireDefault$s(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
572
+
573
+ function _classCallCheck$m(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
574
+
575
+ function _possibleConstructorReturn$i(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
576
+
577
+ function _inherits$i(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
578
+
579
+ var CODE128C = function (_CODE) {
580
+ _inherits$i(CODE128C, _CODE);
581
+
582
+ function CODE128C(string, options) {
583
+ _classCallCheck$m(this, CODE128C);
584
+
585
+ return _possibleConstructorReturn$i(this, (CODE128C.__proto__ || Object.getPrototypeOf(CODE128C)).call(this, _constants$6.C_START_CHAR + string, options));
586
+ }
587
+
588
+ _createClass$h(CODE128C, [{
589
+ key: 'valid',
590
+ value: function valid() {
591
+ return new RegExp('^' + _constants$6.C_CHARS + '+$').test(this.data);
592
+ }
593
+ }]);
594
+
595
+ return CODE128C;
596
+ }(_CODE3.default);
597
+
598
+ CODE128C$1.default = CODE128C;
599
+
600
+ Object.defineProperty(CODE128$2, "__esModule", {
601
+ value: true
602
+ });
603
+ CODE128$2.CODE128C = CODE128$2.CODE128B = CODE128$2.CODE128A = CODE128$2.CODE128 = undefined;
604
+
605
+ var _CODE128_AUTO = CODE128_AUTO;
606
+
607
+ var _CODE128_AUTO2 = _interopRequireDefault$r(_CODE128_AUTO);
608
+
609
+ var _CODE128A = CODE128A$1;
610
+
611
+ var _CODE128A2 = _interopRequireDefault$r(_CODE128A);
612
+
613
+ var _CODE128B = CODE128B$1;
614
+
615
+ var _CODE128B2 = _interopRequireDefault$r(_CODE128B);
616
+
617
+ var _CODE128C = CODE128C$1;
618
+
619
+ var _CODE128C2 = _interopRequireDefault$r(_CODE128C);
620
+
621
+ function _interopRequireDefault$r(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
622
+
623
+ CODE128$2.CODE128 = _CODE128_AUTO2.default;
624
+ CODE128$2.CODE128A = _CODE128A2.default;
625
+ CODE128$2.CODE128B = _CODE128B2.default;
626
+ CODE128$2.CODE128C = _CODE128C2.default;
627
+
628
+ var EAN_UPC = {};
629
+
630
+ var EAN13$1 = {};
631
+
632
+ var constants$1 = {};
633
+
634
+ Object.defineProperty(constants$1, "__esModule", {
635
+ value: true
636
+ });
637
+ // Standard start end and middle bits
638
+ constants$1.SIDE_BIN = '101';
639
+ constants$1.MIDDLE_BIN = '01010';
640
+
641
+ constants$1.BINARIES = {
642
+ 'L': [// The L (left) type of encoding
643
+ '0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011'],
644
+ 'G': [// The G type of encoding
645
+ '0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111'],
646
+ 'R': [// The R (right) type of encoding
647
+ '1110010', '1100110', '1101100', '1000010', '1011100', '1001110', '1010000', '1000100', '1001000', '1110100'],
648
+ 'O': [// The O (odd) encoding for UPC-E
649
+ '0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011'],
650
+ 'E': [// The E (even) encoding for UPC-E
651
+ '0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111']
652
+ };
653
+
654
+ // Define the EAN-2 structure
655
+ constants$1.EAN2_STRUCTURE = ['LL', 'LG', 'GL', 'GG'];
656
+
657
+ // Define the EAN-5 structure
658
+ constants$1.EAN5_STRUCTURE = ['GGLLL', 'GLGLL', 'GLLGL', 'GLLLG', 'LGGLL', 'LLGGL', 'LLLGG', 'LGLGL', 'LGLLG', 'LLGLG'];
659
+
660
+ // Define the EAN-13 structure
661
+ constants$1.EAN13_STRUCTURE = ['LLLLLL', 'LLGLGG', 'LLGGLG', 'LLGGGL', 'LGLLGG', 'LGGLLG', 'LGGGLL', 'LGLGLG', 'LGLGGL', 'LGGLGL'];
662
+
663
+ var EAN$1 = {};
664
+
665
+ var encoder = {};
666
+
667
+ Object.defineProperty(encoder, "__esModule", {
668
+ value: true
669
+ });
670
+
671
+ var _constants$5 = constants$1;
672
+
673
+ // Encode data string
674
+ var encode$1 = function encode(data, structure, separator) {
675
+ var encoded = data.split('').map(function (val, idx) {
676
+ return _constants$5.BINARIES[structure[idx]];
677
+ }).map(function (val, idx) {
678
+ return val ? val[data[idx]] : '';
679
+ });
680
+
681
+ if (separator) {
682
+ var last = data.length - 1;
683
+ encoded = encoded.map(function (val, idx) {
684
+ return idx < last ? val + separator : val;
685
+ });
686
+ }
687
+
688
+ return encoded.join('');
689
+ };
690
+
691
+ encoder.default = encode$1;
692
+
693
+ Object.defineProperty(EAN$1, "__esModule", {
694
+ value: true
695
+ });
696
+
697
+ var _createClass$g = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
698
+
699
+ var _constants$4 = constants$1;
700
+
701
+ var _encoder$4 = encoder;
702
+
703
+ var _encoder2$4 = _interopRequireDefault$q(_encoder$4);
704
+
705
+ var _Barcode2$9 = Barcode$1;
706
+
707
+ var _Barcode3$9 = _interopRequireDefault$q(_Barcode2$9);
708
+
709
+ function _interopRequireDefault$q(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
710
+
711
+ function _classCallCheck$l(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
712
+
713
+ function _possibleConstructorReturn$h(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
714
+
715
+ function _inherits$h(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
716
+
717
+ // Base class for EAN8 & EAN13
718
+ var EAN = function (_Barcode) {
719
+ _inherits$h(EAN, _Barcode);
720
+
721
+ function EAN(data, options) {
722
+ _classCallCheck$l(this, EAN);
723
+
724
+ // Make sure the font is not bigger than the space between the guard bars
725
+ var _this = _possibleConstructorReturn$h(this, (EAN.__proto__ || Object.getPrototypeOf(EAN)).call(this, data, options));
726
+
727
+ _this.fontSize = !options.flat && options.fontSize > options.width * 10 ? options.width * 10 : options.fontSize;
728
+
729
+ // Make the guard bars go down half the way of the text
730
+ _this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
731
+ return _this;
732
+ }
733
+
734
+ _createClass$g(EAN, [{
735
+ key: 'encode',
736
+ value: function encode() {
737
+ return this.options.flat ? this.encodeFlat() : this.encodeGuarded();
738
+ }
739
+ }, {
740
+ key: 'leftText',
741
+ value: function leftText(from, to) {
742
+ return this.text.substr(from, to);
743
+ }
744
+ }, {
745
+ key: 'leftEncode',
746
+ value: function leftEncode(data, structure) {
747
+ return (0, _encoder2$4.default)(data, structure);
748
+ }
749
+ }, {
750
+ key: 'rightText',
751
+ value: function rightText(from, to) {
752
+ return this.text.substr(from, to);
753
+ }
754
+ }, {
755
+ key: 'rightEncode',
756
+ value: function rightEncode(data, structure) {
757
+ return (0, _encoder2$4.default)(data, structure);
758
+ }
759
+ }, {
760
+ key: 'encodeGuarded',
761
+ value: function encodeGuarded() {
762
+ var textOptions = { fontSize: this.fontSize };
763
+ var guardOptions = { height: this.guardHeight };
764
+
765
+ return [{ data: _constants$4.SIDE_BIN, options: guardOptions }, { data: this.leftEncode(), text: this.leftText(), options: textOptions }, { data: _constants$4.MIDDLE_BIN, options: guardOptions }, { data: this.rightEncode(), text: this.rightText(), options: textOptions }, { data: _constants$4.SIDE_BIN, options: guardOptions }];
766
+ }
767
+ }, {
768
+ key: 'encodeFlat',
769
+ value: function encodeFlat() {
770
+ var data = [_constants$4.SIDE_BIN, this.leftEncode(), _constants$4.MIDDLE_BIN, this.rightEncode(), _constants$4.SIDE_BIN];
771
+
772
+ return {
773
+ data: data.join(''),
774
+ text: this.text
775
+ };
776
+ }
777
+ }]);
778
+
779
+ return EAN;
780
+ }(_Barcode3$9.default);
781
+
782
+ EAN$1.default = EAN;
783
+
784
+ Object.defineProperty(EAN13$1, "__esModule", {
785
+ value: true
786
+ });
787
+
788
+ var _createClass$f = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
789
+
790
+ var _get$1 = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
791
+
792
+ var _constants$3 = constants$1;
793
+
794
+ var _EAN2$2 = EAN$1;
795
+
796
+ var _EAN3$2 = _interopRequireDefault$p(_EAN2$2);
797
+
798
+ function _interopRequireDefault$p(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
799
+
800
+ function _classCallCheck$k(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
801
+
802
+ function _possibleConstructorReturn$g(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
803
+
804
+ function _inherits$g(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
805
+ // https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Binary_encoding_of_data_digits_into_EAN-13_barcode
806
+
807
+ // Calculate the checksum digit
808
+ // https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Calculation_of_checksum_digit
809
+ var checksum$4 = function checksum(number) {
810
+ var res = number.substr(0, 12).split('').map(function (n) {
811
+ return +n;
812
+ }).reduce(function (sum, a, idx) {
813
+ return idx % 2 ? sum + a * 3 : sum + a;
814
+ }, 0);
815
+
816
+ return (10 - res % 10) % 10;
817
+ };
818
+
819
+ var EAN13 = function (_EAN) {
820
+ _inherits$g(EAN13, _EAN);
821
+
822
+ function EAN13(data, options) {
823
+ _classCallCheck$k(this, EAN13);
824
+
825
+ // Add checksum if it does not exist
826
+ if (data.search(/^[0-9]{12}$/) !== -1) {
827
+ data += checksum$4(data);
828
+ }
829
+
830
+ // Adds a last character to the end of the barcode
831
+ var _this = _possibleConstructorReturn$g(this, (EAN13.__proto__ || Object.getPrototypeOf(EAN13)).call(this, data, options));
832
+
833
+ _this.lastChar = options.lastChar;
834
+ return _this;
835
+ }
836
+
837
+ _createClass$f(EAN13, [{
838
+ key: 'valid',
839
+ value: function valid() {
840
+ return this.data.search(/^[0-9]{13}$/) !== -1 && +this.data[12] === checksum$4(this.data);
841
+ }
842
+ }, {
843
+ key: 'leftText',
844
+ value: function leftText() {
845
+ return _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'leftText', this).call(this, 1, 6);
846
+ }
847
+ }, {
848
+ key: 'leftEncode',
849
+ value: function leftEncode() {
850
+ var data = this.data.substr(1, 6);
851
+ var structure = _constants$3.EAN13_STRUCTURE[this.data[0]];
852
+ return _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'leftEncode', this).call(this, data, structure);
853
+ }
854
+ }, {
855
+ key: 'rightText',
856
+ value: function rightText() {
857
+ return _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'rightText', this).call(this, 7, 6);
858
+ }
859
+ }, {
860
+ key: 'rightEncode',
861
+ value: function rightEncode() {
862
+ var data = this.data.substr(7, 6);
863
+ return _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'rightEncode', this).call(this, data, 'RRRRRR');
864
+ }
865
+
866
+ // The "standard" way of printing EAN13 barcodes with guard bars
867
+
868
+ }, {
869
+ key: 'encodeGuarded',
870
+ value: function encodeGuarded() {
871
+ var data = _get$1(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'encodeGuarded', this).call(this);
872
+
873
+ // Extend data with left digit & last character
874
+ if (this.options.displayValue) {
875
+ data.unshift({
876
+ data: '000000000000',
877
+ text: this.text.substr(0, 1),
878
+ options: { textAlign: 'left', fontSize: this.fontSize }
879
+ });
880
+
881
+ if (this.options.lastChar) {
882
+ data.push({
883
+ data: '00'
884
+ });
885
+ data.push({
886
+ data: '00000',
887
+ text: this.options.lastChar,
888
+ options: { fontSize: this.fontSize }
889
+ });
890
+ }
891
+ }
892
+
893
+ return data;
894
+ }
895
+ }]);
896
+
897
+ return EAN13;
898
+ }(_EAN3$2.default);
899
+
900
+ EAN13$1.default = EAN13;
901
+
902
+ var EAN8$1 = {};
903
+
904
+ Object.defineProperty(EAN8$1, "__esModule", {
905
+ value: true
906
+ });
907
+
908
+ var _createClass$e = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
909
+
910
+ var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
911
+
912
+ var _EAN2$1 = EAN$1;
913
+
914
+ var _EAN3$1 = _interopRequireDefault$o(_EAN2$1);
915
+
916
+ function _interopRequireDefault$o(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
917
+
918
+ function _classCallCheck$j(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
919
+
920
+ function _possibleConstructorReturn$f(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
921
+
922
+ function _inherits$f(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
923
+ // http://www.barcodeisland.com/ean8.phtml
924
+
925
+ // Calculate the checksum digit
926
+ var checksum$3 = function checksum(number) {
927
+ var res = number.substr(0, 7).split('').map(function (n) {
928
+ return +n;
929
+ }).reduce(function (sum, a, idx) {
930
+ return idx % 2 ? sum + a : sum + a * 3;
931
+ }, 0);
932
+
933
+ return (10 - res % 10) % 10;
934
+ };
935
+
936
+ var EAN8 = function (_EAN) {
937
+ _inherits$f(EAN8, _EAN);
938
+
939
+ function EAN8(data, options) {
940
+ _classCallCheck$j(this, EAN8);
941
+
942
+ // Add checksum if it does not exist
943
+ if (data.search(/^[0-9]{7}$/) !== -1) {
944
+ data += checksum$3(data);
945
+ }
946
+
947
+ return _possibleConstructorReturn$f(this, (EAN8.__proto__ || Object.getPrototypeOf(EAN8)).call(this, data, options));
948
+ }
949
+
950
+ _createClass$e(EAN8, [{
951
+ key: 'valid',
952
+ value: function valid() {
953
+ return this.data.search(/^[0-9]{8}$/) !== -1 && +this.data[7] === checksum$3(this.data);
954
+ }
955
+ }, {
956
+ key: 'leftText',
957
+ value: function leftText() {
958
+ return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'leftText', this).call(this, 0, 4);
959
+ }
960
+ }, {
961
+ key: 'leftEncode',
962
+ value: function leftEncode() {
963
+ var data = this.data.substr(0, 4);
964
+ return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'leftEncode', this).call(this, data, 'LLLL');
965
+ }
966
+ }, {
967
+ key: 'rightText',
968
+ value: function rightText() {
969
+ return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'rightText', this).call(this, 4, 4);
970
+ }
971
+ }, {
972
+ key: 'rightEncode',
973
+ value: function rightEncode() {
974
+ var data = this.data.substr(4, 4);
975
+ return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'rightEncode', this).call(this, data, 'RRRR');
976
+ }
977
+ }]);
978
+
979
+ return EAN8;
980
+ }(_EAN3$1.default);
981
+
982
+ EAN8$1.default = EAN8;
983
+
984
+ var EAN5$1 = {};
985
+
986
+ Object.defineProperty(EAN5$1, "__esModule", {
987
+ value: true
988
+ });
989
+
990
+ var _createClass$d = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
991
+
992
+ var _constants$2 = constants$1;
993
+
994
+ var _encoder$3 = encoder;
995
+
996
+ var _encoder2$3 = _interopRequireDefault$n(_encoder$3);
997
+
998
+ var _Barcode2$8 = Barcode$1;
999
+
1000
+ var _Barcode3$8 = _interopRequireDefault$n(_Barcode2$8);
1001
+
1002
+ function _interopRequireDefault$n(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1003
+
1004
+ function _classCallCheck$i(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1005
+
1006
+ function _possibleConstructorReturn$e(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1007
+
1008
+ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
1009
+ // https://en.wikipedia.org/wiki/EAN_5#Encoding
1010
+
1011
+ var checksum$2 = function checksum(data) {
1012
+ var result = data.split('').map(function (n) {
1013
+ return +n;
1014
+ }).reduce(function (sum, a, idx) {
1015
+ return idx % 2 ? sum + a * 9 : sum + a * 3;
1016
+ }, 0);
1017
+ return result % 10;
1018
+ };
1019
+
1020
+ var EAN5 = function (_Barcode) {
1021
+ _inherits$e(EAN5, _Barcode);
1022
+
1023
+ function EAN5(data, options) {
1024
+ _classCallCheck$i(this, EAN5);
1025
+
1026
+ return _possibleConstructorReturn$e(this, (EAN5.__proto__ || Object.getPrototypeOf(EAN5)).call(this, data, options));
1027
+ }
1028
+
1029
+ _createClass$d(EAN5, [{
1030
+ key: 'valid',
1031
+ value: function valid() {
1032
+ return this.data.search(/^[0-9]{5}$/) !== -1;
1033
+ }
1034
+ }, {
1035
+ key: 'encode',
1036
+ value: function encode() {
1037
+ var structure = _constants$2.EAN5_STRUCTURE[checksum$2(this.data)];
1038
+ return {
1039
+ data: '1011' + (0, _encoder2$3.default)(this.data, structure, '01'),
1040
+ text: this.text
1041
+ };
1042
+ }
1043
+ }]);
1044
+
1045
+ return EAN5;
1046
+ }(_Barcode3$8.default);
1047
+
1048
+ EAN5$1.default = EAN5;
1049
+
1050
+ var EAN2$1 = {};
1051
+
1052
+ Object.defineProperty(EAN2$1, "__esModule", {
1053
+ value: true
1054
+ });
1055
+
1056
+ var _createClass$c = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1057
+
1058
+ var _constants$1 = constants$1;
1059
+
1060
+ var _encoder$2 = encoder;
1061
+
1062
+ var _encoder2$2 = _interopRequireDefault$m(_encoder$2);
1063
+
1064
+ var _Barcode2$7 = Barcode$1;
1065
+
1066
+ var _Barcode3$7 = _interopRequireDefault$m(_Barcode2$7);
1067
+
1068
+ function _interopRequireDefault$m(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1069
+
1070
+ function _classCallCheck$h(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1071
+
1072
+ function _possibleConstructorReturn$d(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1073
+
1074
+ function _inherits$d(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
1075
+ // https://en.wikipedia.org/wiki/EAN_2#Encoding
1076
+
1077
+ var EAN2 = function (_Barcode) {
1078
+ _inherits$d(EAN2, _Barcode);
1079
+
1080
+ function EAN2(data, options) {
1081
+ _classCallCheck$h(this, EAN2);
1082
+
1083
+ return _possibleConstructorReturn$d(this, (EAN2.__proto__ || Object.getPrototypeOf(EAN2)).call(this, data, options));
1084
+ }
1085
+
1086
+ _createClass$c(EAN2, [{
1087
+ key: 'valid',
1088
+ value: function valid() {
1089
+ return this.data.search(/^[0-9]{2}$/) !== -1;
1090
+ }
1091
+ }, {
1092
+ key: 'encode',
1093
+ value: function encode() {
1094
+ // Choose the structure based on the number mod 4
1095
+ var structure = _constants$1.EAN2_STRUCTURE[parseInt(this.data) % 4];
1096
+ return {
1097
+ // Start bits + Encode the two digits with 01 in between
1098
+ data: '1011' + (0, _encoder2$2.default)(this.data, structure, '01'),
1099
+ text: this.text
1100
+ };
1101
+ }
1102
+ }]);
1103
+
1104
+ return EAN2;
1105
+ }(_Barcode3$7.default);
1106
+
1107
+ EAN2$1.default = EAN2;
1108
+
1109
+ var UPC$1 = {};
1110
+
1111
+ Object.defineProperty(UPC$1, "__esModule", {
1112
+ value: true
1113
+ });
1114
+
1115
+ var _createClass$b = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1116
+
1117
+ UPC$1.checksum = checksum$1;
1118
+
1119
+ var _encoder$1 = encoder;
1120
+
1121
+ var _encoder2$1 = _interopRequireDefault$l(_encoder$1);
1122
+
1123
+ var _Barcode2$6 = Barcode$1;
1124
+
1125
+ var _Barcode3$6 = _interopRequireDefault$l(_Barcode2$6);
1126
+
1127
+ function _interopRequireDefault$l(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1128
+
1129
+ function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1130
+
1131
+ function _possibleConstructorReturn$c(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1132
+
1133
+ function _inherits$c(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
1134
+ // https://en.wikipedia.org/wiki/Universal_Product_Code#Encoding
1135
+
1136
+ var UPC = function (_Barcode) {
1137
+ _inherits$c(UPC, _Barcode);
1138
+
1139
+ function UPC(data, options) {
1140
+ _classCallCheck$g(this, UPC);
1141
+
1142
+ // Add checksum if it does not exist
1143
+ if (data.search(/^[0-9]{11}$/) !== -1) {
1144
+ data += checksum$1(data);
1145
+ }
1146
+
1147
+ var _this = _possibleConstructorReturn$c(this, (UPC.__proto__ || Object.getPrototypeOf(UPC)).call(this, data, options));
1148
+
1149
+ _this.displayValue = options.displayValue;
1150
+
1151
+ // Make sure the font is not bigger than the space between the guard bars
1152
+ if (options.fontSize > options.width * 10) {
1153
+ _this.fontSize = options.width * 10;
1154
+ } else {
1155
+ _this.fontSize = options.fontSize;
1156
+ }
1157
+
1158
+ // Make the guard bars go down half the way of the text
1159
+ _this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
1160
+ return _this;
1161
+ }
1162
+
1163
+ _createClass$b(UPC, [{
1164
+ key: "valid",
1165
+ value: function valid() {
1166
+ return this.data.search(/^[0-9]{12}$/) !== -1 && this.data[11] == checksum$1(this.data);
1167
+ }
1168
+ }, {
1169
+ key: "encode",
1170
+ value: function encode() {
1171
+ if (this.options.flat) {
1172
+ return this.flatEncoding();
1173
+ } else {
1174
+ return this.guardedEncoding();
1175
+ }
1176
+ }
1177
+ }, {
1178
+ key: "flatEncoding",
1179
+ value: function flatEncoding() {
1180
+ var result = "";
1181
+
1182
+ result += "101";
1183
+ result += (0, _encoder2$1.default)(this.data.substr(0, 6), "LLLLLL");
1184
+ result += "01010";
1185
+ result += (0, _encoder2$1.default)(this.data.substr(6, 6), "RRRRRR");
1186
+ result += "101";
1187
+
1188
+ return {
1189
+ data: result,
1190
+ text: this.text
1191
+ };
1192
+ }
1193
+ }, {
1194
+ key: "guardedEncoding",
1195
+ value: function guardedEncoding() {
1196
+ var result = [];
1197
+
1198
+ // Add the first digit
1199
+ if (this.displayValue) {
1200
+ result.push({
1201
+ data: "00000000",
1202
+ text: this.text.substr(0, 1),
1203
+ options: { textAlign: "left", fontSize: this.fontSize }
1204
+ });
1205
+ }
1206
+
1207
+ // Add the guard bars
1208
+ result.push({
1209
+ data: "101" + (0, _encoder2$1.default)(this.data[0], "L"),
1210
+ options: { height: this.guardHeight }
1211
+ });
1212
+
1213
+ // Add the left side
1214
+ result.push({
1215
+ data: (0, _encoder2$1.default)(this.data.substr(1, 5), "LLLLL"),
1216
+ text: this.text.substr(1, 5),
1217
+ options: { fontSize: this.fontSize }
1218
+ });
1219
+
1220
+ // Add the middle bits
1221
+ result.push({
1222
+ data: "01010",
1223
+ options: { height: this.guardHeight }
1224
+ });
1225
+
1226
+ // Add the right side
1227
+ result.push({
1228
+ data: (0, _encoder2$1.default)(this.data.substr(6, 5), "RRRRR"),
1229
+ text: this.text.substr(6, 5),
1230
+ options: { fontSize: this.fontSize }
1231
+ });
1232
+
1233
+ // Add the end bits
1234
+ result.push({
1235
+ data: (0, _encoder2$1.default)(this.data[11], "R") + "101",
1236
+ options: { height: this.guardHeight }
1237
+ });
1238
+
1239
+ // Add the last digit
1240
+ if (this.displayValue) {
1241
+ result.push({
1242
+ data: "00000000",
1243
+ text: this.text.substr(11, 1),
1244
+ options: { textAlign: "right", fontSize: this.fontSize }
1245
+ });
1246
+ }
1247
+
1248
+ return result;
1249
+ }
1250
+ }]);
1251
+
1252
+ return UPC;
1253
+ }(_Barcode3$6.default);
1254
+
1255
+ // Calulate the checksum digit
1256
+ // https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Calculation_of_checksum_digit
1257
+
1258
+
1259
+ function checksum$1(number) {
1260
+ var result = 0;
1261
+
1262
+ var i;
1263
+ for (i = 1; i < 11; i += 2) {
1264
+ result += parseInt(number[i]);
1265
+ }
1266
+ for (i = 0; i < 11; i += 2) {
1267
+ result += parseInt(number[i]) * 3;
1268
+ }
1269
+
1270
+ return (10 - result % 10) % 10;
1271
+ }
1272
+
1273
+ UPC$1.default = UPC;
1274
+
1275
+ var UPCE$1 = {};
1276
+
1277
+ Object.defineProperty(UPCE$1, "__esModule", {
1278
+ value: true
1279
+ });
1280
+
1281
+ var _createClass$a = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1282
+
1283
+ var _encoder = encoder;
1284
+
1285
+ var _encoder2 = _interopRequireDefault$k(_encoder);
1286
+
1287
+ var _Barcode2$5 = Barcode$1;
1288
+
1289
+ var _Barcode3$5 = _interopRequireDefault$k(_Barcode2$5);
1290
+
1291
+ var _UPC$1 = UPC$1;
1292
+
1293
+ function _interopRequireDefault$k(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1294
+
1295
+ function _classCallCheck$f(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1296
+
1297
+ function _possibleConstructorReturn$b(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1298
+
1299
+ function _inherits$b(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
1300
+ // https://en.wikipedia.org/wiki/Universal_Product_Code#Encoding
1301
+ //
1302
+ // UPC-E documentation:
1303
+ // https://en.wikipedia.org/wiki/Universal_Product_Code#UPC-E
1304
+
1305
+ var EXPANSIONS = ["XX00000XXX", "XX10000XXX", "XX20000XXX", "XXX00000XX", "XXXX00000X", "XXXXX00005", "XXXXX00006", "XXXXX00007", "XXXXX00008", "XXXXX00009"];
1306
+
1307
+ var PARITIES = [["EEEOOO", "OOOEEE"], ["EEOEOO", "OOEOEE"], ["EEOOEO", "OOEEOE"], ["EEOOOE", "OOEEEO"], ["EOEEOO", "OEOOEE"], ["EOOEEO", "OEEOOE"], ["EOOOEE", "OEEEOO"], ["EOEOEO", "OEOEOE"], ["EOEOOE", "OEOEEO"], ["EOOEOE", "OEEOEO"]];
1308
+
1309
+ var UPCE = function (_Barcode) {
1310
+ _inherits$b(UPCE, _Barcode);
1311
+
1312
+ function UPCE(data, options) {
1313
+ _classCallCheck$f(this, UPCE);
1314
+
1315
+ var _this = _possibleConstructorReturn$b(this, (UPCE.__proto__ || Object.getPrototypeOf(UPCE)).call(this, data, options));
1316
+ // Code may be 6 or 8 digits;
1317
+ // A 7 digit code is ambiguous as to whether the extra digit
1318
+ // is a UPC-A check or number system digit.
1319
+
1320
+
1321
+ _this.isValid = false;
1322
+ if (data.search(/^[0-9]{6}$/) !== -1) {
1323
+ _this.middleDigits = data;
1324
+ _this.upcA = expandToUPCA(data, "0");
1325
+ _this.text = options.text || '' + _this.upcA[0] + data + _this.upcA[_this.upcA.length - 1];
1326
+ _this.isValid = true;
1327
+ } else if (data.search(/^[01][0-9]{7}$/) !== -1) {
1328
+ _this.middleDigits = data.substring(1, data.length - 1);
1329
+ _this.upcA = expandToUPCA(_this.middleDigits, data[0]);
1330
+
1331
+ if (_this.upcA[_this.upcA.length - 1] === data[data.length - 1]) {
1332
+ _this.isValid = true;
1333
+ } else {
1334
+ // checksum mismatch
1335
+ return _possibleConstructorReturn$b(_this);
1336
+ }
1337
+ } else {
1338
+ return _possibleConstructorReturn$b(_this);
1339
+ }
1340
+
1341
+ _this.displayValue = options.displayValue;
1342
+
1343
+ // Make sure the font is not bigger than the space between the guard bars
1344
+ if (options.fontSize > options.width * 10) {
1345
+ _this.fontSize = options.width * 10;
1346
+ } else {
1347
+ _this.fontSize = options.fontSize;
1348
+ }
1349
+
1350
+ // Make the guard bars go down half the way of the text
1351
+ _this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
1352
+ return _this;
1353
+ }
1354
+
1355
+ _createClass$a(UPCE, [{
1356
+ key: 'valid',
1357
+ value: function valid() {
1358
+ return this.isValid;
1359
+ }
1360
+ }, {
1361
+ key: 'encode',
1362
+ value: function encode() {
1363
+ if (this.options.flat) {
1364
+ return this.flatEncoding();
1365
+ } else {
1366
+ return this.guardedEncoding();
1367
+ }
1368
+ }
1369
+ }, {
1370
+ key: 'flatEncoding',
1371
+ value: function flatEncoding() {
1372
+ var result = "";
1373
+
1374
+ result += "101";
1375
+ result += this.encodeMiddleDigits();
1376
+ result += "010101";
1377
+
1378
+ return {
1379
+ data: result,
1380
+ text: this.text
1381
+ };
1382
+ }
1383
+ }, {
1384
+ key: 'guardedEncoding',
1385
+ value: function guardedEncoding() {
1386
+ var result = [];
1387
+
1388
+ // Add the UPC-A number system digit beneath the quiet zone
1389
+ if (this.displayValue) {
1390
+ result.push({
1391
+ data: "00000000",
1392
+ text: this.text[0],
1393
+ options: { textAlign: "left", fontSize: this.fontSize }
1394
+ });
1395
+ }
1396
+
1397
+ // Add the guard bars
1398
+ result.push({
1399
+ data: "101",
1400
+ options: { height: this.guardHeight }
1401
+ });
1402
+
1403
+ // Add the 6 UPC-E digits
1404
+ result.push({
1405
+ data: this.encodeMiddleDigits(),
1406
+ text: this.text.substring(1, 7),
1407
+ options: { fontSize: this.fontSize }
1408
+ });
1409
+
1410
+ // Add the end bits
1411
+ result.push({
1412
+ data: "010101",
1413
+ options: { height: this.guardHeight }
1414
+ });
1415
+
1416
+ // Add the UPC-A check digit beneath the quiet zone
1417
+ if (this.displayValue) {
1418
+ result.push({
1419
+ data: "00000000",
1420
+ text: this.text[7],
1421
+ options: { textAlign: "right", fontSize: this.fontSize }
1422
+ });
1423
+ }
1424
+
1425
+ return result;
1426
+ }
1427
+ }, {
1428
+ key: 'encodeMiddleDigits',
1429
+ value: function encodeMiddleDigits() {
1430
+ var numberSystem = this.upcA[0];
1431
+ var checkDigit = this.upcA[this.upcA.length - 1];
1432
+ var parity = PARITIES[parseInt(checkDigit)][parseInt(numberSystem)];
1433
+ return (0, _encoder2.default)(this.middleDigits, parity);
1434
+ }
1435
+ }]);
1436
+
1437
+ return UPCE;
1438
+ }(_Barcode3$5.default);
1439
+
1440
+ function expandToUPCA(middleDigits, numberSystem) {
1441
+ var lastUpcE = parseInt(middleDigits[middleDigits.length - 1]);
1442
+ var expansion = EXPANSIONS[lastUpcE];
1443
+
1444
+ var result = "";
1445
+ var digitIndex = 0;
1446
+ for (var i = 0; i < expansion.length; i++) {
1447
+ var c = expansion[i];
1448
+ if (c === 'X') {
1449
+ result += middleDigits[digitIndex++];
1450
+ } else {
1451
+ result += c;
1452
+ }
1453
+ }
1454
+
1455
+ result = '' + numberSystem + result;
1456
+ return '' + result + (0, _UPC$1.checksum)(result);
1457
+ }
1458
+
1459
+ UPCE$1.default = UPCE;
1460
+
1461
+ Object.defineProperty(EAN_UPC, "__esModule", {
1462
+ value: true
1463
+ });
1464
+ EAN_UPC.UPCE = EAN_UPC.UPC = EAN_UPC.EAN2 = EAN_UPC.EAN5 = EAN_UPC.EAN8 = EAN_UPC.EAN13 = undefined;
1465
+
1466
+ var _EAN = EAN13$1;
1467
+
1468
+ var _EAN2 = _interopRequireDefault$j(_EAN);
1469
+
1470
+ var _EAN3 = EAN8$1;
1471
+
1472
+ var _EAN4 = _interopRequireDefault$j(_EAN3);
1473
+
1474
+ var _EAN5 = EAN5$1;
1475
+
1476
+ var _EAN6 = _interopRequireDefault$j(_EAN5);
1477
+
1478
+ var _EAN7 = EAN2$1;
1479
+
1480
+ var _EAN8 = _interopRequireDefault$j(_EAN7);
1481
+
1482
+ var _UPC = UPC$1;
1483
+
1484
+ var _UPC2 = _interopRequireDefault$j(_UPC);
1485
+
1486
+ var _UPCE = UPCE$1;
1487
+
1488
+ var _UPCE2 = _interopRequireDefault$j(_UPCE);
1489
+
1490
+ function _interopRequireDefault$j(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1491
+
1492
+ EAN_UPC.EAN13 = _EAN2.default;
1493
+ EAN_UPC.EAN8 = _EAN4.default;
1494
+ EAN_UPC.EAN5 = _EAN6.default;
1495
+ EAN_UPC.EAN2 = _EAN8.default;
1496
+ EAN_UPC.UPC = _UPC2.default;
1497
+ EAN_UPC.UPCE = _UPCE2.default;
1498
+
1499
+ var ITF$2 = {};
1500
+
1501
+ var ITF$1 = {};
1502
+
1503
+ var constants = {};
1504
+
1505
+ Object.defineProperty(constants, "__esModule", {
1506
+ value: true
1507
+ });
1508
+ constants.START_BIN = '1010';
1509
+ constants.END_BIN = '11101';
1510
+
1511
+ constants.BINARIES = ['00110', '10001', '01001', '11000', '00101', '10100', '01100', '00011', '10010', '01010'];
1512
+
1513
+ Object.defineProperty(ITF$1, "__esModule", {
1514
+ value: true
1515
+ });
1516
+
1517
+ var _createClass$9 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1518
+
1519
+ var _constants = constants;
1520
+
1521
+ var _Barcode2$4 = Barcode$1;
1522
+
1523
+ var _Barcode3$4 = _interopRequireDefault$i(_Barcode2$4);
1524
+
1525
+ function _interopRequireDefault$i(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1526
+
1527
+ function _classCallCheck$e(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1528
+
1529
+ function _possibleConstructorReturn$a(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1530
+
1531
+ function _inherits$a(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1532
+
1533
+ var ITF = function (_Barcode) {
1534
+ _inherits$a(ITF, _Barcode);
1535
+
1536
+ function ITF() {
1537
+ _classCallCheck$e(this, ITF);
1538
+
1539
+ return _possibleConstructorReturn$a(this, (ITF.__proto__ || Object.getPrototypeOf(ITF)).apply(this, arguments));
1540
+ }
1541
+
1542
+ _createClass$9(ITF, [{
1543
+ key: 'valid',
1544
+ value: function valid() {
1545
+ return this.data.search(/^([0-9]{2})+$/) !== -1;
1546
+ }
1547
+ }, {
1548
+ key: 'encode',
1549
+ value: function encode() {
1550
+ var _this2 = this;
1551
+
1552
+ // Calculate all the digit pairs
1553
+ var encoded = this.data.match(/.{2}/g).map(function (pair) {
1554
+ return _this2.encodePair(pair);
1555
+ }).join('');
1556
+
1557
+ return {
1558
+ data: _constants.START_BIN + encoded + _constants.END_BIN,
1559
+ text: this.text
1560
+ };
1561
+ }
1562
+
1563
+ // Calculate the data of a number pair
1564
+
1565
+ }, {
1566
+ key: 'encodePair',
1567
+ value: function encodePair(pair) {
1568
+ var second = _constants.BINARIES[pair[1]];
1569
+
1570
+ return _constants.BINARIES[pair[0]].split('').map(function (first, idx) {
1571
+ return (first === '1' ? '111' : '1') + (second[idx] === '1' ? '000' : '0');
1572
+ }).join('');
1573
+ }
1574
+ }]);
1575
+
1576
+ return ITF;
1577
+ }(_Barcode3$4.default);
1578
+
1579
+ ITF$1.default = ITF;
1580
+
1581
+ var ITF14$1 = {};
1582
+
1583
+ Object.defineProperty(ITF14$1, "__esModule", {
1584
+ value: true
1585
+ });
1586
+
1587
+ var _createClass$8 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1588
+
1589
+ var _ITF2$1 = ITF$1;
1590
+
1591
+ var _ITF3$1 = _interopRequireDefault$h(_ITF2$1);
1592
+
1593
+ function _interopRequireDefault$h(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1594
+
1595
+ function _classCallCheck$d(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1596
+
1597
+ function _possibleConstructorReturn$9(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1598
+
1599
+ function _inherits$9(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1600
+
1601
+ // Calculate the checksum digit
1602
+ var checksum = function checksum(data) {
1603
+ var res = data.substr(0, 13).split('').map(function (num) {
1604
+ return parseInt(num, 10);
1605
+ }).reduce(function (sum, n, idx) {
1606
+ return sum + n * (3 - idx % 2 * 2);
1607
+ }, 0);
1608
+
1609
+ return Math.ceil(res / 10) * 10 - res;
1610
+ };
1611
+
1612
+ var ITF14 = function (_ITF) {
1613
+ _inherits$9(ITF14, _ITF);
1614
+
1615
+ function ITF14(data, options) {
1616
+ _classCallCheck$d(this, ITF14);
1617
+
1618
+ // Add checksum if it does not exist
1619
+ if (data.search(/^[0-9]{13}$/) !== -1) {
1620
+ data += checksum(data);
1621
+ }
1622
+ return _possibleConstructorReturn$9(this, (ITF14.__proto__ || Object.getPrototypeOf(ITF14)).call(this, data, options));
1623
+ }
1624
+
1625
+ _createClass$8(ITF14, [{
1626
+ key: 'valid',
1627
+ value: function valid() {
1628
+ return this.data.search(/^[0-9]{14}$/) !== -1 && +this.data[13] === checksum(this.data);
1629
+ }
1630
+ }]);
1631
+
1632
+ return ITF14;
1633
+ }(_ITF3$1.default);
1634
+
1635
+ ITF14$1.default = ITF14;
1636
+
1637
+ Object.defineProperty(ITF$2, "__esModule", {
1638
+ value: true
1639
+ });
1640
+ ITF$2.ITF14 = ITF$2.ITF = undefined;
1641
+
1642
+ var _ITF$1 = ITF$1;
1643
+
1644
+ var _ITF2 = _interopRequireDefault$g(_ITF$1);
1645
+
1646
+ var _ITF3 = ITF14$1;
1647
+
1648
+ var _ITF4 = _interopRequireDefault$g(_ITF3);
1649
+
1650
+ function _interopRequireDefault$g(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1651
+
1652
+ ITF$2.ITF = _ITF2.default;
1653
+ ITF$2.ITF14 = _ITF4.default;
1654
+
1655
+ var MSI$2 = {};
1656
+
1657
+ var MSI$1 = {};
1658
+
1659
+ Object.defineProperty(MSI$1, "__esModule", {
1660
+ value: true
1661
+ });
1662
+
1663
+ var _createClass$7 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1664
+
1665
+ var _Barcode2$3 = Barcode$1;
1666
+
1667
+ var _Barcode3$3 = _interopRequireDefault$f(_Barcode2$3);
1668
+
1669
+ function _interopRequireDefault$f(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1670
+
1671
+ function _classCallCheck$c(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1672
+
1673
+ function _possibleConstructorReturn$8(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1674
+
1675
+ function _inherits$8(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation
1676
+ // https://en.wikipedia.org/wiki/MSI_Barcode#Character_set_and_binary_lookup
1677
+
1678
+ var MSI = function (_Barcode) {
1679
+ _inherits$8(MSI, _Barcode);
1680
+
1681
+ function MSI(data, options) {
1682
+ _classCallCheck$c(this, MSI);
1683
+
1684
+ return _possibleConstructorReturn$8(this, (MSI.__proto__ || Object.getPrototypeOf(MSI)).call(this, data, options));
1685
+ }
1686
+
1687
+ _createClass$7(MSI, [{
1688
+ key: "encode",
1689
+ value: function encode() {
1690
+ // Start bits
1691
+ var ret = "110";
1692
+
1693
+ for (var i = 0; i < this.data.length; i++) {
1694
+ // Convert the character to binary (always 4 binary digits)
1695
+ var digit = parseInt(this.data[i]);
1696
+ var bin = digit.toString(2);
1697
+ bin = addZeroes(bin, 4 - bin.length);
1698
+
1699
+ // Add 100 for every zero and 110 for every 1
1700
+ for (var b = 0; b < bin.length; b++) {
1701
+ ret += bin[b] == "0" ? "100" : "110";
1702
+ }
1703
+ }
1704
+
1705
+ // End bits
1706
+ ret += "1001";
1707
+
1708
+ return {
1709
+ data: ret,
1710
+ text: this.text
1711
+ };
1712
+ }
1713
+ }, {
1714
+ key: "valid",
1715
+ value: function valid() {
1716
+ return this.data.search(/^[0-9]+$/) !== -1;
1717
+ }
1718
+ }]);
1719
+
1720
+ return MSI;
1721
+ }(_Barcode3$3.default);
1722
+
1723
+ function addZeroes(number, n) {
1724
+ for (var i = 0; i < n; i++) {
1725
+ number = "0" + number;
1726
+ }
1727
+ return number;
1728
+ }
1729
+
1730
+ MSI$1.default = MSI;
1731
+
1732
+ var MSI10$1 = {};
1733
+
1734
+ var checksums = {};
1735
+
1736
+ Object.defineProperty(checksums, "__esModule", {
1737
+ value: true
1738
+ });
1739
+ checksums.mod10 = mod10;
1740
+ checksums.mod11 = mod11;
1741
+ function mod10(number) {
1742
+ var sum = 0;
1743
+ for (var i = 0; i < number.length; i++) {
1744
+ var n = parseInt(number[i]);
1745
+ if ((i + number.length) % 2 === 0) {
1746
+ sum += n;
1747
+ } else {
1748
+ sum += n * 2 % 10 + Math.floor(n * 2 / 10);
1749
+ }
1750
+ }
1751
+ return (10 - sum % 10) % 10;
1752
+ }
1753
+
1754
+ function mod11(number) {
1755
+ var sum = 0;
1756
+ var weights = [2, 3, 4, 5, 6, 7];
1757
+ for (var i = 0; i < number.length; i++) {
1758
+ var n = parseInt(number[number.length - 1 - i]);
1759
+ sum += weights[i % weights.length] * n;
1760
+ }
1761
+ return (11 - sum % 11) % 11;
1762
+ }
1763
+
1764
+ Object.defineProperty(MSI10$1, "__esModule", {
1765
+ value: true
1766
+ });
1767
+
1768
+ var _MSI2$4 = MSI$1;
1769
+
1770
+ var _MSI3$4 = _interopRequireDefault$e(_MSI2$4);
1771
+
1772
+ var _checksums$3 = checksums;
1773
+
1774
+ function _interopRequireDefault$e(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1775
+
1776
+ function _classCallCheck$b(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1777
+
1778
+ function _possibleConstructorReturn$7(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1779
+
1780
+ function _inherits$7(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1781
+
1782
+ var MSI10 = function (_MSI) {
1783
+ _inherits$7(MSI10, _MSI);
1784
+
1785
+ function MSI10(data, options) {
1786
+ _classCallCheck$b(this, MSI10);
1787
+
1788
+ return _possibleConstructorReturn$7(this, (MSI10.__proto__ || Object.getPrototypeOf(MSI10)).call(this, data + (0, _checksums$3.mod10)(data), options));
1789
+ }
1790
+
1791
+ return MSI10;
1792
+ }(_MSI3$4.default);
1793
+
1794
+ MSI10$1.default = MSI10;
1795
+
1796
+ var MSI11$1 = {};
1797
+
1798
+ Object.defineProperty(MSI11$1, "__esModule", {
1799
+ value: true
1800
+ });
1801
+
1802
+ var _MSI2$3 = MSI$1;
1803
+
1804
+ var _MSI3$3 = _interopRequireDefault$d(_MSI2$3);
1805
+
1806
+ var _checksums$2 = checksums;
1807
+
1808
+ function _interopRequireDefault$d(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1809
+
1810
+ function _classCallCheck$a(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1811
+
1812
+ function _possibleConstructorReturn$6(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1813
+
1814
+ function _inherits$6(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1815
+
1816
+ var MSI11 = function (_MSI) {
1817
+ _inherits$6(MSI11, _MSI);
1818
+
1819
+ function MSI11(data, options) {
1820
+ _classCallCheck$a(this, MSI11);
1821
+
1822
+ return _possibleConstructorReturn$6(this, (MSI11.__proto__ || Object.getPrototypeOf(MSI11)).call(this, data + (0, _checksums$2.mod11)(data), options));
1823
+ }
1824
+
1825
+ return MSI11;
1826
+ }(_MSI3$3.default);
1827
+
1828
+ MSI11$1.default = MSI11;
1829
+
1830
+ var MSI1010$1 = {};
1831
+
1832
+ Object.defineProperty(MSI1010$1, "__esModule", {
1833
+ value: true
1834
+ });
1835
+
1836
+ var _MSI2$2 = MSI$1;
1837
+
1838
+ var _MSI3$2 = _interopRequireDefault$c(_MSI2$2);
1839
+
1840
+ var _checksums$1 = checksums;
1841
+
1842
+ function _interopRequireDefault$c(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1843
+
1844
+ function _classCallCheck$9(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1845
+
1846
+ function _possibleConstructorReturn$5(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1847
+
1848
+ function _inherits$5(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1849
+
1850
+ var MSI1010 = function (_MSI) {
1851
+ _inherits$5(MSI1010, _MSI);
1852
+
1853
+ function MSI1010(data, options) {
1854
+ _classCallCheck$9(this, MSI1010);
1855
+
1856
+ data += (0, _checksums$1.mod10)(data);
1857
+ data += (0, _checksums$1.mod10)(data);
1858
+ return _possibleConstructorReturn$5(this, (MSI1010.__proto__ || Object.getPrototypeOf(MSI1010)).call(this, data, options));
1859
+ }
1860
+
1861
+ return MSI1010;
1862
+ }(_MSI3$2.default);
1863
+
1864
+ MSI1010$1.default = MSI1010;
1865
+
1866
+ var MSI1110$1 = {};
1867
+
1868
+ Object.defineProperty(MSI1110$1, "__esModule", {
1869
+ value: true
1870
+ });
1871
+
1872
+ var _MSI2$1 = MSI$1;
1873
+
1874
+ var _MSI3$1 = _interopRequireDefault$b(_MSI2$1);
1875
+
1876
+ var _checksums = checksums;
1877
+
1878
+ function _interopRequireDefault$b(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1879
+
1880
+ function _classCallCheck$8(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1881
+
1882
+ function _possibleConstructorReturn$4(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1883
+
1884
+ function _inherits$4(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
1885
+
1886
+ var MSI1110 = function (_MSI) {
1887
+ _inherits$4(MSI1110, _MSI);
1888
+
1889
+ function MSI1110(data, options) {
1890
+ _classCallCheck$8(this, MSI1110);
1891
+
1892
+ data += (0, _checksums.mod11)(data);
1893
+ data += (0, _checksums.mod10)(data);
1894
+ return _possibleConstructorReturn$4(this, (MSI1110.__proto__ || Object.getPrototypeOf(MSI1110)).call(this, data, options));
1895
+ }
1896
+
1897
+ return MSI1110;
1898
+ }(_MSI3$1.default);
1899
+
1900
+ MSI1110$1.default = MSI1110;
1901
+
1902
+ Object.defineProperty(MSI$2, "__esModule", {
1903
+ value: true
1904
+ });
1905
+ MSI$2.MSI1110 = MSI$2.MSI1010 = MSI$2.MSI11 = MSI$2.MSI10 = MSI$2.MSI = undefined;
1906
+
1907
+ var _MSI$1 = MSI$1;
1908
+
1909
+ var _MSI2 = _interopRequireDefault$a(_MSI$1);
1910
+
1911
+ var _MSI3 = MSI10$1;
1912
+
1913
+ var _MSI4 = _interopRequireDefault$a(_MSI3);
1914
+
1915
+ var _MSI5 = MSI11$1;
1916
+
1917
+ var _MSI6 = _interopRequireDefault$a(_MSI5);
1918
+
1919
+ var _MSI7 = MSI1010$1;
1920
+
1921
+ var _MSI8 = _interopRequireDefault$a(_MSI7);
1922
+
1923
+ var _MSI9 = MSI1110$1;
1924
+
1925
+ var _MSI10 = _interopRequireDefault$a(_MSI9);
1926
+
1927
+ function _interopRequireDefault$a(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1928
+
1929
+ MSI$2.MSI = _MSI2.default;
1930
+ MSI$2.MSI10 = _MSI4.default;
1931
+ MSI$2.MSI11 = _MSI6.default;
1932
+ MSI$2.MSI1010 = _MSI8.default;
1933
+ MSI$2.MSI1110 = _MSI10.default;
1934
+
1935
+ var pharmacode$1 = {};
1936
+
1937
+ Object.defineProperty(pharmacode$1, "__esModule", {
1938
+ value: true
1939
+ });
1940
+ pharmacode$1.pharmacode = undefined;
1941
+
1942
+ var _createClass$6 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1943
+
1944
+ var _Barcode2$2 = Barcode$1;
1945
+
1946
+ var _Barcode3$2 = _interopRequireDefault$9(_Barcode2$2);
1947
+
1948
+ function _interopRequireDefault$9(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1949
+
1950
+ function _classCallCheck$7(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1951
+
1952
+ function _possibleConstructorReturn$3(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
1953
+
1954
+ function _inherits$3(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation
1955
+ // http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf
1956
+
1957
+ var pharmacode = function (_Barcode) {
1958
+ _inherits$3(pharmacode, _Barcode);
1959
+
1960
+ function pharmacode(data, options) {
1961
+ _classCallCheck$7(this, pharmacode);
1962
+
1963
+ var _this = _possibleConstructorReturn$3(this, (pharmacode.__proto__ || Object.getPrototypeOf(pharmacode)).call(this, data, options));
1964
+
1965
+ _this.number = parseInt(data, 10);
1966
+ return _this;
1967
+ }
1968
+
1969
+ _createClass$6(pharmacode, [{
1970
+ key: "encode",
1971
+ value: function encode() {
1972
+ var z = this.number;
1973
+ var result = "";
1974
+
1975
+ // http://i.imgur.com/RMm4UDJ.png
1976
+ // (source: http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf, page: 34)
1977
+ while (!isNaN(z) && z != 0) {
1978
+ if (z % 2 === 0) {
1979
+ // Even
1980
+ result = "11100" + result;
1981
+ z = (z - 2) / 2;
1982
+ } else {
1983
+ // Odd
1984
+ result = "100" + result;
1985
+ z = (z - 1) / 2;
1986
+ }
1987
+ }
1988
+
1989
+ // Remove the two last zeroes
1990
+ result = result.slice(0, -2);
1991
+
1992
+ return {
1993
+ data: result,
1994
+ text: this.text
1995
+ };
1996
+ }
1997
+ }, {
1998
+ key: "valid",
1999
+ value: function valid() {
2000
+ return this.number >= 3 && this.number <= 131070;
2001
+ }
2002
+ }]);
2003
+
2004
+ return pharmacode;
2005
+ }(_Barcode3$2.default);
2006
+
2007
+ pharmacode$1.pharmacode = pharmacode;
2008
+
2009
+ var codabar$1 = {};
2010
+
2011
+ Object.defineProperty(codabar$1, "__esModule", {
2012
+ value: true
2013
+ });
2014
+ codabar$1.codabar = undefined;
2015
+
2016
+ var _createClass$5 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2017
+
2018
+ var _Barcode2$1 = Barcode$1;
2019
+
2020
+ var _Barcode3$1 = _interopRequireDefault$8(_Barcode2$1);
2021
+
2022
+ function _interopRequireDefault$8(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2023
+
2024
+ function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2025
+
2026
+ function _possibleConstructorReturn$2(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2027
+
2028
+ function _inherits$2(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding specification:
2029
+ // http://www.barcodeisland.com/codabar.phtml
2030
+
2031
+ var codabar = function (_Barcode) {
2032
+ _inherits$2(codabar, _Barcode);
2033
+
2034
+ function codabar(data, options) {
2035
+ _classCallCheck$6(this, codabar);
2036
+
2037
+ if (data.search(/^[0-9\-\$\:\.\+\/]+$/) === 0) {
2038
+ data = "A" + data + "A";
2039
+ }
2040
+
2041
+ var _this = _possibleConstructorReturn$2(this, (codabar.__proto__ || Object.getPrototypeOf(codabar)).call(this, data.toUpperCase(), options));
2042
+
2043
+ _this.text = _this.options.text || _this.text.replace(/[A-D]/g, '');
2044
+ return _this;
2045
+ }
2046
+
2047
+ _createClass$5(codabar, [{
2048
+ key: "valid",
2049
+ value: function valid() {
2050
+ return this.data.search(/^[A-D][0-9\-\$\:\.\+\/]+[A-D]$/) !== -1;
2051
+ }
2052
+ }, {
2053
+ key: "encode",
2054
+ value: function encode() {
2055
+ var result = [];
2056
+ var encodings = this.getEncodings();
2057
+ for (var i = 0; i < this.data.length; i++) {
2058
+ result.push(encodings[this.data.charAt(i)]);
2059
+ // for all characters except the last, append a narrow-space ("0")
2060
+ if (i !== this.data.length - 1) {
2061
+ result.push("0");
2062
+ }
2063
+ }
2064
+ return {
2065
+ text: this.text,
2066
+ data: result.join('')
2067
+ };
2068
+ }
2069
+ }, {
2070
+ key: "getEncodings",
2071
+ value: function getEncodings() {
2072
+ return {
2073
+ "0": "101010011",
2074
+ "1": "101011001",
2075
+ "2": "101001011",
2076
+ "3": "110010101",
2077
+ "4": "101101001",
2078
+ "5": "110101001",
2079
+ "6": "100101011",
2080
+ "7": "100101101",
2081
+ "8": "100110101",
2082
+ "9": "110100101",
2083
+ "-": "101001101",
2084
+ "$": "101100101",
2085
+ ":": "1101011011",
2086
+ "/": "1101101011",
2087
+ ".": "1101101101",
2088
+ "+": "1011011011",
2089
+ "A": "1011001001",
2090
+ "B": "1001001011",
2091
+ "C": "1010010011",
2092
+ "D": "1010011001"
2093
+ };
2094
+ }
2095
+ }]);
2096
+
2097
+ return codabar;
2098
+ }(_Barcode3$1.default);
2099
+
2100
+ codabar$1.codabar = codabar;
2101
+
2102
+ var GenericBarcode$1 = {};
2103
+
2104
+ Object.defineProperty(GenericBarcode$1, "__esModule", {
2105
+ value: true
2106
+ });
2107
+ GenericBarcode$1.GenericBarcode = undefined;
2108
+
2109
+ var _createClass$4 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2110
+
2111
+ var _Barcode2 = Barcode$1;
2112
+
2113
+ var _Barcode3 = _interopRequireDefault$7(_Barcode2);
2114
+
2115
+ function _interopRequireDefault$7(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2116
+
2117
+ function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2118
+
2119
+ function _possibleConstructorReturn$1(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2120
+
2121
+ function _inherits$1(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2122
+
2123
+ var GenericBarcode = function (_Barcode) {
2124
+ _inherits$1(GenericBarcode, _Barcode);
2125
+
2126
+ function GenericBarcode(data, options) {
2127
+ _classCallCheck$5(this, GenericBarcode);
2128
+
2129
+ return _possibleConstructorReturn$1(this, (GenericBarcode.__proto__ || Object.getPrototypeOf(GenericBarcode)).call(this, data, options)); // Sets this.data and this.text
2130
+ }
2131
+
2132
+ // Return the corresponding binary numbers for the data provided
2133
+
2134
+
2135
+ _createClass$4(GenericBarcode, [{
2136
+ key: "encode",
2137
+ value: function encode() {
2138
+ return {
2139
+ data: "10101010101010101010101010101010101010101",
2140
+ text: this.text
2141
+ };
2142
+ }
2143
+
2144
+ // Resturn true/false if the string provided is valid for this encoder
2145
+
2146
+ }, {
2147
+ key: "valid",
2148
+ value: function valid() {
2149
+ return true;
2150
+ }
2151
+ }]);
2152
+
2153
+ return GenericBarcode;
2154
+ }(_Barcode3.default);
2155
+
2156
+ GenericBarcode$1.GenericBarcode = GenericBarcode;
2157
+
2158
+ Object.defineProperty(barcodes, "__esModule", {
2159
+ value: true
2160
+ });
2161
+
2162
+ var _CODE = CODE39$1;
2163
+
2164
+ var _CODE2 = CODE128$2;
2165
+
2166
+ var _EAN_UPC = EAN_UPC;
2167
+
2168
+ var _ITF = ITF$2;
2169
+
2170
+ var _MSI = MSI$2;
2171
+
2172
+ var _pharmacode = pharmacode$1;
2173
+
2174
+ var _codabar = codabar$1;
2175
+
2176
+ var _GenericBarcode = GenericBarcode$1;
2177
+
2178
+ barcodes.default = {
2179
+ CODE39: _CODE.CODE39,
2180
+ CODE128: _CODE2.CODE128, CODE128A: _CODE2.CODE128A, CODE128B: _CODE2.CODE128B, CODE128C: _CODE2.CODE128C,
2181
+ EAN13: _EAN_UPC.EAN13, EAN8: _EAN_UPC.EAN8, EAN5: _EAN_UPC.EAN5, EAN2: _EAN_UPC.EAN2, UPC: _EAN_UPC.UPC, UPCE: _EAN_UPC.UPCE,
2182
+ ITF14: _ITF.ITF14,
2183
+ ITF: _ITF.ITF,
2184
+ MSI: _MSI.MSI, MSI10: _MSI.MSI10, MSI11: _MSI.MSI11, MSI1010: _MSI.MSI1010, MSI1110: _MSI.MSI1110,
2185
+ pharmacode: _pharmacode.pharmacode,
2186
+ codabar: _codabar.codabar,
2187
+ GenericBarcode: _GenericBarcode.GenericBarcode
2188
+ };
2189
+
2190
+ var merge = {};
2191
+
2192
+ Object.defineProperty(merge, "__esModule", {
2193
+ value: true
2194
+ });
2195
+
2196
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
2197
+
2198
+ merge.default = function (old, replaceObj) {
2199
+ return _extends({}, old, replaceObj);
2200
+ };
2201
+
2202
+ var linearizeEncodings$1 = {};
2203
+
2204
+ Object.defineProperty(linearizeEncodings$1, "__esModule", {
2205
+ value: true
2206
+ });
2207
+ linearizeEncodings$1.default = linearizeEncodings;
2208
+
2209
+ // Encodings can be nestled like [[1-1, 1-2], 2, [3-1, 3-2]
2210
+ // Convert to [1-1, 1-2, 2, 3-1, 3-2]
2211
+
2212
+ function linearizeEncodings(encodings) {
2213
+ var linearEncodings = [];
2214
+ function nextLevel(encoded) {
2215
+ if (Array.isArray(encoded)) {
2216
+ for (var i = 0; i < encoded.length; i++) {
2217
+ nextLevel(encoded[i]);
2218
+ }
2219
+ } else {
2220
+ encoded.text = encoded.text || "";
2221
+ encoded.data = encoded.data || "";
2222
+ linearEncodings.push(encoded);
2223
+ }
2224
+ }
2225
+ nextLevel(encodings);
2226
+
2227
+ return linearEncodings;
2228
+ }
2229
+
2230
+ var fixOptions$1 = {};
2231
+
2232
+ Object.defineProperty(fixOptions$1, "__esModule", {
2233
+ value: true
2234
+ });
2235
+ fixOptions$1.default = fixOptions;
2236
+
2237
+
2238
+ function fixOptions(options) {
2239
+ // Fix the margins
2240
+ options.marginTop = options.marginTop || options.margin;
2241
+ options.marginBottom = options.marginBottom || options.margin;
2242
+ options.marginRight = options.marginRight || options.margin;
2243
+ options.marginLeft = options.marginLeft || options.margin;
2244
+
2245
+ return options;
2246
+ }
2247
+
2248
+ var getRenderProperties$1 = {};
2249
+
2250
+ var getOptionsFromElement$1 = {};
2251
+
2252
+ var optionsFromStrings$1 = {};
2253
+
2254
+ Object.defineProperty(optionsFromStrings$1, "__esModule", {
2255
+ value: true
2256
+ });
2257
+ optionsFromStrings$1.default = optionsFromStrings;
2258
+
2259
+ // Convert string to integers/booleans where it should be
2260
+
2261
+ function optionsFromStrings(options) {
2262
+ var intOptions = ["width", "height", "textMargin", "fontSize", "margin", "marginTop", "marginBottom", "marginLeft", "marginRight"];
2263
+
2264
+ for (var intOption in intOptions) {
2265
+ if (intOptions.hasOwnProperty(intOption)) {
2266
+ intOption = intOptions[intOption];
2267
+ if (typeof options[intOption] === "string") {
2268
+ options[intOption] = parseInt(options[intOption], 10);
2269
+ }
2270
+ }
2271
+ }
2272
+
2273
+ if (typeof options["displayValue"] === "string") {
2274
+ options["displayValue"] = options["displayValue"] != "false";
2275
+ }
2276
+
2277
+ return options;
2278
+ }
2279
+
2280
+ var defaults$1 = {};
2281
+
2282
+ Object.defineProperty(defaults$1, "__esModule", {
2283
+ value: true
2284
+ });
2285
+ var defaults = {
2286
+ width: 2,
2287
+ height: 100,
2288
+ format: "auto",
2289
+ displayValue: true,
2290
+ fontOptions: "",
2291
+ font: "monospace",
2292
+ text: undefined,
2293
+ textAlign: "center",
2294
+ textPosition: "bottom",
2295
+ textMargin: 2,
2296
+ fontSize: 20,
2297
+ background: "#ffffff",
2298
+ lineColor: "#000000",
2299
+ margin: 10,
2300
+ marginTop: undefined,
2301
+ marginBottom: undefined,
2302
+ marginLeft: undefined,
2303
+ marginRight: undefined,
2304
+ valid: function valid() {}
2305
+ };
2306
+
2307
+ defaults$1.default = defaults;
2308
+
2309
+ Object.defineProperty(getOptionsFromElement$1, "__esModule", {
2310
+ value: true
2311
+ });
2312
+
2313
+ var _optionsFromStrings$1 = optionsFromStrings$1;
2314
+
2315
+ var _optionsFromStrings2$1 = _interopRequireDefault$6(_optionsFromStrings$1);
2316
+
2317
+ var _defaults$1 = defaults$1;
2318
+
2319
+ var _defaults2$1 = _interopRequireDefault$6(_defaults$1);
2320
+
2321
+ function _interopRequireDefault$6(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2322
+
2323
+ function getOptionsFromElement(element) {
2324
+ var options = {};
2325
+ for (var property in _defaults2$1.default) {
2326
+ if (_defaults2$1.default.hasOwnProperty(property)) {
2327
+ // jsbarcode-*
2328
+ if (element.hasAttribute("jsbarcode-" + property.toLowerCase())) {
2329
+ options[property] = element.getAttribute("jsbarcode-" + property.toLowerCase());
2330
+ }
2331
+
2332
+ // data-*
2333
+ if (element.hasAttribute("data-" + property.toLowerCase())) {
2334
+ options[property] = element.getAttribute("data-" + property.toLowerCase());
2335
+ }
2336
+ }
2337
+ }
2338
+
2339
+ options["value"] = element.getAttribute("jsbarcode-value") || element.getAttribute("data-value");
2340
+
2341
+ // Since all atributes are string they need to be converted to integers
2342
+ options = (0, _optionsFromStrings2$1.default)(options);
2343
+
2344
+ return options;
2345
+ }
2346
+
2347
+ getOptionsFromElement$1.default = getOptionsFromElement;
2348
+
2349
+ var renderers = {};
2350
+
2351
+ var canvas = {};
2352
+
2353
+ var shared = {};
2354
+
2355
+ Object.defineProperty(shared, "__esModule", {
2356
+ value: true
2357
+ });
2358
+ shared.getTotalWidthOfEncodings = shared.calculateEncodingAttributes = shared.getBarcodePadding = shared.getEncodingHeight = shared.getMaximumHeightOfEncodings = undefined;
2359
+
2360
+ var _merge$3 = merge;
2361
+
2362
+ var _merge2$3 = _interopRequireDefault$5(_merge$3);
2363
+
2364
+ function _interopRequireDefault$5(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2365
+
2366
+ function getEncodingHeight(encoding, options) {
2367
+ return options.height + (options.displayValue && encoding.text.length > 0 ? options.fontSize + options.textMargin : 0) + options.marginTop + options.marginBottom;
2368
+ }
2369
+
2370
+ function getBarcodePadding(textWidth, barcodeWidth, options) {
2371
+ if (options.displayValue && barcodeWidth < textWidth) {
2372
+ if (options.textAlign == "center") {
2373
+ return Math.floor((textWidth - barcodeWidth) / 2);
2374
+ } else if (options.textAlign == "left") {
2375
+ return 0;
2376
+ } else if (options.textAlign == "right") {
2377
+ return Math.floor(textWidth - barcodeWidth);
2378
+ }
2379
+ }
2380
+ return 0;
2381
+ }
2382
+
2383
+ function calculateEncodingAttributes(encodings, barcodeOptions, context) {
2384
+ for (var i = 0; i < encodings.length; i++) {
2385
+ var encoding = encodings[i];
2386
+ var options = (0, _merge2$3.default)(barcodeOptions, encoding.options);
2387
+
2388
+ // Calculate the width of the encoding
2389
+ var textWidth;
2390
+ if (options.displayValue) {
2391
+ textWidth = messureText(encoding.text, options, context);
2392
+ } else {
2393
+ textWidth = 0;
2394
+ }
2395
+
2396
+ var barcodeWidth = encoding.data.length * options.width;
2397
+ encoding.width = Math.ceil(Math.max(textWidth, barcodeWidth));
2398
+
2399
+ encoding.height = getEncodingHeight(encoding, options);
2400
+
2401
+ encoding.barcodePadding = getBarcodePadding(textWidth, barcodeWidth, options);
2402
+ }
2403
+ }
2404
+
2405
+ function getTotalWidthOfEncodings(encodings) {
2406
+ var totalWidth = 0;
2407
+ for (var i = 0; i < encodings.length; i++) {
2408
+ totalWidth += encodings[i].width;
2409
+ }
2410
+ return totalWidth;
2411
+ }
2412
+
2413
+ function getMaximumHeightOfEncodings(encodings) {
2414
+ var maxHeight = 0;
2415
+ for (var i = 0; i < encodings.length; i++) {
2416
+ if (encodings[i].height > maxHeight) {
2417
+ maxHeight = encodings[i].height;
2418
+ }
2419
+ }
2420
+ return maxHeight;
2421
+ }
2422
+
2423
+ function messureText(string, options, context) {
2424
+ var ctx;
2425
+
2426
+ if (context) {
2427
+ ctx = context;
2428
+ } else if (typeof document !== "undefined") {
2429
+ ctx = document.createElement("canvas").getContext("2d");
2430
+ } else {
2431
+ // If the text cannot be messured we will return 0.
2432
+ // This will make some barcode with big text render incorrectly
2433
+ return 0;
2434
+ }
2435
+ ctx.font = options.fontOptions + " " + options.fontSize + "px " + options.font;
2436
+
2437
+ // Calculate the width of the encoding
2438
+ var measureTextResult = ctx.measureText(string);
2439
+ if (!measureTextResult) {
2440
+ // Some implementations don't implement measureText and return undefined.
2441
+ // If the text cannot be measured we will return 0.
2442
+ // This will make some barcode with big text render incorrectly
2443
+ return 0;
2444
+ }
2445
+ var size = measureTextResult.width;
2446
+ return size;
2447
+ }
2448
+
2449
+ shared.getMaximumHeightOfEncodings = getMaximumHeightOfEncodings;
2450
+ shared.getEncodingHeight = getEncodingHeight;
2451
+ shared.getBarcodePadding = getBarcodePadding;
2452
+ shared.calculateEncodingAttributes = calculateEncodingAttributes;
2453
+ shared.getTotalWidthOfEncodings = getTotalWidthOfEncodings;
2454
+
2455
+ Object.defineProperty(canvas, "__esModule", {
2456
+ value: true
2457
+ });
2458
+
2459
+ var _createClass$3 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2460
+
2461
+ var _merge$2 = merge;
2462
+
2463
+ var _merge2$2 = _interopRequireDefault$4(_merge$2);
2464
+
2465
+ var _shared$1 = shared;
2466
+
2467
+ function _interopRequireDefault$4(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2468
+
2469
+ function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2470
+
2471
+ var CanvasRenderer = function () {
2472
+ function CanvasRenderer(canvas, encodings, options) {
2473
+ _classCallCheck$4(this, CanvasRenderer);
2474
+
2475
+ this.canvas = canvas;
2476
+ this.encodings = encodings;
2477
+ this.options = options;
2478
+ }
2479
+
2480
+ _createClass$3(CanvasRenderer, [{
2481
+ key: "render",
2482
+ value: function render() {
2483
+ // Abort if the browser does not support HTML5 canvas
2484
+ if (!this.canvas.getContext) {
2485
+ throw new Error('The browser does not support canvas.');
2486
+ }
2487
+
2488
+ this.prepareCanvas();
2489
+ for (var i = 0; i < this.encodings.length; i++) {
2490
+ var encodingOptions = (0, _merge2$2.default)(this.options, this.encodings[i].options);
2491
+
2492
+ this.drawCanvasBarcode(encodingOptions, this.encodings[i]);
2493
+ this.drawCanvasText(encodingOptions, this.encodings[i]);
2494
+
2495
+ this.moveCanvasDrawing(this.encodings[i]);
2496
+ }
2497
+
2498
+ this.restoreCanvas();
2499
+ }
2500
+ }, {
2501
+ key: "prepareCanvas",
2502
+ value: function prepareCanvas() {
2503
+ // Get the canvas context
2504
+ var ctx = this.canvas.getContext("2d");
2505
+
2506
+ ctx.save();
2507
+
2508
+ (0, _shared$1.calculateEncodingAttributes)(this.encodings, this.options, ctx);
2509
+ var totalWidth = (0, _shared$1.getTotalWidthOfEncodings)(this.encodings);
2510
+ var maxHeight = (0, _shared$1.getMaximumHeightOfEncodings)(this.encodings);
2511
+
2512
+ this.canvas.width = totalWidth + this.options.marginLeft + this.options.marginRight;
2513
+
2514
+ this.canvas.height = maxHeight;
2515
+
2516
+ // Paint the canvas
2517
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
2518
+ if (this.options.background) {
2519
+ ctx.fillStyle = this.options.background;
2520
+ ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
2521
+ }
2522
+
2523
+ ctx.translate(this.options.marginLeft, 0);
2524
+ }
2525
+ }, {
2526
+ key: "drawCanvasBarcode",
2527
+ value: function drawCanvasBarcode(options, encoding) {
2528
+ // Get the canvas context
2529
+ var ctx = this.canvas.getContext("2d");
2530
+
2531
+ var binary = encoding.data;
2532
+
2533
+ // Creates the barcode out of the encoded binary
2534
+ var yFrom;
2535
+ if (options.textPosition == "top") {
2536
+ yFrom = options.marginTop + options.fontSize + options.textMargin;
2537
+ } else {
2538
+ yFrom = options.marginTop;
2539
+ }
2540
+
2541
+ ctx.fillStyle = options.lineColor;
2542
+
2543
+ for (var b = 0; b < binary.length; b++) {
2544
+ var x = b * options.width + encoding.barcodePadding;
2545
+
2546
+ if (binary[b] === "1") {
2547
+ ctx.fillRect(x, yFrom, options.width, options.height);
2548
+ } else if (binary[b]) {
2549
+ ctx.fillRect(x, yFrom, options.width, options.height * binary[b]);
2550
+ }
2551
+ }
2552
+ }
2553
+ }, {
2554
+ key: "drawCanvasText",
2555
+ value: function drawCanvasText(options, encoding) {
2556
+ // Get the canvas context
2557
+ var ctx = this.canvas.getContext("2d");
2558
+
2559
+ var font = options.fontOptions + " " + options.fontSize + "px " + options.font;
2560
+
2561
+ // Draw the text if displayValue is set
2562
+ if (options.displayValue) {
2563
+ var x, y;
2564
+
2565
+ if (options.textPosition == "top") {
2566
+ y = options.marginTop + options.fontSize - options.textMargin;
2567
+ } else {
2568
+ y = options.height + options.textMargin + options.marginTop + options.fontSize;
2569
+ }
2570
+
2571
+ ctx.font = font;
2572
+
2573
+ // Draw the text in the correct X depending on the textAlign option
2574
+ if (options.textAlign == "left" || encoding.barcodePadding > 0) {
2575
+ x = 0;
2576
+ ctx.textAlign = 'left';
2577
+ } else if (options.textAlign == "right") {
2578
+ x = encoding.width - 1;
2579
+ ctx.textAlign = 'right';
2580
+ }
2581
+ // In all other cases, center the text
2582
+ else {
2583
+ x = encoding.width / 2;
2584
+ ctx.textAlign = 'center';
2585
+ }
2586
+
2587
+ ctx.fillText(encoding.text, x, y);
2588
+ }
2589
+ }
2590
+ }, {
2591
+ key: "moveCanvasDrawing",
2592
+ value: function moveCanvasDrawing(encoding) {
2593
+ var ctx = this.canvas.getContext("2d");
2594
+
2595
+ ctx.translate(encoding.width, 0);
2596
+ }
2597
+ }, {
2598
+ key: "restoreCanvas",
2599
+ value: function restoreCanvas() {
2600
+ // Get the canvas context
2601
+ var ctx = this.canvas.getContext("2d");
2602
+
2603
+ ctx.restore();
2604
+ }
2605
+ }]);
2606
+
2607
+ return CanvasRenderer;
2608
+ }();
2609
+
2610
+ canvas.default = CanvasRenderer;
2611
+
2612
+ var svg = {};
2613
+
2614
+ Object.defineProperty(svg, "__esModule", {
2615
+ value: true
2616
+ });
2617
+
2618
+ var _createClass$2 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2619
+
2620
+ var _merge$1 = merge;
2621
+
2622
+ var _merge2$1 = _interopRequireDefault$3(_merge$1);
2623
+
2624
+ var _shared = shared;
2625
+
2626
+ function _interopRequireDefault$3(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2627
+
2628
+ function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2629
+
2630
+ var svgns = "http://www.w3.org/2000/svg";
2631
+
2632
+ var SVGRenderer = function () {
2633
+ function SVGRenderer(svg, encodings, options) {
2634
+ _classCallCheck$3(this, SVGRenderer);
2635
+
2636
+ this.svg = svg;
2637
+ this.encodings = encodings;
2638
+ this.options = options;
2639
+ this.document = options.xmlDocument || document;
2640
+ }
2641
+
2642
+ _createClass$2(SVGRenderer, [{
2643
+ key: "render",
2644
+ value: function render() {
2645
+ var currentX = this.options.marginLeft;
2646
+
2647
+ this.prepareSVG();
2648
+ for (var i = 0; i < this.encodings.length; i++) {
2649
+ var encoding = this.encodings[i];
2650
+ var encodingOptions = (0, _merge2$1.default)(this.options, encoding.options);
2651
+
2652
+ var group = this.createGroup(currentX, encodingOptions.marginTop, this.svg);
2653
+
2654
+ this.setGroupOptions(group, encodingOptions);
2655
+
2656
+ this.drawSvgBarcode(group, encodingOptions, encoding);
2657
+ this.drawSVGText(group, encodingOptions, encoding);
2658
+
2659
+ currentX += encoding.width;
2660
+ }
2661
+ }
2662
+ }, {
2663
+ key: "prepareSVG",
2664
+ value: function prepareSVG() {
2665
+ // Clear the SVG
2666
+ while (this.svg.firstChild) {
2667
+ this.svg.removeChild(this.svg.firstChild);
2668
+ }
2669
+
2670
+ (0, _shared.calculateEncodingAttributes)(this.encodings, this.options);
2671
+ var totalWidth = (0, _shared.getTotalWidthOfEncodings)(this.encodings);
2672
+ var maxHeight = (0, _shared.getMaximumHeightOfEncodings)(this.encodings);
2673
+
2674
+ var width = totalWidth + this.options.marginLeft + this.options.marginRight;
2675
+ this.setSvgAttributes(width, maxHeight);
2676
+
2677
+ if (this.options.background) {
2678
+ this.drawRect(0, 0, width, maxHeight, this.svg).setAttribute("style", "fill:" + this.options.background + ";");
2679
+ }
2680
+ }
2681
+ }, {
2682
+ key: "drawSvgBarcode",
2683
+ value: function drawSvgBarcode(parent, options, encoding) {
2684
+ var binary = encoding.data;
2685
+
2686
+ // Creates the barcode out of the encoded binary
2687
+ var yFrom;
2688
+ if (options.textPosition == "top") {
2689
+ yFrom = options.fontSize + options.textMargin;
2690
+ } else {
2691
+ yFrom = 0;
2692
+ }
2693
+
2694
+ var barWidth = 0;
2695
+ var x = 0;
2696
+ for (var b = 0; b < binary.length; b++) {
2697
+ x = b * options.width + encoding.barcodePadding;
2698
+
2699
+ if (binary[b] === "1") {
2700
+ barWidth++;
2701
+ } else if (barWidth > 0) {
2702
+ this.drawRect(x - options.width * barWidth, yFrom, options.width * barWidth, options.height, parent);
2703
+ barWidth = 0;
2704
+ }
2705
+ }
2706
+
2707
+ // Last draw is needed since the barcode ends with 1
2708
+ if (barWidth > 0) {
2709
+ this.drawRect(x - options.width * (barWidth - 1), yFrom, options.width * barWidth, options.height, parent);
2710
+ }
2711
+ }
2712
+ }, {
2713
+ key: "drawSVGText",
2714
+ value: function drawSVGText(parent, options, encoding) {
2715
+ var textElem = this.document.createElementNS(svgns, 'text');
2716
+
2717
+ // Draw the text if displayValue is set
2718
+ if (options.displayValue) {
2719
+ var x, y;
2720
+
2721
+ textElem.setAttribute("style", "font:" + options.fontOptions + " " + options.fontSize + "px " + options.font);
2722
+
2723
+ if (options.textPosition == "top") {
2724
+ y = options.fontSize - options.textMargin;
2725
+ } else {
2726
+ y = options.height + options.textMargin + options.fontSize;
2727
+ }
2728
+
2729
+ // Draw the text in the correct X depending on the textAlign option
2730
+ if (options.textAlign == "left" || encoding.barcodePadding > 0) {
2731
+ x = 0;
2732
+ textElem.setAttribute("text-anchor", "start");
2733
+ } else if (options.textAlign == "right") {
2734
+ x = encoding.width - 1;
2735
+ textElem.setAttribute("text-anchor", "end");
2736
+ }
2737
+ // In all other cases, center the text
2738
+ else {
2739
+ x = encoding.width / 2;
2740
+ textElem.setAttribute("text-anchor", "middle");
2741
+ }
2742
+
2743
+ textElem.setAttribute("x", x);
2744
+ textElem.setAttribute("y", y);
2745
+
2746
+ textElem.appendChild(this.document.createTextNode(encoding.text));
2747
+
2748
+ parent.appendChild(textElem);
2749
+ }
2750
+ }
2751
+ }, {
2752
+ key: "setSvgAttributes",
2753
+ value: function setSvgAttributes(width, height) {
2754
+ var svg = this.svg;
2755
+ svg.setAttribute("width", width + "px");
2756
+ svg.setAttribute("height", height + "px");
2757
+ svg.setAttribute("x", "0px");
2758
+ svg.setAttribute("y", "0px");
2759
+ svg.setAttribute("viewBox", "0 0 " + width + " " + height);
2760
+
2761
+ svg.setAttribute("xmlns", svgns);
2762
+ svg.setAttribute("version", "1.1");
2763
+
2764
+ svg.setAttribute("style", "transform: translate(0,0)");
2765
+ }
2766
+ }, {
2767
+ key: "createGroup",
2768
+ value: function createGroup(x, y, parent) {
2769
+ var group = this.document.createElementNS(svgns, 'g');
2770
+ group.setAttribute("transform", "translate(" + x + ", " + y + ")");
2771
+
2772
+ parent.appendChild(group);
2773
+
2774
+ return group;
2775
+ }
2776
+ }, {
2777
+ key: "setGroupOptions",
2778
+ value: function setGroupOptions(group, options) {
2779
+ group.setAttribute("style", "fill:" + options.lineColor + ";");
2780
+ }
2781
+ }, {
2782
+ key: "drawRect",
2783
+ value: function drawRect(x, y, width, height, parent) {
2784
+ var rect = this.document.createElementNS(svgns, 'rect');
2785
+
2786
+ rect.setAttribute("x", x);
2787
+ rect.setAttribute("y", y);
2788
+ rect.setAttribute("width", width);
2789
+ rect.setAttribute("height", height);
2790
+
2791
+ parent.appendChild(rect);
2792
+
2793
+ return rect;
2794
+ }
2795
+ }]);
2796
+
2797
+ return SVGRenderer;
2798
+ }();
2799
+
2800
+ svg.default = SVGRenderer;
2801
+
2802
+ var object = {};
2803
+
2804
+ Object.defineProperty(object, "__esModule", {
2805
+ value: true
2806
+ });
2807
+
2808
+ var _createClass$1 = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2809
+
2810
+ function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2811
+
2812
+ var ObjectRenderer = function () {
2813
+ function ObjectRenderer(object, encodings, options) {
2814
+ _classCallCheck$2(this, ObjectRenderer);
2815
+
2816
+ this.object = object;
2817
+ this.encodings = encodings;
2818
+ this.options = options;
2819
+ }
2820
+
2821
+ _createClass$1(ObjectRenderer, [{
2822
+ key: "render",
2823
+ value: function render() {
2824
+ this.object.encodings = this.encodings;
2825
+ }
2826
+ }]);
2827
+
2828
+ return ObjectRenderer;
2829
+ }();
2830
+
2831
+ object.default = ObjectRenderer;
2832
+
2833
+ Object.defineProperty(renderers, "__esModule", {
2834
+ value: true
2835
+ });
2836
+
2837
+ var _canvas = canvas;
2838
+
2839
+ var _canvas2 = _interopRequireDefault$2(_canvas);
2840
+
2841
+ var _svg = svg;
2842
+
2843
+ var _svg2 = _interopRequireDefault$2(_svg);
2844
+
2845
+ var _object = object;
2846
+
2847
+ var _object2 = _interopRequireDefault$2(_object);
2848
+
2849
+ function _interopRequireDefault$2(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2850
+
2851
+ renderers.default = { CanvasRenderer: _canvas2.default, SVGRenderer: _svg2.default, ObjectRenderer: _object2.default };
2852
+
2853
+ var exceptions = {};
2854
+
2855
+ Object.defineProperty(exceptions, "__esModule", {
2856
+ value: true
2857
+ });
2858
+
2859
+ function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2860
+
2861
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
2862
+
2863
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
2864
+
2865
+ var InvalidInputException = function (_Error) {
2866
+ _inherits(InvalidInputException, _Error);
2867
+
2868
+ function InvalidInputException(symbology, input) {
2869
+ _classCallCheck$1(this, InvalidInputException);
2870
+
2871
+ var _this = _possibleConstructorReturn(this, (InvalidInputException.__proto__ || Object.getPrototypeOf(InvalidInputException)).call(this));
2872
+
2873
+ _this.name = "InvalidInputException";
2874
+
2875
+ _this.symbology = symbology;
2876
+ _this.input = input;
2877
+
2878
+ _this.message = '"' + _this.input + '" is not a valid input for ' + _this.symbology;
2879
+ return _this;
2880
+ }
2881
+
2882
+ return InvalidInputException;
2883
+ }(Error);
2884
+
2885
+ var InvalidElementException = function (_Error2) {
2886
+ _inherits(InvalidElementException, _Error2);
2887
+
2888
+ function InvalidElementException() {
2889
+ _classCallCheck$1(this, InvalidElementException);
2890
+
2891
+ var _this2 = _possibleConstructorReturn(this, (InvalidElementException.__proto__ || Object.getPrototypeOf(InvalidElementException)).call(this));
2892
+
2893
+ _this2.name = "InvalidElementException";
2894
+ _this2.message = "Not supported type to render on";
2895
+ return _this2;
2896
+ }
2897
+
2898
+ return InvalidElementException;
2899
+ }(Error);
2900
+
2901
+ var NoElementException = function (_Error3) {
2902
+ _inherits(NoElementException, _Error3);
2903
+
2904
+ function NoElementException() {
2905
+ _classCallCheck$1(this, NoElementException);
2906
+
2907
+ var _this3 = _possibleConstructorReturn(this, (NoElementException.__proto__ || Object.getPrototypeOf(NoElementException)).call(this));
2908
+
2909
+ _this3.name = "NoElementException";
2910
+ _this3.message = "No element to render on.";
2911
+ return _this3;
2912
+ }
2913
+
2914
+ return NoElementException;
2915
+ }(Error);
2916
+
2917
+ exceptions.InvalidInputException = InvalidInputException;
2918
+ exceptions.InvalidElementException = InvalidElementException;
2919
+ exceptions.NoElementException = NoElementException;
2920
+
2921
+ Object.defineProperty(getRenderProperties$1, "__esModule", {
2922
+ value: true
2923
+ });
2924
+
2925
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /* global HTMLImageElement */
2926
+ /* global HTMLCanvasElement */
2927
+ /* global SVGElement */
2928
+
2929
+ var _getOptionsFromElement = getOptionsFromElement$1;
2930
+
2931
+ var _getOptionsFromElement2 = _interopRequireDefault$1(_getOptionsFromElement);
2932
+
2933
+ var _renderers = renderers;
2934
+
2935
+ var _renderers2 = _interopRequireDefault$1(_renderers);
2936
+
2937
+ var _exceptions$1 = exceptions;
2938
+
2939
+ function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2940
+
2941
+ // Takes an element and returns an object with information about how
2942
+ // it should be rendered
2943
+ // This could also return an array with these objects
2944
+ // {
2945
+ // element: The element that the renderer should draw on
2946
+ // renderer: The name of the renderer
2947
+ // afterRender (optional): If something has to done after the renderer
2948
+ // completed, calls afterRender (function)
2949
+ // options (optional): Options that can be defined in the element
2950
+ // }
2951
+
2952
+ function getRenderProperties(element) {
2953
+ // If the element is a string, query select call again
2954
+ if (typeof element === "string") {
2955
+ return querySelectedRenderProperties(element);
2956
+ }
2957
+ // If element is array. Recursivly call with every object in the array
2958
+ else if (Array.isArray(element)) {
2959
+ var returnArray = [];
2960
+ for (var i = 0; i < element.length; i++) {
2961
+ returnArray.push(getRenderProperties(element[i]));
2962
+ }
2963
+ return returnArray;
2964
+ }
2965
+ // If element, render on canvas and set the uri as src
2966
+ else if (typeof HTMLCanvasElement !== 'undefined' && element instanceof HTMLImageElement) {
2967
+ return newCanvasRenderProperties(element);
2968
+ }
2969
+ // If SVG
2970
+ else if (element && element.nodeName && element.nodeName.toLowerCase() === 'svg' || typeof SVGElement !== 'undefined' && element instanceof SVGElement) {
2971
+ return {
2972
+ element: element,
2973
+ options: (0, _getOptionsFromElement2.default)(element),
2974
+ renderer: _renderers2.default.SVGRenderer
2975
+ };
2976
+ }
2977
+ // If canvas (in browser)
2978
+ else if (typeof HTMLCanvasElement !== 'undefined' && element instanceof HTMLCanvasElement) {
2979
+ return {
2980
+ element: element,
2981
+ options: (0, _getOptionsFromElement2.default)(element),
2982
+ renderer: _renderers2.default.CanvasRenderer
2983
+ };
2984
+ }
2985
+ // If canvas (in node)
2986
+ else if (element && element.getContext) {
2987
+ return {
2988
+ element: element,
2989
+ renderer: _renderers2.default.CanvasRenderer
2990
+ };
2991
+ } else if (element && (typeof element === "undefined" ? "undefined" : _typeof(element)) === 'object' && !element.nodeName) {
2992
+ return {
2993
+ element: element,
2994
+ renderer: _renderers2.default.ObjectRenderer
2995
+ };
2996
+ } else {
2997
+ throw new _exceptions$1.InvalidElementException();
2998
+ }
2999
+ }
3000
+
3001
+ function querySelectedRenderProperties(string) {
3002
+ var selector = document.querySelectorAll(string);
3003
+ if (selector.length === 0) {
3004
+ return undefined;
3005
+ } else {
3006
+ var returnArray = [];
3007
+ for (var i = 0; i < selector.length; i++) {
3008
+ returnArray.push(getRenderProperties(selector[i]));
3009
+ }
3010
+ return returnArray;
3011
+ }
3012
+ }
3013
+
3014
+ function newCanvasRenderProperties(imgElement) {
3015
+ var canvas = document.createElement('canvas');
3016
+ return {
3017
+ element: canvas,
3018
+ options: (0, _getOptionsFromElement2.default)(imgElement),
3019
+ renderer: _renderers2.default.CanvasRenderer,
3020
+ afterRender: function afterRender() {
3021
+ imgElement.setAttribute("src", canvas.toDataURL());
3022
+ }
3023
+ };
3024
+ }
3025
+
3026
+ getRenderProperties$1.default = getRenderProperties;
3027
+
3028
+ var ErrorHandler$1 = {};
3029
+
3030
+ Object.defineProperty(ErrorHandler$1, "__esModule", {
3031
+ value: true
3032
+ });
3033
+
3034
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
3035
+
3036
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3037
+
3038
+ /*eslint no-console: 0 */
3039
+
3040
+ var ErrorHandler = function () {
3041
+ function ErrorHandler(api) {
3042
+ _classCallCheck(this, ErrorHandler);
3043
+
3044
+ this.api = api;
3045
+ }
3046
+
3047
+ _createClass(ErrorHandler, [{
3048
+ key: "handleCatch",
3049
+ value: function handleCatch(e) {
3050
+ // If babel supported extending of Error in a correct way instanceof would be used here
3051
+ if (e.name === "InvalidInputException") {
3052
+ if (this.api._options.valid !== this.api._defaults.valid) {
3053
+ this.api._options.valid(false);
3054
+ } else {
3055
+ throw e.message;
3056
+ }
3057
+ } else {
3058
+ throw e;
3059
+ }
3060
+
3061
+ this.api.render = function () {};
3062
+ }
3063
+ }, {
3064
+ key: "wrapBarcodeCall",
3065
+ value: function wrapBarcodeCall(func) {
3066
+ try {
3067
+ var result = func.apply(undefined, arguments);
3068
+ this.api._options.valid(true);
3069
+ return result;
3070
+ } catch (e) {
3071
+ this.handleCatch(e);
3072
+
3073
+ return this.api;
3074
+ }
3075
+ }
3076
+ }]);
3077
+
3078
+ return ErrorHandler;
3079
+ }();
3080
+
3081
+ ErrorHandler$1.default = ErrorHandler;
3082
+
3083
+ var _barcodes = barcodes;
3084
+
3085
+ var _barcodes2 = _interopRequireDefault(_barcodes);
3086
+
3087
+ var _merge = merge;
3088
+
3089
+ var _merge2 = _interopRequireDefault(_merge);
3090
+
3091
+ var _linearizeEncodings = linearizeEncodings$1;
3092
+
3093
+ var _linearizeEncodings2 = _interopRequireDefault(_linearizeEncodings);
3094
+
3095
+ var _fixOptions = fixOptions$1;
3096
+
3097
+ var _fixOptions2 = _interopRequireDefault(_fixOptions);
3098
+
3099
+ var _getRenderProperties = getRenderProperties$1;
3100
+
3101
+ var _getRenderProperties2 = _interopRequireDefault(_getRenderProperties);
3102
+
3103
+ var _optionsFromStrings = optionsFromStrings$1;
3104
+
3105
+ var _optionsFromStrings2 = _interopRequireDefault(_optionsFromStrings);
3106
+
3107
+ var _ErrorHandler = ErrorHandler$1;
3108
+
3109
+ var _ErrorHandler2 = _interopRequireDefault(_ErrorHandler);
3110
+
3111
+ var _exceptions = exceptions;
3112
+
3113
+ var _defaults = defaults$1;
3114
+
3115
+ var _defaults2 = _interopRequireDefault(_defaults);
3116
+
3117
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
3118
+
3119
+ // The protype of the object returned from the JsBarcode() call
3120
+
3121
+
3122
+ // Help functions
3123
+ var API = function API() {};
3124
+
3125
+ // The first call of the library API
3126
+ // Will return an object with all barcodes calls and the data that is used
3127
+ // by the renderers
3128
+
3129
+
3130
+ // Default values
3131
+
3132
+
3133
+ // Exceptions
3134
+ // Import all the barcodes
3135
+ var JsBarcode = function JsBarcode(element, text, options) {
3136
+ var api = new API();
3137
+
3138
+ if (typeof element === "undefined") {
3139
+ throw Error("No element to render on was provided.");
3140
+ }
3141
+
3142
+ // Variables that will be pased through the API calls
3143
+ api._renderProperties = (0, _getRenderProperties2.default)(element);
3144
+ api._encodings = [];
3145
+ api._options = _defaults2.default;
3146
+ api._errorHandler = new _ErrorHandler2.default(api);
3147
+
3148
+ // If text is set, use the simple syntax (render the barcode directly)
3149
+ if (typeof text !== "undefined") {
3150
+ options = options || {};
3151
+
3152
+ if (!options.format) {
3153
+ options.format = autoSelectBarcode();
3154
+ }
3155
+
3156
+ api.options(options)[options.format](text, options).render();
3157
+ }
3158
+
3159
+ return api;
3160
+ };
3161
+
3162
+ // To make tests work TODO: remove
3163
+ JsBarcode.getModule = function (name) {
3164
+ return _barcodes2.default[name];
3165
+ };
3166
+
3167
+ // Register all barcodes
3168
+ for (var name in _barcodes2.default) {
3169
+ if (_barcodes2.default.hasOwnProperty(name)) {
3170
+ // Security check if the propery is a prototype property
3171
+ registerBarcode(_barcodes2.default, name);
3172
+ }
3173
+ }
3174
+ function registerBarcode(barcodes, name) {
3175
+ API.prototype[name] = API.prototype[name.toUpperCase()] = API.prototype[name.toLowerCase()] = function (text, options) {
3176
+ var api = this;
3177
+ return api._errorHandler.wrapBarcodeCall(function () {
3178
+ // Ensure text is options.text
3179
+ options.text = typeof options.text === 'undefined' ? undefined : '' + options.text;
3180
+
3181
+ var newOptions = (0, _merge2.default)(api._options, options);
3182
+ newOptions = (0, _optionsFromStrings2.default)(newOptions);
3183
+ var Encoder = barcodes[name];
3184
+ var encoded = encode(text, Encoder, newOptions);
3185
+ api._encodings.push(encoded);
3186
+
3187
+ return api;
3188
+ });
3189
+ };
3190
+ }
3191
+
3192
+ // encode() handles the Encoder call and builds the binary string to be rendered
3193
+ function encode(text, Encoder, options) {
3194
+ // Ensure that text is a string
3195
+ text = "" + text;
3196
+
3197
+ var encoder = new Encoder(text, options);
3198
+
3199
+ // If the input is not valid for the encoder, throw error.
3200
+ // If the valid callback option is set, call it instead of throwing error
3201
+ if (!encoder.valid()) {
3202
+ throw new _exceptions.InvalidInputException(encoder.constructor.name, text);
3203
+ }
3204
+
3205
+ // Make a request for the binary data (and other infromation) that should be rendered
3206
+ var encoded = encoder.encode();
3207
+
3208
+ // Encodings can be nestled like [[1-1, 1-2], 2, [3-1, 3-2]
3209
+ // Convert to [1-1, 1-2, 2, 3-1, 3-2]
3210
+ encoded = (0, _linearizeEncodings2.default)(encoded);
3211
+
3212
+ // Merge
3213
+ for (var i = 0; i < encoded.length; i++) {
3214
+ encoded[i].options = (0, _merge2.default)(options, encoded[i].options);
3215
+ }
3216
+
3217
+ return encoded;
3218
+ }
3219
+
3220
+ function autoSelectBarcode() {
3221
+ // If CODE128 exists. Use it
3222
+ if (_barcodes2.default["CODE128"]) {
3223
+ return "CODE128";
3224
+ }
3225
+
3226
+ // Else, take the first (probably only) barcode
3227
+ return Object.keys(_barcodes2.default)[0];
3228
+ }
3229
+
3230
+ // Sets global encoder options
3231
+ // Added to the api by the JsBarcode function
3232
+ API.prototype.options = function (options) {
3233
+ this._options = (0, _merge2.default)(this._options, options);
3234
+ return this;
3235
+ };
3236
+
3237
+ // Will create a blank space (usually in between barcodes)
3238
+ API.prototype.blank = function (size) {
3239
+ var zeroes = new Array(size + 1).join("0");
3240
+ this._encodings.push({ data: zeroes });
3241
+ return this;
3242
+ };
3243
+
3244
+ // Initialize JsBarcode on all HTML elements defined.
3245
+ API.prototype.init = function () {
3246
+ // Should do nothing if no elements where found
3247
+ if (!this._renderProperties) {
3248
+ return;
3249
+ }
3250
+
3251
+ // Make sure renderProperies is an array
3252
+ if (!Array.isArray(this._renderProperties)) {
3253
+ this._renderProperties = [this._renderProperties];
3254
+ }
3255
+
3256
+ var renderProperty;
3257
+ for (var i in this._renderProperties) {
3258
+ renderProperty = this._renderProperties[i];
3259
+ var options = (0, _merge2.default)(this._options, renderProperty.options);
3260
+
3261
+ if (options.format == "auto") {
3262
+ options.format = autoSelectBarcode();
3263
+ }
3264
+
3265
+ this._errorHandler.wrapBarcodeCall(function () {
3266
+ var text = options.value;
3267
+ var Encoder = _barcodes2.default[options.format.toUpperCase()];
3268
+ var encoded = encode(text, Encoder, options);
3269
+
3270
+ render(renderProperty, encoded, options);
3271
+ });
3272
+ }
3273
+ };
3274
+
3275
+ // The render API call. Calls the real render function.
3276
+ API.prototype.render = function () {
3277
+ if (!this._renderProperties) {
3278
+ throw new _exceptions.NoElementException();
3279
+ }
3280
+
3281
+ if (Array.isArray(this._renderProperties)) {
3282
+ for (var i = 0; i < this._renderProperties.length; i++) {
3283
+ render(this._renderProperties[i], this._encodings, this._options);
3284
+ }
3285
+ } else {
3286
+ render(this._renderProperties, this._encodings, this._options);
3287
+ }
3288
+
3289
+ return this;
3290
+ };
3291
+
3292
+ API.prototype._defaults = _defaults2.default;
3293
+
3294
+ // Prepares the encodings and calls the renderer
3295
+ function render(renderProperties, encodings, options) {
3296
+ encodings = (0, _linearizeEncodings2.default)(encodings);
3297
+
3298
+ for (var i = 0; i < encodings.length; i++) {
3299
+ encodings[i].options = (0, _merge2.default)(options, encodings[i].options);
3300
+ (0, _fixOptions2.default)(encodings[i].options);
3301
+ }
3302
+
3303
+ (0, _fixOptions2.default)(options);
3304
+
3305
+ var Renderer = renderProperties.renderer;
3306
+ var renderer = new Renderer(renderProperties.element, encodings, options);
3307
+ renderer.render();
3308
+
3309
+ if (renderProperties.afterRender) {
3310
+ renderProperties.afterRender();
3311
+ }
3312
+ }
3313
+
3314
+ // Export to browser
3315
+ if (typeof window !== "undefined") {
3316
+ window.JsBarcode = JsBarcode;
3317
+ }
3318
+
3319
+ // Export to jQuery
3320
+ /*global jQuery */
3321
+ if (typeof jQuery !== 'undefined') {
3322
+ jQuery.fn.JsBarcode = function (content, options) {
3323
+ var elementArray = [];
3324
+ jQuery(this).each(function () {
3325
+ elementArray.push(this);
3326
+ });
3327
+ return JsBarcode(elementArray, content, options);
3328
+ };
3329
+ }
3330
+
3331
+ // Export to commonJS
3332
+ var JsBarcode_1 = JsBarcode;
3333
+
3334
+ const ReactBarcode = ({ style, className, value, options, renderer = "svg" }) => {
3335
+ const containerRef = React.useRef(null);
3336
+ React.useEffect(() => {
3337
+ JsBarcode_1(containerRef.current, value, options);
3338
+ }, [value, options, renderer]);
3339
+ switch (renderer) {
3340
+ case 'canvas':
3341
+ return jsx("canvas", { ref: containerRef, style: style, className: className }, void 0);
3342
+ case 'image':
3343
+ return jsx("img", { ref: containerRef, alt: "barcode", style: style, className: className }, void 0);
3344
+ default:
3345
+ return jsx("svg", { ref: containerRef, style: style, className: className }, void 0);
3346
+ }
3347
+ };
3348
+
3349
+ export { ReactBarcode as default };
3350
+ //# sourceMappingURL=index.esm.js.map