import { component$ } from "@builder.io/qwik"; const DEFAULT_COLORS = ['#6A5ACD', '#E63525','#20B2AA', '#E87D58']; const getModulo = (value: number, divisor: number, useEvenCheck?: number) => { const remainder = value % divisor; if (useEvenCheck && Math.floor(value / Math.pow(10, useEvenCheck) % 10) % 2 === 0) { return -remainder; } return remainder; }; const generateColors = (name: string, colors = DEFAULT_COLORS) => { const hashCode = name.split('').reduce((acc, char) => { acc = ((acc << 5) - acc) + char.charCodeAt(0); return acc & acc; }, 0); const hash = Math.abs(hashCode); const numColors = colors.length; return Array.from({ length: 3 }, (_, index) => ({ color: colors[(hash + index) % numColors], translateX: getModulo(hash * (index + 1), 4, 1), translateY: getModulo(hash * (index + 1), 4, 2), scale: 1.2 + getModulo(hash * (index + 1), 2) / 10, rotate: getModulo(hash * (index + 1), 360, 1) })); }; type Props = { name: string; size?: number; class?:string; colors?: string[] } export default component$(({ class:className, name, size = 80, colors = DEFAULT_COLORS }: Props) => { const colorData = generateColors(name, colors); return ( {`Fallback avatar for ${name}`} ) })