{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "corners",
  "title": "Corners",
  "author": "zyx1121 (https://github.com/zyx1121)",
  "description": "The four fixed corners every zyx.tw site shares: the zyx mark and the page nav on top, Privacy and Terms and the copyright below, each item with a tip.",
  "dependencies": [
    "@base-ui/react"
  ],
  "registryDependencies": [
    "https://ui.zyx.tw/r/utils.json",
    "https://ui.zyx.tw/r/tooltip.json",
    "https://ui.zyx.tw/r/layout.json"
  ],
  "files": [
    {
      "path": "registry/zyx/components/corners.tsx",
      "content": "import { type At, CornerMenu, CornerScope, CornerTip } from \"./corner-tip\"\nimport { ZyxMark } from \"./zyx-mark\"\n\nimport { cn } from \"../lib/utils\"\n\nexport { CornerTip }\n\n/*\n * The frame every zyx.tw site shares: the logo top left, the page nav top\n * right, secondary links bottom left and the copyright bottom right. Each\n * corner is fixed 12px (`--gutter`) in from the viewport's corner, or from the screen's\n * when the site wears the TV frame (`tv` on <html>). All corners use\n * text-body (16px on 24px lines). An item in a corner\n * can carry a tip (`CornerTip`), which opens toward the page.\n */\n\nconst AT: Record<At, string> = {\n  \"top-left\": \"corner-top corner-left\",\n  \"top-right\": \"corner-top corner-right\",\n  \"bottom-left\": \"corner-bottom corner-left\",\n  \"bottom-right\": \"corner-right corner-bottom\",\n}\n\n/**\n * Text links in a corner: uppercase like a terminal menu, muted, lit on hover\n * and for the current page. The hit area reaches 8 px past the text on either\n * side and stays 24 px tall for both header and footer text, centered on the\n * text line.\n */\nexport const cornerLink =\n  \"[font-variant-ligatures:none] relative uppercase text-muted-foreground outline-offset-4 transition-colors after:absolute after:-inset-x-2 after:top-1/2 after:h-6 after:-translate-y-1/2 hover:text-foreground focus-visible:outline-2 aria-[current=page]:text-foreground\"\n\n/**\n * A nav label in brackets, as in a terminal menu: the brackets show on the\n * current page only. They hang outside the label, so the label's own text\n * lines up with the corner's edge and nothing shifts on navigation; a nav of\n * these takes `gap-7`, room for a bracket on either side of the gap.\n */\nexport function CornerLabel({\n  current = false,\n  children,\n}: {\n  current?: boolean\n  children: React.ReactNode\n}) {\n  const bracket = current ? undefined : \"invisible\"\n  return (\n    <span className=\"relative\">\n      <span aria-hidden=\"true\" className={cn(\"absolute right-full\", bracket)}>\n        [\n      </span>\n      {children}\n      <span aria-hidden=\"true\" className={cn(\"absolute left-full\", bracket)}>\n        ]\n      </span>\n    </span>\n  )\n}\n\n/**\n * Privacy and Terms, which every zyx.tw site shares at www.zyx.tw. They lead\n * the bottom left corner; the labels follow the site's\n * language.\n */\nexport function LegalLinks({\n  labels = { privacy: \"Privacy\", terms: \"Terms\" },\n}: {\n  labels?: { privacy: string; terms: string }\n}) {\n  return (\n    <>\n      <a href=\"https://www.zyx.tw/privacy\" className={cornerLink}>\n        {labels.privacy}\n      </a>\n      <a href=\"https://www.zyx.tw/terms\" className={cornerLink}>\n        {labels.terms}\n      </a>\n    </>\n  )\n}\n\n/** One corner of the viewport. A page can fill one the layout leaves empty. */\nexport function Corner({\n  at,\n  className,\n  ...props\n}: React.ComponentProps<\"div\"> & { at: At }) {\n  return (\n    <CornerScope at={at}>\n      <div\n        className={cn(\n          \"fixed z-50 flex items-center gap-4 text-body text-foreground\",\n          AT[at],\n          className\n        )}\n        {...props}\n      />\n    </CornerScope>\n  )\n}\n\n/**\n * A transparent 12px backdrop blur fading out over 64px at the viewport edge,\n * under the corners so scrolling content stays behind the shared chrome. Pages that do not scroll leave it off.\n */\nfunction EdgeFade({ edge }: { edge: \"top\" | \"bottom\" }) {\n  return (\n    <div\n      aria-hidden\n      data-slot=\"corner-edge\"\n      data-edge={edge}\n      className={cn(\n        \"pointer-events-none fixed inset-x-0 z-40 h-16\",\n        edge === \"top\" ? \"top-0\" : \"bottom-0\"\n      )}\n    />\n  )\n}\n\n/*\n * `className` goes on each corner rather than on the <header> or\n * <footer> around them: an entrance animation there would leave a transform\n * on the wrapper, and a transformed ancestor becomes the box that fixed\n * elements are placed in, which pulls the corners off the viewport's.\n */\n\n/** One step of the path to the current page; the last one has no `href`. */\nexport type Crumb = { label: string; href?: string }\n\n/**\n * The path from the mark to the current page, as a shell prints one:\n * `/ WORKS / AINTERN`. Every step but the last is a link. On a phone only\n * the last step shows, and it truncates rather than reach the page nav; with\n * a nav that does not fold, a phone shows no trail at all.\n */\nfunction Trail({ trail, phone }: { trail: Crumb[]; phone: boolean }) {\n  return (\n    <nav\n      aria-label=\"Breadcrumb\"\n      className={cn(\"min-w-0\", !phone && \"max-sm:hidden\")}\n    >\n      <ol className=\"flex gap-2\">\n        {trail.map(({ label, href }, index) => {\n          const last = index === trail.length - 1\n          return (\n            <li\n              key={label}\n              className={cn(\"flex gap-2\", last ? \"min-w-0\" : \"max-sm:hidden\")}\n            >\n              <span aria-hidden=\"true\" className=\"text-muted-foreground\">\n                /\n              </span>\n              {href && !last ? (\n                <a href={href} className={cornerLink}>\n                  {label}\n                </a>\n              ) : (\n                <span aria-current=\"page\" className=\"truncate uppercase\">\n                  {label}\n                </span>\n              )}\n            </li>\n          )\n        })}\n      </ol>\n    </nav>\n  )\n}\n\n/**\n * The top corners: the zyx mark, which mirrors itself on hover, the path to\n * the current page beside it, and the page nav. The mark links to `home`:\n * \"/\" on www.zyx.tw, www.zyx.tw everywhere else. Its tip says where: \"Home\"\n * or the host.\n */\nexport function TopCorners({\n  home = \"https://www.zyx.tw\",\n  label = \"zyx.tw\",\n  markTip = home.startsWith(\"/\") ? \"Home\" : new URL(home).host,\n  trail,\n  nav,\n  foldNav = false,\n  fade = false,\n  className,\n}: {\n  home?: string\n  /** The mark's accessible name. */\n  label?: string\n  markTip?: React.ReactNode\n  /** The steps from the home page to this one; none on the home page. */\n  trail?: Crumb[]\n  nav?: React.ReactNode\n  /** On a phone, fold the nav behind a MENU link so the trail has room. */\n  foldNav?: boolean\n  fade?: boolean\n  /** On each corner, e.g. an entrance animation or a theme scope. */\n  className?: string\n}) {\n  return (\n    <header>\n      {fade && <EdgeFade edge=\"top\" />}\n      {/* With a trail the corner ends 288px from the right edge, clear of a\n          four-item nav, so a long name truncates instead of running into it.\n          A phone has no room for both: there the nav marks the page, or,\n          folded behind MENU, leaves the trail 96px to the right edge. */}\n      <Corner\n        at=\"top-left\"\n        className={cn(\n          trail?.length && \"gap-2 sm:right-72\",\n          trail?.length && (foldNav || !nav) && \"max-sm:right-24\",\n          className\n        )}\n      >\n        <CornerTip tip={markTip}>\n          <a\n            href={home}\n            aria-label={label}\n            className=\"group shrink-0 outline-offset-4 focus-visible:outline-2\"\n          >\n            {/* 20 px tall, the corners' line height. */}\n            <ZyxMark className=\"h-5 w-auto group-hover:-scale-x-100 motion-safe:transition-transform motion-safe:duration-overlay\" />\n          </a>\n        </CornerTip>\n        {trail && trail.length > 0 && (\n          <Trail trail={trail} phone={foldNav || !nav} />\n        )}\n      </Corner>\n      {nav && (\n        <Corner at=\"top-right\" className={className}>\n          {foldNav ? (\n            <>\n              <div className=\"flex max-sm:hidden\">{nav}</div>\n              <CornerMenu linkClassName={cornerLink} className=\"sm:hidden\">\n                {nav}\n              </CornerMenu>\n            </>\n          ) : (\n            nav\n          )}\n        </Corner>\n      )}\n    </header>\n  )\n}\n\n/**\n * The bottom corners: secondary links (privacy, source, Markdown) and the\n * copyright, whose tip names its holder. On a narrow screen the links wrap\n * upward instead of running into the copyright.\n */\nexport function BottomCorners({\n  links,\n  copyrightTip = \"zyx\",\n  fade = false,\n  className,\n}: {\n  links?: React.ReactNode\n  copyrightTip?: React.ReactNode\n  fade?: boolean\n  /** On each corner, e.g. an entrance animation or a theme scope. */\n  className?: string\n}) {\n  const year = new Date().getFullYear()\n\n  return (\n    <footer>\n      {fade && <EdgeFade edge=\"bottom\" />}\n      {links && (\n        // Ends 124px from the right edge: the copyright, its inset and a\n        // 20px gap.\n        <Corner\n          at=\"bottom-left\"\n          className={cn(\"right-31 flex-wrap gap-y-1\", className)}\n        >\n          {links}\n        </Corner>\n      )}\n      <Corner at=\"bottom-right\" className={className}>\n        {/* A prerendered page keeps the year it was built in; a client\n            render in a later year leaves that text rather than tearing the\n            tree down over one number. */}\n        <CornerTip tip={copyrightTip}>\n          <p\n            className=\"text-muted-foreground tabular-nums\"\n            suppressHydrationWarning\n          >\n            © {year}\n          </p>\n        </CornerTip>\n      </Corner>\n    </footer>\n  )\n}\n",
      "type": "registry:component"
    },
    {
      "path": "registry/zyx/components/corner-tip.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"./ui/tooltip\"\n\nimport { cn } from \"../lib/utils\"\n\nexport type At = \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\"\n\nconst CornerContext = React.createContext<At>(\"top-left\")\n\n/**\n * Tells the tips in a corner which corner they sit in, and opens them at\n * once: an app without a TooltipProvider of its own would otherwise wait\n * Base UI's 600 ms.\n */\nexport function CornerScope({\n  at,\n  children,\n}: {\n  at: At\n  children: React.ReactNode\n}) {\n  return (\n    <CornerContext.Provider value={at}>\n      <TooltipProvider>{children}</TooltipProvider>\n    </CornerContext.Provider>\n  )\n}\n\n/**\n * A bubble on hover, and on keyboard focus of a link or button, with what the\n * item's label leaves out. It opens toward the page, below the top corners and\n * above the bottom ones, lined up with the item's outer edge, so it never runs\n * off the viewport. `children` is the item itself: one element that takes the\n * trigger's ref and props. A component that sets its own onClick before\n * spreading its props goes inside a span, or the trigger's onClick replaces\n * it. Without a `tip` the item renders as it is.\n */\nexport function CornerTip({\n  tip,\n  children,\n}: {\n  tip?: React.ReactNode\n  children: React.ReactElement\n}) {\n  const at = React.useContext(CornerContext)\n  const [dark, setDark] = React.useState(false)\n\n  if (tip == null || tip === \"\") return children\n\n  return (\n    <Tooltip\n      onOpenChange={(open, { trigger }) => {\n        // The bubble is portalled to <body>, outside a corner's own scheme,\n        // such as the dark corners over the www.zyx.tw home's 3D stage in\n        // the light theme, so it copies a scheme set below <html>. The site's\n        // own theme it inherits, and follows when that changes while open.\n        if (open) setDark(trigger?.closest(\".dark:not(html)\") != null)\n      }}\n    >\n      <TooltipTrigger render={children} />\n      <TooltipContent\n        side={at.startsWith(\"top\") ? \"bottom\" : \"top\"}\n        align={at.endsWith(\"left\") ? \"start\" : \"end\"}\n        // flex, not the stock inline-flex: in a line box the bubble would sit\n        // on the page's line height and land a few px low.\n        className={cn(\"flex\", dark && \"dark\")}\n      >\n        {tip}\n      </TooltipContent>\n    </Tooltip>\n  )\n}\n\n/**\n * The page nav folded behind a MENU link, for a phone without room for it\n * beside the breadcrumb. It opens a panel under the top right corner with the\n * nav's links in a column, and closes on a pick, a tap outside or Escape.\n */\nexport function CornerMenu({\n  label = \"Menu\",\n  linkClassName,\n  className,\n  children,\n}: {\n  label?: string\n  /** The corner link style, so MENU looks like the links it hides. */\n  linkClassName?: string\n  className?: string\n  children: React.ReactNode\n}) {\n  const [open, setOpen] = React.useState(false)\n  const root = React.useRef<HTMLDivElement>(null)\n  const id = React.useId()\n\n  React.useEffect(() => {\n    if (!open) return\n    const away = (e: PointerEvent) => {\n      if (!root.current?.contains(e.target as Node)) setOpen(false)\n    }\n    const key = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setOpen(false)\n    }\n    document.addEventListener(\"pointerdown\", away)\n    document.addEventListener(\"keydown\", key)\n    return () => {\n      document.removeEventListener(\"pointerdown\", away)\n      document.removeEventListener(\"keydown\", key)\n    }\n  }, [open])\n\n  return (\n    <div ref={root} className={cn(\"relative flex\", className)}>\n      <button\n        type=\"button\"\n        aria-expanded={open}\n        aria-controls={id}\n        onClick={() => setOpen((v) => !v)}\n        className={linkClassName}\n      >\n        {label}\n      </button>\n      <div\n        id={id}\n        hidden={!open}\n        // A pick inside closes the panel; the link still navigates. Capture,\n        // so a link that stops its click still closes it.\n        onClickCapture={(e) => {\n          if ((e.target as HTMLElement).closest(\"a\")) setOpen(false)\n        }}\n        className=\"absolute top-full right-0 mt-3 min-w-40 rounded-control border border-border bg-background/95 px-5 py-3 shadow-window backdrop-blur-md [&_li]:py-2 [&_ul]:flex-col [&_ul]:items-end [&_ul]:gap-0\"\n      >\n        {children}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component"
    },
    {
      "path": "registry/zyx/components/zyx-mark.tsx",
      "content": "import { cn } from \"../lib/utils\"\n\n// The mark from apps/web/public/zyx.svg, with its viewBox tightened to the path's box\n// (0 0 4096 3615), so its edges are the drawing's edges.\nconst PATH =\n  \"M2845.95 13.9357C2917.17 -5.94859 2998.62 -8.73553 3072 33.6369C3135.18 70.1192 3172.66 128.948 3193.36 190.107C3213.74 250.29 3220.34 319.143 3218.74 390.501C3215.54 533.321 3178.64 711.473 3116.9 908.909C3087.54 1002.79 3067.38 1067.46 3055.58 1116.28C3043.27 1167.21 3044.77 1183.61 3045.32 1186.44C3049.46 1207.64 3053.85 1217.91 3057.65 1224.5C3061.46 1231.08 3068.16 1240.01 3084.44 1254.2C3086.61 1256.09 3100.05 1265.59 3150.32 1280.4C3198.49 1294.59 3264.57 1309.46 3360.54 1330.97C3562.38 1376.22 3735.1 1433.34 3860.37 1501.97C3922.96 1536.27 3979.27 1576.42 4021.19 1624.15C4063.8 1672.67 4096 1734.54 4096 1807.5C4096 1892.25 4052.87 1961.41 4000.04 2013.15C3947.46 2064.65 3876.66 2107.96 3796.99 2144.95C3637.03 2219.22 3415.77 2279.62 3157.74 2323.89C2979.46 2354.48 2848.13 2377.03 2749.36 2396.67C2649.09 2416.6 2590.56 2432.05 2554.26 2446.64C2495.41 2470.29 2468.77 2482.03 2445.24 2495.62C2421.7 2509.22 2398.22 2526.42 2348.31 2565.57C2317.52 2589.71 2274.88 2632.68 2207.49 2709.56C2141.09 2785.3 2055.9 2887.77 1940.28 3026.89C1772.92 3228.25 1609.99 3389.69 1465.7 3491.1C1393.83 3541.61 1320.93 3581.28 1250.05 3601.07C1178.83 3620.95 1097.38 3623.73 1024 3581.36C960.82 3544.88 923.345 3486.05 902.64 3424.9C882.264 3364.71 875.65 3295.86 877.25 3224.5C880.452 3081.68 917.353 2903.53 979.096 2706.09C1008.45 2612.2 1028.61 2547.53 1040.41 2498.71C1052.72 2447.78 1051.22 2431.39 1050.67 2428.56C1046.53 2407.36 1042.14 2397.08 1038.34 2390.5C1034.54 2383.91 1027.84 2374.98 1011.55 2360.79C1009.38 2358.9 995.931 2349.4 945.669 2334.59C897.5 2320.41 831.421 2305.53 735.449 2284.02C533.619 2238.78 360.909 2181.67 235.64 2113.04C173.051 2078.74 116.735 2038.59 74.8088 1990.85C32.2045 1942.34 0.0020352 1880.47 0 1807.51C0.00115737 1722.76 43.1356 1653.6 95.9632 1601.86C148.539 1550.36 219.335 1507.05 299.007 1470.06C458.965 1395.78 680.22 1335.38 938.257 1291.1C1116.53 1260.51 1247.86 1237.96 1346.63 1218.33C1446.91 1198.39 1505.44 1182.95 1541.74 1168.36C1600.59 1144.7 1627.22 1132.96 1650.76 1119.37C1674.3 1105.78 1697.78 1088.58 1747.68 1049.43C1778.47 1025.28 1821.11 982.314 1888.51 905.431C1954.9 829.699 2040.09 727.225 2155.71 588.109C2323.07 386.75 2486 225.308 2630.29 123.899C2702.17 73.388 2775.07 33.7253 2845.95 13.9357Z\"\n\n/**\n * The zyx mark in the current text color. Decorative: the link around it\n * carries the name.\n */\nexport function ZyxMark({ className }: { className?: string }) {\n  return (\n    <svg\n      viewBox=\"0 0 4096 3615\"\n      fill=\"currentColor\"\n      aria-hidden\n      focusable=\"false\"\n      className={cn(\"block\", className)}\n    >\n      <path d={PATH} />\n    </svg>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "css": {
    "[data-slot=\"corner-edge\"]": {
      "-webkit-backdrop-filter": "blur(12px)",
      "backdrop-filter": "blur(12px)",
      "-webkit-mask-image": "linear-gradient(var(--edge-direction), #000 35%, transparent)",
      "mask-image": "linear-gradient(var(--edge-direction), #000 35%, transparent)"
    },
    "[data-slot=\"corner-edge\"][data-edge=\"top\"]": {
      "--edge-direction": "to bottom"
    },
    "[data-slot=\"corner-edge\"][data-edge=\"bottom\"]": {
      "--edge-direction": "to top"
    }
  },
  "meta": {
    "useWhen": "The frame of every page: mark and nav on top, legal links and copyright below.",
    "notFor": "In-page navigation or toolbars; those live in the page.",
    "related": [
      "page-decode",
      "section-title"
    ]
  },
  "docs": "Use when: The frame of every page: mark and nav on top, legal links and copyright below.\nNot for: In-page navigation or toolbars; those live in the page.\nGuide: https://ui.zyx.tw/corners.md",
  "categories": [
    "layout",
    "navigation"
  ],
  "type": "registry:component"
}