text: var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  
  function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  
  /* eslint-disable jsx-a11y/anchor-has-content */
  import React, { useContext, createContext } from "react";
  import PropTypes from "prop-types";
  import invariant from "invariant";
  import { polyfill } from "react-lifecycles-compat";
  import { startsWith, pick, resolve, match, insertParams, validateRedirect, shallowCompare } from "./lib/utils";
  import { globalHistory, navigate, createHistory, createMemorySource } from "./lib/history";
  
  ////////////////////////////////////////////////////////////////////////////////
  
  var createNamedContext = function createNamedContext(name, defaultValue) {
    var Ctx = createContext(defaultValue);
    Ctx.displayName = name;
    return Ctx;
  };
  
  ////////////////////////////////////////////////////////////////////////////////
  // Location Context/Provider
  var LocationContext = createNamedContext("Location");
  
  // sets up a listener if there isn't one already so apps don't need to be
  // wrapped in some top level provider
  var Location = function Location(_ref) {
    var children = _ref.children;
    return React.createElement(
      LocationContext.Consumer,
      null,
      function (context) {
        return context ? children(context) : React.createElement(
          LocationProvider,
          null,
          children
        );
      }
    );
  };
  
  var LocationProvider = function (_React$Component) {
    _inherits(LocationProvider, _React$Component);
  
    function LocationProvider() {
      var _temp, _this, _ret;
  
      _classCallCheck(this, LocationProvider);
  
      for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }
  
      return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
        context: _this.getContext(),
        refs: { unlisten: null }
      }, _temp), _possibleConstructorReturn(_this, _ret);
    }
  
    LocationProvider.prototype.getContext = function getContext() {
      var _props$history = this.props.history,
          navigate = _props$history.navigate,
          location = _props$history.location;
  
      return { navigate: navigate, location: location };
    };
  
    LocationProvider.prototype.componentDidCatch = function componentDidCatch(error, info) {
      if (isRedirect(error)) {
        var _navigate = this.props.history.navigate;
  
        _navigate(error.uri, { replace: true });
      } else {
        throw error;
      }
    };
  
    LocationProvider.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
      if (prevState.context.location !== this.state.context.location) {
        this.props.history._onTransitionComplete();
      }
    };
  
    LocationProvider.prototype.componentDidMount = function componentDidMount() {
      var _this2 = this;
  
      var refs = this.state.refs,
          history = this.props.history;
  
      history._onTransitionComplete();
      refs.unlisten = history.listen(function () {
        Promise.resolve().then(function () {
          // TODO: replace rAF with react deferred update API when it's ready https://github.com/facebook/react/issues/13306
          requestAnimationFrame(function () {
            if (!_this2.unmounted) {
              _this2.setState(function () {
                return { context: _this2.getContext() };
              });
            }
          });
        });
      });
    };
  
    LocationProvider.prototype.componentWillUnmount = function componentWillUnmount() {
      var refs = this.state.refs;
  
      this.unmounted = true;
      refs.unlisten();
    };
  
    LocationProvider.prototype.render = function render() {
      var context = this.state.context,
          children = this.props.children;
  
      return React.createElement(
        LocationContext.Provider,
        { value: context },
        typeof children === "function" ? children(context) : children || null
      );
    };
  
    return LocationProvider;
  }(React.Component);
  
  ////////////////////////////////////////////////////////////////////////////////
  
  
  LocationProvider.defaultProps = {
    history: globalHistory
  };
  process.env.NODE_ENV !== "production" ? LocationProvider.propTypes = {
    history: PropTypes.object.isRequired
  } : void 0;
  var ServerLocation = function ServerLocation(_ref2) {
    var url = _ref2.url,
        children = _ref2.children;
  
    var searchIndex = url.indexOf("?");
    var searchExists = searchIndex > -1;
    var pathname = void 0;
    var search = "";
    var hash = "";
  
    if (searchExists) {
      pathname = url.substring(0, searchIndex);
      search = url.substring(searchIndex);
    } else {
      pathname = url;
    }
  
    return React.createElement(
      LocationContext.Provider,
      {
        value: {
          location: {
            pathname: pathname,
            search: search,
            hash: hash
          },
          navigate: function navigate() {
            throw new Error("You can't call navigate on the server.");
          }
        }
      },
      children
    );
  };
  ////////////////////////////////////////////////////////////////////////////////
  // Sets baseuri and basepath for nested routers and links
  var BaseContext = createNamedContext("Base", {
    baseuri: "/",
    basepath: "/",
    navigate: globalHistory.navigate
  });
  
  ////////////////////////////////////////////////////////////////////////////////
  // The main event, welcome to the show everybody.
  var Router = function Router(props) {
    return React.createElement(
      BaseContext.Consumer,
      null,
      function (baseContext) {
        return React.createElement(
          Location,
          null,
          function (locationContext) {
            return React.createElement(RouterImpl, _extends({}, baseContext, locationContext, props));
          }
        );
      }
    );
  };
  
  var RouterImpl = function (_React$PureComponent) {
    _inherits(RouterImpl, _React$PureComponent);
  
    function RouterImpl() {
      _classCallCheck(this, RouterImpl);
  
      return _possibleConstructorReturn(this, _React$PureComponent.apply(this, arguments));
    }
  
    RouterImpl.prototype.render = function render() {
      var _props = this.props,
          location = _props.location,
          _navigate2 = _props.navigate,
          basepath = _props.basepath,
          primary = _props.primary,
          children = _props.children,
          baseuri = _props.baseuri,
          _props$component = _props.component,
          component = _props$component === undefined ? "div" : _props$component,
          domProps = _objectWithoutProperties(_props, ["location", "navigate", "basepath", "primary", "children", "baseuri", "component"]);
  
      var routes = React.Children.toArray(children).reduce(function (array, child) {
        var routes = createRoute(basepath)(child);
        return array.concat(routes);
      }, []);
      var pathname = location.pathname;
  
  
      var match = pick(routes, pathname);
  
      if (match) {
        var params = match.params,
            uri = match.uri,
            route = match.route,
            element = match.route.value;
  
        // remove the /* from the end for child routes relative paths
  
        basepath = route.default ? basepath : route.path.replace(/\*$/, "");
  
        var props = _extends({}, params, {
          uri: uri,
          location: location,
          navigate: function navigate(to, options) {
            return _navigate2(resolve(to, uri), options);
          }
        });
  
        var clone = React.cloneElement(element, props, element.props.children ? React.createElement(
          Router,
          { location: location, primary: primary },
          element.props.children
        ) : undefined);
  
        // using 'div' for < 16.3 support
        var FocusWrapper = primary ? FocusHandler : component;
        // don't pass any props to 'div'
        var wrapperProps = primary ? _extends({ uri: uri, location: location, component: component }, domProps) : domProps;
  
        return React.createElement(
          BaseContext.Provider,
          {
            value: { baseuri: uri, basepath: basepath, navigate: props.navigate }
          },
          React.createElement(
            FocusWrapper,
            wrapperProps,
            clone
          )
        );
      } else {
        // Not sure if we want this, would require index routes at every level
        // warning(
        //   false,
        //   `<Router basepath="${basepath}">\n\nNothing matched:\n\t${
        //     location.pathname
        //   }\n\nPaths checked: \n\t${routes
        //     .map(route => route.path)
        //     .join(
        //       "\n\t"
        //     )}\n\nTo get rid of this warning, add a default NotFound component as child of Router:
        //   \n\tlet NotFound = () => <div>Not Found!</div>
        //   \n\t<Router>\n\t  <NotFound default/>\n\t  {/* ... */}\n\t</Router>`
        // );
        return null;
      }
    };
  
    return RouterImpl;
  }(React.PureComponent);
  
  RouterImpl.defaultProps = {
    primary: true
  };
  
  
  var FocusContext = createNamedContext("Focus");
  
  var FocusHandler = function FocusHandler(_ref3) {
    var uri = _ref3.uri,
        location = _ref3.location,
        component = _ref3.component,
        domProps = _objectWithoutProperties(_ref3, ["uri", "location", "component"]);
  
    return React.createElement(
      FocusContext.Consumer,
      null,
      function (requestFocus) {
        return React.createElement(FocusHandlerImpl, _extends({}, domProps, {
          component: component,
          requestFocus: requestFocus,
          uri: uri,
          location: location
        }));
      }
    );
  };
  
  // don't focus on initial render
  var initialRender = true;
  var focusHandlerCount = 0;
  
  var FocusHandlerImpl = function (_React$Component2) {
    _inherits(FocusHandlerImpl, _React$Component2);
  
    function FocusHandlerImpl() {
      var _temp2, _this4, _ret2;
  
      _classCallCheck(this, FocusHandlerImpl);
  
      for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
        args[_key2] = arguments[_key2];
      }
  
      return _ret2 = (_temp2 = (_this4 = _possibleConstructorReturn(this, _React$Component2.call.apply(_React$Component2, [this].concat(args))), _this4), _this4.state = {}, _this4.requestFocus = function (node) {
        if (!_this4.state.shouldFocus && node) {
          node.focus();
        }
      }, _temp2), _possibleConstructorReturn(_this4, _ret2);
    }
  
    FocusHandlerImpl.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
      var initial = prevState.uri == null;
      if (initial) {
        return _extends({
          shouldFocus: true
        }, nextProps);
      } else {
        var myURIChanged = nextProps.uri !== prevState.uri;
        var navigatedUpToMe = prevState.location.pathname !== nextProps.location.pathname && nextProps.location.pathname === nextProps.uri;
        return _extends({
          shouldFocus: myURIChanged || navigatedUpToMe
        }, nextProps);
      }
    };
  
    FocusHandlerImpl.prototype.componentDidMount = function componentDidMount() {
      focusHandlerCount++;
      this.focus();
    };
  
    FocusHandlerImpl.prototype.componentWillUnmount = function componentWillUnmount() {
      focusHandlerCount--;
      if (focusHandlerCount === 0) {
        initialRender = true;
      }
    };
  
    FocusHandlerImpl.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
      if (prevProps.location !== this.props.location && this.state.shouldFocus) {
        this.focus();
      }
    };
  
    FocusHandlerImpl.prototype.focus = function focus() {
      if (process.env.NODE_ENV === "test") {
        // getting cannot read property focus of null in the tests
        // and that bit of global `initialRender` state causes problems
        // should probably figure it out!
        return;
      }
  
      var requestFocus = this.props.requestFocus;
  
  
      if (requestFocus) {
        requestFocus(this.node);
      } else {
        if (initialRender) {
          initialRender = false;
        } else if (this.node) {
          // React polyfills [autofocus] and it fires earlier than cDM,
          // so we were stealing focus away, this line prevents that.
          if (!this.node.contains(document.activeElement)) {
            this.node.focus();
          }
        }
      }
    };
  
    FocusHandlerImpl.prototype.render = function render() {
      var _this5 = this;
  
      var _props2 = this.props,
          children = _props2.children,
          style = _props2.style,
          requestFocus = _props2.requestFocus,
          _props2$component = _props2.component,
          Comp = _props2$component === undefined ? "div" : _props2$component,
          uri = _props2.uri,
          location = _props2.location,
          domProps = _objectWithoutProperties(_props2, ["children", "style", "requestFocus", "component", "uri", "location"]);
  
      return React.createElement(
        Comp,
        _extends({
          style: _extends({ outline: "none" }, style),
          tabIndex: "-1",
          ref: function ref(n) {
            return _this5.node = n;
          }
        }, domProps),
        React.createElement(
          FocusContext.Provider,
          { value: this.requestFocus },
          this.props.children
        )
      );
    };
  
    return FocusHandlerImpl;
  }(React.Component);
  
  polyfill(FocusHandlerImpl);
  
  var k = function k() {};
  
  ////////////////////////////////////////////////////////////////////////////////
  var forwardRef = React.forwardRef;
  
  if (typeof forwardRef === "undefined") {
    forwardRef = function forwardRef(C) {
      return C;
    };
  }
  
  var Link = forwardRef(function (_ref4, ref) {
    var innerRef = _ref4.innerRef,
        props = _objectWithoutProperties(_ref4, ["innerRef"]);
  
    return React.createElement(
      BaseContext.Consumer,
      null,
      function (_ref5) {
        var basepath = _ref5.basepath,
            baseuri = _ref5.baseuri;
        return React.createElement(
          Location,
          null,
          function (_ref6) {
            var location = _ref6.location,
                navigate = _ref6.navigate;
  
            var to = props.to,
                state = props.state,
                replace = props.replace,
                _props$getProps = props.getProps,
                getProps = _props$getProps === undefined ? k : _props$getProps,
                anchorProps = _objectWithoutProperties(props, ["to", "state", "replace", "getProps"]);
  
            var href = resolve(to, baseuri);
            var encodedHref = encodeURI(href);
            var isCurrent = location.pathname === encodedHref;
            var isPartiallyCurrent = startsWith(location.pathname, encodedHref);
  
            return React.createElement("a", _extends({
              ref: ref || innerRef,
              "aria-current": isCurrent ? "page" : undefined
            }, anchorProps, getProps({ isCurrent: isCurrent, isPartiallyCurrent: isPartiallyCurrent, href: href, location: location }), {
              href: href,
              onClick: function onClick(event) {
                if (anchorProps.onClick) anchorProps.onClick(event);
                if (shouldNavigate(event)) {
                  event.preventDefault();
                  var shouldReplace = replace;
                  if (typeof replace !== "boolean" && isCurrent) {
                    var _location$state = _extends({}, location.state),
                        key = _location$state.key,
                        restState = _objectWithoutProperties(_location$state, ["key"]);
  
                    shouldReplace = shallowCompare(_extends({}, state), restState);
                  }
                  navigate(href, {
                    state: state,
                    replace: shouldReplace
                  });
                }
              }
            }));
          }
        );
      }
    );
  });
  
  Link.displayName = "Link";
  
  process.env.NODE_ENV !== "production" ? Link.propTypes = {
    to: PropTypes.string.isRequired
  } : void 0;
  
  ////////////////////////////////////////////////////////////////////////////////
  function RedirectRequest(uri) {
    this.uri = uri;
  }
  
  var isRedirect = function isRedirect(o) {
    return o instanceof RedirectRequest;
  };
  
  var redirectTo = function redirectTo(to) {
    throw new RedirectRequest(to);
  };
  
  var RedirectImpl = function (_React$Component3) {
    _inherits(RedirectImpl, _React$Component3);
  
    function RedirectImpl() {
      _classCallCheck(this, RedirectImpl);
  
      return _possibleConstructorReturn(this, _React$Component3.apply(this, arguments));
    }
  
    // Support React < 16 with this hook
    RedirectImpl.prototype.componentDidMount = function componentDidMount() {
      var _props3 = this.props,
          navigate = _props3.navigate,
          to = _props3.to,
          from = _props3.from,
          _props3$replace = _props3.replace,
          replace = _props3$replace === undefined ? true : _props3$replace,
          state = _props3.state,
          noThrow = _props3.noThrow,
          baseuri = _props3.baseuri,
          props = _objectWithoutProperties(_props3, ["navigate", "to", "from", "replace", "state", "noThrow", "baseuri"]);
  
      Promise.resolve().then(function () {
        var resolvedTo = resolve(to, baseuri);
        navigate(insertParams(resolvedTo, props), { replace: replace, state: state });
      });
    };
  
    RedirectImpl.prototype.render = function render() {
      var _props4 = this.props,
          navigate = _props4.navigate,
          to = _props4.to,
          from = _props4.from,
          replace = _props4.replace,
          state = _props4.state,
          noThrow = _props4.noThrow,
          baseuri = _props4.baseuri,
          props = _objectWithoutProperties(_props4, ["navigate", "to", "from", "replace", "state", "noThrow", "baseuri"]);
  
      var resolvedTo = resolve(to, baseuri);
      if (!noThrow) redirectTo(insertParams(resolvedTo, props));
      return null;
    };
  
    return RedirectImpl;
  }(React.Component);
  
  var Redirect = function Redirect(props) {
    return React.createElement(
      BaseContext.Consumer,
      null,
      function (_ref7) {
        var baseuri = _ref7.baseuri;
        return React.createElement(
          Location,
          null,
          function (locationContext) {
            return React.createElement(RedirectImpl, _extends({}, locationContext, { baseuri: baseuri }, props));
          }
        );
      }
    );
  };
  
  process.env.NODE_ENV !== "production" ? Redirect.propTypes = {
    from: PropTypes.string,
    to: PropTypes.string.isRequired
  } : void 0;
  
  ////////////////////////////////////////////////////////////////////////////////
  var Match = function Match(_ref8) {
    var path = _ref8.path,
        children = _ref8.children;
    return React.createElement(
      BaseContext.Consumer,
      null,
      function (_ref9) {
        var baseuri = _ref9.baseuri;
        return React.createElement(
          Location,
          null,
          function (_ref10) {
            var navigate = _ref10.navigate,
                location = _ref10.location;
  
            var resolvedPath = resolve(path, baseuri);
            var result = match(resolvedPath, location.pathname);
            return children({
              navigate: navigate,
              location: location,
              match: result ? _extends({}, result.params, {
                uri: result.uri,
                path: path
              }) : null
            });
          }
        );
      }
    );
  };
  
  ////////////////////////////////////////////////////////////////////////////////
  // Hooks
  
  var useLocation = function useLocation() {
    var context = useContext(LocationContext);
  
    if (!context) {
      throw new Error("useLocation hook was used but a LocationContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");
    }
  
    return context.location;
  };
  
  var useNavigate = function useNavigate() {
    var context = useContext(BaseContext);
  
    if (!context) {
      throw new Error("useNavigate hook was used but a BaseContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");
    }
  
    return context.navigate;
  };
  
  var useParams = function useParams() {
    var context = useContext(BaseContext);
  
    if (!context) {
      throw new Error("useParams hook was used but a LocationContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");
    }
  
    var location = useLocation();
  
    var results = match(context.basepath, location.pathname);
  
    return results ? results.params : null;
  };
  
  var useMatch = function useMatch(path) {
    if (!path) {
      throw new Error("useMatch(path: string) requires an argument of a string to match against");
    }
    var context = useContext(BaseContext);
  
    if (!context) {
      throw new Error("useMatch hook was used but a LocationContext.Provider was not found in the parent tree. Make sure this is used in a component that is a child of Router");
    }
  
    var location = useLocation();
  
    var resolvedPath = resolve(path, context.baseuri);
    var result = match(resolvedPath, location.pathname);
    return result ? _extends({}, result.params, {
      uri: result.uri,
      path: path
    }) : null;
  };
  
  ////////////////////////////////////////////////////////////////////////////////
  // Junk
  var stripSlashes = function stripSlashes(str) {
    return str.replace(/(^\/+|\/+$)/g, "");
  };
  
  var createRoute = function createRoute(basepath) {
    return function (element) {
      if (!element) {
        return null;
      }
  
      if (element.type === React.Fragment && element.props.children) {
        return React.Children.map(element.props.children, createRoute(basepath));
      }
      !(element.props.path || element.props.default || element.type === Redirect) ? process.env.NODE_ENV !== "production" ? invariant(false, "<Router>: Children of <Router> must have a `path` or `default` prop, or be a `<Redirect>`. None found on element type `" + element.type + "`") : invariant(false) : void 0;
  
      !!(element.type === Redirect && (!element.props.from || !element.props.to)) ? process.env.NODE_ENV !== "production" ? invariant(false, "<Redirect from=\"" + element.props.from + "\" to=\"" + element.props.to + "\"/> requires both \"from\" and \"to\" props when inside a <Router>.") : invariant(false) : void 0;
  
      !!(element.type === Redirect && !validateRedirect(element.props.from, element.props.to)) ? process.env.NODE_ENV !== "production" ? invariant(false, "<Redirect from=\"" + element.props.from + " to=\"" + element.props.to + "\"/> has mismatched dynamic segments, ensure both paths have the exact same dynamic segments.") : invariant(false) : void 0;
  
      if (element.props.default) {
        return { value: element, default: true };
      }
  
      var elementPath = element.type === Redirect ? element.props.from : element.props.path;
  
      var path = elementPath === "/" ? basepath : stripSlashes(basepath) + "/" + stripSlashes(elementPath);
  
      return {
        value: element,
        default: element.props.default,
        path: element.props.children ? stripSlashes(path) + "/*" : path
      };
    };
  };
  
  var shouldNavigate = function shouldNavigate(event) {
    return !event.defaultPrevented && event.button === 0 && !(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
  };
  
  ////////////////////////////////////////////////////////////////////////
  export { Link, Location, LocationProvider, Match, Redirect, Router, ServerLocation, createHistory, createMemorySource, isRedirect, navigate, redirectTo, globalHistory, match as matchPath, useLocation, useNavigate, useParams, useMatch };