@krate/runtime 0.3.0-beta.7 → 0.3.0-beta.9
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/dom.js +0 -8
- package/dist/krate-hydrate.js +1 -1
- package/dist/server-renderer.js +0 -20
- package/dist/server.d.ts +0 -30
- package/package.json +1 -1
package/dist/dom.js
CHANGED
|
@@ -57,14 +57,6 @@ export function clearNodes(start, end) {
|
|
|
57
57
|
node = next;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
/** Coerce a value to a DOM node for insertion. */
|
|
61
|
-
function toNode(value) {
|
|
62
|
-
if (value == null || value === false || value === true)
|
|
63
|
-
return null;
|
|
64
|
-
if (value instanceof Node)
|
|
65
|
-
return value;
|
|
66
|
-
return document.createTextNode(String(value));
|
|
67
|
-
}
|
|
68
60
|
/**
|
|
69
61
|
* Insert content into a dynamic region delimited by two <!--k--> comment markers.
|
|
70
62
|
* The start marker is located by the caller (comment-based slot lookup); the
|
package/dist/krate-hydrate.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var __krate_exports=(()=>{var D=Object.defineProperty,Ve=Object.defineProperties,je=Object.getOwnPropertyDescriptor,Be=Object.getOwnPropertyDescriptors,Ke=Object.getOwnPropertyNames,me=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var ge=(e,t,n)=>t in e?D(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ee=(e,t)=>{for(var n in t||(t={}))ye.call(t,n)&&ge(e,n,t[n]);if(me)for(var n of me(t))Ue.call(t,n)&&ge(e,n,t[n]);return e},Te=(e,t)=>Ve(e,Be(t));var We=(e,t)=>{for(var n in t)D(e,n,{get:t[n],enumerable:!0})},Fe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of Ke(t))!ye.call(e,c)&&c!==n&&D(e,c,{get:()=>t[c],enumerable:!(r=je(t,c))||r.enumerable});return e};var $e=e=>Fe(D({},"__esModule",{value:!0}),e);var dt={};We(dt,{clearNodes:()=>xe,conditional:()=>lt,createEffect:()=>k,createMemo:()=>Je,createResource:()=>st,createSignal:()=>C,disposeAll:()=>ze,disposeNode:()=>x,forwardRef:()=>et,h:()=>ot,hydrate:()=>it,initRouter:()=>Re,insert:()=>nt,mount:()=>rt,onCleanup:()=>X,onMount:()=>Qe,reconcile:()=>ct,reconcileTrees:()=>Z,reinitRouter:()=>ut,useRef:()=>Ze});var L=[],be=[],W=!1,H=new Set,F=[],$=[],I=!1;function Ne(e){return{fn:e,cleanups:[],disposed:!1,sources:new Set,running:!1,rerun:!1,queued:!1}}function z(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 ze(){for(let e of H)z(e);H.clear();for(let e of F)try{e()}catch(t){}F.length=0,$.length=0,I=!1}function C(e){let t=e,n=new Set;return[()=>{let a=L[L.length-1];return a&&!a.disposed&&(n.add(a),a.sources.add(n)),t},a=>{let u=typeof a=="function"?a(t):a;if(u!==t){t=u;let y=Array.from(n);for(let h of y){if(h.disposed){n.delete(h);continue}if(h.running){h.rerun=!0;continue}h.queued||(h.queued=!0,$.push(h))}Xe()}}]}function Xe(){I||(I=!0,queueMicrotask(Ye))}function Ye(){I=!1;let e=$.splice(0);for(let t of e)t.disposed||(t.queued=!1,t.rerun=!1,V(t),t.rerun&&!t.disposed&&(t.rerun=!1,V(t)))}function V(e){e.running=!0;for(let t of e.cleanups)t();e.cleanups.length=0,L.push(e);try{let t=e.fn();typeof t=="function"&&e.cleanups.push(t)}finally{L.pop(),e.running=!1}}function k(e){let t=Ne(e);return H.add(t),V(t),()=>{z(t),H.delete(t)}}function X(e){let t=L[L.length-1];t?t.cleanups.push(e):F.push(e)}function Qe(e){be.push(e),W||(W=!0,queueMicrotask(Ge))}function Ge(){W=!1;let e=be.splice(0);for(let t of e)t()}function Je(e){let[t,n]=C(void 0),r=Ne(()=>{let a=e();n(a)});H.add(r),V(r);let c=L[L.length-1];return c&&c.cleanups.push(()=>{r.disposed||(z(r),H.delete(r))}),t}function Ze(e){return{current:e}}function et(e){return t=>e(t,t.ref||(()=>{}))}var Y=new WeakMap;function Se(e,t){let n=Y.get(e);n||(n=[],Y.set(e,n)),n.push(t)}function x(e){let t=Y.get(e);if(t){for(let n of t)n();t.length=0}for(let n=0;n<e.childNodes.length;n++)x(e.childNodes[n])}function tt(e){let t=e.nextSibling;for(;t;){if(t.nodeType===8&&t.nodeValue==="k")return t;t=t.nextSibling}return null}function xe(e,t){let n=e.parentNode;if(!n)return;let r=e.nextSibling;for(;r&&r!==t;){let c=r.nextSibling;x(r),n.removeChild(r),r=c}}function nt(e,t,n){let r=tt(n);r?(xe(n,r),Q(e,t,r)):Q(e,t,null)}function Q(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)Q(e,r,n)}}function ve(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(),c=`__krate_${r}`,a=e[c];a&&e.removeEventListener(r,a),e.addEventListener(r,n),e[c]=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 Ae(e,t){if(!(t==null||t===!1||t===!0)){if(Array.isArray(t)){for(let n of t)Ae(e,n);return}if(typeof t=="function"){let n=document.createTextNode("");e.appendChild(n),Se(n,k(()=>{n.nodeValue=String(t())}));return}e.appendChild(t instanceof Node?t:document.createTextNode(String(t)))}}function ot(e,t,...n){if(typeof e=="function")return e(Te(Ee({},t||{}),{children:n}));let r=document.createElement(e);if(t)for(let[c,a]of Object.entries(t))typeof a=="function"&&!c.startsWith("on")?Se(r,k(()=>ve(r,c,a()))):ve(r,c,a);for(let c of n)Ae(r,c);return r}function ke(e){if(typeof e=="string"){let t=document.querySelector(e);if(!t)throw new Error(`Container "${e}" not found`);return t}return e}function rt(e,t){let n=ke(t),r=!1;k(()=>{r||(r=!0,n.appendChild(e()))})}function it(e,t){let n=ke(t);if(n.childNodes.length===0){n.appendChild(e());return}let r=e();r&&x(r)}function st(e,t){let[n,r]=C(void 0),[c,a]=C(!0),[u,y]=C(void 0),[h,m]=C("unresolved"),[N,d]=C(0),l,g=()=>typeof e=="function"?e():e,T=async()=>{l&&l.abort(),l=new AbortController;let A=l,q=g();m(N()>0?"refreshing":"loading"),a(!0),y(void 0);try{let w=await t(q,{signal:A.signal});A.signal.aborted||(r(()=>w),m("ready"))}catch(w){(w==null?void 0:w.name)!=="AbortError"&&!A.signal.aborted&&(y(w),m("error"))}finally{A.signal.aborted||a(!1)}};k(()=>{typeof e=="function"&&e.length===0&&e(),N(),T(),X(()=>{l&&(l.abort(),l=void 0)})});let E=function(){return n()};return Object.defineProperties(E,{loading:{get:()=>c()},error:{get:()=>u()},state:{get:()=>h()}}),[E,{mutate:A=>{r(A)},refetch:()=>{d(A=>A+1)}}]}function ct(e,t,n,r,c,a){let u=[],y=t.nextSibling;for(;y&&y!==n;)u.push(y),y=y.nextSibling;if(a){let h=new Map;for(let d of u){let l=d.__k;l!=null&&h.set(l,d)}let m=[],N=new Set;for(let d=0;d<r.length;d++){let l=r[d],g=a(l);N.add(g);let T=c(l,d);T.__k=g,m.push(T)}for(let[d,l]of h)!N.has(d)&&l.parentNode===e&&(x(l),e.removeChild(l));for(let d=0;d<m.length;d++){let l=m[d],g=d===0?t:m[d-1];l!==g.nextSibling&&e.insertBefore(l,g.nextSibling)}}else{let h=Math.max(u.length,r.length);for(let m=0;m<h;m++)if(m<r.length){let N=c(r[m],m);m<u.length?u[m]!==N&&(x(u[m]),e.replaceChild(N,u[m])):e.insertBefore(N,n)}else m<u.length&&u[m].parentNode===e&&(x(u[m]),e.removeChild(u[m]))}}function lt(e,t,n,r,c,a){let u=null;k(()=>{let h=r()?c():a?a():null;u?h?(x(u),e.replaceChild(h,u)):(x(u),e.removeChild(u)):h&&e.insertBefore(h,n),u=h})}function P(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 we(e,t){let n=new Set;for(let r=0;r<t.attributes.length;r++){let c=t.attributes[r].name,a=t.attributes[r].value;n.add(c),e.getAttribute(c)!==a&&e.setAttribute(c,a)}for(let r=0;r<e.attributes.length;r++){let c=e.attributes[r].name;n.has(c)||e.removeAttribute(c)}}function G(e,t){let n=document.importNode(t,!0);return e.parentNode&&(x(e),e.parentNode.replaceChild(n,e)),n}function Le(e,t){return e.nodeType!==t.nodeType?!1:e.nodeType===Node.ELEMENT_NODE?e.tagName===t.tagName:!0}function J(e,t){if(!Le(e,t))return G(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?G(e,t):e;if(e.nodeType!==Node.ELEMENT_NODE)return e;let n=e,r=t;return P(n)!==P(r)?G(n,r):(we(n,r),Ce(n,r),n)}function Ce(e,t){let n=Array.from(e.childNodes),r=Array.from(t.childNodes);if(n.length===r.length){let d=!0;for(let l=0;l<r.length;l++)if(P(n[l])!==P(r[l])){d=!1;break}if(d){for(let l=0;l<r.length;l++)J(n[l],r[l]);return}}let c=new Map,a=[];n.forEach((d,l)=>{let g=P(d);g!=null?c.has(g)||c.set(g,l):a.push(l)});let u=new Set,y=0,h=null,m=0,N=()=>{for(;m<a.length&&u.has(a[m]);)m++;return m<a.length?a[m]:-1};for(let d of r){let l=P(d),g;if(l!=null&&c.has(l)){let T=c.get(l);c.delete(l),u.add(T);let E=n[T];T<y?e.insertBefore(E,h):y=T,g=J(E,d)}else if(l==null){let T=N();if(T>=0&&Le(n[T],d)){u.add(T);let E=n[T];E.parentNode===e&&E.nextSibling!==h&&e.insertBefore(E,h),g=J(E,d)}else g=document.importNode(d,!0),e.insertBefore(g,h)}else g=document.importNode(d,!0),e.insertBefore(g,h);h=g.nextSibling}n.forEach((d,l)=>{!u.has(l)&&d.parentNode===e&&(x(d),e.removeChild(d))})}function Z(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 c=document.importNode(t,!0);n.parentNode&&n.parentNode.replaceChild(c,n);return}we(n,r),Ce(n,r)}var ee=!1,_,j=null,M=new Map,ft=30,O=new Map,at=50,Me=/\/chunks\/runtime\.[^/]+\.js$/;function Re(){if(typeof document=="undefined"||ee)return;ee=!0;let e=".docs-content, main, #root",t=150,n=200,r=null,c=null,a=new Map,u=null;function y(o){for(let i of e.split(", ")){let s=o.querySelector(i.trim());if(s)return s}return o.body}function h(o){if(o.hasAttribute("data-krate-external"))return!1;let i=o.getAttribute("href");return!(!i||i.startsWith("#")||i.startsWith("javascript:")||o.origin!==location.origin||o.target==="_blank")}function m(o){M.has(o)||fetch(o,{headers:{Accept:"text/html"}}).then(i=>i.ok?i.text():null).then(i=>{if(i){if(M.size>=ft){let s=M.keys().next().value;s!==void 0&&M.delete(s)}M.set(o,i)}}).catch(()=>{})}function N(){document.addEventListener("mouseover",g),document.addEventListener("focusin",g),typeof IntersectionObserver!="undefined"&&(u=new IntersectionObserver(o=>{for(let i of o)if(i.isIntersecting){let s=i.target,f=s.getAttribute("href");if(f&&h(s)){let p=new URL(f,location.origin).href;m(p)}u.unobserve(i.target)}},{rootMargin:"200px"}),d())}function d(){u&&document.querySelectorAll("a[data-prefetch]").forEach(o=>{u.observe(o)})}function l(){document.removeEventListener("mouseover",g),document.removeEventListener("focusin",g);for(let o of a.values())clearTimeout(o);a.clear(),u&&(u.disconnect(),u=null)}function g(o){let i=o.target.closest("a[data-prefetch]");if(!i||!h(i))return;let s=i.getAttribute("href");if(!s)return;let f=new URL(s,location.origin).href;if(M.has(f))return;let p=a.get(i);p&&clearTimeout(p);let b=setTimeout(()=>{a.delete(i),m(f)},n);a.set(i,b)}function T(o){let i=document.createTreeWalker(o,NodeFilter.SHOW_ELEMENT),s=i.nextNode();for(;s;){let f=s;for(let p of Object.keys(f))p.indexOf("__krate_")===0&&delete f[p];s=i.nextNode()}}let E=null;function te(){let o=y(document),i=document.querySelector("template[data-krate-loading]");i&&i.content&&o&&(E=i.content.cloneNode(!0),document.body.appendChild(E)),o&&(o.style.transition=`opacity ${t}ms ease`,o.style.opacity="0")}function A(){E&&E.parentNode&&E.parentNode.removeChild(E),E=null;let o=y(document);o&&(o.style.opacity="1")}function q(o,i,s,f={}){let{replace:p=!1,scroll:b=!0,restoreScroll:R=!1}=f,B=new DOMParser().parseFromString(o,"text/html"),ae=y(B),K=y(document);if(!ae||!K){location.href=i;return}let ue=B.querySelector("title");ue&&(document.title=ue.textContent||""),typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),T(K),Z(K,ae);let de=B.querySelectorAll('link[rel="stylesheet"]'),pe=new Set;de.forEach(v=>{let S=v.getAttribute("href");S&&pe.add(S)}),document.querySelectorAll('link[rel="stylesheet"]').forEach(v=>{let S=v.getAttribute("href");S&&!pe.has(S)&&v.remove()});let he=new Set;document.querySelectorAll('link[rel="stylesheet"]').forEach(v=>{he.add(v.href)}),de.forEach(v=>{let S=v.getAttribute("href");if(S&&!he.has(S)){let U=document.createElement("link");U.rel="stylesheet",U.href=S,document.head.appendChild(U)}}),He(s,i).then(()=>{try{_e(),d()}catch(v){try{let S=globalThis.__krate_onHydrationError;typeof S=="function"&&S(v)}catch(S){}location.href=i}}),A();let Ie=location.pathname+location.search;if(p)history.replaceState({},"",i);else{if(!R){if(O.size>=at){let v=O.keys().next().value;v!==void 0&&O.delete(v)}O.set(Ie,window.scrollY)}history.pushState({},"",i)}ne(i,{restoreScroll:R,scroll:b}),oe(),window.dispatchEvent(new CustomEvent("krate:navigate",{detail:{url:i}}))}function w(o){let i=o.indexOf("#");if(i<0||i===o.length-1)return!1;let s=o.slice(i);try{let f=document.querySelector(s);if(f)return f.scrollIntoView({behavior:"smooth",block:"start"}),!0}catch(f){return!1}return!1}function ne(o,i){if(i.restoreScroll){let s=O.get(o);if(s!==void 0){window.scrollTo(0,s);return}}w(o)||i.scroll&&window.scrollTo(0,0)}function oe(){let o=location.pathname;document.querySelectorAll("a[data-krate-link]").forEach(i=>{let s=i.getAttribute("href");if(!s){i.removeAttribute("aria-current");return}let f=s;try{f=new URL(s,location.origin).pathname}catch(b){return}f===o||o==="/"&&(f===""||f==="/")||f!=="/"&&f.length>1&&o.startsWith(f)?i.setAttribute("aria-current","page"):i.removeAttribute("aria-current")})}function He(o,i){return o.length===0?Promise.resolve():Promise.all(o.map(s=>{let f=s.getAttribute("src");return f?Pe(f,i):Promise.resolve()})).then(()=>{})}function Pe(o,i){return new Promise(s=>{let f=document.createElement("script"),p=re(o,i);f.src=p,Me.test(p)||f.setAttribute("data-krate-spa",""),f.onload=()=>s(),f.onerror=()=>s(),document.body.appendChild(f)})}function re(o,i){if(/^(https?:)?\/\//.test(o)||o.startsWith("/"))return new URL(o,i).href;let s=i;if(!s.endsWith("/")){let f=s.lastIndexOf("/");s=f>0?s.slice(0,f+1):"/"}return new URL(o,s).href}function _e(){typeof globalThis.__krate_hydrate=="function"&&globalThis.__krate_hydrate()}function Oe(o,i){typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),history.pushState({},"",i),document.open(),document.write(o),document.close()}function qe(){return r!==null?Promise.resolve(r):fetch("/404.html",{headers:{Accept:"text/html"}}).then(o=>o.ok?o.text():null).then(o=>(r=o,o)).catch(()=>null)}function De(){return c!==null?Promise.resolve(c):fetch("/500.html",{headers:{Accept:"text/html"}}).then(o=>o.ok?o.text():null).then(o=>(c=o,o)).catch(()=>null)}function ie(o,i){document.querySelectorAll("script[data-krate-spa]").forEach(p=>p.remove());let s=[],f=new Set;return document.querySelectorAll("script[src]").forEach(p=>{f.add(p.src)}),o.querySelectorAll("script[src]").forEach(p=>{let b=p.getAttribute("src");b&&!f.has(re(b,i))&&s.push(p)}),s}function se(o,i={}){let s=M.get(o);if(s){let b=new DOMParser().parseFromString(s,"text/html");q(s,o,ie(b,o),i);return}te(),_&&_.abort(),_=new AbortController;let f=_.signal;fetch(o,{headers:{Accept:"text/html"},signal:f}).then(p=>p.ok?p.text().then(b=>{let fe=new DOMParser().parseFromString(b,"text/html");q(b,o,ie(fe,o),i)}):(p.status>=500?De():qe()).then(R=>{R?Oe(R,o):location.href=o})).catch(p=>{(p==null?void 0:p.name)!=="AbortError"&&(A(),location.href=o)}).finally(()=>{_&&!f.aborted&&(_=void 0)})}let ce=o=>{if(o.defaultPrevented||o.button!==0||o.metaKey||o.ctrlKey||o.shiftKey||o.altKey)return;let i=o.target.closest("a[data-krate-link]");if(!i||!h(i))return;o.preventDefault();let s=i.getAttribute("href");if(!s)return;let f=new URL(s,location.origin).href,p=i.hasAttribute("data-krate-replace"),b=i.getAttribute("data-krate-scroll")!=="false";if(s===location.pathname+location.search+location.hash){p&&history.replaceState({},"",s),ne(f,{scroll:b});return}se(f,{replace:p,scroll:b})},le=()=>{se(location.href,{restoreScroll:!0})};document.addEventListener("click",ce),window.addEventListener("popstate",le),N(),oe(),document.querySelectorAll("script[src]").forEach(o=>{Me.test(o.src)||o.setAttribute("data-krate-spa","")}),j=()=>{document.removeEventListener("click",ce),window.removeEventListener("popstate",le),l()}}function ut(){j&&(j(),j=null),ee=!1,Re()}return $e(dt);})();
|
|
1
|
+
var __krate_exports=(()=>{var D=Object.defineProperty,Ve=Object.defineProperties,je=Object.getOwnPropertyDescriptor,Be=Object.getOwnPropertyDescriptors,Ke=Object.getOwnPropertyNames,me=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var ge=(e,t,n)=>t in e?D(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ee=(e,t)=>{for(var n in t||(t={}))ye.call(t,n)&&ge(e,n,t[n]);if(me)for(var n of me(t))Ue.call(t,n)&&ge(e,n,t[n]);return e},Te=(e,t)=>Ve(e,Be(t));var We=(e,t)=>{for(var n in t)D(e,n,{get:t[n],enumerable:!0})},Fe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of Ke(t))!ye.call(e,c)&&c!==n&&D(e,c,{get:()=>t[c],enumerable:!(r=je(t,c))||r.enumerable});return e};var $e=e=>Fe(D({},"__esModule",{value:!0}),e);var dt={};We(dt,{clearNodes:()=>xe,conditional:()=>lt,createEffect:()=>k,createMemo:()=>Je,createResource:()=>st,createSignal:()=>C,disposeAll:()=>ze,disposeNode:()=>x,forwardRef:()=>et,h:()=>ot,hydrate:()=>it,initRouter:()=>Re,insert:()=>nt,mount:()=>rt,onCleanup:()=>X,onMount:()=>Qe,reconcile:()=>ct,reconcileTrees:()=>Z,reinitRouter:()=>ut,useRef:()=>Ze});var L=[],be=[],W=!1,H=new Set,F=[],$=[],I=!1;function ve(e){return{fn:e,cleanups:[],disposed:!1,sources:new Set,running:!1,rerun:!1,queued:!1}}function z(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 ze(){for(let e of H)z(e);H.clear();for(let e of F)try{e()}catch(t){}F.length=0,$.length=0,I=!1}function C(e){let t=e,n=new Set;return[()=>{let a=L[L.length-1];return a&&!a.disposed&&(n.add(a),a.sources.add(n)),t},a=>{let u=typeof a=="function"?a(t):a;if(u!==t){t=u;let y=Array.from(n);for(let h of y){if(h.disposed){n.delete(h);continue}if(h.running){h.rerun=!0;continue}h.queued||(h.queued=!0,$.push(h))}Xe()}}]}function Xe(){I||(I=!0,queueMicrotask(Ye))}function Ye(){I=!1;let e=$.splice(0);for(let t of e)t.disposed||(t.queued=!1,t.rerun=!1,V(t),t.rerun&&!t.disposed&&(t.rerun=!1,V(t)))}function V(e){e.running=!0;for(let t of e.cleanups)t();e.cleanups.length=0,L.push(e);try{let t=e.fn();typeof t=="function"&&e.cleanups.push(t)}finally{L.pop(),e.running=!1}}function k(e){let t=ve(e);return H.add(t),V(t),()=>{z(t),H.delete(t)}}function X(e){let t=L[L.length-1];t?t.cleanups.push(e):F.push(e)}function Qe(e){be.push(e),W||(W=!0,queueMicrotask(Ge))}function Ge(){W=!1;let e=be.splice(0);for(let t of e)t()}function Je(e){let[t,n]=C(void 0),r=ve(()=>{let a=e();n(a)});H.add(r),V(r);let c=L[L.length-1];return c&&c.cleanups.push(()=>{r.disposed||(z(r),H.delete(r))}),t}function Ze(e){return{current:e}}function et(e){return t=>e(t,t.ref||(()=>{}))}var Y=new WeakMap;function Se(e,t){let n=Y.get(e);n||(n=[],Y.set(e,n)),n.push(t)}function x(e){let t=Y.get(e);if(t){for(let n of t)n();t.length=0}for(let n=0;n<e.childNodes.length;n++)x(e.childNodes[n])}function tt(e){let t=e.nextSibling;for(;t;){if(t.nodeType===8&&t.nodeValue==="k")return t;t=t.nextSibling}return null}function xe(e,t){let n=e.parentNode;if(!n)return;let r=e.nextSibling;for(;r&&r!==t;){let c=r.nextSibling;x(r),n.removeChild(r),r=c}}function nt(e,t,n){let r=tt(n);r?(xe(n,r),Q(e,t,r)):Q(e,t,null)}function Q(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)Q(e,r,n)}}function Ne(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(),c=`__krate_${r}`,a=e[c];a&&e.removeEventListener(r,a),e.addEventListener(r,n),e[c]=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 Ae(e,t){if(!(t==null||t===!1||t===!0)){if(Array.isArray(t)){for(let n of t)Ae(e,n);return}if(typeof t=="function"){let n=document.createTextNode("");e.appendChild(n),Se(n,k(()=>{n.nodeValue=String(t())}));return}e.appendChild(t instanceof Node?t:document.createTextNode(String(t)))}}function ot(e,t,...n){if(typeof e=="function")return e(Te(Ee({},t||{}),{children:n}));let r=document.createElement(e);if(t)for(let[c,a]of Object.entries(t))typeof a=="function"&&!c.startsWith("on")?Se(r,k(()=>Ne(r,c,a()))):Ne(r,c,a);for(let c of n)Ae(r,c);return r}function ke(e){if(typeof e=="string"){let t=document.querySelector(e);if(!t)throw new Error(`Container "${e}" not found`);return t}return e}function rt(e,t){let n=ke(t),r=!1;k(()=>{r||(r=!0,n.appendChild(e()))})}function it(e,t){let n=ke(t);if(n.childNodes.length===0){n.appendChild(e());return}let r=e();r&&x(r)}function st(e,t){let[n,r]=C(void 0),[c,a]=C(!0),[u,y]=C(void 0),[h,m]=C("unresolved"),[v,d]=C(0),l,g=()=>typeof e=="function"?e():e,T=async()=>{l&&l.abort(),l=new AbortController;let A=l,q=g();m(v()>0?"refreshing":"loading"),a(!0),y(void 0);try{let w=await t(q,{signal:A.signal});A.signal.aborted||(r(()=>w),m("ready"))}catch(w){(w==null?void 0:w.name)!=="AbortError"&&!A.signal.aborted&&(y(w),m("error"))}finally{A.signal.aborted||a(!1)}};k(()=>{typeof e=="function"&&e.length===0&&e(),v(),T(),X(()=>{l&&(l.abort(),l=void 0)})});let E=function(){return n()};return Object.defineProperties(E,{loading:{get:()=>c()},error:{get:()=>u()},state:{get:()=>h()}}),[E,{mutate:A=>{r(A)},refetch:()=>{d(A=>A+1)}}]}function ct(e,t,n,r,c,a){let u=[],y=t.nextSibling;for(;y&&y!==n;)u.push(y),y=y.nextSibling;if(a){let h=new Map;for(let d of u){let l=d.__k;l!=null&&h.set(l,d)}let m=[],v=new Set;for(let d=0;d<r.length;d++){let l=r[d],g=a(l);v.add(g);let T=c(l,d);T.__k=g,m.push(T)}for(let[d,l]of h)!v.has(d)&&l.parentNode===e&&(x(l),e.removeChild(l));for(let d=0;d<m.length;d++){let l=m[d],g=d===0?t:m[d-1];l!==g.nextSibling&&e.insertBefore(l,g.nextSibling)}}else{let h=Math.max(u.length,r.length);for(let m=0;m<h;m++)if(m<r.length){let v=c(r[m],m);m<u.length?u[m]!==v&&(x(u[m]),e.replaceChild(v,u[m])):e.insertBefore(v,n)}else m<u.length&&u[m].parentNode===e&&(x(u[m]),e.removeChild(u[m]))}}function lt(e,t,n,r,c,a){let u=null;k(()=>{let h=r()?c():a?a():null;u?h?(x(u),e.replaceChild(h,u)):(x(u),e.removeChild(u)):h&&e.insertBefore(h,n),u=h})}function P(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 we(e,t){let n=new Set;for(let r=0;r<t.attributes.length;r++){let c=t.attributes[r].name,a=t.attributes[r].value;n.add(c),e.getAttribute(c)!==a&&e.setAttribute(c,a)}for(let r=0;r<e.attributes.length;r++){let c=e.attributes[r].name;n.has(c)||e.removeAttribute(c)}}function G(e,t){let n=document.importNode(t,!0);return e.parentNode&&(x(e),e.parentNode.replaceChild(n,e)),n}function Le(e,t){return e.nodeType!==t.nodeType?!1:e.nodeType===Node.ELEMENT_NODE?e.tagName===t.tagName:!0}function J(e,t){if(!Le(e,t))return G(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?G(e,t):e;if(e.nodeType!==Node.ELEMENT_NODE)return e;let n=e,r=t;return P(n)!==P(r)?G(n,r):(we(n,r),Ce(n,r),n)}function Ce(e,t){let n=Array.from(e.childNodes),r=Array.from(t.childNodes);if(n.length===r.length){let d=!0;for(let l=0;l<r.length;l++)if(P(n[l])!==P(r[l])){d=!1;break}if(d){for(let l=0;l<r.length;l++)J(n[l],r[l]);return}}let c=new Map,a=[];n.forEach((d,l)=>{let g=P(d);g!=null?c.has(g)||c.set(g,l):a.push(l)});let u=new Set,y=0,h=null,m=0,v=()=>{for(;m<a.length&&u.has(a[m]);)m++;return m<a.length?a[m]:-1};for(let d of r){let l=P(d),g;if(l!=null&&c.has(l)){let T=c.get(l);c.delete(l),u.add(T);let E=n[T];T<y?e.insertBefore(E,h):y=T,g=J(E,d)}else if(l==null){let T=v();if(T>=0&&Le(n[T],d)){u.add(T);let E=n[T];E.parentNode===e&&E.nextSibling!==h&&e.insertBefore(E,h),g=J(E,d)}else g=document.importNode(d,!0),e.insertBefore(g,h)}else g=document.importNode(d,!0),e.insertBefore(g,h);h=g.nextSibling}n.forEach((d,l)=>{!u.has(l)&&d.parentNode===e&&(x(d),e.removeChild(d))})}function Z(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 c=document.importNode(t,!0);n.parentNode&&n.parentNode.replaceChild(c,n);return}we(n,r),Ce(n,r)}var ee=!1,_,j=null,M=new Map,ft=30,O=new Map,at=50,Me=/\/chunks\/runtime\.[^/]+\.js$/;function Re(){if(typeof document=="undefined"||ee)return;ee=!0;let e=".docs-content, main, #root",t=150,n=200,r=null,c=null,a=new Map,u=null;function y(o){for(let i of e.split(", ")){let s=o.querySelector(i.trim());if(s)return s}return o.body}function h(o){if(o.hasAttribute("data-krate-external"))return!1;let i=o.getAttribute("href");return!(!i||i.startsWith("#")||i.startsWith("javascript:")||o.origin!==location.origin||o.target==="_blank")}function m(o){M.has(o)||fetch(o,{headers:{Accept:"text/html"}}).then(i=>i.ok?i.text():null).then(i=>{if(i){if(M.size>=ft){let s=M.keys().next().value;s!==void 0&&M.delete(s)}M.set(o,i)}}).catch(()=>{})}function v(){document.addEventListener("mouseover",g),document.addEventListener("focusin",g),typeof IntersectionObserver!="undefined"&&(u=new IntersectionObserver(o=>{for(let i of o)if(i.isIntersecting){let s=i.target,f=s.getAttribute("href");if(f&&h(s)){let p=new URL(f,location.origin).href;m(p)}u.unobserve(i.target)}},{rootMargin:"200px"}),d())}function d(){u&&document.querySelectorAll("a[data-prefetch]").forEach(o=>{u.observe(o)})}function l(){document.removeEventListener("mouseover",g),document.removeEventListener("focusin",g);for(let o of a.values())clearTimeout(o);a.clear(),u&&(u.disconnect(),u=null)}function g(o){let i=o.target.closest("a[data-prefetch]");if(!i||!h(i))return;let s=i.getAttribute("href");if(!s)return;let f=new URL(s,location.origin).href;if(M.has(f))return;let p=a.get(i);p&&clearTimeout(p);let b=setTimeout(()=>{a.delete(i),m(f)},n);a.set(i,b)}function T(o){let i=document.createTreeWalker(o,NodeFilter.SHOW_ELEMENT),s=i.nextNode();for(;s;){let f=s;for(let p of Object.keys(f))p.indexOf("__krate_")===0&&delete f[p];s=i.nextNode()}}let E=null;function te(){let o=y(document),i=document.querySelector("template[data-krate-loading]");i&&i.content&&o&&(E=i.content.cloneNode(!0),document.body.appendChild(E)),o&&(o.style.transition=`opacity ${t}ms ease`,o.style.opacity="0")}function A(){E&&E.parentNode&&E.parentNode.removeChild(E),E=null;let o=y(document);o&&(o.style.opacity="1")}function q(o,i,s,f={}){let{replace:p=!1,scroll:b=!0,restoreScroll:R=!1}=f,B=new DOMParser().parseFromString(o,"text/html"),ae=y(B),K=y(document);if(!ae||!K){location.href=i;return}let ue=B.querySelector("title");ue&&(document.title=ue.textContent||""),typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),T(K),Z(K,ae);let de=B.querySelectorAll('link[rel="stylesheet"]'),pe=new Set;de.forEach(N=>{let S=N.getAttribute("href");S&&pe.add(S)}),document.querySelectorAll('link[rel="stylesheet"]').forEach(N=>{let S=N.getAttribute("href");S&&!pe.has(S)&&N.remove()});let he=new Set;document.querySelectorAll('link[rel="stylesheet"]').forEach(N=>{he.add(N.href)}),de.forEach(N=>{let S=N.getAttribute("href");if(S&&!he.has(S)){let U=document.createElement("link");U.rel="stylesheet",U.href=S,document.head.appendChild(U)}}),He(s,i).then(()=>{try{_e(),d()}catch(N){try{let S=globalThis.__krate_onHydrationError;typeof S=="function"&&S(N)}catch(S){}location.href=i}}),A();let Ie=location.pathname+location.search;if(p)history.replaceState({},"",i);else{if(!R){if(O.size>=at){let N=O.keys().next().value;N!==void 0&&O.delete(N)}O.set(Ie,window.scrollY)}history.pushState({},"",i)}ne(i,{restoreScroll:R,scroll:b}),oe(),window.dispatchEvent(new CustomEvent("krate:navigate",{detail:{url:i}}))}function w(o){let i=o.indexOf("#");if(i<0||i===o.length-1)return!1;let s=o.slice(i);try{let f=document.querySelector(s);if(f)return f.scrollIntoView({behavior:"smooth",block:"start"}),!0}catch(f){return!1}return!1}function ne(o,i){if(i.restoreScroll){let s=O.get(o);if(s!==void 0){window.scrollTo(0,s);return}}w(o)||i.scroll&&window.scrollTo(0,0)}function oe(){let o=location.pathname;document.querySelectorAll("a[data-krate-link]").forEach(i=>{let s=i.getAttribute("href");if(!s){i.removeAttribute("aria-current");return}let f=s;try{f=new URL(s,location.origin).pathname}catch(b){return}f===o||o==="/"&&(f===""||f==="/")||f!=="/"&&f.length>1&&o.startsWith(f)?i.setAttribute("aria-current","page"):i.removeAttribute("aria-current")})}function He(o,i){return o.length===0?Promise.resolve():Promise.all(o.map(s=>{let f=s.getAttribute("src");return f?Pe(f,i):Promise.resolve()})).then(()=>{})}function Pe(o,i){return new Promise(s=>{let f=document.createElement("script"),p=re(o,i);f.src=p,Me.test(p)||f.setAttribute("data-krate-spa",""),f.onload=()=>s(),f.onerror=()=>s(),document.body.appendChild(f)})}function re(o,i){if(/^(https?:)?\/\//.test(o)||o.startsWith("/"))return new URL(o,i).href;let s=i;if(!s.endsWith("/")){let f=s.lastIndexOf("/");s=f>0?s.slice(0,f+1):"/"}return new URL(o,s).href}function _e(){typeof globalThis.__krate_hydrate=="function"&&globalThis.__krate_hydrate()}function Oe(o,i){typeof globalThis.disposeAll=="function"&&globalThis.disposeAll(),history.pushState({},"",i),document.open(),document.write(o),document.close()}function qe(){return r!==null?Promise.resolve(r):fetch("/404.html",{headers:{Accept:"text/html"}}).then(o=>o.ok?o.text():null).then(o=>(r=o,o)).catch(()=>null)}function De(){return c!==null?Promise.resolve(c):fetch("/500.html",{headers:{Accept:"text/html"}}).then(o=>o.ok?o.text():null).then(o=>(c=o,o)).catch(()=>null)}function ie(o,i){document.querySelectorAll("script[data-krate-spa]").forEach(p=>p.remove());let s=[],f=new Set;return document.querySelectorAll("script[src]").forEach(p=>{f.add(p.src)}),o.querySelectorAll("script[src]").forEach(p=>{let b=p.getAttribute("src");b&&!f.has(re(b,i))&&s.push(p)}),s}function se(o,i={}){let s=M.get(o);if(s){let b=new DOMParser().parseFromString(s,"text/html");q(s,o,ie(b,o),i);return}te(),_&&_.abort(),_=new AbortController;let f=_.signal;fetch(o,{headers:{Accept:"text/html"},signal:f}).then(p=>p.ok?p.text().then(b=>{let fe=new DOMParser().parseFromString(b,"text/html");q(b,o,ie(fe,o),i)}):(p.status>=500?De():qe()).then(R=>{R?Oe(R,o):location.href=o})).catch(p=>{(p==null?void 0:p.name)!=="AbortError"&&(A(),location.href=o)}).finally(()=>{_&&!f.aborted&&(_=void 0)})}let ce=o=>{if(o.defaultPrevented||o.button!==0||o.metaKey||o.ctrlKey||o.shiftKey||o.altKey)return;let i=o.target.closest("a[data-krate-link]");if(!i||!h(i))return;o.preventDefault();let s=i.getAttribute("href");if(!s)return;let f=new URL(s,location.origin).href,p=i.hasAttribute("data-krate-replace"),b=i.getAttribute("data-krate-scroll")!=="false";if(s===location.pathname+location.search+location.hash){p&&history.replaceState({},"",s),ne(f,{scroll:b});return}se(f,{replace:p,scroll:b})},le=()=>{se(location.href,{restoreScroll:!0})};document.addEventListener("click",ce),window.addEventListener("popstate",le),v(),oe(),document.querySelectorAll("script[src]").forEach(o=>{Me.test(o.src)||o.setAttribute("data-krate-spa","")}),j=()=>{document.removeEventListener("click",ce),window.removeEventListener("popstate",le),l()}}function ut(){j&&(j(),j=null),ee=!1,Re()}return $e(dt);})();
|
|
2
2
|
for (const k in __krate_exports) { window[k] = __krate_exports[k]; }
|
package/dist/server-renderer.js
CHANGED
|
@@ -78,8 +78,6 @@ class ISRCache {
|
|
|
78
78
|
this.cache.set(e.key, {
|
|
79
79
|
html: e.html,
|
|
80
80
|
timestamp: typeof e.timestamp === "number" ? e.timestamp : Date.now(),
|
|
81
|
-
headHTML: e.headHTML,
|
|
82
|
-
scriptHTML: e.scriptHTML,
|
|
83
81
|
});
|
|
84
82
|
}
|
|
85
83
|
}
|
|
@@ -193,20 +191,14 @@ async function renderFresh(page, req) {
|
|
|
193
191
|
}
|
|
194
192
|
const jsxNode = Component(buildProps(req));
|
|
195
193
|
const html = renderToString(jsxNode);
|
|
196
|
-
const headHTML = extractHeadHTML(html);
|
|
197
|
-
const scriptHTML = extractScriptHTML(html);
|
|
198
194
|
const response = {
|
|
199
195
|
html,
|
|
200
196
|
status: 200,
|
|
201
|
-
headHTML,
|
|
202
|
-
scriptHTML,
|
|
203
197
|
};
|
|
204
198
|
if (page.mode === "isr") {
|
|
205
199
|
isrCache.set(variantKey(req), {
|
|
206
200
|
html,
|
|
207
201
|
timestamp: Date.now(),
|
|
208
|
-
headHTML,
|
|
209
|
-
scriptHTML,
|
|
210
202
|
});
|
|
211
203
|
scheduleIsrPersist();
|
|
212
204
|
}
|
|
@@ -256,8 +248,6 @@ async function renderPage(req) {
|
|
|
256
248
|
return {
|
|
257
249
|
html: cached.html,
|
|
258
250
|
status: 200,
|
|
259
|
-
headHTML: cached.headHTML,
|
|
260
|
-
scriptHTML: cached.scriptHTML,
|
|
261
251
|
cached: true,
|
|
262
252
|
cacheStatus: "hit",
|
|
263
253
|
};
|
|
@@ -270,8 +260,6 @@ async function renderPage(req) {
|
|
|
270
260
|
return {
|
|
271
261
|
html: cached.html,
|
|
272
262
|
status: 200,
|
|
273
|
-
headHTML: cached.headHTML,
|
|
274
|
-
scriptHTML: cached.scriptHTML,
|
|
275
263
|
cached: true,
|
|
276
264
|
cacheStatus: "stale",
|
|
277
265
|
};
|
|
@@ -416,14 +404,6 @@ function extractTitle(html) {
|
|
|
416
404
|
const match = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
|
|
417
405
|
return match ? match[1].trim() : "";
|
|
418
406
|
}
|
|
419
|
-
function extractHeadHTML(html) {
|
|
420
|
-
const match = html.match(/<!--head-start-->(.*?)<!--head-end-->/s);
|
|
421
|
-
return match ? match[1] : "";
|
|
422
|
-
}
|
|
423
|
-
function extractScriptHTML(html) {
|
|
424
|
-
const match = html.match(/<!--script-start-->(.*?)<!--script-end-->/s);
|
|
425
|
-
return match ? match[1] : "";
|
|
426
|
-
}
|
|
427
407
|
// ── HTTP Server ──────────────────────────────────────────────────────────────
|
|
428
408
|
const PORT = parseInt(process.env.KRATE_SSR_PORT || "3100", 10);
|
|
429
409
|
const manifestPath = process.env.KRATE_MANIFEST || "";
|
package/dist/server.d.ts
CHANGED
|
@@ -58,34 +58,4 @@ export declare function SyntaxHighlight(props: {
|
|
|
58
58
|
lang?: string;
|
|
59
59
|
children?: any;
|
|
60
60
|
}): JSXNode;
|
|
61
|
-
export interface GetServerSidePropsContext {
|
|
62
|
-
params?: Record<string, string>;
|
|
63
|
-
query?: Record<string, string>;
|
|
64
|
-
req: {
|
|
65
|
-
url: string;
|
|
66
|
-
method: string;
|
|
67
|
-
headers: Record<string, string>;
|
|
68
|
-
};
|
|
69
|
-
res: {
|
|
70
|
-
statusCode: number;
|
|
71
|
-
setHeader(name: string, value: string): void;
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
export interface GetServerSidePropsResult<P> {
|
|
75
|
-
props: P;
|
|
76
|
-
redirect?: {
|
|
77
|
-
destination: string;
|
|
78
|
-
permanent?: boolean;
|
|
79
|
-
};
|
|
80
|
-
notFound?: true;
|
|
81
|
-
}
|
|
82
|
-
export interface GetStaticPropsResult<P> {
|
|
83
|
-
props: P;
|
|
84
|
-
revalidate?: number;
|
|
85
|
-
redirect?: {
|
|
86
|
-
destination: string;
|
|
87
|
-
permanent?: boolean;
|
|
88
|
-
};
|
|
89
|
-
notFound?: true;
|
|
90
|
-
}
|
|
91
61
|
export {};
|
package/package.json
CHANGED