import React, { useEffect, useState } from "react"; interface ImageBlurryProps { src: string; alt?: string; className?: string; key?: string | number; style?: React.CSSProperties; priority?: boolean; placeholder?: string; } const ImageBlurry: React.FC = ({ src, alt, className, key, style, priority = false, placeholder, }) => { const [imgSrc, setImgSrc] = useState(src); const [isError, setIsError] = useState(false); useEffect(() => { setImgSrc(src); }, [src]); const handleImage = () => { const pics = document.querySelectorAll("img"); pics.forEach((pic) => { if (pic.complete) { checkImage(pic); } else { pic.addEventListener("load", function () { checkImage(this as HTMLImageElement); }); } }); }; const checkImage = (img: HTMLImageElement) => { if (img.naturalHeight > img.naturalWidth) { img.classList.add("portrait"); } else if (Math.abs(img.naturalHeight - img.naturalWidth) < 10) { img.classList.add("square"); } else { img.classList.add("landscape"); } }; const onLoad = () => { console.log("Image loaded:", src); handleImage(); }; return (
); }; export default ImageBlurry;