all files / qrcode/ qrcode.js

98.57% Statements 138/140
97.75% Branches 87/89
95.83% Functions 23/24
98.51% Lines 132/134
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 211              503× 503× 503× 503×   503× 503× 503× 503× 503×         509× 509× 509× 509× 509× 509× 509× 509× 509× 509×   509×   509×     503×   1016× 1016× 1010×       1016×   506× 506× 506× 506×         506×   503× 503× 503× 503× 503×         2515×   503× 503× 503× 503× 503×     503×                     13× 13×                                                                        
/* 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", "../barcode/utility/barcode-util", "@syncfusion/ej2-base", "../barcode/enum/enum", "../barcode/primitives/displaytext", "../barcode/primitives/margin", "../barcode/rendering/renderer", "./qr-code-util", "../barcode/primitives/icon"], function (require, exports, barcode_util_1, ej2_base_1, enum_1, displaytext_1, margin_1, renderer_1, qr_code_util_1, icon_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var QRCodeGenerator = (function (_super) {
        __extends(QRCodeGenerator, _super);
        function QRCodeGenerator(options, element) {
            var _this = _super.call(this, options, element) || this;
            _this.widthChange = false;
            _this.heightChange = false;
            return _this;
        }
        QRCodeGenerator.prototype.render = function () {
            this.notify('initial-load', {});
            this.trigger('load');
            this.notify('initial-end', {});
            this.renderElements();
            this.renderComplete();
        };
        QRCodeGenerator.prototype.triggerEvent = function (eventName, message) {
            var arg = {
                message: message
            };
            this.trigger(enum_1.BarcodeEvent["" + eventName], arg);
        };
        QRCodeGenerator.prototype.renderElements = function () {
            var barCode = new qr_code_util_1.QRCode();
            barCode.text = this.value;
            barCode.XDimension = this.xDimension;
            barCode.mIsUserMentionedErrorCorrectionLevel = (this.errorCorrectionLevel !== undefined) ? true : false;
            barCode.mErrorCorrectionLevel = (this.errorCorrectionLevel !== undefined) ? this.errorCorrectionLevel : enum_1.ErrorCorrectionLevel.Medium;
            barCode.version = (this.version !== undefined) ? this.version : undefined;
            barCode.mIsUserMentionedVersion = (this.version !== undefined) ? true : false;
            var mode = (this.mode === 'SVG') ? true : false;
            var validInput = barCode.draw(this.value, this.barcodeCanvas, this.element.offsetHeight, this.element.offsetWidth, this.margin, this.displayText, mode, this.foreColor, this.logo);
            if (this.mode === 'Canvas') {
                this.barcodeCanvas.getContext('2d').setTransform(1, 0, 0, 1, 0, 0);
                this.barcodeCanvas.getContext('2d').scale(1.5, 1.5);
            }
            if (!validInput) {
                var encoding = 'Invalid Input';
                this.triggerEvent(enum_1.BarcodeEvent.invalid, encoding);
            }
            if (this.mode === 'Canvas') {
                this.barcodeCanvas.style.transform = 'scale(' + (2 / 3) + ')';
                this.barcodeCanvas.style.transformOrigin = '0 0';
            }
        };
        QRCodeGenerator.prototype.setCulture = function () {
            this.localeObj = new ej2_base_1.L10n(this.getModuleName(), this.defaultLocale, this.locale);
        };
        QRCodeGenerator.prototype.getElementSize = function (real, rulerSize) {
            var value;
            if (real.toString().indexOf('px') > 0 || real.toString().indexOf('%') > 0) {
                value = real.toString();
            }
            else {
                value = real.toString() + 'px';
            }
            return value;
        };
        QRCodeGenerator.prototype.initialize = function () {
            this.element.style.display = 'block';
            this.element.style.height = this.getElementSize(this.height);
            this.element.style.width = this.getElementSize(this.width);
            this.barcodeCanvas = this.barcodeRenderer.renderRootElement({
                id: this.element.id + 'content',
                height: this.mode === 'SVG' ? this.element.offsetHeight : this.element.offsetHeight * 1.5,
                width: this.mode === 'SVG' ? this.element.offsetWidth : this.element.offsetWidth * 1.5
            }, this.backgroundColor, this.element.offsetWidth, this.element.offsetHeight);
            this.element.appendChild(this.barcodeCanvas);
        };
        QRCodeGenerator.prototype.preRender = function () {
            this.element.classList.add('e-qrcode');
            this.barcodeRenderer = new renderer_1.BarcodeRenderer(this.element.id, this.mode === 'SVG');
            this.initialize();
            this.initializePrivateVariables();
            this.setCulture();
        };
        QRCodeGenerator.prototype.getPersistData = function () {
            var keyEntity = ['loaded'];
            return this.addOnPersist(keyEntity);
        };
        QRCodeGenerator.prototype.getModuleName = function () {
            return 'QRCodeGenerator';
        };
        QRCodeGenerator.prototype.destroy = function () {
            this.notify('destroy', {});
            _super.prototype.destroy.call(this);
            var content = document.getElementById(this.element.id + 'content');
            Eif (content) {
                this.element.removeChild(content);
            }
        };
        QRCodeGenerator.prototype.initializePrivateVariables = function () {
            this.defaultLocale = {};
        };
        QRCodeGenerator.prototype.exportImage = function (filename, barcodeExportType) {
            barcode_util_1.exportAsImage(barcodeExportType, filename, this.element, false, this);
        };
        QRCodeGenerator.prototype.exportAsBase64Image = function (barcodeExportType) {
            var returnValue = barcode_util_1.exportAsImage(barcodeExportType, '', this.element, true, this);
            return returnValue;
        };
        QRCodeGenerator.prototype.onPropertyChanged = function (newProp, oldProp) {
            var width;
            var height;
            if (this.mode === 'Canvas' && newProp.mode !== 'Canvas') {
                barcode_util_1.refreshCanvasBarcode(this, this.barcodeCanvas);
            }
            else {
                this.barcodeRenderer = barcode_util_1.removeChildElements(newProp, this.barcodeCanvas, this.mode, this.element.id);
            }
            if (newProp.width) {
                if (this.mode === 'Canvas' && newProp.mode !== 'Canvas') {
                    this.widthChange = true;
                }
                width = (this.mode === 'Canvas' && newProp.mode !== 'Canvas') ? ((newProp.width * 1.5)) : newProp.width;
                this.barcodeCanvas.setAttribute('width', String(width));
            }
            if (newProp.height) {
                if (this.mode === 'Canvas' && newProp.mode !== 'Canvas') {
                    this.heightChange = true;
                }
                height = (this.mode === 'Canvas' && newProp.mode !== 'Canvas') ? ((newProp.height * 1.5)) : newProp.height;
                this.barcodeCanvas.setAttribute('height', String(height));
            }
            for (var _i = 0, _a = Object.keys(newProp); _i < _a.length; _i++) {
                var prop = _a[_i];
                switch (prop) {
                    case 'width':
                        this.element.style.width = this.getElementSize(width);
                        this.barcodeCanvas.setAttribute('width', String(this.element.offsetWidth));
                        break;
                    case 'height':
                        this.element.style.height = this.getElementSize(height);
                        this.barcodeCanvas.setAttribute('height', String(this.element.offsetHeight));
                        break;
                    case 'backgroundColor':
                        this.barcodeCanvas.setAttribute('style', 'background:' + newProp.backgroundColor);
                        break;
                    case 'mode':
                        this.initialize();
                }
            }
            this.renderElements();
        };
        __decorate([
            ej2_base_1.Property('100%')
        ], QRCodeGenerator.prototype, "height", void 0);
        __decorate([
            ej2_base_1.Complex({}, icon_1.QRCodeLogo)
        ], QRCodeGenerator.prototype, "logo", void 0);
        __decorate([
            ej2_base_1.Property('100%')
        ], QRCodeGenerator.prototype, "width", void 0);
        __decorate([
            ej2_base_1.Property('SVG')
        ], QRCodeGenerator.prototype, "mode", void 0);
        __decorate([
            ej2_base_1.Property(1)
        ], QRCodeGenerator.prototype, "xDimension", void 0);
        __decorate([
            ej2_base_1.Property()
        ], QRCodeGenerator.prototype, "errorCorrectionLevel", void 0);
        __decorate([
            ej2_base_1.Complex({}, margin_1.Margin)
        ], QRCodeGenerator.prototype, "margin", void 0);
        __decorate([
            ej2_base_1.Property('white')
        ], QRCodeGenerator.prototype, "backgroundColor", void 0);
        __decorate([
            ej2_base_1.Event()
        ], QRCodeGenerator.prototype, "invalid", void 0);
        __decorate([
            ej2_base_1.Property('black')
        ], QRCodeGenerator.prototype, "foreColor", void 0);
        __decorate([
            ej2_base_1.Complex({}, displaytext_1.DisplayText)
        ], QRCodeGenerator.prototype, "displayText", void 0);
        __decorate([
            ej2_base_1.Property()
        ], QRCodeGenerator.prototype, "version", void 0);
        __decorate([
            ej2_base_1.Property(undefined)
        ], QRCodeGenerator.prototype, "value", void 0);
        return QRCodeGenerator;
    }(ej2_base_1.Component));
    exports.QRCodeGenerator = QRCodeGenerator;
});