Spaces:
Paused
Paused
File size: 1,535 Bytes
d530f14 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | "use client";
import { HTMLAttributes, useEffect, useRef, memo } from "react";
import { cn } from "@/utils/cn";
import { setIntervalOnVisible } from "@/utils/set-timeout-on-visible";
import data from "./explosion-data.json";
function AsciiExplosion(attrs: HTMLAttributes<HTMLDivElement>) {
const ref = useRef<HTMLDivElement>(null);
const wrapperRef = useRef<HTMLDivElement>(null);
useEffect(() => {
let index = -30;
const interval = setIntervalOnVisible({
element: wrapperRef.current,
callback: () => {
index++;
if (index >= data.length) index = -40;
if (index < 0) return;
if (ref.current) {
ref.current.innerHTML = data[index];
}
},
interval: 40,
});
return () => interval?.();
}, []);
return (
<div
ref={wrapperRef}
{...attrs}
className={cn(
"w-[720px] h-[400px] absolute flex gap-16 pointer-events-none select-none",
attrs.className,
)}
>
<div
className="text-[#FA5D19] font-mono fc-decoration"
dangerouslySetInnerHTML={{ __html: data[0] }}
ref={ref}
style={{
whiteSpace: "pre",
fontSize: "10px",
lineHeight: "12.5px",
}}
/>
</div>
);
}
// Memoized version to prevent re-renders on parent state changes
const MemoizedAsciiExplosion = memo(AsciiExplosion);
// Named export
export { AsciiExplosion };
// Default export for backward compatibility
export default MemoizedAsciiExplosion;
|