@krate/runtime 0.5.0-rc.6 → 0.5.0-rc.7

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.
@@ -0,0 +1 @@
1
+ (()=>{var N="krate-island:",j="/krate-island",I="<!--"+N,_="<!--"+j+"-->",K=/^krate-slot:([0-9a-z]+)$/;function A(e){return e.nodeType===8&&e.data.indexOf(N)===0}function M(e){return e.nodeType===8&&e.data===j}function D(e){return e.nodeType===1&&e.localName==="krate-island"&&e.hasAttribute("data-src")}function F(e){let o=0;for(let t=e.nextSibling;t;t=t.nextSibling)if(A(t))o++;else if(M(t)){if(!o)return t;o--}return null}function H(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]:H(e.start,e.end)}function Q(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 T(e,o=[],t=[]){for(let n=0;n<e.length;n++){let r=e[n];if(A(r)){let i=F(r),a=null;try{a=JSON.parse(r.data.slice(N.length))}catch{a=null}if(!i||!a)continue;for(t.push({key:a.m+"#"+a.e,start:r,end:i,json:r.data.slice(N.length),chain:o,rec:r.__krateIsland});n<e.length-1&&e[n]!==i;)n++}else D(r)?t.push({key:r.getAttribute("data-module")+"#"+r.getAttribute("data-export"),el:r,json:Q(r),chain:o,rec:r.__krateIsland}):r.nodeType===1&&T(r.childNodes,o.concat(r),t)}return t}function V(e){let o=e&&e.handle;return!!e&&!e.gone&&e.status==="hydrated"&&!!o&&typeof o.update=="function"&&typeof o.unmount=="function"}function x(e,o){if(Array.isArray(e))return e.map(n=>x(n,o));if(!e||typeof e!="object")return e;let t={};for(let n in e){let r=e[n];n==="__krateSlotRef"&&typeof r=="string"||n==="r"&&e.$==="h"&&typeof r=="string"?t[n]=o(r):t[n]=x(r,o)}return t}function k(e){try{return JSON.parse(e)}catch{return}}function L(e){let o=k(e.json);return JSON.stringify(x(e.el?o:o&&o.p,()=>""))}function P(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 X(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 S(e){let o="",t=0;for(;;){let n=e.indexOf(I,t),r=X(e,t);if(n<0&&r<0)return o+e.slice(t);if(r>=0&&(n<0||r<n)){let c=e.indexOf("</krate-island>",r);if(c<0)return o+e.slice(t);o+=e.slice(t,r)+"<!--i:"+(/data-module="([^"]*)"/.exec(e.slice(r,e.indexOf(">",r)))||["",""])[1]+"-->",t=c+15;continue}let i=e.indexOf("-->",n);if(i<0)return o+e.slice(t);let a=k(e.slice(n+I.length,i)),s=i+3,l=0;for(;;){let c=e.indexOf(I,s),d=e.indexOf(_,s);if(d<0)return o+e.slice(t);if(c>=0&&c<d){l++,s=c+I.length;continue}if(s=d+_.length,!l)break;l--}o+=e.slice(t,n)+"<!--i:"+(a?a.m+"#"+a.e:"")+"-->",t=s}}function Y(e){let o=[],t=n=>{let r=n.__krateIsland;r&&(A(n)||D(n))&&o.push(r)};for(let n=0;n<e.length;n++){let r=e[n];if(t(r),r.nodeType!==1)continue;let a=(r.ownerDocument||document).createTreeWalker(r,129);for(let s=a.nextNode();s;s=a.nextNode())t(s)}return o}function m(e){let o=Y(e);for(let t=o.length-1;t>=0;t--){let n=o[t];if(n.gone)continue;n.gone=!0;let r=n.handle;if(!(!r||typeof r.unmount!="function"))try{r.unmount()}catch(i){console.error(i)}}}function J(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 Z(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 b(e,o,t,n){let r=new Set(o),i=globalThis.disposeNode;for(let s=t?t.nextSibling:e.firstChild;s&&s!==n;){let l=s.nextSibling;!r.has(s)&&!(g&&g.has(s))&&(e.removeChild(s),typeof i=="function"&&i(s)),s=l}let a=t?t.nextSibling:e.firstChild;for(let s of o){for(;a&&a!==n&&a!==s&&g&&g.has(a)&&!r.has(a);)a=a.nextSibling;s===a?a=a.nextSibling:Z(e,s,a)}}var g=null;function U(e,o){let t=g,n=new Set(t||[]);e.pairs.forEach(r=>O(r).forEach(i=>n.add(i))),e.map.forEach(r=>n.add(r)),g=n;try{o()}finally{g=t}}function v(e,o,t){let n=T(e),r=T(o),i=new Map,a=0;for(let c of r)for(let d=a;d<n.length;d++)if(n[d].key===c.key){a=d+1,V(n[d].rec)&&(!t||t(n[d],c))&&i.set(c,n[d]);break}let s=new Set(i.values()),l=new Map;return i.forEach((c,d)=>l.set(d.el||d.start,d)),{pairs:i,byStart:l,map:new Map,carry:new Set,gone:n.filter(c=>!s.has(c)),live:n,next:r}}function z(e){let o=new Set(e.map.values());e.pairs.forEach((t,n)=>{let r=!0;n.chain.forEach((i,a)=>{if(e.carry.add(i),!r)return;let s=t.chain[a],l=e.map.get(i);if(l){r=l===s;return}s&&s.localName===i.localName&&!o.has(s)?(e.map.set(i,s),o.add(s)):r=!1})})}function E(e,o){let t=[];for(let n=0;n<o.length;n++){let r=o[n],i=e.byStart.get(r);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(r);if(a){J(a,r),b(a,E(e,Array.from(r.childNodes)),null,null),t.push(a);continue}e.carry.has(r)&&b(r,E(e,Array.from(r.childNodes)),null,null),t.push(r)}return t}function B(e){return e.gone.length===0&&e.pairs.size===e.next.length}function G(e,o,t,n,r={}){let i=[];for(let l=o?o.nextSibling:e.firstChild;l&&l!==t;l=l.nextSibling)i.push(l);let a=[],s=v(i,n,r.sameProps?(l,c)=>L(l)===L(c):null);if(s.pairs.size>0&&B(s)&&S(P(i))===S(P(n)))return s.pairs.forEach((l,c)=>w(l,c,a)),a;for(let l of s.gone)m(O(l));return z(s),U(s,()=>b(e,E(s,n),o,t)),s.pairs.forEach((l,c)=>w(l,c,a)),a}function ee(e){let o=[],t=0,n=[],r=i=>{if(A(i))return void t++;if(M(i))return void t--;if(t||i.nodeType!==8)return;let a=K.exec(i.data);if(!a)return;let s=i.parentElement&&i.parentElement.closest("krate-island");if(s&&n.some(f=>f===s||f.contains(s)))return;let l="/krate-slot:"+a[1],c=[],d=i.nextSibling;for(;d&&!(d.nodeType===8&&d.data===l);d=d.nextSibling)c.push(d);d&&o.push({id:a[1],nodes:c})};n=H(e.start,e.end).slice(1,-1);for(let i of n){if(i.nodeType===8){r(i);continue}if(i.nodeType!==1)continue;let a=(i.ownerDocument||document).createTreeWalker(i,128);for(let s=a.nextNode();s;s=a.nextNode())r(s)}return o}function ne(e,o,t){let n=v(e,o,null),r=(s,l)=>{let c=new Map;for(let f of l)f.chain.length===0&&c.set(f.el||f.start,f);let d=[];for(let f=0;f<s.length;f++){let h=c.get(s[f]);if(d.push({node:s[f],isl:h}),h&&h.end)for(;f<s.length-1&&s[f]!==h.end;)f++}return d},i=r(e,n.live),a=r(o,n.next);if(i.length!==a.length)return!1;for(let s=0;s<i.length;s++){let l=i[s],c=a[s];if(l.isl||c.isl){if(!l.isl||!c.isl||n.pairs.get(c.isl)!==l.isl)return!1}else if(l.node.nodeType!==c.node.nodeType||l.node.nodeType===1&&l.node.localName!==c.node.localName)return!1}for(let s of n.gone)m(O(s));for(let s=0;s<i.length;s++)!i[s].isl&&i[s].node.nodeType===1&&n.map.set(a[s].node,i[s].node);return z(n),U(n,()=>{for(let s=0;s<i.length;s++){let l=i[s].node,c=a[s].node;i[s].isl||(l.nodeType===1?(J(l,c),b(l,E(n,Array.from(c.childNodes)),null,null)):l.data!==c.data&&(l.data=c.data))}}),n.pairs.forEach((s,l)=>w(s,l,t)),!0}function te(e){return e.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/--/g,"-\\u002d")}function w(e,o,t){let n=e.rec.handle,r=k(o.json);if(r===void 0)return;if(e.el){if(o.json===e.json)return;try{let u=n.update(r);u&&typeof u.then=="function"&&t.push(u.catch(y=>console.error(y)))}catch(u){console.error(u)}return}let i={},a={},s=!1,l=n.slots||[],c=ee(o),d=[];if(c.forEach((u,y)=>{let p=l.length===c.length?l[y]:void 0,C=P(u.nodes);if(p){if(S(C)===S(p.html)){let R=v(p.set,u.nodes,null);if(B(R)){R.pairs.forEach(($,q)=>w($,q,t)),i[u.id]=p.id,d.push(p);return}}if(ne(p.set,u.nodes,t)){i[u.id]=p.id,p.html=C,d.push(p);return}}p&&m(p.set),a[u.id]=[u.nodes],s=!0,d.push({id:u.id,html:C,set:u.nodes})}),l.length!==c.length)for(let u of l)m(u.set);n.slots=d;let f=x(r.p||{},u=>i[u]||u),h=k(e.json),W=s||JSON.stringify(f)!==JSON.stringify(h?h.p||{}:null);if(r.p=f,e.start.data=N+te(JSON.stringify(r)),!!W)try{let u=s?n.update(f,a):n.update(f);u&&typeof u.then=="function"&&t.push(u.catch(y=>console.error(y)))}catch(u){console.error(u)}}window.__krateIslandSwap={swap:G,unmount:m};})();