hyperf
Version:
Hypertext fragments with reactivity
1 lines • 4.77 kB
JavaScript
var e=function(t,r,n,l){var o;r[0]=0;for(var s=1;s<r.length;s++){var i=r[s++],a=r[s]?(r[0]|=i?1:2,n[r[s++]]):r[++s];3===i?l[0]=a:4===i?l[1]=Object.assign(l[1]||{},a):5===i?(l[1]=l[1]||{})[r[++s]]=a:6===i?l[1][r[++s]]+=a+"":i?(o=t.apply(a,e(t,a,n,["",null])),l.push(o),a[0]?r[0]|=2:(r[s-2]=0,r[s]=o)):l.push(a)}return l},t=new Map;function r(r){var n=t.get(this);return n||(n=new Map,t.set(this,n)),(n=e(this,n.get(r)||(n.set(r,n=function(e){for(var t,r,n=1,l="",o="",s=[0],i=function(e){1===n&&(e||(l=l.replace(/^\s*\n\s*|\s*\n\s*$/g,"")))?s.push(0,e,l):3===n&&(e||l)?(s.push(3,e,l),n=2):2===n&&"..."===l&&e?s.push(4,e,0):2===n&&l&&!e?s.push(5,0,!0,l):n>=5&&((l||!e&&5===n)&&(s.push(n,0,l,r),n=6),e&&(s.push(n,e,0,r),n=6)),l=""},a=0;a<e.length;a++){a&&(1===n&&i(),i(a));for(var u=0;u<e[a].length;u++)t=e[a][u],1===n?"<"===t?(i(),s=[s],n=3):l+=t:4===n?"--"===l&&">"===t?(n=1,l=""):l=t+l[0]:o?t===o?o="":l+=t:'"'===t||"'"===t?o=t:">"===t?(i(),n=1):n&&("="===t?(n=5,r=l,l=""):"/"===t&&(n<5||">"===e[a][u+1])?(i(),3===n&&(s=s[0]),n=s,(s=s[0]).push(2,0,n),n=0):" "===t||"\t"===t||"\n"===t||"\r"===t?(i(),n=2):l+=t),3===n&&"!--"===l&&(n=4,s=s[0])}return i(),s}(r)),n),arguments,[])).length>1?n:n[0]}Symbol.observable||=Symbol("observable");const n=e=>e&&!!(e[Symbol.observable]||e[Symbol.asyncIterator]||e.call&&e.set||e.subscribe||e.then),l=new FinalizationRegistry((e=>e.call?.()));var o=(e,t,r,n,o,s)=>{return e&&(i=(e[Symbol.observable]?.()||e).subscribe?.(t,r,n),s=i&&(()=>i.unsubscribe?.())||e.set&&e.call?.(o,t)||(e.then?.((e=>(!o&&t(e),n?.())),r)||(async l=>{try{for await(l of e){if(o)return;t(l)}n?.()}catch(e){r?.(e)}})())&&(e=>o=1),l.register(e,s),s);var i};const s=(e,t,r,n=null)=>{let l,o,i,a=0,u=r.length,c=t.length,{remove:f,same:p,insert:h,replace:d}=s;for(;a<u&&a<c&&p(t[a],r[a]);)a++;for(;a<u&&a<c&&p(r[u-1],t[c-1]);)n=r[(--c,--u)];if(a==c)for(;a<u;)h(n,r[a++],e);else{for(l=t[a];a<u;)i=r[a++],o=l?l.nextSibling:n,p(l,i)?l=o:a<u&&p(r[a],o)?(d(l,i,e),l=o):h(l,i,e);for(;!p(l,n);)o=l.nextSibling,f(l,e),l=o}return r};s.same=(e,t)=>e==t,s.replace=(e,t,r)=>r.replaceChild(t,e),s.insert=(e,t,r)=>r.insertBefore(t,e),s.remove=(e,t)=>t.removeChild(e);const i=(e,t,r)=>{if(t.startsWith("on")&&(t=t.toLowerCase()),e[t]!==r&&(e[t]=r),null==r||!1===r)e.removeAttribute(t);else if("function"!=typeof r)if(r=!0===r?"":"number"==typeof r||"string"==typeof r?r:"class"===t?(Array.isArray(r)?r.map((e=>e?.trim())):Object.entries(r).map((([e,t])=>t?e:""))).filter(Boolean).join(" "):"style"===t?Object.entries(r).map((([e,t])=>`${e}: ${t}`)).join(";"):r.toString?.()||"","@"===t[0]){a.innerHTML=`<x ${u(t)}/>`;let n=a.firstChild.attributes[0];a.firstChild.removeAttributeNode(n),n.value=r,e.setAttributeNode(n)}else e.setAttribute(u(t),r)},a=document.createElement("div");function u(e){return e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(e=>"-"+e.toLowerCase()))}const c=Symbol();s.same=(e,t)=>e===t||null!=e?.data&&e.data===t?.data,s.insert=(e,t,r)=>null!=t&&r.insertBefore(t?.nodeType?t:y.createTextNode(t),e),s.replace=(e,t,r)=>t?t.nodeType?r.replaceChild(t,e):e.nodeType===f?e.data=t:e.replaceWith(t):e.replace();const f=3,p=e=>e!==Object(e),h=new WeakSet,d={_init:!1},y=document,m=function(e,t,...r){let{_init:l}=this;if("string"==typeof e){if(e=e?y.createElement(e):y.createDocumentFragment(),l){e[c]=!0;for(let r in t)i(e,r,t[r]);return("TEMPLATE"===e.nodeName?e.content:e).append(...b(r)),e}}else{if(l)return null;if("function"==typeof e){if(!(e=e({children:r,...t})))return;return e.nodeType===f||1===e.nodeType||11===e.nodeType?e:Array.isArray(e)?m(y.createDocumentFragment(),null,...e):n(e)?e:m(y.createDocumentFragment(),null,e)}}let a,u,p,h,d,g,v,T,A=[];for(h in t)if(d=t[h],"string"==typeof d&&h.startsWith("class")&&(d=d.replace(/\b(false|null|undefined)\b/g,"")),n(d))o(d,(t=>i(e,h,t)));else if("string"!=typeof d&&"style"===h)for(g in d)n(v=d[g])?o(v,(t=>e.style.setProperty(g,t))):(T=v.match(/(.*)\W+!important\W*$/))?e.style.setProperty(g,T[1],"important"):e.style.setProperty(g,v);else i(e,h,d);if(r.length){for(a=0,u=(r=b(r)).length;a<u;a++)(p=r[a])&&(p[c]?r[a]=p.cloneNode(!0):n(p)&&(A[a]=p,r[a]=y.createTextNode("")));e.childNodes.length?s(e,e.childNodes,r):("TEMPLATE"===e.nodeName?e.content:e).append(...r),A.length&&A.forEach(((t,n)=>o(t,(t=>(r[n]=t,s(e,e.childNodes,b(r)))))))}else e.innerHTML="";return e}.bind(d);function b(e){let t,r=[],n=0;for(;n<e.length;)if(null!=(t=e[n++]))if(t.values)for(t of t)r.push(t);else r.push(t);return r}function g(e){if(!Array.isArray(e))return m(...arguments);let t,n=1;for(h.has(e)||(n++,h.add(e));n--;)d._init=!!n,t=r.apply(m,n?[e]:arguments);return Array.isArray(t)?m(y.createDocumentFragment(),null,...t):t?.[c]?t.cloneNode(!0):t?.nodeType?t:p(t)?y.createTextNode(t??""):t}export{c as _static,g as default};