create-dan
Version:
Dan frameworks
1 lines • 63.4 kB
JSON
{"ast":null,"code":"\"use strict\";\n\nvar _regeneratorRuntime = require(\"@babel/runtime-corejs2/regenerator\");\n\nvar _slicedToArray = require(\"@babel/runtime-corejs2/helpers/slicedToArray\");\n\nvar _Object$assign = require(\"@babel/runtime-corejs2/core-js/object/assign\");\n\nvar _Promise = require(\"@babel/runtime-corejs2/core-js/promise\");\n\nvar _classCallCheck = require(\"@babel/runtime-corejs2/helpers/classCallCheck\");\n\nvar _createClass = require(\"@babel/runtime-corejs2/helpers/createClass\");\n\nvar _Object$defineProperty = require(\"@babel/runtime-corejs2/core-js/object/define-property\");\n\nvar __importDefault = this && this.__importDefault || function (mod) {\n return mod && mod.__esModule ? mod : {\n \"default\": mod\n };\n};\n\n_Object$defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar url_1 = require(\"url\");\n\nvar mitt_1 = __importDefault(require(\"../mitt\"));\n\nvar utils_1 = require(\"../utils\");\n\nvar is_dynamic_1 = require(\"./utils/is-dynamic\");\n\nvar route_matcher_1 = require(\"./utils/route-matcher\");\n\nvar route_regex_1 = require(\"./utils/route-regex\");\n\nfunction addBasePath(path) {\n // @ts-ignore variable is always a string\n var p = process.env.__NEXT_ROUTER_BASEPATH;\n return path.indexOf(p) !== 0 ? p + path : path;\n}\n\nfunction toRoute(path) {\n return path.replace(/\\/$/, '') || '/';\n}\n\nvar Router =\n/*#__PURE__*/\nfunction () {\n function Router(pathname, query, as, _ref) {\n var _this = this;\n\n var initialProps = _ref.initialProps,\n pageLoader = _ref.pageLoader,\n App = _ref.App,\n wrapApp = _ref.wrapApp,\n Component = _ref.Component,\n err = _ref.err,\n subscription = _ref.subscription;\n\n _classCallCheck(this, Router);\n\n // Static Data Cache\n this.sdc = {};\n\n this.onPopState = function (e) {\n if (!e.state) {\n // We get state as undefined for two reasons.\n // 1. With older safari (< 8) and older chrome (< 34)\n // 2. When the URL changed with #\n //\n // In the both cases, we don't need to proceed and change the route.\n // (as it's already changed)\n // But we can simply replace the state with the new changes.\n // Actually, for (1) we don't need to nothing. But it's hard to detect that event.\n // So, doing the following for (1) does no harm.\n var _pathname = _this.pathname,\n _query = _this.query;\n\n _this.changeState('replaceState', utils_1.formatWithValidation({\n pathname: _pathname,\n query: _query\n }), utils_1.getURL());\n\n return;\n } // Make sure we don't re-render on initial load,\n // can be caused by navigating back from an external site\n\n\n if (e.state && _this.isSsr && e.state.url === _this.pathname && e.state.as === _this.asPath) {\n return;\n } // If the downstream application returns falsy, return.\n // They will then be responsible for handling the event.\n\n\n if (_this._bps && !_this._bps(e.state)) {\n return;\n }\n\n var _e$state = e.state,\n url = _e$state.url,\n as = _e$state.as,\n options = _e$state.options;\n\n if (true) {\n if (typeof url === 'undefined' || typeof as === 'undefined') {\n console.warn('`popstate` event triggered but `event.state` did not have `url` or `as` https://err.sh/zeit/next.js/popstate-state-empty');\n }\n }\n\n _this.replace(url, as, options);\n };\n\n this._getStaticData = function (asPath, _cachedData) {\n var pathname = url_1.parse(asPath).pathname;\n pathname = !pathname || pathname === '/' ? '/index' : pathname;\n return false && (_cachedData = _this.sdc[pathname]) ? _Promise.resolve(_cachedData) : fetch( // @ts-ignore __NEXT_DATA__\n \"/_next/data/\".concat(__NEXT_DATA__.buildId).concat(pathname, \".json\")).then(function (res) {\n if (!res.ok) {\n throw new Error(\"Failed to load static props\");\n }\n\n return res.json();\n }).then(function (data) {\n _this.sdc[pathname] = data;\n return data;\n })[\"catch\"](function (err) {\n ;\n err.code = 'PAGE_LOAD_ERROR';\n throw err;\n });\n }; // represents the current component key\n\n\n this.route = toRoute(pathname); // set up the component cache (by route keys)\n\n this.components = {}; // We should not keep the cache, if there's an error\n // Otherwise, this cause issues when when going back and\n // come again to the errored page.\n\n if (pathname !== '/_error') {\n this.components[this.route] = {\n Component: Component,\n props: initialProps,\n err: err\n };\n }\n\n this.components['/_app'] = {\n Component: App\n }; // Backwards compat for Router.router.events\n // TODO: Should be remove the following major version as it was never documented\n // @ts-ignore backwards compatibility\n\n this.events = Router.events;\n this.pageLoader = pageLoader;\n this.pathname = pathname;\n this.query = query; // if auto prerendered and dynamic route wait to update asPath\n // until after mount to prevent hydration mismatch\n\n this.asPath = // @ts-ignore this is temporarily global (attached to window)\n is_dynamic_1.isDynamicRoute(pathname) && __NEXT_DATA__.autoExport ? pathname : as;\n this.sub = subscription;\n this.clc = null;\n this._wrapApp = wrapApp; // make sure to ignore extra popState in safari on navigating\n // back from external site\n\n this.isSsr = true;\n\n if (true) {\n // in order for `e.state` to work on the `onpopstate` event\n // we have to register the initial route upon initialization\n this.changeState('replaceState', utils_1.formatWithValidation({\n pathname: pathname,\n query: query\n }), as);\n window.addEventListener('popstate', this.onPopState);\n }\n } // @deprecated backwards compatibility even though it's a private method.\n\n\n _createClass(Router, [{\n key: \"update\",\n value: function update(route, mod) {\n var Component = mod[\"default\"] || mod;\n var data = this.components[route];\n\n if (!data) {\n throw new Error(\"Cannot update unavailable route: \".concat(route));\n }\n\n var newData = _Object$assign(_Object$assign({}, data), {\n Component: Component\n });\n\n this.components[route] = newData; // pages/_app.js updated\n\n if (route === '/_app') {\n this.notify(this.components[this.route]);\n return;\n }\n\n if (route === this.route) {\n this.notify(newData);\n }\n }\n }, {\n key: \"reload\",\n value: function reload() {\n window.location.reload();\n }\n /**\n * Go back in history\n */\n\n }, {\n key: \"back\",\n value: function back() {\n window.history.back();\n }\n /**\n * Performs a `pushState` with arguments\n * @param url of the route\n * @param as masks `url` for the browser\n * @param options object you can define `shallow` and other options\n */\n\n }, {\n key: \"push\",\n value: function push(url) {\n var as = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : url;\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n return this.change('pushState', url, as, options);\n }\n /**\n * Performs a `replaceState` with arguments\n * @param url of the route\n * @param as masks `url` for the browser\n * @param options object you can define `shallow` and other options\n */\n\n }, {\n key: \"replace\",\n value: function replace(url) {\n var as = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : url;\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n return this.change('replaceState', url, as, options);\n }\n }, {\n key: \"change\",\n value: function change(method, _url, _as, options) {\n var _this2 = this;\n\n return new _Promise(function (resolve, reject) {\n if (!options._h) {\n _this2.isSsr = false;\n } // marking route changes as a navigation start entry\n\n\n if (utils_1.ST) {\n performance.mark('routeChange');\n } // If url and as provided as an object representation,\n // we'll format them into the string version here.\n\n\n var url = typeof _url === 'object' ? utils_1.formatWithValidation(_url) : _url;\n var as = typeof _as === 'object' ? utils_1.formatWithValidation(_as) : _as; // Add the ending slash to the paths. So, we can serve the\n // \"<page>/index.html\" directly for the SSR page.\n\n if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n var rewriteUrlForNextExport = require('./rewrite-url-for-export').rewriteUrlForNextExport; // @ts-ignore this is temporarily global (attached to window)\n\n\n if (__NEXT_DATA__.nextExport) {\n as = rewriteUrlForNextExport(as);\n }\n }\n\n _this2.abortComponentLoad(as); // If the url change is only related to a hash change\n // We should not proceed. We should only change the state.\n // WARNING: `_h` is an internal option for handing Next.js client-side\n // hydration. Your app should _never_ use this property. It may change at\n // any time without notice.\n\n\n if (!options._h && _this2.onlyAHashChange(as)) {\n _this2.asPath = as;\n Router.events.emit('hashChangeStart', as);\n\n _this2.changeState(method, url, addBasePath(as));\n\n _this2.scrollToHash(as);\n\n Router.events.emit('hashChangeComplete', as);\n return resolve(true);\n }\n\n var _url_1$parse = url_1.parse(url, true),\n pathname = _url_1$parse.pathname,\n query = _url_1$parse.query,\n protocol = _url_1$parse.protocol;\n\n if (!pathname || protocol) {\n if (true) {\n throw new Error(\"Invalid href passed to router: \".concat(url, \" https://err.sh/zeit/next.js/invalid-href-passed\"));\n }\n\n return resolve(false);\n } // If asked to change the current URL we should reload the current page\n // (not location.reload() but reload getInitialProps and other Next.js stuffs)\n // We also need to set the method = replaceState always\n // as this should not go into the history (That's how browsers work)\n // We should compare the new asPath to the current asPath, not the url\n\n\n if (!_this2.urlIsNew(as)) {\n method = 'replaceState';\n } // @ts-ignore pathname is always a string\n\n\n var route = toRoute(pathname);\n var _options$shallow = options.shallow,\n shallow = _options$shallow === void 0 ? false : _options$shallow;\n\n if (is_dynamic_1.isDynamicRoute(route)) {\n var _url_1$parse2 = url_1.parse(as),\n asPathname = _url_1$parse2.pathname;\n\n var routeMatch = route_matcher_1.getRouteMatcher(route_regex_1.getRouteRegex(route))(asPathname);\n\n if (!routeMatch) {\n var error = \"The provided `as` value (\".concat(asPathname, \") is incompatible with the `href` value (\").concat(route, \"). \") + \"Read more: https://err.sh/zeit/next.js/incompatible-href-as\";\n\n if (true) {\n throw new Error(error);\n } else {\n console.error(error);\n }\n\n return resolve(false);\n } // Merge params into `query`, overwriting any specified in search\n\n\n _Object$assign(query, routeMatch);\n }\n\n Router.events.emit('routeChangeStart', as); // If shallow is true and the route exists in the router cache we reuse the previous result\n // @ts-ignore pathname is always a string\n\n _this2.getRouteInfo(route, pathname, query, as, shallow).then(function (routeInfo) {\n var error = routeInfo.error;\n\n if (error && error.cancelled) {\n return resolve(false);\n }\n\n Router.events.emit('beforeHistoryChange', as);\n\n _this2.changeState(method, url, addBasePath(as), options);\n\n var hash = window.location.hash.substring(1);\n\n if (true) {\n var appComp = _this2.components['/_app'].Component;\n window.next.isPrerendered = appComp.getInitialProps === appComp.origGetInitialProps && !routeInfo.Component.getInitialProps;\n } // @ts-ignore pathname is always defined\n\n\n _this2.set(route, pathname, query, as, _Object$assign(_Object$assign({}, routeInfo), {\n hash: hash\n }));\n\n if (error) {\n Router.events.emit('routeChangeError', error, as);\n throw error;\n }\n\n Router.events.emit('routeChangeComplete', as);\n return resolve(true);\n }, reject);\n });\n }\n }, {\n key: \"changeState\",\n value: function changeState(method, url, as) {\n var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};\n\n if (true) {\n if (typeof window.history === 'undefined') {\n console.error(\"Warning: window.history is not available.\");\n return;\n } // @ts-ignore method should always exist on history\n\n\n if (typeof window.history[method] === 'undefined') {\n console.error(\"Warning: window.history.\".concat(method, \" is not available\"));\n return;\n }\n }\n\n if (method !== 'pushState' || utils_1.getURL() !== as) {\n // @ts-ignore method should always exist on history\n window.history[method]({\n url: url,\n as: as,\n options: options\n }, null, as);\n }\n }\n }, {\n key: \"getRouteInfo\",\n value: function getRouteInfo(route, pathname, query, as) {\n var _this3 = this;\n\n var shallow = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;\n var cachedRouteInfo = this.components[route]; // If there is a shallow route transition possible\n // If the route is already rendered on the screen.\n\n if (shallow && cachedRouteInfo && this.route === route) {\n return _Promise.resolve(cachedRouteInfo);\n }\n\n return new _Promise(function (resolve, reject) {\n if (cachedRouteInfo) {\n return resolve(cachedRouteInfo);\n }\n\n _this3.fetchComponent(route).then(function (Component) {\n return resolve({\n Component: Component\n });\n }, reject);\n }).then(function (routeInfo) {\n var Component = routeInfo.Component;\n\n if (true) {\n var _require = require('react-is'),\n isValidElementType = _require.isValidElementType;\n\n if (!isValidElementType(Component)) {\n throw new Error(\"The default export is not a React Component in page: \\\"\".concat(pathname, \"\\\"\"));\n }\n }\n\n return _this3._getData(function () {\n return Component.__N_SSG ? _this3._getStaticData(as) : _this3.getInitialProps(Component, // we provide AppTree later so this needs to be `any`\n {\n pathname: pathname,\n query: query,\n asPath: as\n });\n }).then(function (props) {\n routeInfo.props = props;\n _this3.components[route] = routeInfo;\n return routeInfo;\n });\n })[\"catch\"](function (err) {\n return new _Promise(function (resolve) {\n if (err.code === 'PAGE_LOAD_ERROR') {\n // If we can't load the page it could be one of following reasons\n // 1. Page doesn't exists\n // 2. Page does exist in a different zone\n // 3. Internal error while loading the page\n // So, doing a hard reload is the proper way to deal with this.\n window.location.href = as; // Changing the URL doesn't block executing the current code path.\n // So, we need to mark it as a cancelled error and stop the routing logic.\n\n err.cancelled = true; // @ts-ignore TODO: fix the control flow here\n\n return resolve({\n error: err\n });\n }\n\n if (err.cancelled) {\n // @ts-ignore TODO: fix the control flow here\n return resolve({\n error: err\n });\n }\n\n resolve(_this3.fetchComponent('/_error').then(function (Component) {\n var routeInfo = {\n Component: Component,\n err: err\n };\n return new _Promise(function (resolve) {\n _this3.getInitialProps(Component, {\n err: err,\n pathname: pathname,\n query: query\n }).then(function (props) {\n routeInfo.props = props;\n routeInfo.error = err;\n resolve(routeInfo);\n }, function (gipErr) {\n console.error('Error in error page `getInitialProps`: ', gipErr);\n routeInfo.error = err;\n routeInfo.props = {};\n resolve(routeInfo);\n });\n });\n }));\n });\n });\n }\n }, {\n key: \"set\",\n value: function set(route, pathname, query, as, data) {\n this.route = route;\n this.pathname = pathname;\n this.query = query;\n this.asPath = as;\n this.notify(data);\n }\n /**\n * Callback to execute before replacing router state\n * @param cb callback to be executed\n */\n\n }, {\n key: \"beforePopState\",\n value: function beforePopState(cb) {\n this._bps = cb;\n }\n }, {\n key: \"onlyAHashChange\",\n value: function onlyAHashChange(as) {\n if (!this.asPath) return false;\n\n var _this$asPath$split = this.asPath.split('#'),\n _this$asPath$split2 = _slicedToArray(_this$asPath$split, 2),\n oldUrlNoHash = _this$asPath$split2[0],\n oldHash = _this$asPath$split2[1];\n\n var _as$split = as.split('#'),\n _as$split2 = _slicedToArray(_as$split, 2),\n newUrlNoHash = _as$split2[0],\n newHash = _as$split2[1]; // Makes sure we scroll to the provided hash if the url/hash are the same\n\n\n if (newHash && oldUrlNoHash === newUrlNoHash && oldHash === newHash) {\n return true;\n } // If the urls are change, there's more than a hash change\n\n\n if (oldUrlNoHash !== newUrlNoHash) {\n return false;\n } // If the hash has changed, then it's a hash only change.\n // This check is necessary to handle both the enter and\n // leave hash === '' cases. The identity case falls through\n // and is treated as a next reload.\n\n\n return oldHash !== newHash;\n }\n }, {\n key: \"scrollToHash\",\n value: function scrollToHash(as) {\n var _as$split3 = as.split('#'),\n _as$split4 = _slicedToArray(_as$split3, 2),\n hash = _as$split4[1]; // Scroll to top if the hash is just `#` with no value\n\n\n if (hash === '') {\n window.scrollTo(0, 0);\n return;\n } // First we check if the element by id is found\n\n\n var idEl = document.getElementById(hash);\n\n if (idEl) {\n idEl.scrollIntoView();\n return;\n } // If there's no element with the id, we check the `name` property\n // To mirror browsers\n\n\n var nameEl = document.getElementsByName(hash)[0];\n\n if (nameEl) {\n nameEl.scrollIntoView();\n }\n }\n }, {\n key: \"urlIsNew\",\n value: function urlIsNew(asPath) {\n return this.asPath !== asPath;\n }\n /**\n * Prefetch `page` code, you may wait for the data during `page` rendering.\n * This feature only works in production!\n * @param url of prefetched `page`\n */\n\n }, {\n key: \"prefetch\",\n value: function prefetch(url) {\n var _this4 = this;\n\n return new _Promise(function (resolve, reject) {\n var _url_1$parse3 = url_1.parse(url),\n pathname = _url_1$parse3.pathname,\n protocol = _url_1$parse3.protocol;\n\n if (!pathname || protocol) {\n if (true) {\n throw new Error(\"Invalid href passed to router: \".concat(url, \" https://err.sh/zeit/next.js/invalid-href-passed\"));\n }\n\n return;\n } // Prefetch is not supported in development mode because it would trigger on-demand-entries\n\n\n if (true) {\n return;\n } // @ts-ignore pathname is always defined\n\n\n var route = toRoute(pathname);\n\n _this4.pageLoader.prefetch(route).then(resolve, reject);\n });\n }\n }, {\n key: \"fetchComponent\",\n value: function fetchComponent(route) {\n var cancelled, cancel, Component, error;\n return _regeneratorRuntime.async(function fetchComponent$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n cancelled = false;\n\n cancel = this.clc = function () {\n cancelled = true;\n };\n\n _context.next = 4;\n return _regeneratorRuntime.awrap(this.pageLoader.loadPage(route));\n\n case 4:\n Component = _context.sent;\n\n if (!cancelled) {\n _context.next = 9;\n break;\n }\n\n error = new Error(\"Abort fetching component for route: \\\"\".concat(route, \"\\\"\"));\n error.cancelled = true;\n throw error;\n\n case 9:\n if (cancel === this.clc) {\n this.clc = null;\n }\n\n return _context.abrupt(\"return\", Component);\n\n case 11:\n case \"end\":\n return _context.stop();\n }\n }\n }, null, this);\n }\n }, {\n key: \"_getData\",\n value: function _getData(fn) {\n var _this5 = this;\n\n var cancelled = false;\n\n var cancel = function cancel() {\n cancelled = true;\n };\n\n this.clc = cancel;\n return fn().then(function (data) {\n if (cancel === _this5.clc) {\n _this5.clc = null;\n }\n\n if (cancelled) {\n var err = new Error('Loading initial props cancelled');\n err.cancelled = true;\n throw err;\n }\n\n return data;\n });\n }\n }, {\n key: \"getInitialProps\",\n value: function getInitialProps(Component, ctx) {\n var App = this.components['/_app'].Component;\n\n var AppTree = this._wrapApp(App);\n\n ctx.AppTree = AppTree;\n return utils_1.loadGetInitialProps(App, {\n AppTree: AppTree,\n Component: Component,\n router: this,\n ctx: ctx\n });\n }\n }, {\n key: \"abortComponentLoad\",\n value: function abortComponentLoad(as) {\n if (this.clc) {\n var e = new Error('Route Cancelled');\n e.cancelled = true;\n Router.events.emit('routeChangeError', e, as);\n this.clc();\n this.clc = null;\n }\n }\n }, {\n key: \"notify\",\n value: function notify(data) {\n this.sub(data, this.components['/_app'].Component);\n }\n }], [{\n key: \"_rewriteUrlForNextExport\",\n value: function _rewriteUrlForNextExport(url) {\n if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n var rewriteUrlForNextExport = require('./rewrite-url-for-export').rewriteUrlForNextExport;\n\n return rewriteUrlForNextExport(url);\n } else {\n return url;\n }\n }\n }]);\n\n return Router;\n}();\n\nexports[\"default\"] = Router;\nRouter.events = mitt_1[\"default\"]();","map":{"version":3,"sources":["/Users/sbourgal/Documents/Projets/DAN/dan-framework/template/node_modules/next/dist/next-server/lib/router/router.js"],"names":["__importDefault","mod","__esModule","exports","value","url_1","require","mitt_1","utils_1","is_dynamic_1","route_matcher_1","route_regex_1","addBasePath","path","p","process","env","__NEXT_ROUTER_BASEPATH","indexOf","toRoute","replace","Router","pathname","query","as","initialProps","pageLoader","App","wrapApp","Component","err","subscription","sdc","onPopState","e","state","changeState","formatWithValidation","getURL","isSsr","url","asPath","_bps","options","console","warn","_getStaticData","_cachedData","parse","resolve","fetch","__NEXT_DATA__","buildId","then","res","ok","Error","json","data","code","route","components","props","events","isDynamicRoute","autoExport","sub","clc","_wrapApp","window","addEventListener","newData","notify","location","reload","history","back","change","method","_url","_as","reject","_h","ST","performance","mark","__NEXT_EXPORT_TRAILING_SLASH","rewriteUrlForNextExport","nextExport","abortComponentLoad","onlyAHashChange","emit","scrollToHash","protocol","urlIsNew","shallow","asPathname","routeMatch","getRouteMatcher","getRouteRegex","error","getRouteInfo","routeInfo","cancelled","hash","substring","appComp","next","isPrerendered","getInitialProps","origGetInitialProps","set","cachedRouteInfo","fetchComponent","isValidElementType","_getData","__N_SSG","href","gipErr","cb","split","oldUrlNoHash","oldHash","newUrlNoHash","newHash","scrollTo","idEl","document","getElementById","scrollIntoView","nameEl","getElementsByName","prefetch","cancel","loadPage","fn","ctx","AppTree","loadGetInitialProps","router"],"mappings":"AAAA;;;;;;;;;;;;;;;;AACA,IAAIA,eAAe,GAAI,QAAQ,KAAKA,eAAd,IAAkC,UAAUC,GAAV,EAAe;AACnE,SAAQA,GAAG,IAAIA,GAAG,CAACC,UAAZ,GAA0BD,GAA1B,GAAgC;AAAE,eAAWA;AAAb,GAAvC;AACH,CAFD;;AAGA,uBAAsBE,OAAtB,EAA+B,YAA/B,EAA6C;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAA7C;;AACA,IAAMC,KAAK,GAAGC,OAAO,CAAC,KAAD,CAArB;;AACA,IAAMC,MAAM,GAAGP,eAAe,CAACM,OAAO,CAAC,SAAD,CAAR,CAA9B;;AACA,IAAME,OAAO,GAAGF,OAAO,CAAC,UAAD,CAAvB;;AACA,IAAMG,YAAY,GAAGH,OAAO,CAAC,oBAAD,CAA5B;;AACA,IAAMI,eAAe,GAAGJ,OAAO,CAAC,uBAAD,CAA/B;;AACA,IAAMK,aAAa,GAAGL,OAAO,CAAC,qBAAD,CAA7B;;AACA,SAASM,WAAT,CAAqBC,IAArB,EAA2B;AACvB;AACA,MAAMC,CAAC,GAAGC,OAAO,CAACC,GAAR,CAAYC,sBAAtB;AACA,SA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AACA,aAAOjI,OAAO,CAACkI,mBAAR,CAA4B/G,GAA5B,EAAiC;AACpC8G,QAAAA,OAAO,EAAPA,OADoC;AAEpC5G,QAAAA,SAAS,EAATA,SAFoC;AAGpC8G,QAAAA,MAAM,EAAE,IAH4B;AAIpCH,QAAAA,GAAG,EAAHA;AAJoC,OAAjC,CAAP;AAMH;;;uCACkBhH,E,EAAI;AACnB,UAAI,KAAK2C,GAAT,EAAc;AACV,YAAMjC,CAAC,GAAG,IAAIsB,KAAJ,CAAU,iBAAV,CAAV;AACAtB,QAAAA,CAAC,CAACqE,SAAF,GAAc,IAAd;AACAlF,QAAAA,MAAM,CAAC0C,MAAP,CAAc4B,IAAd,CAAmB,kBAAnB,EAAuCzD,CAAvC,EAA0CV,EAA1C;AACA,aAAK2C,GAAL;AACA,aAAKA,GAAL,GAAW,IAAX;AACH;AACJ;;;2BACMT,I,EAAM;AACT,WAAKQ,GAAL,CAASR,IAAT,EAAe,KAAKG,UAAL,CAAgB,OAAhB,EAAyBhC,SAAxC;AACH;;;6CAlY+BW,G,EAAK;AACjC,UAAIzB,OAAO,CAACC,GAAR,CAAYsE,4BAAhB,EAA8C;AAC1C,YAAMC,uBAAuB,GAAGjF,OAAO,CAAC,0BAAD,CAAP,CAC3BiF,uBADL;;AAEA,eAAOA,uBAAuB,CAAC/C,GAAD,CAA9B;AACH,OAJD,MAKK;AACD,eAAOA,GAAP;AACH;AACJ;;;;;;AA2XLrC,OAAO,WAAP,GAAkBkB,MAAlB;AACAA,MAAM,CAAC0C,MAAP,GAAgBxD,MAAM,WAAN,EAAhB","sourcesContent":["\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst url_1 = require(\"url\");\nconst mitt_1 = __importDefault(require(\"../mitt\"));\nconst utils_1 = require(\"../utils\");\nconst is_dynamic_1 = require(\"./utils/is-dynamic\");\nconst route_matcher_1 = require(\"./utils/route-matcher\");\nconst route_regex_1 = require(\"./utils/route-regex\");\nfunction addBasePath(path) {\n // @ts-ignore variable is always a string\n const p = process.env.__NEXT_ROUTER_BASEPATH;\n return path.indexOf(p) !== 0 ? p + path : path;\n}\nfunction toRoute(path) {\n return path.replace(/\\/$/, '') || '/';\n}\nclass Router {\n constructor(pathname, query, as, { initialProps, pageLoader, App, wrapApp, Component, err, subscription, }) {\n // Static Data Cache\n this.sdc = {};\n this.onPopState = (e) => {\n if (!e.state) {\n // We get state as undefined for two reasons.\n // 1. With older safari (< 8) and older chrome (< 34)\n // 2. When the URL changed with #\n //\n // In the both cases, we don't need to proceed and change the route.\n // (as it's already changed)\n // But we can simply replace the state with the new changes.\n // Actually, for (1) we don't need to nothing. But it's hard to detect that event.\n // So, doing the following for (1) does no harm.\n const { pathname, query } = this;\n this.changeState('replaceState', utils_1.formatWithValidation({ pathname, query }), utils_1.getURL());\n return;\n }\n // Make sure we don't re-render on initial load,\n // can be caused by navigating back from an external site\n if (e.state &&\n this.isSsr &&\n e.state.url === this.pathname &&\n e.state.as === this.asPath) {\n return;\n }\n // If the downstream application returns falsy, return.\n // They will then be responsible for handling the event.\n if (this._bps && !this._bps(e.state)) {\n return;\n }\n const { url, as, options } = e.state;\n if (process.env.NODE_ENV !== 'production') {\n if (typeof url === 'undefined' || typeof as === 'undefined') {\n console.warn('`popstate` event triggered but `event.state` did not have `url` or `as` https://err.sh/zeit/next.js/popstate-state-empty');\n }\n }\n this.replace(url, as, options);\n };\n this._getStaticData = (asPath, _cachedData) => {\n let pathname = url_1.parse(asPath).pathname;\n pathname = !pathname || pathname === '/' ? '/index' : pathname;\n return process.env.NODE_ENV === 'production' &&\n (_cachedData = this.sdc[pathname])\n ? Promise.resolve(_cachedData)\n : fetch(\n // @ts-ignore __NEXT_DATA__\n `/_next/data/${__NEXT_DATA__.buildId}${pathname}.json`)\n .then(res => {\n if (!res.ok) {\n throw new Error(`Failed to load static props`);\n }\n return res.json();\n })\n .then(data => {\n this.sdc[pathname] = data;\n return data;\n })\n .catch((err) => {\n ;\n err.code = 'PAGE_LOAD_ERROR';\n throw err;\n });\n };\n // represents the current component key\n this.route = toRoute(pathname);\n // set up the component cache (by route keys)\n this.components = {};\n // We should not keep the cache, if there's an error\n // Otherwise, this cause issues when when going back and\n // come again to the errored page.\n if (pathname !== '/_error') {\n this.components[this.route] = { Component, props: initialProps, err };\n }\n this.components['/_app'] = { Component: App };\n // Backwards compat for Router.router.events\n // TODO: Should be remove the following major version as it was never documented\n // @ts-ignore backwards compatibility\n this.events = Router.events;\n this.pageLoader = pageLoader;\n this.pathname = pathname;\n this.query = query;\n // if auto prerendered and dynamic route wait to update asPath\n // until after mount to prevent hydration mismatch\n this.asPath =\n // @ts-ignore this is temporarily global (attached to window)\n is_dynamic_1.isDynamicRoute(pathname) && __NEXT_DATA__.autoExport ? pathname : as;\n this.sub = subscription;\n this.clc = null;\n this._wrapApp = wrapApp;\n // make sure to ignore extra popState in safari on navigating\n // back from external site\n this.isSsr = true;\n if (typeof window !== 'undefined') {\n // in order for `e.state` to work on the `onpopstate` event\n // we have to register the initial route upon initialization\n this.changeState('replaceState', utils_1.formatWithValidation({ pathname, query }), as);\n window.addEventListener('popstate', this.onPopState);\n }\n }\n // @deprecated backwards compatibility even though it's a private method.\n static _rewriteUrlForNextExport(url) {\n if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n const rewriteUrlForNextExport = require('./rewrite-url-for-export')\n .rewriteUrlForNextExport;\n return rewriteUrlForNextExport(url);\n }\n else {\n return url;\n }\n }\n update(route, mod) {\n const Component = mod.default || mod;\n const data = this.components[route];\n if (!data) {\n throw new Error(`Cannot update unavailable route: ${route}`);\n }\n const newData = Object.assign(Object.assign({}, data), { Component });\n this.components[route] = newData;\n // pages/_app.js updated\n if (route === '/_app') {\n this.notify(this.components[this.route]);\n return;\n }\n if (route === this.route) {\n this.notify(newData);\n }\n }\n reload() {\n window.location.reload();\n }\n /**\n * Go back in history\n */\n back() {\n window.history.back();\n }\n /**\n * Performs a `pushState` with arguments\n * @param url of the route\n * @param as masks `url` for the browser\n * @param options object you can define `shallow` and other options\n */\n push(url, as = url, options = {}) {\n return this.change('pushState', url, as, options);\n }\n /**\n * Performs a `replaceState` with arguments\n * @param url of the route\n * @param as masks `url` for the browser\n * @param options object you can define `shallow` and other options\n */\n replace(url, as = url, options = {}) {\n return this.change('replaceState', url, as, options);\n }\n change(method, _url, _as, options) {\n return new Promise((resolve, reject) => {\n if (!options._h) {\n this.isSsr = false;\n }\n // marking route changes as a navigation start entry\n if (utils_1.ST) {\n performance.mark('routeChange');\n }\n // If url and as provided as an object representation,\n // we'll format them into the string version here.\n const url = typeof _url === 'object' ? utils_1.formatWithValidation(_url) : _url;\n let as = typeof _as === 'object' ? utils_1.formatWithValidation(_as) : _as;\n // Add the ending slash to the paths. So, we can serve the\n // \"<page>/index.html\" directly for the SSR page.\n if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {\n const rewriteUrlForNextExport = require('./rewrite-url-for-export')\n .rewriteUrlForNextExport;\n // @ts-ignore this is temporarily global (attached to window)\n if (__NEXT_DATA__.nextExport) {\n as = rewriteUrlForNextExport(as);\n }\n }\n this.abortComponentLoad(as);\n //