UNPKG

ngx-angular-qrcode

Version:

This library allow you to create beautiful QR Codes in Angular application.

296 lines (288 loc) 11.1 kB
import { __decorate, __assign } from 'tslib'; import { ɵɵdefineInjectable, Injectable, ViewChild, Input, Component, NgModule } from '@angular/core'; import QRCodeStyling from 'qr-code-styling'; var NgxAngularQrcodeService = /** @class */ (function () { function NgxAngularQrcodeService() { } NgxAngularQrcodeService.ɵprov = ɵɵdefineInjectable({ factory: function NgxAngularQrcodeService_Factory() { return new NgxAngularQrcodeService(); }, token: NgxAngularQrcodeService, providedIn: "root" }); NgxAngularQrcodeService = __decorate([ Injectable({ providedIn: 'root' }) ], NgxAngularQrcodeService); return NgxAngularQrcodeService; }()); var QrPreviewSize = { width: 124, height: 124, }; var DefaultQrConfiguration = { width: 240, height: 240, shape: 'square', type: 'canvas', data: 'draft', margin: 5, dotsOptions: { type: 'dots', color: '#000000', }, backgroundOptions: { color: '#ffffff', }, cornersSquareOptions: { type: 'square', color: '#000000', }, cornersDotOptions: { type: 'square', color: '#000000', }, // image: 'https://upload.wikimedia.org/wikipedia/commons/5/51/Facebook_f_logo_%282019%29.svg', imageOptions: { hideBackgroundDots: true, imageSize: 0.4, margin: 5, crossOrigin: 'anonymous', } }; var NgxAngularQrcodeComponent = /** @class */ (function () { function NgxAngularQrcodeComponent() { } NgxAngularQrcodeComponent.prototype.ngOnInit = function () { }; NgxAngularQrcodeComponent.prototype.ngOnChanges = function (changes) { this.displayQr(); }; NgxAngularQrcodeComponent.prototype.ngAfterContentInit = function () { console.debug('🔥 this.qrData', this.qrData); this.displayQr(); }; NgxAngularQrcodeComponent.prototype.displayQr = function () { var _a, _b, _c, _d, _e, _f, _g; if (!QRCodeStyling) { return; } this.qrCodeCanvas.nativeElement.innerHTML = ''; var dotsGradient = { type: this.dotsGradientType, rotation: this.dotsGradientRotation, colorStops: [ { offset: 0, color: this.dotsStartColor }, { offset: 1, color: this.dotsEndColor } ] }; var cornerSquareGradient = { type: this.cornerSquareGradientType, rotation: this.cornerSquareGradientRotation, colorStops: [ { offset: 0, color: this.cornerSquareStartColor }, { offset: 1, color: this.cornerSquareEndColor } ] }; var backgroundGradient = { type: this.backgroundGradientType, rotation: this.backgroundGradientRotation, colorStops: [ { offset: 0, color: this.backgroundStartColor }, { offset: 1, color: this.backgroundEndColor } ] }; var cornerDotGradient = { type: this.cornerDotGradientType, rotation: this.cornerDotGradientRotation, colorStops: [ { offset: 0, color: this.cornerDotStartColor }, { offset: 1, color: this.cornerDotEndColor } ] }; var config = __assign(__assign({}, DefaultQrConfiguration), { shape: this.shape, width: this.width || QrPreviewSize.width, height: this.height || QrPreviewSize.height, margin: this.margin || DefaultQrConfiguration.margin, data: this.qrData || 'https://qrtrac.com', image: this.imageUrl, dotsOptions: __assign({ type: this.dotsType || ((_a = DefaultQrConfiguration.dotsOptions) === null || _a === void 0 ? void 0 : _a.type), color: this.dotsColor }, (this.dotsGradient && { gradient: dotsGradient })), cornersSquareOptions: __assign({ type: this.cornerSquareType || ((_b = DefaultQrConfiguration.cornersSquareOptions) === null || _b === void 0 ? void 0 : _b.type), color: this.cornerSquareColor }, (this.cornerSquareGradient && { gradient: cornerSquareGradient })), cornersDotOptions: __assign({ type: this.cornerDotType || ((_c = DefaultQrConfiguration.cornersDotOptions) === null || _c === void 0 ? void 0 : _c.type), color: this.cornerDotColor }, (this.cornerDotGradient && { gradient: cornerDotGradient })), backgroundOptions: __assign({ color: this.backgroundColor }, (this.backgroundGradient && { gradient: backgroundGradient })), imageOptions: { imageSize: this.imageSize || ((_d = DefaultQrConfiguration.imageOptions) === null || _d === void 0 ? void 0 : _d.imageSize), margin: this.imageMargin || ((_e = DefaultQrConfiguration.imageOptions) === null || _e === void 0 ? void 0 : _e.margin), hideBackgroundDots: this.hideImageBackgroundDots || ((_f = DefaultQrConfiguration.imageOptions) === null || _f === void 0 ? void 0 : _f.hideBackgroundDots) }, qrOptions: { errorCorrectionLevel: this.errorCorrectionLevel || ((_g = DefaultQrConfiguration.qrOptions) === null || _g === void 0 ? void 0 : _g.errorCorrectionLevel) } }); this.qrCodeStyle = new QRCodeStyling(config); this.qrCodeStyle.append(this.qrCodeCanvas.nativeElement); }; NgxAngularQrcodeComponent.prototype.download = function (fileExtension, qrName) { console.debug('🔥 download called'); this.qrCodeStyle.download({ name: qrName || 'ngxs-qrcode', extension: fileExtension }); }; __decorate([ ViewChild('qrCodeCanvas', { static: true }) ], NgxAngularQrcodeComponent.prototype, "qrCodeCanvas", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "qrData", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "imageUrl", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "shape", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "width", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "height", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "margin", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "dotsType", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "dotsGradient", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "dotsGradientType", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "dotsGradientRotation", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "dotsColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "dotsStartColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "dotsEndColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerSquareType", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerSquareGradient", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerSquareGradientType", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerSquareGradientRotation", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerSquareColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerSquareStartColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerSquareEndColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerDotType", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerDotGradient", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerDotGradientType", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerDotGradientRotation", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerDotColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerDotStartColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "cornerDotEndColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "backgroundType", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "backgroundGradient", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "backgroundGradientType", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "backgroundGradientRotation", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "backgroundColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "backgroundStartColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "backgroundEndColor", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "imageSize", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "imageMargin", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "hideImageBackgroundDots", void 0); __decorate([ Input() ], NgxAngularQrcodeComponent.prototype, "errorCorrectionLevel", void 0); NgxAngularQrcodeComponent = __decorate([ Component({ selector: 'qr-code', template: "\n <div #qrCodeCanvas></div> \n " }) ], NgxAngularQrcodeComponent); return NgxAngularQrcodeComponent; }()); var NgxAngularQrcodeModule = /** @class */ (function () { function NgxAngularQrcodeModule() { } NgxAngularQrcodeModule = __decorate([ NgModule({ declarations: [ NgxAngularQrcodeComponent ], imports: [], exports: [ NgxAngularQrcodeComponent ] }) ], NgxAngularQrcodeModule); return NgxAngularQrcodeModule; }()); /* * Public API Surface of ngx-angular-qrcode */ /** * Generated bundle index. Do not edit. */ export { NgxAngularQrcodeComponent, NgxAngularQrcodeModule, NgxAngularQrcodeService }; //# sourceMappingURL=ngx-angular-qrcode.js.map