File size: 1,405 Bytes
75fefa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"use client";

import { HTMLAttributes, useEffect, useRef } from "react";
import { cn } from "@/utils/cn";
import { setIntervalOnVisible } from "@/utils/set-timeout-on-visible";
import data from "./core-flame.json";

export function CoreFlame(attrs: HTMLAttributes<HTMLDivElement>) {
  const ref = useRef<HTMLDivElement>(null);
  const wrapperRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    let index = 0;

    const interval = setIntervalOnVisible({
      element: wrapperRef.current,
      callback: () => {
        index++;
        if (index >= data.length) index = 0;

        const newStr = data[index];

        ref.current!.innerHTML = newStr;
      },
      interval: 80,
    });

    return () => interval?.();
  }, []);

  return (
    <>
      <div className="absolute inset-10 -z-[10] overflow-clip">
        <div
          ref={wrapperRef}
          {...attrs}
          className={cn(
            "cw-[1110px] ch-470 absolute pointer-events-none select-none",
            attrs.className,
          )}
        >
          <div
            className="text-black-alpha-20 relative left-0 font-ascii"
            ref={ref}
            style={{
              whiteSpace: "pre",
              fontSize: 8,
              lineHeight: "10px",
            }}
          />
        </div>
      </div>
    </>
  );
}

// Export default for backward compatibility
export default CoreFlame;