UNPKG

@lxlib/seed

Version:

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

190 lines (183 loc) 5.15 kB
import { __decorate, __metadata } from 'tslib'; import { Injectable, ɵɵdefineInjectable, Directive, ElementRef, Input, NgModule } from '@angular/core'; import { InputNumber, LxlibUtilModule } from '@lxlib/util'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: image.config.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class ImageConfig { constructor() { /** * 默认大小,默认值:`64`,单位:px */ this.size = 64; /** * 错误图片 */ this.error = './assets/img/logo.svg'; } } ImageConfig.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ ImageConfig.ɵprov = ɵɵdefineInjectable({ factory: function ImageConfig_Factory() { return new ImageConfig(); }, token: ImageConfig, providedIn: "root" }); if (false) { /** * 默认大小,默认值:`64`,单位:px * @type {?} */ ImageConfig.prototype.size; /** * 错误图片 * @type {?} */ ImageConfig.prototype.error; } /** * @fileoverview added by tsickle * Generated from: image.directive.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * img标签 * + 支持微信、qq头像规则缩略图规则 * + 支持移除http&https协议http * + 支持增加onerror事件 */ class ImageDirective { /** * @param {?} cog * @param {?} el */ constructor(cog, el) { this.size = 64; this.error = './assets/img/logo.svg'; this.inited = false; Object.assign(this, Object.assign(Object.assign({}, new ImageConfig()), cog)); this.imgEl = el.nativeElement; } /** * @return {?} */ ngOnInit() { this.update(); this.updateError(); this.inited = true; } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { if (!this.inited) return; if (changes.error) { this.updateError(); } this.update(); } /** * @private * @return {?} */ update() { /** @type {?} */ let newSrc = this.src; const { size, imgEl } = this; if (newSrc.includes('qlogo.cn')) { /** @type {?} */ const arr = newSrc.split('/'); /** @type {?} */ const imgSize = arr[arr.length - 1]; arr[arr.length - 1] = imgSize === '0' || +imgSize !== size ? size.toString() : imgSize; newSrc = arr.join('/'); } newSrc = newSrc.replace(/^(?:https?:)/i, ''); imgEl.src = newSrc; imgEl.height = size; imgEl.width = size; } /** * @private * @return {?} */ updateError() { const { imgEl, error } = this; // tslint:disable-next-line: only-arrow-functions imgEl.onerror = (/** * @return {?} */ function () { this.onerror = null; this.src = error; }); } } ImageDirective.decorators = [ { type: Directive, args: [{ selector: '[_src]', exportAs: '_src', },] } ]; /** @nocollapse */ ImageDirective.ctorParameters = () => [ { type: ImageConfig }, { type: ElementRef } ]; ImageDirective.propDecorators = { src: [{ type: Input, args: ['_src',] }], size: [{ type: Input }], error: [{ type: Input }] }; __decorate([ InputNumber(), __metadata("design:type", Object) ], ImageDirective.prototype, "size", void 0); if (false) { /** @type {?} */ ImageDirective.prototype.src; /** @type {?} */ ImageDirective.prototype.size; /** @type {?} */ ImageDirective.prototype.error; /** * @type {?} * @private */ ImageDirective.prototype.inited; /** * @type {?} * @private */ ImageDirective.prototype.imgEl; } /** * @fileoverview added by tsickle * Generated from: image.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const DIRECTIVES = [ImageDirective]; class ImageModule { } ImageModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, LxlibUtilModule], declarations: [...DIRECTIVES], exports: [...DIRECTIVES], },] } ]; /** * @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: image.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { ImageConfig, ImageDirective, ImageModule }; //# sourceMappingURL=image.js.map