UNPKG

react-junctions

Version:

Junction-based routing for React.

2 lines (1 loc) 39.8 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom"],e):e(t.ReactJunctions={},t.React,t.ReactDOM)}(this,function(exports,React,ReactDOM){"use strict";var __DEV__=!1,warning=function(){};__DEV__&&(warning=function(t,e,n){var o=arguments.length;n=Array(o>2?o-2:0);for(var r=2;o>r;r++)n[r-2]=arguments[r];if(void 0===e)throw Error("`warning(condition, format, ...args)` requires a warning message argument");if(10>e.length||/^[s\W]*$/.test(e))throw Error("The warning format should be able to uniquely identify this warning. Please, use a more descriptive format than: "+e);if(!t){var i=0,a="Warning: "+e.replace(/%s/g,function(){return n[i++]});void 0!==console&&console.error(a);try{throw Error(a)}catch(t){}}});var warning_1=warning,NODE_ENV="production",invariant=function(t,e,n,o,r,i,a,s){if("production"!==NODE_ENV&&void 0===e)throw Error("invariant requires an error message argument");if(!t){var c;if(void 0===e)c=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,o,r,i,a,s],h=0;(c=Error(e.replace(/%s/g,function(){return u[h++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}},invariant_1=invariant;function isAbsolute(t){return"/"===t.charAt(0)}function spliceOne(t,e){for(var n=e,o=n+1,r=t.length;r>o;n+=1,o+=1)t[n]=t[o];t.pop()}function resolvePathname(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=t&&t.split("/")||[],o=e&&e.split("/")||[],r=t&&isAbsolute(t),i=e&&isAbsolute(e),a=r||i;if(t&&isAbsolute(t)?o=n:n.length&&(o.pop(),o=o.concat(n)),!o.length)return"/";var s=void 0;if(o.length){var c=o[o.length-1];s="."===c||".."===c||""===c}else s=!1;for(var u=0,h=o.length;h>=0;h--){var l=o[h];"."===l?spliceOne(o,h):".."===l?(spliceOne(o,h),u++):u&&(spliceOne(o,h),u--)}if(!a)for(;u--;u)o.unshift("..");!a||""===o[0]||o[0]&&isAbsolute(o[0])||o.unshift("");var p=o.join("/");return s&&"/"!==p.substr(-1)&&(p+="/"),p}var addLeadingSlash=function(t){return"/"===t.charAt(0)?t:"/"+t},hasBasename=function(t,e){return RegExp("^"+e+"(\\/|\\?|#|$)","i").test(t)},stripBasename=function(t,e){return hasBasename(t,e)?t.substr(e.length):t},stripTrailingSlash=function(t){return"/"===t.charAt(t.length-1)?t.slice(0,-1):t},parsePath=function(t){var e=t||"/",n="",o="",r=e.indexOf("#");-1!==r&&(o=e.substr(r),e=e.substr(0,r));var i=e.indexOf("?");return-1!==i&&(n=e.substr(i),e=e.substr(0,i)),{pathname:e,search:"?"===n?"":n,hash:"#"===o?"":o}},createPath=function(t){var e=t.search,n=t.hash,o=t.pathname||"/";return e&&"?"!==e&&(o+="?"===e.charAt(0)?e:"?"+e),n&&"#"!==n&&(o+="#"===n.charAt(0)?n:"#"+n),o},_extends$1=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},createLocation=function(t,e,n,o){var r=void 0;"string"==typeof t?(r=parsePath(t)).state=e:(void 0===(r=_extends$1({},t)).pathname&&(r.pathname=""),r.search?"?"!==r.search.charAt(0)&&(r.search="?"+r.search):r.search="",r.hash?"#"!==r.hash.charAt(0)&&(r.hash="#"+r.hash):r.hash="",void 0!==e&&void 0===r.state&&(r.state=e));try{r.pathname=decodeURI(r.pathname)}catch(t){throw t instanceof URIError?new URIError('Pathname "'+r.pathname+'" could not be decoded. This is likely caused by an invalid percent-encoding.'):t}return n&&(r.key=n),o?r.pathname?"/"!==r.pathname.charAt(0)&&(r.pathname=resolvePathname(r.pathname,o.pathname)):r.pathname=o.pathname:r.pathname||(r.pathname="/"),r},createTransitionManager=function(){var t=null,e=[];return{setPrompt:function(e){return warning_1(null==t,"A history supports only one prompt at a time"),t=e,function(){t===e&&(t=null)}},confirmTransitionTo:function(e,n,o,r){if(null!=t){var i="function"==typeof t?t(e,n):t;"string"==typeof i?"function"==typeof o?o(i,r):(warning_1(!1,"A history needs a getUserConfirmation function in order to use a prompt message"),r(!0)):r(!1!==i)}else r(!0)},appendListener:function(t){var n=!0,o=function(){n&&t.apply(void 0,arguments)};return e.push(o),function(){n=!1,e=e.filter(function(t){return t!==o})}},notifyListeners:function(){for(var t=arguments.length,n=Array(t),o=0;t>o;o++)n[o]=arguments[o];e.forEach(function(t){return t.apply(void 0,n)})}}},canUseDOM=!("undefined"==typeof window||!window.document||!window.document.createElement),addEventListener=function(t,e,n){return t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent("on"+e,n)},removeEventListener=function(t,e,n){return t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent("on"+e,n)},getConfirmation=function(t,e){return e(window.confirm(t))},supportsHistory=function(){var t=window.navigator.userAgent;return(-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&(window.history&&"pushState"in window.history)},supportsPopStateOnHashChange=function(){return-1===window.navigator.userAgent.indexOf("Trident")},isExtraneousPopstateEvent=function(t){return void 0===t.state&&-1===navigator.userAgent.indexOf("CriOS")},_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_extends=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},PopStateEvent="popstate",HashChangeEvent="hashchange",getHistoryState=function(){try{return window.history.state||{}}catch(t){return{}}},createBrowserHistory=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};invariant_1(canUseDOM,"Browser history needs a DOM");var e=window.history,n=supportsHistory(),o=!supportsPopStateOnHashChange(),r=t.forceRefresh,i=void 0!==r&&r,a=t.getUserConfirmation,s=void 0===a?getConfirmation:a,c=t.keyLength,u=void 0===c?6:c,h=t.basename?stripTrailingSlash(addLeadingSlash(t.basename)):"",l=function(t){var e=t||{},n=e.key,o=e.state,r=window.location,i=r.pathname+r.search+r.hash;return warning_1(!h||hasBasename(i,h),'You are attempting to use a basename on a page whose URL path does not begin with the basename. Expected path "'+i+'" to begin with "'+h+'".'),h&&(i=stripBasename(i,h)),createLocation(i,o,n)},p=function(){return Math.random().toString(36).substr(2,u)},f=createTransitionManager(),d=function(t){_extends(L,t),L.length=e.length,f.notifyListeners(L.location,L.action)},v=function(t){isExtraneousPopstateEvent(t)||y(l(t.state))},m=function(){y(l(getHistoryState()))},g=!1,y=function(t){if(g)g=!1,d();else{f.confirmTransitionTo(t,"POP",s,function(e){e?d({action:"POP",location:t}):b(t)})}},b=function(t){var e=_.indexOf(L.location.key);-1===e&&(e=0);var n=_.indexOf(t.key);-1===n&&(n=0);var o=e-n;o&&(g=!0,O(o))},w=l(getHistoryState()),_=[w.key],P=function(t){return h+createPath(t)},O=function(t){e.go(t)},C=0,R=function(t){1===(C+=t)?(addEventListener(window,PopStateEvent,v),o&&addEventListener(window,HashChangeEvent,m)):0===C&&(removeEventListener(window,PopStateEvent,v),o&&removeEventListener(window,HashChangeEvent,m))},T=!1,L={length:e.length,action:"POP",location:w,createHref:P,push:function(t,o){warning_1(!("object"===(void 0===t?"undefined":_typeof(t))&&void 0!==t.state&&void 0!==o),"You should avoid providing a 2nd state argument to push when the 1st argument is a location-like object that already has state; it is ignored");var r=createLocation(t,o,p(),L.location);f.confirmTransitionTo(r,"PUSH",s,function(t){if(t){var o=P(r),a=r.state;if(n)if(e.pushState({key:r.key,state:a},null,o),i)window.location.href=o;else{var s=_.indexOf(L.location.key),c=_.slice(0,-1===s?0:s+1);c.push(r.key),_=c,d({action:"PUSH",location:r})}else warning_1(void 0===a,"Browser history cannot push state in browsers that do not support HTML5 history"),window.location.href=o}})},replace:function(t,o){warning_1(!("object"===(void 0===t?"undefined":_typeof(t))&&void 0!==t.state&&void 0!==o),"You should avoid providing a 2nd state argument to replace when the 1st argument is a location-like object that already has state; it is ignored");var r="REPLACE",a=createLocation(t,o,p(),L.location);f.confirmTransitionTo(a,r,s,function(t){if(t){var o=P(a),s=a.state;if(n)if(e.replaceState({key:a.key,state:s},null,o),i)window.location.replace(o);else{var c=_.indexOf(L.location.key);-1!==c&&(_[c]=a.key),d({action:r,location:a})}else warning_1(void 0===s,"Browser history cannot replace state in browsers that do not support HTML5 history"),window.location.replace(o)}})},go:O,goBack:function(){return O(-1)},goForward:function(){return O(1)},block:function(){var t=f.setPrompt(arguments.length>0&&void 0!==arguments[0]&&arguments[0]);return T||(R(1),T=!0),function(){return T&&(T=!1,R(-1)),t()}},listen:function(t){var e=f.appendListener(t);return R(1),function(){R(-1),e()}}};return L},__assign=Object.assign||function(t){for(var e,n=1,o=arguments.length;o>n;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t};function concatLocations(t){for(var e=[],n=1;arguments.length>n;n++)e[n-1]=arguments[n];for(var o="string"==typeof t?{pathname:t}:t,r=0;e.length>r;r++){var i=e[r];"string"==typeof i&&(i=parseLocationString(i)),o=__assign({},o,{pathname:joinPaths(o.pathname,i.pathname),search:joinQueryStrings(o.search,i.search,"?"),hash:joinQueryStrings(o.hash,i.hash,"#"),state:o.state||i.state?Object.assign({},o.state,i.state):void 0})}return o}var parsePattern=/^((((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/;function parseLocationString(t){var e=parsePattern.exec(t);if(!e)throw Error("Tried to parse a non-URI object.");return{pathname:e[2],search:e[6],hash:e[7]}}function joinPaths(t,e){return e?("/"===t[t.length-1]&&(t=t.substr(0,t.length-1)),"/"===e[0]&&(e=e.substr(1)),t+"/"+e):t}function joinQueryStrings(t,e,n){return void 0===n&&(n="?"),t&&t[0]===n?e&&e[0]===n?n+t.slice(1)+"&"+e.slice(1):t:e}function createHref(t){return t.pathname+(t.search||"")+(t.hash||"")}function parseQuery(t,e){if(void 0===e&&(e="?"),!t||t[0]!=e)return{};for(var n={},o=t.slice(1).split("&"),r=0,i=o.length;i>r;r++){var a=o[r].split("=");n[a[0]]=a[1]?decodeURIComponent(a[1]):""}return n}function stringifyQuery(t,e){void 0===e&&(e="?");var n=Object.keys(t);if(0===n.length)return"";for(var o=[],r=0,i=n.length;i>r;r++){var a=n[r],s=t[a]+"";o.push(""===s?a:a+"="+encodeURIComponent(s))}return e+o.join("&")}var __assign$1=Object.assign||function(t){for(var e,n=1,o=arguments.length;o>n;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},KEY_WILDCARD="\0";function createRootMountedPattern(t,e){var n=e?compilePattern(e,t):{relativePattern:e||"",relativeKey:"",relativeRegExp:/(?:)/,template:t};if(n.relativePathParams&&n.relativePathParams.length>0)throw Error("Your root path may not contain parameters");return __assign$1({},n,{params:[]})}function compilePattern(t,e){var n=t;if(n.length>1&&"/"===n.substr(-1)&&(n=n.substr(0,n.length-1)),"/"!==n[0]&&(n="/"+n),/\/{2,}/.test(n)&&(n=n.replace(/\/{2,}/g,"/")),0===n.length)throw Error('You cannot use an empty string "" as a Junction pattern!');for(var o=n.split("/").slice(1),r=[],i=[],a=["^"],s=0;o.length>s;s++){var c=o[s];c.length>1&&":"===c[0]?(r.push(c.slice(1)),i.push(KEY_WILDCARD),a.push("([^/]+)")):(i.push(c),a.push(escapeRegExp(c)))}return{relativePattern:n,relativeKey:i.join("/"),relativePathParams:r.length?r:void 0,relativeRegExp:RegExp(a.join("/")),template:e}}function createChildMountedPattern(t,e){return __assign$1({params:t.params.concat(e.relativePathParams||[])},e)}function addParamsToMountedPattern(t,e){var n=e||[];if(t.relativePathParams)for(var o=t.relativePathParams.length-1;o>=0;o--){var r=n.indexOf(t.relativePathParams[o]);-1===r||n.splice(r,1)}return 0===n.length?t:__assign$1({},t,{relativeSearchParams:n.length?n:void 0})}function matchMountedPatternAgainstLocation(t,e){var n=t.relativeRegExp.exec(e.pathname),o={};if(n){if(t.relativePathParams)for(var r=0;t.relativePathParams.length>r;r++){o[s=t.relativePathParams[r]]=n[r+1]}var i={},a=parseQuery(e.search);if(t.relativeSearchParams)for(r=0;t.relativeSearchParams.length>r;r++){var s;void 0!==a[s=t.relativeSearchParams[r]]&&(o[s]=a[s],i[s]=a[s],delete a[s])}var c={pathname:n[0],search:stringifyQuery(i)},u={pathname:e.pathname.slice(n[0].length),search:stringifyQuery(a),hash:e.hash,state:e.state};return{params:o,matchedLocation:c,remainingLocation:""!==u.pathname||""!==u.search?u:void 0}}}function escapeRegExp(t){return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}var Router=function(){function t(t){var e=this;this.listeners=[],this.notifyListeners=function(){for(var t=0;e.listeners.length>t;t++)e.listeners[t]()},this.listeners=[],this.config=t}return t.prototype.getRoute=function(){return this.rootMatcher&&this.rootMatcher.getRoute()},t.prototype.subscribe=function(t){var e=this;return this.listeners.push(t),function(){var n=e.listeners.indexOf(t);-1!==n&&e.listeners.splice(n,1)}},t.prototype.isBusy=function(){return!!this.rootMatcher&&this.rootMatcher.isBusy()},t.prototype.setLocation=function(t){var e,n;if(t&&this.location&&(e=t.pathname!==this.location.pathname,n=t.search!==this.location.search),e||n||(t&&!this.location||!t&&this.location)){this.location=t;var o=t&&matchMountedPatternAgainstLocation(this.config.rootMountedPattern,t);if(!o&&this.rootMatcher)return this.rootMatcher.willUnmount(),this.rootMatcher=void 0,void this.notifyListeners();t&&o&&(this.rootMatcher&&this.rootMatcher.willUnmount(),this.rootMatcher=new this.config.rootJunctionTemplate({routerConfig:this.config,parentLocationPart:{pathname:""},matchableLocationPart:t,mountedPattern:this.config.rootMountedPattern,onChange:this.notifyListeners,shouldFetchContent:!0}),this.notifyListeners())}else this.notifyListeners()},t}();function createRouterConfig(t){return{rootJunctionTemplate:t.rootJunctionTemplate,rootMountedPattern:createRootMountedPattern(t.rootJunctionTemplate,t.rootPath),onEvent:t.onEvent||function(){}}}var Deferred=function(){return function(){this.promise=new Promise(function(t,e){this.resolve=t,this.reject=e}.bind(this)),Object.freeze(this)}}(),__awaiter=function(t,e,n,o){return new(n||(n=Promise))(function(r,i){function a(t){try{c(o.next(t))}catch(t){i(t)}}function s(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(a,s)}c((o=o.apply(t,e||[])).next())})},__generator=function(t,e){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=o[2&i[0]?"return":i[0]?"throw":"next"])&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[0,r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,o=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(r=(r=a.trys).length>0&&r[r.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&r[3]>i[1])){a.label=i[1];break}if(6===i[0]&&r[1]>a.label){a.label=r[1],r=i;break}if(r&&r[2]>a.label){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},defaultPredicate=function(t){return!0};function createContentHelpers(t){function e(t){var e=new Deferred;return o({pathname:"/"===t.substr(-1)?t:t+"/"},function(n){if(n){var o=n[n.length-1];if(o.location.pathname===t)e.resolve(o);else if(o.location.pathname===t+"/"){var r=n[n.length-2];r&&e.resolve(r)}}e.reject(void 0)}),e.promise}function n(t){var e=new Deferred;return o(t,function(t){var o=t&&t[t.length-1];if(o&&"junction"!==o.type){if("page"===o.type)return e.resolve(o);n(o.to).then(e.resolve)}else e.resolve(void 0)}),e.promise}function o(e,n){if(matchMountedPatternAgainstLocation(t.rootMountedPattern,e)){new Deferred;var o=function(){r.isBusy()||(n(r.getRoute()),r.willUnmount())},r=new t.rootJunctionTemplate({parentLocationPart:{pathname:""},matchableLocationPart:e,mountedPattern:t.rootMountedPattern,onChange:o,routerConfig:t,shouldFetchContent:!1});o()}else n()}return{getPages:function(t){if("string"==typeof t)return n({pathname:t}).then(function(t){return t?Promise.resolve(t):Promise.reject(void 0)});for(var e=Object.keys(t),o=[],r=0;e.length>r;r++)o.push(n({pathname:t[e[r]]}));return Promise.all(o).then(function(t){for(var n={},o=0;e.length>o;o++){var r=t[o];if(void 0===r)return Promise.reject(void 0);n[e[o]]=r}return Promise.resolve(n)})},getRouteSegment:e,getPageMap:function(t,n){return void 0===n&&(n=defaultPredicate),__awaiter(this,void 0,void 0,function(){var o,r,i,a,s,c,u,h;return __generator(this,function(l){switch(l.label){case 0:o={},r=Object.entries(t.template.children),i=[t],l.label=1;case 1:if(!i.length)return[3,6];a=i.shift(),s=0,c=r,l.label=2;case 2:return c.length>s?[4,e(u=a.location.pathname+c[s][0])]:[3,5];case 3:"redirect"!==(h=l.sent()).type&&n(h)&&("junction"===h.type?i.push(a):o[u]=h),l.label=4;case 4:return s++,[3,2];case 5:return[3,1];case 6:return[2,o]}})})}}}var BrowserNavigation=function(){function t(t){var e=this;this.handleHistoryChange=function(t){e.location&&e.disableScrollHandling&&t.pathname===e.location.pathname&&t.hash===e.location.hash&&t.search===e.location.search?e.scrollToHash(t.hash):e.router.setLocation(t)},this.handleLocationChange=function(t,n){t!==n&&(e.disableScrollHandling||t&&t.hash===n.hash&&(n.hash||t.pathname===n.pathname)||(e.location=n,t&&e.scrollToHash(n.hash)))},this.handleRouteChange=function(){var t,n,o=e.router.isBusy(),r=e.router.getRoute(),i=r&&r[r.length-1];if(!o&&i&&("page"===i.type&&"/"!==e.history.location.pathname.substr(-1)&&(t=concatLocations(e.history.location,{pathname:"/"})),n=null,"redirect"===i.type?t=i.to:"page"===i.type?("busy"!==i.contentStatus&&(e.waitingForInitialContent=!1),n=i.title):"busy"!==i.status&&(e.waitingForInitialContent=!1)),e.followRedirects&&t)e.replaceLocation(t);else{void 0!==n&&(e.announceTitle&&announce(e.announceTitle(n)),e.setDocumentTitle&&(document.title=e.setDocumentTitle(n)));for(var a=0,s=function(){--a>0||o||e.handleLocationChange(e.location,e.history.location)},c=0,u=e.subscribers;u.length>c;c++){var h=u[c];o&&h.waitForInitialContent&&e.waitingForInitialContent||(h.callback.length>0?(a++,h.callback(s)):h.callback())}0===a&&s()}},!1!==t.announceTitle&&(this.announceTitle="function"==typeof t.announceTitle?t.announceTitle:function(t){return t||"Untitled Page"},createAnnouncerDiv()),!1!==t.setDocumentTitle&&(this.setDocumentTitle="function"==typeof t.setDocumentTitle?t.setDocumentTitle:function(t){return t||"Untitled Page"}),this.autoscroll=void 0===t.autoscroll||t.autoscroll,this.followRedirects=void 0===t.followRedirects||t.followRedirects,this.subscribers=[],this.waitingForInitialContent=!0,this.disableScrollHandling=!!t.disableScrollHandling,this.history=t.history||createBrowserHistory(),this.history.listen(this.handleHistoryChange);var n=createRouterConfig({rootJunctionTemplate:t.rootJunctionTemplate});this.router=new Router(n),this.router.subscribe(this.handleRouteChange),Object.assign(this,createContentHelpers(n)),this.router.setLocation(this.history.location)}return t.prototype.subscribe=function(t,e){var n=this;void 0===e&&(e={});var o={callback:t,waitForInitialContent:!!e.waitForInitialContent};return this.subscribers.push(o),function(){var t=n.subscribers.indexOf(o);-1!==t&&n.subscribers.splice(t,1)}},t.prototype.block=function(t){return this.history.block(t)},t.prototype.isBusy=function(){return this.router.isBusy()},t.prototype.getRoute=function(){return this.router.getRoute()},t.prototype.getLocation=function(){return this.history.location},t.prototype.replaceLocation=function(t,e){this.history.replace(t,e)},t.prototype.pushLocation=function(t,e){this.history.push(t,e)},t.prototype.scrollToHash=function(t){if(t){var e=document.getElementById(t.slice(1));e?(e.scrollIntoView({behavior:"instant",block:"start"}),e.focus()):console.log("no id")}else window.scroll({top:0,left:0,behavior:"instant"})},t}(),announcerId="junctions-BrowserNavigation-announcer",announcerTimeout,announcerDiv;function announce(t,e){var n=document.getElementById(announcerId);e=e||"polite",n&&(n.setAttribute("aria-live","off"),n.setAttribute("aria-live",e),n.innerHTML=t,clearTimeout(announcerTimeout),announcerTimeout=setTimeout(function(){n&&(n.innerHTML=""),announcerTimeout=null},500))}function createAnnouncerDiv(){if(announcerDiv)return announcerDiv;(announcerDiv=document.createElement("div")).id=announcerId,announcerDiv.setAttribute("aria-live","polite");var t=announcerDiv.style;t.position="absolute",t.left="-10000px",t.top="auto",t.width="1px",t.height="1px",t.overflow="hidden",document.body.appendChild(announcerDiv)}var __assign$2=Object.assign||function(t){for(var e,n=1,o=arguments.length;o>n;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},Matcher=function(){function t(t){var e=this;this.handleChange=function(){e.unmounted||e.onChange()};var n=t.parentLocationPart,o=t.matchableLocationPart;this.mountedPattern=addParamsToMountedPattern(t.mountedPattern,this.constructor.params),this.waitingForWatch=!1,this.unmounted=!1,this.onChange=t.onChange,this.routerConfig=t.routerConfig,this.shouldFetchContent=t.shouldFetchContent,this.match=matchMountedPatternAgainstLocation(this.mountedPattern,o),this.segmentLocation=concatLocations(n,this.match?this.match.matchedLocation:o),this.matchableLocationPart=o}return t.prototype.willUnmount=function(){this.unmounted=!0},t.prototype.isBusy=function(){return!!this.waitingForWatch},t.prototype.createSegment=function(t,e){return Object.assign({type:t,params:this.match&&this.match.params||{},location:this.segmentLocation,url:this.segmentLocation.pathname+(this.segmentLocation.search||""),template:this.constructor,component:void 0,meta:void 0},e)},t.prototype.watchAsync=function(t,e,n){var o=this;if(!t.status||"ready"!==t.status){var r=t.getter(this.routerConfig);r&&r.then?(t.promise=r,t.status="busy"):(t.value=r,t.status="ready")}"ready"===t.status&&n("ready",t.value),"busy"===t.status&&t.promise&&(n("busy"),this.waitingForWatch=!0,this.routerConfig.onEvent(__assign$2({},e,{type:e.type+"Start"})),t.promise.then(function(e){t.status="ready",t.value=e,n(t.status,t.value)},function(e){t.status="error",t.promise=void 0,t.error=e,console.error(e),n("error",void 0,e)}).then(function(){o.waitingForWatch=!1,o.routerConfig.onEvent(__assign$2({},e,{type:e.type+"End"})),o.handleChange()}))},t}(),__extends=(fh=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}fh(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),fh,JunctionMatcher=function(t){function e(e){var n=t.call(this,e)||this;if(n.match)for(var o=n.match.remainingLocation?n.match.remainingLocation:{pathname:"/"},r=n.constructor.compiledPatterns,i=function(t){var e=createChildMountedPattern(a.mountedPattern,r[t]),i=matchMountedPatternAgainstLocation(e,o);if(i){a.childMountedPattern=e;var s={parentLocationPart:a.segmentLocation,matchableLocationPart:o,mountedPattern:a.childMountedPattern,onChange:a.handleChange,routerConfig:a.routerConfig,shouldFetchContent:a.shouldFetchContent};return"Template"===e.template.type?(a.childMatcher=new e.template(s),a.childStatus="ready"):e.template.value?(a.childMatcher=new e.template.value(s),a.childStatus="ready"):a.watchAsync(e.template,{type:"junctionChild",location:concatLocations(a.segmentLocation,i.matchedLocation)},function(t,e,o){e&&(n.childMatcher=new e(s)),n.childStatus=t,n.childError=o}),"break"}},a=this,s=r.length-1;s>=0;s--){if("break"===i(s))break}return n}return __extends(e,t),e.prototype.willUnmount=function(){this.childMatcher&&this.childMatcher.willUnmount(),t.prototype.willUnmount.call(this)},e.prototype.isBusy=function(){return!!this.waitingForWatch||!(!this.childMatcher||!this.childMatcher.isBusy())},e.prototype.getRoute=function(){if(this.match){var t,e=[];if(this.childMountedPattern)if("ready"===this.childStatus){var n=this.childMatcher.getRoute();n?(e=n,t="ready"):t="notfound"}else t=this.childStatus;else t="notfound";var o=[this.createSegment("junction",{status:t,component:this.constructor.component,meta:this.constructor.meta,children:this.constructor.children,activePattern:this.childMountedPattern&&this.childMountedPattern.relativePattern,activeChild:e[0]||!1,activeRoute:e})];return o.push.apply(o,e),o}},e.type="Template",e.templateType="Junction",e}(Matcher);function createJunctionTemplate(t){var e="function"==typeof t?t({split:split}):t;if(!e)throw Error("createJunction() was supplied a function that doesn't return any value!");e.children||(e.children={});var n,o=Object.keys(e.children).map(function(t){return compilePattern(t,e.children[t])}).sort(function(t,e){return compareStrings(t.relativeKey,e.relativeKey)});return(n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(JunctionMatcher)).children=e.children,n.meta=e.meta,n.component=e.component,n.params=e.params||[],n.compiledPatterns=o,n}function split(t){return{type:"AsyncObjectContainer",status:void 0,getter:t,value:void 0}}function compareStrings(t,e){return e>t?-1:t>e?1:0}var __extends$1=(Wh=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}Wh(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),Wh,PageMatcher=function(t){function e(e){var n=t.call(this,e)||this;if(n.match){var o=n.match.remainingLocation;o&&"/"!==o.pathname?delete n.match:n.match&&n.shouldFetchContent&&n.watchAsync(n.constructor.contentContainer,{type:"content",location:n.segmentLocation},function(t,e,o){n.content=e,n.contentStatus=t,n.contentError=o})}return n}return __extends$1(e,t),e.prototype.getRoute=function(){if(this.match)return[this.createSegment("page",{title:this.constructor.title,meta:this.constructor.meta,component:this.constructor.component,content:this.content,contentStatus:this.contentStatus,contentError:this.contentError})]},e.type="Template",e.templateType="Page",e}(Matcher);function createPageTemplate(t){var e;if(t.getContent){var n=t.getContent;e=function(t){return n(createContentHelpers(t))}}else e=function(){};var o,r={type:"AsyncObjectContainer",status:void 0,getter:e,value:void 0};return(o=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(PageMatcher)).title=t.title,o.component=t.component,o.meta=t.meta,o.params=t.params||[],o.contentContainer=r,o}var __extends$2=(ti=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}ti(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),ti,RedirectMatcher=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends$2(e,t),e.prototype.getRoute=function(){if(this.match&&(!this.match.remainingLocation||"/"===this.match.remainingLocation.pathname)){var t="function"==typeof this.constructor.to?this.constructor.to(this.segmentLocation):this.constructor.to;return[this.createSegment("redirect",{to:t})]}},e.type="Template",e.templateType="Redirect",e}(Matcher);function createRedirectTemplate(t,e){var n,o="string"==typeof t?{pathname:t}:t;return(n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(RedirectMatcher)).to=o,n.component=void 0,n.params=[],n.meta=e,n}var StaticNavigation=function(){function t(t){var e=this;this.handleRouteChange=function(){e.router.isBusy()||e.finalRootRouteDeferred.resolve(e.router.getRoute())};var n=createRouterConfig({rootJunctionTemplate:t.rootJunctionTemplate});Object.assign(this,createContentHelpers(n)),this.location=t.location,this.finalRootRouteDeferred=new Deferred,this.router=new Router(n),this.router.subscribe(this.handleRouteChange),this.router.setLocation(t.location)}return t.prototype.getFinalRoute=function(){return this.finalRootRouteDeferred.promise},t.prototype.getLocation=function(){return this.location},t.prototype.block=function(t){throw Error("block() is not implemented in StaticNavigation.")},t.prototype.replaceLocation=function(t,e){throw Error("You can't change the location of a StaticNavigation instance.")},t.prototype.pushLocation=function(t,e){throw Error("You can't change the location of a StaticNavigation instance.")},t}(),defaultJunctionActiveChildRenderer=function(t){var e,n=t.child,o=t.env;return React.createElement(t.Component,((e={})[n.type]=n,e.env=o,e))};function JunctionActiveChild(t){var e=t.junction,n=t.render,o=t.notFoundElement,r=void 0===o?null:o,i=t.busyElement,a=void 0===i?null:i,s=t.errorElement,c=void 0===s?null:s,u=e.activeChild;return u&&"redirect"!==u.type?(void 0===n?defaultJunctionActiveChildRenderer:n)({Component:u.component,child:u,env:t.env}):"busy"===e.status?a:"notfound"===e.status?r:c}function createCommonjsModule(t,e){return t(e={exports:{}},e.exports),e.exports}function makeEmptyFunction(t){return function(){return t}}var emptyFunction=function(){};emptyFunction.thatReturns=makeEmptyFunction,emptyFunction.thatReturnsFalse=makeEmptyFunction(!1),emptyFunction.thatReturnsTrue=makeEmptyFunction(!0),emptyFunction.thatReturnsNull=makeEmptyFunction(null),emptyFunction.thatReturnsThis=function(){return this},emptyFunction.thatReturnsArgument=function(t){return t};var emptyFunction_1=emptyFunction;function invariant$2(t,e,n,o,r,i,a,s){if(!t){var c;if(void 0===e)c=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,o,r,i,a,s],h=0;(c=Error(e.replace(/%s/g,function(){return u[h++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}}var invariant_1$1=invariant$2,getOwnPropertySymbols=Object.getOwnPropertySymbols,hasOwnProperty=Object.prototype.hasOwnProperty,propIsEnumerable=Object.prototype.propertyIsEnumerable;function toObject(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function shouldUseNative(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;10>n;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach(function(t){o[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(t){return!1}}var objectAssign=shouldUseNative()?Object.assign:function(t,e){for(var n,o,r=toObject(t),i=1;arguments.length>i;i++){for(var a in n=Object(arguments[i]))hasOwnProperty.call(n,a)&&(r[a]=n[a]);if(getOwnPropertySymbols){o=getOwnPropertySymbols(n);for(var s=0;o.length>s;s++)propIsEnumerable.call(n,o[s])&&(r[o[s]]=n[o[s]])}}return r},ReactPropTypesSecret="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",ReactPropTypesSecret_1=ReactPropTypesSecret,factoryWithThrowingShims=function(){function t(t,e,n,o,r,i){i!==ReactPropTypesSecret_1&&invariant_1$1(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function e(){return t}t.isRequired=t;var n={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e};return n.checkPropTypes=emptyFunction_1,n.PropTypes=n,n},propTypes=createCommonjsModule(function(t){t.exports=factoryWithThrowingShims()}),__extends$3=($j=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}$j(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),$j,__assign$3=Object.assign||function(t){for(var e,n=1,o=arguments.length;o>n;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},__rest$2=function(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&0>e.indexOf(o)&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(t);o.length>r;r++)0>e.indexOf(o[r])&&(n[o[r]]=t[o[r]])}return n},Link=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.handleFollow=function(t){if(o.props.disabled)t.preventDefault();else{var e=o.getLocation();e&&(t.preventDefault(),o.navigation.pushLocation(e))}},o.navigation=o.props.env?o.props.env.navigation:n.navigation,o}return __extends$3(e,t),e.prototype.getLocation=function(){var t=this.props.href;if(t){if("string"!=typeof t)return t;if(-1===t.indexOf("://")&&0!==t.indexOf("mailto:")){var e=t.split("#"),n=e[1],o=e[0].split("?"),r=o[1],i={pathname:o[0]||""};return r&&(i.search="?"+r),n&&(i.hash="#"+n),i}}},e.prototype.render=function(){var t=this.props,n=t.env,o=t.exact,r=t.href,i=t.render,a=void 0===i?e.defaultProps.render:i,s=__rest$2(t,["env","exact","href","render"]),c=this.getLocation(),u=this.navigation.getLocation(),h=n&&c&&(o?c.pathname===u.pathname:0===u.pathname.indexOf(c.pathname));return a(__assign$3({active:!!h,href:c?createHref(c):r},s,{onFollow:this.handleFollow}))},e.defaultProps={render:function(t){return React.createElement(AnchorLink,__assign$3({},t))}},e.contextTypes={navigation:void 0},e}(React.Component),AnchorLink=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.handleClick=function(t){0!==t.button||t.altKey||t.ctrlKey||t.metaKey||t.shiftKey||e.props.target||e.props.onFollow(t)},e}return __extends$3(e,t),e.prototype.render=function(){var t=this.props,e=t.active,n=t.activeClassName,o=t.activeStyle,r=t.className,i=t.style,a=__rest$2(t,["active","activeClassName","activeStyle","className","disabled","style","onFollow"]);return React.createElement("a",__assign$3({},a,{className:(r||"")+" "+(e&&n||""),onClick:this.handleClick,style:Object.assign({},i,e?o:{})}))},e}(React.Component),__extends$5=(cl=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}cl(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),cl,NavigationProvider=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends$5(e,t),e.prototype.getChildContext=function(){return{navigation:this.props.navigation}},e.prototype.render=function(){return this.props.children},e.childContextTypes={navigation:void 0},e}(React.Component),__extends$4=(nl=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}nl(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),nl,renderToString;try{renderToString=eval("require")("react-dom/server").renderToString}catch(t){}var defaultRender=function(t,e,n){return React.createElement(t[0].component,{junction:t[0],env:{navigation:e,location:n}})},JunctionNavigation=function(t){function e(e){var n=t.call(this,e)||this;n.handleRenderComplete=function(){n.renderCompleteCallback&&(n.renderCompleteCallback(),delete n.renderCompleteCallback)},n.setContainer=function(t){n.containerNode=t},n.handleRouteChange=function(t){n.renderCompleteCallback=t,n.setState({route:n.navigation.getRoute(),waitingForInitialContent:!1})};var o=e.root,r=e.history,i=e.followRedirects,a=e.announceTitle,s=e.setDocumentTitle,c=e.waitForInitialContent,u=e.disableScrollHandling,h=e.addToContext;if(n.addToContext=void 0===h||h,n.navigation=new BrowserNavigation({rootJunctionTemplate:o,history:r,followRedirects:i,announceTitle:a,setDocumentTitle:s,disableScrollHandling:u}),n.navigation.subscribe(n.handleRouteChange,{waitForInitialContent:c}),c&&n.navigation.isBusy()){try{n.serverRenderedHTML=document.getElementById("JUNCTIONS_STATIC").innerHTML,n.shouldHydrate=!0}catch(t){n.serverRenderedHTML=""}n.state={waitingForInitialContent:!0}}else n.state={route:n.navigation.getRoute()};return n}return __extends$4(e,t),e.prototype.render=function(){var t=renderToString?renderToString(this.getElementToRender()):this.serverRenderedHTML;return React.createElement("div",{ref:this.setContainer,className:this.props.className,style:this.props.style,dangerouslySetInnerHTML:{__html:t}})},e.prototype.componentDidMount=function(){this.renderChildren()},e.prototype.componentDidUpdate=function(){this.renderChildren()},e.prototype.getElementToRender=function(){var t=(this.props.render||defaultRender)(this.state.route,this.navigation,this.navigation.getLocation());return this.addToContext?React.createElement(NavigationProvider,{navigation:this.navigation},t):t},e.prototype.renderChildren=function(){this.state.waitingForInitialContent||(this.shouldHydrate?ReactDOM.hydrate:ReactDOM.render)(this.getElementToRender(),this.containerNode,this.handleRenderComplete)},e}(React.Component),__extends$6=(Ul=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},function(t,e){function n(){this.constructor=t}Ul(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),Ul,ExitPrompt=function(t){function e(e,n){var o=t.call(this,e,n)||this;return o.navigation=o.props.env?o.props.env.navigation:n.navigation,o}return __extends$6(e,t),e.prototype.enable=function(t){this.unblock&&this.unblock(),this.unblock=this.navigation.block(t)},e.prototype.disable=function(){this.unblock&&(this.unblock(),delete this.unblock)},e.prototype.componentDidMount=function(){this.props.when&&this.enable(this.props.message)},e.prototype.componentDidUpdate=function(t){t.when?this.props.when&&this.props.message===t.message||this.enable(t.message):this.disable()},e.prototype.componentWillUnmount=function(){this.disable()},e.prototype.render=function(){return null},e.propTypes={env:(void 0)({navigation:(void 0)({block:void 0})}),when:void 0,message:(void 0)([void 0,void 0]).isRequired},e.defaultProps={when:!0},e.contextTypes={navigation:(void 0)({block:void 0}).isRequired},e}(React.Component);exports.BrowserNavigation=BrowserNavigation,exports.createContentHelpers=createContentHelpers,exports.createJunctionTemplate=createJunctionTemplate,exports.concatLocations=concatLocations,exports.createHref=createHref,exports.createPageTemplate=createPageTemplate,exports.createRedirectTemplate=createRedirectTemplate,exports.Router=Router,exports.createRouterConfig=createRouterConfig,exports.StaticNavigation=StaticNavigation,exports.defaultJunctionActiveChildRenderer=defaultJunctionActiveChildRenderer,exports.JunctionActiveChild=JunctionActiveChild,exports.Link=Link,exports.AnchorLink=AnchorLink,exports.JunctionNavigation=JunctionNavigation,exports.NavigationProvider=NavigationProvider,exports.ExitPrompt=ExitPrompt,Object.defineProperty(exports,"__esModule",{value:!0})});