@krate/runtime 0.5.0-rc.15 → 0.5.0-rc.16
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/NOTICE +10 -0
- package/dist/cache-scope.d.ts +10 -2
- package/dist/cache-scope.js +26 -4
- package/dist/island-swap.js +46 -8
- package/dist/krate-f-navigation.js +1 -1
- package/dist/krate-hydrate-lite.js +5 -5
- package/dist/krate-hydrate.js +3 -3
- package/dist/krate-island-swap.js +1 -1
- package/dist/krate-runtime.js +4 -4
- package/dist/memsize.d.ts +14 -0
- package/dist/memsize.js +71 -0
- package/dist/segmented-lru.d.ts +14 -1
- package/dist/segmented-lru.js +90 -21
- package/dist/server-handler.d.ts +1 -0
- package/dist/server-handler.js +3 -1
- package/dist/server-renderer.js +4 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.js +53 -27
- package/dist/shared-isr.js +2 -1
- package/dist/ssr-core.d.ts +10 -2
- package/dist/ssr-core.js +19 -6
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var N="krate-island:",
|
|
1
|
+
(()=>{var N="krate-island:",J="/krate-island",x="<!--"+N,R="<!--"+J+"-->",X=/^krate-slot:([0-9a-z]+)$/;function k(e){return e.nodeType===8&&e.data.indexOf(N)===0}function H(e){return e.nodeType===8&&e.data===J}function D(e){return e.nodeType===1&&e.localName==="krate-island"&&e.hasAttribute("data-src")}function U(e){let o=0;for(let t=e.nextSibling;t;t=t.nextSibling)if(k(t))o++;else if(H(t)){if(!o)return t;o--}return null}function z(e,o){let t=[e];for(let n=e.nextSibling;n&&n!==o;n=n.nextSibling)t.push(n);return t.push(o),t}function O(e){return e.el?[e.el]:z(e.start,e.end)}function Y(e){if(e.hasAttribute("data-props"))return e.getAttribute("data-props")||"";let o=e.previousElementSibling;return o&&o.localName==="script"&&o.hasAttribute("data-krate-props")&&o.textContent||""}function L(e,o){return o===null?e:e+"#"+JSON.stringify(o)}function v(e,o=[],t=[]){for(let n=0;n<e.length;n++){let s=e[n];if(k(s)){let i=U(s),a=null;try{a=JSON.parse(s.data.slice(N.length))}catch{a=null}if(!i||!a)continue;let r=typeof a.k=="string";for(t.push({key:L(a.m+"#"+a.e,r?a.k:null),keyed:r,start:s,end:i,json:s.data.slice(N.length),chain:o,rec:s.__krateIsland});n<e.length-1&&e[n]!==i;)n++}else if(D(s)){let i=s.getAttribute("data-key");t.push({key:L(s.getAttribute("data-module")+"#"+s.getAttribute("data-export"),i),keyed:i!==null,el:s,json:Y(s),chain:o,rec:s.__krateIsland})}else s.nodeType===1&&v(s.childNodes,o.concat(s),t)}return t}function M(e){let o=e&&e.handle;return!!e&&!e.gone&&e.status==="hydrated"&&!!o&&typeof o.update=="function"&&typeof o.unmount=="function"}function I(e,o){if(Array.isArray(e))return e.map(n=>I(n,o));if(!e||typeof e!="object")return e;let t={};for(let n in e){let s=e[n];n==="__krateSlotRef"&&typeof s=="string"||n==="r"&&e.$==="h"&&typeof s=="string"?t[n]=o(s):t[n]=I(s,o)}return t}function S(e){try{return JSON.parse(e)}catch{return}}function j(e){let o=S(e.json);return JSON.stringify(I(e.el?o:o&&o.p,()=>""))}function T(e){let o="";for(let t=0;t<e.length;t++){let n=e[t];o+=n.nodeType===1?n.outerHTML:n.nodeType===8?"<!--"+n.data+"-->":n.textContent||""}return o}function Z(e,o){for(let t=e.indexOf("<krate-island ",o);t>=0;t=e.indexOf("<krate-island ",t+1))if(/\sdata-src=/.test(e.slice(t,e.indexOf(">",t))))return t;return-1}function b(e){let o="",t=0;for(;;){let n=e.indexOf(x,t),s=Z(e,t);if(n===-1&&s<0)return o+e.slice(t);if(s>=0&&(n===-1||s<n)){let f=e.indexOf("</krate-island>",s);if(f===-1)return o+e.slice(t);o+=e.slice(t,s)+"<!--i:"+(/data-module="([^"]*)"/.exec(e.slice(s,e.indexOf(">",s)))||["",""])[1]+"-->",t=f+15;continue}let i=e.indexOf("-->",n);if(i===-1)return o+e.slice(t);let a=S(e.slice(n+x.length,i)),r=i+3,l=0;for(;;){let f=e.indexOf(x,r),d=e.indexOf(R,r);if(d===-1)return o+e.slice(t);if(f!==-1&&f<d){l++,r=f+x.length;continue}if(r=d+R.length,!l)break;l--}o+=e.slice(t,n)+"<!--i:"+(a?a.m+"#"+a.e:"")+"-->",t=r}}function ee(e){let o=[],t=new Set,n=s=>{if(t.has(s))return;t.add(s);let i=s.__krateIsland;if(i&&(k(s)||D(s))&&o.push(i),k(s)){let a=U(s);if(a)for(let l=s.nextSibling;l&&l!==a;l=l.nextSibling)n(l);let r=s.__krateInner;if(r)for(let l of r)n(l);return}if(s.nodeType===1)for(let a=s.firstChild;a;a=a.nextSibling)n(a)};for(let s=0;s<e.length;s++)n(e[s]);return o}function y(e){let o=ee(e);for(let t=o.length-1;t>=0;t--){let n=o[t];if(n.gone)continue;n.gone=!0;let s=n.handle;if(!(!s||typeof s.unmount!="function"))try{s.unmount()}catch(i){console.error(i)}}}function K(e,o){for(let t of Array.from(e.attributes))o.hasAttribute(t.name)||e.removeAttribute(t.name);for(let t of Array.from(o.attributes))e.getAttribute(t.name)!==t.value&&(t.namespaceURI?e.setAttributeNS(t.namespaceURI,t.name,t.value):e.setAttribute(t.name,t.value))}function ne(e,o,t){let n=e.moveBefore;if(typeof n=="function"&&o.isConnected&&e.isConnected&&o.parentNode)try{n.call(e,o,t);return}catch{}e.insertBefore(o,t)}function E(e,o,t,n){let s=new Set(o),i=globalThis.disposeNode;for(let r=t?t.nextSibling:e.firstChild;r&&r!==n;){let l=r.nextSibling;!s.has(r)&&!(h&&h.has(r))&&(e.removeChild(r),typeof i=="function"&&i(r)),r=l}let a=t?t.nextSibling:e.firstChild;for(let r of o){for(;a&&a!==n&&a!==r&&h&&h.has(a)&&!s.has(a);)a=a.nextSibling;r===a?a=a.nextSibling:ne(e,r,a)}}var h=null;function B(e,o){let t=h,n=new Set(t||[]);e.pairs.forEach(s=>O(s).forEach(i=>n.add(i))),e.map.forEach(s=>n.add(s)),h=n;try{o()}finally{h=t}}function P(e,o,t){let n=v(e),s=v(o),i=new Map,a=new Map;for(let d of n)d.keyed&&!a.has(d.key)&&a.set(d.key,d);let r=0;for(let d of s){if(d.keyed){let c=a.get(d.key);if(!c)continue;a.delete(d.key),M(c.rec)&&(!t||t(c,d))&&i.set(d,c);continue}for(let c=r;c<n.length;c++)if(!(n[c].keyed||n[c].key!==d.key)){r=c+1,M(n[c].rec)&&(!t||t(n[c],d))&&i.set(d,n[c]);break}}i.forEach((d,c)=>{c.el||(c.slots=W(c))});let l=new Set(i.values()),f=new Map;return i.forEach((d,c)=>f.set(c.el||c.start,c)),{pairs:i,byStart:f,map:new Map,carry:new Set,gone:n.filter(d=>!l.has(d)),live:n,next:s}}function G(e){let o=new Set(e.map.values());e.pairs.forEach((t,n)=>{let s=!0;n.chain.forEach((i,a)=>{if(e.carry.add(i),!s)return;let r=t.chain[a],l=e.map.get(i);if(l){s=l===r;return}r&&r.localName===i.localName&&!o.has(r)?(e.map.set(i,r),o.add(r)):s=!1})})}function w(e,o){let t=[];for(let n=0;n<o.length;n++){let s=o[n],i=e.byStart.get(s);if(i){if(t.push(...O(e.pairs.get(i))),i.end)for(;n<o.length-1&&o[n]!==i.end;)n++;continue}let a=e.map.get(s);if(a){K(a,s),E(a,w(e,Array.from(s.childNodes)),null,null),t.push(a);continue}e.carry.has(s)&&E(s,w(e,Array.from(s.childNodes)),null,null),t.push(s)}return t}function $(e){if(e.gone.length!==0||e.pairs.size!==e.next.length)return!1;let o=-1;for(let t of e.next){let n=e.live.indexOf(e.pairs.get(t));if(n<o)return!1;o=n}return!0}function q(e,o,t,n,s={}){let i=[];for(let l=o?o.nextSibling:e.firstChild;l&&l!==t;l=l.nextSibling)i.push(l);let a=[],r=P(i,n,s.sameProps?(l,f)=>j(l)===j(f):null);if(r.pairs.size>0&&$(r)&&b(T(i))===b(T(n)))return r.pairs.forEach((l,f)=>A(l,f,a)),a;for(let l of r.gone)y(O(l));return G(r),B(r,()=>E(e,w(r,n),o,t)),r.pairs.forEach((l,f)=>A(l,f,a)),a}function W(e){let o=[],t=0,n=[],s=i=>{if(k(i))return void t++;if(H(i))return void t--;if(t||i.nodeType!==8)return;let a=X.exec(i.data);if(!a)return;let r=i.parentElement&&i.parentElement.closest("krate-island");if(r&&n.some(c=>c===r||c.contains(r)))return;let l="/krate-slot:"+a[1],f=[],d=i.nextSibling;for(;d&&!(d.nodeType===8&&d.data===l);d=d.nextSibling)f.push(d);d&&o.push({id:a[1],nodes:f})};n=z(e.start,e.end).slice(1,-1);for(let i of n){if(i.nodeType===8){s(i);continue}if(i.nodeType!==1)continue;let a=(i.ownerDocument||document).createTreeWalker(i,128);for(let r=a.nextNode();r;r=a.nextNode())s(r)}return o}function te(e,o,t){let n=P(e,o,null),s=(r,l)=>{let f=new Map;for(let c of l)c.chain.length===0&&f.set(c.el||c.start,c);let d=[];for(let c=0;c<r.length;c++){let g=f.get(r[c]);if(d.push({node:r[c],isl:g}),g&&g.end)for(;c<r.length-1&&r[c]!==g.end;)c++}return d},i=s(e,n.live),a=s(o,n.next);if(i.length!==a.length)return!1;for(let r=0;r<i.length;r++){let l=i[r],f=a[r];if(l.isl||f.isl){if(!l.isl||!f.isl||n.pairs.get(f.isl)!==l.isl)return!1}else if(l.node.nodeType!==f.node.nodeType||l.node.nodeType===1&&l.node.localName!==f.node.localName)return!1}for(let r of n.gone)y(O(r));for(let r=0;r<i.length;r++)!i[r].isl&&i[r].node.nodeType===1&&n.map.set(a[r].node,i[r].node);return G(n),B(n,()=>{for(let r=0;r<i.length;r++){let l=i[r].node,f=a[r].node;i[r].isl||(l.nodeType===1?(K(l,f),E(l,w(n,Array.from(f.childNodes)),null,null)):l.data!==f.data&&(l.data=f.data))}}),n.pairs.forEach((r,l)=>A(r,l,t)),!0}function oe(e){return e.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/--/g,"-\\u002d")}function A(e,o,t){let n=e.rec.handle,s=S(o.json);if(s===void 0)return;if(e.el){if(o.json===e.json)return;try{let u=n.update(s);u&&typeof u.then=="function"&&t.push(u.catch(m=>console.error(m)))}catch(u){console.error(u)}return}let i={},a={},r=!1,l=n.slots||[],f=o.slots||W(o),d=[];if(f.forEach((u,m)=>{let p=l.length===f.length?l[m]:void 0,C=T(u.nodes);if(p){if(b(C)===b(p.html)){let _=P(p.set,u.nodes,null);if($(_)){_.pairs.forEach((Q,V)=>A(Q,V,t)),i[u.id]=p.id,d.push(p);return}}if(te(p.set,u.nodes,t)){i[u.id]=p.id,p.html=C,d.push(p);return}}p&&y(p.set),a[u.id]=[u.nodes],r=!0,d.push({id:u.id,html:C,set:u.nodes})}),l.length!==f.length)for(let u of l)y(u.set);n.slots=d;let c=I(s.p||{},u=>i[u]||u),g=S(e.json),F=r||JSON.stringify(c)!==JSON.stringify(g?g.p||{}:null);if(s.p=c,g&&g.i!==void 0&&(s.i=g.i),e.start.data=N+oe(JSON.stringify(s)),typeof n.sync=="function")try{n.sync()}catch(u){console.error(u)}if(F)try{let u=r?n.update(c,a):n.update(c);u&&typeof u.then=="function"&&t.push(u.catch(m=>console.error(m)))}catch(u){console.error(u)}}window.__krateIslandSwap={swap:q,unmount:y};})();
|