aboutsummaryrefslogtreecommitdiff
path: root/priv/static/lustre-server-component.min.mjs
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2024-04-01 19:02:57 +0100
committerHayleigh Thompson <me@hayleigh.dev>2024-04-01 19:02:57 +0100
commit5127e9904566ae94a1264e4321e2002297a057fc (patch)
treef376e16e307daf0e6fcf8272edd2dac5c10b8477 /priv/static/lustre-server-component.min.mjs
parent3ad7550a62a2bccdedc8004b46ab5c8293fcfb3a (diff)
downloadlustre-5127e9904566ae94a1264e4321e2002297a057fc.tar.gz
lustre-5127e9904566ae94a1264e4321e2002297a057fc.zip
:package: Generate server component runtime.
Diffstat (limited to 'priv/static/lustre-server-component.min.mjs')
-rw-r--r--priv/static/lustre-server-component.min.mjs2
1 files changed, 1 insertions, 1 deletions
diff --git a/priv/static/lustre-server-component.min.mjs b/priv/static/lustre-server-component.min.mjs
index 980f7f2..8cdbe00 100644
--- a/priv/static/lustre-server-component.min.mjs
+++ b/priv/static/lustre-server-component.min.mjs
@@ -1 +1 @@
-function k(r,n,o,s=!1){let t,l=[{prev:r,next:n,parent:r.parentNode}];for(;l.length;){let{prev:e,next:i,parent:u}=l.pop();if(i.subtree!==void 0&&(i=i.subtree()),i.content!==void 0)if(e)if(e.nodeType===Node.TEXT_NODE)e.textContent!==i.content&&(e.textContent=i.content),t??=e;else{let a=document.createTextNode(i.content);u.replaceChild(a,e),t??=a}else{let a=document.createTextNode(i.content);u.appendChild(a),t??=a}else if(i.tag!==void 0){let a=$({prev:e,next:i,dispatch:o,stack:l,isComponent:s});e?e!==a&&u.replaceChild(a,e):u.appendChild(a),t??=a}}return t}function T(r,n,o){let s=r.parentNode;for(let t of n[0]){let l=t[0].split("-"),e=t[1],i=N(s,l),u;if(i!==null&&i!==s)u=k(i,e,o);else{let a=N(s,l.slice(0,-1)),f=document.createTextNode("");a.appendChild(f),u=k(f,e,o)}l==="0"&&(r=u)}for(let t of n[1]){let l=t[0].split("-");N(s,l).remove()}for(let t of n[2]){let l=t[0].split("-"),e=t[1],i=N(s,l),u=v.get(i);for(let a of e[0]){let f=a[0],m=a[1];if(f.startsWith("data-lustre-on-")){let b=f.slice(15),d=o(J);u.has(b)||el.addEventListener(b,y),u.set(b,d),el.setAttribute(f,m)}else i.setAttribute(f,m),i[f]=m}for(let a of e[1])if(a[0].startsWith("data-lustre-on-")){let f=a[0].slice(15);i.removeEventListener(f,y),u.delete(f)}else i.removeAttribute(a[0])}return r}function $({prev:r,next:n,dispatch:o,stack:s}){let t=n.namespace||"http://www.w3.org/1999/xhtml",l=r&&r.nodeType===Node.ELEMENT_NODE&&r.localName===n.tag&&r.namespaceURI===(n.namespace||"http://www.w3.org/1999/xhtml"),e=l?r:t?document.createElementNS(t,n.tag):document.createElement(n.tag),i;if(v.has(e))i=v.get(e);else{let c=new Map;v.set(e,c),i=c}let u=l?new Set(i.keys()):null,a=l?new Set(Array.from(r.attributes,c=>c.name)):null,f=null,m=null,b=null;for(let c of n.attrs){let h=c[0],p=c[1];if(c[2])e[h]=p;else if(h.startsWith("on")){let g=h.slice(2),A=o(p);i.has(g)||e.addEventListener(g,y),i.set(g,A),l&&u.delete(g)}else if(h.startsWith("data-lustre-on-")){let g=h.slice(15),A=o(J);i.has(g)||e.addEventListener(g,y),i.set(g,A),e.setAttribute(h,p)}else h==="class"?f=f===null?p:f+" "+p:h==="style"?m=m===null?p:m+p:h==="dangerous-unescaped-html"?b=p:(e.setAttribute(h,p),h==="value"&&(e[h]=p),l&&a.delete(h))}if(f!==null&&(e.setAttribute("class",f),l&&a.delete("class")),m!==null&&(e.setAttribute("style",m),l&&a.delete("style")),l){for(let c of a)e.removeAttribute(c);for(let c of u)e.removeEventListener(c,y)}if(n.key!==void 0&&n.key!=="")e.setAttribute("data-lustre-key",n.key);else if(b!==null)return e.innerHTML=b,e;let d=e.firstChild,C=null,w=null,O=null,E=n.children[Symbol.iterator]().next().value;E!==void 0&&E.key!==void 0&&E.key!==""&&(C=new Set,w=L(r),O=L(n));for(let c of n.children)if(c.key!==void 0&&C!==null){for(;d&&!O.has(d.getAttribute("data-lustre-key"));){let p=d.nextSibling;e.removeChild(d),d=p}if(w.size===0){s.unshift({prev:d,next:c,parent:e}),d=d?.nextSibling;continue}if(C.has(c.key)){console.warn(`Duplicate key found in Lustre vnode: ${c.key}`),s.unshift({prev:null,next:c,parent:e});continue}C.add(c.key);let h=w.get(c.key);if(!h&&!d){s.unshift({prev:null,next:c,parent:e});continue}if(!h&&d!==null){let p=document.createTextNode("");e.insertBefore(p,d),s.unshift({prev:p,next:c,parent:e});continue}if(!h||h===d){s.unshift({prev:d,next:c,parent:e}),d=d?.nextSibling;continue}e.insertBefore(h,d),s.unshift({prev:h,next:c,parent:e})}else s.unshift({prev:d,next:c,parent:e}),d=d?.nextSibling;for(;d;){let c=d.nextSibling;e.removeChild(d),d=c}return e}var v=new WeakMap;function y(r){if(!v.has(r.target)){r.target.removeEventListener(r.type,y);return}let n=v.get(r.target);if(!n.has(r.type)){r.target.removeEventListener(r.type,y);return}n.get(r.type)(r)}function J(r){let n=r.target,o=n.getAttribute(`data-lustre-on-${r.type}`),s=JSON.parse(n.getAttribute("data-lustre-data")||"{}"),t=JSON.parse(n.getAttribute("data-lustre-include")||"[]");switch(r.type){case"input":case"change":t.push("target.value");break}return{tag:o,data:t.reduce((l,e)=>{let i=e.split(".");for(let u=0,a=l,f=r;u<i.length;u++)u===i.length-1?a[i[u]]=f[i[u]]:(a[i[u]]??={},f=f[i[u]],a=a[i[u]]);return l},{data:s})}}function L(r){let n=new Map;if(r)for(let o of r.children){let s=o.key||o?.getAttribute("data-lustre-key");s&&n.set(s,o)}return n}function N(r,n){let o,s,t=r;for(;[o,...s]=n,o!==void 0;)t=t.childNodes.item(o),n=s;return t}var S=class extends HTMLElement{static get observedAttributes(){return["route"]}#n=null;#t=null;#e=null;constructor(){super(),this.#n=new MutationObserver(n=>{let o=[];for(let s of n)if(s.type==="attributes"){let{attributeName:t,oldValue:l}=s,e=this.getAttribute(t);if(l!==e)try{o.push([t,JSON.parse(e)])}catch{o.push([t,e])}}o.length&&this.#e?.send(JSON.stringify([5,o]))})}connectedCallback(){this.#t=document.createElement("div"),this.appendChild(this.#t)}attributeChangedCallback(n,o,s){switch(n){case"route":if(!s)this.#e?.close(),this.#e=null;else if(o!==s){let t=this.getAttribute("id"),l=s+(t?`?id=${t}`:"");this.#e?.close(),this.#e=new WebSocket(`ws://${window.location.host}${l}`),this.#e.addEventListener("message",e=>this.messageReceivedCallback(e))}}}messageReceivedCallback({data:n}){let[o,...s]=JSON.parse(n);switch(o){case 0:return this.diff(s);case 1:return this.emit(s);case 2:return this.init(s)}}init([n,o]){let s=[];for(let t of n)t in this?s.push([t,this[t]]):this.hasAttribute(t)&&s.push([t,this.getAttribute(t)]),Object.defineProperty(this,t,{get(){return this[`_${t}`]??this.getAttribute(t)},set(l){let e=this[t];typeof l=="string"?this.setAttribute(t,l):this[`_${t}`]=l,e!==l&&this.#e?.send(JSON.stringify([5,[[t,l]]]))}});this.#n.observe(this,{attributeFilter:n,attributeOldValue:!0,attributes:!0,characterData:!1,characterDataOldValue:!1,childList:!1,subtree:!1}),this.morph(o),s.length&&this.#e?.send(JSON.stringify([5,s]))}morph(n){this.#t=k(this.#t,n,o=>s=>{let t=o(s);this.#e?.send(JSON.stringify([4,t.tag,t.data]))})}diff([n]){this.#t=T(this.#t,n,o=>s=>{let t=o(s);this.#e?.send(JSON.stringify([4,t.tag,t.data]))})}emit([n,o]){this.dispatchEvent(new CustomEvent(n,{detail:o}))}disconnectedCallback(){this.#e?.close()}};window.customElements.define("lustre-server-component",S);export{S as LustreServerComponent};
+function k(l,n,i,s=!1){let t,o=[{prev:l,next:n,parent:l.parentNode}];for(;o.length;){let{prev:e,next:r,parent:u}=o.pop();if(r.subtree!==void 0&&(r=r.subtree()),r.content!==void 0)if(e)if(e.nodeType===Node.TEXT_NODE)e.textContent!==r.content&&(e.textContent=r.content),t??=e;else{let a=document.createTextNode(r.content);u.replaceChild(a,e),t??=a}else{let a=document.createTextNode(r.content);u.appendChild(a),t??=a}else if(r.tag!==void 0){let a=$({prev:e,next:r,dispatch:i,stack:o,isComponent:s});e?e!==a&&u.replaceChild(a,e):u.appendChild(a),t??=a}}return t}function L(l,n,i){let s=l.parentNode;for(let t of n[0]){let o=t[0].split("-"),e=t[1],r=N(s,o),u;if(r!==null&&r!==s)u=k(r,e,i);else{let a=N(s,o.slice(0,-1)),f=document.createTextNode("");a.appendChild(f),u=k(f,e,i)}o==="0"&&(l=u)}for(let t of n[1]){let o=t[0].split("-");N(s,o).remove()}for(let t of n[2]){let o=t[0].split("-"),e=t[1],r=N(s,o),u=v.get(r);for(let a of e[0]){let f=a[0],m=a[1];if(f.startsWith("data-lustre-on-")){let b=f.slice(15),d=i(J);u.has(b)||el.addEventListener(b,y),u.set(b,d),el.setAttribute(f,m)}else r.setAttribute(f,m),r[f]=m}for(let a of e[1])if(a[0].startsWith("data-lustre-on-")){let f=a[0].slice(15);r.removeEventListener(f,y),u.delete(f)}else r.removeAttribute(a[0])}return l}function $({prev:l,next:n,dispatch:i,stack:s}){let t=n.namespace||"http://www.w3.org/1999/xhtml",o=l&&l.nodeType===Node.ELEMENT_NODE&&l.localName===n.tag&&l.namespaceURI===(n.namespace||"http://www.w3.org/1999/xhtml"),e=o?l:t?document.createElementNS(t,n.tag):document.createElement(n.tag),r;if(v.has(e))r=v.get(e);else{let c=new Map;v.set(e,c),r=c}let u=o?new Set(r.keys()):null,a=o?new Set(Array.from(l.attributes,c=>c.name)):null,f=null,m=null,b=null;for(let c of n.attrs){let h=c[0],p=c[1];if(c[2])e[h]=p;else if(h.startsWith("on")){let g=h.slice(2),A=i(p);r.has(g)||e.addEventListener(g,y),r.set(g,A),o&&u.delete(g)}else if(h.startsWith("data-lustre-on-")){let g=h.slice(15),A=i(J);r.has(g)||e.addEventListener(g,y),r.set(g,A),e.setAttribute(h,p)}else h==="class"?f=f===null?p:f+" "+p:h==="style"?m=m===null?p:m+p:h==="dangerous-unescaped-html"?b=p:(e.setAttribute(h,p),h==="value"&&(e[h]=p),o&&a.delete(h))}if(f!==null&&(e.setAttribute("class",f),o&&a.delete("class")),m!==null&&(e.setAttribute("style",m),o&&a.delete("style")),o){for(let c of a)e.removeAttribute(c);for(let c of u)e.removeEventListener(c,y)}if(n.key!==void 0&&n.key!=="")e.setAttribute("data-lustre-key",n.key);else if(b!==null)return e.innerHTML=b,e;let d=e.firstChild,C=null,w=null,O=null,E=n.children[Symbol.iterator]().next().value;E!==void 0&&E.key!==void 0&&E.key!==""&&(C=new Set,w=T(l),O=T(n));for(let c of n.children)if(c.key!==void 0&&C!==null){for(;d&&!O.has(d.getAttribute("data-lustre-key"));){let p=d.nextSibling;e.removeChild(d),d=p}if(w.size===0){s.unshift({prev:d,next:c,parent:e}),d=d?.nextSibling;continue}if(C.has(c.key)){console.warn(`Duplicate key found in Lustre vnode: ${c.key}`),s.unshift({prev:null,next:c,parent:e});continue}C.add(c.key);let h=w.get(c.key);if(!h&&!d){s.unshift({prev:null,next:c,parent:e});continue}if(!h&&d!==null){let p=document.createTextNode("");e.insertBefore(p,d),s.unshift({prev:p,next:c,parent:e});continue}if(!h||h===d){s.unshift({prev:d,next:c,parent:e}),d=d?.nextSibling;continue}e.insertBefore(h,d),s.unshift({prev:h,next:c,parent:e})}else s.unshift({prev:d,next:c,parent:e}),d=d?.nextSibling;for(;d;){let c=d.nextSibling;e.removeChild(d),d=c}return e}var v=new WeakMap;function y(l){let n=l.currentTarget;if(!v.has(n)){n.removeEventListener(l.type,y);return}let i=v.get(n);if(!i.has(l.type)){n.removeEventListener(l.type,y);return}i.get(l.type)(l)}function J(l){let n=l.target,i=n.getAttribute(`data-lustre-on-${l.type}`),s=JSON.parse(n.getAttribute("data-lustre-data")||"{}"),t=JSON.parse(n.getAttribute("data-lustre-include")||"[]");switch(l.type){case"input":case"change":t.push("target.value");break}return{tag:i,data:t.reduce((o,e)=>{let r=e.split(".");for(let u=0,a=o,f=l;u<r.length;u++)u===r.length-1?a[r[u]]=f[r[u]]:(a[r[u]]??={},f=f[r[u]],a=a[r[u]]);return o},{data:s})}}function T(l){let n=new Map;if(l)for(let i of l.children){let s=i.key||i?.getAttribute("data-lustre-key");s&&n.set(s,i)}return n}function N(l,n){let i,s,t=l;for(;[i,...s]=n,i!==void 0;)t=t.childNodes.item(i),n=s;return t}var S=class extends HTMLElement{static get observedAttributes(){return["route"]}#n=null;#t=null;#e=null;constructor(){super(),this.#n=new MutationObserver(n=>{let i=[];for(let s of n)if(s.type==="attributes"){let{attributeName:t,oldValue:o}=s,e=this.getAttribute(t);if(o!==e)try{i.push([t,JSON.parse(e)])}catch{i.push([t,e])}}i.length&&this.#e?.send(JSON.stringify([5,i]))})}connectedCallback(){this.#t=document.createElement("div"),this.appendChild(this.#t)}attributeChangedCallback(n,i,s){switch(n){case"route":if(!s)this.#e?.close(),this.#e=null;else if(i!==s){let t=this.getAttribute("id"),o=s+(t?`?id=${t}`:"");this.#e?.close(),this.#e=new WebSocket(`ws://${window.location.host}${o}`),this.#e.addEventListener("message",e=>this.messageReceivedCallback(e))}}}messageReceivedCallback({data:n}){let[i,...s]=JSON.parse(n);switch(i){case 0:return this.diff(s);case 1:return this.emit(s);case 2:return this.init(s)}}init([n,i]){let s=[];for(let t of n)t in this?s.push([t,this[t]]):this.hasAttribute(t)&&s.push([t,this.getAttribute(t)]),Object.defineProperty(this,t,{get(){return this[`_${t}`]??this.getAttribute(t)},set(o){let e=this[t];typeof o=="string"?this.setAttribute(t,o):this[`_${t}`]=o,e!==o&&this.#e?.send(JSON.stringify([5,[[t,o]]]))}});this.#n.observe(this,{attributeFilter:n,attributeOldValue:!0,attributes:!0,characterData:!1,characterDataOldValue:!1,childList:!1,subtree:!1}),this.morph(i),s.length&&this.#e?.send(JSON.stringify([5,s]))}morph(n){this.#t=k(this.#t,n,i=>s=>{let t=i(s);this.#e?.send(JSON.stringify([4,t.tag,t.data]))})}diff([n]){this.#t=L(this.#t,n,i=>s=>{let t=i(s);this.#e?.send(JSON.stringify([4,t.tag,t.data]))})}emit([n,i]){this.dispatchEvent(new CustomEvent(n,{detail:i}))}disconnectedCallback(){this.#e?.close()}};window.customElements.define("lustre-server-component",S);export{S as LustreServerComponent};