fast-color-generator
Version:
Super fast and efficient pseudo-random color generator, powered by a Linear Congruential Generator (LCG).
2 lines • 869 B
JavaScript
const e=`0123456789abcdef`;var t=class{state;constructor(e=Date.now()){this.state=e>>>0}next(){this.state=this.state*1664525+1013904223>>>0}get hex(){let{r:t,g:n,b:r}=this.rgb;return`#${e[t>>4]}${e[t&15]}${e[n>>4]}${e[n&15]}${e[r>>4]}${e[r&15]}`}set hex(e){if(!/^#[0-9a-fA-F]{6}$/.test(e))throw Error(`Invalid hex color format. Expected format: #rrggbb.`);let t=parseInt(e.slice(1,3),16),n=parseInt(e.slice(3,5),16),r=parseInt(e.slice(5,7),16);this.rgb={r:t,g:n,b:r}}get rgb(){return{r:this.state>>16&255,g:this.state>>8&255,b:this.state&255}}set rgb(e){let{r:t,g:n,b:r}=e;if(!this.isValidChannel(t)||!this.isValidChannel(n)||!this.isValidChannel(r))throw Error(`RGB values must be integers between 0 and 255.`);this.state=(t&255)<<16|(n&255)<<8|r&255}isValidChannel(e){return Number.isInteger(e)&&e>=0&&e<=255}};export{t as default};
//# sourceMappingURL=index.mjs.map