javascript-barcode-reader
Advanced tools
Comparing version 0.4.14 to 0.4.15
var javascriptBarcodeReader = (function (jimp) { | ||
'use strict'; | ||
'use strict'; | ||
jimp = jimp && jimp.hasOwnProperty('default') ? jimp['default'] : jimp; | ||
jimp = jimp && jimp.hasOwnProperty('default') ? jimp['default'] : jimp; | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
return _typeof(obj); | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
var runtime_1 = createCommonjsModule(function (module) { | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
var runtime = function (exports) { | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
var Op = Object.prototype; | ||
var hasOwn = Op.hasOwnProperty; | ||
var undefined$1; // More compressible than void 0. | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
var $Symbol = typeof Symbol === "function" ? Symbol : {}; | ||
var iteratorSymbol = $Symbol.iterator || "@@iterator"; | ||
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; | ||
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; | ||
var generator = Object.create(protoGenerator.prototype); | ||
var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next, | ||
// .throw, and .return methods. | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
generator._invoke = makeInvokeMethod(innerFn, self, context); | ||
return generator; | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion | ||
// record like context.tryEntries[i].completion. This interface could | ||
// have been (and was previously) designed to take a closure to be | ||
// invoked without arguments, but in all the cases we care about we | ||
// already have an existing method we want to call, so there's no need | ||
// to create a new function object. We can even get away with assuming | ||
// the method takes exactly one argument, since that happens to be true | ||
// in every case, so we don't have to touch the arguments object. The | ||
// only additional allocation required is the completion record, which | ||
// has a stable shape and so hopefully should be cheap to allocate. | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { | ||
type: "normal", | ||
arg: fn.call(obj, arg) | ||
}; | ||
} catch (err) { | ||
return { | ||
type: "throw", | ||
arg: err | ||
}; | ||
} | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var GenStateSuspendedStart = "suspendedStart"; | ||
var GenStateSuspendedYield = "suspendedYield"; | ||
var GenStateExecuting = "executing"; | ||
var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as | ||
// breaking out of the dispatch switch statement. | ||
var isNode = (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && process.release && process.release.name === 'node'; // check if string is url | ||
var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and | ||
// .constructor.prototype properties for functions that return Generator | ||
// objects. For full spec compliance, you may wish to configure your | ||
// minifier not to mangle the names of these two functions. | ||
function isUrl(s) { | ||
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/; | ||
return !s[0] === '#' || regexp.test(s); | ||
} | ||
/** | ||
* Creates image data from HTML image | ||
* @param {HTMLImageElement} image HTML Image element | ||
*/ | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function createImageData(image) { | ||
var canvas = document.createElement('canvas'); | ||
var ctx = canvas.getContext('2d'); | ||
var width = image.naturalWidth; | ||
var height = image.naturalHeight; | ||
canvas.width = width; | ||
canvas.height = height; | ||
ctx.drawImage(image, 0, 0); | ||
return ctx.getImageData(0, 0, image.naturalWidth, image.naturalHeight); | ||
} | ||
/** | ||
* Reads image source and returns imageData as only callback parameter | ||
* @param {*} source Image source | ||
* @param {Function} callback Callback to pass the imageData | ||
*/ | ||
function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that | ||
// don't natively support it. | ||
function getImageDataFromSource(_x) { | ||
return _getImageDataFromSource.apply(this, arguments); | ||
} | ||
var IteratorPrototype = {}; | ||
function _getImageDataFromSource() { | ||
_getImageDataFromSource = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(source) { | ||
var isStringSource, isURLSource, tagName; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
isStringSource = typeof source === 'string'; | ||
isURLSource = isStringSource ? isUrl(source) : false; | ||
tagName = source.tagName; | ||
return _context.abrupt("return", new Promise(function (resolve, reject) { | ||
// String source | ||
if (isStringSource) { | ||
// Read file in Node.js | ||
if (isNode) { | ||
jimp.read(isURLSource ? { | ||
url: source, | ||
headers: {} | ||
} : source, function (err, image) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
var _image$bitmap = image.bitmap, | ||
data = _image$bitmap.data, | ||
width = _image$bitmap.width, | ||
height = _image$bitmap.height; | ||
resolve({ | ||
data: data.toJSON().data, | ||
width: width, | ||
height: height | ||
}); | ||
} | ||
}); | ||
} else if (isURLSource) { | ||
// Load Image from source | ||
var img = new Image(); | ||
img.onerror = reject; | ||
IteratorPrototype[iteratorSymbol] = function () { | ||
return this; | ||
}; | ||
img.onload = function () { | ||
return resolve(createImageData(img)); | ||
}; | ||
var getProto = Object.getPrototypeOf; | ||
var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
img.src = source; | ||
} else { | ||
// Find Elment by ID | ||
var imgElem = document.getElementById(source); | ||
if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { | ||
// This environment has a native %IteratorPrototype%; use it instead | ||
// of the polyfill. | ||
IteratorPrototype = NativeIteratorPrototype; | ||
} | ||
if (imgElem) { | ||
resolve(createImageData(imgElem)); | ||
} | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; | ||
GeneratorFunctionPrototype.constructor = GeneratorFunction; | ||
GeneratorFunctionPrototype[toStringTagSymbol] = GeneratorFunction.displayName = "GeneratorFunction"; // Helper for defining the .next, .throw, and .return methods of the | ||
// Iterator interface in terms of a single ._invoke method. | ||
reject(new Error('Invalid image source specified!')); | ||
} | ||
} else if (tagName) { | ||
// HTML Image element | ||
if (tagName === 'IMG') { | ||
resolve(createImageData(source)); | ||
} // HTML Canvas element | ||
else if (tagName === 'CANVAS') { | ||
resolve(source.getContext('2d').getImageData(0, 0, source.naturalWidth, source.naturalHeight)); | ||
} | ||
function defineIteratorMethods(prototype) { | ||
["next", "throw", "return"].forEach(function (method) { | ||
prototype[method] = function (arg) { | ||
return this._invoke(method, arg); | ||
}; | ||
}); | ||
} | ||
reject(new Error('Invalid image source specified!')); | ||
} // Pixel Data | ||
else if (source.data && source.width && source.height) { | ||
resolve(source); | ||
} else { | ||
reject(new Error('Invalid image source specified!')); | ||
} | ||
})); | ||
exports.isGeneratorFunction = function (genFun) { | ||
var ctor = typeof genFun === "function" && genFun.constructor; | ||
return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can | ||
// do is to check its .name property. | ||
(ctor.displayName || ctor.name) === "GeneratorFunction" : false; | ||
}; | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _getImageDataFromSource.apply(this, arguments); | ||
} | ||
exports.mark = function (genFun) { | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); | ||
} else { | ||
genFun.__proto__ = GeneratorFunctionPrototype; | ||
function getLines(obj) { | ||
var data = obj.data, | ||
start = obj.start, | ||
end = obj.end, | ||
channels = obj.channels, | ||
width = obj.width; | ||
var pxLine = data.slice(start, end); | ||
var sum = []; | ||
var bmp = []; | ||
var lines = []; | ||
var count = 1; | ||
var min = 0; | ||
var max = 0; | ||
var padding = { | ||
left: true, | ||
right: true // grey scale section and sum of columns pixels in section | ||
if (!(toStringTagSymbol in genFun)) { | ||
genFun[toStringTagSymbol] = "GeneratorFunction"; | ||
} | ||
} | ||
}; | ||
genFun.prototype = Object.create(Gp); | ||
return genFun; | ||
}; // Within the body of any async function, `await x` is transformed to | ||
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test | ||
// `hasOwn.call(value, "__await")` to determine if the yielded value is | ||
// meant to be awaited. | ||
for (var row = 0; row < 2; row += 1) { | ||
for (var col = 0; col < width; col += 1) { | ||
var i = (row * width + col) * channels; | ||
var g = (pxLine[i] * 3 + pxLine[i + 1] * 4 + pxLine[i + 2] * 2) / 9; | ||
var s = sum[col]; | ||
pxLine[i] = g; | ||
pxLine[i + 1] = g; | ||
pxLine[i + 2] = g; | ||
sum[col] = g + (s || 0); | ||
} | ||
} | ||
for (var _i = 0; _i < width; _i += 1) { | ||
sum[_i] /= 2; | ||
var _s = sum[_i]; | ||
exports.awrap = function (arg) { | ||
return { | ||
__await: arg | ||
}; | ||
}; | ||
if (_s < min) { | ||
min = _s; | ||
} else { | ||
max = _s; | ||
} | ||
} // matches columns in two rows | ||
function AsyncIterator(generator) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if (record.type === "throw") { | ||
reject(record.arg); | ||
} else { | ||
var result = record.arg; | ||
var value = result.value; | ||
var pivot = min + (max - min) / 2; | ||
if (value && typeof value === "object" && hasOwn.call(value, "__await")) { | ||
return Promise.resolve(value.__await).then(function (value) { | ||
invoke("next", value, resolve, reject); | ||
}, function (err) { | ||
invoke("throw", err, resolve, reject); | ||
}); | ||
} | ||
for (var _col = 0; _col < width; _col += 1) { | ||
var matches = 0; | ||
var value = void 0; | ||
return Promise.resolve(value).then(function (unwrapped) { | ||
// When a yielded Promise is resolved, its final value becomes | ||
// the .value of the Promise<{value,done}> result for the | ||
// current iteration. | ||
result.value = unwrapped; | ||
resolve(result); | ||
}, function (error) { | ||
// If a rejected Promise was yielded, throw the rejection back | ||
// into the async generator function so it can be handled there. | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
} | ||
for (var _row = 0; _row < 2; _row += 1) { | ||
value = pxLine[(_row * width + _col) * channels]; | ||
var previousPromise; | ||
if (value > pivot) { | ||
matches += 1; | ||
} | ||
} | ||
function enqueue(method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new Promise(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
if (_col === 0 && value <= pivot) padding.left = false; | ||
return previousPromise = // If enqueue has been called before, then we want to wait until | ||
// all previous Promises have been resolved before calling invoke, | ||
// so that results are always delivered in the correct order. If | ||
// enqueue has not been called before, then it is important to | ||
// call invoke immediately, without waiting on a callback to fire, | ||
// so that the async generator function has the opportunity to do | ||
// any necessary setup in a predictable way. This predictability | ||
// is why the Promise constructor synchronously invokes its | ||
// executor callback, and why async functions synchronously | ||
// execute code before the first await. Since we implement simple | ||
// async functions in terms of async generators, it is especially | ||
// important to get this right, even though it requires care. | ||
previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later | ||
// invocations of the iterator. | ||
callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
} // Define the unified helper method that is used to implement .next, | ||
// .throw, and .return (see defineIteratorMethods). | ||
if (_col === width - 1 && value <= pivot) { | ||
padding.right = false; | ||
} | ||
bmp.push(matches > 1); | ||
} // matches width of barcode lines | ||
this._invoke = enqueue; | ||
} | ||
defineIteratorMethods(AsyncIterator.prototype); | ||
var curr = bmp[0]; | ||
AsyncIterator.prototype[asyncIteratorSymbol] = function () { | ||
return this; | ||
}; | ||
for (var _col2 = 0; _col2 < width; _col2 += 1) { | ||
if (bmp[_col2] === curr) { | ||
count += 1; | ||
exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of | ||
// AsyncIterator objects; they just return a Promise for the value of | ||
// the final result produced by the iterator. | ||
if (_col2 === width - 1) { | ||
lines.push(count); | ||
} | ||
} else { | ||
lines.push(count); | ||
count = 1; | ||
curr = bmp[_col2]; | ||
} | ||
} | ||
exports.async = function (innerFn, outerFn, self, tryLocsList) { | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList)); | ||
return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator. | ||
: iter.next().then(function (result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}; | ||
return { | ||
lines: lines, | ||
padding: padding | ||
}; | ||
} | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = GenStateSuspendedStart; | ||
return function invoke(method, arg) { | ||
if (state === GenStateExecuting) { | ||
throw new Error("Generator is already running"); | ||
} | ||
var utiltities = { | ||
getImageDataFromSource: getImageDataFromSource, | ||
getLines: getLines | ||
}; | ||
if (state === GenStateCompleted) { | ||
if (method === "throw") { | ||
throw arg; | ||
} // Be forgiving, per 25.3.3.3.3 of the spec: | ||
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume | ||
var WIDTH_TBL = ['212222', '222122', '222221', '121223', '121322', '131222', '122213', '122312', '132212', '221213', '221312', '231212', '112232', '122132', '122231', '113222', '123122', '123221', '223211', '221132', '221231', '213212', '223112', '312131', '311222', '321122', '321221', '312212', '322112', '322211', '212123', '212321', '232121', '111323', '131123', '131321', '112313', '132113', '132311', '211313', '231113', '231311', '112133', '112331', '132131', '113123', '113321', '133121', '313121', '211331', '231131', '213113', '213311', '213131', '311123', '311321', '331121', '312113', '312311', '332111', '314111', '221411', '431111', '111224', '111422', '121124', '121421', '141122', '141221', '112214', '112412', '122114', '122411', '142112', '142211', '241211', '221114', '413111', '241112', '134111', '111242', '121142', '121241', '114212', '124112', '124211', '411212', '421112', '421211', '212141', '214121', '412121', '111143', '111341', '131141', '114113', '114311', '411113', '411311', '113141', '114131', '311141', '411131', '211412', '211214', '211232', '233111', '211133', '2331112']; | ||
var TBL_A = [' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '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', '[', '\\', ']', '^', '_', 'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'HT', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', 'FS', 'GS', 'RS', 'US', 'FNC 3', 'FNC 2', 'Shift B', 'Code C', 'Code B', 'FNC 4', 'FNC 1']; | ||
var TBL_B = [' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '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', '[', '\\', ']', '^', '_', '`', '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', '{', '|', '}', '~', 'DEL', 'FNC 3', 'FNC 2', 'Shift A', 'Code C', 'FNC 4', 'Code A', 'FNC 1']; | ||
var TBL_C = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', 'Code B', 'Code A', 'FNC 1']; | ||
var computeGroup = function computeGroup(lines) { | ||
// sum of a group in code-128 must be 11 | ||
var factor = lines.reduce(function (pre, item) { | ||
return pre + item; | ||
}, 0) / 11; // | ||
return doneResult(); | ||
} | ||
return lines.map(function (item) { | ||
return Math.round(item / factor); | ||
}).join(''); | ||
}; | ||
context.method = method; | ||
context.arg = arg; | ||
var code128 = function code128(lines) { | ||
var lookupTBL; | ||
var sumOP; | ||
var letterKey; | ||
var letterCode; | ||
var keyIndex; | ||
var code = []; // extract terminal bar | ||
while (true) { | ||
var delegate = context.delegate; | ||
lines.pop(); | ||
var seq = lines.slice(0); | ||
letterKey = computeGroup(seq.splice(0, 6)); | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
switch (letterKey) { | ||
case '211214': | ||
lookupTBL = TBL_B; | ||
sumOP = 104; | ||
break; | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
case '211232': | ||
lookupTBL = TBL_C; | ||
sumOP = 105; | ||
break; | ||
if (context.method === "next") { | ||
// Setting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
context.sent = context._sent = context.arg; | ||
} else if (context.method === "throw") { | ||
if (state === GenStateSuspendedStart) { | ||
state = GenStateCompleted; | ||
throw context.arg; | ||
} | ||
default: | ||
lookupTBL = TBL_A; | ||
sumOP = 103; | ||
break; | ||
} | ||
context.dispatchException(context.arg); | ||
} else if (context.method === "return") { | ||
context.abrupt("return", context.arg); | ||
} | ||
for (var i = 1; seq.length > 12; i += 1) { | ||
letterKey = computeGroup(seq.splice(0, 6)); | ||
keyIndex = WIDTH_TBL.indexOf(letterKey); | ||
sumOP += i * keyIndex; | ||
letterCode = lookupTBL[keyIndex]; | ||
state = GenStateExecuting; | ||
var record = tryCatch(innerFn, self, context); | ||
switch (letterCode) { | ||
case 'Code A': | ||
lookupTBL = TBL_A; | ||
break; | ||
if (record.type === "normal") { | ||
// If an exception is thrown from innerFn, we leave state === | ||
// GenStateExecuting and loop back for another invocation. | ||
state = context.done ? GenStateCompleted : GenStateSuspendedYield; | ||
case 'Code B': | ||
lookupTBL = TBL_B; | ||
break; | ||
if (record.arg === ContinueSentinel) { | ||
continue; | ||
} | ||
case 'Code C': | ||
lookupTBL = TBL_C; | ||
break; | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} else if (record.type === "throw") { | ||
state = GenStateCompleted; // Dispatch the exception by looping back around to the | ||
// context.dispatchException(context.arg) call above. | ||
default: | ||
code.push(letterCode); | ||
break; | ||
} | ||
} | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
} | ||
} | ||
}; | ||
} // Call delegate.iterator[context.method](context.arg) and handle the | ||
// result, either by returning a { value, done } result from the | ||
// delegate iterator, or by modifying context.method and context.arg, | ||
// setting context.delegate to null, and returning the ContinueSentinel. | ||
letterKey = computeGroup(seq.splice(0, 6)); | ||
if (sumOP % 103 !== WIDTH_TBL.indexOf(letterKey)) return null; | ||
return code.join(''); | ||
}; | ||
var CHAR_SET = ['nnwwn', 'wnnnw', 'nwnnw', 'wwnnn', 'nnwnw', 'wnwnn', 'nwwnn', 'nnnww', 'wnnwn', 'nwnwn']; | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
var _2of5 = function _2of5(lines) { | ||
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'standard'; | ||
var code = []; | ||
var barThreshold = Math.ceil(lines.reduce(function (pre, item) { | ||
return (pre + item) / 2; | ||
}, 0)); | ||
if (method === undefined$1) { | ||
// A .throw or .return when the delegate iterator has no .throw | ||
// method always terminates the yield* loop. | ||
context.delegate = null; | ||
if (type === 'interleaved') { | ||
// extract start/ends pair | ||
var startChar = lines.splice(0, 4).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
var endChar = lines.splice(lines.length - 3, 3).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
if (startChar !== 'nnnn' || endChar !== 'wnn') return null; // Read one encoded character at a time. | ||
if (context.method === "throw") { | ||
// Note: ["return"] must be used for ES3 parsing compatibility. | ||
if (delegate.iterator["return"]) { | ||
// If the delegate iterator has a return method, give it a | ||
// chance to clean up. | ||
context.method = "return"; | ||
context.arg = undefined$1; | ||
maybeInvokeDelegate(delegate, context); | ||
while (lines.length > 0) { | ||
var seg = lines.splice(0, 10); | ||
var a = seg.filter(function (item, index) { | ||
return index % 2 === 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
code.push(CHAR_SET.indexOf(a)); | ||
var b = seg.filter(function (item, index) { | ||
return index % 2 !== 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
code.push(CHAR_SET.indexOf(b)); | ||
} | ||
} else if (type === 'standard') { | ||
// extract start/ends pair | ||
var _startChar = lines.splice(0, 6).filter(function (item, index) { | ||
return index % 2 === 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
if (context.method === "throw") { | ||
// If maybeInvokeDelegate(context) changed context.method from | ||
// "return" to "throw", let that override the TypeError below. | ||
return ContinueSentinel; | ||
} | ||
} | ||
var _endChar = lines.splice(lines.length - 5, 5).filter(function (item, index) { | ||
return index % 2 === 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
context.method = "throw"; | ||
context.arg = new TypeError("The iterator does not provide a 'throw' method"); | ||
} | ||
if (_startChar !== 'wwn' || _endChar !== 'wnw') return null; // Read one encoded character at a time. | ||
return ContinueSentinel; | ||
} | ||
while (lines.length > 0) { | ||
var _a = lines.splice(0, 10).filter(function (item, index) { | ||
return index % 2 === 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
code.push(CHAR_SET.indexOf(_a)); | ||
} | ||
} | ||
if (record.type === "throw") { | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
return code.join(''); | ||
}; | ||
var info = record.arg; | ||
var CHAR_SET$1 = { | ||
nnnwwnwnn: '0', | ||
wnnwnnnnw: '1', | ||
nnwwnnnnw: '2', | ||
wnwwnnnnn: '3', | ||
nnnwwnnnw: '4', | ||
wnnwwnnnn: '5', | ||
nnwwwnnnn: '6', | ||
nnnwnnwnw: '7', | ||
wnnwnnwnn: '8', | ||
nnwwnnwnn: '9', | ||
wnnnnwnnw: 'A', | ||
nnwnnwnnw: 'B', | ||
wnwnnwnnn: 'C', | ||
nnnnwwnnw: 'D', | ||
wnnnwwnnn: 'E', | ||
nnwnwwnnn: 'F', | ||
nnnnnwwnw: 'G', | ||
wnnnnwwnn: 'H', | ||
nnwnnwwnn: 'I', | ||
nnnnwwwnn: 'J', | ||
wnnnnnnww: 'K', | ||
nnwnnnnww: 'L', | ||
wnwnnnnwn: 'M', | ||
nnnnwnnww: 'N', | ||
wnnnwnnwn: 'O', | ||
nnwnwnnwn: 'P', | ||
nnnnnnwww: 'Q', | ||
wnnnnnwwn: 'R', | ||
nnwnnnwwn: 'S', | ||
nnnnwnwwn: 'T', | ||
wwnnnnnnw: 'U', | ||
nwwnnnnnw: 'V', | ||
wwwnnnnnn: 'W', | ||
nwnnwnnnw: 'X', | ||
wwnnwnnnn: 'Y', | ||
nwwnwnnnn: 'Z', | ||
nwnnnnwnw: '-', | ||
wwnnnnwnn: '.', | ||
nwwnnnwnn: ' ', | ||
nwnwnwnnn: '$', | ||
nwnwnnnwn: '/', | ||
nwnnnwnwn: '+', | ||
nnnwnwnwn: '%', | ||
nwnnwnwnn: '*' | ||
}; | ||
if (!info) { | ||
context.method = "throw"; | ||
context.arg = new TypeError("iterator result is not an object"); | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
var code39 = function code39(lines) { | ||
var code = []; | ||
var barThreshold = Math.ceil(lines.reduce(function (pre, item) { | ||
return pre + item; | ||
}, 0) / lines.length); // Read one encoded character at a time. | ||
if (info.done) { | ||
// Assign the result of the finished delegate to the temporary | ||
// variable specified by delegate.resultName (see delegateYield). | ||
context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield). | ||
while (lines.length > 0) { | ||
var sequenceBar = lines.splice(0, 10).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}); | ||
code.push(CHAR_SET$1[sequenceBar.slice(0, 9).join('')]); | ||
} | ||
context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the | ||
// exception, let the outer generator proceed normally. If | ||
// context.method was "next", forget context.arg since it has been | ||
// "consumed" by the delegate iterator. If context.method was | ||
// "return", allow the original .return call to continue in the | ||
// outer generator. | ||
if (code.pop() !== '*' || code.shift() !== '*') return null; | ||
return code.join(''); | ||
}; | ||
if (context.method !== "return") { | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
} else { | ||
// Re-yield the result returned by the delegate method. | ||
return info; | ||
} // The delegate iterator is finished, so forget it and continue with | ||
// the outer generator. | ||
var CHAR_SET$2 = [{ | ||
'100010100': '0' | ||
}, { | ||
'101001000': '1' | ||
}, { | ||
'101000100': '2' | ||
}, { | ||
'101000010': '3' | ||
}, { | ||
'100101000': '4' | ||
}, { | ||
'100100100': '5' | ||
}, { | ||
'100100010': '6' | ||
}, { | ||
'101010000': '7' | ||
}, { | ||
'100010010': '8' | ||
}, { | ||
'100001010': '9' | ||
}, { | ||
'110101000': 'A' | ||
}, { | ||
'110100100': 'B' | ||
}, { | ||
'110100010': 'C' | ||
}, { | ||
'110010100': 'D' | ||
}, { | ||
'110010010': 'E' | ||
}, { | ||
'110001010': 'F' | ||
}, { | ||
'101101000': 'G' | ||
}, { | ||
'101100100': 'H' | ||
}, { | ||
'101100010': 'I' | ||
}, { | ||
'100110100': 'J' | ||
}, { | ||
'100011010': 'K' | ||
}, { | ||
'101011000': 'L' | ||
}, { | ||
'101001100': 'M' | ||
}, { | ||
'101000110': 'N' | ||
}, { | ||
'100101100': 'O' | ||
}, { | ||
'100010110': 'P' | ||
}, { | ||
'110110100': 'Q' | ||
}, { | ||
'110110010': 'R' | ||
}, { | ||
'110101100': 'S' | ||
}, { | ||
'110100110': 'T' | ||
}, { | ||
'110010110': 'U' | ||
}, { | ||
'110011010': 'V' | ||
}, { | ||
'101101100': 'W' | ||
}, { | ||
'101100110': 'X' | ||
}, { | ||
'100110110': 'Y' | ||
}, { | ||
'100111010': 'Z' | ||
}, { | ||
'100101110': '-' | ||
}, { | ||
'111010100': '.' | ||
}, { | ||
'111010010': ' ' | ||
}, { | ||
'111001010': '$' | ||
}, { | ||
'101101110': '/' | ||
}, { | ||
'101110110': '+' | ||
}, { | ||
'110101110': '%' | ||
}, { | ||
'100100110': '($)' | ||
}, { | ||
'111011010': '(%)' | ||
}, { | ||
'111010110': '(/)' | ||
}, { | ||
'100110010': '(+)' | ||
}, { | ||
'101011110': '*' | ||
}]; | ||
var code93 = function code93(lines) { | ||
var code = []; | ||
var binary = []; // remove termination bar | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} // Define Generator.prototype.{next,throw,return} in terms of the | ||
// unified ._invoke helper method. | ||
lines.pop(); | ||
var barThreshold = Math.ceil(lines.reduce(function (pre, item) { | ||
return pre + item; | ||
}, 0) / lines.length); | ||
var minBarWidth = Math.ceil(lines.reduce(function (pre, item) { | ||
if (item < barThreshold) return (pre + item) / 2; | ||
return pre; | ||
}, 0)); // leave the padded * | ||
for (var i = 0; i < lines.length; i += 1) { | ||
var segment = lines[i]; | ||
defineIteratorMethods(Gp); | ||
Gp[toStringTagSymbol] = "Generator"; // A Generator should always return itself as the iterator object when the | ||
// @@iterator function is called on it. Some browsers' implementations of the | ||
// iterator prototype chain incorrectly implement this, causing the Generator | ||
// object to not be returned from this call. This ensures that doesn't happen. | ||
// See https://github.com/facebook/regenerator/issues/274 for more details. | ||
while (segment > 0) { | ||
if (i % 2 === 0) { | ||
binary.push(1); | ||
} else { | ||
binary.push(0); | ||
} | ||
Gp[iteratorSymbol] = function () { | ||
return this; | ||
}; | ||
segment -= minBarWidth; | ||
} | ||
} | ||
Gp.toString = function () { | ||
return "[object Generator]"; | ||
}; | ||
var _loop = function _loop(_i) { | ||
var searcKey = binary.slice(_i, _i + 9).join(''); | ||
var char = CHAR_SET$2.filter(function (item) { | ||
return Object.keys(item)[0] === searcKey; | ||
}); | ||
code.push(char[0][searcKey]); | ||
}; | ||
function pushTryEntry(locs) { | ||
var entry = { | ||
tryLoc: locs[0] | ||
}; | ||
for (var _i = 0; _i < binary.length; _i += 9) { | ||
_loop(_i); | ||
} | ||
if (1 in locs) { | ||
entry.catchLoc = locs[1]; | ||
} | ||
if (code.shift() !== '*' || code.pop() !== '*') return null; | ||
var K = code.pop(); | ||
var sum = 0; | ||
var letter; | ||
var Value; | ||
if (2 in locs) { | ||
entry.finallyLoc = locs[2]; | ||
entry.afterLoc = locs[3]; | ||
} | ||
var findValue = function findValue(item) { | ||
return Object.values(item)[0] === letter; | ||
}; | ||
this.tryEntries.push(entry); | ||
} | ||
for (var _i2 = code.length - 1; _i2 >= 0; _i2 -= 1) { | ||
letter = code[_i2]; | ||
Value = CHAR_SET$2.indexOf(CHAR_SET$2.filter(findValue)[0]); | ||
sum += Value * (1 + (code.length - (_i2 + 1)) % 20); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal"; | ||
delete record.arg; | ||
entry.completion = record; | ||
} | ||
if (Object.values(CHAR_SET$2[sum % 47])[0] !== K) return null; | ||
var C = code.pop(); | ||
sum = 0; | ||
function Context(tryLocsList) { | ||
// The root entry object (effectively a try statement without a catch | ||
// or a finally block) gives us a place to store values thrown from | ||
// locations where there is no enclosing try statement. | ||
this.tryEntries = [{ | ||
tryLoc: "root" | ||
}]; | ||
tryLocsList.forEach(pushTryEntry, this); | ||
this.reset(true); | ||
} | ||
for (var _i3 = code.length - 1; _i3 >= 0; _i3 -= 1) { | ||
letter = code[_i3]; | ||
Value = CHAR_SET$2.indexOf(CHAR_SET$2.filter(findValue)[0]); | ||
sum += Value * (1 + (code.length - (_i3 + 1)) % 20); | ||
} | ||
exports.keys = function (object) { | ||
var keys = []; | ||
if (Object.values(CHAR_SET$2[sum % 47])[0] !== C) return null; | ||
return code.join(''); | ||
}; | ||
for (var key in object) { | ||
keys.push(key); | ||
} | ||
var UPC_SET = { | ||
'3211': '0', | ||
'2221': '1', | ||
'2122': '2', | ||
'1411': '3', | ||
'1132': '4', | ||
'1231': '5', | ||
'1114': '6', | ||
'1312': '7', | ||
'1213': '8', | ||
'3112': '9' | ||
}; | ||
keys.reverse(); // Rather than returning an object with a next method, we keep | ||
// things simple and return the next function itself. | ||
var ean13 = function ean13(lines) { | ||
var code = ''; // manually add start dummy line | ||
return function next() { | ||
while (keys.length) { | ||
var key = keys.pop(); | ||
lines.unshift(0); // start indicator/reference lines | ||
if (key in object) { | ||
next.value = key; | ||
next.done = false; | ||
return next; | ||
} | ||
} // To avoid creating an additional object, we just hang the .value | ||
// and .done properties off the next function object itself. This | ||
// also ensures that the minifier will not anonymize the function. | ||
var bar = ~~((lines[1] + lines[2] + lines[3]) / 3); //eslint-disable-line | ||
for (var i = 1; i < lines.length; i += 1) { | ||
var group = void 0; | ||
next.done = true; | ||
return next; | ||
}; | ||
}; | ||
if (code.length < 6) { | ||
group = lines.slice(i * 4, i * 4 + 4); | ||
} else { | ||
group = lines.slice(i * 4 + 5, i * 4 + 9); | ||
} | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
var digits = [Math.round(group[0] / bar), Math.round(group[1] / bar), Math.round(group[2] / bar), Math.round(group[3] / bar)]; | ||
var result = UPC_SET[digits.join('')] || UPC_SET[digits.reverse().join('')]; | ||
if (iteratorMethod) { | ||
return iteratorMethod.call(iterable); | ||
} | ||
if (result) { | ||
code += result; | ||
} | ||
if (typeof iterable.next === "function") { | ||
return iterable; | ||
} | ||
if (code.length === 12) break; | ||
} | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, | ||
next = function next() { | ||
while (++i < iterable.length) { | ||
if (hasOwn.call(iterable, i)) { | ||
next.value = iterable[i]; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
return code; | ||
}; | ||
next.value = undefined$1; | ||
next.done = true; | ||
return next; | ||
}; | ||
var UPC_SET$1 = { | ||
'3211': '0', | ||
'2221': '1', | ||
'2122': '2', | ||
'1411': '3', | ||
'1132': '4', | ||
'1231': '5', | ||
'1114': '6', | ||
'1312': '7', | ||
'1213': '8', | ||
'3112': '9' | ||
}; | ||
return next.next = next; | ||
} | ||
} // Return an iterator with no values. | ||
var ean8 = function ean8(lines) { | ||
var code = ''; // manually add start dummy line | ||
lines.unshift(0); // start indicator/reference lines | ||
return { | ||
next: doneResult | ||
}; | ||
} | ||
var bar = ~~((lines[1] + lines[2] + lines[3]) / 3); //eslint-disable-line | ||
exports.values = values; | ||
for (var i = 1; i < lines.length; i += 1) { | ||
var group = void 0; | ||
function doneResult() { | ||
return { | ||
value: undefined$1, | ||
done: true | ||
}; | ||
} | ||
if (code.length < 4) { | ||
group = lines.slice(i * 4, i * 4 + 4); | ||
} else { | ||
group = lines.slice(i * 4 + 5, i * 4 + 9); | ||
} | ||
Context.prototype = { | ||
constructor: Context, | ||
reset: function (skipTempReset) { | ||
this.prev = 0; | ||
this.next = 0; // Resetting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
var digits = [Math.round(group[0] / bar), Math.round(group[1] / bar), Math.round(group[2] / bar), Math.round(group[3] / bar)]; | ||
var result = UPC_SET$1[digits.join('')] || UPC_SET$1[digits.reverse().join('')]; | ||
this.sent = this._sent = undefined$1; | ||
this.done = false; | ||
this.delegate = null; | ||
this.method = "next"; | ||
this.arg = undefined$1; | ||
this.tryEntries.forEach(resetTryEntry); | ||
if (result) { | ||
code += result; | ||
} | ||
if (!skipTempReset) { | ||
for (var name in this) { | ||
// Not sure about the optimal order of these conditions: | ||
if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) { | ||
this[name] = undefined$1; | ||
} | ||
} | ||
} | ||
}, | ||
stop: function () { | ||
this.done = true; | ||
var rootEntry = this.tryEntries[0]; | ||
var rootRecord = rootEntry.completion; | ||
if (code.length === 8) break; | ||
} | ||
if (rootRecord.type === "throw") { | ||
throw rootRecord.arg; | ||
} | ||
return code; | ||
}; | ||
return this.rval; | ||
}, | ||
dispatchException: function (exception) { | ||
if (this.done) { | ||
throw exception; | ||
} | ||
var CHAR_SET$3 = { | ||
nnnnnww: '0', | ||
nnnnwwn: '1', | ||
nnnwnnw: '2', | ||
wwnnnnn: '3', | ||
nnwnnwn: '4', | ||
wnnnnwn: '5', | ||
nwnnnnw: '6', | ||
nwnnwnn: '7', | ||
nwwnnnn: '8', | ||
wnnwnnn: '9', | ||
nnnwwnn: '-', | ||
nnwwnnn: '$', | ||
wnnnwnw: ':', | ||
wnwnnnw: '/', | ||
wnwnwnn: '.', | ||
nnwwwww: '+', | ||
nnwwnwn: 'A', | ||
nnnwnww: 'B', | ||
nwnwnnw: 'C', | ||
nnnwwwn: 'D' | ||
}; | ||
var context = this; | ||
var codabar = function codabar(lines) { | ||
var code = []; | ||
var barThreshold = Math.ceil(lines.reduce(function (pre, item) { | ||
return (pre + item) / 2; | ||
}, 0)); // Read one encoded character at a time. | ||
function handle(loc, caught) { | ||
record.type = "throw"; | ||
record.arg = exception; | ||
context.next = loc; | ||
while (lines.length > 0) { | ||
var seg = lines.splice(0, 8).splice(0, 7); | ||
var a = seg.map(function (line) { | ||
return line < barThreshold ? 'n' : 'w'; | ||
}).join(''); | ||
code.push(CHAR_SET$3[a]); | ||
} | ||
if (caught) { | ||
// If the dispatched exception was caught by a catch block, | ||
// then let that catch block handle the exception normally. | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
return code.join(''); | ||
}; | ||
return !!caught; | ||
} | ||
var src = createCommonjsModule(function (module) { | ||
/* eslint-disable */ | ||
var BARCODE_DECODERS = { | ||
'code-128': code128, | ||
'code-2of5': _2of5, | ||
'code-39': code39, | ||
'code-93': code93, | ||
'ean-13': ean13, | ||
'ean-8': ean8, | ||
codabar: codabar | ||
/* eslint-enable */ | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
var record = entry.completion; | ||
/** | ||
* Scans and returns barcode from the provided image | ||
* | ||
* @param {*} image Image element || Canvas || ImageData || Image Path in Node.js | ||
* @param {Object} options Options defining type of barcode to detect | ||
* @param {String} options.barcode Barcode name | ||
* @param {String=} options.type Type of Barcode | ||
* @returns {String} Extracted barcode string | ||
*/ | ||
if (entry.tryLoc === "root") { | ||
// Exception thrown outside of any try block that could handle | ||
// it, so set the completion value of the entire function to | ||
// throw the exception. | ||
return handle("end"); | ||
} | ||
}; | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"); | ||
var hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
function barcodeDecoder(_x, _x2) { | ||
return _barcodeDecoder.apply(this, arguments); | ||
} | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} else if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} | ||
} else if (hasFinally) { | ||
if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else { | ||
throw new Error("try statement without catch or finally"); | ||
} | ||
} | ||
} | ||
}, | ||
abrupt: function (type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
function _barcodeDecoder() { | ||
_barcodeDecoder = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(image, options) { | ||
var list, _ref, data, width, height, channels, spoints, numLines, slineStep, start, end, _UTILITIES$getLines, lines, padding, result; | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
break; | ||
} | ||
} | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
// eslint-disable-next-line | ||
options.barcode = options.barcode.toLowerCase(); | ||
list = Object.keys(BARCODE_DECODERS); | ||
if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) { | ||
// Ignore the finally entry if control is not jumping to a | ||
// location outside the try/catch block. | ||
finallyEntry = null; | ||
} | ||
if (!(list.indexOf(options.barcode) === -1)) { | ||
_context.next = 4; | ||
break; | ||
} | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
record.type = type; | ||
record.arg = arg; | ||
throw new Error("Invalid barcode specified. Available decoders: ".concat(list, ". https://github.com/mubaidr/Javascript-Barcode-Reader#available-decoders")); | ||
if (finallyEntry) { | ||
this.method = "next"; | ||
this.next = finallyEntry.finallyLoc; | ||
return ContinueSentinel; | ||
} | ||
case 4: | ||
_context.next = 6; | ||
return utiltities.getImageDataFromSource(image); | ||
return this.complete(record); | ||
}, | ||
complete: function (record, afterLoc) { | ||
if (record.type === "throw") { | ||
throw record.arg; | ||
} | ||
case 6: | ||
_ref = _context.sent; | ||
data = _ref.data; | ||
width = _ref.width; | ||
height = _ref.height; | ||
channels = data.length / (width * height); // check points for barcode location | ||
if (record.type === "break" || record.type === "continue") { | ||
this.next = record.arg; | ||
} else if (record.type === "return") { | ||
this.rval = this.arg = record.arg; | ||
this.method = "return"; | ||
this.next = "end"; | ||
} else if (record.type === "normal" && afterLoc) { | ||
this.next = afterLoc; | ||
} | ||
spoints = [1, 9, 2, 8, 3, 7, 4, 6, 5]; | ||
numLines = spoints.length; | ||
slineStep = height / (numLines + 1); // eslint-disable-next-line | ||
return ContinueSentinel; | ||
}, | ||
finish: function (finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
case 14: | ||
if (!(numLines -= 1)) { | ||
_context.next = 26; | ||
break; | ||
} | ||
if (entry.finallyLoc === finallyLoc) { | ||
this.complete(entry.completion, entry.afterLoc); | ||
resetTryEntry(entry); | ||
return ContinueSentinel; | ||
} | ||
} | ||
}, | ||
"catch": function (tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
// create section of height 2 | ||
start = channels * width * Math.floor(slineStep * spoints[numLines]); | ||
end = channels * width * Math.floor(slineStep * spoints[numLines]) + 2 * channels * width; // const pxLine = data.slice(start, end) | ||
// const { lines, padding } = UTILITIES.getLines({ | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
_UTILITIES$getLines = utiltities.getLines({ | ||
data: data, | ||
start: start, | ||
end: end, | ||
width: width, | ||
height: height, | ||
channels: channels | ||
}), lines = _UTILITIES$getLines.lines, padding = _UTILITIES$getLines.padding; | ||
if (record.type === "throw") { | ||
var thrown = record.arg; | ||
resetTryEntry(entry); | ||
} | ||
if (!(lines && lines.length !== 0)) { | ||
_context.next = 24; | ||
break; | ||
} | ||
return thrown; | ||
} | ||
} // The context.catch method must only be called with a location | ||
// argument that corresponds to a known catch block. | ||
// remove empty whitespaces on side of barcode | ||
if (padding.left) lines.shift(); | ||
if (padding.right) lines.pop(); // Run the decoder | ||
result = BARCODE_DECODERS[options.barcode](lines, options.type); | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function (iterable, resultName, nextLoc) { | ||
this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}; | ||
if (!result) { | ||
_context.next = 24; | ||
break; | ||
} | ||
if (this.method === "next") { | ||
// Deliberately forget the last sent value so that we don't | ||
// accidentally pass it on to the delegate. | ||
this.arg = undefined$1; | ||
} | ||
return _context.abrupt("return", result); | ||
return ContinueSentinel; | ||
} | ||
}; // Regardless of whether this script is executing as a CommonJS module | ||
// or not, return the runtime object so that we can declare the variable | ||
// regeneratorRuntime in the outer scope, which allows this module to be | ||
// injected easily by `bin/regenerator --include-runtime script.js`. | ||
case 24: | ||
_context.next = 14; | ||
break; | ||
return exports; | ||
}( // If this script is executing as a CommonJS module, use module.exports | ||
// as the regeneratorRuntime namespace. Otherwise create a new empty | ||
// object. Either way, the resulting object will be used to initialize | ||
// the regeneratorRuntime variable at the top of this file. | ||
module.exports ); | ||
case 26: | ||
throw new Error('Failed to extract barcode!'); | ||
try { | ||
regeneratorRuntime = runtime; | ||
} catch (accidentalStrictMode) { | ||
// This module should not be running in strict mode, so the above | ||
// assignment should always work unless something is misconfigured. Just | ||
// in case runtime.js accidentally runs in strict mode, we can escape | ||
// strict mode using a global Function call. This could conceivably fail | ||
// if a Content Security Policy forbids using Function, but in that case | ||
// the proper solution is to fix the accidental strict mode problem. If | ||
// you've misconfigured your bundler to force strict mode and applied a | ||
// CSP to forbid Function, and you're not willing to fix either of those | ||
// problems, please detail your unique predicament in a GitHub issue. | ||
Function("r", "regeneratorRuntime = r")(runtime); | ||
} | ||
}); | ||
case 27: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _barcodeDecoder.apply(this, arguments); | ||
} | ||
var regenerator = runtime_1; | ||
if (module && module.exports) { | ||
module.exports = barcodeDecoder; | ||
} else { | ||
commonjsGlobal.javascriptBarcodeReader = barcodeDecoder; | ||
} | ||
}); | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
return src; | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
var asyncToGenerator = _asyncToGenerator; | ||
var _typeof_1 = createCommonjsModule(function (module) { | ||
function _typeof2(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof2 = function _typeof2(obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof2 = function _typeof2(obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof2(obj); | ||
} | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") { | ||
module.exports = _typeof = function _typeof(obj) { | ||
return _typeof2(obj); | ||
}; | ||
} else { | ||
module.exports = _typeof = function _typeof(obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj); | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
module.exports = _typeof; | ||
}); | ||
var isNode = (typeof process === "undefined" ? "undefined" : _typeof_1(process)) === 'object' && process.release && process.release.name === 'node'; // check if string is url | ||
function isUrl(s) { | ||
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/; | ||
return !s[0] === '#' || regexp.test(s); | ||
} | ||
/** | ||
* Creates image data from HTML image | ||
* @param {HTMLImageElement} image HTML Image element | ||
*/ | ||
function createImageData(image) { | ||
var canvas = document.createElement('canvas'); | ||
var ctx = canvas.getContext('2d'); | ||
var width = image.naturalWidth; | ||
var height = image.naturalHeight; | ||
canvas.width = width; | ||
canvas.height = height; | ||
ctx.drawImage(image, 0, 0); | ||
return ctx.getImageData(0, 0, image.naturalWidth, image.naturalHeight); | ||
} | ||
/** | ||
* Reads image source and returns imageData as only callback parameter | ||
* @param {*} source Image source | ||
* @param {Function} callback Callback to pass the imageData | ||
*/ | ||
function getImageDataFromSource(_x) { | ||
return _getImageDataFromSource.apply(this, arguments); | ||
} | ||
function _getImageDataFromSource() { | ||
_getImageDataFromSource = asyncToGenerator( | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee(source) { | ||
var isStringSource, isURLSource, tagName; | ||
return regenerator.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
isStringSource = typeof source === 'string'; | ||
isURLSource = isStringSource ? isUrl(source) : false; | ||
tagName = source.tagName; | ||
return _context.abrupt("return", new Promise(function (resolve, reject) { | ||
// String source | ||
if (isStringSource) { | ||
// Read file in Node.js | ||
if (isNode) { | ||
jimp.read(isURLSource ? { | ||
url: source, | ||
headers: {} | ||
} : source, function (err, image) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
var _image$bitmap = image.bitmap, | ||
data = _image$bitmap.data, | ||
width = _image$bitmap.width, | ||
height = _image$bitmap.height; | ||
resolve({ | ||
data: data.toJSON().data, | ||
width: width, | ||
height: height | ||
}); | ||
} | ||
}); | ||
} else if (isURLSource) { | ||
// Load Image from source | ||
var img = new Image(); | ||
img.onerror = reject; | ||
img.onload = function () { | ||
return resolve(createImageData(img)); | ||
}; | ||
img.src = source; | ||
} else { | ||
// Find Elment by ID | ||
var imgElem = document.getElementById(source); | ||
if (imgElem) { | ||
resolve(createImageData(imgElem)); | ||
} | ||
reject(new Error('Invalid image source specified!')); | ||
} | ||
} else if (tagName) { | ||
// HTML Image element | ||
if (tagName === 'IMG') { | ||
resolve(createImageData(source)); | ||
} // HTML Canvas element | ||
else if (tagName === 'CANVAS') { | ||
resolve(source.getContext('2d').getImageData(0, 0, source.naturalWidth, source.naturalHeight)); | ||
} | ||
reject(new Error('Invalid image source specified!')); | ||
} // Pixel Data | ||
else if (source.data && source.width && source.height) { | ||
resolve(source); | ||
} else { | ||
reject(new Error('Invalid image source specified!')); | ||
} | ||
})); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _getImageDataFromSource.apply(this, arguments); | ||
} | ||
function getLines(obj) { | ||
var data = obj.data, | ||
start = obj.start, | ||
end = obj.end, | ||
channels = obj.channels, | ||
width = obj.width; | ||
var pxLine = data.slice(start, end); | ||
var sum = []; | ||
var bmp = []; | ||
var lines = []; | ||
var count = 1; | ||
var min = 0; | ||
var max = 0; | ||
var padding = { | ||
left: true, | ||
right: true // grey scale section and sum of columns pixels in section | ||
}; | ||
for (var row = 0; row < 2; row += 1) { | ||
for (var col = 0; col < width; col += 1) { | ||
var i = (row * width + col) * channels; | ||
var g = (pxLine[i] * 3 + pxLine[i + 1] * 4 + pxLine[i + 2] * 2) / 9; | ||
var s = sum[col]; | ||
pxLine[i] = g; | ||
pxLine[i + 1] = g; | ||
pxLine[i + 2] = g; | ||
sum[col] = g + (s || 0); | ||
} | ||
} | ||
for (var _i = 0; _i < width; _i += 1) { | ||
sum[_i] /= 2; | ||
var _s = sum[_i]; | ||
if (_s < min) { | ||
min = _s; | ||
} else { | ||
max = _s; | ||
} | ||
} // matches columns in two rows | ||
var pivot = min + (max - min) / 2; | ||
for (var _col = 0; _col < width; _col += 1) { | ||
var matches = 0; | ||
var value = void 0; | ||
for (var _row = 0; _row < 2; _row += 1) { | ||
value = pxLine[(_row * width + _col) * channels]; | ||
if (value > pivot) { | ||
matches += 1; | ||
} | ||
} | ||
if (_col === 0 && value <= pivot) padding.left = false; | ||
if (_col === width - 1 && value <= pivot) { | ||
padding.right = false; | ||
} | ||
bmp.push(matches > 1); | ||
} // matches width of barcode lines | ||
var curr = bmp[0]; | ||
for (var _col2 = 0; _col2 < width; _col2 += 1) { | ||
if (bmp[_col2] === curr) { | ||
count += 1; | ||
if (_col2 === width - 1) { | ||
lines.push(count); | ||
} | ||
} else { | ||
lines.push(count); | ||
count = 1; | ||
curr = bmp[_col2]; | ||
} | ||
} | ||
return { | ||
lines: lines, | ||
padding: padding | ||
}; | ||
} | ||
var utiltities = { | ||
getImageDataFromSource: getImageDataFromSource, | ||
getLines: getLines | ||
}; | ||
var WIDTH_TBL = ['212222', '222122', '222221', '121223', '121322', '131222', '122213', '122312', '132212', '221213', '221312', '231212', '112232', '122132', '122231', '113222', '123122', '123221', '223211', '221132', '221231', '213212', '223112', '312131', '311222', '321122', '321221', '312212', '322112', '322211', '212123', '212321', '232121', '111323', '131123', '131321', '112313', '132113', '132311', '211313', '231113', '231311', '112133', '112331', '132131', '113123', '113321', '133121', '313121', '211331', '231131', '213113', '213311', '213131', '311123', '311321', '331121', '312113', '312311', '332111', '314111', '221411', '431111', '111224', '111422', '121124', '121421', '141122', '141221', '112214', '112412', '122114', '122411', '142112', '142211', '241211', '221114', '413111', '241112', '134111', '111242', '121142', '121241', '114212', '124112', '124211', '411212', '421112', '421211', '212141', '214121', '412121', '111143', '111341', '131141', '114113', '114311', '411113', '411311', '113141', '114131', '311141', '411131', '211412', '211214', '211232', '233111', '211133', '2331112']; | ||
var TBL_A = [' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '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', '[', '\\', ']', '^', '_', 'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'HT', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', 'FS', 'GS', 'RS', 'US', 'FNC 3', 'FNC 2', 'Shift B', 'Code C', 'Code B', 'FNC 4', 'FNC 1']; | ||
var TBL_B = [' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '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', '[', '\\', ']', '^', '_', '`', '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', '{', '|', '}', '~', 'DEL', 'FNC 3', 'FNC 2', 'Shift A', 'Code C', 'FNC 4', 'Code A', 'FNC 1']; | ||
var TBL_C = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', 'Code B', 'Code A', 'FNC 1']; | ||
var computeGroup = function computeGroup(lines) { | ||
// sum of a group in code-128 must be 11 | ||
var factor = lines.reduce(function (pre, item) { | ||
return pre + item; | ||
}, 0) / 11; // | ||
return lines.map(function (item) { | ||
return Math.round(item / factor); | ||
}).join(''); | ||
}; | ||
var code128 = function code128(lines) { | ||
var lookupTBL; | ||
var sumOP; | ||
var letterKey; | ||
var letterCode; | ||
var keyIndex; | ||
var code = []; // extract terminal bar | ||
lines.pop(); | ||
var seq = lines.slice(0); | ||
letterKey = computeGroup(seq.splice(0, 6)); | ||
switch (letterKey) { | ||
case '211214': | ||
lookupTBL = TBL_B; | ||
sumOP = 104; | ||
break; | ||
case '211232': | ||
lookupTBL = TBL_C; | ||
sumOP = 105; | ||
break; | ||
default: | ||
lookupTBL = TBL_A; | ||
sumOP = 103; | ||
break; | ||
} | ||
for (var i = 1; seq.length > 12; i += 1) { | ||
letterKey = computeGroup(seq.splice(0, 6)); | ||
keyIndex = WIDTH_TBL.indexOf(letterKey); | ||
sumOP += i * keyIndex; | ||
letterCode = lookupTBL[keyIndex]; | ||
switch (letterCode) { | ||
case 'Code A': | ||
lookupTBL = TBL_A; | ||
break; | ||
case 'Code B': | ||
lookupTBL = TBL_B; | ||
break; | ||
case 'Code C': | ||
lookupTBL = TBL_C; | ||
break; | ||
default: | ||
code.push(letterCode); | ||
break; | ||
} | ||
} | ||
letterKey = computeGroup(seq.splice(0, 6)); | ||
if (sumOP % 103 !== WIDTH_TBL.indexOf(letterKey)) return null; | ||
return code.join(''); | ||
}; | ||
var CHAR_SET = ['nnwwn', 'wnnnw', 'nwnnw', 'wwnnn', 'nnwnw', 'wnwnn', 'nwwnn', 'nnnww', 'wnnwn', 'nwnwn']; | ||
var _2of5 = function _2of5(lines) { | ||
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'standard'; | ||
var code = []; | ||
var barThreshold = Math.ceil(lines.reduce(function (pre, item) { | ||
return (pre + item) / 2; | ||
}, 0)); | ||
if (type === 'interleaved') { | ||
// extract start/ends pair | ||
var startChar = lines.splice(0, 4).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
var endChar = lines.splice(lines.length - 3, 3).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
if (startChar !== 'nnnn' || endChar !== 'wnn') return null; // Read one encoded character at a time. | ||
while (lines.length > 0) { | ||
var seg = lines.splice(0, 10); | ||
var a = seg.filter(function (item, index) { | ||
return index % 2 === 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
code.push(CHAR_SET.indexOf(a)); | ||
var b = seg.filter(function (item, index) { | ||
return index % 2 !== 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
code.push(CHAR_SET.indexOf(b)); | ||
} | ||
} else if (type === 'standard') { | ||
// extract start/ends pair | ||
var _startChar = lines.splice(0, 6).filter(function (item, index) { | ||
return index % 2 === 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
var _endChar = lines.splice(lines.length - 5, 5).filter(function (item, index) { | ||
return index % 2 === 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
if (_startChar !== 'wwn' || _endChar !== 'wnw') return null; // Read one encoded character at a time. | ||
while (lines.length > 0) { | ||
var _a = lines.splice(0, 10).filter(function (item, index) { | ||
return index % 2 === 0; | ||
}).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}).join(''); | ||
code.push(CHAR_SET.indexOf(_a)); | ||
} | ||
} | ||
return code.join(''); | ||
}; | ||
var CHAR_SET$1 = { | ||
nnnwwnwnn: '0', | ||
wnnwnnnnw: '1', | ||
nnwwnnnnw: '2', | ||
wnwwnnnnn: '3', | ||
nnnwwnnnw: '4', | ||
wnnwwnnnn: '5', | ||
nnwwwnnnn: '6', | ||
nnnwnnwnw: '7', | ||
wnnwnnwnn: '8', | ||
nnwwnnwnn: '9', | ||
wnnnnwnnw: 'A', | ||
nnwnnwnnw: 'B', | ||
wnwnnwnnn: 'C', | ||
nnnnwwnnw: 'D', | ||
wnnnwwnnn: 'E', | ||
nnwnwwnnn: 'F', | ||
nnnnnwwnw: 'G', | ||
wnnnnwwnn: 'H', | ||
nnwnnwwnn: 'I', | ||
nnnnwwwnn: 'J', | ||
wnnnnnnww: 'K', | ||
nnwnnnnww: 'L', | ||
wnwnnnnwn: 'M', | ||
nnnnwnnww: 'N', | ||
wnnnwnnwn: 'O', | ||
nnwnwnnwn: 'P', | ||
nnnnnnwww: 'Q', | ||
wnnnnnwwn: 'R', | ||
nnwnnnwwn: 'S', | ||
nnnnwnwwn: 'T', | ||
wwnnnnnnw: 'U', | ||
nwwnnnnnw: 'V', | ||
wwwnnnnnn: 'W', | ||
nwnnwnnnw: 'X', | ||
wwnnwnnnn: 'Y', | ||
nwwnwnnnn: 'Z', | ||
nwnnnnwnw: '-', | ||
wwnnnnwnn: '.', | ||
nwwnnnwnn: ' ', | ||
nwnwnwnnn: '$', | ||
nwnwnnnwn: '/', | ||
nwnnnwnwn: '+', | ||
nnnwnwnwn: '%', | ||
nwnnwnwnn: '*' | ||
}; | ||
var code39 = function code39(lines) { | ||
var code = []; | ||
var barThreshold = Math.ceil(lines.reduce(function (pre, item) { | ||
return pre + item; | ||
}, 0) / lines.length); // Read one encoded character at a time. | ||
while (lines.length > 0) { | ||
var sequenceBar = lines.splice(0, 10).map(function (line) { | ||
return line > barThreshold ? 'w' : 'n'; | ||
}); | ||
code.push(CHAR_SET$1[sequenceBar.slice(0, 9).join('')]); | ||
} | ||
if (code.pop() !== '*' || code.shift() !== '*') return null; | ||
return code.join(''); | ||
}; | ||
var CHAR_SET$2 = [{ | ||
'100010100': '0' | ||
}, { | ||
'101001000': '1' | ||
}, { | ||
'101000100': '2' | ||
}, { | ||
'101000010': '3' | ||
}, { | ||
'100101000': '4' | ||
}, { | ||
'100100100': '5' | ||
}, { | ||
'100100010': '6' | ||
}, { | ||
'101010000': '7' | ||
}, { | ||
'100010010': '8' | ||
}, { | ||
'100001010': '9' | ||
}, { | ||
'110101000': 'A' | ||
}, { | ||
'110100100': 'B' | ||
}, { | ||
'110100010': 'C' | ||
}, { | ||
'110010100': 'D' | ||
}, { | ||
'110010010': 'E' | ||
}, { | ||
'110001010': 'F' | ||
}, { | ||
'101101000': 'G' | ||
}, { | ||
'101100100': 'H' | ||
}, { | ||
'101100010': 'I' | ||
}, { | ||
'100110100': 'J' | ||
}, { | ||
'100011010': 'K' | ||
}, { | ||
'101011000': 'L' | ||
}, { | ||
'101001100': 'M' | ||
}, { | ||
'101000110': 'N' | ||
}, { | ||
'100101100': 'O' | ||
}, { | ||
'100010110': 'P' | ||
}, { | ||
'110110100': 'Q' | ||
}, { | ||
'110110010': 'R' | ||
}, { | ||
'110101100': 'S' | ||
}, { | ||
'110100110': 'T' | ||
}, { | ||
'110010110': 'U' | ||
}, { | ||
'110011010': 'V' | ||
}, { | ||
'101101100': 'W' | ||
}, { | ||
'101100110': 'X' | ||
}, { | ||
'100110110': 'Y' | ||
}, { | ||
'100111010': 'Z' | ||
}, { | ||
'100101110': '-' | ||
}, { | ||
'111010100': '.' | ||
}, { | ||
'111010010': ' ' | ||
}, { | ||
'111001010': '$' | ||
}, { | ||
'101101110': '/' | ||
}, { | ||
'101110110': '+' | ||
}, { | ||
'110101110': '%' | ||
}, { | ||
'100100110': '($)' | ||
}, { | ||
'111011010': '(%)' | ||
}, { | ||
'111010110': '(/)' | ||
}, { | ||
'100110010': '(+)' | ||
}, { | ||
'101011110': '*' | ||
}]; | ||
var code93 = function code93(lines) { | ||
var code = []; | ||
var binary = []; // remove termination bar | ||
lines.pop(); | ||
var barThreshold = Math.ceil(lines.reduce(function (pre, item) { | ||
return pre + item; | ||
}, 0) / lines.length); | ||
var minBarWidth = Math.ceil(lines.reduce(function (pre, item) { | ||
if (item < barThreshold) return (pre + item) / 2; | ||
return pre; | ||
}, 0)); // leave the padded * | ||
for (var i = 0; i < lines.length; i += 1) { | ||
var segment = lines[i]; | ||
while (segment > 0) { | ||
if (i % 2 === 0) { | ||
binary.push(1); | ||
} else { | ||
binary.push(0); | ||
} | ||
segment -= minBarWidth; | ||
} | ||
} | ||
var _loop = function _loop(_i) { | ||
var searcKey = binary.slice(_i, _i + 9).join(''); | ||
var char = CHAR_SET$2.filter(function (item) { | ||
return Object.keys(item)[0] === searcKey; | ||
}); | ||
code.push(char[0][searcKey]); | ||
}; | ||
for (var _i = 0; _i < binary.length; _i += 9) { | ||
_loop(_i); | ||
} | ||
if (code.shift() !== '*' || code.pop() !== '*') return null; | ||
var K = code.pop(); | ||
var sum = 0; | ||
var letter; | ||
var Value; | ||
var findValue = function findValue(item) { | ||
return Object.values(item)[0] === letter; | ||
}; | ||
for (var _i2 = code.length - 1; _i2 >= 0; _i2 -= 1) { | ||
letter = code[_i2]; | ||
Value = CHAR_SET$2.indexOf(CHAR_SET$2.filter(findValue)[0]); | ||
sum += Value * (1 + (code.length - (_i2 + 1)) % 20); | ||
} | ||
if (Object.values(CHAR_SET$2[sum % 47])[0] !== K) return null; | ||
var C = code.pop(); | ||
sum = 0; | ||
for (var _i3 = code.length - 1; _i3 >= 0; _i3 -= 1) { | ||
letter = code[_i3]; | ||
Value = CHAR_SET$2.indexOf(CHAR_SET$2.filter(findValue)[0]); | ||
sum += Value * (1 + (code.length - (_i3 + 1)) % 20); | ||
} | ||
if (Object.values(CHAR_SET$2[sum % 47])[0] !== C) return null; | ||
return code.join(''); | ||
}; | ||
var UPC_SET = { | ||
'3211': '0', | ||
'2221': '1', | ||
'2122': '2', | ||
'1411': '3', | ||
'1132': '4', | ||
'1231': '5', | ||
'1114': '6', | ||
'1312': '7', | ||
'1213': '8', | ||
'3112': '9' | ||
}; | ||
var ean13 = function ean13(lines) { | ||
var code = ''; // manually add start dummy line | ||
lines.unshift(0); // start indicator/reference lines | ||
var bar = ~~((lines[1] + lines[2] + lines[3]) / 3); //eslint-disable-line | ||
for (var i = 1; i < lines.length; i += 1) { | ||
var group = void 0; | ||
if (code.length < 6) { | ||
group = lines.slice(i * 4, i * 4 + 4); | ||
} else { | ||
group = lines.slice(i * 4 + 5, i * 4 + 9); | ||
} | ||
var digits = [Math.round(group[0] / bar), Math.round(group[1] / bar), Math.round(group[2] / bar), Math.round(group[3] / bar)]; | ||
var result = UPC_SET[digits.join('')] || UPC_SET[digits.reverse().join('')]; | ||
if (result) { | ||
code += result; | ||
} | ||
if (code.length === 12) break; | ||
} | ||
return code; | ||
}; | ||
var UPC_SET$1 = { | ||
'3211': '0', | ||
'2221': '1', | ||
'2122': '2', | ||
'1411': '3', | ||
'1132': '4', | ||
'1231': '5', | ||
'1114': '6', | ||
'1312': '7', | ||
'1213': '8', | ||
'3112': '9' | ||
}; | ||
var ean8 = function ean8(lines) { | ||
var code = ''; // manually add start dummy line | ||
lines.unshift(0); // start indicator/reference lines | ||
var bar = ~~((lines[1] + lines[2] + lines[3]) / 3); //eslint-disable-line | ||
for (var i = 1; i < lines.length; i += 1) { | ||
var group = void 0; | ||
if (code.length < 4) { | ||
group = lines.slice(i * 4, i * 4 + 4); | ||
} else { | ||
group = lines.slice(i * 4 + 5, i * 4 + 9); | ||
} | ||
var digits = [Math.round(group[0] / bar), Math.round(group[1] / bar), Math.round(group[2] / bar), Math.round(group[3] / bar)]; | ||
var result = UPC_SET$1[digits.join('')] || UPC_SET$1[digits.reverse().join('')]; | ||
if (result) { | ||
code += result; | ||
} | ||
if (code.length === 8) break; | ||
} | ||
return code; | ||
}; | ||
var CHAR_SET$3 = { | ||
nnnnnww: '0', | ||
nnnnwwn: '1', | ||
nnnwnnw: '2', | ||
wwnnnnn: '3', | ||
nnwnnwn: '4', | ||
wnnnnwn: '5', | ||
nwnnnnw: '6', | ||
nwnnwnn: '7', | ||
nwwnnnn: '8', | ||
wnnwnnn: '9', | ||
nnnwwnn: '-', | ||
nnwwnnn: '$', | ||
wnnnwnw: ':', | ||
wnwnnnw: '/', | ||
wnwnwnn: '.', | ||
nnwwwww: '+', | ||
nnwwnwn: 'A', | ||
nnnwnww: 'B', | ||
nwnwnnw: 'C', | ||
nnnwwwn: 'D' | ||
}; | ||
var codabar = function codabar(lines) { | ||
var code = []; | ||
var barThreshold = Math.ceil(lines.reduce(function (pre, item) { | ||
return (pre + item) / 2; | ||
}, 0)); // Read one encoded character at a time. | ||
while (lines.length > 0) { | ||
var seg = lines.splice(0, 8).splice(0, 7); | ||
var a = seg.map(function (line) { | ||
return line < barThreshold ? 'n' : 'w'; | ||
}).join(''); | ||
code.push(CHAR_SET$3[a]); | ||
} | ||
return code.join(''); | ||
}; | ||
var src = createCommonjsModule(function (module) { | ||
/* eslint-disable */ | ||
var BARCODE_DECODERS = { | ||
'code-128': code128, | ||
'code-2of5': _2of5, | ||
'code-39': code39, | ||
'code-93': code93, | ||
'ean-13': ean13, | ||
'ean-8': ean8, | ||
codabar: codabar | ||
/* eslint-enable */ | ||
/** | ||
* Scans and returns barcode from the provided image | ||
* | ||
* @param {*} image Image element || Canvas || ImageData || Image Path in Node.js | ||
* @param {Object} options Options defining type of barcode to detect | ||
* @param {String} options.barcode Barcode name | ||
* @param {String=} options.type Type of Barcode | ||
* @returns {String} Extracted barcode string | ||
*/ | ||
}; | ||
function barcodeDecoder(_x, _x2) { | ||
return _barcodeDecoder.apply(this, arguments); | ||
} | ||
function _barcodeDecoder() { | ||
_barcodeDecoder = asyncToGenerator( | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee(image, options) { | ||
var list, _ref, data, width, height, channels, spoints, numLines, slineStep, start, end, _UTILITIES$getLines, lines, padding, result; | ||
return regenerator.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
// eslint-disable-next-line | ||
options.barcode = options.barcode.toLowerCase(); | ||
list = Object.keys(BARCODE_DECODERS); | ||
if (!(list.indexOf(options.barcode) === -1)) { | ||
_context.next = 4; | ||
break; | ||
} | ||
throw new Error("Invalid barcode specified. Available decoders: ".concat(list, ". https://github.com/mubaidr/Javascript-Barcode-Reader#available-decoders")); | ||
case 4: | ||
_context.next = 6; | ||
return utiltities.getImageDataFromSource(image); | ||
case 6: | ||
_ref = _context.sent; | ||
data = _ref.data; | ||
width = _ref.width; | ||
height = _ref.height; | ||
channels = data.length / (width * height); // check points for barcode location | ||
spoints = [1, 9, 2, 8, 3, 7, 4, 6, 5]; | ||
numLines = spoints.length; | ||
slineStep = height / (numLines + 1); // eslint-disable-next-line | ||
case 14: | ||
if (!(numLines -= 1)) { | ||
_context.next = 26; | ||
break; | ||
} | ||
// create section of height 2 | ||
start = channels * width * Math.floor(slineStep * spoints[numLines]); | ||
end = channels * width * Math.floor(slineStep * spoints[numLines]) + 2 * channels * width; // const pxLine = data.slice(start, end) | ||
// const { lines, padding } = UTILITIES.getLines({ | ||
_UTILITIES$getLines = utiltities.getLines({ | ||
data: data, | ||
start: start, | ||
end: end, | ||
width: width, | ||
height: height, | ||
channels: channels | ||
}), lines = _UTILITIES$getLines.lines, padding = _UTILITIES$getLines.padding; | ||
if (!(lines && lines.length !== 0)) { | ||
_context.next = 24; | ||
break; | ||
} | ||
// remove empty whitespaces on side of barcode | ||
if (padding.left) lines.shift(); | ||
if (padding.right) lines.pop(); // Run the decoder | ||
result = BARCODE_DECODERS[options.barcode](lines, options.type); | ||
if (!result) { | ||
_context.next = 24; | ||
break; | ||
} | ||
return _context.abrupt("return", result); | ||
case 24: | ||
_context.next = 14; | ||
break; | ||
case 26: | ||
throw new Error('Failed to extract barcode!'); | ||
case 27: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _barcodeDecoder.apply(this, arguments); | ||
} | ||
if (module && module.exports) { | ||
module.exports = barcodeDecoder; | ||
} else { | ||
commonjsGlobal.javascriptBarcodeReader = barcodeDecoder; | ||
} | ||
}); | ||
return src; | ||
}(window.jimp)); | ||
//# sourceMappingURL=javascript-barcode-reader.js.map |
@@ -1,2 +0,2 @@ | ||
var javascriptBarcodeReader=function(n){"use strict";function e(n){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}function r(n,e,r,t,w,a,i){try{var o=n[a](i),u=o.value}catch(n){return void r(n)}o.done?e(u):Promise.resolve(u).then(t,w)}function t(n){return function(){var e=this,t=arguments;return new Promise(function(w,a){var i=n.apply(e,t);function o(n){r(i,w,a,o,u,"next",n)}function u(n){r(i,w,a,o,u,"throw",n)}o(void 0)})}}n=n&&n.hasOwnProperty("default")?n.default:n;var w="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var a="object"===("undefined"==typeof process?"undefined":e(process))&&process.release&&"node"===process.release.name;function i(n){var e=document.createElement("canvas"),r=e.getContext("2d"),t=n.naturalWidth,w=n.naturalHeight;return e.width=t,e.height=w,r.drawImage(n,0,0),r.getImageData(0,0,n.naturalWidth,n.naturalHeight)}function o(){return(o=t(regeneratorRuntime.mark(function e(r){var t,w,o;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return w=!!(t="string"==typeof r)&&("#"===!(u=r)[0]||/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(u)),o=r.tagName,e.abrupt("return",new Promise(function(e,u){if(t)if(a)n.read(w?{url:r,headers:{}}:r,function(n,r){if(n)u(n);else{var t=r.bitmap,w=t.data,a=t.width,i=t.height;e({data:w.toJSON().data,width:a,height:i})}});else if(w){var c=new Image;c.onerror=u,c.onload=function(){return e(i(c))},c.src=r}else{var f=document.getElementById(r);f&&e(i(f)),u(new Error("Invalid image source specified!"))}else o?("IMG"===o?e(i(r)):"CANVAS"===o&&e(r.getContext("2d").getImageData(0,0,r.naturalWidth,r.naturalHeight)),u(new Error("Invalid image source specified!"))):r.data&&r.width&&r.height?e(r):u(new Error("Invalid image source specified!"))}));case 4:case"end":return e.stop()}var u},e)}))).apply(this,arguments)}var u,c={getImageDataFromSource:function(n){return o.apply(this,arguments)},getLines:function(n){for(var e=n.data,r=n.start,t=n.end,w=n.channels,a=n.width,i=e.slice(r,t),o=[],u=[],c=[],f=1,l=0,s=0,d={left:!0,right:!0},h=0;h<2;h+=1)for(var p=0;p<a;p+=1){var v=(h*a+p)*w,g=(3*i[v]+4*i[v+1]+2*i[v+2])/9,m=o[p];i[v]=g,i[v+1]=g,i[v+2]=g,o[p]=g+(m||0)}for(var b=0;b<a;b+=1){o[b]/=2;var C=o[b];C<l?l=C:s=C}for(var y=l+(s-l)/2,j=0;j<a;j+=1){for(var S=0,x=void 0,M=0;M<2;M+=1)(x=i[(M*a+j)*w])>y&&(S+=1);0===j&&x<=y&&(d.left=!1),j===a-1&&x<=y&&(d.right=!1),u.push(S>1)}for(var O=u[0],N=0;N<a;N+=1)u[N]===O?(f+=1,N===a-1&&c.push(f)):(c.push(f),f=1,O=u[N]);return{lines:c,padding:d}}},f=["212222","222122","222221","121223","121322","131222","122213","122312","132212","221213","221312","231212","112232","122132","122231","113222","123122","123221","223211","221132","221231","213212","223112","312131","311222","321122","321221","312212","322112","322211","212123","212321","232121","111323","131123","131321","112313","132113","132311","211313","231113","231311","112133","112331","132131","113123","113321","133121","313121","211331","231131","213113","213311","213131","311123","311321","331121","312113","312311","332111","314111","221411","431111","111224","111422","121124","121421","141122","141221","112214","112412","122114","122411","142112","142211","241211","221114","413111","241112","134111","111242","121142","121241","114212","124112","124211","411212","421112","421211","212141","214121","412121","111143","111341","131141","114113","114311","411113","411311","113141","114131","311141","411131","211412","211214","211232","233111","211133","2331112"],l=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","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","[","\\","]","^","_","NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS","HT","LF","VT","FF","CR","SO","SI","DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM","SUB","ESC","FS","GS","RS","US","FNC 3","FNC 2","Shift B","Code C","Code B","FNC 4","FNC 1"],s=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","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","[","\\","]","^","_","`","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","{","|","}","~","DEL","FNC 3","FNC 2","Shift A","Code C","FNC 4","Code A","FNC 1"],d=["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","Code B","Code A","FNC 1"],h=function(n){var e=n.reduce(function(n,e){return n+e},0)/11;return n.map(function(n){return Math.round(n/e)}).join("")},p=function(n){var e,r,t,w,a,i=[];n.pop();var o=n.slice(0);switch(t=h(o.splice(0,6))){case"211214":e=s,r=104;break;case"211232":e=d,r=105;break;default:e=l,r=103}for(var u=1;o.length>12;u+=1)switch(t=h(o.splice(0,6)),r+=u*(a=f.indexOf(t)),w=e[a]){case"Code A":e=l;break;case"Code B":e=s;break;case"Code C":e=d;break;default:i.push(w)}return t=h(o.splice(0,6)),r%103!==f.indexOf(t)?null:i.join("")},v=["nnwwn","wnnnw","nwnnw","wwnnn","nnwnw","wnwnn","nwwnn","nnnww","wnnwn","nwnwn"],g=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"standard",r=[],t=Math.ceil(n.reduce(function(n,e){return(n+e)/2},0));if("interleaved"===e){var w=n.splice(0,4).map(function(n){return n>t?"w":"n"}).join(""),a=n.splice(n.length-3,3).map(function(n){return n>t?"w":"n"}).join("");if("nnnn"!==w||"wnn"!==a)return null;for(;n.length>0;){var i=n.splice(0,10),o=i.filter(function(n,e){return e%2==0}).map(function(n){return n>t?"w":"n"}).join("");r.push(v.indexOf(o));var u=i.filter(function(n,e){return e%2!=0}).map(function(n){return n>t?"w":"n"}).join("");r.push(v.indexOf(u))}}else if("standard"===e){var c=n.splice(0,6).filter(function(n,e){return e%2==0}).map(function(n){return n>t?"w":"n"}).join(""),f=n.splice(n.length-5,5).filter(function(n,e){return e%2==0}).map(function(n){return n>t?"w":"n"}).join("");if("wwn"!==c||"wnw"!==f)return null;for(;n.length>0;){var l=n.splice(0,10).filter(function(n,e){return e%2==0}).map(function(n){return n>t?"w":"n"}).join("");r.push(v.indexOf(l))}}return r.join("")},m={nnnwwnwnn:"0",wnnwnnnnw:"1",nnwwnnnnw:"2",wnwwnnnnn:"3",nnnwwnnnw:"4",wnnwwnnnn:"5",nnwwwnnnn:"6",nnnwnnwnw:"7",wnnwnnwnn:"8",nnwwnnwnn:"9",wnnnnwnnw:"A",nnwnnwnnw:"B",wnwnnwnnn:"C",nnnnwwnnw:"D",wnnnwwnnn:"E",nnwnwwnnn:"F",nnnnnwwnw:"G",wnnnnwwnn:"H",nnwnnwwnn:"I",nnnnwwwnn:"J",wnnnnnnww:"K",nnwnnnnww:"L",wnwnnnnwn:"M",nnnnwnnww:"N",wnnnwnnwn:"O",nnwnwnnwn:"P",nnnnnnwww:"Q",wnnnnnwwn:"R",nnwnnnwwn:"S",nnnnwnwwn:"T",wwnnnnnnw:"U",nwwnnnnnw:"V",wwwnnnnnn:"W",nwnnwnnnw:"X",wwnnwnnnn:"Y",nwwnwnnnn:"Z",nwnnnnwnw:"-",wwnnnnwnn:".",nwwnnnwnn:" ",nwnwnwnnn:"$",nwnwnnnwn:"/",nwnnnwnwn:"+",nnnwnwnwn:"%",nwnnwnwnn:"*"},b=function(n){for(var e=[],r=Math.ceil(n.reduce(function(n,e){return n+e},0)/n.length);n.length>0;){var t=n.splice(0,10).map(function(n){return n>r?"w":"n"});e.push(m[t.slice(0,9).join("")])}return"*"!==e.pop()||"*"!==e.shift()?null:e.join("")},C=[{100010100:"0"},{101001000:"1"},{101000100:"2"},{101000010:"3"},{100101000:"4"},{100100100:"5"},{100100010:"6"},{101010000:"7"},{100010010:"8"},{100001010:"9"},{110101000:"A"},{110100100:"B"},{110100010:"C"},{110010100:"D"},{110010010:"E"},{110001010:"F"},{101101000:"G"},{101100100:"H"},{101100010:"I"},{100110100:"J"},{100011010:"K"},{101011000:"L"},{101001100:"M"},{101000110:"N"},{100101100:"O"},{100010110:"P"},{110110100:"Q"},{110110010:"R"},{110101100:"S"},{110100110:"T"},{110010110:"U"},{110011010:"V"},{101101100:"W"},{101100110:"X"},{100110110:"Y"},{100111010:"Z"},{100101110:"-"},{111010100:"."},{111010010:" "},{111001010:"$"},{101101110:"/"},{101110110:"+"},{110101110:"%"},{100100110:"($)"},{111011010:"(%)"},{111010110:"(/)"},{100110010:"(+)"},{101011110:"*"}],y=function(n){var e=[],r=[];n.pop();for(var t=Math.ceil(n.reduce(function(n,e){return n+e},0)/n.length),w=Math.ceil(n.reduce(function(n,e){return e<t?(n+e)/2:n},0)),a=0;a<n.length;a+=1)for(var i=n[a];i>0;)a%2==0?r.push(1):r.push(0),i-=w;for(var o=function(n){var t=r.slice(n,n+9).join(""),w=C.filter(function(n){return Object.keys(n)[0]===t});e.push(w[0][t])},u=0;u<r.length;u+=9)o(u);if("*"!==e.shift()||"*"!==e.pop())return null;for(var c,f=e.pop(),l=0,s=function(n){return Object.values(n)[0]===c},d=e.length-1;d>=0;d-=1)c=e[d],l+=C.indexOf(C.filter(s)[0])*(1+(e.length-(d+1))%20);if(Object.values(C[l%47])[0]!==f)return null;var h=e.pop();l=0;for(var p=e.length-1;p>=0;p-=1)c=e[p],l+=C.indexOf(C.filter(s)[0])*(1+(e.length-(p+1))%20);return Object.values(C[l%47])[0]!==h?null:e.join("")},j={3211:"0",2221:"1",2122:"2",1411:"3",1132:"4",1231:"5",1114:"6",1312:"7",1213:"8",3112:"9"},S=function(n){var e="";n.unshift(0);for(var r=~~((n[1]+n[2]+n[3])/3),t=1;t<n.length;t+=1){var w=void 0;w=e.length<6?n.slice(4*t,4*t+4):n.slice(4*t+5,4*t+9);var a=[Math.round(w[0]/r),Math.round(w[1]/r),Math.round(w[2]/r),Math.round(w[3]/r)],i=j[a.join("")]||j[a.reverse().join("")];if(i&&(e+=i),12===e.length)break}return e},x={3211:"0",2221:"1",2122:"2",1411:"3",1132:"4",1231:"5",1114:"6",1312:"7",1213:"8",3112:"9"},M=function(n){var e="";n.unshift(0);for(var r=~~((n[1]+n[2]+n[3])/3),t=1;t<n.length;t+=1){var w=void 0;w=e.length<4?n.slice(4*t,4*t+4):n.slice(4*t+5,4*t+9);var a=[Math.round(w[0]/r),Math.round(w[1]/r),Math.round(w[2]/r),Math.round(w[3]/r)],i=x[a.join("")]||x[a.reverse().join("")];if(i&&(e+=i),8===e.length)break}return e},O={nnnnnww:"0",nnnnwwn:"1",nnnwnnw:"2",wwnnnnn:"3",nnwnnwn:"4",wnnnnwn:"5",nwnnnnw:"6",nwnnwnn:"7",nwwnnnn:"8",wnnwnnn:"9",nnnwwnn:"-",nnwwnnn:"$",wnnnwnw:":",wnwnnnw:"/",wnwnwnn:".",nnwwwww:"+",nnwwnwn:"A",nnnwnww:"B",nwnwnnw:"C",nnnwwwn:"D"},N=function(n){for(var e=[],r=Math.ceil(n.reduce(function(n,e){return(n+e)/2},0));n.length>0;){var t=n.splice(0,8).splice(0,7).map(function(n){return n<r?"n":"w"}).join("");e.push(O[t])}return e.join("")};return function(n){var e={"code-128":p,"code-2of5":g,"code-39":b,"code-93":y,"ean-13":S,"ean-8":M,codabar:N};function r(n,e){return a.apply(this,arguments)}function a(){return(a=t(regeneratorRuntime.mark(function n(r,t){var w,a,i,o,u,f,l,s,d,h,p,v,g,m,b;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(t.barcode=t.barcode.toLowerCase(),-1!==(w=Object.keys(e)).indexOf(t.barcode)){n.next=4;break}throw new Error("Invalid barcode specified. Available decoders: ".concat(w,". https://github.com/mubaidr/Javascript-Barcode-Reader#available-decoders"));case 4:return n.next=6,c.getImageDataFromSource(r);case 6:a=n.sent,i=a.data,o=a.width,u=a.height,f=i.length/(o*u),s=(l=[1,9,2,8,3,7,4,6,5]).length,d=u/(s+1);case 14:if(!(s-=1)){n.next=26;break}if(h=f*o*Math.floor(d*l[s]),p=f*o*Math.floor(d*l[s])+2*f*o,v=c.getLines({data:i,start:h,end:p,width:o,height:u,channels:f}),g=v.lines,m=v.padding,!g||0===g.length){n.next=24;break}if(m.left&&g.shift(),m.right&&g.pop(),!(b=e[t.barcode](g,t.type))){n.next=24;break}return n.abrupt("return",b);case 24:n.next=14;break;case 26:throw new Error("Failed to extract barcode!");case 27:case"end":return n.stop()}},n)}))).apply(this,arguments)}n&&n.exports?n.exports=r:w.javascriptBarcodeReader=r}(u={exports:{}},u.exports),u.exports}(window.jimp); | ||
var javascriptBarcodeReader=function(n){"use strict";n=n&&n.hasOwnProperty("default")?n.default:n;var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(n,t){return n(t={exports:{}},t.exports),t.exports}var r=e(function(n){var t=function(n){var t,e=Object.prototype,r=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(n,t,e,r){var o=t&&t.prototype instanceof d?t:d,i=Object.create(o.prototype),a=new O(r||[]);return i._invoke=function(n,t,e){var r=f;return function(o,i){if(r===s)throw new Error("Generator is already running");if(r===h){if("throw"===o)throw i;return F()}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=L(a,e);if(u){if(u===p)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(r===f)throw r=h,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);r=s;var c=w(n,t,e);if("normal"===c.type){if(r=e.done?h:l,c.arg===p)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(r=h,e.method="throw",e.arg=c.arg)}}}(n,e,a),i}function w(n,t,e){try{return{type:"normal",arg:n.call(t,e)}}catch(n){return{type:"throw",arg:n}}}n.wrap=c;var f="suspendedStart",l="suspendedYield",s="executing",h="completed",p={};function d(){}function v(){}function g(){}var y={};y[i]=function(){return this};var m=Object.getPrototypeOf,b=m&&m(m(N([])));b&&b!==e&&r.call(b,i)&&(y=b);var x=g.prototype=d.prototype=Object.create(y);function E(n){["next","throw","return"].forEach(function(t){n[t]=function(n){return this._invoke(t,n)}})}function j(n){var t;this._invoke=function(e,o){function i(){return new Promise(function(t,i){!function t(e,o,i,a){var u=w(n[e],n,o);if("throw"!==u.type){var c=u.arg,f=c.value;return f&&"object"==typeof f&&r.call(f,"__await")?Promise.resolve(f.__await).then(function(n){t("next",n,i,a)},function(n){t("throw",n,i,a)}):Promise.resolve(f).then(function(n){c.value=n,i(c)},function(n){return t("throw",n,i,a)})}a(u.arg)}(e,o,t,i)})}return t=t?t.then(i,i):i()}}function L(n,e){var r=n.iterator[e.method];if(r===t){if(e.delegate=null,"throw"===e.method){if(n.iterator.return&&(e.method="return",e.arg=t,L(n,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var o=w(r,n.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[n.resultName]=i.value,e.next=n.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function S(n){var t={tryLoc:n[0]};1 in n&&(t.catchLoc=n[1]),2 in n&&(t.finallyLoc=n[2],t.afterLoc=n[3]),this.tryEntries.push(t)}function C(n){var t=n.completion||{};t.type="normal",delete t.arg,n.completion=t}function O(n){this.tryEntries=[{tryLoc:"root"}],n.forEach(S,this),this.reset(!0)}function N(n){if(n){var e=n[i];if(e)return e.call(n);if("function"==typeof n.next)return n;if(!isNaN(n.length)){var o=-1,a=function e(){for(;++o<n.length;)if(r.call(n,o))return e.value=n[o],e.done=!1,e;return e.value=t,e.done=!0,e};return a.next=a}}return{next:F}}function F(){return{value:t,done:!0}}return v.prototype=x.constructor=g,g.constructor=v,g[u]=v.displayName="GeneratorFunction",n.isGeneratorFunction=function(n){var t="function"==typeof n&&n.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},n.mark=function(n){return Object.setPrototypeOf?Object.setPrototypeOf(n,g):(n.__proto__=g,u in n||(n[u]="GeneratorFunction")),n.prototype=Object.create(x),n},n.awrap=function(n){return{__await:n}},E(j.prototype),j.prototype[a]=function(){return this},n.AsyncIterator=j,n.async=function(t,e,r,o){var i=new j(c(t,e,r,o));return n.isGeneratorFunction(e)?i:i.next().then(function(n){return n.done?n.value:i.next()})},E(x),x[u]="Generator",x[i]=function(){return this},x.toString=function(){return"[object Generator]"},n.keys=function(n){var t=[];for(var e in n)t.push(e);return t.reverse(),function e(){for(;t.length;){var r=t.pop();if(r in n)return e.value=r,e.done=!1,e}return e.done=!0,e}},n.values=N,O.prototype={constructor:O,reset:function(n){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(C),!n)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var n=this.tryEntries[0].completion;if("throw"===n.type)throw n.arg;return this.rval},dispatchException:function(n){if(this.done)throw n;var e=this;function o(r,o){return u.type="throw",u.arg=n,e.next=r,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),w=r.call(a,"finallyLoc");if(c&&w){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!w)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(n,t){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===n||"continue"===n)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=n,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(n,t){if("throw"===n.type)throw n.arg;return"break"===n.type||"continue"===n.type?this.next=n.arg:"return"===n.type?(this.rval=this.arg=n.arg,this.method="return",this.next="end"):"normal"===n.type&&t&&(this.next=t),p},finish:function(n){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.finallyLoc===n)return this.complete(e.completion,e.afterLoc),C(e),p}},catch:function(n){for(var t=this.tryEntries.length-1;t>=0;--t){var e=this.tryEntries[t];if(e.tryLoc===n){var r=e.completion;if("throw"===r.type){var o=r.arg;C(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(n,e,r){return this.delegate={iterator:N(n),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=t),p}},n}(n.exports);try{regeneratorRuntime=t}catch(n){Function("r","regeneratorRuntime = r")(t)}});function o(n,t,e,r,o,i,a){try{var u=n[i](a),c=u.value}catch(n){return void e(n)}u.done?t(c):Promise.resolve(c).then(r,o)}var i=function(n){return function(){var t=this,e=arguments;return new Promise(function(r,i){var a=n.apply(t,e);function u(n){o(a,r,i,u,c,"next",n)}function c(n){o(a,r,i,u,c,"throw",n)}u(void 0)})}},a=e(function(n){function t(n){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(n)}function e(r){return"function"==typeof Symbol&&"symbol"===t(Symbol.iterator)?n.exports=e=function(n){return t(n)}:n.exports=e=function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":t(n)},e(r)}n.exports=e}),u="object"===("undefined"==typeof process?"undefined":a(process))&&process.release&&"node"===process.release.name;function c(n){var t=document.createElement("canvas"),e=t.getContext("2d"),r=n.naturalWidth,o=n.naturalHeight;return t.width=r,t.height=o,e.drawImage(n,0,0),e.getImageData(0,0,n.naturalWidth,n.naturalHeight)}function w(){return(w=i(r.mark(function t(e){var o,i,a;return r.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=!!(o="string"==typeof e)&&("#"===!(r=e)[0]||/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(r)),a=e.tagName,t.abrupt("return",new Promise(function(t,r){if(o)if(u)n.read(i?{url:e,headers:{}}:e,function(n,e){if(n)r(n);else{var o=e.bitmap,i=o.data,a=o.width,u=o.height;t({data:i.toJSON().data,width:a,height:u})}});else if(i){var w=new Image;w.onerror=r,w.onload=function(){return t(c(w))},w.src=e}else{var f=document.getElementById(e);f&&t(c(f)),r(new Error("Invalid image source specified!"))}else a?("IMG"===a?t(c(e)):"CANVAS"===a&&t(e.getContext("2d").getImageData(0,0,e.naturalWidth,e.naturalHeight)),r(new Error("Invalid image source specified!"))):e.data&&e.width&&e.height?t(e):r(new Error("Invalid image source specified!"))}));case 4:case"end":return t.stop()}var r},t)}))).apply(this,arguments)}var f={getImageDataFromSource:function(n){return w.apply(this,arguments)},getLines:function(n){for(var t=n.data,e=n.start,r=n.end,o=n.channels,i=n.width,a=t.slice(e,r),u=[],c=[],w=[],f=1,l=0,s=0,h={left:!0,right:!0},p=0;p<2;p+=1)for(var d=0;d<i;d+=1){var v=(p*i+d)*o,g=(3*a[v]+4*a[v+1]+2*a[v+2])/9,y=u[d];a[v]=g,a[v+1]=g,a[v+2]=g,u[d]=g+(y||0)}for(var m=0;m<i;m+=1){u[m]/=2;var b=u[m];b<l?l=b:s=b}for(var x=l+(s-l)/2,E=0;E<i;E+=1){for(var j=0,L=void 0,S=0;S<2;S+=1)(L=a[(S*i+E)*o])>x&&(j+=1);0===E&&L<=x&&(h.left=!1),E===i-1&&L<=x&&(h.right=!1),c.push(j>1)}for(var C=c[0],O=0;O<i;O+=1)c[O]===C?(f+=1,O===i-1&&w.push(f)):(w.push(f),f=1,C=c[O]);return{lines:w,padding:h}}},l=["212222","222122","222221","121223","121322","131222","122213","122312","132212","221213","221312","231212","112232","122132","122231","113222","123122","123221","223211","221132","221231","213212","223112","312131","311222","321122","321221","312212","322112","322211","212123","212321","232121","111323","131123","131321","112313","132113","132311","211313","231113","231311","112133","112331","132131","113123","113321","133121","313121","211331","231131","213113","213311","213131","311123","311321","331121","312113","312311","332111","314111","221411","431111","111224","111422","121124","121421","141122","141221","112214","112412","122114","122411","142112","142211","241211","221114","413111","241112","134111","111242","121142","121241","114212","124112","124211","411212","421112","421211","212141","214121","412121","111143","111341","131141","114113","114311","411113","411311","113141","114131","311141","411131","211412","211214","211232","233111","211133","2331112"],s=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","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","[","\\","]","^","_","NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS","HT","LF","VT","FF","CR","SO","SI","DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM","SUB","ESC","FS","GS","RS","US","FNC 3","FNC 2","Shift B","Code C","Code B","FNC 4","FNC 1"],h=[" ","!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","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","[","\\","]","^","_","`","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","{","|","}","~","DEL","FNC 3","FNC 2","Shift A","Code C","FNC 4","Code A","FNC 1"],p=["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99","Code B","Code A","FNC 1"],d=function(n){var t=n.reduce(function(n,t){return n+t},0)/11;return n.map(function(n){return Math.round(n/t)}).join("")},v=function(n){var t,e,r,o,i,a=[];n.pop();var u=n.slice(0);switch(r=d(u.splice(0,6))){case"211214":t=h,e=104;break;case"211232":t=p,e=105;break;default:t=s,e=103}for(var c=1;u.length>12;c+=1)switch(r=d(u.splice(0,6)),e+=c*(i=l.indexOf(r)),o=t[i]){case"Code A":t=s;break;case"Code B":t=h;break;case"Code C":t=p;break;default:a.push(o)}return r=d(u.splice(0,6)),e%103!==l.indexOf(r)?null:a.join("")},g=["nnwwn","wnnnw","nwnnw","wwnnn","nnwnw","wnwnn","nwwnn","nnnww","wnnwn","nwnwn"],y=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"standard",e=[],r=Math.ceil(n.reduce(function(n,t){return(n+t)/2},0));if("interleaved"===t){var o=n.splice(0,4).map(function(n){return n>r?"w":"n"}).join(""),i=n.splice(n.length-3,3).map(function(n){return n>r?"w":"n"}).join("");if("nnnn"!==o||"wnn"!==i)return null;for(;n.length>0;){var a=n.splice(0,10),u=a.filter(function(n,t){return t%2==0}).map(function(n){return n>r?"w":"n"}).join("");e.push(g.indexOf(u));var c=a.filter(function(n,t){return t%2!=0}).map(function(n){return n>r?"w":"n"}).join("");e.push(g.indexOf(c))}}else if("standard"===t){var w=n.splice(0,6).filter(function(n,t){return t%2==0}).map(function(n){return n>r?"w":"n"}).join(""),f=n.splice(n.length-5,5).filter(function(n,t){return t%2==0}).map(function(n){return n>r?"w":"n"}).join("");if("wwn"!==w||"wnw"!==f)return null;for(;n.length>0;){var l=n.splice(0,10).filter(function(n,t){return t%2==0}).map(function(n){return n>r?"w":"n"}).join("");e.push(g.indexOf(l))}}return e.join("")},m={nnnwwnwnn:"0",wnnwnnnnw:"1",nnwwnnnnw:"2",wnwwnnnnn:"3",nnnwwnnnw:"4",wnnwwnnnn:"5",nnwwwnnnn:"6",nnnwnnwnw:"7",wnnwnnwnn:"8",nnwwnnwnn:"9",wnnnnwnnw:"A",nnwnnwnnw:"B",wnwnnwnnn:"C",nnnnwwnnw:"D",wnnnwwnnn:"E",nnwnwwnnn:"F",nnnnnwwnw:"G",wnnnnwwnn:"H",nnwnnwwnn:"I",nnnnwwwnn:"J",wnnnnnnww:"K",nnwnnnnww:"L",wnwnnnnwn:"M",nnnnwnnww:"N",wnnnwnnwn:"O",nnwnwnnwn:"P",nnnnnnwww:"Q",wnnnnnwwn:"R",nnwnnnwwn:"S",nnnnwnwwn:"T",wwnnnnnnw:"U",nwwnnnnnw:"V",wwwnnnnnn:"W",nwnnwnnnw:"X",wwnnwnnnn:"Y",nwwnwnnnn:"Z",nwnnnnwnw:"-",wwnnnnwnn:".",nwwnnnwnn:" ",nwnwnwnnn:"$",nwnwnnnwn:"/",nwnnnwnwn:"+",nnnwnwnwn:"%",nwnnwnwnn:"*"},b=function(n){for(var t=[],e=Math.ceil(n.reduce(function(n,t){return n+t},0)/n.length);n.length>0;){var r=n.splice(0,10).map(function(n){return n>e?"w":"n"});t.push(m[r.slice(0,9).join("")])}return"*"!==t.pop()||"*"!==t.shift()?null:t.join("")},x=[{100010100:"0"},{101001000:"1"},{101000100:"2"},{101000010:"3"},{100101000:"4"},{100100100:"5"},{100100010:"6"},{101010000:"7"},{100010010:"8"},{100001010:"9"},{110101000:"A"},{110100100:"B"},{110100010:"C"},{110010100:"D"},{110010010:"E"},{110001010:"F"},{101101000:"G"},{101100100:"H"},{101100010:"I"},{100110100:"J"},{100011010:"K"},{101011000:"L"},{101001100:"M"},{101000110:"N"},{100101100:"O"},{100010110:"P"},{110110100:"Q"},{110110010:"R"},{110101100:"S"},{110100110:"T"},{110010110:"U"},{110011010:"V"},{101101100:"W"},{101100110:"X"},{100110110:"Y"},{100111010:"Z"},{100101110:"-"},{111010100:"."},{111010010:" "},{111001010:"$"},{101101110:"/"},{101110110:"+"},{110101110:"%"},{100100110:"($)"},{111011010:"(%)"},{111010110:"(/)"},{100110010:"(+)"},{101011110:"*"}],E=function(n){var t=[],e=[];n.pop();for(var r=Math.ceil(n.reduce(function(n,t){return n+t},0)/n.length),o=Math.ceil(n.reduce(function(n,t){return t<r?(n+t)/2:n},0)),i=0;i<n.length;i+=1)for(var a=n[i];a>0;)i%2==0?e.push(1):e.push(0),a-=o;for(var u=function(n){var r=e.slice(n,n+9).join(""),o=x.filter(function(n){return Object.keys(n)[0]===r});t.push(o[0][r])},c=0;c<e.length;c+=9)u(c);if("*"!==t.shift()||"*"!==t.pop())return null;for(var w,f=t.pop(),l=0,s=function(n){return Object.values(n)[0]===w},h=t.length-1;h>=0;h-=1)w=t[h],l+=x.indexOf(x.filter(s)[0])*(1+(t.length-(h+1))%20);if(Object.values(x[l%47])[0]!==f)return null;var p=t.pop();l=0;for(var d=t.length-1;d>=0;d-=1)w=t[d],l+=x.indexOf(x.filter(s)[0])*(1+(t.length-(d+1))%20);return Object.values(x[l%47])[0]!==p?null:t.join("")},j={3211:"0",2221:"1",2122:"2",1411:"3",1132:"4",1231:"5",1114:"6",1312:"7",1213:"8",3112:"9"},L=function(n){var t="";n.unshift(0);for(var e=~~((n[1]+n[2]+n[3])/3),r=1;r<n.length;r+=1){var o=void 0;o=t.length<6?n.slice(4*r,4*r+4):n.slice(4*r+5,4*r+9);var i=[Math.round(o[0]/e),Math.round(o[1]/e),Math.round(o[2]/e),Math.round(o[3]/e)],a=j[i.join("")]||j[i.reverse().join("")];if(a&&(t+=a),12===t.length)break}return t},S={3211:"0",2221:"1",2122:"2",1411:"3",1132:"4",1231:"5",1114:"6",1312:"7",1213:"8",3112:"9"},C=function(n){var t="";n.unshift(0);for(var e=~~((n[1]+n[2]+n[3])/3),r=1;r<n.length;r+=1){var o=void 0;o=t.length<4?n.slice(4*r,4*r+4):n.slice(4*r+5,4*r+9);var i=[Math.round(o[0]/e),Math.round(o[1]/e),Math.round(o[2]/e),Math.round(o[3]/e)],a=S[i.join("")]||S[i.reverse().join("")];if(a&&(t+=a),8===t.length)break}return t},O={nnnnnww:"0",nnnnwwn:"1",nnnwnnw:"2",wwnnnnn:"3",nnwnnwn:"4",wnnnnwn:"5",nwnnnnw:"6",nwnnwnn:"7",nwwnnnn:"8",wnnwnnn:"9",nnnwwnn:"-",nnwwnnn:"$",wnnnwnw:":",wnwnnnw:"/",wnwnwnn:".",nnwwwww:"+",nnwwnwn:"A",nnnwnww:"B",nwnwnnw:"C",nnnwwwn:"D"},N=function(n){for(var t=[],e=Math.ceil(n.reduce(function(n,t){return(n+t)/2},0));n.length>0;){var r=n.splice(0,8).splice(0,7).map(function(n){return n<e?"n":"w"}).join("");t.push(O[r])}return t.join("")};return e(function(n){var e={"code-128":v,"code-2of5":y,"code-39":b,"code-93":E,"ean-13":L,"ean-8":C,codabar:N};function o(n,t){return a.apply(this,arguments)}function a(){return(a=i(r.mark(function n(t,o){var i,a,u,c,w,l,s,h,p,d,v,g,y,m,b;return r.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(o.barcode=o.barcode.toLowerCase(),-1!==(i=Object.keys(e)).indexOf(o.barcode)){n.next=4;break}throw new Error("Invalid barcode specified. Available decoders: ".concat(i,". https://github.com/mubaidr/Javascript-Barcode-Reader#available-decoders"));case 4:return n.next=6,f.getImageDataFromSource(t);case 6:a=n.sent,u=a.data,c=a.width,w=a.height,l=u.length/(c*w),h=(s=[1,9,2,8,3,7,4,6,5]).length,p=w/(h+1);case 14:if(!(h-=1)){n.next=26;break}if(d=l*c*Math.floor(p*s[h]),v=l*c*Math.floor(p*s[h])+2*l*c,g=f.getLines({data:u,start:d,end:v,width:c,height:w,channels:l}),y=g.lines,m=g.padding,!y||0===y.length){n.next=24;break}if(m.left&&y.shift(),m.right&&y.pop(),!(b=e[o.barcode](y,o.type))){n.next=24;break}return n.abrupt("return",b);case 24:n.next=14;break;case 26:throw new Error("Failed to extract barcode!");case 27:case"end":return n.stop()}},n)}))).apply(this,arguments)}n&&n.exports?n.exports=o:t.javascriptBarcodeReader=o})}(window.jimp); | ||
//# sourceMappingURL=javascript-barcode-reader.min.js.map |
@@ -7,2 +7,3 @@ { | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.5", | ||
"jimp": "^0.6.4" | ||
@@ -13,6 +14,7 @@ }, | ||
"@babel/core": "^7.4.5", | ||
"@babel/plugin-transform-runtime": "^7.4.4", | ||
"@babel/preset-env": "7.4.5", | ||
"eslint": "^6.0.0", | ||
"eslint-config-airbnb": "^17.1.0", | ||
"eslint-config-prettier": "^5.0.0", | ||
"eslint-config-prettier": "^6.0.0", | ||
"eslint-plugin-import": "^2.17.3", | ||
@@ -24,2 +26,3 @@ "eslint-plugin-jsx-a11y": "^6.2.1", | ||
"jest": "^24.8.0", | ||
"npm-run-all": "^4.1.5", | ||
"rollup": "^1.16.2", | ||
@@ -57,7 +60,6 @@ "rollup-plugin-babel": "^4.3.3", | ||
"test": "jest", | ||
"test-gpu": "nodemon ./src/gpu-utilities.js", | ||
"test:watch": "jest --watch", | ||
"watch": "rollup -c -w" | ||
}, | ||
"version": "0.4.14" | ||
"version": "0.4.15" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
276410
2490
2
19
+ Added@babel/runtime@^7.4.5
+ Added@babel/runtime@7.24.6(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)