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