{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "link",
  "type": "registry:ui",
  "title": "Link",
  "description": "Link is semantic navigational text styled as inline or standalone links — not for primary actions.",
  "author": "Skrewww",
  "dependencies": [],
  "registryDependencies": [
    "@skrewww/foundation"
  ],
  "docs": "Host requirements (assumed already present, not installed by this command): react, react-dom.",
  "files": [
    {
      "path": "components/ui/Link.tsx",
      "content": "/** @skrewww-component link */\nimport type { AnchorHTMLAttributes, ReactNode } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { RouterAnchor } from \"@/components/ui/router-navigation\";\nimport { getLinkRel } from \"@/components/ui/internal/link-utils\";\nimport styles from \"@/components/ui/link.module.css\";\n\nexport type LinkVariant = \"default\" | \"subtle\" | \"danger\";\nexport type LinkSize = \"sm\" | \"md\" | \"lg\";\n\nexport type LinkProps = Omit<\n  AnchorHTMLAttributes<HTMLAnchorElement>,\n  \"href\" | \"children\"\n> & {\n  href: string;\n  variant?: LinkVariant;\n  size?: LinkSize;\n  leadingIcon?: ReactNode;\n  trailingIcon?: ReactNode;\n  children: ReactNode;\n  className?: string;\n};\n\nconst variantClass: Record<LinkVariant, string> = {\n  default: styles.default,\n  subtle: styles.subtle,\n  danger: styles.danger,\n};\n\nconst sizeClass: Record<LinkSize, string> = {\n  sm: styles.sm,\n  md: styles.md,\n  lg: styles.lg,\n};\n\nexport function Link({\n  href,\n  variant = \"default\",\n  size = \"md\",\n  leadingIcon,\n  trailingIcon,\n  children,\n  className,\n  target,\n  rel,\n  ...rest\n}: LinkProps) {\n  const resolvedRel = getLinkRel(target, rel);\n  const classes = cn(styles.link, variantClass[variant], sizeClass[size], className);\n\n  const content = (\n    <>\n      {leadingIcon ? (\n        <span className={styles.icon} aria-hidden=\"true\">\n          {leadingIcon}\n        </span>\n      ) : null}\n      <span className={styles.label}>{children}</span>\n      {trailingIcon ? (\n        <span className={styles.icon} aria-hidden=\"true\">\n          {trailingIcon}\n        </span>\n      ) : null}\n    </>\n  );\n\n  return (\n    <RouterAnchor href={href} className={classes} target={target} rel={resolvedRel} {...rest}>\n      {content}\n    </RouterAnchor>\n  );\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/Link.tsx"
    },
    {
      "path": "components/ui/link.module.css",
      "content": ".link {\n  /* Component-owned geometry — travels with /r/link.json; semantic colors\n     resolve from Foundation. */\n  --link-text-default: var(--semantic-action-primary);\n  --link-text-hover: var(--semantic-action-primary-hover);\n  --link-font-size-sm: 0.8125rem;\n  --link-font-size-md: 0.875rem;\n  --link-font-size-lg: 1rem;\n  --link-icon-gap: 0.25rem;\n  --link-underline-thickness: 1px;\n  --link-underline-offset: 0.15em;\n\n  display: inline-flex;\n  align-items: center;\n  gap: var(--link-icon-gap);\n  font-weight: 500;\n  text-decoration: underline;\n  text-decoration-thickness: var(--link-underline-thickness);\n  text-underline-offset: var(--link-underline-offset);\n  border-radius: 2px;\n  transition: color 0.15s ease;\n}\n\n.link:focus-visible {\n  outline: 2px solid var(--semantic-focus-ring);\n  outline-offset: 2px;\n  text-decoration-thickness: var(--link-underline-thickness);\n}\n\n.sm {\n  font-size: var(--link-font-size-sm);\n}\n\n.md {\n  font-size: var(--link-font-size-md);\n}\n\n.lg {\n  font-size: var(--link-font-size-lg);\n}\n\n.default {\n  color: var(--link-text-default);\n}\n\n.default:hover {\n  color: var(--link-text-hover);\n}\n\n/* After :hover so :active wins while the pointer is also hovered */\n.default:active {\n  color: var(--primitive-color-brand-700);\n}\n\n.subtle {\n  color: var(--semantic-text-secondary);\n}\n\n.subtle:hover {\n  /* Figma Secondary Hover — semantic/text/primary (not Primary's --link-text-hover) */\n  color: var(--semantic-text-primary);\n}\n\n/* After :hover so :active wins while the pointer is also hovered */\n.subtle:active {\n  color: var(--semantic-text-primary);\n}\n\n.danger {\n  /* Icon currentColor — semantic/icon/danger → danger/500 → #E5484D */\n  color: var(--semantic-icon-danger);\n}\n\n.danger .label {\n  /* Accessible danger text — semantic/text/danger → danger/600 → #CC3B37 */\n  color: var(--semantic-text-danger);\n}\n\n.danger:hover {\n  /* Figma Danger Hover converges label + icon to #CC3B37 */\n  color: var(--semantic-text-danger);\n}\n\n.danger:hover .label {\n  color: var(--semantic-text-danger);\n}\n\n/* After :hover so :active wins while the pointer is also hovered */\n.danger:active {\n  color: var(--primitive-color-danger-700);\n}\n\n.danger:active .label {\n  color: var(--primitive-color-danger-700);\n}\n\n.icon {\n  display: inline-flex;\n  flex-shrink: 0;\n}\n\n.label {\n  text-decoration: inherit;\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/link.module.css"
    },
    {
      "path": "lib/cn.ts",
      "content": "export function cn(...classes: Array<string | false | null | undefined>): string {\n  return classes.filter(Boolean).join(\" \");\n}\n",
      "type": "registry:lib",
      "target": "~/lib/cn.ts"
    },
    {
      "path": "components/ui/internal/link-utils.ts",
      "content": "/**\n * Framework-neutral link classification helpers.\n * No docs-site / repository configuration imports — origin is either passed\n * explicitly or read from the runtime location when available.\n */\n\nfunction normalizeHref(href: string): string {\n  return href.trim();\n}\n\nfunction resolveDefaultOrigin(): string | undefined {\n  if (typeof globalThis === \"undefined\") return undefined;\n  const locationLike = (globalThis as { location?: { origin?: string } }).location;\n  return locationLike?.origin;\n}\n\nexport function isHashHref(href: string): boolean {\n  return normalizeHref(href).startsWith(\"#\");\n}\n\nexport function isSpecialProtocolHref(href: string): boolean {\n  const value = normalizeHref(href).toLowerCase();\n  return value.startsWith(\"mailto:\") || value.startsWith(\"tel:\");\n}\n\nexport function isExternalHref(href: string, origin: string | undefined = resolveDefaultOrigin()): boolean {\n  const value = normalizeHref(href);\n\n  if (!value || isHashHref(value) || value.startsWith(\"/\") || value.startsWith(\"./\") || value.startsWith(\"../\")) {\n    return false;\n  }\n\n  if (isSpecialProtocolHref(value)) {\n    return true;\n  }\n\n  if (value.startsWith(\"//\")) {\n    return true;\n  }\n\n  if (/^https?:\\/\\//i.test(value)) {\n    if (!origin) {\n      // No origin context (SSR without an explicit origin) — treat absolute\n      // http(s) as external so NextLink is not used for foreign hosts.\n      return true;\n    }\n    try {\n      return new URL(value).origin !== origin;\n    } catch {\n      return true;\n    }\n  }\n\n  return false;\n}\n\nexport function shouldUseNativeAnchor(\n  href: string,\n  origin: string | undefined = resolveDefaultOrigin(),\n): boolean {\n  const value = normalizeHref(href);\n  return isSpecialProtocolHref(value) || isExternalHref(value, origin);\n}\n\nexport function getLinkRel(target?: string, rel?: string): string | undefined {\n  if (rel) return rel;\n  if (target === \"_blank\") return \"noopener noreferrer\";\n  return undefined;\n}\n\n/**\n * True only for root-relative internal paths (\"/components/button\"). These are\n * the only hrefs a host router can be asked to navigate to: hash-only links,\n * relative paths, protocol-relative URLs, mailto:/tel: and absolute URLs are\n * left to the browser so native behavior (scrolling, resolution against the\n * current URL, other origins) is never reimplemented.\n */\nexport function isRouterNavigableHref(href: string): boolean {\n  const value = normalizeHref(href);\n  return value.startsWith(\"/\") && !value.startsWith(\"//\");\n}\n\nexport type NavigationInterceptionInput = {\n  href: string;\n  target?: string;\n  download?: unknown;\n  button: number;\n  metaKey: boolean;\n  ctrlKey: boolean;\n  shiftKey: boolean;\n  altKey: boolean;\n  defaultPrevented: boolean;\n};\n\n/**\n * Whether a click on an anchor should be handed to the host router instead of\n * the browser. Only a plain, primary-button, same-window activation of an\n * internal path qualifies; every case where the browser should win returns\n * false.\n */\nexport function shouldInterceptNavigation(input: NavigationInterceptionInput): boolean {\n  if (input.defaultPrevented) return false;\n  if (input.button !== 0) return false;\n  if (input.metaKey || input.ctrlKey || input.shiftKey || input.altKey) return false;\n  if (input.target && input.target !== \"_self\") return false;\n  if (input.download !== undefined && input.download !== false) return false;\n  return isRouterNavigableHref(input.href);\n}\n",
      "type": "registry:lib",
      "target": "~/components/ui/internal/link-utils.ts"
    },
    {
      "path": "components/ui/router-navigation.tsx",
      "content": "\"use client\";\n\nimport {\n  createContext,\n  forwardRef,\n  useContext,\n  type AnchorHTMLAttributes,\n  type MouseEvent,\n  type ReactNode,\n} from \"react\";\nimport { shouldInterceptNavigation } from \"@/components/ui/internal/link-utils\";\n\n/**\n * Router integration for link-bearing components (Button, Link, Pagination,\n * List Item). Components always render a native `<a href>`; with no provider\n * a click is ordinary browser navigation. A host application may mount one\n * `SkrewwwRouterProvider` so eligible internal navigations are handed to its\n * own router instead of reloading the page. The contract is navigation\n * intent (\"go to this path\"), not any particular router.\n */\nexport type SkrewwwNavigate = (href: string) => void;\n\nconst SkrewwwNavigateContext = createContext<SkrewwwNavigate | null>(null);\n\nexport type SkrewwwRouterProviderProps = {\n  /**\n   * Called with the root-relative href of a plain, same-window click on an\n   * internal link. Modified or non-primary clicks, `target` other than\n   * `_self`, `download`, prevented events and every non-root-relative href\n   * are never passed to it. Memoize it to avoid re-rendering link consumers.\n   */\n  navigate: SkrewwwNavigate;\n  children: ReactNode;\n};\n\nexport function SkrewwwRouterProvider({ navigate, children }: SkrewwwRouterProviderProps) {\n  return <SkrewwwNavigateContext.Provider value={navigate}>{children}</SkrewwwNavigateContext.Provider>;\n}\n\nexport type RouterAnchorProps = AnchorHTMLAttributes<HTMLAnchorElement> & { href: string };\n\n/** Internal building block — not part of the public package API. */\nexport const RouterAnchor = forwardRef<HTMLAnchorElement, RouterAnchorProps>(function RouterAnchor(\n  { href, target, download, onClick, ...rest },\n  ref,\n) {\n  const navigate = useContext(SkrewwwNavigateContext);\n\n  function handleClick(event: MouseEvent<HTMLAnchorElement>) {\n    onClick?.(event);\n    if (!navigate) return;\n    const intercept = shouldInterceptNavigation({\n      href,\n      target,\n      download,\n      button: event.button,\n      metaKey: event.metaKey,\n      ctrlKey: event.ctrlKey,\n      shiftKey: event.shiftKey,\n      altKey: event.altKey,\n      defaultPrevented: event.defaultPrevented,\n    });\n    if (!intercept) return;\n    event.preventDefault();\n    navigate(href);\n  }\n\n  return <a ref={ref} href={href} target={target} download={download} onClick={handleClick} {...rest} />;\n});\n",
      "type": "registry:ui",
      "target": "~/components/ui/router-navigation.tsx"
    }
  ]
}
