UNPKG

@lxlib/seed

Version:

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.

397 lines (389 loc) 11.3 kB
import { Injectable, ɵɵdefineInjectable, ɵɵinject, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, Input, Output, NgModule } from '@angular/core'; import { __assign, __decorate, __metadata, __spread } from 'tslib'; import { InputNumber, LxlibUtilModule } from '@lxlib/util'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: qr.config.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var QRConfig = /** @class */ (function () { function QRConfig() { /** * 背景,默认:`white` */ this.background = 'white'; /** * 背景透明级别,范围:`0-1` 之间,默认:`1.0` */ this.backgroundAlpha = 1; /** * 前景,默认:`black` */ this.foreground = 'black'; /** * 前景透明级别,范围:`0-1` 之间,默认:`1.0` */ this.foregroundAlpha = 1; /** * 误差校正级别,默认:`L` */ this.level = 'L'; /** * 二维码输出图片MIME类型,默认:`image/png` */ this.mime = 'image/png'; /** * 内边距(单位:px),默认:`10` */ this.padding = 10; /** * 大小(单位:px),默认:`220` */ this.size = 220; } QRConfig.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ QRConfig.ɵprov = ɵɵdefineInjectable({ factory: function QRConfig_Factory() { return new QRConfig(); }, token: QRConfig, providedIn: "root" }); return QRConfig; }()); if (false) { /** * 背景,默认:`white` * @type {?} */ QRConfig.prototype.background; /** * 背景透明级别,范围:`0-1` 之间,默认:`1.0` * @type {?} */ QRConfig.prototype.backgroundAlpha; /** * 前景,默认:`black` * @type {?} */ QRConfig.prototype.foreground; /** * 前景透明级别,范围:`0-1` 之间,默认:`1.0` * @type {?} */ QRConfig.prototype.foregroundAlpha; /** * 误差校正级别,默认:`L` * @type {?} */ QRConfig.prototype.level; /** * 二维码输出图片MIME类型,默认:`image/png` * @type {?} */ QRConfig.prototype.mime; /** * 内边距(单位:px),默认:`10` * @type {?} */ QRConfig.prototype.padding; /** * 大小(单位:px),默认:`220` * @type {?} */ QRConfig.prototype.size; } /** * @fileoverview added by tsickle * Generated from: qr.service.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var QRService = /** @class */ (function () { function QRService(cog) { /** * 背景透明级别,范围:`0-1` 之间 */ this.backgroundAlpha = 1; Object.assign(this, cog); this.qr = new QRious(); } /** * 生成二维码,并返回Base64编码 * * @param [value] 重新指定值 */ /** * 生成二维码,并返回Base64编码 * * @param {?=} value * @return {?} */ QRService.prototype.refresh = /** * 生成二维码,并返回Base64编码 * * @param {?=} value * @return {?} */ function (value) { /** @type {?} */ var option = typeof value === 'object' ? value : { background: this.background, backgroundAlpha: this.backgroundAlpha, foreground: this.foreground, foregroundAlpha: this.foregroundAlpha, level: this.level, padding: this.padding, size: this.size, value: value || this.value, }; option.value = this.toUtf8ByteArray(option.value); this.qr.set(option); return this.dataURL; }; /** * @private * @param {?} str * @return {?} */ QRService.prototype.toUtf8ByteArray = /** * @private * @param {?} str * @return {?} */ function (str) { str = encodeURI(str); /** @type {?} */ var result = []; for (var 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 {?} */ function (v) { return String.fromCharCode(v); })).join(''); }; Object.defineProperty(QRService.prototype, "dataURL", { /** * 返回当前二维码Base64编码 */ get: /** * 返回当前二维码Base64编码 * @return {?} */ function () { return this.qr.toDataURL(); }, enumerable: true, configurable: true }); QRService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ QRService.ctorParameters = function () { return [ { type: QRConfig } ]; }; /** @nocollapse */ QRService.ɵprov = ɵɵdefineInjectable({ factory: function QRService_Factory() { return new QRService(ɵɵinject(QRConfig)); }, token: QRService, providedIn: "root" }); return QRService; }()); if (false) { /** * 当前qr实例 * @type {?} */ QRService.prototype.qr; /** * 背景 * @type {?} */ QRService.prototype.background; /** * 背景透明级别,范围:`0-1` 之间 * @type {?} */ QRService.prototype.backgroundAlpha; /** * 前景 * @type {?} */ QRService.prototype.foreground; /** * 前景透明级别,范围:`0-1` 之间 * @type {?} */ QRService.prototype.foregroundAlpha; /** * 误差校正级别 * @type {?} */ QRService.prototype.level; /** * 二维码输出图片MIME类型 * @type {?} */ QRService.prototype.mime; /** * 内边距(单位:px) * @type {?} */ QRService.prototype.padding; /** * 大小(单位:px) * @type {?} */ QRService.prototype.size; /** * 值 * @type {?} */ QRService.prototype.value; } /** * @fileoverview added by tsickle * Generated from: qr.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var QRComponent = /** @class */ (function () { // #endregion function QRComponent(cog, srv, cdr) { this.srv = srv; this.cdr = cdr; // tslint:disable-next-line:no-output-native this.change = new EventEmitter(); Object.assign(this, __assign(__assign({}, new QRConfig()), cog)); } /** * @return {?} */ QRComponent.prototype.ngOnChanges = /** * @return {?} */ function () { this.dataURL = this.srv.refresh({ 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.value, }); this.cdr.detectChanges(); this.change.emit(this.dataURL); }; QRComponent.decorators = [ { type: Component, args: [{ selector: 'qr', exportAs: 'qr', template: " <img class=\"qr__img\" src=\"{{ dataURL }}\" /> ", host: { '[class.qr]': 'true', '[style.height.px]': 'size', '[style.width.px]': 'size', }, preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }] } ]; /** @nocollapse */ QRComponent.ctorParameters = function () { return [ { type: QRConfig }, { type: QRService }, { type: ChangeDetectorRef } ]; }; 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 }], 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); return QRComponent; }()); if (false) { /** @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.change; /** * @type {?} * @private */ QRComponent.prototype.srv; /** * @type {?} * @private */ QRComponent.prototype.cdr; } /** * @fileoverview added by tsickle * Generated from: qr.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var COMPONENTS = [QRComponent]; var QRModule = /** @class */ (function () { function QRModule() { } QRModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, LxlibUtilModule], declarations: __spread(COMPONENTS), exports: __spread(COMPONENTS), },] } ]; return QRModule; }()); /** * @fileoverview added by tsickle * Generated from: public_api.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * Generated from: qr.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { QRComponent, QRConfig, QRModule, QRService }; //# sourceMappingURL=qr.js.map