{"version":3,"file":"Link.mjs","names":[],"sources":["../../../src/mdx/mdxComponents/Link.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport A from '@/A';\nimport type { AProps } from '@/types';\nimport type { CitationItem } from '@/types/citation';\nimport { safeParseJSON } from '@/utils/safeParseJSON';\n\nimport Citation from './Citation';\n\nexport interface LinkProps extends AProps {\n  'aria-describedby'?: string;\n  'citations'?: CitationItem[];\n  'data-footnote-ref'?: boolean;\n  'data-link'?: string;\n  'id'?: string;\n  'node'?: any;\n}\n\nconst Link: FC<LinkProps> = ({ href, target, citations, ...rest }) => {\n  // [^1] 格式类型\n  if (rest['data-footnote-ref']) {\n    return (\n      <Citation inSup citationDetail={safeParseJSON(rest['data-link'])} href={href} id={rest.id!}>\n        {rest.children}\n      </Citation>\n    );\n  }\n\n  // [1] 格式类型，搭配 citations 注入\n  const match = href?.match(/citation-(\\d+)/);\n\n  if (match) {\n    const index = Number.parseInt(match[1]) - 1;\n\n    const detail = citations?.[index];\n\n    return (\n      <Citation citationDetail={detail} id={match[1]}>\n        {match[1]}\n      </Citation>\n    );\n  }\n\n  const isNewWindow = href?.startsWith('http');\n\n  return <A href={href} target={target || isNewWindow ? '_blank' : undefined} {...rest} />;\n};\n\nLink.displayName = 'MdxLink';\n\nexport default Link;\n"],"mappings":";;;;;;AAoBA,MAAM,QAAuB,EAAE,MAAM,QAAQ,WAAW,GAAG,WAAW;AAEpE,KAAI,KAAK,qBACP,QACE,oBAAC,UAAD;EAAU,OAAA;EAAM,gBAAgB,cAAc,KAAK,aAAa;EAAQ;EAAM,IAAI,KAAK;YACpF,KAAK;EACG,CAAA;CAKf,MAAM,QAAQ,MAAM,MAAM,iBAAiB;AAE3C,KAAI,OAAO;EACT,MAAM,QAAQ,OAAO,SAAS,MAAM,GAAG,GAAG;EAE1C,MAAM,SAAS,YAAY;AAE3B,SACE,oBAAC,UAAD;GAAU,gBAAgB;GAAQ,IAAI,MAAM;aACzC,MAAM;GACE,CAAA;;CAIf,MAAM,cAAc,MAAM,WAAW,OAAO;AAE5C,QAAO,oBAAC,GAAD;EAAS;EAAM,QAAQ,UAAU,cAAc,WAAW,KAAA;EAAW,GAAI;EAAQ,CAAA;;AAG1F,KAAK,cAAc"}