123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- "use strict";
- var __assign = (this && this.__assign) || function () {
- __assign = Object.assign || function(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
- if (ar || !(i in from)) {
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
- ar[i] = from[i];
- }
- }
- return to.concat(ar || Array.prototype.slice.call(from));
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.ERROR_CORRECTION_LEVEL_HIGH = exports.ERROR_CORRECTION_LEVEL_QUARTILE = exports.ERROR_CORRECTION_LEVEL_MEDIUM = exports.ERROR_CORRECTION_LEVEL_LOW = void 0;
- var qr_1 = require("@akamfoad/qr");
- exports.ERROR_CORRECTION_LEVEL_LOW = 'L'; // Allows recovery of up to 7% data loss
- exports.ERROR_CORRECTION_LEVEL_MEDIUM = 'M'; // Allows recovery of up to 15% data loss
- exports.ERROR_CORRECTION_LEVEL_QUARTILE = 'Q'; // Allows recovery of up to 25% data loss
- exports.ERROR_CORRECTION_LEVEL_HIGH = 'H'; // Allows recovery of up to 30% data loss
- var DEFAULT_CONSTRUCTOR_PARAMS = {
- level: exports.ERROR_CORRECTION_LEVEL_LOW,
- padding: 1,
- invert: false,
- typeNumber: 0,
- errorsEnabled: false,
- };
- var QRCodeRaw = /** @class */ (function () {
- function QRCodeRaw(value, options) {
- if (options === void 0) { options = {}; }
- var params = __assign(__assign({}, DEFAULT_CONSTRUCTOR_PARAMS), options);
- this.value = value;
- this.level = params.level;
- this.typeNumber = params.typeNumber;
- this.padding = params.padding;
- this.invert = params.invert;
- this.errorsEnabled = params.errorsEnabled;
- }
- QRCodeRaw.prototype.setValue = function (value) {
- this.value = value;
- this._clearCache();
- };
- QRCodeRaw.prototype.getDataSize = function () {
- var data = this.getData();
- return data ? data.length : 0;
- };
- QRCodeRaw.prototype._clearCache = function () {
- this.qrCodeData = null;
- };
- QRCodeRaw.prototype._getQrCodeData = function (modules) {
- var qrCodeData = [];
- var padding = this.padding;
- var invert = this.invert;
- var rowPadding = Array(padding * 2 + modules.length).fill(invert);
- var rowsPadding = Array(padding).fill(rowPadding);
- var columnPadding = Array(padding).fill(invert);
- if (padding) {
- qrCodeData.push.apply(qrCodeData, rowsPadding);
- }
- modules.forEach(function (row) {
- var qrCodeRow = [];
- qrCodeRow.push.apply(qrCodeRow, __spreadArray(__spreadArray(__spreadArray([], columnPadding, false), row.map(function (isBlack) { return (invert ? !isBlack : isBlack); }), false), columnPadding, false));
- qrCodeData.push(qrCodeRow);
- });
- if (padding) {
- qrCodeData.push.apply(qrCodeData, rowsPadding);
- }
- return qrCodeData;
- };
- QRCodeRaw.prototype.getData = function () {
- if (!this.qrCodeData) {
- try {
- var qrcode = new qr_1.QRCode(this.typeNumber, qr_1.ErrorCorrectLevel[this.level]);
- qrcode.addData(this.value);
- qrcode.make();
- if (!qrcode.modules) {
- return null;
- }
- this.qrCodeData = this._getQrCodeData(qrcode.modules);
- Object.freeze(this.qrCodeData);
- }
- catch (error) {
- if (this.errorsEnabled) {
- throw error;
- }
- return null;
- }
- }
- return this.qrCodeData;
- };
- return QRCodeRaw;
- }());
- exports.default = QRCodeRaw;
|