@krate/runtime 0.4.0-rc.3 → 0.4.0-rc.5
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/class-helpers.d.ts +4 -4
- package/dist/class-helpers.js +5 -5
- package/dist/context.d.ts +18 -1
- package/dist/context.js +27 -7
- package/dist/dev-overlay.d.ts +37 -0
- package/dist/dev-overlay.js +583 -0
- package/dist/dev-overlay.test.d.ts +1 -0
- package/dist/dev-overlay.test.js +130 -0
- package/dist/dom.js +5 -5
- package/dist/error-overlay.d.ts +1 -1
- package/dist/error-overlay.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -2
- package/dist/krate-dev.js +490 -0
- package/dist/krate-hydrate.js +1 -1
- package/dist/krate-runtime.js +1 -1
- package/dist/reconcile.js +25 -21
- package/dist/reconcile.test.d.ts +1 -0
- package/dist/reconcile.test.js +47 -0
- package/dist/router.d.ts +12 -0
- package/dist/router.js +239 -54
- package/dist/server-jsx-runtime.js +1 -1
- package/dist/server-renderer.js +64 -24
- package/dist/server.js +13 -13
- package/dist/server.test.d.ts +1 -0
- package/dist/server.test.js +26 -0
- package/dist/signal.d.ts +44 -10
- package/dist/signal.js +22 -15
- package/package.json +1 -1
package/dist/krate-runtime.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var __krate_exports=(()=>{var X=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var rt=(e,t)=>{for(var n in t)X(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of tt(t))!nt.call(e,i)&&i!==n&&X(e,i,{get:()=>t[i],enumerable:!(r=et(t,i))||r.enumerable});return e};var st=e=>it(X({},"__esModule",{value:!0}),e);var Wt={};rt(Wt,{Fragment:()=>Nt,Slot:()=>Ft,clearNodes:()=>Ie,clearPersisted:()=>lt,cloneElement:()=>Ut,clsx:()=>fe,cn:()=>Kt,conditional:()=>It,createCSSChoice:()=>gt,createCSSFlags:()=>bt,createCSSGroup:()=>mt,createCSSRange:()=>pt,createCSSStack:()=>ht,createCSSToggle:()=>ft,createContext:()=>at,createEffect:()=>S,createMemo:()=>At,createReducer:()=>yt,createResource:()=>Pt,createSignal:()=>A,cva:()=>qt,disposeAll:()=>dt,disposeNode:()=>L,forwardRef:()=>Lt,h:()=>z,hydrate:()=>Ct,initRouter:()=>Fe,insert:()=>kt,jsx:()=>Be,jsxs:()=>Rt,mount:()=>wt,onCleanup:()=>q,onMount:()=>Et,readDurableState:()=>Q,readPersisted:()=>Z,reconcile:()=>Ot,reconcileTrees:()=>ce,reinitRouter:()=>Bt,resetContexts:()=>G,resolvePersist:()=>$,subscribePersist:()=>te,twMerge:()=>be,useRef:()=>Mt,writePersisted:()=>ee});var ot=0,N=new Map;function G(){for(let[e,t]of N)if(t.length>0){let n=t[0];N.set(e,[n])}}function at(e){let t=ot++;return N.set(t,[e]),{id:t,defaultValue:e,Provider:n=>{let r=N.get(t)||[e];r.push(n.value),N.set(t,r);let i=document.createElement("div");if(i.style.display="contents",n.children)for(let a of n.children)a instanceof Node?i.appendChild(a):a!=null&&i.appendChild(document.createTextNode(String(a)));return r.pop(),r.length===0&&r.push(e),i},useContext:()=>{let n=N.get(t);return n&&n.length>0?n[n.length-1]:e}}}function ut(){let e=new Map;return{getItem:t=>e.has(t)?e.get(t):null,setItem:(t,n)=>{e.set(t,n)},removeItem:t=>{e.delete(t)}}}var J=ut();function Ce(){return typeof window<"u"}function Y(e){if(e&&typeof e=="object")return e;if(!Ce())return J;try{return e==="session"?window.sessionStorage:e==="memory"?J:window.localStorage}catch{return J}}function $(e){let t=typeof e=="string"?{key:e}:e;if(!t.key)throw new Error("[krate] createSignal persist requires a key");let n=t.store??"local";return{key:t.key,store:n,serialize:t.serialize??(r=>JSON.stringify(r)),deserialize:t.deserialize??(r=>JSON.parse(r)),sync:t.sync??n==="local"}}function Q(e,t){let r=globalThis.__KRATE_STATE__;if(!r||!Object.prototype.hasOwnProperty.call(r,e))return{found:!1};let i=r[e];if(typeof i=="string")try{return{found:!0,value:t(i)}}catch{return{found:!0,value:i}}return{found:!0,value:i}}function Z(e){let t=Y(e.store),n;try{n=t.getItem(e.key)}catch{return{found:!1}}if(n==null)return{found:!1};try{return{found:!0,value:e.deserialize(n)}}catch{return{found:!1}}}function ee(e,t){let n=Y(e.store);try{n.setItem(e.key,e.serialize(t))}catch{}}function lt(e){let t=Y(e.store);try{t.removeItem(e.key)}catch{}}var B=new Map,we=!1;function ct(){we||!Ce()||(we=!0,window.addEventListener("storage",e=>{if(e.key===null)return;let t=B.get(e.key);if(t)for(let n of t)n(e.newValue)}))}function te(e,t){if(!e.sync)return()=>{};let n=B.get(e.key)??new Set;return n.add(t),B.set(e.key,n),ct(),()=>{n.delete(t),n.size===0&&B.delete(e.key)}}var k=[],Pe=[],ne=!1,R=new Set,re=[],ie=[],V=!1;function Ne(e){return{fn:e,cleanups:[],disposed:!1,sources:new Set,running:!1,rerun:!1,queued:!1}}function se(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 dt(){for(let e of R)se(e);R.clear();for(let e of re)try{e()}catch{}re.length=0,ie.length=0,V=!1,G()}function gt(e,t){return A(e)}function ft(e,t){return A(e)}function bt(e,t){let n={};for(let i of e){let[a]=A(!1);n[i]=a}return[n,(i,a)=>{}]}function mt(e,t){return A(e)}function pt(e,t){return A(e)}function ht(e,t){let n=()=>e[0];return[{top:n,peek:n},{push:r=>{},pop:()=>{},clear:()=>{}}]}function A(e,t){let n=e,r=null;if(t?.persist){r=$(t.persist);let c=Q(r.key,r.deserialize);if(c.found)n=c.value;else{let u=Z(r);u.found&&(n=u.value)}}let i=new Set,a=()=>{let c=k[k.length-1];return c&&!c.disposed&&(i.add(c),c.sources.add(i)),n},l=()=>{let c=Array.from(i);for(let u of c){if(u.disposed){i.delete(u);continue}if(u.running){u.rerun=!0;continue}u.queued||(u.queued=!0,ie.push(u))}Tt()},h=c=>{let u=typeof c=="function"?c(n):c;u!==n&&(n=u,r&&ee(r,n),l())};if(r&&r.sync){let c=r,u=te(c,v=>{if(v!==null)try{let b=c.deserialize(v);b!==n&&(n=b,l())}catch{}});q(u)}return[a,h]}function Tt(){V||(V=!0,queueMicrotask(vt))}function vt(){V=!1;let e=ie.splice(0);for(let t of e)t.disposed||(t.queued=!1,t.rerun=!1,K(t),t.rerun&&!t.disposed&&(t.rerun=!1,K(t)))}function K(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=Ne(e);return R.add(t),K(t),()=>{se(t),R.delete(t)}}function q(e){let t=k[k.length-1];t?t.cleanups.push(e):re.push(e)}function Et(e){Pe.push(e),ne||(ne=!0,queueMicrotask(Ht))}function Ht(){ne=!1;let e=Pe.splice(0);for(let t of e)t()}function At(e){let[t,n]=A(void 0),r=Ne(()=>{let a=e();n(a)});R.add(r),K(r);let i=k[k.length-1];return i&&i.cleanups.push(()=>{r.disposed||(se(r),R.delete(r))}),t}function yt(e,t){let[n,r]=A(t);return[n,a=>r(l=>e(l,a))]}function Mt(e){return{current:e}}function Lt(e){return t=>e(t,t.ref||(()=>{}))}var xt={doubleclick:"dblclick",focus:"focusin",blur:"focusout",change:"input"},oe=new WeakMap;function Oe(e,t){let n=oe.get(e);n||(n=[],oe.set(e,n)),n.push(t)}function L(e){let t=oe.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 Ie(e,t){let n=e.parentNode;if(!n)return;let r=e.nextSibling;for(;r&&r!==t;){let i=r.nextSibling;L(r),n.removeChild(r),r=i}}function kt(e,t,n){let r=St(n);r?(Ie(n,r),ae(e,t,r)):ae(e,t,null)}function ae(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)ae(e,r,n)}}function Re(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(),i=xt[r]||r,a=`__krate_${i}`,l=e[a];l&&e.removeEventListener(i,l),e.addEventListener(i,n),e[a]=n}else t==="value"||t==="checked"||t==="selected"?t==="value"?e.value=n==null||n===!1?"":n:e[t]=!!n: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 _e(e,t){if(!(t==null||t===!1||t===!0)){if(Array.isArray(t)){for(let n of t)_e(e,n);return}if(typeof t=="function"){let n=document.createTextNode("");e.appendChild(n),Oe(n,S(()=>{n.nodeValue=String(t())}));return}e.appendChild(t instanceof Node?t:document.createTextNode(String(t)))}}function z(e,t,...n){if(typeof e=="function")return e({...t||{},children:n});let r=document.createElement(e);if(t)for(let[i,a]of Object.entries(t))typeof a=="function"&&!i.startsWith("on")?Oe(r,S(()=>Re(r,i,a()))):Re(r,i,a);for(let i of n)_e(r,i);return r}function De(e){if(typeof e=="string"){let t=document.querySelector(e);if(!t)throw new Error(`Container "${e}" not found`);return t}return e}function wt(e,t){let n=De(t),r=!1;S(()=>{r||(r=!0,n.appendChild(e()))})}function Ct(e,t){let n=De(t);if(n.childNodes.length===0){n.appendChild(e());return}let r=e();r&&L(r)}function Pt(e,t){let[n,r]=A(void 0),[i,a]=A(!0),[l,h]=A(void 0),[c,u]=A("unresolved"),[v,b]=A(0),g,p=()=>typeof e=="function"?e():e,E=async()=>{g&&g.abort(),g=new AbortController;let x=g,D=p();u(v()>0?"refreshing":"loading"),a(!0),h(void 0);try{let w=await t(D,{signal:x.signal});x.signal.aborted||(r(()=>w),u("ready"))}catch(w){w?.name!=="AbortError"&&!x.signal.aborted&&(h(w),u("error"))}finally{x.signal.aborted||a(!1)}};S(()=>{typeof e=="function"&&e.length===0&&e(),v(),E(),q(()=>{g&&(g.abort(),g=void 0)})});let T=function(){return n()};return Object.defineProperties(T,{loading:{get:()=>i()},error:{get:()=>l()},state:{get:()=>c()}}),[T,{mutate:x=>{r(x)},refetch:()=>{b(x=>x+1)}}]}function Nt(e){let t=document.createDocumentFragment(),n=e.children;if(n){let r=Array.isArray(n)?n:[n];for(let i of r)i instanceof Node?t.appendChild(i):t.appendChild(document.createTextNode(String(i)))}return t}function Be(e,t,n){let r=e;if(!t)return z(r,null);let{children:i,...a}=t,l=i!==void 0?Array.isArray(i)?i:[i]:[];return z(r,Object.keys(a).length>0?a:null,...l)}function Rt(e,t,n){return Be(e,t,n)}function Ot(e,t,n,r,i,a){let l=[],h=t.nextSibling;for(;h&&h!==n;)l.push(h),h=h.nextSibling;if(a){let c=new Map;for(let b of l){let g=b.__k;g!=null&&c.set(g,b)}let u=[],v=new Set;for(let b=0;b<r.length;b++){let g=r[b],p=a(g);v.add(p);let E=i(g,b);E.__k=p,u.push(E)}for(let[b,g]of c)!v.has(b)&&g.parentNode===e&&(L(g),e.removeChild(g));for(let b=0;b<u.length;b++){let g=u[b],p=b===0?t:u[b-1];g!==p.nextSibling&&e.insertBefore(g,p.nextSibling)}}else{let c=Math.max(l.length,r.length);for(let u=0;u<c;u++)if(u<r.length){let v=i(r[u],u);u<l.length?l[u]!==v&&(L(l[u]),e.replaceChild(v,l[u])):e.insertBefore(v,n)}else u<l.length&&l[u].parentNode===e&&(L(l[u]),e.removeChild(l[u]))}}function It(e,t,n,r,i,a){let l=null;S(()=>{let c=r()?i():a?a():null;l?c?(L(l),e.replaceChild(c,l)):(L(l),e.removeChild(l)):c&&e.insertBefore(c,n),l=c})}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 Ve(e,t){let n=new Set;for(let r=0;r<t.attributes.length;r++){let i=t.attributes[r].name,a=t.attributes[r].value;n.add(i),e.getAttribute(i)!==a&&e.setAttribute(i,a)}for(let r=0;r<e.attributes.length;r++){let i=e.attributes[r].name;n.has(i)||e.removeAttribute(i)}}function ue(e,t){let n=document.importNode(t,!0);return e.parentNode&&(L(e),e.parentNode.replaceChild(n,e)),n}function Ke(e,t){return e.nodeType!==t.nodeType?!1:e.nodeType===Node.ELEMENT_NODE?e.tagName===t.tagName:!0}function le(e,t){if(!Ke(e,t))return ue(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?ue(e,t):e;if(e.nodeType!==Node.ELEMENT_NODE)return e;let n=e,r=t;return O(n)!==O(r)?ue(n,r):(Ve(n,r),qe(n,r),n)}function qe(e,t){let n=Array.from(e.childNodes),r=Array.from(t.childNodes);if(n.length===r.length){let b=!0;for(let g=0;g<r.length;g++)if(O(n[g])!==O(r[g])){b=!1;break}if(b){for(let g=0;g<r.length;g++)le(n[g],r[g]);return}}let i=new Map,a=[];n.forEach((b,g)=>{let p=O(b);p!=null?i.has(p)||i.set(p,g):a.push(g)});let l=new Set,h=0,c=null,u=0,v=()=>{for(;u<a.length&&l.has(a[u]);)u++;return u<a.length?a[u]:-1};for(let b of r){let g=O(b),p;if(g!=null&&i.has(g)){let E=i.get(g);i.delete(g),l.add(E);let T=n[E];E<h?e.insertBefore(T,c):h=E,p=le(T,b)}else if(g==null){let E=v();if(E>=0&&Ke(n[E],b)){l.add(E);let T=n[E];T.parentNode===e&&T.nextSibling!==c&&e.insertBefore(T,c),p=le(T,b)}else p=document.importNode(b,!0),e.insertBefore(p,c)}else p=document.importNode(b,!0),e.insertBefore(p,c);c=p.nextSibling}n.forEach((b,g)=>{!l.has(g)&&b.parentNode===e&&(L(b),e.removeChild(b))})}function ce(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 i=document.importNode(t,!0);n.parentNode&&n.parentNode.replaceChild(i,n);return}Ve(n,r),qe(n,r)}var de=!1,I,F=null,C=new Map,_t=30,_=new Map,Dt=50,ze=/\/chunks\/runtime\.[^/]+\.js$/;function Fe(){if(typeof document>"u"||de)return;de=!0;let e=".docs-content, main, #root",t=150,n=200,r=null,i=null,a=new Map,l=null;function h(s){for(let o of e.split(", ")){let d=s.querySelector(o.trim());if(d)return d}return s.body}function c(s){if(s.hasAttribute("data-krate-external"))return!1;let o=s.getAttribute("href");return!(!o||o.startsWith("#")||o.startsWith("javascript:")||s.origin!==location.origin||s.target==="_blank")}function u(s){C.has(s)||fetch(s,{headers:{Accept:"text/html"}}).then(o=>o.ok?o.text():null).then(o=>{if(o){if(C.size>=_t){let d=C.keys().next().value;d!==void 0&&C.delete(d)}C.set(s,o)}}).catch(()=>{})}function v(){document.addEventListener("mouseover",p),document.addEventListener("focusin",p),typeof IntersectionObserver<"u"&&(l=new IntersectionObserver(s=>{for(let o of s)if(o.isIntersecting){let d=o.target,f=d.getAttribute("href");if(f&&c(d)){let m=new URL(f,location.origin).href;u(m)}l.unobserve(o.target)}},{rootMargin:"200px"}),b())}function b(){l&&document.querySelectorAll("a[data-prefetch]").forEach(s=>{l.observe(s)})}function g(){document.removeEventListener("mouseover",p),document.removeEventListener("focusin",p);for(let s of a.values())clearTimeout(s);a.clear(),l&&(l.disconnect(),l=null)}function p(s){let o=s.target.closest("a[data-prefetch]");if(!o||!c(o))return;let d=o.getAttribute("href");if(!d)return;let f=new URL(d,location.origin).href;if(C.has(f))return;let m=a.get(o);m&&clearTimeout(m);let H=setTimeout(()=>{a.delete(o),u(f)},n);a.set(o,H)}function E(s){let o=document.createTreeWalker(s,NodeFilter.SHOW_ELEMENT),d=o.nextNode();for(;d;){let f=d;for(let m of Object.keys(f))m.indexOf("__krate_")===0&&delete f[m];d=o.nextNode()}}let T=null;function me(){let s=h(document),o=document.querySelector("template[data-krate-loading]");o&&o.content&&s&&(T=o.content.cloneNode(!0),document.body.appendChild(T)),s&&(s.style.transition=`opacity ${t}ms ease`,s.style.opacity="0")}function x(){T&&T.parentNode&&T.parentNode.removeChild(T),T=null;let s=h(document);s&&(s.style.opacity="1")}function D(s){try{let o=globalThis.__krate_onNavigation;typeof o=="function"&&o(s)}catch{}}function w(s,o,d,f={}){let{replace:m=!1,scroll:H=!0,restoreScroll:P=!1}=f,j=new DOMParser().parseFromString(s,"text/html"),Me=h(j),U=h(document);if(!Me||!U){location.href=o;return}let Le=j.querySelector("title");Le&&(document.title=Le.textContent||""),typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),E(U),ce(U,Me);let xe=j.querySelectorAll('link[rel="stylesheet"]'),Se=new Set;xe.forEach(y=>{let M=y.getAttribute("href");M&&Se.add(M)}),document.querySelectorAll('link[rel="stylesheet"]').forEach(y=>{let M=y.getAttribute("href");M&&!Se.has(M)&&y.remove()});let ke=new Set;document.querySelectorAll('link[rel="stylesheet"]').forEach(y=>{ke.add(y.href)}),xe.forEach(y=>{let M=y.getAttribute("href");if(M&&!ke.has(M)){let W=document.createElement("link");W.rel="stylesheet",W.href=M,document.head.appendChild(W)}}),Xe(d,o).then(()=>{try{Je(),b()}catch(y){try{let M=globalThis.__krate_onHydrationError;typeof M=="function"&&M(y)}catch{}location.href=o}}),x();let Ze=location.pathname+location.search;if(m)history.replaceState({},"",o);else{if(!P){if(_.size>=Dt){let y=_.keys().next().value;y!==void 0&&_.delete(y)}_.set(Ze,window.scrollY)}history.pushState({},"",o)}pe(o,{restoreScroll:P,scroll:H}),he(),window.dispatchEvent(new CustomEvent("krate:navigate",{detail:{url:o}})),D(o)}function We(s){let o=s.indexOf("#");if(o<0||o===s.length-1)return!1;let d=s.slice(o);try{let f=document.querySelector(d);if(f)return f.scrollIntoView({behavior:"smooth",block:"start"}),!0}catch{return!1}return!1}function pe(s,o){if(o.restoreScroll){let d=_.get(s);if(d!==void 0){window.scrollTo(0,d);return}}We(s)||o.scroll&&window.scrollTo(0,0)}function he(){let s=location.pathname;document.querySelectorAll("a[data-krate-link]").forEach(o=>{let d=o.getAttribute("href");if(!d){o.removeAttribute("aria-current");return}let f=d;try{f=new URL(d,location.origin).pathname}catch{return}f===s||s==="/"&&(f===""||f==="/")||f!=="/"&&f.length>1&&s.startsWith(f)?o.setAttribute("aria-current","page"):o.removeAttribute("aria-current")})}function Xe(s,o){return s.length===0?Promise.resolve():Promise.all(s.map(d=>{let f=d.getAttribute("src");return f?Ge(f,o):Promise.resolve()})).then(()=>{})}function Ge(s,o){return new Promise(d=>{let f=document.createElement("script"),m=Te(s,o);f.src=m,ze.test(m)||f.setAttribute("data-krate-spa",""),f.onload=()=>d(),f.onerror=()=>d(),document.body.appendChild(f)})}function Te(s,o){if(/^(https?:)?\/\//.test(s)||s.startsWith("/"))return new URL(s,o).href;let d=o;if(!d.endsWith("/")){let f=d.lastIndexOf("/");d=f>0?d.slice(0,f+1):"/"}return new URL(s,d).href}function Je(){typeof globalThis.__krate_hydrate=="function"&&globalThis.__krate_hydrate()}function Ye(s,o){typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),history.pushState({},"",o),D(o),document.open(),document.write(s),document.close()}function $e(){return r!==null?Promise.resolve(r):fetch("/404.html",{headers:{Accept:"text/html"}}).then(s=>s.ok?s.text():null).then(s=>(r=s,s)).catch(()=>null)}function Qe(){return i!==null?Promise.resolve(i):fetch("/500.html",{headers:{Accept:"text/html"}}).then(s=>s.ok?s.text():null).then(s=>(i=s,s)).catch(()=>null)}function ve(s,o){document.querySelectorAll("script[data-krate-spa]").forEach(m=>m.remove());let d=[],f=new Set;return document.querySelectorAll("script[src]").forEach(m=>{f.add(m.src)}),s.querySelectorAll("script[src]").forEach(m=>{let H=m.getAttribute("src");H&&!f.has(Te(H,o))&&d.push(m)}),d}function Ee(s,o={}){let d=C.get(s);if(d){let H=new DOMParser().parseFromString(d,"text/html");w(d,s,ve(H,s),o);return}me(),I&&I.abort(),I=new AbortController;let f=I.signal;fetch(s,{headers:{Accept:"text/html"},signal:f}).then(m=>m.ok?m.text().then(H=>{let ye=new DOMParser().parseFromString(H,"text/html");w(H,s,ve(ye,s),o)}):(m.status>=500?Qe():$e()).then(P=>{P?Ye(P,s):location.href=s})).catch(m=>{m?.name!=="AbortError"&&(x(),location.href=s)}).finally(()=>{I&&!f.aborted&&(I=void 0)})}let He=s=>{if(s.defaultPrevented||s.button!==0||s.metaKey||s.ctrlKey||s.shiftKey||s.altKey)return;let o=s.target.closest("a[data-krate-link]");if(!o||!c(o))return;s.preventDefault();let d=o.getAttribute("href");if(!d)return;let f=new URL(d,location.origin).href,m=o.hasAttribute("data-krate-replace"),H=o.getAttribute("data-krate-scroll")!=="false";if(d===location.pathname+location.search+location.hash){m&&history.replaceState({},"",d),pe(f,{scroll:H});return}Ee(f,{replace:m,scroll:H})},Ae=()=>{Ee(location.href,{restoreScroll:!0})};document.addEventListener("click",He),window.addEventListener("popstate",Ae),v(),he(),document.querySelectorAll("script[src]").forEach(s=>{ze.test(s.src)||s.setAttribute("data-krate-spa","")}),F=()=>{document.removeEventListener("click",He),window.removeEventListener("popstate",Ae),g()}}function Bt(){F&&(F(),F=null),de=!1,Fe()}function ge(e,t){if(!(e==null||e===!1||e===!0||e==="")){if(typeof e=="string"||typeof e=="number"){t.push(String(e));return}if(Array.isArray(e)){for(let n of e)ge(n,t);return}if(typeof e=="object")for(let n of Object.keys(e))e[n]&&t.push(n)}}function fe(...e){let t=[];for(let n of e)ge(n,t);return t.join(" ")}function be(...e){let t=[];for(let i of e)ge(i,t);let n=new Map,r=[];for(let i of t){let a=Vt(i);n.has(a)||r.push(a),n.set(a,i)}return r.map(i=>n.get(i)).join(" ")}function Vt(e){let t=e,n="",r=t.lastIndexOf(":");r>=0&&(n=t.slice(0,r+1),t=t.slice(r+1));let i=t.indexOf("-"),a=i>=0?t.slice(0,i):t,l=i>=0?t.slice(i+1,i+2):"";return n+a+(l&&/[0-9]/.test(l)?"-"+l:"")}function Kt(...e){return be(fe(...e))}function qt(e,t){let n=t?.variants??{},r=t?.defaultVariants??{};return i=>{let a={};for(let c of Object.keys(n)){let u=i?.[c]??r[c];u!=null&&(a[c]=String(u))}let l=[e];for(let c of Object.keys(n)){let u=a[c];u&&n[c][u]&&l.push(n[c][u])}for(let c of t?.compoundVariants??[])if(zt(c,a,r)){let u=c.class;typeof u=="string"&&l.push(u)}let h=i?.class??i?.className;return typeof h=="string"&&l.push(h),be(fe(l))}}function zt(e,t,n){for(let r of Object.keys(e)){if(r==="class")continue;let i=e[r],a=t[r]??n[r]??void 0;if(Array.isArray(i)){if(!i.includes(a))return!1}else if(i!==a)return!1}return!0}function Ft(e){let t=je(e?.children);return t?(Ue(t,e),t):null}function je(e){if(e==null)return null;if(Array.isArray(e)){for(let t of e){let n=je(t);if(n)return n}return null}return e instanceof Node?e:null}function Ue(e,t){if(e instanceof Element)for(let n of Object.keys(t)){if(n==="children"||n==="ref")continue;let r=t[n];if(!(r==null||r===!1)){if(n==="class"||n==="className"){let i=e.getAttribute("class"),a=i?i+" "+String(r):String(r);e.setAttribute("class",a);continue}if(n==="style"&&typeof r=="object"){for(let[i,a]of Object.entries(r))e.style.setProperty(jt(i),String(a));continue}if(n.startsWith("on")&&typeof r=="function"){e[n]=r;continue}if(r===!0){e.setAttribute(n,"");continue}e.setAttribute(n,String(r))}}}function jt(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function Ut(e,t,...n){if(!(e instanceof Node))return e;if(t&&Ue(e,t),n.length>0&&e instanceof Element){e.textContent="";for(let r of n)r instanceof Node?e.appendChild(r):r!=null&&e.appendChild(document.createTextNode(String(r)))}return e}return st(Wt);})();
|
|
1
|
+
var __krate_exports=(()=>{var Q=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var gt=Object.prototype.hasOwnProperty;var ft=(e,t)=>{for(var n in t)Q(e,n,{get:t[n],enumerable:!0})},bt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of dt(t))!gt.call(e,s)&&s!==n&&Q(e,s,{get:()=>t[s],enumerable:!(r=ct(t,s))||r.enumerable});return e};var mt=e=>bt(Q({},"__esModule",{value:!0}),e);var an={};ft(an,{Fragment:()=>zt,Slot:()=>rn,clearNodes:()=>Ke,clearPersisted:()=>Et,cloneElement:()=>on,clsx:()=>Te,cn:()=>en,conditional:()=>Wt,createCSSChoice:()=>Ht,createCSSFlags:()=>Lt,createCSSGroup:()=>St,createCSSRange:()=>xt,createCSSStack:()=>kt,createCSSToggle:()=>Mt,createContext:()=>ee,createEffect:()=>x,createMemo:()=>Rt,createReducer:()=>Ot,createResource:()=>qt,createScope:()=>ht,createScopeFlags:()=>Tt,createSignal:()=>y,cva:()=>tn,disposeAll:()=>At,disposeNode:()=>L,forwardRef:()=>_t,h:()=>U,hydrate:()=>Ft,initRouter:()=>Ge,insert:()=>Bt,jsx:()=>Fe,jsxs:()=>jt,mount:()=>Vt,navigate:()=>$t,onCleanup:()=>j,onMount:()=>Pt,readDurableState:()=>ie,readPersisted:()=>se,reconcile:()=>Ut,reconcileTrees:()=>Xt,reinitRouter:()=>Qt,resetContexts:()=>Z,resolvePersist:()=>re,subscribePersist:()=>ae,twMerge:()=>ve,useRef:()=>It,writePersisted:()=>oe});var pt=0,R=new Map;function Z(){for(let[e,t]of R)if(t.length>0){let n=t[0];R.set(e,[n])}}function ht(){return ee({})}function Tt(){return ee({})}function ee(e){let t=pt++;R.set(t,[e]);let n=()=>{let r=R.get(t);return r&&r.length>0?r[r.length-1]:e};return{id:t,defaultValue:e,Provider:r=>{let s=R.get(t)||[e];s.push(r.value),R.set(t,s);let a=document.createElement("div");if(a.style.display="contents",r.children)for(let u of r.children)u instanceof Node?a.appendChild(u):u!=null&&a.appendChild(document.createTextNode(String(u)));return s.pop(),s.length===0&&s.push(e),a},useContext:n,use:n}}function vt(){let e=new Map;return{getItem:t=>e.has(t)?e.get(t):null,setItem:(t,n)=>{e.set(t,n)},removeItem:t=>{e.delete(t)}}}var te=vt();function Re(){return typeof window<"u"}function ne(e){if(e&&typeof e=="object")return e;if(!Re())return te;try{return e==="session"?window.sessionStorage:e==="memory"?te:window.localStorage}catch{return te}}function re(e){let t=typeof e=="string"?{key:e}:e;if(!t.key)throw new Error("[krate] createSignal persist requires a key");let n=t.store??"local";return{key:t.key,store:n,serialize:t.serialize??(r=>JSON.stringify(r)),deserialize:t.deserialize??(r=>JSON.parse(r)),sync:t.sync??n==="local"}}function ie(e,t){let r=globalThis.__KRATE_STATE__;if(!r||!Object.prototype.hasOwnProperty.call(r,e))return{found:!1};let s=r[e];if(typeof s=="string")try{return{found:!0,value:t(s)}}catch{return{found:!0,value:s}}return{found:!0,value:s}}function se(e){let t=ne(e.store),n;try{n=t.getItem(e.key)}catch{return{found:!1}}if(n==null)return{found:!1};try{return{found:!0,value:e.deserialize(n)}}catch{return{found:!1}}}function oe(e,t){let n=ne(e.store);try{n.setItem(e.key,e.serialize(t))}catch{}}function Et(e){let t=ne(e.store);try{t.removeItem(e.key)}catch{}}var V=new Map,Ne=!1;function yt(){Ne||!Re()||(Ne=!0,window.addEventListener("storage",e=>{if(e.key===null)return;let t=V.get(e.key);if(t)for(let n of t)n(e.newValue)}))}function ae(e,t){if(!e.sync)return()=>{};let n=V.get(e.key)??new Set;return n.add(t),V.set(e.key,n),yt(),()=>{n.delete(t),n.size===0&&V.delete(e.key)}}var C=[],Oe=[],ue=!1,O=new Set,le=[],ce=[],F=!1;function Ie(e){return{fn:e,cleanups:[],disposed:!1,sources:new Set,running:!1,rerun:!1,queued:!1}}function de(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 At(){for(let e of O)de(e);O.clear();for(let e of le)try{e()}catch{}le.length=0,ce.length=0,F=!1,Z()}function Ht(e,t){return z(y(e))}function Mt(e,t){return z(y(e))}function Lt(e,t){let n={};for(let a of e){let[u]=y(!1);n[a]=u}let s=[n,(a,u)=>{}];return s.trigger=a=>({"data-krate-scope":"trigger",value:a}),s.panel=a=>({"data-krate-scope":"panel",value:a}),s.close=()=>({"data-krate-scope":"close"}),s}function St(e,t){return z(y(e))}function xt(e,t){return z(y(e))}function z(e){let t=e;return t.trigger=n=>({"data-krate-scope":"trigger",value:n}),t.panel=n=>({"data-krate-scope":"panel",value:n}),t.close=()=>({"data-krate-scope":"close"}),t.current=()=>e[0](),t}function kt(e,t){let n=()=>e[0];return[{top:n,peek:n},{push:r=>{},pop:()=>{},clear:()=>{}}]}function y(e,t){let n=e,r=null;if(t?.persist){r=re(t.persist);let d=ie(r.key,r.deserialize);if(d.found)n=d.value;else{let l=se(r);l.found&&(n=l.value)}}let s=new Set,a=()=>{let d=C[C.length-1];return d&&!d.disposed&&(s.add(d),d.sources.add(s)),n},u=()=>{let d=Array.from(s);for(let l of d){if(l.disposed){s.delete(l);continue}if(l.running){l.rerun=!0;continue}l.queued||(l.queued=!0,ce.push(l))}wt()},T=d=>{let l=typeof d=="function"?d(n):d;l!==n&&(n=l,r&&oe(r,n),u())};if(r&&r.sync){let d=r,l=ae(d,m=>{if(m!==null)try{let b=d.deserialize(m);b!==n&&(n=b,u())}catch{}});j(l)}return[a,T]}function wt(){F||(F=!0,queueMicrotask(Ct))}function Ct(){F=!1;let e=ce.splice(0);for(let t of e)t.disposed||(t.queued=!1,t.rerun=!1,q(t),t.rerun&&!t.disposed&&(t.rerun=!1,q(t)))}function q(e){e.running=!0;for(let t of e.cleanups)t();e.cleanups.length=0,C.push(e);try{let t=e.fn();typeof t=="function"&&e.cleanups.push(t)}finally{C.pop(),e.running=!1}}function x(e){let t=Ie(e);return O.add(t),q(t),()=>{de(t),O.delete(t)}}function j(e){let t=C[C.length-1];t?t.cleanups.push(e):le.push(e)}function Pt(e){Oe.push(e),ue||(ue=!0,queueMicrotask(Nt))}function Nt(){ue=!1;let e=Oe.splice(0);for(let t of e)t()}function Rt(e){let[t,n]=y(void 0),r=Ie(()=>{let a=e();n(a)});O.add(r),q(r);let s=C[C.length-1];return s&&s.cleanups.push(()=>{r.disposed||(de(r),O.delete(r))}),t}function Ot(e,t){let[n,r]=y(t);return[n,a=>r(u=>e(u,a))]}function It(e){return{current:e}}function _t(e){return t=>e(t,t.ref||(()=>{}))}var Dt={doubleclick:"dblclick",focus:"focusin",blur:"focusout",change:"input"},ge=new WeakMap;function De(e,t){let n=ge.get(e);n||(n=[],ge.set(e,n)),n.push(t)}function L(e){let t=ge.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 Kt(e){let t=e.nextSibling;for(;t;){if(t.nodeType===8&&t.nodeValue==="k")return t;t=t.nextSibling}return null}function Ke(e,t){let n=e.parentNode;if(!n)return;let r=e.nextSibling;for(;r&&r!==t;){let s=r.nextSibling;L(r),n.removeChild(r),r=s}}function Bt(e,t,n){let r=Kt(n);r?(Ke(n,r),fe(e,t,r)):fe(e,t,null)}function fe(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)fe(e,r,n)}}function _e(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(),s=Dt[r]||r,a=`__krate_${s}`,u=e[a];u&&e.removeEventListener(s,u),e.addEventListener(s,n),e[a]=n}else t==="value"||t==="checked"||t==="selected"?t==="value"?e.value=n==null||n===!1?"":n:e[t]=!!n: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 Be(e,t){if(!(t==null||t===!1||t===!0)){if(Array.isArray(t)){for(let n of t)Be(e,n);return}if(typeof t=="function"){let n=document.createTextNode("");e.appendChild(n),De(n,x(()=>{n.nodeValue=String(t())}));return}e.appendChild(t instanceof Node?t:document.createTextNode(String(t)))}}function U(e,t,...n){if(typeof e=="function")return e({...t||{},children:n});let r=document.createElement(e);if(t)for(let[s,a]of Object.entries(t))typeof a=="function"&&!s.startsWith("on")?De(r,x(()=>_e(r,s,a()))):_e(r,s,a);for(let s of n)Be(r,s);return r}function Ve(e){if(typeof e=="string"){let t=document.querySelector(e);if(!t)throw new Error(`Container "${e}" not found`);return t}return e}function Vt(e,t){let n=Ve(t),r=!1;x(()=>{r||(r=!0,n.appendChild(e()))})}function Ft(e,t){let n=Ve(t);if(n.childNodes.length===0){n.appendChild(e());return}let r=e();r&&L(r)}function qt(e,t){let[n,r]=y(void 0),[s,a]=y(!0),[u,T]=y(void 0),[d,l]=y("unresolved"),[m,b]=y(0),f,E=()=>typeof e=="function"?e():e,v=async()=>{f&&f.abort(),f=new AbortController;let S=f,K=E();l(m()>0?"refreshing":"loading"),a(!0),T(void 0);try{let k=await t(K,{signal:S.signal});S.signal.aborted||(r(()=>k),l("ready"))}catch(k){k?.name!=="AbortError"&&!S.signal.aborted&&(T(k),l("error"))}finally{S.signal.aborted||a(!1)}};x(()=>{typeof e=="function"&&e.length===0&&e(),m(),v(),j(()=>{f&&(f.abort(),f=void 0)})});let A=function(){return n()};return Object.defineProperties(A,{loading:{get:()=>s()},error:{get:()=>u()},state:{get:()=>d()}}),[A,{mutate:S=>{r(S)},refetch:()=>{b(S=>S+1)}}]}function zt(e){let t=document.createDocumentFragment(),n=e.children;if(n){let r=Array.isArray(n)?n:[n];for(let s of r)s instanceof Node?t.appendChild(s):t.appendChild(document.createTextNode(String(s)))}return t}function Fe(e,t,n){let r=e;if(!t)return U(r,null);let{children:s,...a}=t,u=s!==void 0?Array.isArray(s)?s:[s]:[];return U(r,Object.keys(a).length>0?a:null,...u)}function jt(e,t,n){return Fe(e,t,n)}function Ut(e,t,n,r,s,a){let u=[],T=t.nextSibling;for(;T&&T!==n;)u.push(T),T=T.nextSibling;if(a){let d=new Map;for(let m of u){let b=m.__k;b!=null&&!d.has(b)&&d.set(b,m)}let l=[];for(let m=0;m<r.length;m++){let b=a(r[m]),f=d.get(b);f?d.delete(b):(f=s(r[m],m),f.__k=b),l.push(f)}for(let m of d.values())m.parentNode===e&&(L(m),e.removeChild(m));for(let m=0;m<l.length;m++){let b=m===0?t:l[m-1];l[m]!==b.nextSibling&&e.insertBefore(l[m],b.nextSibling)}}else{let d=Math.max(u.length,r.length);for(let l=0;l<d;l++)if(l<r.length){let m=s(r[l],l);l<u.length?u[l]!==m&&(L(u[l]),e.replaceChild(m,u[l])):e.insertBefore(m,n)}else l<u.length&&u[l].parentNode===e&&(L(u[l]),e.removeChild(u[l]))}}function Wt(e,t,n,r,s,a){let u=null;x(()=>{let d=r()?s():a?a():null;u?d?(L(u),e.replaceChild(d,u)):(L(u),e.removeChild(u)):d&&e.insertBefore(d,n),u=d})}function I(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 qe(e,t){let n=new Set;for(let r=0;r<t.attributes.length;r++){let s=t.attributes[r].name,a=t.attributes[r].value;n.add(s),e.getAttribute(s)!==a&&e.setAttribute(s,a)}for(let r=0;r<e.attributes.length;r++){let s=e.attributes[r].name;n.has(s)||e.removeAttribute(s)}}function be(e,t){let n=document.importNode(t,!0);return e.parentNode&&(L(e),e.parentNode.replaceChild(n,e)),n}function ze(e,t){return e.nodeType!==t.nodeType?!1:e.nodeType===Node.ELEMENT_NODE?e.tagName===t.tagName:!0}function me(e,t){if(!ze(e,t))return be(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?be(e,t):e;if(e.nodeType!==Node.ELEMENT_NODE)return e;let n=e,r=t;return I(n)!==I(r)?be(n,r):(qe(n,r),je(n,r),n)}function je(e,t){let n=Array.from(e.childNodes),r=Array.from(t.childNodes);if(n.length===r.length){let b=!0;for(let f=0;f<r.length;f++)if(I(n[f])!==I(r[f])){b=!1;break}if(b){for(let f=0;f<r.length;f++)me(n[f],r[f]);return}}let s=new Map,a=[];n.forEach((b,f)=>{let E=I(b);E!=null?s.has(E)||s.set(E,f):a.push(f)});let u=new Set,T=0,d=null,l=0,m=()=>{for(;l<a.length&&u.has(a[l]);)l++;return l<a.length?a[l]:-1};for(let b of r){let f=I(b),E;if(f!=null&&s.has(f)){let v=s.get(f);s.delete(f),u.add(v);let A=n[v];v<T?e.insertBefore(A,d):T=v,E=me(A,b)}else if(f==null){let v=m();if(v>=0&&ze(n[v],b)){u.add(v);let A=n[v];A.parentNode===e&&A.nextSibling!==d&&e.insertBefore(A,d),E=me(A,b)}else E=document.importNode(b,!0),e.insertBefore(E,d)}else E=document.importNode(b,!0),e.insertBefore(E,d);d=E.nextSibling}n.forEach((b,f)=>{!u.has(f)&&b.parentNode===e&&(L(b),e.removeChild(b))})}function Xt(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 s=document.importNode(t,!0);n.parentNode&&n.parentNode.replaceChild(s,n);return}qe(n,r),je(n,r)}var pe=!1,_,X=null,W=0,P=new Map,Gt=30,D=new Map,Jt=50,Ue=/\/chunks\/runtime\.[^/]+\.js$/;function Xe(){return globalThis.__KRATE_CFG__||{}}function Yt(){let e=Xe().basePath||"";return!e||e==="/"?"":"/"+e.replace(/^\/+|\/+$/g,"")}function We(e){let t=Yt();if(t&&(e===t||e.startsWith(t+"/"))){let n=e.slice(t.length);return n===""?"/":n}return e}var G=null;function $t(e,t={}){return G?(G(e,t),!1):(typeof location<"u"&&(location.href=e),!0)}function Ge(){if(typeof document>"u"||pe)return;pe=!0;let e="#root, main, .docs-content",t=150,n=200,r=null,s=null,a=new Map,u=null;function T(i){for(let o of e.split(", ")){let c=i.querySelector(o.trim());if(c)return c}return i.body}function d(i){if(i.hasAttribute("data-krate-external"))return!1;let o=i.getAttribute("href");return!(!o||o.startsWith("#")||o.startsWith("javascript:")||i.origin!==location.origin||i.target==="_blank")}function l(i){P.has(i)||fetch(i,{headers:{Accept:"text/html"}}).then(o=>o.ok?o.text():null).then(o=>{if(o){if(P.size>=Gt){let c=P.keys().next().value;c!==void 0&&P.delete(c)}P.set(i,o)}}).catch(()=>{})}function m(){document.addEventListener("mouseover",E),document.addEventListener("focusin",E),typeof IntersectionObserver<"u"&&(u=new IntersectionObserver(i=>{for(let o of i)if(o.isIntersecting){let c=o.target,g=c.getAttribute("href");if(g&&d(c)){let p=new URL(g,location.origin).href;l(p)}u.unobserve(o.target)}},{rootMargin:"200px"}),b())}function b(){u&&document.querySelectorAll("a[data-prefetch]").forEach(i=>{u.observe(i)})}function f(){document.removeEventListener("mouseover",E),document.removeEventListener("focusin",E);for(let i of a.values())clearTimeout(i);a.clear(),u&&(u.disconnect(),u=null)}function E(i){let o=i.target.closest("a[data-prefetch]");if(!o||!d(o))return;let c=o.getAttribute("href");if(!c)return;let g=new URL(c,location.origin).href;if(P.has(g))return;let p=a.get(o);p&&clearTimeout(p);let h=setTimeout(()=>{a.delete(o),l(g)},n);a.set(o,h)}let v=null;function A(){if(k())return;let i=T(document),o=document.querySelector("template[data-krate-loading]");o&&o.content&&i&&(v=o.content.cloneNode(!0),document.body.appendChild(v)),i&&(i.style.transition=`opacity ${t}ms ease`,i.style.opacity="0")}function J(){if(k())return;v&&v.parentNode&&v.parentNode.removeChild(v),v=null;let i=T(document);i&&(i.style.opacity="1")}function S(i){try{let o=globalThis.__krate_onNavigation;typeof o=="function"&&o(i)}catch{}}function K(i,o){try{window.dispatchEvent(new CustomEvent(i,{detail:{url:o}}))}catch{}}function k(){if(Xe().viewTransitions===!1)return!1;if(typeof window<"u"&&window.matchMedia)try{if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return!1}catch{}return typeof document.startViewTransition=="function"}function $e(i){let o=i.querySelectorAll('link[rel="stylesheet"]'),c=new Set;o.forEach(p=>{let h=p.getAttribute("href");h&&c.add(new URL(h,location.origin).href)}),document.querySelectorAll('link[rel="stylesheet"]').forEach(p=>{let h=p.href;h&&!c.has(h)&&p.remove()});let g=new Set;document.querySelectorAll('link[rel="stylesheet"]').forEach(p=>g.add(p.href)),o.forEach(p=>{let h=p.getAttribute("href");if(!h)return;let H=new URL(h,location.origin).href;if(!g.has(H)){let w=document.createElement("link");w.rel="stylesheet",w.href=H,document.head.appendChild(w)}})}function Ee(i){i.querySelectorAll("[data-view-transition]").forEach(o=>{let c=o.getAttribute("data-view-transition");c&&(o.style.viewTransitionName=c)})}function Qe(){let i=T(document);if(i){i.hasAttribute("tabindex")||i.setAttribute("tabindex","-1");try{i.focus({preventScroll:!0})}catch{try{i.focus()}catch{}}}}function Ze(){let i=HTMLScriptElement.supports;if(!(typeof i!="function"||!i("speculationrules")))try{let o=document.createElement("script");o.type="speculationrules",o.textContent=JSON.stringify({prefetch:[{where:{and:[{href_matches:"/*"},{not:{href_matches:"/__krate/*"}},{not:{href_matches:"/api/*"}}]},eagerness:"moderate"}]}),document.head.appendChild(o)}catch{}}function ye(i){return i.getElementById("root")||i.body}let Ae='meta[name="description"], meta[property^="og:"], meta[name^="twitter:"], link[rel="canonical"], script[type="application/ld+json"]';function et(i){document.head.querySelectorAll(Ae).forEach(o=>o.remove()),i.head.querySelectorAll(Ae).forEach(o=>{document.head.appendChild(document.importNode(o,!0))})}function He(i,o,c,g={}){let{replace:p=!1,scroll:h=!0,restoreScroll:H=!1}=g,N=new DOMParser().parseFromString(i,"text/html"),Ce=ye(N),Pe=ye(document);if(!Ce||!Pe){location.href=o;return}K("krate:navigate-start",o);let $=()=>{let M=N.querySelector("title");M&&(document.title=M.textContent||""),typeof globalThis.disposeAll=="function"&&globalThis.disposeAll();let B=Array.from(Ce.childNodes).map(lt=>document.importNode(lt,!0));Pe.replaceChildren(...B),$e(N),et(N),Ee(document)};if(k())try{let M=document.startViewTransition($);M&&M.finished&&typeof M.finished.catch=="function"&&M.finished.catch(()=>{})}catch{$()}else $();nt(c,o).then(()=>{try{it(),b()}catch(M){try{let B=globalThis.__krate_onHydrationError;typeof B=="function"&&B(M)}catch{}location.href=o}}),J();let ut=location.pathname+location.search;if(p)history.replaceState({},"",o);else{if(!H){if(D.size>=Jt){let M=D.keys().next().value;M!==void 0&&D.delete(M)}D.set(ut,window.scrollY)}history.pushState({},"",o)}Me(o,{restoreScroll:H,scroll:h}),H||Qe(),Le(),window.dispatchEvent(new CustomEvent("krate:navigate",{detail:{url:o}})),K("krate:navigate-end",o),S(o)}function tt(i){let o=i.indexOf("#");if(o<0||o===i.length-1)return!1;let c=i.slice(o);try{let g=document.querySelector(c);if(g)return g.scrollIntoView({behavior:"smooth",block:"start"}),!0}catch{return!1}return!1}function Me(i,o){if(o.restoreScroll){let c=D.get(i);if(c!==void 0){window.scrollTo(0,c);return}}tt(i)||o.scroll&&window.scrollTo(0,0)}function Le(){let i=We(location.pathname);document.querySelectorAll("a[data-krate-link]").forEach(o=>{let c=o.getAttribute("href");if(!c){o.removeAttribute("aria-current");return}let g=c;try{g=We(new URL(c,location.origin).pathname)}catch{return}g===i||i==="/"&&(g===""||g==="/")||g!=="/"&&g.length>1&&i.startsWith(g)?o.setAttribute("aria-current","page"):o.removeAttribute("aria-current")})}function nt(i,o){return i.length===0?Promise.resolve():Promise.all(i.map(c=>{let g=c.getAttribute("src");return g?rt(g,o):Promise.resolve()})).then(()=>{})}function rt(i,o){return new Promise(c=>{let g=document.createElement("script"),p=Se(i,o);g.src=p,Ue.test(p)||g.setAttribute("data-krate-spa",""),g.onload=()=>c(),g.onerror=()=>c(),document.body.appendChild(g)})}function Se(i,o){if(/^(https?:)?\/\//.test(i)||i.startsWith("/"))return new URL(i,o).href;let c=o;if(!c.endsWith("/")){let g=c.lastIndexOf("/");c=g>0?c.slice(0,g+1):"/"}return new URL(i,c).href}function it(){typeof globalThis.__krate_hydrate=="function"&&globalThis.__krate_hydrate()}function st(i,o){typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),history.pushState({},"",o),S(o),document.open(),document.write(i),document.close()}function ot(){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 at(){return s!==null?Promise.resolve(s):fetch("/500.html",{headers:{Accept:"text/html"}}).then(i=>i.ok?i.text():null).then(i=>(s=i,i)).catch(()=>null)}function xe(i,o){document.querySelectorAll("script[data-krate-spa]").forEach(p=>p.remove());let c=[],g=new Set;return document.querySelectorAll("script[src]").forEach(p=>{g.add(p.src)}),i.querySelectorAll("script[src]").forEach(p=>{let h=p.getAttribute("src");h&&!g.has(Se(h,o))&&c.push(p)}),c}function Y(i,o={}){let c=++W,g=P.get(i);if(g){let H=new DOMParser().parseFromString(g,"text/html");He(g,i,xe(H,i),o);return}A(),_&&_.abort(),_=new AbortController;let p=_.signal;fetch(i,{headers:{Accept:"text/html"},signal:p}).then(h=>{if(c===W)return h.ok?h.text().then(H=>{if(c!==W)return;let N=new DOMParser().parseFromString(H,"text/html");He(H,i,xe(N,i),o)}):(h.status>=500?at():ot()).then(w=>{c===W&&(w?st(w,i):location.href=i)})}).catch(h=>{h?.name!=="AbortError"&&(J(),location.href=i)}).finally(()=>{_&&!p.aborted&&(_=void 0)})}let ke=i=>{if(i.defaultPrevented||i.button!==0||i.metaKey||i.ctrlKey||i.shiftKey||i.altKey)return;let o=i.target.closest("a[data-krate-link]");if(!o||!d(o))return;i.preventDefault();let c=o.getAttribute("href");if(!c)return;let g=new URL(c,location.origin).href,p=o.hasAttribute("data-krate-replace"),h=o.getAttribute("data-krate-scroll")!=="false";if(c===location.pathname+location.search+location.hash){p&&history.replaceState({},"",c),Me(g,{scroll:h});return}Y(g,{replace:p,scroll:h})},we=()=>{Y(location.href,{restoreScroll:!0})};document.addEventListener("click",ke),window.addEventListener("popstate",we),m(),Ze(),Le(),Ee(document),G=(i,o={})=>{let c=!0;try{c=new URL(i,location.href).origin===location.origin}catch{c=!1}if(!c){location.href=i;return}Y(new URL(i,location.href).href,o)},document.querySelectorAll("script[src]").forEach(i=>{Ue.test(i.src)||i.setAttribute("data-krate-spa","")}),X=()=>{document.removeEventListener("click",ke),window.removeEventListener("popstate",we),f(),G=null}}function Qt(){X&&(X(),X=null),pe=!1,Ge()}function he(e,t){if(!(e==null||e===!1||e===!0||e==="")){if(typeof e=="string"||typeof e=="number"){t.push(String(e));return}if(Array.isArray(e)){for(let n of e)he(n,t);return}if(typeof e=="object")for(let n of Object.keys(e))e[n]&&t.push(n)}}function Te(...e){let t=[];for(let n of e)he(n,t);return t.join(" ")}function ve(...e){let t=[];for(let s of e)he(s,t);let n=new Map,r=[];for(let s of t){let a=Zt(s);n.has(a)||r.push(a),n.set(a,s)}return r.map(s=>n.get(s)).join(" ")}function Zt(e){let t=e,n="",r=t.lastIndexOf(":");r>=0&&(n=t.slice(0,r+1),t=t.slice(r+1));let s=t.indexOf("-"),a=s>=0?t.slice(0,s):t,u=s>=0?t.slice(s+1,s+2):"";return n+a+(u&&/[0-9]/.test(u)?"-"+u:"")}function en(...e){return ve(Te(...e))}function tn(e,t){let n=t?.variants??{},r=t?.defaultVariants??{};return s=>{let a={};for(let d of Object.keys(n)){let l=s?.[d]??r[d];l!=null&&(a[d]=String(l))}let u=[e];for(let d of Object.keys(n)){let l=a[d];l&&n[d][l]&&u.push(n[d][l])}for(let d of t?.compoundVariants??[])if(nn(d,a,r)){let l=d.class;typeof l=="string"&&u.push(l)}let T=s?.class??s?.className;return typeof T=="string"&&u.push(T),ve(Te(u))}}function nn(e,t,n){for(let r of Object.keys(e)){if(r==="class")continue;let s=e[r],a=t[r]??n[r]??void 0;if(Array.isArray(s)){if(!s.includes(a))return!1}else if(s!==a)return!1}return!0}function rn(e){let t=Je(e?.children);return t?(Ye(t,e),t):null}function Je(e){if(e==null)return null;if(Array.isArray(e)){for(let t of e){let n=Je(t);if(n)return n}return null}return e instanceof Node?e:null}function Ye(e,t){if(e instanceof Element)for(let n of Object.keys(t)){if(n==="children"||n==="ref")continue;let r=t[n];if(!(r==null||r===!1)){if(n==="class"||n==="className"){let s=e.getAttribute("class"),a=s?s+" "+String(r):String(r);e.setAttribute("class",a);continue}if(n==="style"&&typeof r=="object"){for(let[s,a]of Object.entries(r))e.style.setProperty(sn(s),String(a));continue}if(n.startsWith("on")&&typeof r=="function"){e[n]=r;continue}if(r===!0){e.setAttribute(n,"");continue}e.setAttribute(n,String(r))}}}function sn(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function on(e,t,...n){if(!(e instanceof Node))return e;if(t&&Ye(e,t),n.length>0&&e instanceof Element){e.textContent="";for(let r of n)r instanceof Node?e.appendChild(r):r!=null&&e.appendChild(document.createTextNode(String(r)))}return e}return mt(an);})();
|
|
2
2
|
for (const k in __krate_exports) { window[k] = __krate_exports[k]; }
|
package/dist/reconcile.js
CHANGED
|
@@ -21,37 +21,41 @@ export function reconcile(parent, startMarker, endMarker, items, mapFn, keyFn) {
|
|
|
21
21
|
node = node.nextSibling;
|
|
22
22
|
}
|
|
23
23
|
if (keyFn) {
|
|
24
|
-
// Keyed reconciliation
|
|
25
|
-
|
|
24
|
+
// Keyed reconciliation: reuse the existing node for a key still present
|
|
25
|
+
// (preserving DOM state such as focus/scroll), create nodes only for new
|
|
26
|
+
// keys, then drop stale nodes and reorder.
|
|
27
|
+
const existingByKey = new Map();
|
|
26
28
|
for (const child of existing) {
|
|
27
29
|
const key = child.__k;
|
|
28
|
-
if (key != null)
|
|
29
|
-
|
|
30
|
+
if (key != null && !existingByKey.has(key))
|
|
31
|
+
existingByKey.set(key, child);
|
|
30
32
|
}
|
|
31
33
|
const newNodes = [];
|
|
32
|
-
const usedKeys = new Set();
|
|
33
34
|
for (let i = 0; i < items.length; i++) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const key = keyFn(items[i]);
|
|
36
|
+
let node = existingByKey.get(key);
|
|
37
|
+
if (node) {
|
|
38
|
+
// Consume the key so a later duplicate key falls back to a fresh node.
|
|
39
|
+
existingByKey.delete(key);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
node = mapFn(items[i], i);
|
|
43
|
+
node.__k = key;
|
|
44
|
+
}
|
|
45
|
+
newNodes.push(node);
|
|
40
46
|
}
|
|
41
|
-
// Remove nodes whose keys are no longer present
|
|
42
|
-
for (const
|
|
43
|
-
if (
|
|
47
|
+
// Remove nodes whose keys are no longer present.
|
|
48
|
+
for (const child of existingByKey.values()) {
|
|
49
|
+
if (child.parentNode === parent) {
|
|
44
50
|
disposeNode(child);
|
|
45
51
|
parent.removeChild(child);
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
|
-
// Reorder: insert nodes in the correct order before endMarker
|
|
54
|
+
// Reorder: insert nodes in the correct order before endMarker.
|
|
49
55
|
for (let i = 0; i < newNodes.length; i++) {
|
|
50
|
-
const newNode = newNodes[i];
|
|
51
|
-
// Find the node that should be before this one
|
|
52
56
|
const prevNode = i === 0 ? startMarker : newNodes[i - 1];
|
|
53
|
-
if (
|
|
54
|
-
parent.insertBefore(
|
|
57
|
+
if (newNodes[i] !== prevNode.nextSibling) {
|
|
58
|
+
parent.insertBefore(newNodes[i], prevNode.nextSibling);
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -115,7 +119,7 @@ export function conditional(parent, startMarker, endMarker, test, trueContent, f
|
|
|
115
119
|
current = newNode;
|
|
116
120
|
});
|
|
117
121
|
}
|
|
118
|
-
//
|
|
122
|
+
// Tree reconciliation (SPA navigation)
|
|
119
123
|
// Diffs a live DOM subtree against a freshly-parsed one, patching only what
|
|
120
124
|
// changed. Unchanged nodes are kept in place so their state survives navigation:
|
|
121
125
|
// element listeners attached at hydration (`__krate_<event>` props), media
|
|
@@ -272,7 +276,7 @@ function reconcileChildren(parent, newParent) {
|
|
|
272
276
|
}
|
|
273
277
|
}
|
|
274
278
|
else {
|
|
275
|
-
// Keyed but not present in old tree
|
|
279
|
+
// Keyed but not present in old tree -> insert new
|
|
276
280
|
placedNode = document.importNode(newChild, true);
|
|
277
281
|
parent.insertBefore(placedNode, anchor);
|
|
278
282
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { reconcile } from './reconcile';
|
|
3
|
+
function markers(parent) {
|
|
4
|
+
const start = document.createComment('s');
|
|
5
|
+
const end = document.createComment('e');
|
|
6
|
+
parent.append(start, end);
|
|
7
|
+
return { start, end };
|
|
8
|
+
}
|
|
9
|
+
function texts(parent, start, end) {
|
|
10
|
+
const out = [];
|
|
11
|
+
let n = start.nextSibling;
|
|
12
|
+
while (n && n !== end) {
|
|
13
|
+
out.push(n.textContent ?? '');
|
|
14
|
+
n = n.nextSibling;
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
const span = (s) => {
|
|
19
|
+
const el = document.createElement('span');
|
|
20
|
+
el.textContent = s;
|
|
21
|
+
return el;
|
|
22
|
+
};
|
|
23
|
+
describe('reconcile', () => {
|
|
24
|
+
it('renders, shrinks, grows and replaces unkeyed lists', () => {
|
|
25
|
+
const parent = document.createElement('div');
|
|
26
|
+
const { start, end } = markers(parent);
|
|
27
|
+
reconcile(parent, start, end, ['a', 'b', 'c'], span);
|
|
28
|
+
expect(texts(parent, start, end)).toEqual(['a', 'b', 'c']);
|
|
29
|
+
reconcile(parent, start, end, ['a', 'b'], span);
|
|
30
|
+
expect(texts(parent, start, end)).toEqual(['a', 'b']);
|
|
31
|
+
reconcile(parent, start, end, ['a', 'b', 'c', 'd'], span);
|
|
32
|
+
expect(texts(parent, start, end)).toEqual(['a', 'b', 'c', 'd']);
|
|
33
|
+
reconcile(parent, start, end, [], span);
|
|
34
|
+
expect(texts(parent, start, end)).toEqual([]);
|
|
35
|
+
});
|
|
36
|
+
it('keyed reconciliation keeps order and drops removed keys', () => {
|
|
37
|
+
const parent = document.createElement('div');
|
|
38
|
+
const { start, end } = markers(parent);
|
|
39
|
+
const map = (n) => span(String(n));
|
|
40
|
+
reconcile(parent, start, end, [1, 2, 3], map, (n) => n);
|
|
41
|
+
expect(texts(parent, start, end)).toEqual(['1', '2', '3']);
|
|
42
|
+
reconcile(parent, start, end, [2, 3, 4], map, (n) => n);
|
|
43
|
+
expect(texts(parent, start, end)).toEqual(['2', '3', '4']);
|
|
44
|
+
reconcile(parent, start, end, [4, 2], map, (n) => n);
|
|
45
|
+
expect(texts(parent, start, end)).toEqual(['4', '2']);
|
|
46
|
+
});
|
|
47
|
+
});
|
package/dist/router.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
export interface NavigateOptions {
|
|
2
|
+
replace?: boolean;
|
|
3
|
+
scroll?: boolean;
|
|
4
|
+
/** State stored on the new history entry. */
|
|
5
|
+
state?: unknown;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Programmatic SPA navigation. Falls back to a full page load when the router
|
|
9
|
+
* has not initialized (e.g. before hydration). Returns false when handled
|
|
10
|
+
* client-side, true when a full navigation was triggered.
|
|
11
|
+
*/
|
|
12
|
+
export declare function navigate(url: string, opts?: NavigateOptions): boolean;
|
|
1
13
|
export declare function initRouter(): void;
|
|
2
14
|
/** Dispose old effects, re-register router listeners for new page. */
|
|
3
15
|
export declare function reinitRouter(): void;
|