default-avatar
Version:
A customizable React component to generate default avatars with initials and themed colors.
16 lines (14 loc) • 2.95 kB
JavaScript
var j=Object.create;var x=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var k=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var H=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of P(t))!_.call(r,n)&&n!==e&&x(r,n,{get:()=>t[n],enumerable:!(s=y(t,n))||s.enumerable});return r};var v=(r,t,e)=>(e=r!=null?j(S(r)):{},H(t||!r||!r.__esModule?x(e,"default",{value:r,enumerable:!0}):e,r));var M=k(p=>{"use strict";var F=Symbol.for("react.transitional.element"),O=Symbol.for("react.fragment");function C(r,t,e){var s=null;if(e!==void 0&&(s=""+e),t.key!==void 0&&(s=""+t.key),"key"in t){e={};for(var n in t)n!=="key"&&(e[n]=t[n])}else e=t;return t=e.ref,{$$typeof:F,type:r,key:s,ref:t!==void 0?t:null,props:e}}p.Fragment=O;p.jsx=C;p.jsxs=C});var g=k((w,E)=>{"use strict";E.exports=M()});function A(r){let t=r.match(/^\s*([A-Za-z])[^\s]*\s+(?:[A-Za-z]+?\s+)?([A-Za-z])[^\s]*/);if(t){let[,e,s]=t;return(e+s).toUpperCase()}return r[0]?.toUpperCase()??""}function T(r={}){let{name:t,useNameBasedColor:e=!1,theme:s="dark"}=r;return e&&t?N(t,s):q(s)}function N(r,t){let e=[...r].reduce((u,f)=>u+f.charCodeAt(0),0),s=e%360,n=70+e%20,c=t==="dark"?30+e%10:65+e%10,o=t==="dark"?c+30:c-30,a=Math.max(10,Math.min(90,o)),i=d(s,n,c),l=d(s,n,a);return{primary:i,contrast:l}}function q(r="dark"){let t=Math.floor(Math.random()*360),e=70+Math.random()*30,s=r==="dark"?15+Math.random()*10:65+Math.random()*10,n=r==="dark"?s+15:s-30,c=d(t,e,s),o=d(t,e,n);return{primary:c,contrast:o}}function d(r,t,e){t/=100,e/=100;let s=(1-Math.abs(2*e-1))*t,n=s*(1-Math.abs(r/60%2-1)),c=e-s/2,[o,a,i]=[0,0,0];r<60?[o,a,i]=[s,n,0]:r<120?[o,a,i]=[n,s,0]:r<180?[o,a,i]=[0,s,n]:r<240?[o,a,i]=[0,n,s]:r<300?[o,a,i]=[n,0,s]:[o,a,i]=[s,0,n];let l=u=>Math.round((u+c)*255).toString(16).padStart(2,"0");return`#${l(o)}${l(a)}${l(i)}`}var b=v(g());function Z({name:r,fontFamily:t="Arial, sans-serif",size:e=50,shape:s="circle",style:n={},backgroundColor:c,textColor:o,fontSize:a,padding:i="4px",useNameBasedColor:l=!1,theme:u="dark",...f}){let{primary:R,contrast:$}=T({name:r,useNameBasedColor:l,theme:u}),L=A(r),m;if(s==="circle")m="50%";else if(s==="square")m="0%";else{let h=f.radius;m=typeof h=="number"?`${h}px`:h}return(0,b.jsx)("div",{style:{backgroundColor:c??R,color:o??$,height:e,width:e,borderRadius:m,fontFamily:t,textAlign:"center",lineHeight:`${e}px`,textTransform:"uppercase",fontSize:a??`clamp(30px, ${e*.5}px, 40px)`,padding:i,...n},children:L})}export{Z as default};
/*! Bundled license information:
react/cjs/react-jsx-runtime.production.js:
(**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
*/
//# sourceMappingURL=index.js.map