@lxlib/seed
Version:
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.
373 lines (365 loc) • 10.2 kB
JavaScript
import { Injectable, ɵɵdefineInjectable, ɵɵinject, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, Input, Output, NgModule } from '@angular/core';
import { __decorate, __metadata } 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
*/
class QRConfig {
constructor() {
/**
* 背景,默认:`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" });
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
*/
class QRService {
/**
* @param {?} cog
*/
constructor(cog) {
/**
* 背景透明级别,范围:`0-1` 之间
*/
this.backgroundAlpha = 1;
Object.assign(this, cog);
this.qr = new QRious();
}
/**
* 生成二维码,并返回Base64编码
*
* @param {?=} value
* @return {?}
*/
refresh(value) {
/** @type {?} */
const 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 {?}
*/
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('');
}
/**
* 返回当前二维码Base64编码
* @return {?}
*/
get dataURL() {
return this.qr.toDataURL();
}
}
QRService.decorators = [
{ type: Injectable, args: [{ providedIn: 'root' },] }
];
/** @nocollapse */
QRService.ctorParameters = () => [
{ type: QRConfig }
];
/** @nocollapse */ QRService.ɵprov = ɵɵdefineInjectable({ factory: function QRService_Factory() { return new QRService(ɵɵinject(QRConfig)); }, token: QRService, providedIn: "root" });
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
*/
class QRComponent {
// #endregion
/**
* @param {?} cog
* @param {?} srv
* @param {?} cdr
*/
constructor(cog, srv, cdr) {
this.srv = srv;
this.cdr = cdr;
// tslint:disable-next-line:no-output-native
this.change = new EventEmitter();
Object.assign(this, Object.assign(Object.assign({}, new QRConfig()), cog));
}
/**
* @return {?}
*/
ngOnChanges() {
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 = () => [
{ 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);
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 {?} */
const COMPONENTS = [QRComponent];
class QRModule {
}
QRModule.decorators = [
{ type: NgModule, args: [{
imports: [CommonModule, LxlibUtilModule],
declarations: [...COMPONENTS],
exports: [...COMPONENTS],
},] }
];
/**
* @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