UNPKG

rb-letter-avatar

Version:
2 lines 8.56 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("rb-letter-avatar",["exports","@angular/core","@angular/common"],e):e(t["rb-letter-avatar"]={},t.ng.core,t.ng.common)}(this,function(t,e,a){"use strict";var r=function(){this.defaultColors=["#5A8770","#B2B7BB","#6FA9AB","#F5AF29","#0088B9","#F18636","#D93A37","#A6B12E","#5C9BBC","#F5888D","#9A89B5","#407887","#9A89B5","#5A8770","#D33F33","#A2B01F","#F0B126","#0087BF","#F18636","#0087BF","#B2B7BB","#72ACAE","#9C8AB4","#5A8770","#EEB424","#407887"],this.defaultTextColor="#ffffff",this.defaultBorder="border:5px solid white",this.defaultTriangleup="width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 100px solid;",this.deafultFontsize="30",this.defaultHeight="50",this.deafultWidth="50",this.defaultRadius="border-radius:50%;",this.deafultDynamic="false",this.defaultRotatedeg="0",this.defaultAvatarborder="false",this.defaultFontWeight="400",this.defaultFontFamily="HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica, Arial,Lucida Grande, sans-serif"},i=function(){this.alphabetcolors="avatar-alphabet-colors",this.textColor="avatar-text-color",this.defaultBorder="avatar-default-border",this.triangleup="avatar-triangle-up",this.fontsize="avatar-font-size",this.height="avatar-height",this.width="avatar-width",this.radius="avatar-radius",this.avatarcustombgcolor="avatar-custom-bg-color",this.dynamic="avatar-dynamic",this.fontWeight="avatar-font-weight",this.fontFamily="avatar-font-family",this.shape="avatar-shape",this.data="avatar-data",this.rotatedeg="avatar-rotate-degree",this.avatarborder="avatar-border"},s=function(){function t(t){this._meta=new r,this.attribute=new i,this.base="data:image/svg+xml;base64,",this.charCount="1",this.letteravatar=t.nativeElement}return t.prototype.ngAfterViewInit=function(){this.alphabetcolors||(this.alphabetcolors=this.getPropertyValue(this.attribute.alphabetcolors)?this.getPropertyValue(this.attribute.alphabetcolors):this._meta.defaultColors),this.textColor||(this.textColor=this.getPropertyValue(this.attribute.textColor)?this.getPropertyValue(this.attribute.textColor):this._meta.defaultTextColor),this.avatarcustombgcolor||(this.avatarcustombgcolor=this.getPropertyValue(this.attribute.avatarcustombgcolor)),this.avatarborder||(this.avatarborder=this.getPropertyValue(this.attribute.avatarborder)?this.getPropertyValue(this.attribute.avatarborder):this._meta.defaultAvatarborder),this.defaultBorder||(this.defaultBorder=this.getPropertyValue(this.attribute.defaultBorder)?this.getPropertyValue(this.attribute.defaultBorder):this._meta.defaultBorder),this.triangleup||(this.triangleup=this.getPropertyValue(this.attribute.triangleup)?this.getPropertyValue(this.attribute.triangleup):this._meta.defaultTriangleup),this.fontsize||(this.fontsize=this.getPropertyValue(this.attribute.fontsize)?this.getPropertyValue(this.attribute.fontsize):this._meta.deafultFontsize),this.height||(this.height=this.getPropertyValue(this.attribute.height)?this.getPropertyValue(this.attribute.height):this._meta.defaultHeight),this.width||(this.width=this.getPropertyValue(this.attribute.width)?this.getPropertyValue(this.attribute.width):this._meta.deafultWidth),this.radius||(this.radius=this.getPropertyValue(this.attribute.radius)?this.getPropertyValue(this.attribute.radius):this._meta.defaultRadius),this.dynamic||(this.dynamic=!!this.getPropertyValue(this.attribute.dynamic)&&this.getPropertyValue(this.attribute.dynamic)),this.rotatedeg||(this.rotatedeg=this.getPropertyValue(this.attribute.rotatedeg)?this.getPropertyValue(this.attribute.rotatedeg):this._meta.defaultRotatedeg),this.fontWeight||(this.fontWeight=this.getPropertyValue(this.attribute.fontWeight)?this.getPropertyValue(this.attribute.fontWeight):this._meta.defaultFontWeight),this.fontFamily||(this.fontFamily=this.getPropertyValue(this.attribute.fontFamily)?this.getPropertyValue(this.attribute.fontFamily):this._meta.defaultFontFamily),this.shape||(this.shape=this.getPropertyValue(this.attribute.shape)),this.data||(this.data=this.getPropertyValue(this.attribute.data)),this.createAvatar()},t.prototype.getPropertyValue=function(t){return this.letteravatar.getAttribute(t)},t.prototype.createAvatar=function(){var t="";if("2"===this.charCount){var e=this.getFirstAndLastName(this.data.toUpperCase());t=e||this.data.substring(0,+this.charCount).toUpperCase()}else t=this.data.substring(0,+this.charCount).toUpperCase();var a,r=this.getCharacterTextTag(t,this.textColor,this.fontFamily,this.fontWeight,this.fontsize),i="";t.charCodeAt(0)<65?i=this.getRandomColors():(a=Math.floor((t.charCodeAt(0)-65)%this.alphabetcolors.length),i=this.alphabetcolors[a]),this.avatarcustombgcolor&&(i=this.avatarcustombgcolor),this.createSvg(this.width,this.height,i,r);var s,o=this.getLVText(),h=window.btoa(unescape(encodeURIComponent(o))),u=this.base,n="";if(this.avatarBorderStyle?n=this.avatarBorderStyle:"true"===this.avatarborder&&(n=this.defaultBorder),"0"!==this.rotatedeg&&(n="-ms-transform: rotate("+this.rotatedeg+"deg); -webkit-transform: rotate("+this.rotatedeg+"deg); transform: rotate("+this.rotatedeg+"deg)"),this.shape){if("round"===this.shape){var l=this.radius+n;if(-1<this.data.indexOf("http")||-1<this.data.indexOf("data:image")){var d="width:"+this.width+"px;height:"+this.height+"px;";s="<img src="+this.data+" style='"+d+l+"' />"}else s="<img src="+u+h+" style='"+l+"' title='"+this.data+"' />"}}else if(-1<this.data.indexOf("http")||-1<this.data.indexOf("data:image")){d="width:"+this.width+"px;height:"+this.height+"px;";s="<img src="+this.data+" style='"+d+n+"' />"}else s="<img src="+u+h+" style='"+n+"' title='"+this.data+"' />";this.letteravatar.innerHTML=s},t.prototype.getLVText=function(){return document.createElement("div").appendChild(this.imageTag.cloneNode()),this.imageTag.outerHTML},t.prototype.createSvg=function(t,e,a,r){var i=document.createElement("svg");return i.setAttribute("xmlns","http://www.w3.org/2000/svg"),i.setAttribute("pointer-events","none"),i.setAttribute("width",t),i.setAttribute("height",e),i.setAttribute("style","background-color:"+a+";width:"+t+"px;height:"+e+"px"),i.appendChild(r),(this.imageTag=i).innerHTML},t.prototype.getCharacterTextTag=function(t,e,a,r,i){var s=document.createElement("text");return s.setAttribute("text-anchor","middle"),s.setAttribute("x","50%"),s.setAttribute("y","50%"),s.setAttribute("dy","0.35em"),s.setAttribute("pointer-events","auto"),s.setAttribute("fill",e),s.setAttribute("font-family",a),s.setAttribute("style","font-weight:"+r+";font-size:"+i+"px"),s.innerText=t,s},t.prototype.getRandomColors=function(){for(var t="0123456789ABCDEF".split(""),e="#",a=0;a<6;a++)e+=t[Math.floor(16*Math.random())];return e},t.prototype.getFirstAndLastName=function(t){var e=t.split(" ");if(e&&2<=e.length){var a=e[0],r=e[1];return a&&r?a.substr(0,1)+r.substr(0,1):t.substr(0,2)}},t.decorators=[{type:e.Component,args:[{selector:"rb-letter-avatar",template:"<ng-content></ng-content>"}]}],t.ctorParameters=function(){return[{type:e.ElementRef}]},t.propDecorators={alphabetcolors:[{type:e.Input,args:["avatar-alphabet-colors"]}],textColor:[{type:e.Input,args:["avatar-text-color"]}],defaultBorder:[{type:e.Input,args:["avatar-default-border"]}],triangleup:[{type:e.Input,args:["avatar-triangle-up"]}],fontsize:[{type:e.Input,args:["avatar-font-size"]}],height:[{type:e.Input,args:["avatar-height"]}],width:[{type:e.Input,args:["avatar-width"]}],fontWeight:[{type:e.Input,args:["avatar-font-weight"]}],fontFamily:[{type:e.Input,args:["avatar-font-family"]}],radius:[{type:e.Input,args:["avatar-radius"]}],dynamic:[{type:e.Input,args:["avatar-dynamic"]}],rotatedeg:[{type:e.Input,args:["avatar-rotate-degree"]}],charCount:[{type:e.Input,args:["avatar-char-count"]}],data:[{type:e.Input,args:["avatar-data"]}],avatarBorderStyle:[{type:e.Input,args:["avatar-border-style"]}],avatarborder:[{type:e.Input,args:["avatar-border"]}],avatarcustomborder:[{type:e.Input,args:["avatar-custom-border"]}],shape:[{type:e.Input,args:["avatar-shape"]}],avatarcustombgcolor:[{type:e.Input,args:["avatar-custom-bg-color"]}]},t}(),o=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[a.CommonModule],declarations:[s],providers:[],exports:[s]}]}],t.ctorParameters=function(){return[]},t}();t.ɵa=s,t.RbLetterAvatarModule=o,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=rb-letter-avatar.umd.min.js.map