Jacky Zhao
2025-03-13 c005fe440895c3533e6a263d8ad4c63df5a1ad2b
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
import { JSX } from "preact"
import { randomIdNonSecure } from "../util/random"
 
const OverflowList = ({
  children,
  ...props
}: JSX.HTMLAttributes<HTMLUListElement> & { id: string }) => {
  return (
    <ul {...props} class={[props.class, "overflow"].filter(Boolean).join(" ")} id={props.id}>
      {children}
      <li class="overflow-end" />
    </ul>
  )
}
 
export default () => {
  const id = randomIdNonSecure()
 
  return {
    OverflowList: (props: JSX.HTMLAttributes<HTMLUListElement>) => (
      <OverflowList {...props} id={id} />
    ),
    overflowListAfterDOMLoaded: `
document.addEventListener("nav", (e) => {
  const observer = new IntersectionObserver((entries) => {
    for (const entry of entries) {
      const parentUl = entry.target.parentElement
      if (!parentUl) return
      if (entry.isIntersecting) {
        parentUl.classList.remove("gradient-active")
      } else {
        parentUl.classList.add("gradient-active")
      }
    }
  })
 
  const ul = document.getElementById("${id}")
  if (!ul) return
 
  const end = ul.querySelector(".overflow-end")
  if (!end) return
 
  observer.observe(end)
  window.addCleanup(() => observer.disconnect())
})
`,
  }
}