react-jsbarcode 0.2.0 → 0.2.3

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