UNPKG

0x1

Version:

0x1: Lightning-fast web framework for JavaScript/TypeScript with zero overhead and maximum performance, powered by Bun

64 lines (63 loc) 22.7 kB
import { jsx, jsxs, jsxDEV, Fragment, createElement } from "/0x1/jsx-runtime.js"; class h{routes=[];currentPath="/";listeners=[];middleware=[];isServer=typeof window==="undefined";options;scrollPositions=new Map;isBackForward=!1;layoutCache={};constructor(e={}){if(this.options={mode:"history",debug:!1,base:"",scrollBehavior:"auto",scrollToTop:!0,...e},!this.isServer)this.initializeHookSystem(),window.addEventListener("popstate",(r)=>{this.saveScrollPosition(this.currentPath),this.isBackForward=!0,this.navigate(window.location.pathname,!1)}),window.__0x1_router=this,this.currentPath=window.location.pathname}initializeHookSystem(){if(typeof window==="undefined")return;if(window.__0x1_real_hooks_loaded){console.log("[0x1 Router] Real hooks system detected - using real hooks instead of minimal fallback");return}if(!window.__0x1_hooks)window.__0x1_hooks={currentComponent:null,stateIndex:0,states:new Map,isRenderingComponent:!1,componentStack:[]};if(typeof window.__0x1_enterComponentContext!=="function")console.log("[0x1 Router] Setting up minimal hook fallbacks (real hooks not detected)"),window.__0x1_enterComponentContext=(e)=>{let r=window.__0x1_hooks;if(r)r.componentStack=r.componentStack||[],r.componentStack.push(r.currentComponent),r.currentComponent=e,r.stateIndex=0,r.isRenderingComponent=!0};if(typeof window.__0x1_exitComponentContext!=="function")window.__0x1_exitComponentContext=()=>{let e=window.__0x1_hooks;if(e)e.componentStack=e.componentStack||[],e.currentComponent=e.componentStack.pop()||null,e.isRenderingComponent=!1};if(typeof window.__0x1_triggerUpdate!=="function")window.__0x1_triggerUpdate=(e)=>{if(e){let r=document.querySelector(`[data-component-id="${e}"]`);if(r&&r.getAttribute("data-update-callback")){let o=r.__updateCallback;if(typeof o==="function")o()}}}}init(){if(this.isServer)return;document.addEventListener("click",(e)=>{let r=e.target.closest("a[href]");if(!r)return;let o=r.getAttribute("href");if(!o)return;if(o.startsWith("http")||o.startsWith("mailto:")||o.startsWith("tel:"))return;if(r.target&&r.target!=="_self")return;if(e.ctrlKey||e.metaKey||e.shiftKey)return;e.preventDefault(),this.navigate(o,!0)}),window.addEventListener("popstate",()=>{let e=new URLSearchParams(location.search)})}addRoute(e,r,o){if(typeof e==="string"){let n={path:e,component:r,exact:o?.exact!==!1,meta:o?.layout?{layout:o.layout}:{}};this.routes.push(n)}else this.routes.push(e)}async navigate(e,r=!0,o){if(this.isServer)return;if(r)this.saveScrollPosition(this.currentPath);if(r&&e!==this.currentPath)window.history.pushState({},"",e);let n=this.currentPath;this.currentPath=e,await this.executeMiddleware(e),await this.renderCurrentRoute(),this.handleScrollBehavior(e,n,o),this.isBackForward=!1,this.listeners.forEach(async(t)=>{try{await t()}catch(i){console.error("[0x1 Router] Error in route change listener:",i)}})}saveScrollPosition(e){if(this.isServer)return;this.scrollPositions.set(e,{x:window.scrollX||window.pageXOffset,y:window.scrollY||window.pageYOffset})}handleScrollBehavior(e,r,o){if(this.isServer)return;let[n,t]=e.split("#"),i=o||this.options.scrollBehavior||"auto";if(i==="preserve")return;if(i==="auto")if(t)this.scrollToHash(t);else if(this.isBackForward)this.restoreScrollPosition(e);else this.scrollToTop();else if(i==="top")this.scrollToTop();else if(i==="smooth")this.scrollToTop("smooth")}scrollToTop(e="auto"){if(this.isServer)return;try{window.scrollTo({top:0,left:0,behavior:e})}catch(r){window.scrollTo(0,0)}}scrollToHash(e){if(this.isServer)return;setTimeout(()=>{try{let r=document.getElementById(e)||document.querySelector(`[name="${e}"]`)||document.querySelector(`a[name="${e}"]`);if(r){if(r.scrollIntoView({behavior:"smooth",block:"start"}),!window.location.hash.includes(e))window.history.replaceState({},"",`${window.location.pathname}#${e}`)}else console.warn(`[0x1 Router] Hash target not found: #${e}`),this.scrollToTop()}catch(r){console.error("[0x1 Router] Error scrolling to hash:",r),this.scrollToTop()}},50)}restoreScrollPosition(e){if(this.isServer)return;let r=this.scrollPositions.get(e);if(r)setTimeout(()=>{try{window.scrollTo({left:r.x,top:r.y,behavior:"auto"})}catch(o){window.scrollTo(r.x,r.y)}},10);else this.scrollToTop()}async executeMiddleware(e){let r=this.matchRoute(e);if(!r)return;let o={path:e,params:r.params,query:new URLSearchParams(window?.location.search||""),meta:r.route.meta||{}},n=[...this.middleware,...r.route.middleware||[]],t=0,i=async()=>{if(t<n.length)await n[t++](o,i)};await i()}matchRoute(e){for(let r of this.routes){let o=this.pathToRegExp(r.path,r.exact),n=e.match(o.regex);if(n){let t={};return o.keys.forEach((i,a)=>{t[i]=n[a+1]||""}),{route:r,params:t}}}return null}pathToRegExp(e,r){if(!e||typeof e!=="string")return console.warn("[0x1 Router] Invalid path provided to pathToRegExp:",e),{regex:new RegExp("^/$"),keys:[]};if(e==="*")return{regex:new RegExp(".*"),keys:[]};let o=[],n=e.replace(/\//g,"/").replace(/:([^/]+)/g,(t,i)=>{return o.push(i),"([^/]+)"});if(r)n=`^${n}$`;else n=`^${n}`;return{regex:new RegExp(n),keys:o}}reRender(){if(this.isServer)return;this.renderCurrentRoute().catch((e)=>{console.error("[0x1 Router] reRender failed:",e)})}async renderCurrentRoute(){if(this.isServer)return;if(this._isRendering)return;if(this._isRendering=!0,this._currentRouteId)this[`_cancelled_${this._currentRouteId}`]=!0;let e=Math.random().toString(36).slice(2,8);this._currentRouteId=e;let r=setTimeout(()=>{if(this._isRendering)console.warn("[0x1 Router] Rendering took too long, forcing reset"),this._isRendering=!1},5000),o=this.options?.rootElement;if(!o){console.warn("[0x1 Router] No root element specified for rendering"),clearTimeout(r),this._isRendering=!1;return}let n=this.matchRoute(this.currentPath);if(n)try{let t=n.route.component,i=n.route.meta?.layout;if(i){if(this.layoutCache.layoutComponent!==i||!this.layoutCache.element||!this.layoutCache.contentSlot){this.layoutCache={};let s=null;try{s=this.jsxToDom(i({children:null}),e)}catch(c){console.error("[0x1 Router] Layout rendering failed:",c);let d=this.jsxToDom(t(n.params),e);if(d)o.innerHTML="",o.appendChild(d);clearTimeout(r),this._isRendering=!1;return}if(!s){console.error("[0x1 Router] Failed to render layout component"),clearTimeout(r),this._isRendering=!1;return}let l=s.querySelector('[data-slot="children"]')||s.querySelector("main")||s;this.layoutCache={element:s,layoutComponent:i,contentSlot:l},o.innerHTML="",o.appendChild(s)}if(!this.layoutCache.contentSlot){console.error("[0x1 Router] Content slot not found in cached layout"),clearTimeout(r),this._isRendering=!1;return}let a=null;try{let s=t(n.params);if(s&&typeof s==="object"&&typeof s.then==="function"){let l=document.getElementById("app-loading");if(l)l.classList.remove("loaded");try{let c=await s;if(a=this.jsxToDom(c,e),l)l.classList.add("loaded")}catch(c){if(console.error("[0x1 Router] Promise component failed:",c),l)l.classList.add("loaded");this.layoutCache.contentSlot.innerHTML=` <div style="padding: 20px; text-align: center; color: #ef4444;"> <div>❌ Error loading page</div> <div style="font-size: 12px; margin-top: 4px; opacity: 0.7;">${c instanceof Error?c.message:"Promise component error"}</div> </div> `,clearTimeout(r),this._isRendering=!1;return}}else a=this.jsxToDom(s,e)}catch(s){console.error("[0x1 Router] Component rendering failed:",s),this.layoutCache.contentSlot.innerHTML=` <div style="padding: 20px; text-align: center; color: #ef4444;"> <div>❌ Error loading page</div> <div style="font-size: 12px; margin-top: 4px; opacity: 0.7;">${s instanceof Error?s.message:"Component error"}</div> </div> `,clearTimeout(r),this._isRendering=!1;return}if(!a){console.error("[0x1 Router] Failed to render page component"),clearTimeout(r),this._isRendering=!1;return}this.layoutCache.contentSlot.innerHTML="",this.layoutCache.contentSlot.appendChild(a)}else{this.layoutCache={};let a=null;try{let s=t(n.params);if(s&&typeof s==="object"&&typeof s.then==="function"){let l=document.getElementById("app-loading");if(l)l.classList.remove("loaded");try{let c=await s;if(a=this.jsxToDom(c,e),l)l.classList.add("loaded")}catch(c){if(console.error("[0x1 Router] Promise component failed:",c),l)l.classList.add("loaded");o.innerHTML=` <div style="padding: 40px; text-align: center; color: #ef4444;"> <div>❌ Error loading page</div> <div style="font-size: 12px; margin-top: 4px; opacity: 0.7;">${c instanceof Error?c.message:"Promise component error"}</div> </div> `,clearTimeout(r),this._isRendering=!1;return}}else a=this.jsxToDom(s,e)}catch(s){console.error("[0x1 Router] Component rendering failed:",s),o.innerHTML=` <div style="padding: 40px; text-align: center; color: #ef4444;"> <div>❌ Error loading page</div> <div style="font-size: 12px; margin-top: 4px; opacity: 0.7;">${s instanceof Error?s.message:"Component error"}</div> </div> `,clearTimeout(r),this._isRendering=!1;return}if(!a){console.error("[0x1 Router] Failed to render component"),clearTimeout(r),this._isRendering=!1;return}if("startViewTransition"in document)document.startViewTransition(()=>{o.innerHTML="",o.appendChild(a)});else o.innerHTML="",o.appendChild(a)}}catch(t){console.error("[0x1 Router] Error rendering route:",t)}else if(console.warn(`[0x1 Router] No route found for: ${this.currentPath}`),this.layoutCache.element&&this.layoutCache.contentSlot)this.layoutCache.contentSlot.innerHTML=` <div style="padding: 40px; text-align: center; font-family: system-ui, sans-serif;"> <div style="font-size: 4rem; font-weight: bold; color: #8b5cf6; margin-bottom: 16px;">404</div> <div style="font-size: 1.5rem; font-weight: bold; margin-bottom: 8px;">Page Not Found</div> <div style="color: #6b7280; margin-bottom: 24px;">The page you're looking for doesn't exist.</div> <a href="/" style="display: inline-block; padding: 8px 16px; background: #8b5cf6; color: white; border-radius: 6px; text-decoration: none;">← Back to Home</a> </div> `;else this.layoutCache={},o.innerHTML=` <div style="display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; text-align: center; padding: 16px; font-family: system-ui, sans-serif;"> <div style="font-size: 6rem; font-weight: bold; color: #8b5cf6; margin-bottom: 16px;">404</div> <div style="font-size: 1.875rem; font-weight: bold; margin-bottom: 16px;">Page Not Found</div> <div style="color: #6b7280; margin-bottom: 32px;">The page you're looking for doesn't exist or has been moved.</div> <a href="/" onclick="event.preventDefault(); window.router?.navigate('/') || (window.location.href = '/')" style="display: inline-block; padding: 12px 24px; background: #8b5cf6; color: white; border-radius: 8px; text-decoration: none; font-weight: 500;">\uD83C\uDFE0 Back to Home</a> </div> `;clearTimeout(r),this._isRendering=!1}renderFallback404(e){console.log("[0x1 Router] \uD83C\uDFE0 Rendering fallback 404 page"),e.innerHTML="",e.appendChild(this.createFallback404Element())}createFallback404Element(){let e=document.createElement("div");return e.style.cssText=` display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; text-align: center; padding: 16px; font-family: system-ui, -apple-system, sans-serif; `,e.innerHTML=` <div style="margin-bottom: 32px;"> <h1 style="font-size: 6rem; font-weight: bold; color: #8b5cf6; margin-bottom: 16px; line-height: 1;">404</h1> </div> <div style="max-width: 28rem; margin: 0 auto;"> <h2 style="font-size: 1.875rem; font-weight: bold; color: #1f2937; margin-bottom: 16px;">Page Not Found</h2> <p style="font-size: 1.125rem; color: #6b7280; margin-bottom: 32px;">The page you're looking for doesn't exist or has been moved.</p> <div style="display: flex; flex-direction: column; gap: 16px; align-items: center;"> <a href="/" onclick="event.preventDefault(); window.router?.navigate('/') || (window.location.href = '/')" style="display: inline-block; padding: 12px 24px; background: linear-gradient(135deg, #8b5cf6, #7c3aed); color: white; border-radius: 8px; text-decoration: none; font-weight: 500; transition: all 0.2s; box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3); cursor: pointer;"> \uD83C\uDFE0 Back to Home </a> </div> </div> `,e}jsxToDom(e,r){try{if(!e)return null;if(e&&typeof e==="object"&&typeof e.then==="function"){let o=document.createElement("div");return o.innerHTML='<span style="color: #f59e0b;">⚠️ Promise JSX not resolved</span>',o}if(typeof e==="string"||typeof e==="number"){let o=document.createTextNode(String(e)),n=document.createElement("span");return n.appendChild(o),n}if(typeof e==="boolean")return null;if(Array.isArray(e)){let o=document.createDocumentFragment();e.forEach((t)=>{let i=this.jsxToDom(t,r);if(i)o.appendChild(i)});let n=document.createElement("div");return n.appendChild(o),n}if(e instanceof Node)return e;if(typeof e==="object"&&(e.type||e.__isVNode)){if(e.type===Symbol.for("react.fragment")||e.type===Symbol.for("React.Fragment")){let o=[];try{let t=e.children||e.props?.children;if(t===null||t===void 0)o=[];else if(Array.isArray(t))o=t.filter((i)=>i!==null&&i!==void 0);else o=[t]}catch(t){console.warn("[0x1 Router] Error normalizing fragment children:",t),o=[]}if(!Array.isArray(o))console.warn("[0x1 Router] Fragment children normalization failed, forcing array"),o=[];let n=document.createDocumentFragment();if(o.forEach((t)=>{let i=this.jsxToDom(t,r);if(i)n.appendChild(i)}),n.children.length===1)return n.children[0];else{let t=document.createElement("div");return t.appendChild(n),t}}else if(typeof e.type==="string"){let o=["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","use","text","tspan"].includes(e.type.toLowerCase())?document.createElementNS("http://www.w3.org/2000/svg",e.type):document.createElement(e.type);if(e.props)Object.keys(e.props).forEach((t)=>{try{if(t==="children")return;else if(t==="__self"||t==="__source"||t==="ref"||t==="key")return;else if(t==="className"){if(e.props[t])if(o instanceof SVGElement)o.setAttribute("class",e.props[t]);else o.className=e.props[t]}else if(t==="onClick"||t==="onclick"){let i=e.props[t];if(typeof i==="function")o.addEventListener("click",(a)=>{try{i(a)}catch(s){console.error("[0x1 Router] Error in click handler:",s)}});else if(typeof i==="string")o.setAttribute("onclick",i)}else if(t.startsWith("on")&&typeof e.props[t]==="function"){let i=t.slice(2).toLowerCase();o.addEventListener(i,(a)=>{e.props[t](a)})}else if(t==="style"&&typeof e.props[t]==="object")Object.assign(o.style,e.props[t]);else if(t==="dangerouslySetInnerHTML"){if(e.props[t]&&e.props[t].__html)o.innerHTML=e.props[t].__html}else if(e.props[t]!==null&&e.props[t]!==void 0&&e.props[t]!==!1&&(typeof e.props[t]==="string"||typeof e.props[t]==="number"||typeof e.props[t]==="boolean"))if(o instanceof SVGElement||["path","circle","rect","line","polygon","polyline","ellipse","g","defs","use"].includes(o.tagName.toLowerCase())){let i={viewbox:"viewBox",strokewidth:"stroke-width",strokelinecap:"stroke-linecap",strokelinejoin:"stroke-linejoin",strokemiterlimit:"stroke-miterlimit",strokeopacity:"stroke-opacity",strokedasharray:"stroke-dasharray",strokedashoffset:"stroke-dashoffset",stopcolor:"stop-color",stopopacity:"stop-opacity",fillrule:"fill-rule",fillopacity:"fill-opacity",clippath:"clip-path",clippathunits:"clipPathUnits"}[t.toLowerCase()]||t;if(t==="xmlns")o.setAttribute("xmlns",String(e.props[t]));else o.setAttributeNS(null,i,String(e.props[t]))}else o.setAttribute(t,String(e.props[t]))}catch(i){console.error(`[0x1 Router] Error setting prop ${t} on element:`,i)}});let n=[];try{let t=e.__isVNode&&e.children!==void 0?e.children:e.children!==void 0?e.children:e.props?.children;if(t===null||t===void 0)n=[];else if(Array.isArray(t))n=t.filter((i)=>i!==null&&i!==void 0);else n=[t]}catch(t){console.warn("[0x1 Router] Error normalizing children:",t),n=[]}if(!Array.isArray(n))console.warn("[0x1 Router] Children normalization failed, forcing array"),n=[];if(n.forEach((t)=>{if(t===null||t===void 0||t===!1||t===!0)return;if(typeof t==="string"||typeof t==="number")o.appendChild(document.createTextNode(String(t)));else if(t&&typeof t==="object"){let i=this.jsxToDom(t,r);if(i)o.appendChild(i)}}),e.props&&o.setAttribute){let t=e.props["data-component-id"],i=e.props["data-component-name"];if(t)o.setAttribute("data-component-id",t);if(i)o.setAttribute("data-component-name",i)}return o}else if(typeof e.type==="function")try{let o=this.renderComponentWithHookContext(e.type,e.props||{}),n=this.jsxToDom(o,r);if(n&&n.setAttribute){let t=o?.props?.["data-component-id"],i=o?.props?.["data-component-name"];if(t)n.setAttribute("data-component-id",t);if(i)n.setAttribute("data-component-name",i)}return n}catch(o){console.error("[0x1 Router] Error rendering component:",o);let n=document.createElement("div");return n.className="component-error p-4 bg-red-50/80 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg shadow-sm",n.innerHTML=` <h3 class="text-red-700 dark:text-red-300 font-medium mb-2">Component Error</h3> <p class="text-red-600 dark:text-red-400 text-sm font-mono break-words">${o?.message||String(o)}</p> `,n}}return console.warn("[0x1 Router] Component returned invalid JSX object. Expected object with string|function type, got:",typeof e.type,e.type,` Full object:`,e,` This usually means a component is returning hyperscript/h() calls instead of proper JSX. Check your component's return statement.`),null}catch(o){console.error("[0x1 Router] Error in jsxToDom:",o);let n=document.createElement("div");return n.className="jsx-error p-2 bg-red-100 dark:bg-red-900/30 border border-red-300 dark:border-red-700 rounded text-red-700 dark:text-red-300",n.textContent=`JSX Render Error: ${o?.message||String(o)}`,n}}renderComponentWithHookContext(e,r){if(typeof window==="undefined")return e(r);if(typeof e!=="function")return console.warn("[0x1 Router] Invalid component provided to renderComponentWithHookContext"),null;let o=e.name&&e.name.trim()||"AnonymousComponent",n=window.__0x1_hooks;if(n?.componentRegistry){let i=n.componentRegistry,a=[];for(let[s,l]of i.entries())if(s.startsWith(`${o}_`)&&s!==o){if(!document.querySelector(`[data-component-id="${s}"]`))a.push(s)}a.forEach((s)=>{if(i.delete(s),n?.componentUpdateCallbacks)n.componentUpdateCallbacks.delete(s)})}let t=`${o}_${Math.random().toString(36).slice(2,8)}`;if(!t||t==="undefined"||t==="null"||t.includes("undefined")||t.includes("null"))return console.warn("[0x1 Router] Generated invalid componentId, rendering without hook context:",t),e(r);if(!window.__0x1_hooks||typeof window.__0x1_enterComponentContext!=="function"||typeof window.__0x1_exitComponentContext!=="function")return e(r);try{let i=()=>{requestAnimationFrame(()=>{try{let s=document.querySelector(`[data-component-id="${t}"]`);if(s&&s.parentNode){window.__0x1_enterComponentContext(t);let l=e(r),c=this.jsxToDom(l,t);if(window.__0x1_exitComponentContext(),c){if(c.setAttribute)c.setAttribute("data-component-id",t),c.setAttribute("data-component-name",o);s.parentNode.replaceChild(c,s)}}}catch(s){console.error("[0x1 Router] Error updating component:",s)}})};window.__0x1_enterComponentContext(t,i);let a=e(r);if(a&&typeof a==="object"&&a.props)a.props["data-component-id"]=t,a.props["data-component-name"]=o;return a}catch(i){throw console.error(`[0x1 Router] Error in component ${t}:`,i),i}finally{window.__0x1_exitComponentContext()}}hashProps(e){if(!e||typeof e!=="object")return"no-props";try{let r=Object.keys(e).sort().map((n)=>`${n}:${typeof e[n]}`).join("|"),o=0;for(let n=0;n<r.length;n++){let t=r.charCodeAt(n);o=(o<<5)-o+t,o=o&o}return Math.abs(o).toString(36)}catch(r){return"hash-error"}}use(e){this.middleware.push(e)}getCurrentRoute(){return this.matchRoute(this.currentPath)}onRouteChange(e){return this.listeners.push(e),()=>{this.listeners=this.listeners.filter((r)=>r!==e)}}resolveRoute(e){return this.matchRoute(e)}prefetch(e){let r=this.matchRoute(e)}generateStaticRoutes(){return this.routes.filter((e)=>!e.path.includes(":")).map((e)=>e.path)}getRoutes(){return this.routes}}function f(){if(typeof window==="undefined")return null;return window.__0x1_ROUTER__||window.__0x1_router||window.router||null}function y(){let e=f();if(!e)return{navigate:(r,o=!0,n)=>{if(typeof window!=="undefined")window.location.href=r},currentPath:"/",getCurrentRoute:()=>null,prefetch:()=>{}};return{navigate:(r,o=!0,n)=>e.navigate(r,o,n),currentPath:e.currentPath,getCurrentRoute:()=>e.getCurrentRoute(),prefetch:(r)=>e.prefetch(r)}}function w(){let e=f();return(e?e.getCurrentRoute():null)?.params||{}}function x(){let e=f();if(!e){if(typeof window!=="undefined")return new URLSearchParams(window.location.search);return new URLSearchParams("")}let r=e.currentPath,o=r.includes("?")?r.split("?")[1]:"";return new URLSearchParams(o)}function m(e){let{to:r,children:o,className:n="",activeClassName:t="active",exact:i=!1,...a}=e,s=document.createElement("a");s.href=r,s.className=n;let l=window.location.pathname;if((i?l===r:l.startsWith(r)&&(r!=="/"||l==="/"))&&t)s.className=s.className?`${s.className} ${t}`:t;return Object.entries(a).forEach(([d,p])=>{if(d.startsWith("on")&&typeof p==="function"){let u=d.substring(2).toLowerCase();s.addEventListener(u,p)}else if(d==="style"&&typeof p==="object")Object.entries(p).forEach(([u,g])=>{s.style[u]=g});else if(p!==void 0&&p!==null)s.setAttribute(d,String(p))}),o.forEach((d)=>{if(typeof d==="string")s.appendChild(document.createTextNode(d));else if(d instanceof HTMLElement)s.appendChild(d)}),s}function _(e){return m({...e,activeClassName:e.activeClassName||"active"})}function v(e){return{render:()=>{return setTimeout(()=>{let r=window.__0x1_ROUTER__;if(r&&typeof r.navigate==="function")r.navigate(e.to);else if(e.to.startsWith("http")||e.to.startsWith("//"))window.location.href=e.to;else window.location.pathname=e.to},0),document.createElement("div")}}}function k(e){return new h(e)}export{x as useSearchParams,y as useRouter,w as useParams,k as createRouter,v as RouterRedirect,_ as RouterNavLink,m as RouterLink};