export function easeLinear(t) { return t; }
export function easeInCubic(t) { return t * t * t; }
export function easeOutCubic(t) { return 1 - Math.pow(1 - t, 3); }
export function easeInOutCubic(t) {
    return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
}
export function easeSpring(t) {
    const c4 = (2 * Math.PI) / 3;
    return t === 0 ? 0 : t === 1 ? 1 : Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
}
export function getEasingFn(name) {
    switch (name) {
        case 'linear': return easeLinear;
        case 'ease-in': return easeInCubic;
        case 'ease-out': return easeOutCubic;
        case 'spring': return easeSpring;
        case 'ease': return easeOutCubic;
        case 'ease-in-out':
        default: return easeInOutCubic;
    }
}
export function interpolateColor(color1, color2, progress) {
    if (color1 === 'transparent')
        color1 = '#00000000';
    if (color2 === 'transparent')
        color2 = '#00000000';
    const hex1 = color1.replace('#', '');
    const hex2 = color2.replace('#', '');
    const r1 = parseInt(hex1.substring(0, 2), 16) || 0;
    const g1 = parseInt(hex1.substring(2, 4), 16) || 0;
    const b1 = parseInt(hex1.substring(4, 6), 16) || 0;
    const a1 = hex1.length === 8 ? parseInt(hex1.substring(6, 8), 16) / 255 : 1;
    const r2 = parseInt(hex2.substring(0, 2), 16) || 0;
    const g2 = parseInt(hex2.substring(2, 4), 16) || 0;
    const b2 = parseInt(hex2.substring(4, 6), 16) || 0;
    const a2 = hex2.length === 8 ? parseInt(hex2.substring(6, 8), 16) / 255 : 1;
    const r = Math.round(r1 + (r2 - r1) * progress);
    const g = Math.round(g1 + (g2 - g1) * progress);
    const b = Math.round(b1 + (b2 - b1) * progress);
    const a = a1 + (a2 - a1) * progress;
    if (a < 1) {
        return `rgba(${r}, ${g}, ${b}, ${a.toFixed(2)})`;
    }
    return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
}
export function hashFraction(str, salt = 0) {
    let hash = salt;
    for (let i = 0; i < str.length; i++) {
        hash = ((hash << 5) - hash) + str.charCodeAt(i);
        hash |= 0;
    }
    return (Math.abs(hash) % 1000) / 1000;
}
export function getFloatAnimName(direction, seed) {
    const h = Math.floor(hashFraction(seed) * 100);
    switch (direction) {
        case 'vertical': return 'float-vertical';
        case 'horizontal': return 'float-horizontal';
        case 'both':
        default:
            return `float-both-${h % 4}`;
    }
}
export function computeFloatAmp(cfg, seed) {
    const r = cfg.amplitudeRandomness ?? 0;
    if (r === 0)
        return cfg.amplitude;
    return cfg.amplitude * (1 - r + r * hashFraction(seed, 1));
}
export function computeFloatSpeed(cfg, seed) {
    const r = cfg.speedRandomness ?? 0;
    if (r === 0)
        return cfg.speed;
    return cfg.speed * (1 - r + r * hashFraction(seed, 2));
}
export function getBackgroundStyle(bg) {
    if (bg.type === 'transparent')
        return 'background: transparent';
    if (bg.type === 'solid')
        return `background-color: ${bg.color ?? 'transparent'}`;
    if (bg.type === 'gradient' && bg.gradient) {
        const { type, angle = 135, colors } = bg.gradient;
        if (type === 'linear')
            return `background: linear-gradient(${angle}deg, ${colors.join(', ')})`;
        return `background: radial-gradient(circle, ${colors.join(', ')})`;
    }
    if (bg.type === 'image' && bg.image)
        return `background-image: url(${bg.image}); background-size: cover; background-position: center`;
    return 'background: transparent';
}
