Closed ritchieanesco closed 3 years ago
ok looks like this issue is coming from svelte and seems to be an ongoing thing. https://github.com/sveltejs/svelte/issues/3165. Is it possible to publish the source files in order to address this issue as suggested by this comment
For a temporary solution i've created a patch using patch package. Below is the patch for v0.4.6. This patch simply replaces import statements that reference the distributable folder with source folder.
diff --git a/node_modules/tinro/.DS_Store b/node_modules/tinro/.DS_Store
new file mode 100644
index 0000000..b07e2f4
Binary files /dev/null and b/node_modules/tinro/.DS_Store differ
diff --git a/node_modules/tinro/cmp/Route.svelte b/node_modules/tinro/cmp/Route.svelte
index 9a17f54..bb104f1 100644
--- a/node_modules/tinro/cmp/Route.svelte
+++ b/node_modules/tinro/cmp/Route.svelte
@@ -1,5 +1,5 @@
<script>
- import {createRouteObject} from './../dist/tinro_lib';
+ import {createRouteObject} from '../src/lib';
export let path = '/*';
export let fallback = false;
diff --git a/node_modules/tinro/cmp/index.js b/node_modules/tinro/cmp/index.js
index eaa0bb0..6ebb7e9 100644
--- a/node_modules/tinro/cmp/index.js
+++ b/node_modules/tinro/cmp/index.js
@@ -1,2 +1,2 @@
export {default as Route} from './Route.svelte';
-export {router,active} from './../dist/tinro_lib';
\ No newline at end of file
+export {router,active} from '../src/router';
diff --git a/node_modules/tinro/dist/.DS_Store b/node_modules/tinro/dist/.DS_Store
new file mode 100644
index 0000000..5008ddf
Binary files /dev/null and b/node_modules/tinro/dist/.DS_Store differ
diff --git a/node_modules/tinro/dist/tinro.es.js b/node_modules/tinro/dist/tinro.es.js
index dd9d13a..a77c572 100644
--- a/node_modules/tinro/dist/tinro.es.js
+++ b/node_modules/tinro/dist/tinro.es.js
@@ -1 +1,2 @@
-function t(){}function e(t){return t()}function n(){return Object.create(null)}function r(t){t.forEach(e)}function a(t){return"function"==typeof t}function c(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function o(t,e,n,r){return t[1]&&r?function(t,e){for(const n in e)t[n]=e[n];return t}(n.ctx.slice(),t[1](r(e))):n.ctx}function i(t,e,n,r,a,c,i){const s=function(t,e,n,r){if(t[2]&&r){const a=t[2](r(n));if(void 0===e.dirty)return a;if("object"==typeof a){const t=[],n=Math.max(e.dirty.length,a.length);for(let r=0;r<n;r+=1)t[r]=e.dirty[r]|a[r];return t}return e.dirty|a}return e.dirty}(e,r,a,c);if(s){const a=o(e,n,r,i);t.p(a,s)}}function s(t){t.parentNode.removeChild(t)}function l(){return t="",document.createTextNode(t);var t}let u;function f(t){u=t}function h(){if(!u)throw new Error("Function called outside component initialization");return u}function p(t){h().$$.on_mount.push(t)}function d(t,e){h().$$.context.set(t,e)}function b(t){return h().$$.context.get(t)}const m=[],w=[],g=[],$=[],k=Promise.resolve();let x=!1;function v(){x||(x=!0,k.then(W))}function y(){return v(),k}function E(t){g.push(t)}let _=!1;const S=new Set;function W(){if(!_){_=!0;do{for(let t=0;t<m.length;t+=1){const e=m[t];f(e),z(e.$$)}for(f(null),m.length=0;w.length;)w.pop()();for(let t=0;t<g.length;t+=1){const e=g[t];S.has(e)||(S.add(e),e())}g.length=0}while(m.length);for(;$.length;)$.pop()();x=!1,_=!1,S.clear()}}function z(t){if(null!==t.fragment){t.update(),r(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(E)}}const R=new Set;let j;function A(t,e){t&&t.i&&(R.delete(t),t.i(e))}function C(t,e,n,r){if(t&&t.o){if(R.has(t))return;R.add(t),j.c.push(()=>{R.delete(t),r&&(n&&t.d(1),r())}),t.o(e)}}function P(c,o,i,l,h,p,d=[-1]){const b=u;f(c);const w=o.props||{},g=c.$$={fragment:null,ctx:null,props:p,update:t,not_equal:h,bound:n(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(b?b.$$.context:[]),callbacks:n(),dirty:d,skip_bound:!1};let $=!1;if(g.ctx=i?i(c,w,(t,e,...n)=>{const r=n.length?n[0]:e;return g.ctx&&h(g.ctx[t],g.ctx[t]=r)&&(!g.skip_bound&&g.bound[t]&&g.bound[t](r),$&&function(t,e){-1===t.$$.dirty[0]&&(m.push(t),v(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}(c,t)),e}):[],g.update(),$=!0,r(g.before_update),g.fragment=!!l&&l(g.ctx),o.target){if(o.hydrate){const t=(k=o.target,Array.from(k.childNodes));g.fragment&&g.fragment.l(t),t.forEach(s)}else g.fragment&&g.fragment.c();o.intro&&A(c.$$.fragment),function(t,n,c){const{fragment:o,on_mount:i,on_destroy:s,after_update:l}=t.$$;o&&o.m(n,c),E(()=>{const n=i.map(e).filter(a);s?s.push(...n):r(n),t.$$.on_mount=[]}),l.forEach(E)}(c,o.target,o.anchor),W()}var k;f(b)}const L=[];function N(e,n=t){let r;const a=[];function o(t){if(c(e,t)&&(e=t,r)){const t=!L.length;for(let t=0;t<a.length;t+=1){const n=a[t];n[1](),L.push(n,e)}if(t){for(let t=0;t<L.length;t+=2)L[t][0](L[t+1]);L.length=0}}}return{set:o,update:function(t){o(t(e))},subscribe:function(c,i=t){const s=[c,i];return a.push(s),1===a.length&&(r=n(o)||t),c(e),()=>{const t=a.indexOf(s);-1!==t&&a.splice(t,1),0===a.length&&(r(),r=null)}}}}function O(t){const e=b("tinro");e&&(e.exact||e.fallback)&&function(t){throw new Error(t)}(`${t.fallback?"<Route fallback>":`<Route path="${t.path}">`} can't be inside ${e.fallback?"<Route fallback>":`<Route path="${e.path||"/"}"> with exact path`}`);const n=t.fallback?"fallbacks":"childs",r={un:null,exact:!1,pattern:"",params:{},parent:e,fallback:t.fallback,redirect:t.redirect,childs:new Set,activeChilds:new Set,fallbacks:new Set,makePattern(t){r.exact=!t.endsWith("/*"),r.pattern=q(`${r.parent&&r.parent.pattern||""}${t}`)},register:()=>{if(r.parent)return r.parent[n].add(r),()=>{r.parent[n].delete(r),r.un&&r.un()}},show:()=>{t.onShow(),!r.fallback&&r.parent&&r.parent.activeChilds.add(r)},hide:()=>{t.onHide(),!r.fallback&&r.parent&&r.parent.activeChilds.delete(r)},match:async e=>{const n=function(t,e){t=q(t,!0),e=q(e,!0);const n=[];let r={},a=!0,c=t.split("/").map(t=>t.startsWith(":")?(n.push(t.slice(1)),"([^\\/]+)"):t).join("\\/"),o=e.match(new RegExp(`^${c}$`));return o||(a=!1,o=e.match(new RegExp("^"+c))),o?(n.forEach((t,e)=>r[t]=o[e+1]),{exact:a,params:r}):null}(r.pattern,e);if(n&&r.redirect&&(!r.exact||r.exact&&n.exact))return D.goto(function(t,e,n){if(""===n)return t;if("/"===n[0])return n;const r=t=>t.split("/").filter(t=>""!==t),a=r(t);return"/"+r(e).map((t,e)=>a[e]).join("/")+"/"+n}(e,r.parent.pattern,r.redirect));if(!r.fallback&&n&&(!r.exact||r.exact&&n.exact)?(t.onParams(r.params=n.params),r.show()):r.hide(),await y(),!r.fallback&&n&&(r.childs.size>0&&0==r.activeChilds.size||0==r.childs.size&&r.fallbacks.size>0)){let t=r;for(;0==t.fallbacks.size;)if(t=t.parent,!t)return;t&&t.fallbacks.forEach(t=>t.show())}}};return r.makePattern(t.path),d("tinro",r),p(()=>r.register()),r.un=D.subscribe(t=>{r.match(t.path)}),r}function q(t,e=!1){return(t=t.slice(t.startsWith("/#")?2:0,t.endsWith("/*")?-2:void 0)).startsWith("/")||(t="/"+t),"/"===t&&(t=""),e&&!t.endsWith("/")&&(t+="/"),t}function H(t){const e=t.split("&").map(t=>t.split("=")).reduce((t,e)=>{const n=e[0];if(!n)return t;let r=!(e.length>1)||e[e.length-1];return"string"==typeof r&&r.includes(",")&&(r=r.split(",")),void 0===t[n]?t[n]=[r]:t[n].push(r),t},{});return Object.entries(e).reduce((t,e)=>(t[e[0]]=e[1].length>1?e[1]:e[1][0],t),{})}const D=function(){let t="srcdoc"===window.location.pathname;const e=(e,n)=>{t?window.location.hash=e:history.pushState({},"",e),n(M(t))},{subscribe:n,set:r}=N(M(t),n=>{window.hashchange=window.onpopstate=e=>r(M(t));const a=function(t){const e=e=>{const n=e.target.closest("a[href]");if((!n||!function(t,e,n,r){const a=[e,"data-"+e].reduce((e,r)=>{const a=t.getAttribute(r);return n&&t.removeAttribute(r),null===a?e:a},!1);return!r&&""===a||a||r||!1}(n,"tinro-ignore"))&&n){const r=n.getAttribute("href").replace(/^\/#/,"");/^\/\/|^[a-zA-Z]+:/.test(r)||(e.preventDefault(),t(r.startsWith("/")?r:n.href.replace(window.location.origin,"")))}};return addEventListener("click",e),()=>removeEventListener("click",e)}(t=>e(t,r));return t=>{window.hashchange=window.onpopstate=null,a()}});return{subscribe:n,goto:t=>e(t,r),params:Z,useHashNavigation:e=>r(M(t=void 0===e||e))}}();function M(t){return t?function(){const t=String(window.location.hash.slice(1)||"/").match(/^([^?#]+)(?:\?([^#]+))?(?:\#(.+))?$/);return{path:t[1]||"",query:H(t[2]||""),hash:t[3]||""}}():{path:window.location.pathname,query:H(window.location.search.slice(1)),hash:window.location.hash.slice(1)}}function Z(){return b("tinro").params}const B=t=>({params:2&t}),F=t=>({params:t[1]});function T(t){let e;const n=t[6].default,r=function(t,e,n,r){if(t){const a=o(t,e,n,r);return t[0](a)}}(n,t,t[5],F);return{c(){r&&r.c()},m(t,n){r&&r.m(t,n),e=!0},p(t,e){r&&r.p&&34&e&&i(r,n,t,t[5],e,B,F)},i(t){e||(A(r,t),e=!0)},o(t){C(r,t),e=!1},d(t){r&&r.d(t)}}}function G(t){let e,n,a=t[0]&&T(t);return{c(){a&&a.c(),e=l()},m(t,r){a&&a.m(t,r),function(t,e,n){t.insertBefore(e,n||null)}(t,e,r),n=!0},p(t,[n]){t[0]?a?(a.p(t,n),1&n&&A(a,1)):(a=T(t),a.c(),A(a,1),a.m(e.parentNode,e)):a&&(j={r:0,c:[],p:j},C(a,1,1,()=>{a=null}),j.r||r(j.c),j=j.p)},i(t){n||(A(a),n=!0)},o(t){C(a),n=!1},d(t){a&&a.d(t),t&&s(e)}}}function I(t,e,n){let{$$slots:r={},$$scope:a}=e,{path:c="/*"}=e,{fallback:o=!1}=e,{redirect:i=!1}=e,s=!1,l={};return O({path:c,fallback:o,redirect:i,onShow(){n(0,s=!0)},onHide(){n(0,s=!1)},onParams(t){n(1,l=t)}}),t.$$set=t=>{"path"in t&&n(2,c=t.path),"fallback"in t&&n(3,o=t.fallback),"redirect"in t&&n(4,i=t.redirect),"$$scope"in t&&n(5,a=t.$$scope)},[s,l,c,o,i,a,r]}class J extends class{$destroy(){!function(t,e){const n=t.$$;null!==n.fragment&&(r(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}(this,1),this.$destroy=t}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}{constructor(t){super(),P(this,t,I,G,c,{path:2,fallback:3,redirect:4})}}function K(t){const e=b("tinro");e&&(e.exact||e.fallback)&&function(t){throw new Error(t)}(`${t.fallback?"<Route fallback>":`<Route path="${t.path}">`} can't be inside ${e.fallback?"<Route fallback>":`<Route path="${e.path||"/"}"> with exact path`}`);const n=t.fallback?"fallbacks":"childs",r={un:null,exact:!1,pattern:"",params:{},parent:e,fallback:t.fallback,redirect:t.redirect,childs:new Set,activeChilds:new Set,fallbacks:new Set,makePattern(t){r.exact=!t.endsWith("/*"),r.pattern=Q(`${r.parent&&r.parent.pattern||""}${t}`)},register:()=>{if(r.parent)return r.parent[n].add(r),()=>{r.parent[n].delete(r),r.un&&r.un()}},show:()=>{t.onShow(),!r.fallback&&r.parent&&r.parent.activeChilds.add(r)},hide:()=>{t.onHide(),!r.fallback&&r.parent&&r.parent.activeChilds.delete(r)},match:async e=>{const n=U(r.pattern,e);if(n&&r.redirect&&(!r.exact||r.exact&&n.exact))return Y.goto(function(t,e,n){if(""===n)return t;if("/"===n[0])return n;const r=t=>t.split("/").filter(t=>""!==t),a=r(t);return"/"+r(e).map((t,e)=>a[e]).join("/")+"/"+n}(e,r.parent.pattern,r.redirect));if(!r.fallback&&n&&(!r.exact||r.exact&&n.exact)?(t.onParams(r.params=n.params),r.show()):r.hide(),await y(),!r.fallback&&n&&(r.childs.size>0&&0==r.activeChilds.size||0==r.childs.size&&r.fallbacks.size>0)){let t=r;for(;0==t.fallbacks.size;)if(t=t.parent,!t)return;t&&t.fallbacks.forEach(t=>t.show())}}};return r.makePattern(t.path),d("tinro",r),p(()=>r.register()),r.un=Y.subscribe(t=>{r.match(t.path)}),r}function Q(t,e=!1){return(t=t.slice(t.startsWith("/#")?2:0,t.endsWith("/*")?-2:void 0)).startsWith("/")||(t="/"+t),"/"===t&&(t=""),e&&!t.endsWith("/")&&(t+="/"),t}function U(t,e){t=Q(t,!0),e=Q(e,!0);const n=[];let r={},a=!0,c=t.split("/").map(t=>t.startsWith(":")?(n.push(t.slice(1)),"([^\\/]+)"):t).join("\\/"),o=e.match(new RegExp(`^${c}$`));return o||(a=!1,o=e.match(new RegExp("^"+c))),o?(n.forEach((t,e)=>r[t]=o[e+1]),{exact:a,params:r}):null}function V(t,e,n,r){const a=[e,"data-"+e].reduce((e,r)=>{const a=t.getAttribute(r);return n&&t.removeAttribute(r),null===a?e:a},!1);return!r&&""===a||(a||(r||!1))}function X(t){const e=t.split("&").map(t=>t.split("=")).reduce((t,e)=>{const n=e[0];if(!n)return t;let r=!(e.length>1)||e[e.length-1];return"string"==typeof r&&r.includes(",")&&(r=r.split(",")),void 0===t[n]?t[n]=[r]:t[n].push(r),t},{});return Object.entries(e).reduce((t,e)=>(t[e[0]]=e[1].length>1?e[1]:e[1][0],t),{})}const Y=function(){let t="srcdoc"===window.location.pathname;const e=(e,n)=>{t?window.location.hash=e:history.pushState({},"",e),n(et(t))},{subscribe:n,set:r}=N(et(t),n=>{window.hashchange=window.onpopstate=e=>r(et(t));const a=function(t){const e=e=>{const n=e.target.closest("a[href]");if(!(n&&V(n,"tinro-ignore"))&&n){const r=n.getAttribute("href").replace(/^\/#/,"");/^\/\/|^[a-zA-Z]+:/.test(r)||(e.preventDefault(),t(r.startsWith("/")?r:n.href.replace(window.location.origin,"")))}};return addEventListener("click",e),()=>removeEventListener("click",e)}(t=>e(t,r));return t=>{window.hashchange=window.onpopstate=null,a()}});return{subscribe:n,goto:t=>e(t,r),params:nt,useHashNavigation:e=>r(et(t=void 0===e||e))}}();function tt(t){const e=V(t,"href"),n=V(t,"exact",!0),r=V(t,"active-class",!0,"active");return{destroy:Y.subscribe(a=>{const c=U(e,a.path);c&&(c.exact&&n||!n)?t.classList.add(r):t.classList.remove(r)})}}function et(t){return t?function(){const t=String(window.location.hash.slice(1)||"/").match(/^([^?#]+)(?:\?([^#]+))?(?:\#(.+))?$/);return{path:t[1]||"",query:X(t[2]||""),hash:t[3]||""}}():{path:window.location.pathname,query:X(window.location.search.slice(1)),hash:window.location.hash.slice(1)}}function nt(){return b("tinro").params}export{J as Route,tt as active,K as createRouteObject,Y as router};
+export {default as Route} from '../cmp/Route.svelte';
+export * from '../src/tinro';
diff --git a/node_modules/tinro/dist/tinro.js b/node_modules/tinro/dist/tinro.js
index 67c8c63..a77c572 100644
--- a/node_modules/tinro/dist/tinro.js
+++ b/node_modules/tinro/dist/tinro.js
@@ -1 +1,2 @@
-"use strict";function t(){}function e(t){return t()}function n(){return Object.create(null)}function r(t){t.forEach(e)}function a(t){return"function"==typeof t}function c(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function o(t,e,n,r){return t[1]&&r?function(t,e){for(const n in e)t[n]=e[n];return t}(n.ctx.slice(),t[1](r(e))):n.ctx}function i(t,e,n,r,a,c,i){const s=function(t,e,n,r){if(t[2]&&r){const a=t[2](r(n));if(void 0===e.dirty)return a;if("object"==typeof a){const t=[],n=Math.max(e.dirty.length,a.length);for(let r=0;r<n;r+=1)t[r]=e.dirty[r]|a[r];return t}return e.dirty|a}return e.dirty}(e,r,a,c);if(s){const a=o(e,n,r,i);t.p(a,s)}}function s(t){t.parentNode.removeChild(t)}function l(){return t="",document.createTextNode(t);var t}let u;function f(t){u=t}function h(){if(!u)throw new Error("Function called outside component initialization");return u}function p(t){h().$$.on_mount.push(t)}function d(t,e){h().$$.context.set(t,e)}function b(t){return h().$$.context.get(t)}Object.defineProperty(exports,"__esModule",{value:!0});const m=[],w=[],g=[],$=[],k=Promise.resolve();let x=!1;function v(){x||(x=!0,k.then(R))}function y(){return v(),k}function _(t){g.push(t)}let E=!1;const S=new Set;function R(){if(!E){E=!0;do{for(let t=0;t<m.length;t+=1){const e=m[t];f(e),W(e.$$)}for(f(null),m.length=0;w.length;)w.pop()();for(let t=0;t<g.length;t+=1){const e=g[t];S.has(e)||(S.add(e),e())}g.length=0}while(m.length);for(;$.length;)$.pop()();x=!1,E=!1,S.clear()}}function W(t){if(null!==t.fragment){t.update(),r(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(_)}}const z=new Set;let j;function A(t,e){t&&t.i&&(z.delete(t),t.i(e))}function C(t,e,n,r){if(t&&t.o){if(z.has(t))return;z.add(t),j.c.push(()=>{z.delete(t),r&&(n&&t.d(1),r())}),t.o(e)}}function P(c,o,i,l,h,p,d=[-1]){const b=u;f(c);const w=o.props||{},g=c.$$={fragment:null,ctx:null,props:p,update:t,not_equal:h,bound:n(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(b?b.$$.context:[]),callbacks:n(),dirty:d,skip_bound:!1};let $=!1;if(g.ctx=i?i(c,w,(t,e,...n)=>{const r=n.length?n[0]:e;return g.ctx&&h(g.ctx[t],g.ctx[t]=r)&&(!g.skip_bound&&g.bound[t]&&g.bound[t](r),$&&function(t,e){-1===t.$$.dirty[0]&&(m.push(t),v(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}(c,t)),e}):[],g.update(),$=!0,r(g.before_update),g.fragment=!!l&&l(g.ctx),o.target){if(o.hydrate){const t=(k=o.target,Array.from(k.childNodes));g.fragment&&g.fragment.l(t),t.forEach(s)}else g.fragment&&g.fragment.c();o.intro&&A(c.$$.fragment),function(t,n,c){const{fragment:o,on_mount:i,on_destroy:s,after_update:l}=t.$$;o&&o.m(n,c),_(()=>{const n=i.map(e).filter(a);s?s.push(...n):r(n),t.$$.on_mount=[]}),l.forEach(_)}(c,o.target,o.anchor),R()}var k;f(b)}const O=[];function L(e,n=t){let r;const a=[];function o(t){if(c(e,t)&&(e=t,r)){const t=!O.length;for(let t=0;t<a.length;t+=1){const n=a[t];n[1](),O.push(n,e)}if(t){for(let t=0;t<O.length;t+=2)O[t][0](O[t+1]);O.length=0}}}return{set:o,update:function(t){o(t(e))},subscribe:function(c,i=t){const s=[c,i];return a.push(s),1===a.length&&(r=n(o)||t),c(e),()=>{const t=a.indexOf(s);-1!==t&&a.splice(t,1),0===a.length&&(r(),r=null)}}}}function N(t){const e=b("tinro");e&&(e.exact||e.fallback)&&function(t){throw new Error(t)}(`${t.fallback?"<Route fallback>":`<Route path="${t.path}">`} can't be inside ${e.fallback?"<Route fallback>":`<Route path="${e.path||"/"}"> with exact path`}`);const n=t.fallback?"fallbacks":"childs",r={un:null,exact:!1,pattern:"",params:{},parent:e,fallback:t.fallback,redirect:t.redirect,childs:new Set,activeChilds:new Set,fallbacks:new Set,makePattern(t){r.exact=!t.endsWith("/*"),r.pattern=q(`${r.parent&&r.parent.pattern||""}${t}`)},register:()=>{if(r.parent)return r.parent[n].add(r),()=>{r.parent[n].delete(r),r.un&&r.un()}},show:()=>{t.onShow(),!r.fallback&&r.parent&&r.parent.activeChilds.add(r)},hide:()=>{t.onHide(),!r.fallback&&r.parent&&r.parent.activeChilds.delete(r)},match:async e=>{const n=function(t,e){t=q(t,!0),e=q(e,!0);const n=[];let r={},a=!0,c=t.split("/").map(t=>t.startsWith(":")?(n.push(t.slice(1)),"([^\\/]+)"):t).join("\\/"),o=e.match(new RegExp(`^${c}$`));return o||(a=!1,o=e.match(new RegExp("^"+c))),o?(n.forEach((t,e)=>r[t]=o[e+1]),{exact:a,params:r}):null}(r.pattern,e);if(n&&r.redirect&&(!r.exact||r.exact&&n.exact))return M.goto(function(t,e,n){if(""===n)return t;if("/"===n[0])return n;const r=t=>t.split("/").filter(t=>""!==t),a=r(t);return"/"+r(e).map((t,e)=>a[e]).join("/")+"/"+n}(e,r.parent.pattern,r.redirect));if(!r.fallback&&n&&(!r.exact||r.exact&&n.exact)?(t.onParams(r.params=n.params),r.show()):r.hide(),await y(),!r.fallback&&n&&(r.childs.size>0&&0==r.activeChilds.size||0==r.childs.size&&r.fallbacks.size>0)){let t=r;for(;0==t.fallbacks.size;)if(t=t.parent,!t)return;t&&t.fallbacks.forEach(t=>t.show())}}};return r.makePattern(t.path),d("tinro",r),p(()=>r.register()),r.un=M.subscribe(t=>{r.match(t.path)}),r}function q(t,e=!1){return(t=t.slice(t.startsWith("/#")?2:0,t.endsWith("/*")?-2:void 0)).startsWith("/")||(t="/"+t),"/"===t&&(t=""),e&&!t.endsWith("/")&&(t+="/"),t}function H(t){const e=t.split("&").map(t=>t.split("=")).reduce((t,e)=>{const n=e[0];if(!n)return t;let r=!(e.length>1)||e[e.length-1];return"string"==typeof r&&r.includes(",")&&(r=r.split(",")),void 0===t[n]?t[n]=[r]:t[n].push(r),t},{});return Object.entries(e).reduce((t,e)=>(t[e[0]]=e[1].length>1?e[1]:e[1][0],t),{})}const M=function(){let t="srcdoc"===window.location.pathname;const e=(e,n)=>{t?window.location.hash=e:history.pushState({},"",e),n(D(t))},{subscribe:n,set:r}=L(D(t),n=>{window.hashchange=window.onpopstate=e=>r(D(t));const a=function(t){const e=e=>{const n=e.target.closest("a[href]");if((!n||!function(t,e,n,r){const a=[e,"data-"+e].reduce((e,r)=>{const a=t.getAttribute(r);return n&&t.removeAttribute(r),null===a?e:a},!1);return!r&&""===a||a||r||!1}(n,"tinro-ignore"))&&n){const r=n.getAttribute("href").replace(/^\/#/,"");/^\/\/|^[a-zA-Z]+:/.test(r)||(e.preventDefault(),t(r.startsWith("/")?r:n.href.replace(window.location.origin,"")))}};return addEventListener("click",e),()=>removeEventListener("click",e)}(t=>e(t,r));return t=>{window.hashchange=window.onpopstate=null,a()}});return{subscribe:n,goto:t=>e(t,r),params:Z,useHashNavigation:e=>r(D(t=void 0===e||e))}}();function D(t){return t?function(){const t=String(window.location.hash.slice(1)||"/").match(/^([^?#]+)(?:\?([^#]+))?(?:\#(.+))?$/);return{path:t[1]||"",query:H(t[2]||""),hash:t[3]||""}}():{path:window.location.pathname,query:H(window.location.search.slice(1)),hash:window.location.hash.slice(1)}}function Z(){return b("tinro").params}const B=t=>({params:2&t}),F=t=>({params:t[1]});function T(t){let e;const n=t[6].default,r=function(t,e,n,r){if(t){const a=o(t,e,n,r);return t[0](a)}}(n,t,t[5],F);return{c(){r&&r.c()},m(t,n){r&&r.m(t,n),e=!0},p(t,e){r&&r.p&&34&e&&i(r,n,t,t[5],e,B,F)},i(t){e||(A(r,t),e=!0)},o(t){C(r,t),e=!1},d(t){r&&r.d(t)}}}function G(t){let e,n,a=t[0]&&T(t);return{c(){a&&a.c(),e=l()},m(t,r){a&&a.m(t,r),function(t,e,n){t.insertBefore(e,n||null)}(t,e,r),n=!0},p(t,[n]){t[0]?a?(a.p(t,n),1&n&&A(a,1)):(a=T(t),a.c(),A(a,1),a.m(e.parentNode,e)):a&&(j={r:0,c:[],p:j},C(a,1,1,()=>{a=null}),j.r||r(j.c),j=j.p)},i(t){n||(A(a),n=!0)},o(t){C(a),n=!1},d(t){a&&a.d(t),t&&s(e)}}}function I(t,e,n){let{$$slots:r={},$$scope:a}=e,{path:c="/*"}=e,{fallback:o=!1}=e,{redirect:i=!1}=e,s=!1,l={};return N({path:c,fallback:o,redirect:i,onShow(){n(0,s=!0)},onHide(){n(0,s=!1)},onParams(t){n(1,l=t)}}),t.$$set=t=>{"path"in t&&n(2,c=t.path),"fallback"in t&&n(3,o=t.fallback),"redirect"in t&&n(4,i=t.redirect),"$$scope"in t&&n(5,a=t.$$scope)},[s,l,c,o,i,a,r]}function J(t,e=!1){return(t=t.slice(t.startsWith("/#")?2:0,t.endsWith("/*")?-2:void 0)).startsWith("/")||(t="/"+t),"/"===t&&(t=""),e&&!t.endsWith("/")&&(t+="/"),t}function K(t,e){t=J(t,!0),e=J(e,!0);const n=[];let r={},a=!0,c=t.split("/").map(t=>t.startsWith(":")?(n.push(t.slice(1)),"([^\\/]+)"):t).join("\\/"),o=e.match(new RegExp(`^${c}$`));return o||(a=!1,o=e.match(new RegExp("^"+c))),o?(n.forEach((t,e)=>r[t]=o[e+1]),{exact:a,params:r}):null}function Q(t,e,n,r){const a=[e,"data-"+e].reduce((e,r)=>{const a=t.getAttribute(r);return n&&t.removeAttribute(r),null===a?e:a},!1);return!r&&""===a||(a||(r||!1))}function U(t){const e=t.split("&").map(t=>t.split("=")).reduce((t,e)=>{const n=e[0];if(!n)return t;let r=!(e.length>1)||e[e.length-1];return"string"==typeof r&&r.includes(",")&&(r=r.split(",")),void 0===t[n]?t[n]=[r]:t[n].push(r),t},{});return Object.entries(e).reduce((t,e)=>(t[e[0]]=e[1].length>1?e[1]:e[1][0],t),{})}const V=function(){let t="srcdoc"===window.location.pathname;const e=(e,n)=>{t?window.location.hash=e:history.pushState({},"",e),n(X(t))},{subscribe:n,set:r}=L(X(t),n=>{window.hashchange=window.onpopstate=e=>r(X(t));const a=function(t){const e=e=>{const n=e.target.closest("a[href]");if(!(n&&Q(n,"tinro-ignore"))&&n){const r=n.getAttribute("href").replace(/^\/#/,"");/^\/\/|^[a-zA-Z]+:/.test(r)||(e.preventDefault(),t(r.startsWith("/")?r:n.href.replace(window.location.origin,"")))}};return addEventListener("click",e),()=>removeEventListener("click",e)}(t=>e(t,r));return t=>{window.hashchange=window.onpopstate=null,a()}});return{subscribe:n,goto:t=>e(t,r),params:Y,useHashNavigation:e=>r(X(t=void 0===e||e))}}();function X(t){return t?function(){const t=String(window.location.hash.slice(1)||"/").match(/^([^?#]+)(?:\?([^#]+))?(?:\#(.+))?$/);return{path:t[1]||"",query:U(t[2]||""),hash:t[3]||""}}():{path:window.location.pathname,query:U(window.location.search.slice(1)),hash:window.location.hash.slice(1)}}function Y(){return b("tinro").params}exports.Route=class extends class{$destroy(){!function(t,e){const n=t.$$;null!==n.fragment&&(r(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}(this,1),this.$destroy=t}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}{constructor(t){super(),P(this,t,I,G,c,{path:2,fallback:3,redirect:4})}},exports.active=function(t){const e=Q(t,"href"),n=Q(t,"exact",!0),r=Q(t,"active-class",!0,"active");return{destroy:V.subscribe(a=>{const c=K(e,a.path);c&&(c.exact&&n||!n)?t.classList.add(r):t.classList.remove(r)})}},exports.createRouteObject=function(t){const e=b("tinro");e&&(e.exact||e.fallback)&&function(t){throw new Error(t)}(`${t.fallback?"<Route fallback>":`<Route path="${t.path}">`} can't be inside ${e.fallback?"<Route fallback>":`<Route path="${e.path||"/"}"> with exact path`}`);const n=t.fallback?"fallbacks":"childs",r={un:null,exact:!1,pattern:"",params:{},parent:e,fallback:t.fallback,redirect:t.redirect,childs:new Set,activeChilds:new Set,fallbacks:new Set,makePattern(t){r.exact=!t.endsWith("/*"),r.pattern=J(`${r.parent&&r.parent.pattern||""}${t}`)},register:()=>{if(r.parent)return r.parent[n].add(r),()=>{r.parent[n].delete(r),r.un&&r.un()}},show:()=>{t.onShow(),!r.fallback&&r.parent&&r.parent.activeChilds.add(r)},hide:()=>{t.onHide(),!r.fallback&&r.parent&&r.parent.activeChilds.delete(r)},match:async e=>{const n=K(r.pattern,e);if(n&&r.redirect&&(!r.exact||r.exact&&n.exact))return V.goto(function(t,e,n){if(""===n)return t;if("/"===n[0])return n;const r=t=>t.split("/").filter(t=>""!==t),a=r(t);return"/"+r(e).map((t,e)=>a[e]).join("/")+"/"+n}(e,r.parent.pattern,r.redirect));if(!r.fallback&&n&&(!r.exact||r.exact&&n.exact)?(t.onParams(r.params=n.params),r.show()):r.hide(),await y(),!r.fallback&&n&&(r.childs.size>0&&0==r.activeChilds.size||0==r.childs.size&&r.fallbacks.size>0)){let t=r;for(;0==t.fallbacks.size;)if(t=t.parent,!t)return;t&&t.fallbacks.forEach(t=>t.show())}}};return r.makePattern(t.path),d("tinro",r),p(()=>r.register()),r.un=V.subscribe(t=>{r.match(t.path)}),r},exports.router=V;
+export {default as Route} from '../cmp/Route.svelte';
+export * from '../src/tinro';
diff --git a/node_modules/tinro/src/index.js b/node_modules/tinro/src/index.js
new file mode 100644
index 0000000..65ccf50
--- /dev/null
+++ b/node_modules/tinro/src/index.js
@@ -0,0 +1,2 @@
+export {default as Route} from '../cmp/Route.svelte';
+export * from './tinro';
diff --git a/node_modules/tinro/src/lib.js b/node_modules/tinro/src/lib.js
new file mode 100644
index 0000000..e2352b3
--- /dev/null
+++ b/node_modules/tinro/src/lib.js
@@ -0,0 +1,166 @@
+import {getContext,setContext,onMount,tick} from 'svelte';
+import {router} from './router';
+
+export function createRouteObject(options){
+
+ const parent = getContext('tinro');
+
+ if(parent && (parent.exact || parent.fallback) ) err(
+ `${options.fallback ? '<Route fallback>' : `<Route path="${options.path}">`} can't be inside ${parent.fallback ?
+ '<Route fallback>' :
+ `<Route path="${parent.path || '/'}"> with exact path` }`
+ );
+
+ const type = options.fallback ? 'fallbacks' : 'childs';
+
+ const route = {
+ un:null,
+ exact: false,
+ pattern: '',
+ params: {},
+ parent,
+ fallback: options.fallback,
+ redirect: options.redirect,
+ childs: new Set(),
+ activeChilds: new Set(),
+ fallbacks: new Set(),
+ makePattern(path){
+ route.exact = !path.endsWith('/*');
+ route.pattern = formatPath(`${route.parent && route.parent.pattern || ''}${path}`)
+ },
+ register: () => {
+ if(!route.parent) return;
+ route.parent[type].add(route);
+ return ()=>{
+ route.parent[type].delete(route);
+ route.un && route.un();
+ }
+ },
+ show: ()=>{
+ options.onShow();
+ !route.fallback && route.parent && route.parent.activeChilds.add(route);
+ },
+ hide: ()=>{
+ options.onHide();
+ !route.fallback && route.parent && route.parent.activeChilds.delete(route);
+ },
+ match: async (url)=>{
+ const params = getRouteData(route.pattern,url);
+
+ if(params && route.redirect && (!route.exact || (route.exact && params.exact))){
+ return router.goto(makeRedirectURL(url,route.parent.pattern,route.redirect));
+ }
+
+ if(!route.fallback && params && (!route.exact || (route.exact && params.exact))){
+ options.onParams(route.params = params.params);
+ route.show();
+ }else{
+ route.hide();
+ }
+
+ await tick();
+
+ if(
+ !route.fallback && params &&
+ (
+ (route.childs.size > 0 && route.activeChilds.size == 0) ||
+ (route.childs.size == 0 && route.fallbacks.size > 0)
+ )
+ ){
+ let obj = route;
+ while(obj.fallbacks.size == 0){
+ obj = obj.parent;
+ if(!obj) return;
+ }
+ obj && obj.fallbacks.forEach(fb => fb.show());
+ }
+ }
+ }
+
+ route.makePattern(options.path);
+
+ setContext('tinro',route);
+ onMount(()=>route.register());
+
+ route.un = router.subscribe(r => {
+ route.match(r.path);
+ });
+
+ return route;
+}
+
+
+export function formatPath(path,slash=false){
+ path = path.slice(
+ path.startsWith('/#') ? 2 : 0,
+ path.endsWith('/*') ? -2 : undefined
+ )
+ if(!path.startsWith('/')) path = '/'+path;
+ if(path==='/') path = '';
+ if(slash && !path.endsWith('/')) path += '/';
+ return path;
+}
+
+export function getRouteData(pattern,path){
+ pattern = formatPath(pattern,true);
+ path = formatPath(path,true);
+
+ const keys = [];
+ let params = {};
+ let exact = true;
+ let rx = pattern
+ .split('/')
+ .map(s => s.startsWith(':') ? (keys.push(s.slice(1)),'([^\\/]+)') : s)
+ .join('\\/');
+
+ let match = path.match(new RegExp(`^${rx}$`));
+ if(!match) {
+ exact = false;
+ match = path.match(new RegExp(`^${rx}`));
+ }
+ if(!match) return null;
+ keys.forEach((key,i) => params[key] = match[i+1]);
+
+ return {exact,params};
+}
+
+export function makeRedirectURL(path,parent_pattern,slug){
+ if(slug === '') return path;
+ if(slug[0] === '/') return slug;
+ const getParts = url => url.split('/').filter(p=>p!=='');
+
+ const pathParts = getParts(path);
+ const patternParts = getParts(parent_pattern);
+
+ return '/'+patternParts.map((_,i)=>pathParts[i]).join('/')+'/'+slug;
+}
+
+export function getAttr(node,attr,rm,def){
+ const re = [attr,'data-'+attr].reduce(
+ (r,c) => {
+ const a = node.getAttribute(c);
+ if(rm) node.removeAttribute(c);
+ return a === null ? r: a;
+ },
+ false );
+ return !def && re === '' ? true : re ? re : def ? def : false;
+}
+
+export function parseQuery(str){
+ const o= str.split('&')
+ .map(p => p.split('='))
+ .reduce((r,p) => {
+ const name = p[0];
+ if(!name) return r;
+ let value = p.length > 1 ? p[p.length-1] : true;
+ if(typeof value === 'string' && value.includes(',')) value = value.split(',');
+ (r[name] === undefined) ? r[name]=[value] : r[name].push(value);
+ return r;
+ },{});
+
+ return Object.entries(o).reduce((r,p)=>(r[p[0]]=p[1].length>1 ? p[1] : p[1][0],r),{});
+}
+
+function err(text){
+ throw new Error(text);
+}
\ No newline at end of file
diff --git a/node_modules/tinro/src/router.js b/node_modules/tinro/src/router.js
new file mode 100644
index 0000000..ec437b3
--- /dev/null
+++ b/node_modules/tinro/src/router.js
@@ -0,0 +1,81 @@
+import {getContext} from 'svelte';
+import {writable} from 'svelte/store';
+import {getAttr,parseQuery,getRouteData} from './lib';
+
+export const router = routerStore();
+
+export function active(node){
+ const href = getAttr(node,'href'),
+ exact = getAttr(node,'exact',true),
+ cl = getAttr(node,'active-class',true,'active');
+
+ return {destroy:router.subscribe(r => {
+ const data = getRouteData(href,r.path);
+ data && (data.exact && exact || !exact) ? node.classList.add(cl) : node.classList.remove(cl);
+ })}
+}
+
+function routerStore(){
+ let hsh = window.location.pathname === 'srcdoc';
+
+ const go = (href,set) => {
+ hsh ? window.location.hash=href : history.pushState({}, '', href);
+ set(getLocation(hsh));
+ }
+
+ const {subscribe,set} = writable(getLocation(hsh), _ => {
+ window.hashchange = window.onpopstate = _ => set(getLocation(hsh));
+ const un = aClickListener(href=>go(href,set));
+ return _ => {
+ window.hashchange = window.onpopstate = null;
+ un();
+ }
+ });
+
+ return {
+ subscribe,
+ goto: href => go(href,set),
+ params: getParams,
+ useHashNavigation: s => set(getLocation(hsh = s===undefined ? true : s))
+ }
+}
+
+function getLocation(hsh){
+ return hsh ? getLocationFromHash() : {
+ path: window.location.pathname,
+ query: parseQuery(window.location.search.slice(1)),
+ hash: window.location.hash.slice(1)
+ }
+}
+
+function getLocationFromHash(){
+ const match = String(window.location.hash.slice(1)||'/').match(/^([^?#]+)(?:\?([^#]+))?(?:\#(.+))?$/);
+ return {
+ path: match[1] || '',
+ query: parseQuery(match[2] || ''),
+ hash: match[3] || '',
+ };
+ }
+
+function aClickListener(go){
+ const h = e => {
+ const a = e.target.closest('a[href]');
+ const i = a && getAttr(a,'tinro-ignore');
+
+ if(!i && a){
+ const href = a.getAttribute('href').replace(/^\/#/,'');
+
+ if(!/^\/\/|^[a-zA-Z]+:/.test(href)) {
+ e.preventDefault();
+ go(href.startsWith('/') ? href : a.href.replace(window.location.origin,''));
+ }
+ }
+ }
+
+ addEventListener('click', h);
+ return () => removeEventListener('click', h);
+}
+
+function getParams(){
+ return getContext('tinro').params;
+}
diff --git a/node_modules/tinro/src/tinro.js b/node_modules/tinro/src/tinro.js
new file mode 100644
index 0000000..d840858
--- /dev/null
+++ b/node_modules/tinro/src/tinro.js
@@ -0,0 +1,5 @@
+import {router,active} from './router.js';
+import {createRouteObject} from './lib.js';
+//import {routes,registerRouteObject} from './routes.js';
+
+export {router,active,createRouteObject};
\ No newline at end of file
@AlexxNB this issue seems to be resolved with the latest update (0.5.3).
I moved bundling from Rollup to ESBuild. I think it is why module working great now.
I'm using Testing Library which uses Jest to simulate the browser experience. Below is example of how I am testing routes.
The following error happens when i navigate to another page:
TypeError: Cannot read property 'c' of undefined
.Node provides some additional information: "UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch()."
The call stack:
Any idea what is going on?