{"ast":null,"code":"\"use strict\";\n\nvar _slicedToArray = require(\"@babel/runtime/helpers/slicedToArray\");\n\nvar _interopRequireWildcard = require(\"@babel/runtime/helpers/interopRequireWildcard\");\n\nexports.__esModule = true;\nexports[\"default\"] = void 0;\n\nvar _react = _interopRequireWildcard(require(\"react\"));\n\nvar _utils = require(\"../next-server/lib/utils\");\n\nvar _router = require(\"./router\");\n\nvar _router2 = require(\"../next-server/lib/router/router\");\n/**\n* Detects whether a given url is from the same origin as the current page (browser only).\n*/\n\n\nfunction isLocal(url) {\n  var locationOrigin = (0, _utils.getLocationOrigin)();\n  var resolved = new URL(url, locationOrigin);\n  return resolved.origin === locationOrigin;\n}\n\nvar cachedObserver;\nvar listeners = new Map();\nvar IntersectionObserver = true ? window.IntersectionObserver : null;\nvar prefetched = {};\n\nfunction getObserver() {\n  // Return shared instance of IntersectionObserver if already created\n  if (cachedObserver) {\n    return cachedObserver;\n  } // Only create shared IntersectionObserver if supported in browser\n\n\n  if (!IntersectionObserver) {\n    return undefined;\n  }\n\n  return cachedObserver = new IntersectionObserver(function (entries) {\n    entries.forEach(function (entry) {\n      if (!listeners.has(entry.target)) {\n        return;\n      }\n\n      var cb = listeners.get(entry.target);\n\n      if (entry.isIntersecting || entry.intersectionRatio > 0) {\n        cachedObserver.unobserve(entry.target);\n        listeners[\"delete\"](entry.target);\n        cb();\n      }\n    });\n  }, {\n    rootMargin: '200px'\n  });\n}\n\nvar listenToIntersections = function listenToIntersections(el, cb) {\n  var observer = getObserver();\n\n  if (!observer) {\n    return function () {};\n  }\n\n  observer.observe(el);\n  listeners.set(el, cb);\n  return function () {\n    try {\n      observer.unobserve(el);\n    } catch (err) {\n      console.error(err);\n    }\n\n    listeners[\"delete\"](el);\n  };\n};\n\nfunction prefetch(router, href, as, options) {\n  if (false) return; // Prefetch the JSON page if asked (only in the client)\n  // We need to handle a prefetch error here since we may be\n  // loading with priority which can reject but we don't\n  // want to force navigation since this is only a prefetch\n\n  router.prefetch(href, as, options)[\"catch\"](function (err) {\n    if (false) {\n      // rethrow to show invalid URL errors\n      throw err;\n    }\n  }); // Join on an invalid URI character\n\n  prefetched[href + '%' + as] = true;\n}\n\nfunction linkClicked(e, router, href, as, replace, shallow, scroll) {\n  var _e$currentTarget = e.currentTarget,\n      nodeName = _e$currentTarget.nodeName,\n      target = _e$currentTarget.target;\n\n  if (nodeName === 'A' && (target && target !== '_self' || e.metaKey || e.ctrlKey || e.shiftKey || e.nativeEvent && e.nativeEvent.which === 2)) {\n    // ignore click for new tab / new window behavior\n    return;\n  }\n\n  if (!isLocal(href)) {\n    // ignore click if it's outside our scope (e.g. https://google.com)\n    return;\n  }\n\n  e.preventDefault(); //  avoid scroll for urls with anchor refs\n\n  if (scroll == null) {\n    scroll = as.indexOf('#') < 0;\n  } // replace state instead of push if prop is present\n\n\n  router[replace ? 'replace' : 'push'](href, as, {\n    shallow: shallow\n  }).then(function (success) {\n    if (!success) return;\n\n    if (scroll) {\n      window.scrollTo(0, 0);\n      document.body.focus();\n    }\n  });\n}\n\nfunction Link(props) {\n  if (false) {\n    // This hook is in a conditional but that is ok because `process.env.NODE_ENV` never changes\n    // eslint-disable-next-line react-hooks/rules-of-hooks\n    var hasWarned = _react[\"default\"].useRef(false);\n\n    if (props.prefetch && !hasWarned.current) {\n      hasWarned.current = true;\n      console.warn('Next.js auto-prefetches automatically based on viewport. The prefetch attribute is no longer needed. More: https://err.sh/vercel/next.js/prefetch-true-deprecated');\n    }\n  }\n\n  var p = props.prefetch !== false;\n\n  var _react$default$useSta = _react[\"default\"].useState(),\n      _react$default$useSta2 = _slicedToArray(_react$default$useSta, 2),\n      childElm = _react$default$useSta2[0],\n      setChildElm = _react$default$useSta2[1];\n\n  var router = (0, _router.useRouter)();\n\n  var _react$default$useMem = _react[\"default\"].useMemo(function () {\n    var resolvedHref = (0, _router2.resolveHref)(router.pathname, props.href);\n    return {\n      href: resolvedHref,\n      as: props.as ? (0, _router2.resolveHref)(router.pathname, props.as) : resolvedHref\n    };\n  }, [router.pathname, props.href, props.as]),\n      href = _react$default$useMem.href,\n      as = _react$default$useMem.as;\n\n  _react[\"default\"].useEffect(function () {\n    if (p && IntersectionObserver && childElm && childElm.tagName) {\n      // Join on an invalid URI character\n      var isPrefetched = prefetched[href + '%' + as];\n\n      if (!isPrefetched) {\n        return listenToIntersections(childElm, function () {\n          prefetch(router, href, as);\n        });\n      }\n    }\n  }, [p, childElm, href, as, router]);\n\n  var children = props.children,\n      replace = props.replace,\n      shallow = props.shallow,\n      scroll = props.scroll; // Deprecated. Warning shown by propType check. If the children provided is a string (<Link>example</Link>) we wrap it in an <a> tag\n\n  if (typeof children === 'string') {\n    children = /*#__PURE__*/_react[\"default\"].createElement(\"a\", null, children);\n  } // This will return the first child, if multiple are provided it will throw an error\n\n\n  var child = _react.Children.only(children);\n\n  var childProps = {\n    ref: function ref(el) {\n      if (el) setChildElm(el);\n\n      if (child && typeof child === 'object' && child.ref) {\n        if (typeof child.ref === 'function') child.ref(el);else if (typeof child.ref === 'object') {\n          child.ref.current = el;\n        }\n      }\n    },\n    onClick: function onClick(e) {\n      if (child.props && typeof child.props.onClick === 'function') {\n        child.props.onClick(e);\n      }\n\n      if (!e.defaultPrevented) {\n        linkClicked(e, router, href, as, replace, shallow, scroll);\n      }\n    }\n  };\n\n  if (p) {\n    childProps.onMouseEnter = function (e) {\n      if (child.props && typeof child.props.onMouseEnter === 'function') {\n        child.props.onMouseEnter(e);\n      }\n\n      prefetch(router, href, as, {\n        priority: true\n      });\n    };\n  } // If child is an <a> tag and doesn't have a href attribute, or if the 'passHref' property is\n  // defined, we specify the current 'href', so that repetition is not needed by the user\n\n\n  if (props.passHref || child.type === 'a' && !('href' in child.props)) {\n    childProps.href = (0, _router2.addBasePath)(as);\n  } // Add the ending slash to the paths. So, we can serve the\n  // \"<page>/index.html\" directly.\n\n\n  if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n    var rewriteUrlForNextExport = require('../next-server/lib/router/rewrite-url-for-export').rewriteUrlForNextExport;\n\n    if (childProps.href && typeof __NEXT_DATA__ !== 'undefined' && __NEXT_DATA__.nextExport) {\n      childProps.href = rewriteUrlForNextExport(childProps.href);\n    }\n  }\n\n  return _react[\"default\"].cloneElement(child, childProps);\n}\n\nif (false) {\n  var warn = (0, _utils.execOnce)(console.error); // This module gets removed by webpack.IgnorePlugin\n\n  var PropTypes = require('prop-types');\n\n  var exact = require('prop-types-exact'); // @ts-ignore the property is supported, when declaring it on the class it outputs an extra bit of code which is not needed.\n\n\n  Link.propTypes = exact({\n    href: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,\n    as: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),\n    prefetch: PropTypes.bool,\n    replace: PropTypes.bool,\n    shallow: PropTypes.bool,\n    passHref: PropTypes.bool,\n    scroll: PropTypes.bool,\n    children: PropTypes.oneOfType([PropTypes.element, function (props, propName) {\n      var value = props[propName];\n\n      if (typeof value === 'string') {\n        warn(\"Warning: You're using a string directly inside <Link>. This usage has been deprecated. Please add an <a> tag as child of <Link>\");\n      }\n\n      return null;\n    }]).isRequired\n  });\n}\n\nvar _default = Link;\nexports[\"default\"] = _default;","map":null,"metadata":{},"sourceType":"script"}