all files / pdf417/ pdf417.js

97.81% Statements 134/137
92.54% Branches 62/67
96% Functions 24/25
97.71% Lines 128/131
18 statements, 7 functions, 29 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210  1× 1× 1× 1× 1× 1×   1× 1× 1× 1×       1× 1× 1× 1× 1×   1×   1× 1× 1× 1× 1× 55×   1× 55× 55× 55× 55× 55× 55× 55× 55×   1× 1× 1×   1× 332×   1× 55×                           1× 56×   1× 126× 126×   1× 63×     63×     63× 63× 63× 63× 63× 63× 63×       63×   1× 63× 63×   63×   1× 12× 12×   1× 55× 55× 55× 55×   1× 8× 1×   8× 8× 8×   1×     1× 1×   1× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 63× 12× 12×     51× 51×   63× 14× 14×     1× 55× 55× 55× 55× 55×   1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×   1×    
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/* istanbul ignore next */ 
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../barcode/enum/enum", "../barcode/primitives/displaytext", "../barcode/primitives/margin", "../barcode/rendering/renderer", "../barcode/utility/barcode-util", "./pdf417-util"], function (require, exports, ej2_base_1, ej2_base_2, enum_1, displaytext_1, margin_1, renderer_1, barcode_util_1, pdf417_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PDF417_ARIA_TEXT_LIMIT = 100;
    var PDF417Generator = (function (_super) {
        __extends(PDF417Generator, _super);
        function PDF417Generator(options, element) {
            return _super.call(this, options, element) || this;
        }
        PDF417Generator.prototype.destroy = function () {
            this.notify('destroy', {});
            this.removeRootElement();
            this.element.classList.remove('e-pdf417');
            this.element.removeAttribute('role');
            this.element.removeAttribute('aria-label');
            this.barcodeRenderer = null;
            this.symbolInfo = null;
            _super.prototype.destroy.call(this);
        };
        PDF417Generator.prototype.getPersistData = function () {
            var keyEntity = ['loaded'];
            return this.addOnPersist(keyEntity);
        };
        PDF417Generator.prototype.getModuleName = function () {
            return 'PDF417Generator';
        };
        PDF417Generator.prototype.initializePrivateVariables = function () {
            this.defaultLocale = {
                ariaLabel: 'PDF417 barcode',
                EmptyValue: 'The value is empty.',
                InvalidTextValue: 'The value contains characters that are not supported by Text compaction.',
                InvalidNumericValue: 'Numeric compaction supports only the digits 0-9.',
                InvalidCompactionMode: 'The compaction mode is not supported.',
                InvalidErrorCorrectionLevel: 'The error correction level must be Auto or a level from 0 to 8.',
                InvalidRows: 'The number of rows must be 0 (auto) or 3-90, and enough to hold the value. Rows x columns must not exceed 928.',
                InvalidColumns: 'The number of columns must be 0 (auto) or 1-30, and enough to hold the value. Rows x columns must not exceed 928.',
                InvalidRowHeightRatio: 'The row height ratio must be a number of 3 or more.',
                CapacityExceeded: 'The value is too long for the PDF417 symbol with the current settings.',
                InsufficientSize: 'The width and height are too small to render the PDF417 symbol after margins and text.'
            };
        };
        PDF417Generator.prototype.setCulture = function () {
            this.localeObj = new ej2_base_1.L10n(this.getModuleName(), this.defaultLocale, this.locale);
        };
        PDF417Generator.prototype.getElementSize = function (real) {
            var value = real.toString();
            return (value.indexOf('px') > 0 || value.indexOf('%') > 0) ? value : value + 'px';
        };
        PDF417Generator.prototype.initialize = function () {
            Iif (!this.width) {
                this.width = '100%';
            }
            Iif (!this.height) {
                this.height = '100%';
            }
            this.element.style.display = 'block';
            this.element.style.width = this.getElementSize(this.width);
            this.element.style.height = this.getElementSize(this.height);
            this.barcodeRenderer = new renderer_1.BarcodeRenderer(this.element.id, this.mode === 'SVG');
            var height = this.mode === 'SVG' ? this.element.offsetHeight : this.element.offsetHeight * 1.5;
            var width = this.mode === 'SVG' ? this.element.offsetWidth : this.element.offsetWidth * 1.5;
            this.barcodeCanvas = this.barcodeRenderer.renderRootElement({
                id: this.element.id + 'content',
                height: height, width: width
            }, this.backgroundColor, width, height);
            this.element.appendChild(this.barcodeCanvas);
        };
        PDF417Generator.prototype.removeRootElement = function () {
            Eif (this.barcodeCanvas && this.barcodeCanvas.parentNode) {
                this.barcodeCanvas.parentNode.removeChild(this.barcodeCanvas);
            }
            this.barcodeCanvas = null;
        };
        PDF417Generator.prototype.triggerEvent = function (eventName, message) {
            var arg = { message: message };
            this.trigger(enum_1.BarcodeEvent["" + eventName], arg);
        };
        PDF417Generator.prototype.preRender = function () {
            this.element.classList.add('e-pdf417');
            this.initializePrivateVariables();
            this.setCulture();
            this.initialize();
        };
        PDF417Generator.prototype.onPropertyChanged = function (newProp, oldProp) {
            if (newProp.locale !== undefined) {
                this.setCulture();
            }
            this.removeRootElement();
            this.initialize();
            this.renderElements();
        };
        PDF417Generator.prototype.exportImage = function (fileName, exportType) {
            barcode_util_1.exportAsImage(exportType, fileName, this.element, false, this);
        };
        PDF417Generator.prototype.exportAsBase64Image = function (barcodeExportType) {
            return barcode_util_1.exportAsImage(barcodeExportType, '', this.element, true, this);
        };
        PDF417Generator.prototype.renderElements = function () {
            var pdf417 = new pdf417_util_1.PDF417();
            this.value = (this.value === undefined || this.value === null) ? '' : this.value;
            pdf417.value = this.value;
            pdf417.width = Number(this.barcodeCanvas.getAttribute('width'));
            pdf417.height = Number(this.barcodeCanvas.getAttribute('height'));
            pdf417.isSvgMode = this.mode === 'SVG';
            pdf417.margin = this.margin;
            pdf417.displayText = this.displayText;
            pdf417.foreColor = this.foreColor;
            pdf417.compactionMode = this.compactionMode;
            pdf417.errorCorrectionLevel = this.errorCorrectionLevel;
            pdf417.rows = this.rows;
            pdf417.columns = this.columns;
            pdf417.isCompact = this.isCompact;
            pdf417.rowHeightRatio = this.rowHeightRatio;
            var result = pdf417.build();
            this.element.setAttribute('role', 'img');
            var label = this.localeObj.getConstant('ariaLabel');
            var text = String(this.displayText.text || this.value);
            var spoken = text.length > PDF417_ARIA_TEXT_LIMIT ? text.substring(0, PDF417_ARIA_TEXT_LIMIT) + '\u2026' : text;
            this.element.setAttribute('aria-label', spoken ? label + ': ' + spoken : label);
            if (!result.success) {
                this.symbolInfo = null;
                this.triggerEvent(enum_1.BarcodeEvent.invalid, this.localeObj.getConstant(result.error));
            }
            else {
                this.symbolInfo = { rows: result.rows, columns: result.columns, errorCorrectionLevel: result.errorCorrectionLevel };
                pdf417.draw(this.barcodeCanvas);
            }
            if (this.mode === 'Canvas') {
                this.barcodeCanvas.style.transform = 'scale(' + (2 / 3) + ')';
                this.barcodeCanvas.style.transformOrigin = '0 0';
            }
        };
        PDF417Generator.prototype.render = function () {
            this.notify('initial-load', {});
            this.trigger('load');
            this.notify('initial-end', {});
            this.renderElements();
            this.renderComplete();
        };
        __decorate([
            ej2_base_1.Property('SVG')
        ], PDF417Generator.prototype, "mode", void 0);
        __decorate([
            ej2_base_1.Property(undefined)
        ], PDF417Generator.prototype, "value", void 0);
        __decorate([
            ej2_base_1.Property('100%')
        ], PDF417Generator.prototype, "height", void 0);
        __decorate([
            ej2_base_1.Property('100%')
        ], PDF417Generator.prototype, "width", void 0);
        __decorate([
            ej2_base_1.Property('Auto')
        ], PDF417Generator.prototype, "compactionMode", void 0);
        __decorate([
            ej2_base_1.Property(enum_1.PDF417ErrorCorrectionLevel.Auto)
        ], PDF417Generator.prototype, "errorCorrectionLevel", void 0);
        __decorate([
            ej2_base_1.Property(0)
        ], PDF417Generator.prototype, "columns", void 0);
        __decorate([
            ej2_base_1.Property(0)
        ], PDF417Generator.prototype, "rows", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], PDF417Generator.prototype, "isCompact", void 0);
        __decorate([
            ej2_base_1.Property(3)
        ], PDF417Generator.prototype, "rowHeightRatio", void 0);
        __decorate([
            ej2_base_2.Complex({}, displaytext_1.DisplayText)
        ], PDF417Generator.prototype, "displayText", void 0);
        __decorate([
            ej2_base_2.Complex({}, margin_1.Margin)
        ], PDF417Generator.prototype, "margin", void 0);
        __decorate([
            ej2_base_1.Property('white')
        ], PDF417Generator.prototype, "backgroundColor", void 0);
        __decorate([
            ej2_base_1.Property('black')
        ], PDF417Generator.prototype, "foreColor", void 0);
        __decorate([
            ej2_base_2.Event()
        ], PDF417Generator.prototype, "invalid", void 0);
        return PDF417Generator;
    }(ej2_base_1.Component));
    exports.PDF417Generator = PDF417Generator;
});