@krate/runtime 0.4.0-beta.1 → 0.4.0-beta.2

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.
@@ -1,4 +1,25 @@
1
1
  declare global {
2
+ /**
3
+ * Extension point for Krate-generated types. `krate build` writes
4
+ * `krate-env.d.ts`, which augments these interfaces with the project's
5
+ * routes and content collections (see `.krate/types/`).
6
+ *
7
+ * `TypedRoutes` is intentionally empty by default so the runtime type-checks
8
+ * with no generated files present.
9
+ */
10
+ namespace Krate {
11
+ interface TypedRoutes {
12
+ }
13
+ }
14
+ /**
15
+ * A navigation target. When the project has generated route types,
16
+ * `Krate.TypedRoutes.href` is a union of its routes, which gives `<Link href>`
17
+ * and `<a href>` autocomplete. `string` is always accepted so arbitrary URLs
18
+ * (external, query strings, hashes) keep working.
19
+ */
20
+ type KrateHref = Krate.TypedRoutes extends {
21
+ href: infer H;
22
+ } ? H extends string ? H | (string & {}) : string : string;
2
23
  namespace JSX {
3
24
  interface Element extends Node {
4
25
  }
@@ -221,7 +242,7 @@ declare global {
221
242
  }
222
243
  interface AnchorHTMLAttributes extends HTMLAttributes {
223
244
  download?: string;
224
- href?: string;
245
+ href?: KrateHref;
225
246
  hrefLang?: string;
226
247
  media?: string;
227
248
  ping?: string;
@@ -995,7 +1016,7 @@ declare global {
995
1016
  [key: string]: any;
996
1017
  }
997
1018
  interface LinkProps extends AnchorHTMLAttributes {
998
- href: string;
1019
+ href: KrateHref;
999
1020
  className?: string;
1000
1021
  external?: boolean;
1001
1022
  children?: any;
@@ -1,2 +1,2 @@
1
- var __krate_exports=(()=>{var B=Object.defineProperty,je=Object.defineProperties,Ke=Object.getOwnPropertyDescriptor,We=Object.getOwnPropertyDescriptors,Xe=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable;var Te=(e,t,n)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ee=(e,t)=>{for(var n in t||(t={}))W.call(t,n)&&Te(e,n,t[n]);if(_)for(var n of _(t))ve.call(t,n)&&Te(e,n,t[n]);return e},He=(e,t)=>je(e,We(t));var Ae=(e,t)=>{var n={};for(var r in e)W.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&_)for(var r of _(e))t.indexOf(r)<0&&ve.call(e,r)&&(n[r]=e[r]);return n};var Ge=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},Je=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xe(t))!W.call(e,o)&&o!==n&&B(e,o,{get:()=>t[o],enumerable:!(r=Ke(t,o))||r.enumerable});return e};var Ye=e=>Je(B({},"__esModule",{value:!0}),e);var ht={};Ge(ht,{Fragment:()=>ct,clearNodes:()=>Se,conditional:()=>bt,createEffect:()=>S,createMemo:()=>nt,createResource:()=>lt,createSignal:()=>w,disposeAll:()=>$e,disposeNode:()=>L,forwardRef:()=>it,h:()=>V,hydrate:()=>ut,initRouter:()=>De,insert:()=>ot,jsx:()=>Ce,jsxs:()=>dt,mount:()=>at,onCleanup:()=>$,onMount:()=>et,reconcile:()=>gt,reconcileTrees:()=>ne,reinitRouter:()=>pt,useRef:()=>rt});var k=[],Me=[],X=!1,P=new Set,G=[],J=[],q=!1;function Le(e){return{fn:e,cleanups:[],disposed:!1,sources:new Set,running:!1,rerun:!1,queued:!1}}function Y(e){if(!e.disposed){e.disposed=!0;for(let t of e.sources)t.delete(e);e.sources.clear();for(let t of e.cleanups)t();e.cleanups.length=0}}function $e(){for(let e of P)Y(e);P.clear();for(let e of G)try{e()}catch(t){}G.length=0,J.length=0,q=!1}function w(e){let t=e,n=new Set;return[()=>{let u=k[k.length-1];return u&&!u.disposed&&(n.add(u),u.sources.add(n)),t},u=>{let d=typeof u=="function"?u(t):u;if(d!==t){t=d;let h=Array.from(n);for(let f of h){if(f.disposed){n.delete(f);continue}if(f.running){f.rerun=!0;continue}f.queued||(f.queued=!0,J.push(f))}Qe()}}]}function Qe(){q||(q=!0,queueMicrotask(Ze))}function Ze(){q=!1;let e=J.splice(0);for(let t of e)t.disposed||(t.queued=!1,t.rerun=!1,F(t),t.rerun&&!t.disposed&&(t.rerun=!1,F(t)))}function F(e){e.running=!0;for(let t of e.cleanups)t();e.cleanups.length=0,k.push(e);try{let t=e.fn();typeof t=="function"&&e.cleanups.push(t)}finally{k.pop(),e.running=!1}}function S(e){let t=Le(e);return P.add(t),F(t),()=>{Y(t),P.delete(t)}}function $(e){let t=k[k.length-1];t?t.cleanups.push(e):G.push(e)}function et(e){Me.push(e),X||(X=!0,queueMicrotask(tt))}function tt(){X=!1;let e=Me.splice(0);for(let t of e)t()}function nt(e){let[t,n]=w(void 0),r=Le(()=>{let u=e();n(u)});P.add(r),F(r);let o=k[k.length-1];return o&&o.cleanups.push(()=>{r.disposed||(Y(r),P.delete(r))}),t}function rt(e){return{current:e}}function it(e){return t=>e(t,t.ref||(()=>{}))}var Q=new WeakMap;function xe(e,t){let n=Q.get(e);n||(n=[],Q.set(e,n)),n.push(t)}function L(e){let t=Q.get(e);if(t){for(let n of t)n();t.length=0}for(let n=0;n<e.childNodes.length;n++)L(e.childNodes[n])}function st(e){let t=e.nextSibling;for(;t;){if(t.nodeType===8&&t.nodeValue==="k")return t;t=t.nextSibling}return null}function Se(e,t){let n=e.parentNode;if(!n)return;let r=e.nextSibling;for(;r&&r!==t;){let o=r.nextSibling;L(r),n.removeChild(r),r=o}}function ot(e,t,n){let r=st(n);r?(Se(n,r),Z(e,t,r)):Z(e,t,null)}function Z(e,t,n){if(!(t==null||t===!1||t===!0)){if(typeof t=="string"||typeof t=="number")e.insertBefore(document.createTextNode(String(t)),n);else if(t instanceof Node)e.insertBefore(t,n);else if(Array.isArray(t))for(let r of t)Z(e,r,n)}}function ye(e,t,n){if(t==="class"||t==="className")n===!1||n===null||n===void 0?e.className="":e.className=String(n);else if(t==="style")typeof n=="string"?e.setAttribute("style",n):n&&typeof n=="object"&&Object.assign(e.style,n);else if(t.startsWith("on")&&typeof n=="function"){let r=t.slice(2).toLowerCase(),o=`__krate_${r}`,u=e[o];u&&e.removeEventListener(r,u),e.addEventListener(r,n),e[o]=n}else t==="ref"?typeof n=="function"?n(e):n&&typeof n=="object"&&"current"in n&&(n.current=e):t==="key"||n!=null&&n!==!1&&e.setAttribute(t,String(n))}function ke(e,t){if(!(t==null||t===!1||t===!0)){if(Array.isArray(t)){for(let n of t)ke(e,n);return}if(typeof t=="function"){let n=document.createTextNode("");e.appendChild(n),xe(n,S(()=>{n.nodeValue=String(t())}));return}e.appendChild(t instanceof Node?t:document.createTextNode(String(t)))}}function V(e,t,...n){if(typeof e=="function")return e(He(Ee({},t||{}),{children:n}));let r=document.createElement(e);if(t)for(let[o,u]of Object.entries(t))typeof u=="function"&&!o.startsWith("on")?xe(r,S(()=>ye(r,o,u()))):ye(r,o,u);for(let o of n)ke(r,o);return r}function we(e){if(typeof e=="string"){let t=document.querySelector(e);if(!t)throw new Error(`Container "${e}" not found`);return t}return e}function at(e,t){let n=we(t),r=!1;S(()=>{r||(r=!0,n.appendChild(e()))})}function ut(e,t){let n=we(t);if(n.childNodes.length===0){n.appendChild(e());return}let r=e();r&&L(r)}function lt(e,t){let[n,r]=w(void 0),[o,u]=w(!0),[d,h]=w(void 0),[f,m]=w("unresolved"),[H,g]=w(0),l,p=()=>typeof e=="function"?e():e,v=async()=>{l&&l.abort(),l=new AbortController;let y=l,I=p();m(H()>0?"refreshing":"loading"),u(!0),h(void 0);try{let x=await t(I,{signal:y.signal});y.signal.aborted||(r(()=>x),m("ready"))}catch(x){(x==null?void 0:x.name)!=="AbortError"&&!y.signal.aborted&&(h(x),m("error"))}finally{y.signal.aborted||u(!1)}};S(()=>{typeof e=="function"&&e.length===0&&e(),H(),v(),$(()=>{l&&(l.abort(),l=void 0)})});let T=function(){return n()};return Object.defineProperties(T,{loading:{get:()=>o()},error:{get:()=>d()},state:{get:()=>f()}}),[T,{mutate:y=>{r(y)},refetch:()=>{g(y=>y+1)}}]}function ct(e){let t=document.createDocumentFragment(),n=e.children;if(n){let r=Array.isArray(n)?n:[n];for(let o of r)o instanceof Node?t.appendChild(o):t.appendChild(document.createTextNode(String(o)))}return t}function Ce(e,t,n){let r=e;if(!t)return V(r,null);let h=t,{children:o}=h,u=Ae(h,["children"]),d=o!==void 0?Array.isArray(o)?o:[o]:[];return V(r,Object.keys(u).length>0?u:null,...d)}function dt(e,t,n){return Ce(e,t,n)}function gt(e,t,n,r,o,u){let d=[],h=t.nextSibling;for(;h&&h!==n;)d.push(h),h=h.nextSibling;if(u){let f=new Map;for(let g of d){let l=g.__k;l!=null&&f.set(l,g)}let m=[],H=new Set;for(let g=0;g<r.length;g++){let l=r[g],p=u(l);H.add(p);let v=o(l,g);v.__k=p,m.push(v)}for(let[g,l]of f)!H.has(g)&&l.parentNode===e&&(L(l),e.removeChild(l));for(let g=0;g<m.length;g++){let l=m[g],p=g===0?t:m[g-1];l!==p.nextSibling&&e.insertBefore(l,p.nextSibling)}}else{let f=Math.max(d.length,r.length);for(let m=0;m<f;m++)if(m<r.length){let H=o(r[m],m);m<d.length?d[m]!==H&&(L(d[m]),e.replaceChild(H,d[m])):e.insertBefore(H,n)}else m<d.length&&d[m].parentNode===e&&(L(d[m]),e.removeChild(d[m]))}}function bt(e,t,n,r,o,u){let d=null;S(()=>{let f=r()?o():u?u():null;d?f?(L(d),e.replaceChild(f,d)):(L(d),e.removeChild(d)):f&&e.insertBefore(f,n),d=f})}function O(e){if(e.nodeType===Node.COMMENT_NODE){let t=e.nodeValue||"";return t.indexOf("k:")===0?t:null}if(e.nodeType===Node.ELEMENT_NODE){let t=e,n=t.getAttribute("data-k");if(n)return n;let r=t.getAttribute("id");if(r)return"#"+r}return null}function Ne(e,t){let n=new Set;for(let r=0;r<t.attributes.length;r++){let o=t.attributes[r].name,u=t.attributes[r].value;n.add(o),e.getAttribute(o)!==u&&e.setAttribute(o,u)}for(let r=0;r<e.attributes.length;r++){let o=e.attributes[r].name;n.has(o)||e.removeAttribute(o)}}function ee(e,t){let n=document.importNode(t,!0);return e.parentNode&&(L(e),e.parentNode.replaceChild(n,e)),n}function Pe(e,t){return e.nodeType!==t.nodeType?!1:e.nodeType===Node.ELEMENT_NODE?e.tagName===t.tagName:!0}function te(e,t){if(!Pe(e,t))return ee(e,t);if(e.nodeType===Node.TEXT_NODE)return e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e;if(e.nodeType===Node.COMMENT_NODE)return e.nodeValue!==t.nodeValue?ee(e,t):e;if(e.nodeType!==Node.ELEMENT_NODE)return e;let n=e,r=t;return O(n)!==O(r)?ee(n,r):(Ne(n,r),Oe(n,r),n)}function Oe(e,t){let n=Array.from(e.childNodes),r=Array.from(t.childNodes);if(n.length===r.length){let g=!0;for(let l=0;l<r.length;l++)if(O(n[l])!==O(r[l])){g=!1;break}if(g){for(let l=0;l<r.length;l++)te(n[l],r[l]);return}}let o=new Map,u=[];n.forEach((g,l)=>{let p=O(g);p!=null?o.has(p)||o.set(p,l):u.push(l)});let d=new Set,h=0,f=null,m=0,H=()=>{for(;m<u.length&&d.has(u[m]);)m++;return m<u.length?u[m]:-1};for(let g of r){let l=O(g),p;if(l!=null&&o.has(l)){let v=o.get(l);o.delete(l),d.add(v);let T=n[v];v<h?e.insertBefore(T,f):h=v,p=te(T,g)}else if(l==null){let v=H();if(v>=0&&Pe(n[v],g)){d.add(v);let T=n[v];T.parentNode===e&&T.nextSibling!==f&&e.insertBefore(T,f),p=te(T,g)}else p=document.importNode(g,!0),e.insertBefore(p,f)}else p=document.importNode(g,!0),e.insertBefore(p,f);f=p.nextSibling}n.forEach((g,l)=>{!d.has(l)&&g.parentNode===e&&(L(g),e.removeChild(g))})}function ne(e,t){if(e.nodeType!==Node.ELEMENT_NODE||t.nodeType!==Node.ELEMENT_NODE)return;let n=e,r=t;if(n.tagName!==r.tagName){let o=document.importNode(t,!0);n.parentNode&&n.parentNode.replaceChild(o,n);return}Ne(n,r),Oe(n,r)}var re=!1,R,U=null,C=new Map,ft=30,D=new Map,mt=50,Re=/\/chunks\/runtime\.[^/]+\.js$/;function De(){if(typeof document=="undefined"||re)return;re=!0;let e=".docs-content, main, #root",t=150,n=200,r=null,o=null,u=new Map,d=null;function h(i){for(let s of e.split(", ")){let a=i.querySelector(s.trim());if(a)return a}return i.body}function f(i){if(i.hasAttribute("data-krate-external"))return!1;let s=i.getAttribute("href");return!(!s||s.startsWith("#")||s.startsWith("javascript:")||i.origin!==location.origin||i.target==="_blank")}function m(i){C.has(i)||fetch(i,{headers:{Accept:"text/html"}}).then(s=>s.ok?s.text():null).then(s=>{if(s){if(C.size>=ft){let a=C.keys().next().value;a!==void 0&&C.delete(a)}C.set(i,s)}}).catch(()=>{})}function H(){document.addEventListener("mouseover",p),document.addEventListener("focusin",p),typeof IntersectionObserver!="undefined"&&(d=new IntersectionObserver(i=>{for(let s of i)if(s.isIntersecting){let a=s.target,c=a.getAttribute("href");if(c&&f(a)){let b=new URL(c,location.origin).href;m(b)}d.unobserve(s.target)}},{rootMargin:"200px"}),g())}function g(){d&&document.querySelectorAll("a[data-prefetch]").forEach(i=>{d.observe(i)})}function l(){document.removeEventListener("mouseover",p),document.removeEventListener("focusin",p);for(let i of u.values())clearTimeout(i);u.clear(),d&&(d.disconnect(),d=null)}function p(i){let s=i.target.closest("a[data-prefetch]");if(!s||!f(s))return;let a=s.getAttribute("href");if(!a)return;let c=new URL(a,location.origin).href;if(C.has(c))return;let b=u.get(s);b&&clearTimeout(b);let E=setTimeout(()=>{u.delete(s),m(c)},n);u.set(s,E)}function v(i){let s=document.createTreeWalker(i,NodeFilter.SHOW_ELEMENT),a=s.nextNode();for(;a;){let c=a;for(let b of Object.keys(c))b.indexOf("__krate_")===0&&delete c[b];a=s.nextNode()}}let T=null;function ie(){let i=h(document),s=document.querySelector("template[data-krate-loading]");s&&s.content&&i&&(T=s.content.cloneNode(!0),document.body.appendChild(T)),i&&(i.style.transition=`opacity ${t}ms ease`,i.style.opacity="0")}function y(){T&&T.parentNode&&T.parentNode.removeChild(T),T=null;let i=h(document);i&&(i.style.opacity="1")}function I(i){try{let s=globalThis.__krate_onNavigation;typeof s=="function"&&s(i)}catch(s){}}function x(i,s,a,c={}){let{replace:b=!1,scroll:E=!0,restoreScroll:N=!1}=c,z=new DOMParser().parseFromString(i,"text/html"),be=h(z),j=h(document);if(!be||!j){location.href=s;return}let fe=z.querySelector("title");fe&&(document.title=fe.textContent||""),typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),v(j),ne(j,be);let me=z.querySelectorAll('link[rel="stylesheet"]'),pe=new Set;me.forEach(A=>{let M=A.getAttribute("href");M&&pe.add(M)}),document.querySelectorAll('link[rel="stylesheet"]').forEach(A=>{let M=A.getAttribute("href");M&&!pe.has(M)&&A.remove()});let he=new Set;document.querySelectorAll('link[rel="stylesheet"]').forEach(A=>{he.add(A.href)}),me.forEach(A=>{let M=A.getAttribute("href");if(M&&!he.has(M)){let K=document.createElement("link");K.rel="stylesheet",K.href=M,document.head.appendChild(K)}}),_e(a,s).then(()=>{try{qe(),g()}catch(A){try{let M=globalThis.__krate_onHydrationError;typeof M=="function"&&M(A)}catch(M){}location.href=s}}),y();let ze=location.pathname+location.search;if(b)history.replaceState({},"",s);else{if(!N){if(D.size>=mt){let A=D.keys().next().value;A!==void 0&&D.delete(A)}D.set(ze,window.scrollY)}history.pushState({},"",s)}se(s,{restoreScroll:N,scroll:E}),oe(),window.dispatchEvent(new CustomEvent("krate:navigate",{detail:{url:s}})),I(s)}function Ie(i){let s=i.indexOf("#");if(s<0||s===i.length-1)return!1;let a=i.slice(s);try{let c=document.querySelector(a);if(c)return c.scrollIntoView({behavior:"smooth",block:"start"}),!0}catch(c){return!1}return!1}function se(i,s){if(s.restoreScroll){let a=D.get(i);if(a!==void 0){window.scrollTo(0,a);return}}Ie(i)||s.scroll&&window.scrollTo(0,0)}function oe(){let i=location.pathname;document.querySelectorAll("a[data-krate-link]").forEach(s=>{let a=s.getAttribute("href");if(!a){s.removeAttribute("aria-current");return}let c=a;try{c=new URL(a,location.origin).pathname}catch(E){return}c===i||i==="/"&&(c===""||c==="/")||c!=="/"&&c.length>1&&i.startsWith(c)?s.setAttribute("aria-current","page"):s.removeAttribute("aria-current")})}function _e(i,s){return i.length===0?Promise.resolve():Promise.all(i.map(a=>{let c=a.getAttribute("src");return c?Be(c,s):Promise.resolve()})).then(()=>{})}function Be(i,s){return new Promise(a=>{let c=document.createElement("script"),b=ae(i,s);c.src=b,Re.test(b)||c.setAttribute("data-krate-spa",""),c.onload=()=>a(),c.onerror=()=>a(),document.body.appendChild(c)})}function ae(i,s){if(/^(https?:)?\/\//.test(i)||i.startsWith("/"))return new URL(i,s).href;let a=s;if(!a.endsWith("/")){let c=a.lastIndexOf("/");a=c>0?a.slice(0,c+1):"/"}return new URL(i,a).href}function qe(){typeof globalThis.__krate_hydrate=="function"&&globalThis.__krate_hydrate()}function Fe(i,s){typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),history.pushState({},"",s),I(s),document.open(),document.write(i),document.close()}function Ve(){return r!==null?Promise.resolve(r):fetch("/404.html",{headers:{Accept:"text/html"}}).then(i=>i.ok?i.text():null).then(i=>(r=i,i)).catch(()=>null)}function Ue(){return o!==null?Promise.resolve(o):fetch("/500.html",{headers:{Accept:"text/html"}}).then(i=>i.ok?i.text():null).then(i=>(o=i,i)).catch(()=>null)}function ue(i,s){document.querySelectorAll("script[data-krate-spa]").forEach(b=>b.remove());let a=[],c=new Set;return document.querySelectorAll("script[src]").forEach(b=>{c.add(b.src)}),i.querySelectorAll("script[src]").forEach(b=>{let E=b.getAttribute("src");E&&!c.has(ae(E,s))&&a.push(b)}),a}function le(i,s={}){let a=C.get(i);if(a){let E=new DOMParser().parseFromString(a,"text/html");x(a,i,ue(E,i),s);return}ie(),R&&R.abort(),R=new AbortController;let c=R.signal;fetch(i,{headers:{Accept:"text/html"},signal:c}).then(b=>b.ok?b.text().then(E=>{let ge=new DOMParser().parseFromString(E,"text/html");x(E,i,ue(ge,i),s)}):(b.status>=500?Ue():Ve()).then(N=>{N?Fe(N,i):location.href=i})).catch(b=>{(b==null?void 0:b.name)!=="AbortError"&&(y(),location.href=i)}).finally(()=>{R&&!c.aborted&&(R=void 0)})}let ce=i=>{if(i.defaultPrevented||i.button!==0||i.metaKey||i.ctrlKey||i.shiftKey||i.altKey)return;let s=i.target.closest("a[data-krate-link]");if(!s||!f(s))return;i.preventDefault();let a=s.getAttribute("href");if(!a)return;let c=new URL(a,location.origin).href,b=s.hasAttribute("data-krate-replace"),E=s.getAttribute("data-krate-scroll")!=="false";if(a===location.pathname+location.search+location.hash){b&&history.replaceState({},"",a),se(c,{scroll:E});return}le(c,{replace:b,scroll:E})},de=()=>{le(location.href,{restoreScroll:!0})};document.addEventListener("click",ce),window.addEventListener("popstate",de),H(),oe(),document.querySelectorAll("script[src]").forEach(i=>{Re.test(i.src)||i.setAttribute("data-krate-spa","")}),U=()=>{document.removeEventListener("click",ce),window.removeEventListener("popstate",de),l()}}function pt(){U&&(U(),U=null),re=!1,De()}return Ye(ht);})();
1
+ var __krate_exports=(()=>{var B=Object.defineProperty,Ke=Object.defineProperties,je=Object.getOwnPropertyDescriptor,We=Object.getOwnPropertyDescriptors,Xe=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable;var Te=(e,t,n)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,He=(e,t)=>{for(var n in t||(t={}))W.call(t,n)&&Te(e,n,t[n]);if(_)for(var n of _(t))ve.call(t,n)&&Te(e,n,t[n]);return e},Ee=(e,t)=>Ke(e,We(t));var Ae=(e,t)=>{var n={};for(var r in e)W.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&_)for(var r of _(e))t.indexOf(r)<0&&ve.call(e,r)&&(n[r]=e[r]);return n};var Ge=(e,t)=>{for(var n in t)B(e,n,{get:t[n],enumerable:!0})},Je=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xe(t))!W.call(e,o)&&o!==n&&B(e,o,{get:()=>t[o],enumerable:!(r=je(t,o))||r.enumerable});return e};var Ye=e=>Je(B({},"__esModule",{value:!0}),e);var ht={};Ge(ht,{Fragment:()=>ct,clearNodes:()=>Se,conditional:()=>bt,createEffect:()=>S,createMemo:()=>nt,createResource:()=>lt,createSignal:()=>w,disposeAll:()=>$e,disposeNode:()=>L,forwardRef:()=>it,h:()=>V,hydrate:()=>ut,initRouter:()=>De,insert:()=>ot,jsx:()=>Ce,jsxs:()=>dt,mount:()=>at,onCleanup:()=>$,onMount:()=>et,reconcile:()=>gt,reconcileTrees:()=>ne,reinitRouter:()=>pt,useRef:()=>rt});var k=[],Me=[],X=!1,P=new Set,G=[],J=[],q=!1;function Le(e){return{fn:e,cleanups:[],disposed:!1,sources:new Set,running:!1,rerun:!1,queued:!1}}function Y(e){if(!e.disposed){e.disposed=!0;for(let t of e.sources)t.delete(e);e.sources.clear();for(let t of e.cleanups)t();e.cleanups.length=0}}function $e(){for(let e of P)Y(e);P.clear();for(let e of G)try{e()}catch(t){}G.length=0,J.length=0,q=!1}function w(e){let t=e,n=new Set;return[()=>{let u=k[k.length-1];return u&&!u.disposed&&(n.add(u),u.sources.add(n)),t},u=>{let d=typeof u=="function"?u(t):u;if(d!==t){t=d;let h=Array.from(n);for(let f of h){if(f.disposed){n.delete(f);continue}if(f.running){f.rerun=!0;continue}f.queued||(f.queued=!0,J.push(f))}Qe()}}]}function Qe(){q||(q=!0,queueMicrotask(Ze))}function Ze(){q=!1;let e=J.splice(0);for(let t of e)t.disposed||(t.queued=!1,t.rerun=!1,F(t),t.rerun&&!t.disposed&&(t.rerun=!1,F(t)))}function F(e){e.running=!0;for(let t of e.cleanups)t();e.cleanups.length=0,k.push(e);try{let t=e.fn();typeof t=="function"&&e.cleanups.push(t)}finally{k.pop(),e.running=!1}}function S(e){let t=Le(e);return P.add(t),F(t),()=>{Y(t),P.delete(t)}}function $(e){let t=k[k.length-1];t?t.cleanups.push(e):G.push(e)}function et(e){Me.push(e),X||(X=!0,queueMicrotask(tt))}function tt(){X=!1;let e=Me.splice(0);for(let t of e)t()}function nt(e){let[t,n]=w(void 0),r=Le(()=>{let u=e();n(u)});P.add(r),F(r);let o=k[k.length-1];return o&&o.cleanups.push(()=>{r.disposed||(Y(r),P.delete(r))}),t}function rt(e){return{current:e}}function it(e){return t=>e(t,t.ref||(()=>{}))}var Q=new WeakMap;function xe(e,t){let n=Q.get(e);n||(n=[],Q.set(e,n)),n.push(t)}function L(e){let t=Q.get(e);if(t){for(let n of t)n();t.length=0}for(let n=0;n<e.childNodes.length;n++)L(e.childNodes[n])}function st(e){let t=e.nextSibling;for(;t;){if(t.nodeType===8&&t.nodeValue==="k")return t;t=t.nextSibling}return null}function Se(e,t){let n=e.parentNode;if(!n)return;let r=e.nextSibling;for(;r&&r!==t;){let o=r.nextSibling;L(r),n.removeChild(r),r=o}}function ot(e,t,n){let r=st(n);r?(Se(n,r),Z(e,t,r)):Z(e,t,null)}function Z(e,t,n){if(!(t==null||t===!1||t===!0)){if(typeof t=="string"||typeof t=="number")e.insertBefore(document.createTextNode(String(t)),n);else if(t instanceof Node)e.insertBefore(t,n);else if(Array.isArray(t))for(let r of t)Z(e,r,n)}}function ye(e,t,n){if(t==="class"||t==="className")n===!1||n===null||n===void 0?e.className="":e.className=String(n);else if(t==="style")typeof n=="string"?e.setAttribute("style",n):n&&typeof n=="object"&&Object.assign(e.style,n);else if(t.startsWith("on")&&typeof n=="function"){let r=t.slice(2).toLowerCase(),o=`__krate_${r}`,u=e[o];u&&e.removeEventListener(r,u),e.addEventListener(r,n),e[o]=n}else t==="ref"?typeof n=="function"?n(e):n&&typeof n=="object"&&"current"in n&&(n.current=e):t==="key"||n!=null&&n!==!1&&e.setAttribute(t,String(n))}function ke(e,t){if(!(t==null||t===!1||t===!0)){if(Array.isArray(t)){for(let n of t)ke(e,n);return}if(typeof t=="function"){let n=document.createTextNode("");e.appendChild(n),xe(n,S(()=>{n.nodeValue=String(t())}));return}e.appendChild(t instanceof Node?t:document.createTextNode(String(t)))}}function V(e,t,...n){if(typeof e=="function")return e(Ee(He({},t||{}),{children:n}));let r=document.createElement(e);if(t)for(let[o,u]of Object.entries(t))typeof u=="function"&&!o.startsWith("on")?xe(r,S(()=>ye(r,o,u()))):ye(r,o,u);for(let o of n)ke(r,o);return r}function we(e){if(typeof e=="string"){let t=document.querySelector(e);if(!t)throw new Error(`Container "${e}" not found`);return t}return e}function at(e,t){let n=we(t),r=!1;S(()=>{r||(r=!0,n.appendChild(e()))})}function ut(e,t){let n=we(t);if(n.childNodes.length===0){n.appendChild(e());return}let r=e();r&&L(r)}function lt(e,t){let[n,r]=w(void 0),[o,u]=w(!0),[d,h]=w(void 0),[f,m]=w("unresolved"),[E,g]=w(0),l,p=()=>typeof e=="function"?e():e,v=async()=>{l&&l.abort(),l=new AbortController;let y=l,I=p();m(E()>0?"refreshing":"loading"),u(!0),h(void 0);try{let x=await t(I,{signal:y.signal});y.signal.aborted||(r(()=>x),m("ready"))}catch(x){(x==null?void 0:x.name)!=="AbortError"&&!y.signal.aborted&&(h(x),m("error"))}finally{y.signal.aborted||u(!1)}};S(()=>{typeof e=="function"&&e.length===0&&e(),E(),v(),$(()=>{l&&(l.abort(),l=void 0)})});let T=function(){return n()};return Object.defineProperties(T,{loading:{get:()=>o()},error:{get:()=>d()},state:{get:()=>f()}}),[T,{mutate:y=>{r(y)},refetch:()=>{g(y=>y+1)}}]}function ct(e){let t=document.createDocumentFragment(),n=e.children;if(n){let r=Array.isArray(n)?n:[n];for(let o of r)o instanceof Node?t.appendChild(o):t.appendChild(document.createTextNode(String(o)))}return t}function Ce(e,t,n){let r=e;if(!t)return V(r,null);let h=t,{children:o}=h,u=Ae(h,["children"]),d=o!==void 0?Array.isArray(o)?o:[o]:[];return V(r,Object.keys(u).length>0?u:null,...d)}function dt(e,t,n){return Ce(e,t,n)}function gt(e,t,n,r,o,u){let d=[],h=t.nextSibling;for(;h&&h!==n;)d.push(h),h=h.nextSibling;if(u){let f=new Map;for(let g of d){let l=g.__k;l!=null&&f.set(l,g)}let m=[],E=new Set;for(let g=0;g<r.length;g++){let l=r[g],p=u(l);E.add(p);let v=o(l,g);v.__k=p,m.push(v)}for(let[g,l]of f)!E.has(g)&&l.parentNode===e&&(L(l),e.removeChild(l));for(let g=0;g<m.length;g++){let l=m[g],p=g===0?t:m[g-1];l!==p.nextSibling&&e.insertBefore(l,p.nextSibling)}}else{let f=Math.max(d.length,r.length);for(let m=0;m<f;m++)if(m<r.length){let E=o(r[m],m);m<d.length?d[m]!==E&&(L(d[m]),e.replaceChild(E,d[m])):e.insertBefore(E,n)}else m<d.length&&d[m].parentNode===e&&(L(d[m]),e.removeChild(d[m]))}}function bt(e,t,n,r,o,u){let d=null;S(()=>{let f=r()?o():u?u():null;d?f?(L(d),e.replaceChild(f,d)):(L(d),e.removeChild(d)):f&&e.insertBefore(f,n),d=f})}function O(e){if(e.nodeType===Node.COMMENT_NODE){let t=e.nodeValue||"";return t.indexOf("k:")===0?t:null}if(e.nodeType===Node.ELEMENT_NODE){let t=e,n=t.getAttribute("data-k");if(n)return n;let r=t.getAttribute("id");if(r)return"#"+r}return null}function Ne(e,t){let n=new Set;for(let r=0;r<t.attributes.length;r++){let o=t.attributes[r].name,u=t.attributes[r].value;n.add(o),e.getAttribute(o)!==u&&e.setAttribute(o,u)}for(let r=0;r<e.attributes.length;r++){let o=e.attributes[r].name;n.has(o)||e.removeAttribute(o)}}function ee(e,t){let n=document.importNode(t,!0);return e.parentNode&&(L(e),e.parentNode.replaceChild(n,e)),n}function Pe(e,t){return e.nodeType!==t.nodeType?!1:e.nodeType===Node.ELEMENT_NODE?e.tagName===t.tagName:!0}function te(e,t){if(!Pe(e,t))return ee(e,t);if(e.nodeType===Node.TEXT_NODE)return e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e;if(e.nodeType===Node.COMMENT_NODE)return e.nodeValue!==t.nodeValue?ee(e,t):e;if(e.nodeType!==Node.ELEMENT_NODE)return e;let n=e,r=t;return O(n)!==O(r)?ee(n,r):(Ne(n,r),Oe(n,r),n)}function Oe(e,t){let n=Array.from(e.childNodes),r=Array.from(t.childNodes);if(n.length===r.length){let g=!0;for(let l=0;l<r.length;l++)if(O(n[l])!==O(r[l])){g=!1;break}if(g){for(let l=0;l<r.length;l++)te(n[l],r[l]);return}}let o=new Map,u=[];n.forEach((g,l)=>{let p=O(g);p!=null?o.has(p)||o.set(p,l):u.push(l)});let d=new Set,h=0,f=null,m=0,E=()=>{for(;m<u.length&&d.has(u[m]);)m++;return m<u.length?u[m]:-1};for(let g of r){let l=O(g),p;if(l!=null&&o.has(l)){let v=o.get(l);o.delete(l),d.add(v);let T=n[v];v<h?e.insertBefore(T,f):h=v,p=te(T,g)}else if(l==null){let v=E();if(v>=0&&Pe(n[v],g)){d.add(v);let T=n[v];T.parentNode===e&&T.nextSibling!==f&&e.insertBefore(T,f),p=te(T,g)}else p=document.importNode(g,!0),e.insertBefore(p,f)}else p=document.importNode(g,!0),e.insertBefore(p,f);f=p.nextSibling}n.forEach((g,l)=>{!d.has(l)&&g.parentNode===e&&(L(g),e.removeChild(g))})}function ne(e,t){if(e.nodeType!==Node.ELEMENT_NODE||t.nodeType!==Node.ELEMENT_NODE)return;let n=e,r=t;if(n.tagName!==r.tagName){let o=document.importNode(t,!0);n.parentNode&&n.parentNode.replaceChild(o,n);return}Ne(n,r),Oe(n,r)}var re=!1,R,U=null,C=new Map,ft=30,D=new Map,mt=50,Re=/\/chunks\/runtime\.[^/]+\.js$/;function De(){if(typeof document=="undefined"||re)return;re=!0;let e=".docs-content, main, #root",t=150,n=200,r=null,o=null,u=new Map,d=null;function h(i){for(let s of e.split(", ")){let a=i.querySelector(s.trim());if(a)return a}return i.body}function f(i){if(i.hasAttribute("data-krate-external"))return!1;let s=i.getAttribute("href");return!(!s||s.startsWith("#")||s.startsWith("javascript:")||i.origin!==location.origin||i.target==="_blank")}function m(i){C.has(i)||fetch(i,{headers:{Accept:"text/html"}}).then(s=>s.ok?s.text():null).then(s=>{if(s){if(C.size>=ft){let a=C.keys().next().value;a!==void 0&&C.delete(a)}C.set(i,s)}}).catch(()=>{})}function E(){document.addEventListener("mouseover",p),document.addEventListener("focusin",p),typeof IntersectionObserver!="undefined"&&(d=new IntersectionObserver(i=>{for(let s of i)if(s.isIntersecting){let a=s.target,c=a.getAttribute("href");if(c&&f(a)){let b=new URL(c,location.origin).href;m(b)}d.unobserve(s.target)}},{rootMargin:"200px"}),g())}function g(){d&&document.querySelectorAll("a[data-prefetch]").forEach(i=>{d.observe(i)})}function l(){document.removeEventListener("mouseover",p),document.removeEventListener("focusin",p);for(let i of u.values())clearTimeout(i);u.clear(),d&&(d.disconnect(),d=null)}function p(i){let s=i.target.closest("a[data-prefetch]");if(!s||!f(s))return;let a=s.getAttribute("href");if(!a)return;let c=new URL(a,location.origin).href;if(C.has(c))return;let b=u.get(s);b&&clearTimeout(b);let H=setTimeout(()=>{u.delete(s),m(c)},n);u.set(s,H)}function v(i){let s=document.createTreeWalker(i,NodeFilter.SHOW_ELEMENT),a=s.nextNode();for(;a;){let c=a;for(let b of Object.keys(c))b.indexOf("__krate_")===0&&delete c[b];a=s.nextNode()}}let T=null;function ie(){let i=h(document),s=document.querySelector("template[data-krate-loading]");s&&s.content&&i&&(T=s.content.cloneNode(!0),document.body.appendChild(T)),i&&(i.style.transition=`opacity ${t}ms ease`,i.style.opacity="0")}function y(){T&&T.parentNode&&T.parentNode.removeChild(T),T=null;let i=h(document);i&&(i.style.opacity="1")}function I(i){try{let s=globalThis.__krate_onNavigation;typeof s=="function"&&s(i)}catch(s){}}function x(i,s,a,c={}){let{replace:b=!1,scroll:H=!0,restoreScroll:N=!1}=c,z=new DOMParser().parseFromString(i,"text/html"),be=h(z),K=h(document);if(!be||!K){location.href=s;return}let fe=z.querySelector("title");fe&&(document.title=fe.textContent||""),typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),v(K),ne(K,be);let me=z.querySelectorAll('link[rel="stylesheet"]'),pe=new Set;me.forEach(A=>{let M=A.getAttribute("href");M&&pe.add(M)}),document.querySelectorAll('link[rel="stylesheet"]').forEach(A=>{let M=A.getAttribute("href");M&&!pe.has(M)&&A.remove()});let he=new Set;document.querySelectorAll('link[rel="stylesheet"]').forEach(A=>{he.add(A.href)}),me.forEach(A=>{let M=A.getAttribute("href");if(M&&!he.has(M)){let j=document.createElement("link");j.rel="stylesheet",j.href=M,document.head.appendChild(j)}}),_e(a,s).then(()=>{try{qe(),g()}catch(A){try{let M=globalThis.__krate_onHydrationError;typeof M=="function"&&M(A)}catch(M){}location.href=s}}),y();let ze=location.pathname+location.search;if(b)history.replaceState({},"",s);else{if(!N){if(D.size>=mt){let A=D.keys().next().value;A!==void 0&&D.delete(A)}D.set(ze,window.scrollY)}history.pushState({},"",s)}se(s,{restoreScroll:N,scroll:H}),oe(),window.dispatchEvent(new CustomEvent("krate:navigate",{detail:{url:s}})),I(s)}function Ie(i){let s=i.indexOf("#");if(s<0||s===i.length-1)return!1;let a=i.slice(s);try{let c=document.querySelector(a);if(c)return c.scrollIntoView({behavior:"smooth",block:"start"}),!0}catch(c){return!1}return!1}function se(i,s){if(s.restoreScroll){let a=D.get(i);if(a!==void 0){window.scrollTo(0,a);return}}Ie(i)||s.scroll&&window.scrollTo(0,0)}function oe(){let i=location.pathname;document.querySelectorAll("a[data-krate-link]").forEach(s=>{let a=s.getAttribute("href");if(!a){s.removeAttribute("aria-current");return}let c=a;try{c=new URL(a,location.origin).pathname}catch(H){return}c===i||i==="/"&&(c===""||c==="/")||c!=="/"&&c.length>1&&i.startsWith(c)?s.setAttribute("aria-current","page"):s.removeAttribute("aria-current")})}function _e(i,s){return i.length===0?Promise.resolve():Promise.all(i.map(a=>{let c=a.getAttribute("src");return c?Be(c,s):Promise.resolve()})).then(()=>{})}function Be(i,s){return new Promise(a=>{let c=document.createElement("script"),b=ae(i,s);c.src=b,Re.test(b)||c.setAttribute("data-krate-spa",""),c.onload=()=>a(),c.onerror=()=>a(),document.body.appendChild(c)})}function ae(i,s){if(/^(https?:)?\/\//.test(i)||i.startsWith("/"))return new URL(i,s).href;let a=s;if(!a.endsWith("/")){let c=a.lastIndexOf("/");a=c>0?a.slice(0,c+1):"/"}return new URL(i,a).href}function qe(){typeof globalThis.__krate_hydrate=="function"&&globalThis.__krate_hydrate()}function Fe(i,s){typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),history.pushState({},"",s),I(s),document.open(),document.write(i),document.close()}function Ve(){return r!==null?Promise.resolve(r):fetch("/404.html",{headers:{Accept:"text/html"}}).then(i=>i.ok?i.text():null).then(i=>(r=i,i)).catch(()=>null)}function Ue(){return o!==null?Promise.resolve(o):fetch("/500.html",{headers:{Accept:"text/html"}}).then(i=>i.ok?i.text():null).then(i=>(o=i,i)).catch(()=>null)}function ue(i,s){document.querySelectorAll("script[data-krate-spa]").forEach(b=>b.remove());let a=[],c=new Set;return document.querySelectorAll("script[src]").forEach(b=>{c.add(b.src)}),i.querySelectorAll("script[src]").forEach(b=>{let H=b.getAttribute("src");H&&!c.has(ae(H,s))&&a.push(b)}),a}function le(i,s={}){let a=C.get(i);if(a){let H=new DOMParser().parseFromString(a,"text/html");x(a,i,ue(H,i),s);return}ie(),R&&R.abort(),R=new AbortController;let c=R.signal;fetch(i,{headers:{Accept:"text/html"},signal:c}).then(b=>b.ok?b.text().then(H=>{let ge=new DOMParser().parseFromString(H,"text/html");x(H,i,ue(ge,i),s)}):(b.status>=500?Ue():Ve()).then(N=>{N?Fe(N,i):location.href=i})).catch(b=>{(b==null?void 0:b.name)!=="AbortError"&&(y(),location.href=i)}).finally(()=>{R&&!c.aborted&&(R=void 0)})}let ce=i=>{if(i.defaultPrevented||i.button!==0||i.metaKey||i.ctrlKey||i.shiftKey||i.altKey)return;let s=i.target.closest("a[data-krate-link]");if(!s||!f(s))return;i.preventDefault();let a=s.getAttribute("href");if(!a)return;let c=new URL(a,location.origin).href,b=s.hasAttribute("data-krate-replace"),H=s.getAttribute("data-krate-scroll")!=="false";if(a===location.pathname+location.search+location.hash){b&&history.replaceState({},"",a),se(c,{scroll:H});return}le(c,{replace:b,scroll:H})},de=()=>{le(location.href,{restoreScroll:!0})};document.addEventListener("click",ce),window.addEventListener("popstate",de),E(),oe(),document.querySelectorAll("script[src]").forEach(i=>{Re.test(i.src)||i.setAttribute("data-krate-spa","")}),U=()=>{document.removeEventListener("click",ce),window.removeEventListener("popstate",de),l()}}function pt(){U&&(U(),U=null),re=!1,De()}return Ye(ht);})();
2
2
  for (const k in __krate_exports) { window[k] = __krate_exports[k]; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krate/runtime",
3
- "version": "0.4.0-beta.1",
3
+ "version": "0.4.0-beta.2",
4
4
  "description": "Client-side runtime for Krate — signals, hydration, SPA router, resources, and context.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -56,7 +56,7 @@
56
56
  ],
57
57
  "devDependencies": {
58
58
  "@types/node": "^26.2.0",
59
- "esbuild": "^0.25.0",
59
+ "esbuild": "^0.28.0",
60
60
  "typescript": "^5.5.0"
61
61
  },
62
62
  "scripts": {