UNPKG

@aotearoan/neon

Version:

Neon is a lightweight design library of Vue 3 components with minimal dependencies.

3 lines (2 loc) 2.62 kB
"use strict";var N=Object.defineProperty;var v=(g,e,t)=>e in g?N(g,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):g[e]=t;var f=(g,e,t)=>(v(g,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./NeonRandomUtils.cjs.js"),r=class r{static genSvg(e,t,n){return r.generateIdenticon(e,n,C.NeonRandomUtils.rand(t)).outerHTML}static generateIdenticon(e,t,n){const o=r.hueShift(e.slice(),n),l=document.createElementNS(r.svgns,"svg");l.setAttribute("xmlns",r.svgns),l.setAttributeNS(null,"x","0"),l.setAttributeNS(null,"y","0"),l.setAttributeNS(null,"width",`${t}`),l.setAttributeNS(null,"height",`${t}`),r.genShape([r.genColor(o,n)],t,0,r.shapeCount-1,l,()=>0);for(let i=0;i<r.shapeCount-1;i++)r.genShape(o,t,i,r.shapeCount-1,l,n);return l}static genShape(e,t,n,o,l,i){const u=t/2,s=document.createElementNS(r.svgns,"rect");s.setAttributeNS(null,"x","0"),s.setAttributeNS(null,"y","0"),s.setAttributeNS(null,"width",`${t}`),s.setAttributeNS(null,"height",`${t}`);const a=i(),c=Math.PI*2*a,h=t/o*i()+n*t/o,S=Math.cos(c)*h,b=Math.sin(c)*h,p=`translate(${S} ${b})`,x=i(),d="rotate("+(a*360+x*180).toFixed(1)+" "+u+" "+u+")",m=p+" "+d;s.setAttributeNS(null,"transform",m);const A=r.genColor(e,i);s.setAttributeNS(null,"fill",A),l.appendChild(s)}static genColor(e,t){const n=Math.floor(e.length*t());return e.splice(n,1)[0]}static hueShift(e,t){const n=t()*30-r.wobble/2,o=l=>r.colorRotate(l,n);return e.map(o)}static colorRotate(e,t){const n=r.hexToHSL(e);let o=n.h;return o=(o+t)%360,o=o<0?360+o:o,n.h=o,r.hslToHex(n)}static hexToHSL(e){let t=+("0x"+e[1]+e[2]),n=+("0x"+e[3]+e[4]),o=+("0x"+e[5]+e[6]);t/=255,n/=255,o/=255;const l=Math.min(t,n,o),i=Math.max(t,n,o),u=i-l;let s=0,a=0,c=0;return u===0?s=0:i===t?s=(n-o)/u%6:i===n?s=(o-t)/u+2:s=(t-n)/u+4,s=Math.round(s*60),s<0&&(s+=360),c=(i+l)/2,a=u===0?0:u/(1-Math.abs(2*c-1)),a=+(a*100).toFixed(1),c=+(c*100).toFixed(1),{h:s,s:a,l:c}}static hslToHex(e){const t=e.h;let{s:n,l:o}=e;n/=100,o/=100;const l=(1-Math.abs(2*o-1))*n,i=l*(1-Math.abs(t/60%2-1)),u=o-l/2;let s=0,a=0,c=0;t>=0&&t<60?(s=l,a=i,c=0):t>=60&&t<120?(s=i,a=l,c=0):t>=120&&t<180?(s=0,a=l,c=i):t>=180&&t<240?(s=0,a=i,c=l):t>=240&&t<300?(s=i,a=0,c=l):t>=300&&t<360&&(s=l,a=0,c=i);let h=Math.round((s+u)*255).toString(16),S=Math.round((a+u)*255).toString(16),b=Math.round((c+u)*255).toString(16);return h.length===1&&(h="0"+s),S.length===1&&(S="0"+a),b.length===1&&(b="0"+c),"#"+h+S+b}};f(r,"shapeCount",4),f(r,"svgns","http://www.w3.org/2000/svg"),f(r,"wobble",30);let M=r;exports.NeonJazziconUtils=M; //# sourceMappingURL=NeonJazziconUtils.cjs.js.map