@tanstack/router-core 0.0.1-beta.194 → 0.0.1-beta.195

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RouterCore={})}(this,(function(t){"use strict";function e(t,e){if(!t)throw new Error("Invariant failed")}const s="pushstate",o="popstate",r="beforeunload",a=t=>(t.preventDefault(),t.returnValue=""),n=()=>{removeEventListener(r,a,{capture:!0})};function i(t){let e=t.getLocation(),s=()=>{},o=new Set,i=[],h=[];const d=()=>{if(i.length)i[0]?.(d,(()=>{i=[],n()}));else{for(;h.length;)h.shift()?.();t.subscriber||u()}},l=t=>{h.push(t),d()},u=()=>{e=t.getLocation(),o.forEach((t=>t()))};return{get location(){return e},subscribe:e=>(0===o.size&&(s="function"==typeof t.subscriber?t.subscriber(u):()=>{}),o.add(e),()=>{o.delete(e),0===o.size&&s()}),push:(e,s)=>{c(s),l((()=>{t.pushState(e,s)}))},replace:(e,s)=>{c(s),l((()=>{t.replaceState(e,s)}))},go:e=>{l((()=>{t.go(e)}))},back:()=>{l((()=>{t.back()}))},forward:()=>{l((()=>{t.forward()}))},createHref:e=>t.createHref(e),block:t=>(i.push(t),1===i.length&&addEventListener(r,a,{capture:!0}),()=>{i=i.filter((e=>e!==t)),i.length||n()})}}function c(t){t.key=u()}function h(t){const e=t?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=t?.createHref??(t=>t);return i({getLocation:()=>l(e(),window.history.state),subscriber:t=>{window.addEventListener(s,t),window.addEventListener(o,t);var e=window.history.pushState;window.history.pushState=function(){let s=e.apply(history,arguments);return t(),s};var r=window.history.replaceState;return window.history.replaceState=function(){let e=r.apply(history,arguments);return t(),e},()=>{window.history.pushState=e,window.history.replaceState=r,window.removeEventListener(s,t),window.removeEventListener(o,t)}},pushState:(t,e)=>{window.history.pushState(e,"",r(t))},replaceState:(t,e)=>{window.history.replaceState(e,"",r(t))},back:()=>window.history.back(),forward:()=>window.history.forward(),go:t=>window.history.go(t),createHref:t=>r(t)})}function d(t={initialEntries:["/"]}){const e=t.initialEntries;let s=t.initialIndex??e.length-1,o={key:u()};return i({getLocation:()=>l(e[s],o),subscriber:!1,pushState:(t,r)=>{o=r,e.push(t),s++},replaceState:(t,r)=>{o=r,e[s]=t},back:()=>{s--},forward:()=>{s=Math.min(s+1,e.length-1)},go:t=>window.history.go(t),createHref:t=>t})}function l(t,e){let s=t.indexOf("#"),o=t.indexOf("?");return{href:t,pathname:t.substring(0,s>0?o>0?Math.min(s,o):s:o>0?o:t.length),hash:s>-1?t.substring(s):"",search:o>-1?t.slice(o,-1===s?void 0:s):"",state:e||{}}}function u(){return(Math.random()+1).toString(36).substring(7)}function p(t){return t[t.length-1]}function f(t,e){return"function"==typeof t?t(e):t}function m(t,e){return e.reduce(((e,s)=>(e[s]=t[s],e)),{})}function y(t,e){if(t===e)return t;const s=e,o=Array.isArray(t)&&Array.isArray(s);if(o||g(t)&&g(s)){const e=o?t.length:Object.keys(t).length,r=o?s:Object.keys(s),a=r.length,n=o?[]:{};let i=0;for(let e=0;e<a;e++){const a=o?e:r[e];n[a]=y(t[a],s[a]),n[a]===t[a]&&i++}return e===a&&i===e?t:n}return s}function g(t){if(!w(t))return!1;const e=t.constructor;if(void 0===e)return!0;const s=e.prototype;return!!w(s)&&!!s.hasOwnProperty("isPrototypeOf")}function w(t){return"[object Object]"===Object.prototype.toString.call(t)}function v(t,e){return t===e||typeof t==typeof e&&(g(t)&&g(e)?!Object.keys(e).some((s=>!v(t[s],e[s]))):!(!Array.isArray(t)||!Array.isArray(e))&&(t.length===e.length&&t.every(((t,s)=>v(t,e[s])))))}function _(t){return b(t.filter(Boolean).join("/"))}function b(t){return t.replace(/\/{2,}/g,"/")}function S(t){return"/"===t?t:t.replace(/^\/{1,}/,"")}function R(t){return"/"===t?t:t.replace(/\/{1,}$/,"")}function I(t){return R(S(t))}function M(t,e,s){e=e.replace(new RegExp(`^${t}`),"/"),s=s.replace(new RegExp(`^${t}`),"/");let o=x(e);const r=x(s);r.forEach(((t,e)=>{if("/"===t.value)e?e===r.length-1&&o.push(t):o=[t];else if(".."===t.value)o.length>1&&"/"===p(o)?.value&&o.pop(),o.pop();else{if("."===t.value)return;o.push(t)}}));return b(_([t,...o.map((t=>t.value))]))}function x(t){if(!t)return[];const e=[];if("/"===(t=b(t)).slice(0,1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),!t)return e;const s=t.split("/").filter(Boolean);return e.push(...s.map((t=>"$"===t||"*"===t?{type:"wildcard",value:t}:"$"===t.charAt(0)?{type:"param",value:t}:{type:"pathname",value:t}))),"/"===t.slice(-1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),e}function E(t,e,s=!1){return _(x(t).map((t=>{if("wildcard"===t.type){const o=e[t.value];return s?`${t.value}${o??""}`:o}return"param"===t.type?e[t.value.substring(1)]??"":t.value})))}function L(t,e,s){const o=P(t,e,s);if(!s.to||o)return o??{}}function P(t,e,s){e="/"!=t?e.substring(t.length):e;const o=`${s.to??"$"}`,r=x(e),a=x(o);e.startsWith("/")||r.unshift({type:"pathname",value:"/"}),o.startsWith("/")||a.unshift({type:"pathname",value:"/"});const n={};return(()=>{for(let t=0;t<Math.max(r.length,a.length);t++){const e=r[t],o=a[t],i=t>=r.length-1,c=t>=a.length-1;if(o){if("wildcard"===o.type)return!!e?.value&&(n["*"]=_(r.slice(t).map((t=>t.value))),!0);if("pathname"===o.type){if("/"===o.value&&!e?.value)return!0;if(e)if(s.caseSensitive){if(o.value!==e.value)return!1}else if(o.value.toLowerCase()!==e.value.toLowerCase())return!1}if(!e)return!1;if("param"===o.type){if("/"===e?.value)return!1;"$"!==e.value.charAt(0)&&(n[o.value.substring(1)]=e.value)}}if(!i&&c)return!!s.fuzzy}return!0})()?n:void 0}function A(t,e){var s,o,r,a="";for(s in t)if(void 0!==(r=t[s]))if(Array.isArray(r))for(o=0;o<r.length;o++)a&&(a+="&"),a+=encodeURIComponent(s)+"="+encodeURIComponent(r[o]);else a&&(a+="&"),a+=encodeURIComponent(s)+"="+encodeURIComponent(r);return(e||"")+a}function O(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||(0*+e==0&&+e+""===e?+e:e))}function D(t){for(var e,s,o={},r=t.split("&");e=r.shift();)void 0!==o[s=(e=e.split("=")).shift()]?o[s]=[].concat(o[s],O(e.shift())):o[s]=O(e.shift());return o}const B="__root__";class C{constructor(t){this.options=t||{},this.isRoot=!t?.getParentRoute,C.__onInit(this)}init=t=>{this.originalIndex=t.originalIndex,this.router=t.router;const s=this.options,o=!s?.path&&!s?.id;this.parentRoute=this.options?.getParentRoute?.(),o?this.path=B:e(this.parentRoute);let r=o?B:s.path;r&&"/"!==r&&(r=I(r));const a=s?.id||r;let n=o?B:_([this.parentRoute.id===B?"":this.parentRoute.id,a]);r===B&&(r="/"),n!==B&&(n=_(["/",n]));const i=n===B?"/":_([this.parentRoute.fullPath,r]);this.path=r,this.id=n,this.fullPath=i,this.to=i};addChildren=t=>(this.children=t,this);update=t=>(Object.assign(this.options,t),this);static __onInit=t=>{}}class $ extends C{constructor(t){super(t)}}
11
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).RouterCore={})}(this,(function(t){"use strict";function e(t,e){if(!t)throw new Error("Invariant failed")}const s="pushstate",o="popstate",r="beforeunload",a=t=>(t.preventDefault(),t.returnValue=""),n=()=>{removeEventListener(r,a,{capture:!0})};function i(t){let e=t.getLocation(),s=()=>{},o=new Set,i=[],h=[];const d=()=>{if(i.length)i[0]?.(d,(()=>{i=[],n()}));else{for(;h.length;)h.shift()?.();t.subscriber||u()}},l=t=>{h.push(t),d()},u=()=>{e=t.getLocation(),o.forEach((t=>t()))};return{get location(){return e},subscribe:e=>(0===o.size&&(s="function"==typeof t.subscriber?t.subscriber(u):()=>{}),o.add(e),()=>{o.delete(e),0===o.size&&s()}),push:(e,s)=>{c(s),l((()=>{t.pushState(e,s,u)}))},replace:(e,s)=>{c(s),l((()=>{t.replaceState(e,s,u)}))},go:e=>{l((()=>{t.go(e)}))},back:()=>{l((()=>{t.back()}))},forward:()=>{l((()=>{t.forward()}))},createHref:e=>t.createHref(e),block:t=>(i.push(t),1===i.length&&addEventListener(r,a,{capture:!0}),()=>{i=i.filter((e=>e!==t)),i.length||n()}),flush:()=>t.flush?.()}}function c(t){t.key=u()}function h(t){const e=t?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=t?.createHref??(t=>t);let a=l(e(),window.history.state);let n,c,h=!0;const d=()=>{h=!1,(()=>{n&&(window.history[n.isPush?"pushState":"replaceState"](n.state,"",n.href),n=void 0,c=void 0)})(),h=!0},u=(t,e,s,o)=>{const i=r(e);a=l(i,s),n={href:i,state:s,isPush:n?.isPush||"push"===t},o(),c||(c=Promise.resolve().then((()=>d())))};return i({getLocation:()=>a,subscriber:t=>{window.addEventListener(s,(()=>{a=l(e(),window.history.state),t()})),window.addEventListener(o,(()=>{a=l(e(),window.history.state),t()}));var r=window.history.pushState;window.history.pushState=function(){let e=r.apply(history,arguments);return h&&t(),e};var n=window.history.replaceState;return window.history.replaceState=function(){let e=n.apply(history,arguments);return h&&t(),e},()=>{window.history.pushState=r,window.history.replaceState=n,window.removeEventListener(s,t),window.removeEventListener(o,t)}},pushState:(t,e,s)=>u("push",t,e,s),replaceState:(t,e,s)=>u("replace",t,e,s),back:()=>window.history.back(),forward:()=>window.history.forward(),go:t=>window.history.go(t),createHref:t=>r(t),flush:d})}function d(t={initialEntries:["/"]}){const e=t.initialEntries;let s=t.initialIndex??e.length-1,o={key:u()};return i({getLocation:()=>l(e[s],o),subscriber:!1,pushState:(t,r)=>{o=r,e.push(t),s++},replaceState:(t,r)=>{o=r,e[s]=t},back:()=>{s--},forward:()=>{s=Math.min(s+1,e.length-1)},go:t=>window.history.go(t),createHref:t=>t})}function l(t,e){let s=t.indexOf("#"),o=t.indexOf("?");return{href:t,pathname:t.substring(0,s>0?o>0?Math.min(s,o):s:o>0?o:t.length),hash:s>-1?t.substring(s):"",search:o>-1?t.slice(o,-1===s?void 0:s):"",state:e||{}}}function u(){return(Math.random()+1).toString(36).substring(7)}function p(t){return t[t.length-1]}function f(t,e){return"function"==typeof t?t(e):t}function m(t,e){return e.reduce(((e,s)=>(e[s]=t[s],e)),{})}function y(t,e){if(t===e)return t;const s=e,o=Array.isArray(t)&&Array.isArray(s);if(o||g(t)&&g(s)){const e=o?t.length:Object.keys(t).length,r=o?s:Object.keys(s),a=r.length,n=o?[]:{};let i=0;for(let e=0;e<a;e++){const a=o?e:r[e];n[a]=y(t[a],s[a]),n[a]===t[a]&&i++}return e===a&&i===e?t:n}return s}function g(t){if(!w(t))return!1;const e=t.constructor;if(void 0===e)return!0;const s=e.prototype;return!!w(s)&&!!s.hasOwnProperty("isPrototypeOf")}function w(t){return"[object Object]"===Object.prototype.toString.call(t)}function v(t,e){return t===e||typeof t==typeof e&&(g(t)&&g(e)?!Object.keys(e).some((s=>!v(t[s],e[s]))):!(!Array.isArray(t)||!Array.isArray(e))&&(t.length===e.length&&t.every(((t,s)=>v(t,e[s])))))}function _(t){return b(t.filter(Boolean).join("/"))}function b(t){return t.replace(/\/{2,}/g,"/")}function S(t){return"/"===t?t:t.replace(/^\/{1,}/,"")}function R(t){return"/"===t?t:t.replace(/\/{1,}$/,"")}function I(t){return R(S(t))}function M(t,e,s){e=e.replace(new RegExp(`^${t}`),"/"),s=s.replace(new RegExp(`^${t}`),"/");let o=x(e);const r=x(s);r.forEach(((t,e)=>{if("/"===t.value)e?e===r.length-1&&o.push(t):o=[t];else if(".."===t.value)o.length>1&&"/"===p(o)?.value&&o.pop(),o.pop();else{if("."===t.value)return;o.push(t)}}));return b(_([t,...o.map((t=>t.value))]))}function x(t){if(!t)return[];const e=[];if("/"===(t=b(t)).slice(0,1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),!t)return e;const s=t.split("/").filter(Boolean);return e.push(...s.map((t=>"$"===t||"*"===t?{type:"wildcard",value:t}:"$"===t.charAt(0)?{type:"param",value:t}:{type:"pathname",value:t}))),"/"===t.slice(-1)&&(t=t.substring(1),e.push({type:"pathname",value:"/"})),e}function E(t,e,s=!1){return _(x(t).map((t=>{if("wildcard"===t.type){const o=e[t.value];return s?`${t.value}${o??""}`:o}return"param"===t.type?e[t.value.substring(1)]??"":t.value})))}function L(t,e,s){const o=P(t,e,s);if(!s.to||o)return o??{}}function P(t,e,s){e="/"!=t?e.substring(t.length):e;const o=`${s.to??"$"}`,r=x(e),a=x(o);e.startsWith("/")||r.unshift({type:"pathname",value:"/"}),o.startsWith("/")||a.unshift({type:"pathname",value:"/"});const n={};return(()=>{for(let t=0;t<Math.max(r.length,a.length);t++){const e=r[t],o=a[t],i=t>=r.length-1,c=t>=a.length-1;if(o){if("wildcard"===o.type)return!!e?.value&&(n["*"]=_(r.slice(t).map((t=>t.value))),!0);if("pathname"===o.type){if("/"===o.value&&!e?.value)return!0;if(e)if(s.caseSensitive){if(o.value!==e.value)return!1}else if(o.value.toLowerCase()!==e.value.toLowerCase())return!1}if(!e)return!1;if("param"===o.type){if("/"===e?.value)return!1;"$"!==e.value.charAt(0)&&(n[o.value.substring(1)]=e.value)}}if(!i&&c)return!!s.fuzzy}return!0})()?n:void 0}function A(t,e){var s,o,r,a="";for(s in t)if(void 0!==(r=t[s]))if(Array.isArray(r))for(o=0;o<r.length;o++)a&&(a+="&"),a+=encodeURIComponent(s)+"="+encodeURIComponent(r[o]);else a&&(a+="&"),a+=encodeURIComponent(s)+"="+encodeURIComponent(r);return(e||"")+a}function O(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||(0*+e==0&&+e+""===e?+e:e))}function D(t){for(var e,s,o={},r=t.split("&");e=r.shift();)void 0!==o[s=(e=e.split("=")).shift()]?o[s]=[].concat(o[s],O(e.shift())):o[s]=O(e.shift());return o}const B="__root__";class C{constructor(t){this.options=t||{},this.isRoot=!t?.getParentRoute,C.__onInit(this)}init=t=>{this.originalIndex=t.originalIndex,this.router=t.router;const s=this.options,o=!s?.path&&!s?.id;this.parentRoute=this.options?.getParentRoute?.(),o?this.path=B:e(this.parentRoute);let r=o?B:s.path;r&&"/"!==r&&(r=I(r));const a=s?.id||r;let n=o?B:_([this.parentRoute.id===B?"":this.parentRoute.id,a]);r===B&&(r="/"),n!==B&&(n=_(["/",n]));const i=n===B?"/":_([this.parentRoute.fullPath,r]);this.path=r,this.id=n,this.fullPath=i,this.to=i};addChildren=t=>(this.children=t,this);update=t=>(Object.assign(this.options,t),this);static __onInit=t=>{}}class $ extends C{constructor(t){super(t)}}
12
12
  /**
13
13
  * @tanstack/store/src/index.ts
14
14
  *