mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
1 line
22 KiB
JSON
1 line
22 KiB
JSON
|
|
{"ast":null,"code":"import { __decorate } from 'tslib';\nimport { Input, Component, NgModule } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport * as ɵngcc0 from '@angular/core';\nlet LettersAvatarComponent = class LettersAvatarComponent {\n constructor() {\n this.avatarName = \"\";\n this.className = \"\";\n this.fontFamily = \"arial\";\n this.circular = false;\n }\n ngOnInit() {\n if (!this.width && !this.height) this.width = 60;\n }\n ngAfterViewInit() {\n this.drawAvatar();\n }\n drawAvatar() {\n let image = document.getElementById(\"avatar-img\"),\n name = this.avatarName;\n image.id = this.id ? this.id : this.avatarName.replace(/\\s/g, \"\") + \"Avatar\";\n image.setAttribute('alt', `${name} avatar`);\n image.setAttribute('width', `${this.width ? this.width : this.height}px`);\n image.setAttribute('height', `${this.height ? this.height : this.width}px`);\n image.setAttribute('class', this.className);\n if (this.circular) image.style.borderRadius = \"50%\";\n if (this.borderRadius) image.style.borderRadius = `${this.borderRadius}px`;\n if (this.src) image.setAttribute('src', this.src);else image.setAttribute('src', this.createCanvasURI(name));\n }\n createCanvasURI(name = \"\") {\n let colours = [\"#1abc9c\", \"#2ecc71\", \"#3498db\", \"#9b59b6\", \"#34495e\", \"#f7ca18\", \"#f15a22\", \"#1ba39c\", \"#2abb9b\", \"#1f3a93\", \"#96281b\", \"#e67e22\", \"#e74c3c\", \"#ecf0f1\", \"#95a5a6\", \"#f39c12\", \"#d35400\", \"#c0392b\", \"#22a7f0\", \"#2c3e50\"],\n nameSplit = String(name).toUpperCase().split(' '),\n size = this.width,\n initials,\n charIndex,\n colourIndex,\n canvas,\n context,\n dataURI;\n if (nameSplit.length < 2) initials = nameSplit[0] ? nameSplit[0].charAt(0) : '?';else initials = nameSplit[0].charAt(0) + nameSplit[1].charAt(0);\n if (window.devicePixelRatio) size = size * window.devicePixelRatio;\n charIndex = (initials == '?' ? 72 : initials.charCodeAt(0)) - 64;\n colourIndex = charIndex % 20;\n canvas = document.createElement('canvas');\n canvas.width = size;\n canvas.height = size;\n context = canvas.getContext(\"2d\");\n context.fillStyle = colours[colourIndex - 1];\n context.fillRect(0, 0, canvas.width, canvas.height);\n context.font = `${Math.round(canvas.width / 2.7)}px ${this.fontFamily}`;\n context.textAlign = \"center\";\n context.fillStyle = \"#FFF\";\n context.textBaseline = \"middle\";\n initials = initials.split(\"\").join(String.fromCharCode(8202));\n context.fillText(initials, size / 2, size / 1.85);\n dataURI = canvas.toDataURL();\n canvas = null;\n return dataURI;\n }\n};\nLettersAvatarComponent.ɵfac = function LettersAvatarComponent_Factory(t) {\n return new (t || LettersAvatarComponent)();\n};\nLettersAvatarComponent.ɵcmp = /*@__PURE__*/ɵngcc0.ɵɵdefineComponent({\n type: LettersAvatarComponent,\n selectors: [[\"ngx-letters-avatar\"]],\n inputs: {\n avatarName: \"avatarName\",\n className: \"className\",\n fontFamily: \"fontFamily\",\n circular: \"circular\",\n width: \"width\",\n height: \"height\",\n src: \"src\",\n borderRadius: \"borderRadius\",\n id: \"id\"\n },\n decls: 1,\n vars: 0,\n consts: [[\"id\", \"avatar-img\"]],\n template: function LettersAvatarComponent_Template(rf, ctx) {\n if (rf & 1) {\n ɵngcc0.ɵɵelement(0, \"img\", 0);\n }\n },\n styles: [\"[_nghost-%COMP%]{display:inline-flex}\"]\n});\n__decorate([Input('width')], LettersAvatarComponent.prototype, \"width\", void 0);\n__decorate([Input('height')], LettersAvatarComponent.prototype, \"height\", void 0);\n__decorate([Input('avatarName')], LettersAvatarComponent.prototype, \"avatarName\", void 0);\n__decorate([Input('src')], LettersAvatarComponent.prototype, \"src\", void 0);\n__decorate([Input('className')], LettersAvatarComponent.prototype, \"className\", void 0);\n__decorate([Input('fontFamily')], LettersAvatarComponent.prototype, \"fontFamily\", void 0);\n__decorate([In
|