@jvereecken/ngx-qr-scanner
Version:
Angular wrapper for the qr-scanner library
125 lines (119 loc) • 5.49 kB
JavaScript
import * as i0 from '@angular/core';
import { EventEmitter, Component, Output, Input, ViewChild, NgModule } from '@angular/core';
import QrScanner from 'qr-scanner';
class NgxQrScannerComponent {
constructor(zone) {
this.zone = zone;
this.decode = new EventEmitter();
this.decodeError = new EventEmitter();
this.ready = new EventEmitter();
this.preferredCamera = "environment";
this.maxScansPerSecond = 1;
this.highlightScanRegion = true;
this.highlightCodeOutline = true;
}
ngAfterViewInit() {
var _a;
if (this.videoFeed) {
this._qrScanner = new QrScanner(this.videoFeed.nativeElement, result => {
this.zone.run(() => {
this.decode.emit(result);
});
}, {
onDecodeError: error => {
this.zone.run(() => {
this.decodeError.emit(error);
});
},
preferredCamera: (_a = this.deviceId) !== null && _a !== void 0 ? _a : this.preferredCamera,
maxScansPerSecond: this.maxScansPerSecond,
returnDetailedScanResult: true,
highlightScanRegion: this.highlightScanRegion,
highlightCodeOutline: this.highlightCodeOutline,
calculateScanRegion: this.calculateScanRegion,
overlay: this.overlay,
});
this._qrScanner.start();
this.ready.emit();
}
else {
console.error('something went wrong');
}
}
ngOnChanges(changes) {
var _a;
if (changes['deviceId']) {
const change = changes['deviceId'];
(_a = this._qrScanner) === null || _a === void 0 ? void 0 : _a.setCamera(change.currentValue);
}
}
ngOnDestroy() {
var _a;
(_a = this._qrScanner) === null || _a === void 0 ? void 0 : _a.destroy();
this._qrScanner = undefined;
}
}
NgxQrScannerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: NgxQrScannerComponent, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
NgxQrScannerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: NgxQrScannerComponent, selector: "ngx-qr-scanner", inputs: { preferredCamera: "preferredCamera", maxScansPerSecond: "maxScansPerSecond", deviceId: "deviceId", highlightScanRegion: "highlightScanRegion", highlightCodeOutline: "highlightCodeOutline", calculateScanRegion: "calculateScanRegion", overlay: "overlay" }, outputs: { decode: "decode", decodeError: "decodeError", ready: "ready" }, viewQueries: [{ propertyName: "videoFeed", first: true, predicate: ["videoFeed"], descendants: true }], usesOnChanges: true, ngImport: i0, template: `
<video #videoFeed></video>
`, isInline: true, styles: ["video{width:100%;height:100%}\n"] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: NgxQrScannerComponent, decorators: [{
type: Component,
args: [{
selector: 'ngx-qr-scanner',
template: `
<video #videoFeed></video>
`,
styles: [
`
video {
width: 100%;
height: 100%;
}
`
]
}]
}], ctorParameters: function () { return [{ type: i0.NgZone }]; }, propDecorators: { decode: [{
type: Output
}], decodeError: [{
type: Output
}], ready: [{
type: Output
}], preferredCamera: [{
type: Input
}], maxScansPerSecond: [{
type: Input
}], deviceId: [{
type: Input
}], highlightScanRegion: [{
type: Input
}], highlightCodeOutline: [{
type: Input
}], calculateScanRegion: [{
type: Input
}], overlay: [{
type: Input
}], videoFeed: [{
type: ViewChild,
args: ['videoFeed']
}] } });
class NgxQrScannerModule {
}
NgxQrScannerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: NgxQrScannerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
NgxQrScannerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: NgxQrScannerModule, declarations: [NgxQrScannerComponent], exports: [NgxQrScannerComponent] });
NgxQrScannerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: NgxQrScannerModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: NgxQrScannerModule, decorators: [{
type: NgModule,
args: [{
declarations: [NgxQrScannerComponent],
exports: [NgxQrScannerComponent]
}]
}] });
/*
* Public API Surface of ngx-qr-scanner
*/
/**
* Generated bundle index. Do not edit.
*/
export { NgxQrScannerComponent, NgxQrScannerModule };
//# sourceMappingURL=jvereecken-ngx-qr-scanner.mjs.map