UNPKG

@ohayojp.com/components

Version:

Common business components of ohayojp.

324 lines (316 loc) 9.05 kB
import { __decorate, __metadata } from 'tslib'; import { Platform } from '@angular/cdk/platform'; import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, Input, Output, NgModule } from '@angular/core'; import { OhayoConfigService, LazyService, InputNumber, OhayoUtilModule } from '@ohayojp.com/util'; import { filter } from 'rxjs/operators'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: qr.config.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const QR_DEFULAT_CONFIG = { lib: `https://cdn.bootcdn.net/ajax/libs/qrious/4.0.2/qrious.min.js`, background: 'white', backgroundAlpha: 1, foreground: 'black', foregroundAlpha: 1, level: 'L', mime: 'image/png', padding: 10, size: 220, delay: 0, }; /** * @fileoverview added by tsickle * Generated from: qr.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class QRComponent { // #endregion /** * @param {?} cdr * @param {?} configSrv * @param {?} lazySrv * @param {?} platform */ constructor(cdr, configSrv, lazySrv, platform) { this.cdr = cdr; this.lazySrv = lazySrv; this.platform = platform; this.inited = false; this.value = ''; // tslint:disable-next-line:no-output-native this.change = new EventEmitter(); this.cog = (/** @type {?} */ (configSrv.merge('qr', QR_DEFULAT_CONFIG))); Object.assign(this, this.cog); } /** * @private * @return {?} */ init() { if (!this.inited) { return; } if (this.qr == null) { this.qr = new ((/** @type {?} */ (window))).QRious(); } this.qr.set(this.option); this.dataURL = this.qr.toDataURL(); this.change.emit(this.dataURL); this.cdr.detectChanges(); } /** * @private * @return {?} */ initDelay() { this.inited = true; setTimeout((/** * @return {?} */ () => this.init()), this.delay); } /** * @return {?} */ ngAfterViewInit() { if (!this.platform.isBrowser) { return; } if (((/** @type {?} */ (window))).QRious) { this.initDelay(); return; } /** @type {?} */ const url = (/** @type {?} */ (this.cog.lib)); this.lazy$ = this.lazySrv.change .pipe(filter((/** * @param {?} ls * @return {?} */ ls => ls.length === 1 && ls[0].path === url && ls[0].status === 'ok'))) .subscribe((/** * @return {?} */ () => this.initDelay())); this.lazySrv.load(url); } /** * @return {?} */ ngOnChanges() { /** @type {?} */ const option = { background: this.background, backgroundAlpha: this.backgroundAlpha, foreground: this.foreground, foregroundAlpha: this.foregroundAlpha, level: this.level, mime: this.mime, padding: this.padding, size: this.size, value: this.toUtf8ByteArray(this.value), }; this.option = option; this.init(); } /** * @private * @param {?} str * @return {?} */ toUtf8ByteArray(str) { str = encodeURI(str); /** @type {?} */ const result = []; for (let i = 0; i < str.length; i++) { if (str.charAt(i) !== '%') { result.push(str.charCodeAt(i)); } else { result.push(parseInt(str.substr(i + 1, 2), 16)); i += 2; } } return result.map((/** * @param {?} v * @return {?} */ v => String.fromCharCode(v))).join(''); } /** * @return {?} */ ngOnDestroy() { if (this.lazy$) { this.lazy$.unsubscribe(); } } } QRComponent.decorators = [ { type: Component, args: [{ selector: 'qr', exportAs: 'qr', template: ` <img *ngIf="dataURL" style="max-width: 100%; max-height: 100%;" [src]="dataURL" /> `, host: { '[style.display]': `'inline-block'`, '[style.height.px]': 'size', '[style.width.px]': 'size', }, preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }] } ]; /** @nocollapse */ QRComponent.ctorParameters = () => [ { type: ChangeDetectorRef }, { type: OhayoConfigService }, { type: LazyService }, { type: Platform } ]; QRComponent.propDecorators = { background: [{ type: Input }], backgroundAlpha: [{ type: Input }], foreground: [{ type: Input }], foregroundAlpha: [{ type: Input }], level: [{ type: Input }], mime: [{ type: Input }], padding: [{ type: Input }], size: [{ type: Input }], value: [{ type: Input }], delay: [{ type: Input }], change: [{ type: Output }] }; __decorate([ InputNumber(), __metadata("design:type", Number) ], QRComponent.prototype, "padding", void 0); __decorate([ InputNumber(), __metadata("design:type", Number) ], QRComponent.prototype, "size", void 0); __decorate([ InputNumber(), __metadata("design:type", Number) ], QRComponent.prototype, "delay", void 0); if (false) { /** @type {?} */ QRComponent.ngAcceptInputType_padding; /** @type {?} */ QRComponent.ngAcceptInputType_size; /** @type {?} */ QRComponent.ngAcceptInputType_delay; /** * @type {?} * @private */ QRComponent.prototype.lazy$; /** * @type {?} * @private */ QRComponent.prototype.qr; /** * @type {?} * @private */ QRComponent.prototype.cog; /** * @type {?} * @private */ QRComponent.prototype.option; /** * @type {?} * @private */ QRComponent.prototype.inited; /** @type {?} */ QRComponent.prototype.dataURL; /** @type {?} */ QRComponent.prototype.background; /** @type {?} */ QRComponent.prototype.backgroundAlpha; /** @type {?} */ QRComponent.prototype.foreground; /** @type {?} */ QRComponent.prototype.foregroundAlpha; /** @type {?} */ QRComponent.prototype.level; /** @type {?} */ QRComponent.prototype.mime; /** @type {?} */ QRComponent.prototype.padding; /** @type {?} */ QRComponent.prototype.size; /** @type {?} */ QRComponent.prototype.value; /** @type {?} */ QRComponent.prototype.delay; /** @type {?} */ QRComponent.prototype.change; /** * @type {?} * @private */ QRComponent.prototype.cdr; /** * @type {?} * @private */ QRComponent.prototype.lazySrv; /** * @type {?} * @private */ QRComponent.prototype.platform; } /** * @fileoverview added by tsickle * Generated from: qr.types.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function QROptions() { } if (false) { /** @type {?} */ QROptions.prototype.value; } /** * @fileoverview added by tsickle * Generated from: qr.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const COMPONENTS = [QRComponent]; class QRModule { } QRModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, OhayoUtilModule], declarations: [...COMPONENTS], exports: [...COMPONENTS], },] } ]; /** * @fileoverview added by tsickle * Generated from: public_api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * Generated from: qr.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { QRComponent, QRModule, QR_DEFULAT_CONFIG }; //# sourceMappingURL=qr.js.map