-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathasync.js
More file actions
2 lines (2 loc) · 6.36 KB
/
Copy pathasync.js
File metadata and controls
2 lines (2 loc) · 6.36 KB
1
2
self.uhtml=function(e){"use strict";class t extends Map{set(e,t){return super.set(e,t),t}}class n extends WeakMap{set(e,t){return super.set(e,t),t}}const{isArray:r}=Array,s=(e,t)=>{const n=[];for(const{length:l}=e;t<l;t++)n.push(r(e[t])?s(e[t],0):e[t]);return Promise.all(n)};var l=e=>{function t(t,n){return e.apply(this,[t].concat(n))}return function(e){return s(arguments,1).then(t.bind(this,e))}};
/*! (c) Andrea Giammarchi - ISC */const o=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,a=/<([a-z]+[a-z0-9:._-]*)([^>]*?)(\/?)>/g,c=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,i=/[\x01\x02]/g;const u=(e,t)=>111===e.nodeType?1/t<0?t?(({firstChild:e,lastChild:t})=>{const n=document.createRange();return n.setStartAfter(e),n.setEndAfter(t),n.deleteContents(),e})(e):e.lastChild:t?e.valueOf():e.firstChild:e,{isArray:d}=Array,f=e=>null==e?e:e.valueOf(),p=(e,t)=>{let n,r,s=t.slice(2);return!(t in e)&&(r=t.toLowerCase())in e&&(s=r.slice(2)),t=>{const r=d(t)?t:[t,!1];n!==r[0]&&(n&&e.removeEventListener(s,n,r[1]),(n=r[0])&&e.addEventListener(s,n,r[1]))}};const{isArray:h,prototype:m}=Array,{indexOf:g}=m,{createDocumentFragment:y,createElement:b,createElementNS:v,createTextNode:w,createTreeWalker:x,importNode:N}=new Proxy({},{get:(e,t)=>document[t].bind(document)});let A;const C=(e,t)=>t?(e=>{A||(A=v("http://www.w3.org/2000/svg","svg")),A.innerHTML=e;const t=y();return t.append(...A.childNodes),t})(e):(e=>{const t=b("template");return t.innerHTML=e,t.content})(e),k=({childNodes:e},t)=>e[t],$=(e,t,n)=>((e,t,n,r,s)=>{const l=n.length;let o=t.length,a=l,c=0,i=0,u=null;for(;c<o||i<a;)if(o===c){const t=a<l?i?r(n[i-1],-0).nextSibling:r(n[a-i],0):s;for(;i<a;)e.insertBefore(r(n[i++],1),t)}else if(a===i)for(;c<o;)u&&u.has(t[c])||e.removeChild(r(t[c],-1)),c++;else if(t[c]===n[i])c++,i++;else if(t[o-1]===n[a-1])o--,a--;else if(t[c]===n[a-1]&&n[i]===t[o-1]){const s=r(t[--o],-1).nextSibling;e.insertBefore(r(n[i++],1),r(t[c++],-1).nextSibling),e.insertBefore(r(n[--a],1),s),t[o]=n[a]}else{if(!u){u=new Map;let e=i;for(;e<a;)u.set(n[e],e++)}if(u.has(t[c])){const s=u.get(t[c]);if(i<s&&s<a){let l=c,d=1;for(;++l<o&&l<a&&u.get(t[l])===s+d;)d++;if(d>s-i){const l=r(t[c],0);for(;i<s;)e.insertBefore(r(n[i++],1),l)}else e.replaceChild(r(n[i++],1),r(t[c++],-1))}else c++}else e.removeChild(r(t[c++],-1))}return n})(e.parentNode,t,n,u,e),E=(e,t)=>{switch(t[0]){case"?":return((e,t,n)=>r=>{const s=!!f(r);n!==s&&((n=s)?e.setAttribute(t,""):e.removeAttribute(t))})(e,t.slice(1),!1);case".":return((e,t)=>"dataset"===t?(({dataset:e})=>t=>{for(const n in t){const r=t[n];null==r?delete e[n]:e[n]=r}})(e):n=>{e[t]=n})(e,t.slice(1));case"@":return p(e,"on"+t.slice(1));case"o":if("n"===t[1])return p(e,t)}switch(t){case"ref":return(e=>{let t;return n=>{t!==n&&(t=n,"function"==typeof n?n(e):n.current=e)}})(e);case"aria":return(e=>t=>{for(const n in t){const r="role"===n?n:`aria-${n}`,s=t[n];null==s?e.removeAttribute(r):e.setAttribute(r,s)}})(e)}return((e,t)=>{let n,r=!0;const s=document.createAttributeNS(null,t);return t=>{const l=f(t);n!==l&&(null==(n=l)?r||(e.removeAttributeNode(s),r=!0):(s.value=l,r&&(e.setAttributeNodeNS(s),r=!1)))}})(e,t)};function O(e){const{type:t,path:n}=e,r=n.reduceRight(k,this);return"node"===t?(e=>{let t,n,r=[];const s=l=>{switch(typeof l){case"string":case"number":case"boolean":t!==l&&(t=l,n||(n=w("")),n.data=l,r=$(e,r,[n]));break;case"object":case"undefined":if(null==l){t!=l&&(t=l,r=$(e,r,[]));break}if(h(l)){t=l,0===l.length?r=$(e,r,[]):"object"==typeof l[0]?r=$(e,r,l):s(String(l));break}if(t!==l)if("ELEMENT_NODE"in l)t=l,r=$(e,r,11===l.nodeType?[...l.childNodes]:[l]);else{const e=l.valueOf();e!==l&&s(e)}break;case"function":s(l(e))}};return s})(r):"attr"===t?E(r,e.name):(e=>{let t;return n=>{const r=f(n);t!=r&&(t=r,e.textContent=null==r?"":r)}})(r)}const T=e=>{const t=[];let{parentNode:n}=e;for(;n;)t.push(g.call(n.childNodes,e)),e=n,({parentNode:n}=e);return t},S="isµ",L=new n,M=/^(?:textarea|script|style|title|plaintext|xmp)$/,j=(e,t)=>{const n="svg"===e,r=((e,t,n)=>{let r=0;return e.join("").trim().replace(a,((e,t,r,s)=>{let l=t+r.replace(c,"=$2$1").trimEnd();return s.length&&(l+=n||o.test(t)?" /":"></"+t),"<"+l+">"})).replace(i,(e=>""===e?"\x3c!--"+t+r+++"--\x3e":t+r++))})(t,S,n),s=C(r,n),l=x(s,129),u=[],d=t.length-1;let f=0,p=`${S}${f}`;for(;f<d;){const e=l.nextNode();if(!e)throw`bad template: ${r}`;if(8===e.nodeType)e.data===p&&(u.push({type:"node",path:T(e)}),p=`${S}${++f}`);else{for(;e.hasAttribute(p);)u.push({type:"attr",path:T(e),name:e.getAttribute(p)}),e.removeAttribute(p),p=`${S}${++f}`;M.test(e.localName)&&e.textContent.trim()===`\x3c!--${p}--\x3e`&&(e.textContent="",u.push({type:"text",path:T(e)}),p=`${S}${++f}`)}}return{content:s,nodes:u}},B=(e,t)=>{const{content:n,nodes:r}=L.get(t)||L.set(t,j(e,t)),s=N(n,!0);return{content:s,updates:r.map(O,s)}},P=(e,{type:t,template:n,values:r})=>{const s=D(e,r);let{entry:l}=e;l&&l.template===n&&l.type===t||(e.entry=l=((e,t)=>{const{content:n,updates:r}=B(e,t);return{type:e,template:t,content:n,updates:r,wire:null}})(t,n));const{content:o,updates:a,wire:c}=l;for(let e=0;e<s;e++)a[e](r[e]);return c||(l.wire=(e=>{const{firstChild:t,lastChild:n}=e;if(t===n)return n||e;const{childNodes:r}=e,s=[...r];return{ELEMENT_NODE:1,nodeType:111,firstChild:t,lastChild:n,valueOf:()=>(r.length!==s.length&&e.append(...s),e)}})(o))},D=({stack:e},t)=>{const{length:n}=t;for(let r=0;r<n;r++){const n=t[r];n instanceof H?t[r]=P(e[r]||(e[r]={stack:[],entry:null,wire:null}),n):h(n)?D(e[r]||(e[r]={stack:[],entry:null,wire:null}),n):e[r]=null}return n<e.length&&e.splice(n),n};class H{constructor(e,t,n){this.type=e,this.template=t,this.values=n}}const _=e=>{const r=new n;return Object.assign(((t,...n)=>new H(e,t,n)),{for(n,s){const l=r.get(n)||r.set(n,new t);return l.get(s)||l.set(s,(t=>(n,...r)=>P(t,{type:e,template:n,values:r}))({stack:[],entry:null,wire:null}))},node:(t,...n)=>P({stack:[],entry:null,wire:null},new H(e,t,n)).valueOf()})},z=new n,R=_("html"),W=_("svg"),{defineProperties:F}=Object,q=e=>{const t=new n;return F(l(e),{for:{value(n,r){const s=e.for(n,r);return t.get(s)||t.set(s,l(s))}},node:{value:l(e.node)}})},G=q(R),I=q(W);return e.Hole=H,e.html=G,e.render=(e,t)=>{const n="function"==typeof t?t():t;return Promise.resolve(n).then((t=>((e,t)=>{const n="function"==typeof t?t():t,r=z.get(e)||z.set(e,{stack:[],entry:null,wire:null}),s=n instanceof H?P(r,n):n;return s!==r.wire&&(r.wire=s,e.replaceChildren(s.valueOf())),e})(e,t)))},e.svg=I,e}({});