{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "landing-page-v1",
  "title": "Landing Page v1",
  "description": "Fullscreen startup waitlist — monochrome ink-print hero with a boiling misregistered display title and floating hex-tile cursor effect on the left, Clerk's <Waitlist /> component (shadcn theme) on the right. Palette in app/globals.css; layout and type via Tailwind on the page. Renders a keyless demo form until Clerk keys are set. New projects only (shadcn init --template next).",
  "dependencies": [
    "@clerk/nextjs",
    "@clerk/ui",
    "geist"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/new-york/templates/landing-page-v1/app/layout.tsx",
      "content": "import type { Metadata } from \"next\"\nimport { ClerkProvider } from \"@clerk/nextjs\"\nimport { shadcn } from \"@clerk/ui/themes\"\nimport { GeistMono } from \"geist/font/mono\"\nimport { GeistSans } from \"geist/font/sans\"\nimport type { ReactNode } from \"react\"\n\nimport { site } from \"../lib/site\"\n\nimport \"./globals.css\"\n\nexport const metadata: Metadata = {\n  title: `${site.name} — ${site.tagline}`,\n  description: site.tagline,\n}\n\n// The page renders a keyless demo form until Clerk keys are set in .env.local,\n// so the provider is skipped too (ClerkProvider throws without a publishable key).\nconst clerkEnabled = Boolean(process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY)\n\nexport default function RootLayout({ children }: { children: ReactNode }) {\n  return (\n    <html\n      lang=\"en\"\n      className={`${GeistSans.variable} ${GeistMono.variable} h-full antialiased`}\n      suppressHydrationWarning\n    >\n      <body className=\"flex min-h-svh flex-col bg-background font-sans text-foreground\">\n        {clerkEnabled ? (\n          // waitlistUrl points at \"/\" because <Waitlist /> is on the home page.\n          // Fallback redirects send invite-accept / sign-in back here (override\n          // via NEXT_PUBLIC_CLERK_SIGN_*_FALLBACK_REDIRECT_URL once you add /dashboard).\n          <ClerkProvider\n            appearance={{ theme: shadcn }}\n            waitlistUrl=\"/\"\n            signInFallbackRedirectUrl=\"/\"\n            signUpFallbackRedirectUrl=\"/\"\n          >\n            {children}\n          </ClerkProvider>\n        ) : (\n          children\n        )}\n      </body>\n    </html>\n  )\n}\n",
      "type": "registry:page",
      "target": "app/layout.tsx"
    },
    {
      "path": "registry/new-york/templates/landing-page-v1/app/page.tsx",
      "content": "import { HexFloat } from \"../components/hex-float\"\nimport { TextureTitle } from \"../components/texture-title\"\nimport { WaitlistPanel } from \"../components/waitlist-panel\"\nimport { site } from \"../lib/site\"\n\n/** Black grain on paper — xerox wash over the page. */\nconst GRAIN_LIGHT =\n  \"url(\\\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='11'/><feColorMatrix type='matrix' values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/></filter><rect width='180' height='180' filter='url(%23g)'/></svg>\\\")\"\n\n/** White grain on ink. */\nconst GRAIN_DARK =\n  \"url(\\\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='11'/><feColorMatrix type='matrix' values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.6 0'/></filter><rect width='180' height='180' filter='url(%23g)'/></svg>\\\")\"\n\nexport default function HomePage() {\n  return (\n    <main className=\"relative flex min-h-svh flex-col bg-background text-foreground lg:h-svh lg:flex-row lg:overflow-hidden\">\n      <section className=\"relative flex min-h-svh min-w-0 flex-col lg:min-h-0 lg:flex-1\">\n        {/* Hex field is out of flow so the hero can size to copy on small screens. */}\n        <div className=\"pointer-events-none absolute inset-0 overflow-hidden\">\n          <HexFloat\n            className=\"size-full\"\n            grain={0}\n            iridescence={0.15}\n            speed={0.15}\n            tilt={6}\n            bevel={1.5}\n            shine={0.15}\n          >\n            <div aria-hidden className=\"size-full bg-background\" />\n          </HexFloat>\n        </div>\n\n        <div className=\"pointer-events-none relative z-1 flex flex-1 flex-col items-center justify-center px-6 py-16 text-center sm:px-10 sm:py-20 md:px-14 lg:py-0\">\n          <div className=\"pointer-events-auto max-w-full\">\n            <TextureTitle>{site.name}</TextureTitle>\n          </div>\n          <p className=\"mt-6 max-w-xl text-[clamp(1.125rem,4.5vw,1.75rem)] font-medium leading-[1.2] tracking-[-0.02em] sm:mt-8\">\n            {site.tagline}\n          </p>\n          <ul className=\"mt-6 flex w-full max-w-80 flex-col gap-2 text-left text-sm leading-[1.4] tracking-[-0.01em] text-foreground sm:mt-8\">\n            {site.perks.map((perk) => (\n              <li key={perk} className=\"flex gap-2.5\">\n                <span\n                  aria-hidden\n                  className=\"mt-[0.5em] size-[0.3rem] shrink-0 bg-foreground\"\n                />\n                {perk}\n              </li>\n            ))}\n          </ul>\n        </div>\n      </section>\n\n      <section className=\"relative flex min-w-0 flex-col items-center justify-center gap-4 border-t border-border bg-background px-6 py-16 sm:px-8 sm:py-20 lg:min-h-0 lg:flex-1 lg:overflow-y-auto lg:border-l lg:border-t-0 lg:py-0\">\n        <WaitlistPanel />\n      </section>\n\n      {/* Topmost xerox wash — must sit above both panels or it only shows through gaps. */}\n      <div\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 z-10 bg-size-[180px_180px] opacity-[0.06] dark:hidden\"\n        style={{ backgroundImage: GRAIN_LIGHT }}\n      />\n      <div\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 z-10 hidden bg-size-[180px_180px] opacity-[0.06] dark:block\"\n        style={{ backgroundImage: GRAIN_DARK }}\n      />\n    </main>\n  )\n}\n",
      "type": "registry:page",
      "target": "app/page.tsx"
    },
    {
      "path": "registry/new-york/templates/landing-page-v1/app/globals.css",
      "content": "@import \"tailwindcss\";\n@import \"@clerk/ui/themes/shadcn.css\";\n\n@custom-variant dark (&:is(.dark *));\n\n/* Same light/dark palette as the host app/globals.css */\n:root {\n  --background: oklch(1 0 0);\n  --foreground: oklch(0.145 0 0);\n  --card: oklch(1 0 0);\n  --card-foreground: oklch(0.145 0 0);\n  --popover: oklch(1 0 0);\n  --popover-foreground: oklch(0.145 0 0);\n  --primary: oklch(0.205 0 0);\n  --primary-foreground: oklch(0.985 0 0);\n  --secondary: oklch(0.97 0 0);\n  --secondary-foreground: oklch(0.205 0 0);\n  --muted: oklch(0.97 0 0);\n  --muted-foreground: oklch(0.556 0 0);\n  --accent: oklch(0.97 0 0);\n  --accent-foreground: oklch(0.205 0 0);\n  --destructive: oklch(0.577 0.245 27.325);\n  --border: oklch(0.922 0 0);\n  --input: oklch(0.922 0 0);\n  --ring: oklch(0.708 0 0);\n  --chart-1: oklch(0.828 0.111 230.318);\n  --chart-2: oklch(0.685 0.169 237.323);\n  --chart-3: oklch(0.588 0.158 241.966);\n  --chart-4: oklch(0.5 0.134 242.749);\n  --chart-5: oklch(0.443 0.11 240.79);\n  --radius: 0.45rem;\n  --sidebar: oklch(0.985 0 0);\n  --sidebar-foreground: oklch(0.145 0 0);\n  --sidebar-primary: oklch(0.205 0 0);\n  --sidebar-primary-foreground: oklch(0.985 0 0);\n  --sidebar-accent: oklch(0.97 0 0);\n  --sidebar-accent-foreground: oklch(0.205 0 0);\n  --sidebar-border: oklch(0.922 0 0);\n  --sidebar-ring: oklch(0.708 0 0);\n}\n\n.dark {\n  --background: oklch(0.145 0 0);\n  --foreground: oklch(0.985 0 0);\n  --card: oklch(0.205 0 0);\n  --card-foreground: oklch(0.985 0 0);\n  --popover: oklch(0.205 0 0);\n  --popover-foreground: oklch(0.985 0 0);\n  --primary: oklch(0.922 0 0);\n  --primary-foreground: oklch(0.205 0 0);\n  --secondary: oklch(0.269 0 0);\n  --secondary-foreground: oklch(0.985 0 0);\n  --muted: oklch(0.269 0 0);\n  --muted-foreground: oklch(0.708 0 0);\n  --accent: oklch(0.269 0 0);\n  --accent-foreground: oklch(0.985 0 0);\n  --destructive: oklch(0.704 0.191 22.216);\n  --border: oklch(1 0 0 / 10%);\n  --input: oklch(1 0 0 / 15%);\n  --ring: oklch(0.556 0 0);\n  --chart-1: oklch(0.828 0.111 230.318);\n  --chart-2: oklch(0.685 0.169 237.323);\n  --chart-3: oklch(0.588 0.158 241.966);\n  --chart-4: oklch(0.5 0.134 242.749);\n  --chart-5: oklch(0.443 0.11 240.79);\n  --sidebar: oklch(0.205 0 0);\n  --sidebar-foreground: oklch(0.985 0 0);\n  --sidebar-primary: oklch(0.488 0.243 264.376);\n  --sidebar-primary-foreground: oklch(0.985 0 0);\n  --sidebar-accent: oklch(0.269 0 0);\n  --sidebar-accent-foreground: oklch(0.985 0 0);\n  --sidebar-border: oklch(1 0 0 / 10%);\n  --sidebar-ring: oklch(0.556 0 0);\n}\n\n@theme inline {\n  --font-sans: var(--font-geist-sans);\n  --font-mono: var(--font-geist-mono);\n  --color-background: var(--background);\n  --color-foreground: var(--foreground);\n  --color-card: var(--card);\n  --color-card-foreground: var(--card-foreground);\n  --color-popover: var(--popover);\n  --color-popover-foreground: var(--popover-foreground);\n  --color-primary: var(--primary);\n  --color-primary-foreground: var(--primary-foreground);\n  --color-secondary: var(--secondary);\n  --color-secondary-foreground: var(--secondary-foreground);\n  --color-muted: var(--muted);\n  --color-muted-foreground: var(--muted-foreground);\n  --color-accent: var(--accent);\n  --color-accent-foreground: var(--accent-foreground);\n  --color-destructive: var(--destructive);\n  --color-border: var(--border);\n  --color-input: var(--input);\n  --color-ring: var(--ring);\n  --color-chart-1: var(--chart-1);\n  --color-chart-2: var(--chart-2);\n  --color-chart-3: var(--chart-3);\n  --color-chart-4: var(--chart-4);\n  --color-chart-5: var(--chart-5);\n  --color-sidebar: var(--sidebar);\n  --color-sidebar-foreground: var(--sidebar-foreground);\n  --color-sidebar-primary: var(--sidebar-primary);\n  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);\n  --color-sidebar-accent: var(--sidebar-accent);\n  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);\n  --color-sidebar-border: var(--sidebar-border);\n  --color-sidebar-ring: var(--sidebar-ring);\n  --radius-sm: calc(var(--radius) * 0.6);\n  --radius-md: calc(var(--radius) * 0.8);\n  --radius-lg: var(--radius);\n  --radius-xl: calc(var(--radius) * 1.4);\n}\n\n@layer base {\n  * {\n    @apply border-border outline-ring/50;\n  }\n  body {\n    @apply bg-background text-foreground;\n  }\n}\n",
      "type": "registry:file",
      "target": "app/globals.css"
    },
    {
      "path": "registry/new-york/templates/landing-page-v1/app/api/webhooks/route.ts",
      "content": "import { verifyWebhook } from \"@clerk/nextjs/webhooks\"\nimport type { NextRequest } from \"next/server\"\n\n/**\n * Clerk waitlist webhooks — verify every delivery, then react to\n * waitlistEntry.created / waitlistEntry.updated.\n *\n * Local testing:\n *   clerk webhooks listen --forward-to http://localhost:3000/api/webhooks\n * Add the printed relay URL as a Dashboard webhook endpoint (subscribe to\n * waitlistEntry.*), then put that endpoint's signing secret in\n * CLERK_WEBHOOK_SIGNING_SECRET.\n */\nexport async function POST(req: NextRequest) {\n  let evt\n  try {\n    evt = await verifyWebhook(req)\n  } catch (err) {\n    console.error(\"Webhook verification failed:\", err)\n    return new Response(\"Verification failed\", { status: 400 })\n  }\n\n  if (\n    evt.type === \"waitlistEntry.created\" ||\n    evt.type === \"waitlistEntry.updated\"\n  ) {\n    const { id, email_address, status } = evt.data\n    // Hook your own side effects here (DB insert, Resend, Slack, etc.).\n    console.log(`[waitlist] ${evt.type}`, { id, email: email_address, status })\n  }\n\n  return new Response(\"OK\", { status: 200 })\n}\n",
      "type": "registry:page",
      "target": "app/api/webhooks/route.ts"
    },
    {
      "path": "registry/new-york/templates/landing-page-v1/components/waitlist-panel.tsx",
      "content": "\"use client\"\n\nimport { Waitlist } from \"@clerk/nextjs\"\nimport { useState, type FormEvent } from \"react\"\n\nconst clerkEnabled = Boolean(process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY)\n\nconst panelClassName =\n  \"w-full max-w-sm rounded-lg border border-border bg-card p-6 shadow-sm\"\n\n/**\n * Renders Clerk's prebuilt <Waitlist /> (shadcn theme is applied at the\n * ClerkProvider level in app/layout.tsx). Until Clerk keys are set in\n * .env.local, a local demo form renders instead so the page works on\n * first run — it does not store emails anywhere.\n */\nexport function WaitlistPanel() {\n  if (!clerkEnabled) {\n    return <WaitlistDemoForm />\n  }\n\n  return (\n    <div className=\"w-full max-w-sm\">\n      <Waitlist fallback={<WaitlistSkeleton />} />\n    </div>\n  )\n}\n\nfunction WaitlistDemoForm() {\n  const [joined, setJoined] = useState(false)\n\n  function onSubmit(event: FormEvent<HTMLFormElement>) {\n    event.preventDefault()\n    setJoined(true)\n  }\n\n  return (\n    <div className={panelClassName}>\n      {joined ? (\n        <div className=\"flex flex-col items-center py-8 text-center\">\n          <span\n            aria-hidden\n            className=\"flex size-10 items-center justify-center rounded-full bg-muted text-sm font-medium text-muted-foreground\"\n          >\n            ✓\n          </span>\n          <h2 className=\"mt-4 text-lg font-semibold text-card-foreground\">\n            You&apos;re on the list\n          </h2>\n          <p className=\"mt-1 text-sm text-muted-foreground\">\n            We&apos;ll email you when your spot is ready.\n          </p>\n        </div>\n      ) : (\n        <>\n          <h2 className=\"text-lg font-semibold text-card-foreground\">\n            Join the waitlist\n          </h2>\n          <p className=\"mt-1 text-sm text-muted-foreground\">\n            Enter your email address and we&apos;ll let you know when your spot\n            is ready.\n          </p>\n          <form onSubmit={onSubmit} className=\"mt-6 flex flex-col gap-3\">\n            <label\n              htmlFor=\"waitlist-email\"\n              className=\"text-sm font-medium text-card-foreground\"\n            >\n              Email address\n            </label>\n            <input\n              id=\"waitlist-email\"\n              type=\"email\"\n              required\n              placeholder=\"you@example.com\"\n              className=\"h-9 w-full rounded-md border border-input bg-transparent px-3 text-sm text-foreground outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n            />\n            <button\n              type=\"submit\"\n              className=\"h-9 w-full rounded-md bg-primary text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90\"\n            >\n              Join the waitlist\n            </button>\n          </form>\n        </>\n      )}\n    </div>\n  )\n}\n\nfunction WaitlistSkeleton() {\n  return (\n    <div className={panelClassName}>\n      <div className=\"h-5 w-2/5 animate-pulse rounded-md bg-muted\" />\n      <div className=\"mt-3 h-4 w-4/5 animate-pulse rounded-md bg-muted\" />\n      <div className=\"mt-6 h-9 w-full animate-pulse rounded-md bg-muted\" />\n      <div className=\"mt-3 h-9 w-full animate-pulse rounded-md bg-muted\" />\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/waitlist-panel.tsx"
    },
    {
      "path": "registry/new-york/templates/landing-page-v1/components/texture-title.tsx",
      "content": "\"use client\"\n\nimport { useRef, useSyncExternalStore, type ReactNode } from \"react\"\n\nconst MAIN_FILTER_ID = \"lp1-ink-main\"\nconst GHOST_FILTER_ID = \"lp1-ink-ghost\"\n\nconst MAIN_SCALE = { rest: \"4\", boost: \"10\" }\nconst GHOST_SCALE = { rest: \"16\", boost: \"36\" }\n\nconst MOTION_QUERY = \"(prefers-reduced-motion: no-preference)\"\n\nfunction subscribeMotion(onStoreChange: () => void) {\n  const query = window.matchMedia(MOTION_QUERY)\n  query.addEventListener(\"change\", onStoreChange)\n  return () => query.removeEventListener(\"change\", onStoreChange)\n}\n\nfunction getMotionSnapshot() {\n  return window.matchMedia(MOTION_QUERY).matches\n}\n\n/** SSR / hydration snapshot — no SMIL until after hydrate. */\nfunction getMotionServerSnapshot() {\n  return false\n}\n\n/**\n * Misregistered screen-print title: a crisp layer with a slight ink wobble\n * sits over a blurred, heavily displaced \"ink bleed\" ghost of the same text.\n * Fractal noise reseeds on a short loop so both layers boil, and hovering\n * the title kicks the displacement up like a mis-pulled print. The noise\n * loop is skipped for users who prefer reduced motion (and during SSR —\n * SMIL <animate> only mounts on the client).\n */\nexport function TextureTitle({ children }: { children: ReactNode }) {\n  const animate = useSyncExternalStore(\n    subscribeMotion,\n    getMotionSnapshot,\n    getMotionServerSnapshot\n  )\n  const mainDisplaceRef = useRef<SVGFEDisplacementMapElement>(null)\n  const ghostDisplaceRef = useRef<SVGFEDisplacementMapElement>(null)\n\n  const setBoost = (on: boolean) => {\n    mainDisplaceRef.current?.setAttribute(\n      \"scale\",\n      on ? MAIN_SCALE.boost : MAIN_SCALE.rest\n    )\n    ghostDisplaceRef.current?.setAttribute(\n      \"scale\",\n      on ? GHOST_SCALE.boost : GHOST_SCALE.rest\n    )\n  }\n\n  const noiseLoop = animate ? (\n    <>\n      <animate\n        attributeName=\"baseFrequency\"\n        dur=\"0.5s\"\n        repeatCount=\"indefinite\"\n        values=\"0.85;1;0.8;1.05;0.85\"\n      />\n      <animate\n        attributeName=\"seed\"\n        dur=\"0.5s\"\n        repeatCount=\"indefinite\"\n        calcMode=\"discrete\"\n        values=\"3;15;8;22;3\"\n      />\n    </>\n  ) : null\n\n  return (\n    <span\n      className=\"relative block w-fit max-w-full\"\n      onPointerEnter={() => setBoost(true)}\n      onPointerLeave={() => setBoost(false)}\n    >\n      <svg aria-hidden className=\"absolute size-0\">\n        <filter\n          id={MAIN_FILTER_ID}\n          x=\"-25%\"\n          y=\"-25%\"\n          width=\"150%\"\n          height=\"150%\"\n          colorInterpolationFilters=\"sRGB\"\n        >\n          <feTurbulence\n            type=\"fractalNoise\"\n            baseFrequency=\"0.9\"\n            numOctaves=\"4\"\n            seed=\"7\"\n            result=\"grain\"\n          >\n            {noiseLoop}\n          </feTurbulence>\n          <feDisplacementMap\n            ref={mainDisplaceRef}\n            in=\"SourceGraphic\"\n            in2=\"grain\"\n            scale={MAIN_SCALE.rest}\n            xChannelSelector=\"R\"\n            yChannelSelector=\"G\"\n          />\n        </filter>\n        <filter\n          id={GHOST_FILTER_ID}\n          x=\"-25%\"\n          y=\"-25%\"\n          width=\"150%\"\n          height=\"150%\"\n          colorInterpolationFilters=\"sRGB\"\n        >\n          <feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"2.5\" result=\"soft\" />\n          <feTurbulence\n            type=\"fractalNoise\"\n            baseFrequency=\"0.9\"\n            numOctaves=\"4\"\n            seed=\"12\"\n            result=\"grain\"\n          >\n            {noiseLoop}\n          </feTurbulence>\n          <feDisplacementMap\n            ref={ghostDisplaceRef}\n            in=\"soft\"\n            in2=\"grain\"\n            scale={GHOST_SCALE.rest}\n            xChannelSelector=\"R\"\n            yChannelSelector=\"G\"\n          />\n        </filter>\n      </svg>\n      <span\n        aria-hidden\n        className=\"absolute inset-0 max-w-full translate-x-[0.04em] translate-y-[0.045em] select-none text-[clamp(2.75rem,12vw,6.5rem)] font-bold leading-[0.9] tracking-[-0.04em] wrap-break-word opacity-55\"\n        style={{ filter: `url(#${GHOST_FILTER_ID})` }}\n      >\n        {children}\n      </span>\n      <h1\n        className=\"relative max-w-full text-[clamp(2.75rem,12vw,6.5rem)] font-bold leading-[0.9] tracking-[-0.04em] wrap-break-word\"\n        style={{ filter: `url(#${MAIN_FILTER_ID})` }}\n      >\n        {children}\n      </h1>\n    </span>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/texture-title.tsx"
    },
    {
      "path": "registry/new-york/templates/landing-page-v1/components/hex-float.tsx",
      "content": "\"use client\"\n\nimport {\n  useEffect,\n  useRef,\n  useState,\n  useSyncExternalStore,\n  type ReactNode,\n} from \"react\"\n\nexport interface HexFloatOptions {\n  /** Width of each hex tile in CSS pixels. */\n  size?: number\n  /** Seam between tiles in CSS pixels. */\n  gap?: number\n  /** Width of the shiny beveled rim in CSS pixels. */\n  bevel?: number\n  /** Backward lean of the page in degrees (-30 to 30). Positive tilts the top away. */\n  tilt?: number\n  /** Camera closeness (0 to 1). Higher exaggerates the perspective of the tilt. */\n  perspective?: number\n  /** How far tiles bob up and down as they float (0 to 1). 0 keeps them still. */\n  float?: number\n  /** Speed of the floating motion. 1 is normal speed. */\n  speed?: number\n  /** Intensity of the specular glints on rims and tile faces (0 to 2). */\n  shine?: number\n  /** How strongly tiles rise along the edges of the fluid reading window (0 to 1). */\n  lift?: number\n  /** Size of the fluid splats the cursor injects, in CSS pixels. Sets the reading window's scale. */\n  radius?: number\n  /** How strongly cursor movement pushes the fluid around (0 to 3). */\n  flow?: number\n  /** Vorticity of the fluid (0 to 15). Higher makes the window's trail curl into eddies. */\n  swirl?: number\n  /** How long the fluid trail lingers before healing (0 to 1). */\n  trail?: number\n  /** Strength of the iridescent hue shift on highlights (0 to 2). 0 keeps highlights neutral. */\n  iridescence?: number\n  /** Bloom glow around bright highlights (0 to 1). 0 skips the pass entirely. */\n  bloom?: number\n  /** Animated film grain over the final image (0 to 1). 0 skips the pass entirely. */\n  grain?: number\n  /** Seam color as [r, g, b] in 0-1 range, or \"auto\" to derive a dark seam from the page background. */\n  gapColor?: [number, number, number] | \"auto\"\n}\n\nexport interface HexFloatElements {\n  /** Canvas with layoutsubtree that hosts the HTML content. */\n  source: HTMLCanvasElement\n  /** The element inside the source canvas that gets captured. */\n  content: HTMLElement\n  /** Canvas the WebGL effect renders to. */\n  output: HTMLCanvasElement\n}\n\nexport interface HexFloatInstance {\n  /** Update effect options live. */\n  setOptions: (options: HexFloatOptions) => void\n  /** Re-read canvas size. Call when the element is resized. */\n  resize: () => void\n  /** Stop the loop and release all GPU resources. */\n  destroy: () => void\n}\n\nconst DEFAULTS: Required<HexFloatOptions> = {\n  size: 160,\n  gap: 0,\n  bevel: 1.5,\n  tilt: 20,\n  perspective: 0.5,\n  float: 0,\n  speed: 1,\n  shine: 0.5,\n  lift: 0.1,\n  radius: 1200,\n  flow: 0,\n  swirl: 0,\n  trail: 0,\n  iridescence: 5,\n  bloom: 0,\n  grain: 0.8,\n  gapColor: \"auto\",\n}\n\ntype PaintableCanvas = HTMLCanvasElement & {\n  onpaint?: (() => void) | null\n  requestPaint?: () => void\n  // Chrome 156+: children are only hit-testable once their geometry is registered.\n  updateElementGeometry?: (element: Element) => void\n}\n\ntype ElementImageContext = CanvasRenderingContext2D & {\n  drawElementImage?: (element: Element, x: number, y: number) => void\n}\n\nconst VERT = `#version 300 es\nprecision highp float;\nlayout(location = 0) in vec2 aPos;\nout vec2 vUv;\nvoid main () {\n  vUv = aPos * 0.5 + 0.5;\n  gl_Position = vec4(aPos, 0.0, 1.0);\n}`\n\nconst FRAG = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nout vec4 outColor;\nuniform sampler2D uContent;\nuniform vec2 uRes;\nuniform float uSize;\nuniform float uGap;\nuniform float uBevel;\nuniform float uTilt;\nuniform float uDist;\nuniform float uFloat;\nuniform float uShine;\nuniform float uLift;\nuniform float uIrid;\nuniform sampler2D uFlow;\nuniform vec2 uScroll;\nuniform float uTime;\nuniform float uHasContent;\nuniform float uMaxX;\nuniform vec3 uBg;\nuniform vec3 uGapColor;\n\nconst float TAU = 6.2831853;\nconst float SQ3 = 1.7320508;\n\nfloat hash12 (vec2 p) {\n  vec3 p3 = fract(vec3(p.xyx) * 0.1031);\n  p3 += dot(p3, p3.yzx + 33.33);\n  return fract((p3.x + p3.y) * p3.z);\n}\n\nvec2 hextile (inout vec2 p) {\n  const vec2 sz = vec2(1.0, SQ3);\n  const vec2 hsz = 0.5 * sz;\n  vec2 p1 = mod(p, sz) - hsz;\n  vec2 p2 = mod(p - hsz, sz) - hsz;\n  vec2 p3 = dot(p1, p1) < dot(p2, p2) ? p1 : p2;\n  vec2 n = (p3 - p + hsz) / sz;\n  p = p3;\n  n -= vec2(0.5);\n  return round(n * 2.0) * 0.5;\n}\n\nfloat hexDist (vec2 p) {\n  p = abs(p);\n  return max(dot(p, vec2(0.5, 0.8660254)), p.x);\n}\n\nfloat flowAt (vec2 xy) {\n  vec2 uv = (xy * uSize - uScroll) / uRes;\n  if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) return 0.0;\n  return clamp(texture(uFlow, uv).r, 0.0, 4.0);\n}\n\nfloat tileZ (vec2 center, float f) {\n  vec2 id = center * vec2(1.0, 1.0 / SQ3);\n  float h = hash12(id * 7.31 + 3.7);\n  float focus = smoothstep(0.18, 0.85, f);\n  float ring = smoothstep(0.02, 0.14, f) * (1.0 - smoothstep(0.14, 0.6, f));\n  float bob = uFloat * 0.4 * sin(uTime * 1.4 + h * TAU) * (1.0 - focus);\n  float lift = uLift * ring;\n  return -(bob + lift * 1.2);\n}\n\nvec4 page (vec2 px) {\n  vec2 p = px / uRes;\n  if (p.x < 0.0 || p.x > uMaxX || p.y < 0.0 || p.y > 1.0) return vec4(0.0);\n  return texture(uContent, p);\n}\n\nvec4 shade (vec2 sUv) {\n  float cell = max(uSize, 8.0);\n  float hw = max(0.5 - (uGap / cell) * 0.5, 0.15);\n  float bevW = clamp(uBevel / cell, 0.0, hw - 0.1);\n  float th = 0.09;\n\n  float aspect = uRes.x / uRes.y;\n  vec2 ndc = vec2((sUv.x * 2.0 - 1.0) * aspect, sUv.y * 2.0 - 1.0);\n\n  float sa = sin(uTilt);\n  float ca = cos(uTilt);\n  vec3 fwd = vec3(0.0, -sa, ca);\n  vec3 upv = vec3(0.0, ca, sa);\n  float H = uRes.y / cell;\n  float D = H * uDist;\n  float focal = (D + sqrt(D * D + H * H * sa * sa)) / (H * ca);\n  float dy = 0.5 * H - sa * D\n    - ca * D * (ca - focal * sa) / (sa + focal * ca);\n  vec3 la = vec3(uScroll.x / cell + 0.5 * uRes.x / cell,\n                 uScroll.y / cell + 0.5 * H + dy, 0.0);\n  vec3 ro = la - fwd * D;\n  vec3 rd = normalize(vec3(ndc.x, 0.0, 0.0) + ndc.y * upv + focal * fwd);\n\n  vec3 seam = uGapColor;\n\n  if (rd.z < 0.02) {\n    return uHasContent > 0.5 ? vec4(uBg, 1.0) : vec4(0.0);\n  }\n\n  float maxUp = uFloat * 0.4 + uLift * 1.2 + th;\n  float floorZ = th + 0.06;\n  float tFloor = (floorZ - ro.z) / rd.z;\n  float t0 = max((-maxUp - ro.z) / rd.z, 0.0);\n\n  vec2 oxy = ro.xy;\n  vec2 rxy = rd.xy;\n  vec2 sp = oxy + rxy * t0;\n  vec2 local = sp;\n  hextile(local);\n  vec2 center = sp - local;\n\n  vec2 N0 = vec2(1.0, 0.0);\n  vec2 N1 = vec2(0.5, 0.8660254);\n  vec2 N2 = vec2(-0.5, 0.8660254);\n\n  bool hit = false;\n  bool onTop = false;\n  float tHit = 0.0;\n  vec3 n = vec3(0.0, 0.0, -1.0);\n  float zc = 0.0;\n\n  float hwc = hw;\n  float fCell = 0.0;\n  for (int i = 0; i < 64; i++) {\n    fCell = flowAt(center);\n    zc = tileZ(center, fCell);\n    hwc = mix(hw, 0.502, smoothstep(0.18, 0.85, fCell));\n    float zTop = zc - th;\n    float tZin = (zTop - ro.z) / rd.z;\n    float tZout = (zc + th - ro.z) / rd.z;\n\n    float tIn = -1.0e9;\n    float tOut = 1.0e9;\n    vec2 inN = vec2(0.0);\n    bool empty = false;\n    for (int k = 0; k < 3; k++) {\n      vec2 Nk = k == 0 ? N0 : (k == 1 ? N1 : N2);\n      float d = dot(rxy, Nk);\n      float o = dot(oxy - center, Nk);\n      if (abs(d) < 1.0e-6) {\n        if (abs(o) > hwc) { empty = true; break; }\n      } else {\n        float ta = (-hwc - o) / d;\n        float tb = (hwc - o) / d;\n        float lo = min(ta, tb);\n        float hi = max(ta, tb);\n        if (lo > tIn) { tIn = lo; inN = -sign(d) * Nk; }\n        tOut = min(tOut, hi);\n      }\n    }\n\n    if (!empty) {\n      float lo = max(tIn, tZin);\n      float hi = min(tOut, tZout);\n      if (lo <= hi && hi > 0.0) {\n        tHit = max(lo, 0.0);\n        onTop = tZin >= tIn;\n        n = onTop ? vec3(0.0, 0.0, -1.0) : vec3(inN, 0.0);\n        hit = true;\n        break;\n      }\n    }\n\n    float tExit = 1.0e9;\n    vec2 step2 = vec2(0.0);\n    for (int k = 0; k < 3; k++) {\n      vec2 Nk = k == 0 ? N0 : (k == 1 ? N1 : N2);\n      float d = dot(rxy, Nk);\n      if (abs(d) < 1.0e-6) continue;\n      float o = dot(oxy - center, Nk);\n      float te = (0.5 * sign(d) - o) / d;\n      if (te < tExit) { tExit = te; step2 = sign(d) * Nk; }\n    }\n    if (tExit >= tFloor || step2 == vec2(0.0)) break;\n    center += step2;\n  }\n\n  vec3 Ld = normalize(vec3(-0.35, -0.5, -0.78));\n\n  if (!hit) {\n    vec2 fl = (oxy + rxy * tFloor);\n    vec2 fLocal = fl;\n    hextile(fLocal);\n    float open = smoothstep(hw, hw + 0.22, hexDist(fLocal));\n    if (uHasContent < 0.5) {\n      return vec4(0.0, 0.0, 0.0, 0.4 - 0.25 * open);\n    }\n    return vec4(seam * mix(0.6, 1.0, open), 1.0);\n  }\n\n  vec3 p = ro + rd * tHit;\n\n  float fc = smoothstep(0.18, 0.85, fCell);\n\n  if (onTop) {\n    vec2 lp = p.xy - center;\n    float e = hwc - hexDist(lp);\n    if (e < bevW) {\n      float ax = abs(lp.x);\n      float a1 = abs(dot(lp, N1));\n      float a2 = abs(dot(lp, N2));\n      vec2 dir = ax > a1 && ax > a2 ? N0 : (a1 > a2 ? N1 : N2);\n      dir *= sign(dot(lp, dir));\n      float k = (1.0 - smoothstep(0.0, max(bevW, 1.0e-4), e)) * (1.0 - fc);\n      n = normalize(mix(vec3(0.0, 0.0, -1.0), vec3(dir * 0.85, -0.6), k));\n    }\n  }\n\n  float diff = max(dot(n, Ld), 0.0);\n  vec3 refl = reflect(rd, n);\n  vec3 Ld2 = normalize(vec3(0.55, -0.25, -0.8));\n  float glintL = pow(max(dot(refl, Ld), 0.0), 120.0);\n  float sheenL = pow(max(dot(refl, Ld2), 0.0), 8.0) * 0.35;\n  float spec = (glintL + sheenL) * uShine * (1.0 - fc);\n  float fres = pow(1.0 - max(dot(n, -rd), 0.0), 3.0) * (1.0 - fc);\n  float iridPh = dot(n, -rd) * 2.2 + (p.x + p.y) * 0.22;\n  vec3 iridTint = 1.0 + uIrid * 0.3 * cos(vec3(0.0, 2.094, 4.188) + iridPh * 3.5);\n  vec3 specCol = spec * iridTint;\n  float raised = clamp(-zc, -0.6, 1.4);\n\n  if (uHasContent < 0.5) {\n    float glint = spec * (0.4 + 0.6 * (onTop ? 0.4 : 1.0)) + fres * 0.2 * uShine;\n    float shadeSide = onTop ? 0.0 : 0.3;\n    float a = clamp(glint * 0.85 + shadeSide, 0.0, 0.85) * (1.0 - fc);\n    return vec4(vec3(min(glint, a)), a);\n  }\n\n  if (onTop) {\n    vec4 c = page(p.xy * cell - uScroll);\n    vec3 face = mix(uBg, c.rgb, c.a);\n    vec3 lit = face * (0.86 + 0.14 * diff + raised * 0.06)\n      + specCol * 0.9 + fres * iridTint * 0.12 * uShine;\n    return vec4(mix(lit, face, fc), 1.0);\n  }\n\n  float wallAo = 1.0 - smoothstep(zc - th, floorZ, p.z) * 0.4;\n  vec3 wallCol = seam * mix(0.55, 1.0, diff) * wallAo\n    + specCol * 1.3 + fres * iridTint * 0.28 * uShine;\n  return vec4(wallCol, 1.0);\n}\n\nvoid main () {\n  vec2 sUv = vec2(vUv.x, 1.0 - vUv.y);\n  vec2 px = 1.0 / uRes;\n  vec4 a = shade(sUv + vec2( 0.125,  0.375) * px);\n  vec4 b = shade(sUv + vec2(-0.125, -0.375) * px);\n  vec4 c = a + b;\n  if (dot(abs(a - b), vec4(1.0)) > 0.02) {\n    c += shade(sUv + vec2(-0.375,  0.125) * px)\n       + shade(sUv + vec2( 0.375, -0.125) * px);\n    outColor = c * 0.25;\n  } else {\n    outColor = c * 0.5;\n  }\n}`\n\nconst SIM_VERT = `#version 300 es\nprecision highp float;\nlayout(location = 0) in vec2 aPos;\nout vec2 vUv;\nout vec2 vL;\nout vec2 vR;\nout vec2 vT;\nout vec2 vB;\nuniform vec2 texelSize;\nvoid main () {\n  vUv = aPos * 0.5 + 0.5;\n  vL = vUv - vec2(texelSize.x, 0.0);\n  vR = vUv + vec2(texelSize.x, 0.0);\n  vT = vUv + vec2(0.0, texelSize.y);\n  vB = vUv - vec2(0.0, texelSize.y);\n  gl_Position = vec4(aPos, 0.0, 1.0);\n}`\n\nconst FRAG_SPLAT = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nout vec4 outColor;\nuniform sampler2D uTarget;\nuniform float uAspect;\nuniform vec3 uColor;\nuniform vec2 uPoint;\nuniform float uRadius;\nvoid main () {\n  vec2 p = vUv - uPoint;\n  p.x *= uAspect;\n  vec3 splat = exp(-dot(p, p) / uRadius) * uColor;\n  vec3 base = texture(uTarget, vUv).xyz;\n  outColor = vec4(base + splat, 1.0);\n}`\n\nconst FRAG_ADVECT = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nout vec4 outColor;\nuniform sampler2D uVelocity;\nuniform sampler2D uSource;\nuniform vec2 texelSize;\nuniform float uDt;\nuniform float uDissipation;\nvoid main () {\n  vec2 coord = vUv - uDt * texture(uVelocity, vUv).xy * texelSize;\n  outColor = uDissipation * texture(uSource, coord);\n  outColor.a = 1.0;\n}`\n\nconst FRAG_CLEAR = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nout vec4 outColor;\nuniform sampler2D uTexture;\nuniform float uValue;\nvoid main () {\n  outColor = uValue * texture(uTexture, vUv);\n}`\n\nconst FRAG_DIVERGENCE = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nin vec2 vL;\nin vec2 vR;\nin vec2 vT;\nin vec2 vB;\nout vec4 outColor;\nuniform sampler2D uVelocity;\nvoid main () {\n  float L = texture(uVelocity, vL).x;\n  float R = texture(uVelocity, vR).x;\n  float T = texture(uVelocity, vT).y;\n  float B = texture(uVelocity, vB).y;\n  vec2 C = texture(uVelocity, vUv).xy;\n  if (vL.x < 0.0) { L = -C.x; }\n  if (vR.x > 1.0) { R = -C.x; }\n  if (vT.y > 1.0) { T = -C.y; }\n  if (vB.y < 0.0) { B = -C.y; }\n  float div = 0.5 * (R - L + T - B);\n  outColor = vec4(div, 0.0, 0.0, 1.0);\n}`\n\nconst FRAG_CURL = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nin vec2 vL;\nin vec2 vR;\nin vec2 vT;\nin vec2 vB;\nout vec4 outColor;\nuniform sampler2D uVelocity;\nvoid main () {\n  float L = texture(uVelocity, vL).y;\n  float R = texture(uVelocity, vR).y;\n  float T = texture(uVelocity, vT).x;\n  float B = texture(uVelocity, vB).x;\n  float vorticity = R - L - T + B;\n  outColor = vec4(vorticity, 0.0, 0.0, 1.0);\n}`\n\nconst FRAG_VORTICITY = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nin vec2 vL;\nin vec2 vR;\nin vec2 vT;\nin vec2 vB;\nout vec4 outColor;\nuniform sampler2D uVelocity;\nuniform sampler2D uCurl;\nuniform float uCurlStrength;\nuniform float uDt;\nvoid main () {\n  float L = texture(uCurl, vL).x;\n  float R = texture(uCurl, vR).x;\n  float T = texture(uCurl, vT).x;\n  float B = texture(uCurl, vB).x;\n  float C = texture(uCurl, vUv).x;\n  vec2 force = vec2(abs(T) - abs(B), abs(R) - abs(L)) * 0.5;\n  force /= length(force) + 1.0;\n  force *= uCurlStrength * C;\n  force.y *= -1.0;\n  vec2 velocity = texture(uVelocity, vUv).xy;\n  outColor = vec4(velocity + force * uDt, 0.0, 1.0);\n}`\n\nconst FRAG_PRESSURE = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nin vec2 vL;\nin vec2 vR;\nin vec2 vT;\nin vec2 vB;\nout vec4 outColor;\nuniform sampler2D uPressure;\nuniform sampler2D uDivergence;\nvoid main () {\n  float L = texture(uPressure, vL).x;\n  float R = texture(uPressure, vR).x;\n  float T = texture(uPressure, vT).x;\n  float B = texture(uPressure, vB).x;\n  float divergence = texture(uDivergence, vUv).x;\n  float pressure = (L + R + B + T - divergence) * 0.25;\n  outColor = vec4(pressure, 0.0, 0.0, 1.0);\n}`\n\nconst FRAG_GRADIENT = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nin vec2 vL;\nin vec2 vR;\nin vec2 vT;\nin vec2 vB;\nout vec4 outColor;\nuniform sampler2D uPressure;\nuniform sampler2D uVelocity;\nvoid main () {\n  float L = texture(uPressure, vL).x;\n  float R = texture(uPressure, vR).x;\n  float T = texture(uPressure, vT).x;\n  float B = texture(uPressure, vB).x;\n  vec2 velocity = texture(uVelocity, vUv).xy;\n  velocity.xy -= vec2(R - L, T - B);\n  outColor = vec4(velocity, 0.0, 1.0);\n}`\n\ninterface Target {\n  fbo: WebGLFramebuffer\n  texture: WebGLTexture\n  width: number\n  height: number\n}\n\ninterface DoubleTarget {\n  read: Target\n  write: Target\n  swap: () => void\n}\n\nconst FRAG_BRIGHT = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nout vec4 outColor;\nuniform sampler2D uScene;\nvoid main () {\n  vec3 c = texture(uScene, vUv).rgb;\n  float l = dot(c, vec3(0.299, 0.587, 0.114));\n  outColor = vec4(c * smoothstep(0.55, 0.95, l), 1.0);\n}`\n\nconst FRAG_BLUR = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nout vec4 outColor;\nuniform sampler2D uScene;\nuniform vec2 uDir;\nvoid main () {\n  vec3 c = texture(uScene, vUv).rgb * 0.227027;\n  c += texture(uScene, vUv + uDir * 1.3846154).rgb * 0.3162162;\n  c += texture(uScene, vUv - uDir * 1.3846154).rgb * 0.3162162;\n  c += texture(uScene, vUv + uDir * 3.2307692).rgb * 0.0702703;\n  c += texture(uScene, vUv - uDir * 3.2307692).rgb * 0.0702703;\n  outColor = vec4(c, 1.0);\n}`\n\nconst FRAG_COMPOSITE = `#version 300 es\nprecision highp float;\nin vec2 vUv;\nout vec4 outColor;\nuniform sampler2D uScene;\nuniform sampler2D uBloomTex;\nuniform float uBloomAmt;\nuniform float uGrainAmt;\nuniform float uTime;\nvoid main () {\n  vec4 scene = texture(uScene, vUv);\n  vec3 bloom = texture(uBloomTex, vUv).rgb * uBloomAmt;\n  vec3 col = scene.rgb + bloom;\n  float g = fract(sin(dot(gl_FragCoord.xy + vec2(uTime * 61.7, uTime * 123.4),\n    vec2(12.9898, 78.233))) * 43758.5453) - 0.5;\n  col += g * uGrainAmt * 0.14;\n  float ba = dot(bloom, vec3(0.333));\n  outColor = vec4(col, clamp(scene.a + ba, 0.0, 1.0));\n}`\n\nconst SIM_RES = 96\nconst FLOW_RES = 256\nconst SIM_DT = 1 / 60\nconst VELOCITY_DISSIPATION = 0.985\nconst PRESSURE_DECAY = 0.8\nconst PRESSURE_ITERATIONS = 4\n\nexport function supportsHtmlInCanvas(): boolean {\n  if (typeof document === \"undefined\") return false\n  const probe = document.createElement(\"canvas\") as PaintableCanvas\n  const ctx = probe.getContext(\"2d\") as ElementImageContext | null\n  return Boolean(\n    ctx &&\n    typeof ctx.drawElementImage === \"function\" &&\n    typeof probe.requestPaint === \"function\"\n  )\n}\n\nconst HOVER_ATTR = \"data-canvasui-hover\"\nconst CONTENT_ATTR = \"data-canvasui-content\"\nconst HOVER_REWRITE = `:is([${HOVER_ATTR}], :hover:where(:not([${CONTENT_ATTR}], [${CONTENT_ATTR}] *)))`\n\nfunction patchHoverRules() {\n  if (typeof document === \"undefined\") return\n  if (document.documentElement.dataset.canvasuiHoverRules === \"\") return\n  document.documentElement.dataset.canvasuiHoverRules = \"\"\n  const walk = (rules: CSSRuleList) => {\n    for (const rule of Array.from(rules)) {\n      if (rule instanceof CSSStyleRule) {\n        if (rule.selectorText.includes(\":hover\")) {\n          try {\n            rule.selectorText = rule.selectorText.replace(\n              /:hover\\b/g,\n              HOVER_REWRITE\n            )\n          } catch {}\n        }\n        if (rule.cssRules.length) walk(rule.cssRules)\n      } else if (\"cssRules\" in rule) {\n        try {\n          walk((rule as CSSGroupingRule).cssRules)\n        } catch {}\n      }\n    }\n  }\n  for (const sheet of Array.from(document.styleSheets)) {\n    try {\n      walk(sheet.cssRules)\n    } catch {}\n  }\n  const style = document.createElement(\"style\")\n  style.textContent = `[${CONTENT_ATTR}], [${CONTENT_ATTR}] * { cursor: var(--canvasui-cursor, auto) !important; }`\n  document.head.appendChild(style)\n}\n\nexport function createHexFloat(\n  elements: HexFloatElements,\n  options: HexFloatOptions = {}\n): HexFloatInstance | null {\n  const config = { ...DEFAULTS, ...options }\n  const { source, content, output } = elements\n\n  const gl = output.getContext(\"webgl2\", {\n    alpha: true,\n    depth: false,\n    stencil: false,\n    antialias: false,\n    premultipliedAlpha: true,\n  })\n  if (!gl || gl.isContextLost()) return null\n\n  const sourceCtx = source.getContext(\"2d\") as ElementImageContext | null\n  const paintable = source as PaintableCanvas\n  const htmlInCanvas = Boolean(\n    sourceCtx &&\n    typeof sourceCtx.drawElementImage === \"function\" &&\n    typeof paintable.requestPaint === \"function\"\n  )\n\n  let contentDirty = false\n  let wake = () => {}\n\n  if (htmlInCanvas) {\n    paintable.onpaint = () => {\n      try {\n        sourceCtx!.reset()\n        sourceCtx!.drawElementImage!(content, 0, 0)\n        // Register hit-test geometry so links/buttons under the canvas get clicks.\n        paintable.updateElementGeometry?.(content)\n        contentDirty = true\n        wake()\n      } catch {}\n    }\n  }\n\n  function compile(type: number, text: string): WebGLShader {\n    const shader = gl!.createShader(type)!\n    gl!.shaderSource(shader, text)\n    gl!.compileShader(shader)\n    if (!gl!.getShaderParameter(shader, gl!.COMPILE_STATUS)) {\n      console.error(\"HexFloat shader error:\", gl!.getShaderInfoLog(shader))\n    }\n    return shader\n  }\n\n  const vertexShader = compile(gl.VERTEX_SHADER, VERT)\n  const fragmentShader = compile(gl.FRAGMENT_SHADER, FRAG)\n  const program = gl.createProgram()!\n  gl.attachShader(program, vertexShader)\n  gl.attachShader(program, fragmentShader)\n  gl.linkProgram(program)\n\n  const uniforms: Record<string, WebGLUniformLocation> = {}\n  const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS)\n  for (let i = 0; i < count; i++) {\n    const info = gl.getActiveUniform(program, i)!\n    uniforms[info.name.replace(\"[0]\", \"\")] = gl.getUniformLocation(\n      program,\n      info.name\n    )!\n  }\n\n  const quad = gl.createBuffer()\n  gl.bindBuffer(gl.ARRAY_BUFFER, quad)\n  gl.bufferData(\n    gl.ARRAY_BUFFER,\n    new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),\n    gl.STATIC_DRAW\n  )\n  gl.enableVertexAttribArray(0)\n  gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0)\n\n  gl.getExtension(\"EXT_color_buffer_float\")\n  const supportsLinear = Boolean(gl.getExtension(\"OES_texture_float_linear\"))\n  const filtering = supportsLinear ? gl.LINEAR : gl.NEAREST\n\n  const simShaders: WebGLShader[] = []\n  const simPrograms: WebGLProgram[] = []\n\n  function compileSim(type: number, text: string): WebGLShader {\n    const shader = compile(type, text)\n    simShaders.push(shader)\n    return shader\n  }\n\n  const simVertexShader = compileSim(gl.VERTEX_SHADER, SIM_VERT)\n\n  interface SimProgram {\n    program: WebGLProgram\n    uniforms: Record<string, WebGLUniformLocation>\n  }\n\n  function createSimProgram(fragSource: string): SimProgram {\n    const prog = gl!.createProgram()!\n    gl!.attachShader(prog, simVertexShader)\n    gl!.attachShader(prog, compileSim(gl!.FRAGMENT_SHADER, fragSource))\n    gl!.linkProgram(prog)\n    simPrograms.push(prog)\n    const u: Record<string, WebGLUniformLocation> = {}\n    const n = gl!.getProgramParameter(prog, gl!.ACTIVE_UNIFORMS)\n    for (let i = 0; i < n; i++) {\n      const info = gl!.getActiveUniform(prog, i)!\n      u[info.name] = gl!.getUniformLocation(prog, info.name)!\n    }\n    return { program: prog, uniforms: u }\n  }\n\n  const splatProgram = createSimProgram(FRAG_SPLAT)\n  const advectProgram = createSimProgram(FRAG_ADVECT)\n  const clearProgram = createSimProgram(FRAG_CLEAR)\n  const divergenceProgram = createSimProgram(FRAG_DIVERGENCE)\n  const curlProgram = createSimProgram(FRAG_CURL)\n  const vorticityProgram = createSimProgram(FRAG_VORTICITY)\n  const pressureProgram = createSimProgram(FRAG_PRESSURE)\n  const gradientProgram = createSimProgram(FRAG_GRADIENT)\n\n  function createTarget(\n    size: number,\n    internalFormat: number,\n    format: number,\n    filter: number\n  ): Target {\n    const texture = gl!.createTexture()!\n    gl!.bindTexture(gl!.TEXTURE_2D, texture)\n    gl!.texParameteri(gl!.TEXTURE_2D, gl!.TEXTURE_MIN_FILTER, filter)\n    gl!.texParameteri(gl!.TEXTURE_2D, gl!.TEXTURE_MAG_FILTER, filter)\n    gl!.texParameteri(gl!.TEXTURE_2D, gl!.TEXTURE_WRAP_S, gl!.CLAMP_TO_EDGE)\n    gl!.texParameteri(gl!.TEXTURE_2D, gl!.TEXTURE_WRAP_T, gl!.CLAMP_TO_EDGE)\n    gl!.texImage2D(\n      gl!.TEXTURE_2D,\n      0,\n      internalFormat,\n      size,\n      size,\n      0,\n      format,\n      gl!.HALF_FLOAT,\n      null\n    )\n    const fbo = gl!.createFramebuffer()!\n    gl!.bindFramebuffer(gl!.FRAMEBUFFER, fbo)\n    gl!.framebufferTexture2D(\n      gl!.FRAMEBUFFER,\n      gl!.COLOR_ATTACHMENT0,\n      gl!.TEXTURE_2D,\n      texture,\n      0\n    )\n    gl!.viewport(0, 0, size, size)\n    gl!.clearColor(0, 0, 0, 1)\n    gl!.clear(gl!.COLOR_BUFFER_BIT)\n    return { fbo, texture, width: size, height: size }\n  }\n\n  function createDoubleTarget(\n    size: number,\n    internalFormat: number,\n    format: number,\n    filter: number\n  ): DoubleTarget {\n    let read = createTarget(size, internalFormat, format, filter)\n    let write = createTarget(size, internalFormat, format, filter)\n    return {\n      get read() {\n        return read\n      },\n      get write() {\n        return write\n      },\n      swap() {\n        const t = read\n        read = write\n        write = t\n      },\n    }\n  }\n\n  const velocity = createDoubleTarget(SIM_RES, gl.RG16F, gl.RG, filtering)\n  const flow = createDoubleTarget(FLOW_RES, gl.R16F, gl.RED, filtering)\n  const divergence = createTarget(SIM_RES, gl.R16F, gl.RED, gl.NEAREST)\n  const curl = createTarget(SIM_RES, gl.R16F, gl.RED, gl.NEAREST)\n  const pressure = createDoubleTarget(SIM_RES, gl.R16F, gl.RED, gl.NEAREST)\n  const simTexel = 1 / SIM_RES\n\n  function releaseSim() {\n    ;[\n      velocity.read,\n      velocity.write,\n      flow.read,\n      flow.write,\n      pressure.read,\n      pressure.write,\n      divergence,\n      curl,\n    ].forEach((t) => {\n      gl!.deleteFramebuffer(t.fbo)\n      gl!.deleteTexture(t.texture)\n    })\n    simPrograms.forEach((p) => gl!.deleteProgram(p))\n    simShaders.forEach((s) => gl!.deleteShader(s))\n  }\n\n  function blit(target: Target) {\n    gl!.bindFramebuffer(gl!.FRAMEBUFFER, target.fbo)\n    gl!.viewport(0, 0, target.width, target.height)\n    gl!.drawArrays(gl!.TRIANGLE_STRIP, 0, 4)\n  }\n\n  function bindSimTexture(texture: WebGLTexture, unit: number): number {\n    gl!.activeTexture(gl!.TEXTURE0 + unit)\n    gl!.bindTexture(gl!.TEXTURE_2D, texture)\n    return unit\n  }\n\n  function applySplat(\n    x: number,\n    y: number,\n    dx: number,\n    dy: number,\n    dye: number\n  ) {\n    const aspect = output.clientWidth / Math.max(output.clientHeight, 1)\n    const rUv = Math.max(config.radius, 40) / Math.max(output.clientHeight, 1)\n    const radius = rUv * rUv * 0.28\n\n    gl!.useProgram(splatProgram.program)\n    gl!.uniform1f(splatProgram.uniforms.uAspect, aspect)\n    gl!.uniform2f(splatProgram.uniforms.uPoint, x, y)\n    gl!.uniform1f(splatProgram.uniforms.uRadius, radius)\n    gl!.uniform1i(\n      splatProgram.uniforms.uTarget,\n      bindSimTexture(velocity.read.texture, 0)\n    )\n    gl!.uniform3f(splatProgram.uniforms.uColor, dx, dy, 0)\n    blit(velocity.write)\n    velocity.swap()\n\n    gl!.uniform1i(\n      splatProgram.uniforms.uTarget,\n      bindSimTexture(flow.read.texture, 0)\n    )\n    gl!.uniform3f(splatProgram.uniforms.uColor, dye, 0, 0)\n    blit(flow.write)\n    flow.swap()\n  }\n\n  function stepSim(delta: number) {\n    gl!.disable(gl!.BLEND)\n\n    gl!.useProgram(curlProgram.program)\n    gl!.uniform2f(curlProgram.uniforms.texelSize, simTexel, simTexel)\n    gl!.uniform1i(\n      curlProgram.uniforms.uVelocity,\n      bindSimTexture(velocity.read.texture, 0)\n    )\n    blit(curl)\n\n    gl!.useProgram(vorticityProgram.program)\n    gl!.uniform2f(vorticityProgram.uniforms.texelSize, simTexel, simTexel)\n    gl!.uniform1i(\n      vorticityProgram.uniforms.uVelocity,\n      bindSimTexture(velocity.read.texture, 0)\n    )\n    gl!.uniform1i(\n      vorticityProgram.uniforms.uCurl,\n      bindSimTexture(curl.texture, 1)\n    )\n    gl!.uniform1f(\n      vorticityProgram.uniforms.uCurlStrength,\n      Math.max(config.swirl, 0)\n    )\n    gl!.uniform1f(vorticityProgram.uniforms.uDt, SIM_DT)\n    blit(velocity.write)\n    velocity.swap()\n\n    gl!.useProgram(divergenceProgram.program)\n    gl!.uniform2f(divergenceProgram.uniforms.texelSize, simTexel, simTexel)\n    gl!.uniform1i(\n      divergenceProgram.uniforms.uVelocity,\n      bindSimTexture(velocity.read.texture, 0)\n    )\n    blit(divergence)\n\n    gl!.useProgram(clearProgram.program)\n    gl!.uniform1i(\n      clearProgram.uniforms.uTexture,\n      bindSimTexture(pressure.read.texture, 0)\n    )\n    gl!.uniform1f(\n      clearProgram.uniforms.uValue,\n      Math.pow(PRESSURE_DECAY, delta * 60)\n    )\n    blit(pressure.write)\n    pressure.swap()\n\n    gl!.useProgram(pressureProgram.program)\n    gl!.uniform2f(pressureProgram.uniforms.texelSize, simTexel, simTexel)\n    gl!.uniform1i(\n      pressureProgram.uniforms.uDivergence,\n      bindSimTexture(divergence.texture, 0)\n    )\n    for (let i = 0; i < PRESSURE_ITERATIONS; i++) {\n      gl!.uniform1i(\n        pressureProgram.uniforms.uPressure,\n        bindSimTexture(pressure.read.texture, 1)\n      )\n      blit(pressure.write)\n      pressure.swap()\n    }\n\n    gl!.useProgram(gradientProgram.program)\n    gl!.uniform2f(gradientProgram.uniforms.texelSize, simTexel, simTexel)\n    gl!.uniform1i(\n      gradientProgram.uniforms.uPressure,\n      bindSimTexture(pressure.read.texture, 0)\n    )\n    gl!.uniform1i(\n      gradientProgram.uniforms.uVelocity,\n      bindSimTexture(velocity.read.texture, 1)\n    )\n    blit(velocity.write)\n    velocity.swap()\n\n    gl!.useProgram(advectProgram.program)\n    gl!.uniform2f(advectProgram.uniforms.texelSize, simTexel, simTexel)\n    gl!.uniform1i(\n      advectProgram.uniforms.uVelocity,\n      bindSimTexture(velocity.read.texture, 0)\n    )\n    gl!.uniform1i(\n      advectProgram.uniforms.uSource,\n      bindSimTexture(velocity.read.texture, 0)\n    )\n    gl!.uniform1f(advectProgram.uniforms.uDt, SIM_DT)\n    gl!.uniform1f(\n      advectProgram.uniforms.uDissipation,\n      Math.pow(VELOCITY_DISSIPATION, delta * 60)\n    )\n    blit(velocity.write)\n    velocity.swap()\n\n    gl!.uniform1i(\n      advectProgram.uniforms.uVelocity,\n      bindSimTexture(velocity.read.texture, 0)\n    )\n    gl!.uniform1i(\n      advectProgram.uniforms.uSource,\n      bindSimTexture(flow.read.texture, 1)\n    )\n    const flowDissipation = 0.9 + Math.min(Math.max(config.trail, 0), 1) * 0.08\n    gl!.uniform1f(\n      advectProgram.uniforms.uDissipation,\n      Math.pow(flowDissipation, delta * 60)\n    )\n    blit(flow.write)\n    flow.swap()\n  }\n\n  function createPostProgram(fragSource: string): SimProgram {\n    const prog = gl!.createProgram()!\n    gl!.attachShader(prog, vertexShader)\n    gl!.attachShader(prog, compileSim(gl!.FRAGMENT_SHADER, fragSource))\n    gl!.linkProgram(prog)\n    simPrograms.push(prog)\n    const u: Record<string, WebGLUniformLocation> = {}\n    const n = gl!.getProgramParameter(prog, gl!.ACTIVE_UNIFORMS)\n    for (let i = 0; i < n; i++) {\n      const info = gl!.getActiveUniform(prog, i)!\n      u[info.name] = gl!.getUniformLocation(prog, info.name)!\n    }\n    return { program: prog, uniforms: u }\n  }\n\n  const brightProgram = createPostProgram(FRAG_BRIGHT)\n  const blurProgram = createPostProgram(FRAG_BLUR)\n  const compositeProgram = createPostProgram(FRAG_COMPOSITE)\n\n  let sceneTarget: Target | null = null\n  let bloomA: Target | null = null\n  let bloomB: Target | null = null\n\n  function createPostTarget(width: number, height: number): Target {\n    const texture = gl!.createTexture()!\n    gl!.bindTexture(gl!.TEXTURE_2D, texture)\n    gl!.texParameteri(gl!.TEXTURE_2D, gl!.TEXTURE_MIN_FILTER, gl!.LINEAR)\n    gl!.texParameteri(gl!.TEXTURE_2D, gl!.TEXTURE_MAG_FILTER, gl!.LINEAR)\n    gl!.texParameteri(gl!.TEXTURE_2D, gl!.TEXTURE_WRAP_S, gl!.CLAMP_TO_EDGE)\n    gl!.texParameteri(gl!.TEXTURE_2D, gl!.TEXTURE_WRAP_T, gl!.CLAMP_TO_EDGE)\n    gl!.texImage2D(\n      gl!.TEXTURE_2D,\n      0,\n      gl!.RGBA8,\n      width,\n      height,\n      0,\n      gl!.RGBA,\n      gl!.UNSIGNED_BYTE,\n      null\n    )\n    const fbo = gl!.createFramebuffer()!\n    gl!.bindFramebuffer(gl!.FRAMEBUFFER, fbo)\n    gl!.framebufferTexture2D(\n      gl!.FRAMEBUFFER,\n      gl!.COLOR_ATTACHMENT0,\n      gl!.TEXTURE_2D,\n      texture,\n      0\n    )\n    return { fbo, texture, width, height }\n  }\n\n  function releasePost() {\n    ;[sceneTarget, bloomA, bloomB].forEach((t) => {\n      if (!t) return\n      gl!.deleteFramebuffer(t.fbo)\n      gl!.deleteTexture(t.texture)\n    })\n    sceneTarget = null\n    bloomA = null\n    bloomB = null\n  }\n\n  function ensurePost() {\n    const w = output.width\n    const h = output.height\n    if (sceneTarget && sceneTarget.width === w && sceneTarget.height === h) {\n      return\n    }\n    releasePost()\n    sceneTarget = createPostTarget(w, h)\n    const bw = Math.max(1, w >> 2)\n    const bh = Math.max(1, h >> 2)\n    bloomA = createPostTarget(bw, bh)\n    bloomB = createPostTarget(bw, bh)\n  }\n\n  const contentTexture = gl.createTexture()!\n  gl.bindTexture(gl.TEXTURE_2D, contentTexture)\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)\n  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)\n  gl.texImage2D(\n    gl.TEXTURE_2D,\n    0,\n    gl.RGBA,\n    1,\n    1,\n    0,\n    gl.RGBA,\n    gl.UNSIGNED_BYTE,\n    new Uint8Array([0, 0, 0, 0])\n  )\n\n  let contentMaxX = 1\n\n  let bg: [number, number, number] = [1, 1, 1]\n  const bgProbe = document.createElement(\"canvas\")\n  bgProbe.width = bgProbe.height = 1\n  const bgCtx = bgProbe.getContext(\"2d\", { willReadFrequently: true })\n\n  function syncBgColor() {\n    if (!bgCtx) return\n    let el: Element | null = content\n    while (el) {\n      const css = getComputedStyle(el).backgroundColor\n      if (css && css !== \"transparent\") {\n        bgCtx.clearRect(0, 0, 1, 1)\n        bgCtx.fillStyle = css\n        bgCtx.fillRect(0, 0, 1, 1)\n        const [r, g, b, a] = bgCtx.getImageData(0, 0, 1, 1).data\n        if (a > 0) {\n          bg = [r / 255, g / 255, b / 255]\n          return\n        }\n      }\n      el = el.parentElement\n    }\n    bg = [1, 1, 1]\n  }\n\n  function syncCanvasSize() {\n    const dpr = Math.min(window.devicePixelRatio || 1, 2)\n    const width = Math.max(1, Math.round(output.clientWidth * dpr))\n    const height = Math.max(1, Math.round(output.clientHeight * dpr))\n    if (output.width !== width || output.height !== height) {\n      output.width = width\n      output.height = height\n    }\n    contentMaxX = Math.min(\n      1,\n      Math.max(0.05, content.clientWidth / Math.max(output.clientWidth, 1))\n    )\n    if (htmlInCanvas) {\n      const cssWidth = Math.max(1, Math.round(source.clientWidth))\n      const cssHeight = Math.max(1, Math.round(source.clientHeight))\n      if (\n        source.width !== cssWidth * dpr ||\n        source.height !== cssHeight * dpr\n      ) {\n        source.width = cssWidth * dpr\n        source.height = cssHeight * dpr\n      }\n      paintable.requestPaint!()\n    }\n  }\n\n  syncBgColor()\n  syncCanvasSize()\n\n  function uploadContent() {\n    if (!htmlInCanvas || !contentDirty) return\n    contentDirty = false\n    gl!.bindTexture(gl!.TEXTURE_2D, contentTexture)\n    gl!.texImage2D(\n      gl!.TEXTURE_2D,\n      0,\n      gl!.RGBA,\n      gl!.RGBA,\n      gl!.UNSIGNED_BYTE,\n      source\n    )\n  }\n\n  let time = 0\n  let pointerOn = false\n  let pointerClientX = 0\n  let pointerClientY = 0\n  let prevFlowX = 0\n  let prevFlowY = 0\n  let hasPrevFlow = false\n  let simActiveUntil = 0\n\n  function gapColor(): [number, number, number] {\n    if (config.gapColor !== \"auto\") return config.gapColor\n    const lum = 0.2126 * bg[0] + 0.7152 * bg[1] + 0.0722 * bg[2]\n    const k = lum > 0.5 ? 0.55 : 0.35\n    return [bg[0] * k, bg[1] * k, bg[2] * k]\n  }\n\n  function render() {\n    uploadContent()\n    const dpr = output.width / Math.max(output.clientWidth, 1)\n    const seam = gapColor()\n    gl!.useProgram(program)\n    gl!.activeTexture(gl!.TEXTURE0)\n    gl!.bindTexture(gl!.TEXTURE_2D, contentTexture)\n    gl!.uniform1i(uniforms.uContent, 0)\n    gl!.uniform2f(uniforms.uRes, output.width, output.height)\n    gl!.uniform1f(uniforms.uSize, Math.max(config.size, 8) * dpr)\n    gl!.uniform1f(uniforms.uGap, Math.max(config.gap, 0) * dpr)\n    gl!.uniform1f(uniforms.uBevel, Math.max(config.bevel, 0) * dpr)\n    gl!.uniform1f(\n      uniforms.uTilt,\n      (Math.min(Math.max(config.tilt, -30), 30) * Math.PI) / 180\n    )\n    gl!.uniform1f(\n      uniforms.uDist,\n      2.6 - Math.min(Math.max(config.perspective, 0), 1) * 2.2\n    )\n    gl!.uniform1f(uniforms.uFloat, Math.max(config.float, 0))\n    gl!.uniform1f(uniforms.uShine, Math.max(config.shine, 0))\n    gl!.uniform1f(uniforms.uLift, Math.max(config.lift, 0))\n    gl!.uniform1f(uniforms.uIrid, Math.max(config.iridescence, 0))\n    gl!.activeTexture(gl!.TEXTURE1)\n    gl!.bindTexture(gl!.TEXTURE_2D, flow.read.texture)\n    gl!.uniform1i(uniforms.uFlow, 1)\n    gl!.uniform2f(\n      uniforms.uScroll,\n      content.scrollLeft * dpr,\n      content.scrollTop * dpr\n    )\n    gl!.uniform1f(uniforms.uTime, time)\n    gl!.uniform1f(uniforms.uHasContent, htmlInCanvas ? 1 : 0)\n    gl!.uniform1f(uniforms.uMaxX, contentMaxX)\n    gl!.uniform3f(uniforms.uBg, bg[0], bg[1], bg[2])\n    gl!.uniform3f(uniforms.uGapColor, seam[0], seam[1], seam[2])\n\n    const bloomOn = config.bloom > 0.001\n    const usePost = bloomOn || config.grain > 0.001\n    if (!usePost) {\n      gl!.bindFramebuffer(gl!.FRAMEBUFFER, null)\n      gl!.viewport(0, 0, output.width, output.height)\n      gl!.drawArrays(gl!.TRIANGLE_STRIP, 0, 4)\n      return\n    }\n\n    ensurePost()\n    blit(sceneTarget!)\n\n    if (bloomOn) {\n      gl!.useProgram(brightProgram.program)\n      gl!.uniform1i(\n        brightProgram.uniforms.uScene,\n        bindSimTexture(sceneTarget!.texture, 0)\n      )\n      blit(bloomA!)\n\n      gl!.useProgram(blurProgram.program)\n      gl!.uniform1i(\n        blurProgram.uniforms.uScene,\n        bindSimTexture(bloomA!.texture, 0)\n      )\n      gl!.uniform2f(blurProgram.uniforms.uDir, 1 / bloomA!.width, 0)\n      blit(bloomB!)\n      gl!.uniform1i(\n        blurProgram.uniforms.uScene,\n        bindSimTexture(bloomB!.texture, 0)\n      )\n      gl!.uniform2f(blurProgram.uniforms.uDir, 0, 1 / bloomA!.height)\n      blit(bloomA!)\n    }\n\n    gl!.useProgram(compositeProgram.program)\n    gl!.uniform1i(\n      compositeProgram.uniforms.uScene,\n      bindSimTexture(sceneTarget!.texture, 0)\n    )\n    gl!.uniform1i(\n      compositeProgram.uniforms.uBloomTex,\n      bindSimTexture((bloomA ?? sceneTarget)!.texture, 1)\n    )\n    gl!.uniform1f(\n      compositeProgram.uniforms.uBloomAmt,\n      bloomOn ? Math.min(Math.max(config.bloom, 0), 1) * 1.4 : 0\n    )\n    gl!.uniform1f(\n      compositeProgram.uniforms.uGrainAmt,\n      Math.min(Math.max(config.grain, 0), 1)\n    )\n    gl!.uniform1f(compositeProgram.uniforms.uTime, time)\n    gl!.bindFramebuffer(gl!.FRAMEBUFFER, null)\n    gl!.viewport(0, 0, output.width, output.height)\n    gl!.drawArrays(gl!.TRIANGLE_STRIP, 0, 4)\n  }\n\n  let raf = 0\n  let lastTime = performance.now()\n  let destroyed = false\n  let running = false\n  let visible = true\n\n  const motionQuery = window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n  let reducedMotion = motionQuery.matches\n\n  function animating(): boolean {\n    if (reducedMotion) return false\n    if (config.float > 0) return true\n    if (config.grain > 0.001) return true\n    if (pointerOn) return true\n    if (performance.now() < simActiveUntil) return true\n    return false\n  }\n\n  function frame(now: number) {\n    if (destroyed) return\n    if (!visible) {\n      running = false\n      return\n    }\n    const delta = Math.min(Math.max((now - lastTime) / 1000, 0), 1 / 30)\n    lastTime = now\n    if (!reducedMotion) {\n      time += delta * Math.max(config.speed, 0)\n      if (pointerOn) {\n        const p = contentPoint(pointerClientX, pointerClientY)\n        if (p) {\n          const w = Math.max(output.clientWidth, 1)\n          const h = Math.max(output.clientHeight, 1)\n          const fx = p.x / w\n          const fy = p.y / h\n          const dx = hasPrevFlow ? (fx - prevFlowX) * w : 0\n          const dy = hasPrevFlow ? (fy - prevFlowY) * h : 0\n          const push = 1.6 * Math.max(config.flow, 0)\n          applySplat(fx, fy, dx * push, dy * push, 10 * delta)\n          prevFlowX = fx\n          prevFlowY = fy\n          hasPrevFlow = true\n          simActiveUntil = now + 4000\n        }\n      }\n      if (now < simActiveUntil || pointerOn) stepSim(delta)\n    }\n    render()\n    if (!animating() && !contentDirty) {\n      running = false\n      return\n    }\n    raf = requestAnimationFrame(frame)\n  }\n\n  function start() {\n    if (destroyed || running || !visible) return\n    running = true\n    lastTime = performance.now()\n    raf = requestAnimationFrame(frame)\n  }\n\n  wake = start\n  start()\n\n  function onPointerMove(event: PointerEvent) {\n    pointerClientX = event.clientX\n    pointerClientY = event.clientY\n    pointerOn = true\n    simActiveUntil = performance.now() + 4000\n    updateHover(event.clientX, event.clientY)\n    start()\n  }\n\n  function onPointerLeave() {\n    pointerOn = false\n    hasPrevFlow = false\n    setHoverTarget(null)\n    start()\n  }\n\n  content.addEventListener(\"pointermove\", onPointerMove, { passive: true })\n  content.addEventListener(\"pointerleave\", onPointerLeave, { passive: true })\n\n  function onScroll() {\n    if (pointerOn) updateHover(pointerClientX, pointerClientY)\n    start()\n  }\n  content.addEventListener(\"scroll\", onScroll, { passive: true })\n\n  function contentPoint(\n    clientX: number,\n    clientY: number\n  ): { x: number; y: number } | null {\n    const rect = output.getBoundingClientRect()\n    const dpr = output.width / Math.max(output.clientWidth, 1)\n    const w = output.width\n    const hPx = output.height\n    if (w < 1 || hPx < 1) return null\n    const sx = (clientX - rect.left) * dpr\n    const sy = (clientY - rect.top) * dpr\n    const aspect = w / hPx\n    const ndcX = ((sx / w) * 2 - 1) * aspect\n    const ndcY = (sy / hPx) * 2 - 1\n    const tilt = (Math.min(Math.max(config.tilt, -30), 30) * Math.PI) / 180\n    const sa = Math.sin(tilt)\n    const ca = Math.cos(tilt)\n    const cell = Math.max(config.size, 8) * dpr\n    const h = hPx / cell\n    const dist = 2.6 - Math.min(Math.max(config.perspective, 0), 1) * 2.2\n    const d = h * dist\n    const focal = (d + Math.sqrt(d * d + h * h * sa * sa)) / (h * ca)\n    const dy =\n      0.5 * h - sa * d - (ca * d * (ca - focal * sa)) / (sa + focal * ca)\n    const scrollX = content.scrollLeft * dpr\n    const scrollY = content.scrollTop * dpr\n    const roX = scrollX / cell + (0.5 * w) / cell\n    const roY = scrollY / cell + 0.5 * h + dy + sa * d\n    const roZ = -ca * d\n    const rdX = ndcX\n    const rdY = ndcY * ca - focal * sa\n    const rdZ = ndcY * sa + focal * ca\n    if (rdZ < 1e-6) return null\n    const t = -roZ / rdZ\n    const px = (roX + rdX * t) * cell - scrollX\n    const py = (roY + rdY * t) * cell - scrollY\n    return { x: px / dpr, y: py / dpr }\n  }\n\n  let forwarding = false\n\n  let hoverChain: Element[] = []\n  let hoverTarget: Element | null = null\n\n  if (htmlInCanvas) {\n    patchHoverRules()\n    content.setAttribute(CONTENT_ATTR, \"\")\n  }\n\n  function setHoverTarget(target: Element | null) {\n    if (target === hoverTarget) return\n    hoverTarget = target\n    const next = new Set<Element>()\n    for (let el: Element | null = target; el; el = el.parentElement) {\n      next.add(el)\n      if (el === content) break\n    }\n    for (const el of hoverChain) {\n      if (!next.has(el)) el.removeAttribute(HOVER_ATTR)\n    }\n    for (const el of next) el.setAttribute(HOVER_ATTR, \"\")\n    hoverChain = Array.from(next)\n    if (target) {\n      content.style.setProperty(\n        \"--canvasui-cursor\",\n        getComputedStyle(target).cursor\n      )\n    } else {\n      content.style.removeProperty(\"--canvasui-cursor\")\n    }\n  }\n\n  function updateHover(clientX: number, clientY: number) {\n    if (!htmlInCanvas) return\n    const p = contentPoint(clientX, clientY)\n    if (!p) {\n      setHoverTarget(null)\n      return\n    }\n    const rect = content.getBoundingClientRect()\n    const target = document.elementFromPoint(rect.left + p.x, rect.top + p.y)\n    setHoverTarget(target && content.contains(target) ? target : null)\n  }\n\n  function onClick(event: MouseEvent) {\n    if (forwarding || !htmlInCanvas) return\n    const p = contentPoint(event.clientX, event.clientY)\n    if (!p) return\n    const rect = content.getBoundingClientRect()\n    const tx = rect.left + p.x\n    const ty = rect.top + p.y\n    if (Math.hypot(tx - event.clientX, ty - event.clientY) < 1.5) return\n    event.preventDefault()\n    event.stopPropagation()\n    const target = document.elementFromPoint(tx, ty)\n    if (!target || !content.contains(target)) return\n    const focusable = target.closest<HTMLElement>(\n      \"a, button, input, select, textarea, [tabindex]\"\n    )\n    forwarding = true\n    try {\n      focusable?.focus?.()\n      target.dispatchEvent(\n        new MouseEvent(\"click\", {\n          bubbles: true,\n          cancelable: true,\n          view: window,\n          clientX: tx,\n          clientY: ty,\n          button: event.button,\n          ctrlKey: event.ctrlKey,\n          shiftKey: event.shiftKey,\n          altKey: event.altKey,\n          metaKey: event.metaKey,\n        })\n      )\n    } finally {\n      forwarding = false\n    }\n  }\n\n  content.addEventListener(\"click\", onClick, true)\n\n  function caretAt(\n    x: number,\n    y: number\n  ): { node: Node; offset: number } | null {\n    const doc = document as Document & {\n      caretPositionFromPoint?: (\n        x: number,\n        y: number\n      ) => { offsetNode: Node; offset: number } | null\n      caretRangeFromPoint?: (x: number, y: number) => Range | null\n    }\n    if (typeof doc.caretPositionFromPoint === \"function\") {\n      const c = doc.caretPositionFromPoint(x, y)\n      return c ? { node: c.offsetNode, offset: c.offset } : null\n    }\n    const r = doc.caretRangeFromPoint?.(x, y)\n    return r ? { node: r.startContainer, offset: r.startOffset } : null\n  }\n\n  function remapped(event: MouseEvent): { x: number; y: number } | null {\n    const p = contentPoint(event.clientX, event.clientY)\n    if (!p) return null\n    const rect = content.getBoundingClientRect()\n    const tx = rect.left + p.x\n    const ty = rect.top + p.y\n    if (Math.hypot(tx - event.clientX, ty - event.clientY) < 1.5) return null\n    return { x: tx, y: ty }\n  }\n\n  let selecting = false\n\n  function onMouseDown(event: MouseEvent) {\n    if (forwarding || !htmlInCanvas || event.button !== 0) return\n    const m = remapped(event)\n    if (!m) return\n    event.preventDefault()\n    const caret = caretAt(m.x, m.y)\n    if (!caret || !content.contains(caret.node)) return\n    const sel = window.getSelection()\n    if (!sel) return\n    sel.removeAllRanges()\n    sel.collapse(caret.node, caret.offset)\n    selecting = true\n  }\n\n  function onSelMove(event: MouseEvent) {\n    if (!selecting) return\n    if (!(event.buttons & 1)) {\n      selecting = false\n      return\n    }\n    const m = remapped(event)\n    const caret = m ? caretAt(m.x, m.y) : null\n    const sel = window.getSelection()\n    if (caret && sel && sel.anchorNode && content.contains(caret.node)) {\n      sel.extend(caret.node, caret.offset)\n    }\n  }\n\n  function onSelEnd() {\n    selecting = false\n  }\n\n  content.addEventListener(\"mousedown\", onMouseDown, true)\n  window.addEventListener(\"mousemove\", onSelMove, true)\n  window.addEventListener(\"mouseup\", onSelEnd, true)\n\n  function onMotionChange() {\n    reducedMotion = motionQuery.matches\n    if (reducedMotion) {\n      pointerOn = false\n      hasPrevFlow = false\n      simActiveUntil = 0\n    }\n    start()\n  }\n  motionQuery.addEventListener(\"change\", onMotionChange)\n\n  const observer = new ResizeObserver(() => {\n    syncCanvasSize()\n    start()\n  })\n  observer.observe(output)\n  observer.observe(content)\n\n  const intersection = new IntersectionObserver((entries) => {\n    visible = entries[entries.length - 1]?.isIntersecting ?? true\n    if (visible) start()\n  })\n  intersection.observe(output)\n\n  const mutation = new MutationObserver(() => {\n    syncBgColor()\n    start()\n  })\n  mutation.observe(document.documentElement, {\n    attributes: true,\n    attributeFilter: [\"class\", \"style\", \"data-theme\"],\n  })\n\n  return {\n    setOptions(next) {\n      if (\n        !Object.entries(next).some(\n          ([key, value]) => config[key as keyof HexFloatOptions] !== value\n        )\n      )\n        return\n      Object.assign(config, next)\n      start()\n    },\n    resize() {\n      syncCanvasSize()\n      start()\n    },\n    destroy() {\n      destroyed = true\n      cancelAnimationFrame(raf)\n      setHoverTarget(null)\n      content.removeAttribute(CONTENT_ATTR)\n      content.removeEventListener(\"pointermove\", onPointerMove)\n      content.removeEventListener(\"pointerleave\", onPointerLeave)\n      content.removeEventListener(\"scroll\", onScroll)\n      content.removeEventListener(\"click\", onClick, true)\n      content.removeEventListener(\"mousedown\", onMouseDown, true)\n      window.removeEventListener(\"mousemove\", onSelMove, true)\n      window.removeEventListener(\"mouseup\", onSelEnd, true)\n      observer.disconnect()\n      intersection.disconnect()\n      mutation.disconnect()\n      motionQuery.removeEventListener(\"change\", onMotionChange)\n      gl!.deleteTexture(contentTexture)\n      releaseSim()\n      releasePost()\n      gl!.deleteProgram(program)\n      gl!.deleteShader(vertexShader)\n      gl!.deleteShader(fragmentShader)\n      gl!.deleteBuffer(quad)\n      if (htmlInCanvas) paintable.onpaint = null\n    },\n  }\n}\n\nexport interface HexFloatProps extends HexFloatOptions {\n  children: ReactNode\n  className?: string\n  style?: React.CSSProperties\n}\n\nconst emptySubscribe = () => () => {}\n\nexport function HexFloat({\n  children,\n  className,\n  style,\n  ...options\n}: HexFloatProps) {\n  const sourceRef = useRef<HTMLCanvasElement>(null)\n  const contentRef = useRef<HTMLDivElement>(null)\n  const outputRef = useRef<HTMLCanvasElement>(null)\n  const instanceRef = useRef<HexFloatInstance | null>(null)\n  const [initialOptions] = useState(options)\n  const [failed, setFailed] = useState(false)\n\n  const supported = useSyncExternalStore(\n    emptySubscribe,\n    supportsHtmlInCanvas,\n    () => false\n  )\n  const native = supported && !failed\n\n  useEffect(() => {\n    const source = sourceRef.current\n    const content = contentRef.current\n    const output = outputRef.current\n    if (!source || !content || !output) return\n    instanceRef.current = createHexFloat(\n      { source, content, output },\n      initialOptions\n    )\n    // eslint-disable-next-line react-hooks/set-state-in-effect -- recover from GPU init failure\n    if (native && !instanceRef.current) setFailed(true)\n    return () => {\n      instanceRef.current?.destroy()\n      instanceRef.current = null\n    }\n  }, [initialOptions, native])\n\n  useEffect(() => {\n    instanceRef.current?.setOptions(options)\n  })\n\n  return (\n    <div className={className} style={{ position: \"relative\", ...style }}>\n      <canvas\n        ref={sourceRef}\n        // @ts-expect-error experimental html-in-canvas attribute\n        layoutsubtree=\"true\"\n        // Chrome 156+ html-in-canvas needs content=\"drawable\" for children to be\n        // hit-tested; without it links/buttons under the canvas never get clicks.\n        content=\"drawable\"\n        suppressHydrationWarning\n        style={\n          native\n            ? { position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\" }\n            : { display: \"none\" }\n        }\n      >\n        {native ? (\n          <div\n            ref={contentRef}\n            // Chrome 157+ rejects drawElementImage() on descendants without `drawable`.\n            // @ts-expect-error experimental html-in-canvas attribute\n            drawable=\"\"\n            style={{\n              position: \"relative\",\n              width: \"100%\",\n              height: \"100%\",\n              overflow: \"auto\",\n            }}\n          >\n            {children}\n          </div>\n        ) : null}\n      </canvas>\n      {!native ? (\n        <div\n          ref={contentRef}\n          style={{\n            position: \"relative\",\n            width: \"100%\",\n            height: \"100%\",\n            overflow: \"auto\",\n          }}\n        >\n          {children}\n        </div>\n      ) : null}\n      <canvas\n        ref={outputRef}\n        aria-hidden\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          width: \"100%\",\n          height: \"100%\",\n          pointerEvents: \"none\",\n        }}\n      />\n    </div>\n  )\n}\n\nexport default HexFloat\n",
      "type": "registry:component",
      "target": "components/hex-float.tsx"
    },
    {
      "path": "registry/new-york/templates/landing-page-v1/lib/site.ts",
      "content": "/**\n * Edit this file to make the landing page yours — every string on the\n * page lives here. The waitlist itself is wired in components/waitlist-panel.tsx,\n * and the brand colors in app/globals.css.\n */\nexport const site = {\n  name: \"Acme\",\n  /** One-line product promise under the brand. */\n  tagline: \"The workspace where your team and your AI agents ship as one.\",\n  /** Short unlock lines — what joining the waitlist gets you. */\n  perks: [\n    \"Early access before public launch\",\n    \"Founding-member pricing\",\n    \"Direct line to the team\",\n  ],\n} as const\n",
      "type": "registry:lib",
      "target": "lib/site.ts"
    },
    {
      "path": "registry/new-york/templates/landing-page-v1/proxy.ts",
      "content": "import { clerkMiddleware } from \"@clerk/nextjs/server\"\n\n// Public waitlist landing. /api/webhooks stays reachable because this middleware\n// does not call auth.protect() — keep it that way (or exclude the route) if you\n// add protected pages later.\nexport default clerkMiddleware()\n\nexport const config = {\n  matcher: [\n    // Skip Next.js internals and all static files, unless found in search params\n    \"/((?!_next|[^?]*\\\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)\",\n    // Always run for API routes\n    \"/(api|trpc)(.*)\",\n    // Always run for Clerk-specific frontend API routes\n    \"/__clerk/(.*)\",\n  ],\n}\n",
      "type": "registry:file",
      "target": "proxy.ts"
    },
    {
      "path": "registry/new-york/templates/landing-page-v1/.env.example",
      "content": "# Clerk keys — run `npx clerk init -y` to fill these automatically (https://clerk.com/docs/cli),\n# or grab both from https://dashboard.clerk.com/~/api-keys\n# Then enable Waitlist mode: Clerk Dashboard → Waitlist → toggle \"Enable waitlist\".\n# Until these are set, the page renders a local demo form that stores nothing.\n\nNEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=\nCLERK_SECRET_KEY=\n\n# After invite accept / sign-in, send people back to the homepage.\n# Change these to /dashboard (or similar) once you add that route.\n# Also set the same URLs in Clerk Dashboard → Account Portal → Redirects\n# so hosted invite emails don't land on accounts.dev/default-redirect.\nNEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL=/\nNEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL=/\n\n# Svix signing secret from the webhook endpoint in Clerk Dashboard.\n# Local: clerk webhooks listen --forward-to http://localhost:3000/api/webhooks\n# → add the printed https://webhooks.clerk.com/in/c_…/ URL as an endpoint\n#   (subscribe to waitlistEntry.created / waitlistEntry.updated), then paste\n#   that endpoint's whsec_… secret here.\nCLERK_WEBHOOK_SIGNING_SECRET=\n",
      "type": "registry:file",
      "target": ".env.example"
    }
  ],
  "envVars": {
    "NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY": "",
    "CLERK_SECRET_KEY": "",
    "CLERK_WEBHOOK_SIGNING_SECRET": "",
    "NEXT_PUBLIC_CLERK_SIGN_IN_FALLBACK_REDIRECT_URL": "/",
    "NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL": "/"
  },
  "docs": "New Next.js project only (same flow as https://ui.shadcn.com/create):\n  npx shadcn@latest init --template next -y \"https://uiception.com/r/landing-page-v1.json\"\n\nThis scaffolds Next.js + shadcn, then installs the full site.\n\nClerk setup — fastest path is the Clerk CLI (https://clerk.com/docs/cli):\n  npx clerk init -y\nThis links (or creates) a Clerk app and writes both keys to .env.local — no dashboard copy-paste. Alternatively, copy the keys from https://dashboard.clerk.com/~/api-keys into .env.local (see .env.example).\n\nThen enable Waitlist mode: Clerk Dashboard → Waitlist → toggle \"Enable waitlist\".\n\n<Waitlist /> submits to Clerk's Frontend API; entries show in the Dashboard. app/api/webhooks/route.ts verifies waitlistEntry.created / waitlistEntry.updated (add side effects there). Local test:\n  clerk webhooks listen --forward-to http://localhost:3000/api/webhooks\nAdd the printed relay URL as a Dashboard webhook endpoint (subscribe to waitlistEntry.*), set CLERK_WEBHOOK_SIGNING_SECRET from that endpoint, restart the app, then join the waitlist.\n\nUntil keys are set, the page renders a local demo form that stores nothing. The <Waitlist /> component is mounted on the home page, so waitlistUrl is \"/\" (set on ClerkProvider in app/layout.tsx). The shadcn theme comes from @clerk/ui/themes and its CSS is imported in app/globals.css.\n\nEdit all page copy (name, tagline, footer links) in lib/site.ts.",
  "categories": [
    "template",
    "landing-pages"
  ],
  "type": "registry:block"
}