{"version":3,"sources":["../src/components/link/link.tsx"],"names":["React","Link","href","target","rel","children","styles","prefetch","btnStyle","onClick","onPointerDown","disabled","className","props","ref","disabledProps","handlers","useDisabledState","computedRel","securityTokens","token","safeHref","disabledAttrs","ui_default","IconLink","icon","LinkButton","LinkWithSubcomponents","link_default"],"mappings":"kFAAA,OAAOA,MAAW,QAgGX,IAAMC,EAAOD,EAAM,WACxB,CACE,CACE,KAAAE,EACA,OAAAC,EACA,IAAAC,EACA,SAAAC,EACA,OAAAC,EACA,SAAAC,EAAW,GACX,SAAAC,EACA,QAAAC,EACA,cAAAC,EACA,SAAAC,EACA,UAAAC,EACA,GAAGC,CACL,EACAC,IACG,CAIH,GAAM,CAAE,cAAAC,EAAe,SAAAC,CAAS,EAAIC,EAClCN,EACA,CACE,SAAU,CAAE,QAAAF,EAAS,cAAAC,CAAc,EACnC,UAAAE,CACF,CACF,EAWMM,EAAclB,EAAM,QAAQ,IAAM,CACtC,GAAIG,IAAW,SAAU,CAEvB,IAAMgB,EAAiB,IAAI,IAAI,CAAC,WAAY,YAAY,CAAC,EAGzD,OAAIZ,GACFY,EAAe,IAAI,UAAU,EAI3Bf,GACFA,EAAI,MAAM,KAAK,EAAE,QAASgB,GAAU,CAC9BA,GAAOD,EAAe,IAAIC,CAAK,CACrC,CAAC,EAGI,MAAM,KAAKD,CAAc,EAAE,KAAK,GAAG,CAC5C,CAGA,OAAOf,CACT,EAAG,CAACD,EAAQC,EAAKG,CAAQ,CAAC,EAKpBc,EAAWV,EAAW,OAAYT,EAKlCoB,EAAgBX,EAClB,CAAE,GAAGI,CAAc,EACnB,CAAE,UAAWH,GAAa,MAAU,EAExC,OACEZ,EAAA,cAACuB,EAAA,CACC,GAAG,IACH,IAAKT,EACL,KAAMO,EACN,OAAQlB,EACR,IAAKe,EACL,OAAQZ,EACR,WAAUE,EACT,GAAGc,EACJ,QAASN,EAAS,QAClB,cAAeA,EAAS,cACvB,GAAGH,GAEHR,CACH,CAEJ,CACF,EAEamB,EAAWxB,EAAM,WAC5B,CAAC,CAAE,KAAAE,EAAM,KAAAuB,EAAM,GAAGZ,CAAM,EAAGC,IAEvBd,EAAA,cAACC,EAAA,CAAK,IAAKa,EAAK,KAAMZ,EAAO,GAAGW,GAC7BY,CACH,CAGN,EAEaC,EAAa1B,EAAM,WAC9B,CAAC,CAAE,KAAAE,EAAM,SAAAG,EAAU,GAAGQ,CAAM,EAAGC,IAE3Bd,EAAA,cAACC,EAAA,CAAK,IAAKa,EAAK,KAAMZ,EAAO,GAAGW,GAC9Bb,EAAA,cAAC,SAAGK,CAAS,CACf,CAGN,EAEAJ,EAAK,YAAc,OACnBuB,EAAS,YAAc,WACvBE,EAAW,YAAc,aAYzB,IAAMC,EAAwB,OAAO,OAAO1B,EAAM,CAChD,WAAAyB,EACA,SAAAF,CACF,CAAC,EAEMI,EAAQD","sourcesContent":["import React from \"react\";\nimport UI from \"../ui\";\nimport type { LinkProps } from \"./link.types\";\nimport { useDisabledState } from \"../../hooks/use-disabled-state\";\n\n/**\n * Link - A semantic, accessible anchor component with enhanced security and styling.\n *\n * The Link component renders accessible `<a>` elements with automatic security\n * attributes for external links, customizable styling variants, and full WCAG 2.1\n * AA compliance. It supports traditional text links, button-styled links, and\n * programmatic focus management via ref forwarding.\n *\n * ## Features\n *\n * - 🔒 **Automatic Security**: External links get `rel=\"noopener noreferrer\"`\n * - ♿ **WCAG 2.1 AA Compliant**: Accessible focus indicators and semantic HTML\n * - 🎨 **Flexible Styling**: Text links, button links, and pill variants\n * - ⚡ **Performance**: Optional prefetch hints for faster navigation\n * - 🎯 **Ref Forwarding**: Direct DOM access for focus management and scroll\n * - 🧪 **Type-Safe**: Full TypeScript support with comprehensive prop types\n *\n * ## Accessibility\n *\n * - ✅ Semantic `<a>` element for proper keyboard navigation\n * - ✅ Focus indicators meet WCAG 2.4.7 (3:1 contrast ratio)\n * - ✅ Screen readers announce link purpose and destination\n * - ✅ External links include security attributes automatically\n * - ✅ Supports `aria-label` for icon-only or ambiguous links\n * - ✅ Ref forwarding enables skip-link patterns\n *\n * @example\n * // Basic internal link\n * <Link href=\"/about\">About Us</Link>\n *\n * @example\n * // External link with automatic security\n * <Link href=\"https://example.com\" target=\"_blank\">\n *   Visit Example\n * </Link>\n *\n * @example\n * // Button-styled call-to-action link\n * <Link href=\"/signup\">\n *   <b>Get Started</b>\n * </Link>\n *\n * @example\n * // Icon-only link with accessible label\n * <Link href=\"/settings\" aria-label=\"Open settings\">\n *   <SettingsIcon aria-hidden=\"true\" />\n * </Link>\n *\n * @example\n * // Analytics tracking with onClick (includes keyboard users)\n * <Link\n *   href=\"/products\"\n *   onClick={(e) => trackEvent('link_click', { href: '/products' })}\n * >\n *   Browse Products\n * </Link>\n *\n * @example\n * // Skip link with ref forwarding for focus management\n * const mainRef = useRef<HTMLAnchorElement>(null);\n *\n * <Link ref={mainRef} href=\"#main-content\">\n *   Skip to main content\n * </Link>\n *\n * @example\n * // Custom styled link with CSS variables\n * <Link\n *   href=\"/products\"\n *   styles={{\n *     '--link-color': '#0066cc',\n *     '--link-decoration': 'underline',\n *   }}\n * >\n *   Browse Products\n * </Link>\n *\n * @example\n * // ✅ GOOD: Descriptive link text\n * <Link href=\"/docs/installation\">\n *   Read installation guide\n * </Link>\n *\n * @example\n * // ❌ BAD: Generic link text (poor for screen readers)\n * <Link href=\"/docs/installation\">\n *   Click here\n * </Link>\n *\n * @see {@link LinkProps} for complete prop documentation\n */\nexport const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(\n  (\n    {\n      href,\n      target,\n      rel,\n      children,\n      styles,\n      prefetch = false,\n      btnStyle,\n      onClick,\n      onPointerDown,\n      disabled,\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    // Anchor elements have no native `disabled` attribute; the library's\n    // convention is aria-disabled via the shared hook so the link stays in\n    // tab order (WCAG 2.1.1) and screen readers announce the state.\n    const { disabledProps, handlers } = useDisabledState<HTMLAnchorElement>(\n      disabled,\n      {\n        handlers: { onClick, onPointerDown },\n        className,\n      }\n    );\n    /**\n     * Compute the final `rel` attribute value with security defaults.\n     *\n     * For external links (target=\"_blank\"), we merge user-provided `rel` values\n     * with security defaults `noopener noreferrer` to prevent:\n     * - window.opener exploitation (noopener)\n     * - Referrer header leakage (noreferrer)\n     *\n     * If prefetch is enabled, we also add the `prefetch` hint.\n     */\n    const computedRel = React.useMemo(() => {\n      if (target === \"_blank\") {\n        // Start with security defaults\n        const securityTokens = new Set([\"noopener\", \"noreferrer\"]);\n\n        // Add prefetch if enabled\n        if (prefetch) {\n          securityTokens.add(\"prefetch\");\n        }\n\n        // Merge with user-provided rel tokens (if any)\n        if (rel) {\n          rel.split(/\\s+/).forEach((token) => {\n            if (token) securityTokens.add(token);\n          });\n        }\n\n        return Array.from(securityTokens).join(\" \");\n      }\n\n      // For non-external links, use provided rel as-is\n      return rel;\n    }, [target, rel, prefetch]);\n\n    // Disabled links shouldn't navigate on keyboard activation either; the\n    // hook already blocks onClick, but removing href closes the loop for\n    // screen readers and prevents URL flashes on activation.\n    const safeHref = disabled ? undefined : href;\n\n    // Only emit the disabled attributes when actually disabled — default\n    // `aria-disabled=\"false\"` adds noise to the DOM and invalidates\n    // snapshot tests of callers that render Links (breadcrumbs, nav, etc).\n    const disabledAttrs = disabled\n      ? { ...disabledProps }\n      : { className: className || undefined };\n\n    return (\n      <UI\n        as=\"a\"\n        ref={ref}\n        href={safeHref}\n        target={target}\n        rel={computedRel}\n        styles={styles}\n        data-btn={btnStyle}\n        {...disabledAttrs}\n        onClick={handlers.onClick}\n        onPointerDown={handlers.onPointerDown}\n        {...props}\n      >\n        {children}\n      </UI>\n    );\n  }\n);\n\nexport const IconLink = React.forwardRef<HTMLAnchorElement, LinkProps>(\n  ({ href, icon, ...props }, ref) => {\n    return (\n      <Link ref={ref} href={href} {...props}>\n        {icon}\n      </Link>\n    );\n  }\n);\n\nexport const LinkButton = React.forwardRef<HTMLAnchorElement, LinkProps>(\n  ({ href, children, ...props }, ref) => {\n    return (\n      <Link ref={ref} href={href} {...props}>\n        <i>{children}</i>\n      </Link>\n    );\n  }\n);\n\nLink.displayName = \"Link\";\nIconLink.displayName = \"IconLink\";\nLinkButton.displayName = \"LinkButton\";\n\n// Compound component pattern - attach subcomponents to Link with proper typing\nexport interface LinkComponent\n  extends React.ForwardRefExoticComponent<\n    LinkProps & React.RefAttributes<HTMLAnchorElement>\n  > {\n  LinkButton: typeof LinkButton;\n  IconLink: typeof IconLink;\n}\n\n// Attach subcomponents to Link using Object.assign for better type inference\nconst LinkWithSubcomponents = Object.assign(Link, {\n  LinkButton,\n  IconLink,\n});\n\nexport default LinkWithSubcomponents as LinkComponent;\n"]}