UNPKG

0x1

Version:

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

2 lines (1 loc) 1.12 kB
function M(j){let{to:w,children:E,className:G="",activeClassName:A="active",exact:H=!1,...I}=j,f=document.createElement("a");f.href=w,f.className=G;let B=window.location.pathname;if((H?B===w:B.startsWith(w)&&(w!=="/"||B==="/"))&&A)f.className=f.className?`${f.className} ${A}`:A;return Object.entries(I).forEach(([q,z])=>{if(q.startsWith("on")&&typeof z==="function"){let D=q.substring(2).toLowerCase();f.addEventListener(D,z)}else if(q==="style"&&typeof z==="object")Object.entries(z).forEach(([D,J])=>{f.style[D]=J});else if(z!==void 0&&z!==null)f.setAttribute(q,String(z))}),E.forEach((q)=>{if(typeof q==="string")f.appendChild(document.createTextNode(q));else if(q instanceof HTMLElement)f.appendChild(q)}),f}function Q(j){return M({...j,activeClassName:j.activeClassName||"active"})}function S(j){return{render:()=>{return setTimeout(()=>{let w=window.__0x1_ROUTER__;if(w&&typeof w.navigate==="function")w.navigate(j.to);else if(j.to.startsWith("http")||j.to.startsWith("//"))window.location.href=j.to;else window.location.pathname=j.to},0),document.createElement("div")}}}export{S as Redirect,Q as NavLink,M as Link};