0x1
Version:
64 lines (63 loc) • 22.8 kB
JavaScript
import { jsx, jsxs, jsxDEV, Fragment, createElement } from "/0x1/jsx-runtime.js";
class L{routes=[];currentPath="/";listeners=[];middleware=[];isServer=typeof window==="undefined";options;scrollPositions=new Map;isBackForward=!1;layoutCache={};constructor(q={}){if(this.options={mode:"history",debug:!1,base:"",scrollBehavior:"auto",scrollToTop:!0,...q},!this.isServer)this.initializeHookSystem(),window.addEventListener("popstate",(G)=>{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=(q)=>{let G=window.__0x1_hooks;if(G)G.componentStack=G.componentStack||[],G.componentStack.push(G.currentComponent),G.currentComponent=q,G.stateIndex=0,G.isRenderingComponent=!0};if(typeof window.__0x1_exitComponentContext!=="function")window.__0x1_exitComponentContext=()=>{let q=window.__0x1_hooks;if(q)q.componentStack=q.componentStack||[],q.currentComponent=q.componentStack.pop()||null,q.isRenderingComponent=!1};if(typeof window.__0x1_triggerUpdate!=="function")window.__0x1_triggerUpdate=(q)=>{if(q){let G=document.querySelector(`[data-component-id="${q}"]`);if(G&&G.getAttribute("data-update-callback")){let U=G.__updateCallback;if(typeof U==="function")U()}}}}init(){if(this.isServer)return;document.addEventListener("click",(q)=>{let U=q.target.closest("a[href]");if(!U)return;let Q=U.getAttribute("href");if(!Q)return;if(Q.startsWith("http")||Q.startsWith("mailto:")||Q.startsWith("tel:"))return;if(U.target&&U.target!=="_self")return;if(q.ctrlKey||q.metaKey||q.shiftKey)return;q.preventDefault(),this.navigate(Q,!0)}),window.addEventListener("popstate",()=>{let q=new URLSearchParams(location.search)})}addRoute(q,G,U){if(typeof q==="string"){let Q={path:q,component:G,exact:U?.exact!==!1,meta:U?.layout?{layout:U.layout}:{}};this.routes.push(Q)}else this.routes.push(q)}async navigate(q,G=!0,U){if(this.isServer)return;if(G)this.saveScrollPosition(this.currentPath);if(G&&q!==this.currentPath)window.history.pushState({},"",q);let Q=this.currentPath;this.currentPath=q,await this.executeMiddleware(q),await this.renderCurrentRoute(),this.handleScrollBehavior(q,Q,U),this.isBackForward=!1,this.listeners.forEach(async(V)=>{try{await V()}catch(J){console.error("[0x1 Router] Error in route change listener:",J)}})}saveScrollPosition(q){if(this.isServer)return;this.scrollPositions.set(q,{x:window.scrollX||window.pageXOffset,y:window.scrollY||window.pageYOffset})}handleScrollBehavior(q,G,U){if(this.isServer)return;let[Q,V]=q.split("#"),J=U||this.options.scrollBehavior||"auto";if(J==="preserve")return;if(J==="auto")if(V)this.scrollToHash(V);else if(this.isBackForward)this.restoreScrollPosition(q);else this.scrollToTop();else if(J==="top")this.scrollToTop();else if(J==="smooth")this.scrollToTop("smooth")}scrollToTop(q="auto"){if(this.isServer)return;try{window.scrollTo({top:0,left:0,behavior:q})}catch(G){window.scrollTo(0,0)}}scrollToHash(q){if(this.isServer)return;setTimeout(()=>{try{let G=document.getElementById(q)||document.querySelector(`[name="${q}"]`)||document.querySelector(`a[name="${q}"]`);if(G){if(G.scrollIntoView({behavior:"smooth",block:"start"}),!window.location.hash.includes(q))window.history.replaceState({},"",`${window.location.pathname}#${q}`)}else console.warn(`[0x1 Router] Hash target not found: #${q}`),this.scrollToTop()}catch(G){console.error("[0x1 Router] Error scrolling to hash:",G),this.scrollToTop()}},50)}restoreScrollPosition(q){if(this.isServer)return;let G=this.scrollPositions.get(q);if(G)setTimeout(()=>{try{window.scrollTo({left:G.x,top:G.y,behavior:"auto"})}catch(U){window.scrollTo(G.x,G.y)}},10);else this.scrollToTop()}async executeMiddleware(q){let G=this.matchRoute(q);if(!G)return;let U={path:q,params:G.params,query:new URLSearchParams(window?.location.search||""),meta:G.route.meta||{}},Q=[...this.middleware,...G.route.middleware||[]],V=0,J=async()=>{if(V<Q.length)await Q[V++](U,J)};await J()}matchRoute(q){for(let G of this.routes){let U=this.pathToRegExp(G.path,G.exact),Q=q.match(U.regex);if(Q){let V={};return U.keys.forEach((J,Y)=>{V[J]=Q[Y+1]||""}),{route:G,params:V}}}return null}pathToRegExp(q,G){if(!q||typeof q!=="string")return console.warn("[0x1 Router] Invalid path provided to pathToRegExp:",q),{regex:new RegExp("^/$"),keys:[]};if(q==="*")return{regex:new RegExp(".*"),keys:[]};let U=[],Q=q.replace(/\//g,"/").replace(/:([^/]+)/g,(V,J)=>{return U.push(J),"([^/]+)"});if(G)Q=`^${Q}$`;else Q=`^${Q}`;return{regex:new RegExp(Q),keys:U}}reRender(){if(this.isServer)return;this.renderCurrentRoute().catch((q)=>{console.error("[0x1 Router] reRender failed:",q)})}async renderCurrentRoute(){if(this.isServer)return;if(this._isRendering)return;if(this._isRendering=!0,this._currentRouteId)this[`_cancelled_${this._currentRouteId}`]=!0;let q=Math.random().toString(36).slice(2,8);this._currentRouteId=q;let G=setTimeout(()=>{if(this._isRendering)console.warn("[0x1 Router] Rendering took too long, forcing reset"),this._isRendering=!1},5000),U=this.options?.rootElement;if(!U){console.warn("[0x1 Router] No root element specified for rendering"),clearTimeout(G),this._isRendering=!1;return}let Q=this.matchRoute(this.currentPath);if(Q)try{let V=Q.route.component,J=Q.route.meta?.layout;if(J){if(this.layoutCache.layoutComponent!==J||!this.layoutCache.element||!this.layoutCache.contentSlot){this.layoutCache={};let X=null;try{X=this.jsxToDom(J({children:null}),q)}catch($){console.error("[0x1 Router] Layout rendering failed:",$);let W=this.jsxToDom(V(Q.params),q);if(W)U.innerHTML="",U.appendChild(W);clearTimeout(G),this._isRendering=!1;return}if(!X){console.error("[0x1 Router] Failed to render layout component"),clearTimeout(G),this._isRendering=!1;return}let _=X.querySelector('[data-slot="children"]')||X.querySelector("main")||X;this.layoutCache={element:X,layoutComponent:J,contentSlot:_},U.innerHTML="",U.appendChild(X)}if(!this.layoutCache.contentSlot){console.error("[0x1 Router] Content slot not found in cached layout"),clearTimeout(G),this._isRendering=!1;return}let Z=null;try{let X=V(Q.params);if(X&&typeof X==="object"&&typeof X.then==="function"){let _=document.getElementById("app-loading");if(_)_.classList.remove("loaded");try{let $=await X;if(Z=this.jsxToDom($,q),_)_.classList.add("loaded")}catch($){if(console.error("[0x1 Router] Promise component failed:",$),_)_.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;">${$ instanceof Error?$.message:"Promise component error"}</div>
</div>
`,clearTimeout(G),this._isRendering=!1;return}}else Z=this.jsxToDom(X,q)}catch(X){console.error("[0x1 Router] Component rendering failed:",X),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;">${X instanceof Error?X.message:"Component error"}</div>
</div>
`,clearTimeout(G),this._isRendering=!1;return}if(!Z){console.error("[0x1 Router] Failed to render page component"),clearTimeout(G),this._isRendering=!1;return}this.layoutCache.contentSlot.innerHTML="",this.layoutCache.contentSlot.appendChild(Z)}else{this.layoutCache={};let Y=null;try{let Z=V(Q.params);if(Z&&typeof Z==="object"&&typeof Z.then==="function"){let X=document.getElementById("app-loading");if(X)X.classList.remove("loaded");try{let _=await Z;if(Y=this.jsxToDom(_,q),X)X.classList.add("loaded")}catch(_){if(console.error("[0x1 Router] Promise component failed:",_),X)X.classList.add("loaded");U.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;">${_ instanceof Error?_.message:"Promise component error"}</div>
</div>
`,clearTimeout(G),this._isRendering=!1;return}}else Y=this.jsxToDom(Z,q)}catch(Z){console.error("[0x1 Router] Component rendering failed:",Z),U.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;">${Z instanceof Error?Z.message:"Component error"}</div>
</div>
`,clearTimeout(G),this._isRendering=!1;return}if(!Y){console.error("[0x1 Router] Failed to render component"),clearTimeout(G),this._isRendering=!1;return}if("startViewTransition"in document)document.startViewTransition(()=>{U.innerHTML="",U.appendChild(Y)});else U.innerHTML="",U.appendChild(Y)}}catch(V){console.error("[0x1 Router] Error rendering route:",V)}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={},U.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(G),this._isRendering=!1}renderFallback404(q){console.log("[0x1 Router] \uD83C\uDFE0 Rendering fallback 404 page"),q.innerHTML="",q.appendChild(this.createFallback404Element())}createFallback404Element(){let q=document.createElement("div");return q.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;
`,q.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>
`,q}jsxToDom(q,G){try{if(!q)return null;if(q&&typeof q==="object"&&typeof q.then==="function"){let U=document.createElement("div");return U.innerHTML='<span style="color: #f59e0b;">⚠️ Promise JSX not resolved</span>',U}if(typeof q==="string"||typeof q==="number"){let U=document.createTextNode(String(q)),Q=document.createElement("span");return Q.appendChild(U),Q}if(typeof q==="boolean")return null;if(Array.isArray(q)){let U=document.createDocumentFragment();q.forEach((V)=>{let J=this.jsxToDom(V,G);if(J)U.appendChild(J)});let Q=document.createElement("div");return Q.appendChild(U),Q}if(q instanceof Node)return q;if(typeof q==="object"&&(q.type||q.__isVNode)){if(q.type===Symbol.for("react.fragment")||q.type===Symbol.for("React.Fragment")){let U=[];try{let V=q.children||q.props?.children;if(V===null||V===void 0)U=[];else if(Array.isArray(V))U=V.filter((J)=>J!==null&&J!==void 0);else U=[V]}catch(V){console.warn("[0x1 Router] Error normalizing fragment children:",V),U=[]}if(!Array.isArray(U))console.warn("[0x1 Router] Fragment children normalization failed, forcing array"),U=[];let Q=document.createDocumentFragment();if(U.forEach((V)=>{let J=this.jsxToDom(V,G);if(J)Q.appendChild(J)}),Q.children.length===1)return Q.children[0];else{let V=document.createElement("div");return V.appendChild(Q),V}}else if(typeof q.type==="string"){let Q=["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","use","text","tspan"].includes(q.type.toLowerCase())?document.createElementNS("http://www.w3.org/2000/svg",q.type):document.createElement(q.type);if(q.props)Object.keys(q.props).forEach((J)=>{try{if(J==="children")return;else if(J==="__self"||J==="__source"||J==="ref"||J==="key")return;else if(J==="className"){if(q.props[J])if(Q instanceof SVGElement)Q.setAttribute("class",q.props[J]);else Q.className=q.props[J]}else if(J==="onClick"||J==="onclick"){let Y=q.props[J];if(typeof Y==="function")Q.addEventListener("click",(Z)=>{try{Y(Z)}catch(X){console.error("[0x1 Router] Error in click handler:",X)}});else if(typeof Y==="string")Q.setAttribute("onclick",Y)}else if(J.startsWith("on")&&typeof q.props[J]==="function"){let Y=J.slice(2).toLowerCase();Q.addEventListener(Y,(Z)=>{q.props[J](Z)})}else if(J==="style"&&typeof q.props[J]==="object")Object.assign(Q.style,q.props[J]);else if(J==="dangerouslySetInnerHTML"){if(q.props[J]&&q.props[J].__html)Q.innerHTML=q.props[J].__html}else if(q.props[J]!==null&&q.props[J]!==void 0&&q.props[J]!==!1&&(typeof q.props[J]==="string"||typeof q.props[J]==="number"||typeof q.props[J]==="boolean"))if(Q instanceof SVGElement||["path","circle","rect","line","polygon","polyline","ellipse","g","defs","use"].includes(Q.tagName.toLowerCase())){let Z={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"}[J.toLowerCase()]||J;if(J==="xmlns")Q.setAttribute("xmlns",String(q.props[J]));else Q.setAttributeNS(null,Z,String(q.props[J]))}else Q.setAttribute(J,String(q.props[J]))}catch(Y){console.error(`[0x1 Router] Error setting prop ${J} on element:`,Y)}});let V=[];try{let J=q.__isVNode&&q.children!==void 0?q.children:q.children!==void 0?q.children:q.props?.children;if(J===null||J===void 0)V=[];else if(Array.isArray(J))V=J.filter((Y)=>Y!==null&&Y!==void 0);else V=[J]}catch(J){console.warn("[0x1 Router] Error normalizing children:",J),V=[]}if(!Array.isArray(V))console.warn("[0x1 Router] Children normalization failed, forcing array"),V=[];if(V.forEach((J)=>{if(J===null||J===void 0||J===!1||J===!0)return;if(typeof J==="string"||typeof J==="number")Q.appendChild(document.createTextNode(String(J)));else if(J&&typeof J==="object"){let Y=this.jsxToDom(J,G);if(Y)Q.appendChild(Y)}}),q.props&&Q.setAttribute){let J=q.props["data-component-id"],Y=q.props["data-component-name"];if(J)Q.setAttribute("data-component-id",J);if(Y)Q.setAttribute("data-component-name",Y)}return Q}else if(typeof q.type==="function")try{let U=this.renderComponentWithHookContext(q.type,q.props||{}),Q=this.jsxToDom(U,G);if(Q&&Q.setAttribute){let V=U?.props?.["data-component-id"],J=U?.props?.["data-component-name"];if(V)Q.setAttribute("data-component-id",V);if(J)Q.setAttribute("data-component-name",J)}return Q}catch(U){console.error("[0x1 Router] Error rendering component:",U);let Q=document.createElement("div");return Q.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",Q.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">${U?.message||String(U)}</p>
`,Q}}return console.warn("[0x1 Router] Component returned invalid JSX object. Expected object with string|function type, got:",typeof q.type,q.type,`
Full object:`,q,`
This usually means a component is returning hyperscript/h() calls instead of proper JSX. Check your component's return statement.`),null}catch(U){console.error("[0x1 Router] Error in jsxToDom:",U);let Q=document.createElement("div");return Q.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",Q.textContent=`JSX Render Error: ${U?.message||String(U)}`,Q}}renderComponentWithHookContext(q,G){if(typeof window==="undefined")return q(G);if(typeof q!=="function")return console.warn("[0x1 Router] Invalid component provided to renderComponentWithHookContext"),null;let U=q.name&&q.name.trim()||"AnonymousComponent",Q=window.__0x1_hooks;if(Q?.componentRegistry){let Y=Q.componentRegistry,Z=[];for(let[X,_]of Y.entries())if(X.startsWith(`${U}_`)&&X!==U){if(!document.querySelector(`[data-component-id="${X}"]`))Z.push(X)}Z.forEach((X)=>{if(Y.delete(X),Q?.componentUpdateCallbacks)Q.componentUpdateCallbacks.delete(X)})}let V=`${U}_${Math.random().toString(36).slice(2,8)}`;if(!V||V==="undefined"||V==="null"||V.includes("undefined")||V.includes("null"))return console.warn("[0x1 Router] Generated invalid componentId, rendering without hook context:",V),q(G);if(!window.__0x1_hooks||typeof window.__0x1_enterComponentContext!=="function"||typeof window.__0x1_exitComponentContext!=="function")return q(G);try{let Y=()=>{requestAnimationFrame(()=>{try{let X=document.querySelector(`[data-component-id="${V}"]`);if(X&&X.parentNode){window.__0x1_enterComponentContext(V);let _=q(G),$=this.jsxToDom(_,V);if(window.__0x1_exitComponentContext(),$){if($.setAttribute)$.setAttribute("data-component-id",V),$.setAttribute("data-component-name",U);X.parentNode.replaceChild($,X)}}}catch(X){console.error("[0x1 Router] Error updating component:",X)}})};window.__0x1_enterComponentContext(V,Y);let Z=q(G);if(Z&&typeof Z==="object"&&Z.props)Z.props["data-component-id"]=V,Z.props["data-component-name"]=U;return Z}catch(Y){throw console.error(`[0x1 Router] Error in component ${V}:`,Y),Y}finally{window.__0x1_exitComponentContext()}}hashProps(q){if(!q||typeof q!=="object")return"no-props";try{let U=Object.keys(q).sort().map((V)=>`${V}:${typeof q[V]}`).join("|"),Q=0;for(let V=0;V<U.length;V++){let J=U.charCodeAt(V);Q=(Q<<5)-Q+J,Q=Q&Q}return Math.abs(Q).toString(36)}catch(G){return"hash-error"}}use(q){this.middleware.push(q)}getCurrentRoute(){return this.matchRoute(this.currentPath)}onRouteChange(q){return this.listeners.push(q),()=>{this.listeners=this.listeners.filter((G)=>G!==q)}}resolveRoute(q){return this.matchRoute(q)}prefetch(q){let G=this.matchRoute(q)}generateStaticRoutes(){return this.routes.filter((q)=>!q.path.includes(":")).map((q)=>q.path)}getRoutes(){return this.routes}}function A(q){let G=new L(q);return G.rootElement=q.rootElement,G.mode=q.mode||"history",G}function K(){if(typeof window==="undefined")return null;return window.__0x1_ROUTER__||window.__0x1_router||window.router||null}function F({href:q,className:G,children:U,prefetch:Q,scrollBehavior:V,scrollToTop:J}){let Y=K();if(Q&&Y)Y.prefetch(q);let Z=J?"top":V;return{type:"a",props:{href:q,className:G,onClick:(X)=>{if(X.preventDefault(),X.stopPropagation(),q.startsWith("/")){let _=K();if(_)_.navigate(q,!0,Z);else if(typeof window!=="undefined")window.history.pushState(null,"",q),window.dispatchEvent(new PopStateEvent("popstate"))}else window.location.href=q},children:U}}}function M(){let q=K();if(!q)return{navigate:(G,U=!0,Q)=>{if(typeof window!=="undefined")window.location.href=G},currentPath:"/",getCurrentRoute:()=>null,prefetch:()=>{}};return{navigate:(G,U=!0,Q)=>q.navigate(G,U,Q),currentPath:q.currentPath,getCurrentRoute:()=>q.getCurrentRoute(),prefetch:(G)=>q.prefetch(G)}}function H(){let q=K();return(q?q.getCurrentRoute():null)?.params||{}}function D(){let q=K();if(!q){if(typeof window!=="undefined")return new URLSearchParams(window.location.search);return new URLSearchParams("")}let G=q.currentPath,U=G.includes("?")?G.split("?")[1]:"";return new URLSearchParams(U)}function O(q){let{href:G,className:U,children:Q,activeClass:V="active",prefetch:J}=q,Y=K(),X=(Y?Y.currentPath===G:!1)?`${U||""} ${V}`.trim():U;if(J&&Y)Y.prefetch(G);return{type:"a",props:{href:G,className:X,onClick:(_)=>{if(_.preventDefault(),_.stopPropagation(),G.startsWith("/")){let $=K();if($)$.navigate(G);else if(typeof window!=="undefined")window.history.pushState(null,"",G),window.dispatchEvent(new PopStateEvent("popstate"))}else window.location.href=G},children:Q}}}function B({to:q}){if(typeof window!=="undefined")setTimeout(()=>{let G=K();if(G)G.navigate(q);else window.location.href=q},0);return null}var P=L;export{D as useSearchParams,M as useRouter,H as useParams,P as default,A as createRouter,L as Router,B as Redirect,O as NavLink,F as Link};