@real-router/navigation-plugin 0.7.5 → 0.7.6

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.
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@real-router/core/api`),t=require(`@real-router/core`);const n=()=>globalThis.window!==void 0&&!!globalThis.history;function r(e){if(!e)return e;let t=e.replaceAll(/\/+/g,`/`);return t.startsWith(`/`)||(t=`/${t}`),t.length>1&&t.endsWith(`/`)&&(t=t.slice(0,-1)),t===`/`?``:t}const i=e=>{try{return encodeURI(decodeURI(e))}catch(t){return console.warn(`[browser-env] Could not encode path "${e}"`,t),e}},a=e=>{let t=!1;return n=>{t||=(console.warn(`[browser-env] Browser API is running in a non-browser environment (context: "${e}"). Method "${n}" is a no-op. This is expected for SSR, but may indicate misconfiguration if you expected browser behavior.`),!0)}};function o(e,t,n){return r=>{if(r)for(let i of Object.keys(r)){if(!(i in e))continue;let a=r[i];if(a===void 0)continue;let o=typeof e[i],s=typeof a;if(s!==o)throw Error(`[${t}] Invalid type for '${i}': expected ${o}, got ${s}`);let c=n?.[i];if(c){let e=c.validate(a);if(e!==null)throw Error(`[${t}] Invalid '${i}': ${e}`)}}}}const s=/[\u0000-\u001F\u007F]/,c={validate:e=>s.test(e)?`must not contain control characters`:e.split(`/`).includes(`..`)?`must not contain '..' segments`:null};function l(e){return encodeURI(e).replaceAll(`#`,`%23`)}function u(e){try{return decodeURIComponent(e)}catch{return e}}function d(e){let t=e;for(;t.startsWith(`#`);)t=t.slice(1);return u(t)}function f(e){let t=e.getHash();return t?u(t.startsWith(`#`)?t.slice(1):t):``}function p(e){let t=e,n=t.indexOf(`://`);if(n!==-1){let e=n+3,r=t.length;for(let n=e;n<t.length;n++){let e=t[n];if(e===`/`||e===`?`||e===`#`){r=n;break}}t=r===t.length?`/`:t.slice(r),(t.startsWith(`?`)||t.startsWith(`#`))&&(t=`/${t}`)}let r=t.indexOf(`#`),i=r===-1?``:t.slice(r),a=r===-1?t:t.slice(0,r),o=a.indexOf(`?`),s=o===-1?``:a.slice(o);return{pathname:o===-1?a:a.slice(0,o),search:s,hash:i}}function m(e,t){if(!e)return`/`;if(t&&(e===t||e.startsWith(`${t}/`))){let n=e.slice(t.length);return n.startsWith(`/`)?n:`/${n}`}return e.startsWith(`/`)?e:`/${e}`}function h(e,t){return e?t?e===`/`?t:e.startsWith(`/`)?`${t}${e}`:`${t}/${e}`:e.startsWith(`/`)?e:`/${e}`:t}function g(e,t){let n=p(e);return m(n.pathname,t)+n.search}function _(e,t){let n=p(e);return{path:m(n.pathname,t)+n.search,hash:n.hash?u(n.hash.slice(1)):``}}function v(e,t){return g(e,t)}function y(e,t){return e.addInterceptor(`start`,(e,n)=>e(n??t.getLocation()))}function b(e,t){return(n,r,i)=>{let a=h(e.buildPath(n,r),t);if(i?.hash===void 0)return a;let o=d(i.hash);return o?`${a}#${l(o)}`:a}}function x(e,t,n,r,i=!0){let a={name:``,params:{},path:``};return(o,s={},c)=>{let u=e.buildState(o,s);if(!u)throw Error(`[real-router] Cannot replace state: route "${o}" is not found`);let f=e.makeState(u.name,u.params,t.buildPath(u.name,u.params),{params:u.meta}),p;if(c?.hash!==void 0){let e=d(c.hash);p=e?`#${l(e)}`:``}else p=i?n.getHash():``;let m=r(o,s)+p;a.name=f.name,a.params=f.params,a.path=f.path,n.replaceState(a,m)}}function S(e,t,n){return e.replace===!0?!0:n?!!e.reload&&t.path===n.path:e.replace!==!1}const C={forceDeactivate:!1,base:``},w=`@real-router/navigation-plugin:syncing`,T=Object.freeze({info:w});function E(e){let t=globalThis.navigation;return{getLocation:()=>i(m(globalThis.location.pathname,e))+globalThis.location.search,getHash:()=>globalThis.location.hash,navigate:(e,n)=>{t.navigate(e,{...n,info:w})},replaceState:(e,n)=>{t.navigate(n,{state:e,history:`replace`,info:w})},updateCurrentEntry:e=>{t.updateCurrentEntry(e)},traverseTo:e=>{t.traverseTo(e,T)},addNavigateListener:e=>(t.addEventListener(`navigate`,e),()=>{t.removeEventListener(`navigate`,e)}),entries:()=>t.entries(),get currentEntry(){return t.currentEntry},getActivationType:()=>t.activation?.navigationType}}function D(e,t,n,r){if(!e)throw Error(`No history entry for route "${t}"`);let i=e.url;if(!i)throw Error(`No matching route for entry URL "${i}"`);let a=v(i,r),o=n.matchPath(a);if(!o)throw Error(`No matching route for entry URL "${i}"`);return{entry:e,entryUrl:i,matchedState:o}}function O(e,t,n){if(e?.url)return t.matchPath(v(e.url,n))??void 0}function k(e,t,n,r){let i=e.currentEntry?.index;if(i!=null)return O(e.entries()[i+r],t,n)}function A(e,t,n){return k(e,t,n,-1)}function j(e,t,n){return k(e,t,n,1)}function M(e,t,n,r){return e.entries().some(e=>O(e,t,n)?.name===r)}function N(e,t,n){let r=new Set;for(let i of e.entries()){let e=O(i,t,n);e&&r.add(e.name)}return[...r]}function P(e,t,n,r){let i=0;for(let a of e.entries())O(a,t,n)?.name===r&&i++;return i}function F(e,t,n,r,i){for(let a=e.length-1;a>=0;a--){let o=e[a];if(o.key!==i&&O(o,n,r)?.name===t)return o}}function I(e){let t=e.currentEntry?.index;return t!=null&&t>0}function L(e){let t=e.currentEntry?.index;return t==null?!1:t<e.entries().length-1}function R(e,t,n,r){let i=e.currentEntry?.index;if(i==null)return!1;let a=e.entries();for(let e=i-1;e>=0;e--)if(O(a[e],t,n)?.name===r)return!0;return!1}function z(e,t){if(!t)return!1;try{let n=new URL(e,t),r=new URL(t);return n.protocol===r.protocol&&n.host===r.host&&(n.pathname||`/`)===(r.pathname||`/`)&&n.search===r.search&&n.hash===r.hash}catch{return!1}}const B={handler:async()=>{},scroll:`manual`};function V(e,t,n){return e===`traverse`?t===n?`unknown`:t>n?`forward`:`back`:e===`push`?`forward`:`unknown`}function H(e){let{router:n,api:r,browser:i,base:a,transitionOptions:o}=e,{allowNotFound:s}=r.getOptions();return function(c){if(!c.canIntercept||!n.isActive())return;if(c.info===`@real-router/navigation-plugin:syncing`){c.intercept(B);return}let{path:l,hash:u}=_(c.destination.url,a),d=r.matchPath(l),f=c.navigationType,p=i.currentEntry?.index??-1;e.setCapturedMeta({navigationType:f,userInitiated:c.userInitiated,info:c.info,direction:V(f,c.destination.index,p),sourceElement:c.sourceElement??null}),d?c.intercept({handler:()=>U(()=>r.navigateToState(d,{...o,hash:u,...c.hashChange?{force:!0,hashChange:!0}:{},signal:c.signal}),n,i)}):s?c.intercept({handler:()=>{n.navigateToNotFound(l)}}):c.intercept({handler:async()=>{let e=new t.RouterError(t.errorCodes.ROUTE_NOT_FOUND,{path:l});throw r.emitTransitionError(e),e}})}}async function U(e,n,r){try{await e()}catch(e){if(!(e instanceof t.RouterError)){W(e,n,r);return}if(e.code===t.errorCodes.TRANSITION_CANCELLED||e.code===t.errorCodes.SAME_STATES)return;G(n,r)}}function W(e,t,n){console.error(`[navigation-plugin] Critical error in navigate handler`,e),G(t,n)}function G(e,t){try{let n=e.getState();if(n){let r=n.context?.url?.hash,i=e.buildUrl(n.name,n.params,r?{hash:r}:void 0);t.navigate(i,{state:{name:n.name,params:n.params,path:n.path},history:`replace`})}}catch(e){console.error(`[navigation-plugin] Failed to sync URL to router state`,e)}}function K(e,t,n){return e.reload&&t.path===n?.path?`reload`:S(e,t,n)?`replace`:`push`}var q=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d=``;#f={name:``,params:{},path:``};constructor(e,t,n,r,i,a){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#o=t.claimContextNamespace(`navigation`),this.#s=t.claimContextNamespace(`url`),this.#i=y(t,this.#r);let o=this.#r.getActivationType();o&&(this.#l={navigationType:o,userInitiated:!1,direction:o===`push`?`forward`:`unknown`,sourceElement:null});let s=b(e,n.base);this.#a=t.extendRouter({buildUrl:s,matchUrl:e=>t.matchPath(g(e,n.base))??void 0,replaceHistoryState:x(t,e,this.#r,s),peekBack:()=>A(this.#r,t,n.base),peekForward:()=>j(this.#r,t,n.base),hasVisited:e=>M(this.#r,t,n.base,e),getVisitedRoutes:()=>N(this.#r,t,n.base),getRouteVisitCount:e=>P(this.#r,t,n.base,e),traverseToLast:e=>this.traverseToLast(e),canGoBack:()=>I(this.#r),canGoForward:()=>L(this.#r),canGoBackTo:e=>R(this.#r,t,n.base,e)});let c=H({router:e,api:t,browser:this.#r,setCapturedMeta:e=>{this.#l=e},base:n.base,transitionOptions:i});this.#c=X({browser:this.#r,shared:a,handler:c,removeStartInterceptor:this.#i,removeExtensions:this.#a,releaseClaim:()=>{this.#o.release(),this.#s.release()}})}async traverseToLast(e){let t=this.#r.entries(),n=this.#r.currentEntry?.key,{entry:r,entryUrl:i,matchedState:a}=D(F(t,e,this.#t,this.#n.base,n),e,this.#t,this.#n.base),o=this.#r.currentEntry;if(!o)throw Error(`[navigation-plugin] Cannot determine direction for traverseToLast("${e}"): browser.currentEntry is null. The plugin must be started before calling traverseToLast.`);return this.#l={navigationType:`traverse`,userInitiated:!1,direction:r.index>o.index?`forward`:`back`,sourceElement:null},this.#u=r.key,this.#d=Y(i),this.#e.navigate(a.name,a.params)}getPlugin(){return{...this.#c,onTransitionStart:e=>{this.#l&&this.#o.write(e,this.#l)},onTransitionSuccess:(e,n,r)=>{if(!this.#l){let t=K(r,e,n);this.#l={navigationType:t,userInitiated:!1,direction:t===`push`?`forward`:`unknown`,sourceElement:null}}let i=Object.freeze(this.#l);this.#o.write(e,i),this.#l=void 0;let a=this.#u,o=this.#d;this.#u=void 0,this.#d=``;let s=J(n);if(a)this.#s.write(e,Object.freeze({hash:o,hashChanged:o!==s})),this.#r.traverseTo(a);else{let a=f(this.#r),o=r.hash===void 0?a:d(r.hash);this.#s.write(e,Object.freeze({hash:o,hashChanged:r.hashChange??o!==s}));let c=h(e.path,this.#n.base),u=o?`${c}#${l(o)}`:c;if(this.#f.name=e.name,this.#f.params=e.params,this.#f.path=e.path,e.name===t.UNKNOWN_ROUTE||z(u,this.#r.currentEntry?.url))this.#r.updateCurrentEntry({state:this.#f});else{let e=n===void 0,t=i.navigationType!==`push`||e;this.#r.navigate(u,{state:this.#f,history:t?`replace`:`push`})}}},onTransitionCancel:()=>{this.#l=void 0,this.#u=void 0,this.#d=``},onTransitionError:()=>{this.#l=void 0,this.#u=void 0,this.#d=``}}}};function J(e){return(e?.context)?.url?.hash??``}function Y(e){let t=p(e).hash;return t?u(t.slice(1)):``}function X(e){return{onStart(){e.shared.removeNavigateListener?.(),e.shared.removeNavigateListener=e.browser.addNavigateListener(e.handler)},onStop(){e.shared.removeNavigateListener?.(),e.shared.removeNavigateListener=void 0},teardown(){e.shared.removeNavigateListener?.(),e.shared.removeNavigateListener=void 0,e.removeStartInterceptor(),e.removeExtensions(),e.releaseClaim()}}}const Z=()=>{},Q=e=>{let t=a(e);return{getLocation:()=>(t(`getLocation`),`/`),getHash:()=>(t(`getHash`),``),navigate:()=>{t(`navigate`)},replaceState:()=>{t(`replaceState`)},updateCurrentEntry:()=>{t(`updateCurrentEntry`)},traverseTo:()=>{t(`traverseTo`)},addNavigateListener:()=>(t(`addNavigateListener`),Z),entries:()=>(t(`entries`),[]),currentEntry:null,getActivationType:()=>void 0}},$=o(C,`navigation-plugin`,{base:c});function ee(t,i){if(!i&&n()&&!(`navigation`in globalThis))throw Error(`[navigation-plugin] Navigation API is not supported. Use @real-router/browser-plugin instead.`);$(t);let a={...C,...t};a.base=r(a.base);let o=i??te(a.base),s={forceDeactivate:a.forceDeactivate,source:`navigate`,replace:!0},c={removeNavigateListener:void 0};return t=>new q(t,(0,e.getPluginApi)(t),a,o,s,c).getPlugin()}function te(e){return`navigation`in globalThis?E(e):Q(`navigation-plugin`)}exports.PLUGIN_SYNC_INFO=w,exports.navigationPluginFactory=ee;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@real-router/core/api"),t=require("@real-router/core");const n=()=>globalThis.window!==void 0&&!!globalThis.history;function r(e){if(!e)return e;let t=e.replaceAll(/\/+/g,`/`);return t.startsWith(`/`)||(t=`/${t}`),t.length>1&&t.endsWith(`/`)&&(t=t.slice(0,-1)),t===`/`?``:t}const i=e=>{try{return encodeURI(decodeURI(e))}catch(t){return console.warn(`[browser-env] Could not encode path "${e}"`,t),e}},a=e=>{let t=!1;return n=>{t||=(console.warn(`[browser-env] Browser API is running in a non-browser environment (context: "${e}"). Method "${n}" is a no-op. This is expected for SSR, but may indicate misconfiguration if you expected browser behavior.`),!0)}};function o(e,t,n){return r=>{if(r)for(let i of Object.keys(r)){if(!(i in e))continue;let a=r[i];if(a===void 0)continue;let o=typeof e[i],s=typeof a;if(s!==o)throw Error(`[${t}] Invalid type for '${i}': expected ${o}, got ${s}`);let c=n?.[i];if(c){let e=c.validate(a);if(e!==null)throw Error(`[${t}] Invalid '${i}': ${e}`)}}}}const s=/[\u0000-\u001F\u007F]/,c={validate:e=>s.test(e)?`must not contain control characters`:e.split(`/`).includes(`..`)?`must not contain '..' segments`:null};function l(e){return encodeURI(e).replaceAll(`#`,`%23`)}function u(e){try{return decodeURIComponent(e)}catch{return e}}function d(e){let t=e;for(;t.startsWith(`#`);)t=t.slice(1);return u(t)}function f(e){let t=e.getHash();return t?u(t.startsWith(`#`)?t.slice(1):t):``}function p(e){let t=e,n=t.indexOf(`://`);if(n!==-1){let e=n+3,r=t.length;for(let n=e;n<t.length;n++){let e=t[n];if(e===`/`||e===`?`||e===`#`){r=n;break}}t=r===t.length?`/`:t.slice(r),(t.startsWith(`?`)||t.startsWith(`#`))&&(t=`/${t}`)}let r=t.indexOf(`#`),i=r===-1?``:t.slice(r),a=r===-1?t:t.slice(0,r),o=a.indexOf(`?`),s=o===-1?``:a.slice(o);return{pathname:o===-1?a:a.slice(0,o),search:s,hash:i}}function m(e,t){if(!e)return`/`;if(t&&(e===t||e.startsWith(`${t}/`))){let n=e.slice(t.length);return n.startsWith(`/`)?n:`/${n}`}return e.startsWith(`/`)?e:`/${e}`}function h(e,t){return e?t?e===`/`?t:e.startsWith(`/`)?`${t}${e}`:`${t}/${e}`:e.startsWith(`/`)?e:`/${e}`:t}function g(e,t){let n=p(e);return m(n.pathname,t)+n.search}function _(e,t){let n=p(e);return{path:m(n.pathname,t)+n.search,hash:n.hash?u(n.hash.slice(1)):``}}function v(e,t){return g(e,t)}function y(e,t){return e.addInterceptor(`start`,(e,n)=>e(n??t.getLocation()))}function b(e,t){return(n,r,i)=>{let a=h(e.buildPath(n,r),t);if(i?.hash===void 0)return a;let o=d(i.hash);return o?`${a}#${l(o)}`:a}}function x(e,t,n,r,i=!0){let a={name:``,params:{},path:``};return(o,s={},c)=>{let u=e.buildState(o,s);if(!u)throw Error(`[real-router] Cannot replace state: route "${o}" is not found`);let f=e.makeState(u.name,u.params,t.buildPath(u.name,u.params),{params:u.meta}),p;if(c?.hash!==void 0){let e=d(c.hash);p=e?`#${l(e)}`:``}else p=i?n.getHash():``;let m=r(o,s)+p;a.name=f.name,a.params=f.params,a.path=f.path,n.replaceState(a,m)}}function S(e,t,n){return e.replace===!0?!0:n?!!e.reload&&t.path===n.path:e.replace!==!1}const C={forceDeactivate:!1,base:``},w=`@real-router/navigation-plugin:syncing`,T=Object.freeze({info:w});function E(e){let t=globalThis.navigation;return{getLocation:()=>i(m(globalThis.location.pathname,e))+globalThis.location.search,getHash:()=>globalThis.location.hash,navigate:(e,n)=>{t.navigate(e,{...n,info:w})},replaceState:(e,n)=>{t.navigate(n,{state:e,history:`replace`,info:w})},updateCurrentEntry:e=>{t.updateCurrentEntry(e)},traverseTo:e=>{t.traverseTo(e,T)},addNavigateListener:e=>(t.addEventListener(`navigate`,e),()=>{t.removeEventListener(`navigate`,e)}),entries:()=>t.entries(),get currentEntry(){return t.currentEntry},getActivationType:()=>t.activation?.navigationType}}function D(e,t,n,r){if(!e)throw Error(`No history entry for route "${t}"`);let i=e.url;if(!i)throw Error(`No matching route for entry URL "${i}"`);let a=v(i,r),o=n.matchPath(a);if(!o)throw Error(`No matching route for entry URL "${i}"`);return{entry:e,entryUrl:i,matchedState:o}}function O(e,t,n){if(e?.url)return t.matchPath(v(e.url,n))??void 0}function k(e,t,n,r){let i=e.currentEntry?.index;if(i!=null)return O(e.entries()[i+r],t,n)}function A(e,t,n){return k(e,t,n,-1)}function j(e,t,n){return k(e,t,n,1)}function M(e,t,n,r){return e.entries().some(e=>O(e,t,n)?.name===r)}function N(e,t,n){let r=new Set;for(let i of e.entries()){let e=O(i,t,n);e&&r.add(e.name)}return[...r]}function P(e,t,n,r){let i=0;for(let a of e.entries())O(a,t,n)?.name===r&&i++;return i}function F(e,t,n,r,i){for(let a=e.length-1;a>=0;a--){let o=e[a];if(o.key!==i&&O(o,n,r)?.name===t)return o}}function I(e){let t=e.currentEntry?.index;return t!=null&&t>0}function L(e){let t=e.currentEntry?.index;return t==null?!1:t<e.entries().length-1}function R(e,t,n,r){let i=e.currentEntry?.index;if(i==null)return!1;let a=e.entries();for(let e=i-1;e>=0;e--)if(O(a[e],t,n)?.name===r)return!0;return!1}function z(e,t){if(!t)return!1;try{let n=new URL(e,t),r=new URL(t);return n.protocol===r.protocol&&n.host===r.host&&(n.pathname||`/`)===(r.pathname||`/`)&&n.search===r.search&&n.hash===r.hash}catch{return!1}}const B={handler:async()=>{},scroll:`manual`};function V(e,t,n){return e===`traverse`?t===n?`unknown`:t>n?`forward`:`back`:e===`push`?`forward`:`unknown`}function H(e){let{router:n,api:r,browser:i,base:a,transitionOptions:o}=e,{allowNotFound:s}=r.getOptions();return function(c){if(!c.canIntercept||!n.isActive())return;if(c.info===`@real-router/navigation-plugin:syncing`){c.intercept(B);return}let{path:l,hash:u}=_(c.destination.url,a),d=r.matchPath(l),f=c.navigationType,p=i.currentEntry?.index??-1;e.setCapturedMeta({navigationType:f,userInitiated:c.userInitiated,info:c.info,direction:V(f,c.destination.index,p),sourceElement:c.sourceElement??null}),d?c.intercept({handler:()=>U(()=>r.navigateToState(d,{...o,hash:u,...c.hashChange?{force:!0,hashChange:!0}:{},signal:c.signal}),n,i)}):s?c.intercept({handler:()=>{n.navigateToNotFound(l)}}):c.intercept({handler:async()=>{let e=new t.RouterError(t.errorCodes.ROUTE_NOT_FOUND,{path:l});throw r.emitTransitionError(e),e}})}}async function U(e,n,r){try{await e()}catch(e){if(!(e instanceof t.RouterError)){W(e,n,r);return}if(e.code===t.errorCodes.TRANSITION_CANCELLED||e.code===t.errorCodes.SAME_STATES)return;G(n,r)}}function W(e,t,n){console.error(`[navigation-plugin] Critical error in navigate handler`,e),G(t,n)}function G(e,t){try{let n=e.getState();if(n){let r=n.context?.url?.hash,i=e.buildUrl(n.name,n.params,r?{hash:r}:void 0);t.navigate(i,{state:{name:n.name,params:n.params,path:n.path},history:`replace`})}}catch(e){console.error(`[navigation-plugin] Failed to sync URL to router state`,e)}}function K(e,t,n){return e.reload&&t.path===n?.path?`reload`:S(e,t,n)?`replace`:`push`}var q=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d=``;#f={name:``,params:{},path:``};constructor(e,t,n,r,i,a){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#o=t.claimContextNamespace(`navigation`),this.#s=t.claimContextNamespace(`url`),this.#i=y(t,this.#r);let o=this.#r.getActivationType();o&&(this.#l={navigationType:o,userInitiated:!1,direction:o===`push`?`forward`:`unknown`,sourceElement:null});let s=b(e,n.base);this.#a=t.extendRouter({buildUrl:s,matchUrl:e=>t.matchPath(g(e,n.base))??void 0,replaceHistoryState:x(t,e,this.#r,s),peekBack:()=>A(this.#r,t,n.base),peekForward:()=>j(this.#r,t,n.base),hasVisited:e=>M(this.#r,t,n.base,e),getVisitedRoutes:()=>N(this.#r,t,n.base),getRouteVisitCount:e=>P(this.#r,t,n.base,e),traverseToLast:e=>this.traverseToLast(e),canGoBack:()=>I(this.#r),canGoForward:()=>L(this.#r),canGoBackTo:e=>R(this.#r,t,n.base,e)});let c=H({router:e,api:t,browser:this.#r,setCapturedMeta:e=>{this.#l=e},base:n.base,transitionOptions:i});this.#c=X({browser:this.#r,shared:a,handler:c,removeStartInterceptor:this.#i,removeExtensions:this.#a,releaseClaim:()=>{this.#o.release(),this.#s.release()}})}async traverseToLast(e){let t=this.#r.entries(),n=this.#r.currentEntry?.key,{entry:r,entryUrl:i,matchedState:a}=D(F(t,e,this.#t,this.#n.base,n),e,this.#t,this.#n.base),o=this.#r.currentEntry;if(!o)throw Error(`[navigation-plugin] Cannot determine direction for traverseToLast("${e}"): browser.currentEntry is null. The plugin must be started before calling traverseToLast.`);return this.#l={navigationType:`traverse`,userInitiated:!1,direction:r.index>o.index?`forward`:`back`,sourceElement:null},this.#u=r.key,this.#d=Y(i),this.#e.navigate(a.name,a.params)}getPlugin(){return{...this.#c,onTransitionStart:e=>{this.#l&&this.#o.write(e,this.#l)},onTransitionSuccess:(e,n,r)=>{if(!this.#l){let t=K(r,e,n);this.#l={navigationType:t,userInitiated:!1,direction:t===`push`?`forward`:`unknown`,sourceElement:null}}let i=Object.freeze(this.#l);this.#o.write(e,i),this.#l=void 0;let a=this.#u,o=this.#d;this.#u=void 0,this.#d=``;let s=J(n);if(a)this.#s.write(e,Object.freeze({hash:o,hashChanged:o!==s})),this.#r.traverseTo(a);else{let a=f(this.#r),o=r.hash===void 0?a:d(r.hash);this.#s.write(e,Object.freeze({hash:o,hashChanged:r.hashChange??o!==s}));let c=h(e.path,this.#n.base),u=o?`${c}#${l(o)}`:c;if(this.#f.name=e.name,this.#f.params=e.params,this.#f.path=e.path,e.name===t.UNKNOWN_ROUTE||z(u,this.#r.currentEntry?.url))this.#r.updateCurrentEntry({state:this.#f});else{let e=n===void 0,t=i.navigationType!==`push`||e;this.#r.navigate(u,{state:this.#f,history:t?`replace`:`push`})}}},onTransitionCancel:()=>{this.#l=void 0,this.#u=void 0,this.#d=``},onTransitionError:()=>{this.#l=void 0,this.#u=void 0,this.#d=``}}}};function J(e){return(e?.context)?.url?.hash??``}function Y(e){let t=p(e).hash;return t?u(t.slice(1)):``}function X(e){return{onStart(){e.shared.removeNavigateListener?.(),e.shared.removeNavigateListener=e.browser.addNavigateListener(e.handler)},onStop(){e.shared.removeNavigateListener?.(),e.shared.removeNavigateListener=void 0},teardown(){e.shared.removeNavigateListener?.(),e.shared.removeNavigateListener=void 0,e.removeStartInterceptor(),e.removeExtensions(),e.releaseClaim()}}}const Z=()=>{},Q=e=>{let t=a(e);return{getLocation:()=>(t(`getLocation`),`/`),getHash:()=>(t(`getHash`),``),navigate:()=>{t(`navigate`)},replaceState:()=>{t(`replaceState`)},updateCurrentEntry:()=>{t(`updateCurrentEntry`)},traverseTo:()=>{t(`traverseTo`)},addNavigateListener:()=>(t(`addNavigateListener`),Z),entries:()=>(t(`entries`),[]),currentEntry:null,getActivationType:()=>void 0}},$=o(C,`navigation-plugin`,{base:c});function ee(t,i){if(!i&&n()&&!(`navigation`in globalThis))throw Error(`[navigation-plugin] Navigation API is not supported. Use @real-router/browser-plugin instead.`);$(t);let a={...C,...t};a.base=r(a.base);let o=i??te(a.base),s={forceDeactivate:a.forceDeactivate,source:`navigate`,replace:!0},c={removeNavigateListener:void 0};return t=>new q(t,(0,e.getPluginApi)(t),a,o,s,c).getPlugin()}function te(e){return`navigation`in globalThis?E(e):Q(`navigation-plugin`)}exports.PLUGIN_SYNC_INFO=w,exports.navigationPluginFactory=ee;
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/navigation-plugin",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
4
4
  "type": "commonjs",
5
5
  "description": "Navigation API integration plugin for browser URL synchronization",
6
6
  "main": "./dist/cjs/index.js",
@@ -44,11 +44,11 @@
44
44
  },
45
45
  "sideEffects": false,
46
46
  "dependencies": {
47
- "@real-router/core": "^0.54.6",
47
+ "@real-router/core": "^0.55.0",
48
48
  "@real-router/types": "^0.35.0"
49
49
  },
50
50
  "devDependencies": {
51
- "jsdom": "28.1.0",
51
+ "jsdom": "29.1.1",
52
52
  "type-guards": "^0.4.9"
53
53
  },
54
54
  "scripts": {