--- import { Image } from "astro:assets"; import type { ImageMetadata } from "astro"; import { shuffleArray } from "@lib/utils"; interface Props { images: Array; class: string; altText?: string | ((index: number) => string); interval?: number; backgroundColour?: string; backgroundOpacity?: string; transitionStyle?: string; transitionDuration?: string; foreground?: boolean; foregroundColour?: string; foregroundOpacity?: string; quality?: number; height?: number; shuffle?: boolean; } const { images, class: className, altText = null, interval = 5000, backgroundColour = "bg-black", backgroundOpacity = "opacity-100", transitionStyle = "ease-in-out", transitionDuration = "duration-2000", foreground = false, foregroundColour = "bg-black", foregroundOpacity = "opacity-50", quality = "80", height, shuffle = false } = Astro.props as Props; const IDs: string[] = []; const imagesArray = shuffle ? shuffleArray(images) : images; ---
{ imagesArray.map((image, index) => { const ID = `image-carousel-${Math.random().toString(36)}`; IDs.push(ID); return ( 0 ? "opacity-0" : "", index < 2 ? "" : "hidden" ]} src={image} alt={ typeof altText === "function" ? altText(index) : (altText ?? "") } loading={index < 2 ? "eager" : "lazy"} aria-hidden={index === 0 ? "false" : "true"} layout="full-width" fit="cover" quality={quality} height={height === undefined ? undefined : height} /> ); }) } { foreground && (
) }