{"version":3,"file":"index.modern.mjs","sources":["../src/parse-path.js","../src/is-local-link.js","../src/prefix-helpers.js","../src/rewrite-link-path.js","../src/index.js"],"sourcesContent":["export function parsePath(path) {\n  let pathname = path || `/`\n  let search = ``\n  let hash = ``\n\n  const hashIndex = pathname.indexOf(`#`)\n  if (hashIndex !== -1) {\n    hash = pathname.slice(hashIndex)\n    pathname = pathname.slice(0, hashIndex)\n  }\n\n  const searchIndex = pathname.indexOf(`?`)\n  if (searchIndex !== -1) {\n    search = pathname.slice(searchIndex)\n    pathname = pathname.slice(0, searchIndex)\n  }\n\n  return {\n    pathname: pathname,\n    search: search === `?` ? `` : search,\n    hash: hash === `#` ? `` : hash,\n  }\n}\n","// Copied from https://github.com/sindresorhus/is-absolute-url/blob/3ab19cc2e599a03ea691bcb8a4c09fa3ebb5da4f/index.js\nconst ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\\d+\\-.]*?:/\nconst isAbsolute = path => ABSOLUTE_URL_REGEX.test(path)\n\nexport const isLocalLink = path => {\n  if (typeof path !== `string`) {\n    return undefined\n    // TODO(v5): Re-Add TypeError\n    // throw new TypeError(`Expected a \\`string\\`, got \\`${typeof path}\\``)\n  }\n\n  return !isAbsolute(path)\n}\n","import { isLocalLink } from \"./is-local-link\"\n\nexport const getGlobalBasePrefix = () =>\n  process.env.NODE_ENV !== `production`\n    ? typeof __BASE_PATH__ !== `undefined`\n      ? __BASE_PATH__\n      : undefined\n    : __BASE_PATH__\n\n// These global values are wrapped in typeof clauses to ensure the values exist.\n// This is especially problematic in unit testing of this component.\nexport const getGlobalPathPrefix = () =>\n  process.env.NODE_ENV !== `production`\n    ? typeof __PATH_PREFIX__ !== `undefined`\n      ? __PATH_PREFIX__\n      : undefined\n    : __PATH_PREFIX__\n\nexport function withPrefix(path, prefix = getGlobalBasePrefix()) {\n  if (!isLocalLink(path)) {\n    return path\n  }\n\n  if (path.startsWith(`./`) || path.startsWith(`../`)) {\n    return path\n  }\n  const base = prefix ?? getGlobalPathPrefix() ?? `/`\n\n  return `${base?.endsWith(`/`) ? base.slice(0, -1) : base}${\n    path.startsWith(`/`) ? path : `/${path}`\n  }`\n}\n","import { resolve } from \"@gatsbyjs/reach-router\"\n// Specific import to treeshake Node.js stuff\nimport { applyTrailingSlashOption } from \"gatsby-page-utils/apply-trailing-slash-option\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { withPrefix } from \"./prefix-helpers\"\n\nconst isAbsolutePath = path => path?.startsWith(`/`)\n\nconst getGlobalTrailingSlash = () =>\n  typeof __TRAILING_SLASH__ !== `undefined` ? __TRAILING_SLASH__ : undefined\n\nfunction applyTrailingSlashOptionOnPathnameOnly(path, option) {\n  const { pathname, search, hash } = parsePath(path)\n  const output = applyTrailingSlashOption(pathname, option)\n\n  return `${output}${search}${hash}`\n}\n\nfunction absolutify(path, current) {\n  // If it's already absolute, return as-is\n  if (isAbsolutePath(path)) {\n    return path\n  }\n\n  const option = getGlobalTrailingSlash()\n  const absolutePath = resolve(path, current)\n\n  if (option === `always` || option === `never`) {\n    return applyTrailingSlashOptionOnPathnameOnly(absolutePath, option)\n  }\n\n  return absolutePath\n}\n\nfunction applyPrefix(path) {\n  const prefixed = withPrefix(path)\n  const option = getGlobalTrailingSlash()\n\n  if (option === `always` || option === `never`) {\n    return applyTrailingSlashOptionOnPathnameOnly(prefixed, option)\n  }\n\n  return prefixed\n}\n\nexport const rewriteLinkPath = (path, relativeTo) => {\n  if (typeof path === `number`) {\n    return path\n  }\n  if (!isLocalLink(path)) {\n    return path\n  }\n\n  return isAbsolutePath(path) ? applyPrefix(path) : absolutify(path, relativeTo)\n}\n","import PropTypes from \"prop-types\"\nimport React from \"react\"\nimport { Link as ReachRouterLink, Location } from \"@gatsbyjs/reach-router\"\nimport { parsePath } from \"./parse-path\"\nimport { isLocalLink } from \"./is-local-link\"\nimport { rewriteLinkPath } from \"./rewrite-link-path\"\nimport { withPrefix, getGlobalPathPrefix } from \"./prefix-helpers\"\n\nexport { parsePath, withPrefix }\n\nexport function withAssetPrefix(path) {\n  return withPrefix(path, getGlobalPathPrefix())\n}\n\nconst NavLinkPropTypes = {\n  activeClassName: PropTypes.string,\n  activeStyle: PropTypes.object,\n  partiallyActive: PropTypes.bool,\n}\n\n// Set up IntersectionObserver\nconst createIntersectionObserver = (el, cb) => {\n  const io = new window.IntersectionObserver(entries => {\n    entries.forEach(entry => {\n      if (el === entry.target) {\n        // Check if element is within viewport, remove listener, destroy observer, and run link callback.\n        // MSEdge doesn't currently support isIntersecting, so also test for  an intersectionRatio > 0\n        cb(entry.isIntersecting || entry.intersectionRatio > 0)\n      }\n    })\n  })\n\n  // Add element to the observer\n  io.observe(el)\n\n  return { instance: io, el }\n}\n\nfunction GatsbyLinkLocationWrapper(props) {\n  return (\n    <Location>\n      {({ location }) => <GatsbyLink {...props} _location={location} />}\n    </Location>\n  )\n}\n\nclass GatsbyLink extends React.Component {\n  constructor(props) {\n    super(props)\n    // Default to no support for IntersectionObserver\n    let IOSupported = false\n    if (typeof window !== `undefined` && window.IntersectionObserver) {\n      IOSupported = true\n    }\n\n    this.state = {\n      IOSupported,\n    }\n    this.abortPrefetch = null\n    this.handleRef = this.handleRef.bind(this)\n  }\n\n  _prefetch() {\n    let currentPath = window.location.pathname + window.location.search\n\n    // reach router should have the correct state\n    if (this.props._location && this.props._location.pathname) {\n      currentPath = this.props._location.pathname + this.props._location.search\n    }\n\n    const rewrittenPath = rewriteLinkPath(this.props.to, currentPath)\n    const parsed = parsePath(rewrittenPath)\n\n    const newPathName = parsed.pathname + parsed.search\n\n    // Prefetch is used to speed up next navigations. When you use it on the current navigation,\n    // there could be a race-condition where Chrome uses the stale data instead of waiting for the network to complete\n    if (currentPath !== newPathName) {\n      return ___loader.enqueue(newPathName)\n    }\n\n    return undefined\n  }\n\n  componentWillUnmount() {\n    if (!this.io) {\n      return\n    }\n    const { instance, el } = this.io\n\n    if (this.abortPrefetch) {\n      this.abortPrefetch.abort()\n    }\n\n    instance.unobserve(el)\n    instance.disconnect()\n  }\n\n  handleRef(ref) {\n    if (\n      this.props.innerRef &&\n      Object.prototype.hasOwnProperty.call(this.props.innerRef, `current`)\n    ) {\n      this.props.innerRef.current = ref\n    } else if (this.props.innerRef) {\n      this.props.innerRef(ref)\n    }\n\n    if (this.state.IOSupported && ref) {\n      // If IO supported and element reference found, setup Observer functionality\n      this.io = createIntersectionObserver(ref, inViewPort => {\n        if (inViewPort) {\n          this.abortPrefetch = this._prefetch()\n        } else {\n          if (this.abortPrefetch) {\n            this.abortPrefetch.abort()\n          }\n        }\n      })\n    }\n  }\n\n  defaultGetProps = ({ isPartiallyCurrent, isCurrent }) => {\n    if (this.props.partiallyActive ? isPartiallyCurrent : isCurrent) {\n      return {\n        className: [this.props.className, this.props.activeClassName]\n          .filter(Boolean)\n          .join(` `),\n        style: { ...this.props.style, ...this.props.activeStyle },\n      }\n    }\n    return null\n  }\n\n  render() {\n    const {\n      to,\n      getProps = this.defaultGetProps,\n      onClick,\n      onMouseEnter,\n      /* eslint-disable no-unused-vars */\n      activeClassName: $activeClassName,\n      activeStyle: $activeStyle,\n      innerRef: $innerRef,\n      partiallyActive,\n      state,\n      replace,\n      _location,\n      /* eslint-enable no-unused-vars */\n      ...rest\n    } = this.props\n\n    if (process.env.NODE_ENV !== `production` && !isLocalLink(to)) {\n      console.warn(\n        `External link ${to} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`\n      )\n    }\n\n    const prefixedTo = rewriteLinkPath(to, _location.pathname)\n    if (!isLocalLink(prefixedTo)) {\n      return <a href={prefixedTo} {...rest} />\n    }\n\n    return (\n      <ReachRouterLink\n        to={prefixedTo}\n        state={state}\n        getProps={getProps}\n        innerRef={this.handleRef}\n        onMouseEnter={e => {\n          if (onMouseEnter) {\n            onMouseEnter(e)\n          }\n          const parsed = parsePath(prefixedTo)\n          ___loader.hovering(parsed.pathname + parsed.search)\n        }}\n        onClick={e => {\n          if (onClick) {\n            onClick(e)\n          }\n\n          if (\n            e.button === 0 && // ignore right clicks\n            !this.props.target && // let browser handle \"target=_blank\"\n            !e.defaultPrevented && // onClick prevented default\n            !e.metaKey && // ignore clicks with modifier keys...\n            !e.altKey &&\n            !e.ctrlKey &&\n            !e.shiftKey\n          ) {\n            e.preventDefault()\n\n            let shouldReplace = replace\n            const isCurrent = encodeURI(prefixedTo) === _location.pathname\n\n            if (typeof replace !== `boolean` && isCurrent) {\n              shouldReplace = true\n            }\n            // Make sure the necessary scripts and data are\n            // loaded before continuing.\n            window.___navigate(prefixedTo, {\n              state,\n              replace: shouldReplace,\n            })\n          }\n\n          return true\n        }}\n        {...rest}\n      />\n    )\n  }\n}\n\nGatsbyLink.propTypes = {\n  ...NavLinkPropTypes,\n  onClick: PropTypes.func,\n  to: PropTypes.string.isRequired,\n  replace: PropTypes.bool,\n  state: PropTypes.object,\n}\n\nexport const Link = React.forwardRef((props, ref) => (\n  <GatsbyLinkLocationWrapper innerRef={ref} {...props} />\n))\n\nexport const navigate = (to, options) => {\n  window.___navigate(rewriteLinkPath(to, window.location.pathname), options)\n}\n"],"names":["parsePath","path","pathname","search","hash","hashIndex","indexOf","slice","searchIndex","isLocalLink","ABSOLUTE_URL_REGEX","test","isAbsolute","getGlobalBasePrefix","process","env","NODE_ENV","__BASE_PATH__","undefined","getGlobalPathPrefix","__PATH_PREFIX__","withPrefix","prefix","_ref","startsWith","base","endsWith","isAbsolutePath","getGlobalTrailingSlash","__TRAILING_SLASH__","applyTrailingSlashOptionOnPathnameOnly","option","applyTrailingSlashOption","rewriteLinkPath","relativeTo","prefixed","applyPrefix","current","absolutePath","resolve","absolutify","withAssetPrefix","activeClassName","PropTypes","string","activeStyle","object","partiallyActive","bool","GatsbyLinkLocationWrapper","props","React","createElement","Location","location","GatsbyLink","_extends","_location","Component","constructor","super","defaultGetProps","isPartiallyCurrent","isCurrent","this","className","filter","Boolean","join","style","IOSupported","window","IntersectionObserver","state","abortPrefetch","handleRef","bind","_prefetch","currentPath","parsed","to","newPathName","enqueue","componentWillUnmount","io","instance","el","abort","unobserve","disconnect","ref","innerRef","Object","prototype","hasOwnProperty","call","cb","entries","forEach","entry","target","isIntersecting","intersectionRatio","observe","createIntersectionObserver","inViewPort","render","_this$props","getProps","onClick","onMouseEnter","replace","rest","_objectWithoutPropertiesLoose","_excluded","console","warn","prefixedTo","ReachRouterLink","e","___loader","hovering","button","defaultPrevented","metaKey","altKey","ctrlKey","shiftKey","preventDefault","shouldReplace","encodeURI","___navigate","href","propTypes","NavLinkPropTypes","func","isRequired","Link","forwardRef","navigate","options"],"mappings":"qbAAO,SAAkBA,EAACC,GACxB,IAAYC,EAAGD,GAAS,IACpBE,EAAU,GACNC,EAAI,GAEZ,MAAMC,EAAYH,EAASI,QAAS,MACjB,IAAfD,IACFD,EAAOF,EAASK,MAAMF,GACtBH,EAAWA,EAASK,MAAM,EAAGF,IAG/B,QAAoBH,EAASI,QAAS,KAMtC,OALqB,IAAjBE,IACFL,EAASD,EAASK,MAAMC,GACxBN,EAAWA,EAASK,MAAM,EAAGC,IAGxB,CACLN,SAAUA,EACVC,OAAoB,MAAZA,EAAkB,GAAIA,EAC9BC,KAAgB,MAAVA,EAAgB,GAAIA,EAE9B,CCrBA,QAA2B,6BAGdK,EAAcR,IACzB,GAAqB,iBAANA,EAMf,OATiBA,IAAQS,EAAmBC,KAAKV,GASzCW,CAAWX,EAAI,ECTZY,EAAsB,IACP,eAA1BC,QAAQC,IAAIC,SACkB,oBAANC,cAClBA,mBACAC,EACFD,cAIOE,EAAsB,IACP,eAA1BL,QAAQC,IAAIC,SACoB,oBAArBI,gBACLA,qBACAF,EACFE,gBAEC,SAAmBC,EAACpB,EAAMqB,EAAST,KACxC,IAAAU,EAAA,IAAKd,EAAYR,GACf,OAAOA,EAGT,GAAIA,EAAKuB,WAAY,OAAQvB,EAAKuB,WAAY,OAC5C,OACFvB,EACA,MAAUwB,SAAAF,EAAS,MAAND,EAAAA,EAAUH,OAA0B,IAEjD,MAAQ,G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