superfinesse
Version:
modified version of superfine
3 lines (2 loc) • 3.71 kB
JavaScript
const e={},n=[],l=n.map,r=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i,t=Array.isArray,o=document,i=function(e){return this.__ev[e.type](e)},s=(e,n,l)=>{"-"===n[0]?e.setProperty(n,l):e[n]="number"==typeof l&&!1===r.test(n)?l+"px":null==l?"":l},d=(e,n,l,r,t,o,d)=>{if(t?"className"===n&&(n="class"):"class"===n&&(n="className"),"key"===n||"children"===n);else if("style"===n)if(o=e.style,"string"==typeof l)o.cssText=l;else{if("string"==typeof r&&(o.cssText="",r=null),r)for(let e in r)l&&e in l||s(o,e,"");if(l)for(let e in l)r&&l[e]===r[e]||s(o,e,l[e])}else if("o"===n[0]&&"n"===n[1]){let t=n!==(n=n.replace(/Capture$/,"")),o=n.toLowerCase();n=(o in e?o:n).slice(2),l?(r||e.addEventListener(n,i,t),(e.__ev||(e.__ev={}))[n]=l):e.removeEventListener(n,i,t)}else if("dangerouslySetInnerHTML"===n){if((l||r)&&(l&&r&&l.__html==r.__html||(e.innerHTML=l&&l.__html||""),l))return!0}else["list","tagName","form","type","size"].includes(n)||t||!(n in e)?"function"!=typeof l&&(n!==(n=n.replace(/^xlink:?/,""))?null==l||!1===l?e.removeAttributeNS("http://www.w3.org/1999/xlink",n.toLowerCase()):e.setAttributeNS("http://www.w3.org/1999/xlink",n.toLowerCase(),l):null==l||!1===l&&!/^ar/.test(n)?e.removeAttribute(n):e.setAttribute(n,l)):e[n]=null==l?"":l},u=(e,n,l,r,t)=>{let o;for(o in l)o in n||d(e,o,null,l[o],r)&&(t=!0);for(o in n)"value"!==o&&"checked"!==o&&l[o]!==n[o]&&d(e,o,n[o],l[o],r)&&(t=!0);return t},a=e=>null==e?null:e.key,f=(e,n,l,r,t)=>{if(l===r);else if(null!=l&&3===l.type&&3===r.type)l.name!==r.name&&(n.nodeValue=r.name);else if(null==l||l.name!==r.name)n=e.insertBefore(p(r,t),n),null!=l&&e.removeChild(l.node);else{let e,d,h,c,m=l.children,v=r.children,y=0,g=0,w=m.length-1,C=v.length-1;if(u(n,r.props,l.props,t=t||"svg"===r.name))return r.node=n;for(;g<=C&&y<=w&&null!=(h=a(m[y]))&&h===a(v[g]);)f(n,m[y].node,m[y++],v[g++],t);for(;g<=C&&y<=w&&null!=(h=a(m[w]))&&h===a(v[C]);)f(n,m[w].node,m[w--],v[C--],t);if(y>w)for(;g<=C;)n.insertBefore(p(v[g++],t),(d=m[y])&&d.node);else if(g>C)for(;y<=w;)n.removeChild(m[y++].node);else{for(var o=y,i={},s={};o<=w;o++)null!=(h=m[o].key)&&(i[h]=m[o]);for(;g<=C;)h=a(d=m[y]),c=a(v[g]),s[h]||null!=c&&c===a(m[y+1])?(null==h&&n.removeChild(d.node),y++):null==c||1===l.type?(null==h&&(f(n,d&&d.node,d,v[g],t),g++),y++):(h===c?(f(n,d.node,d,v[g],t),s[c]=!0,y++):null!=(e=i[c])?(f(n,n.insertBefore(e.node,d&&d.node),e,v[g],t),s[c]=!0):f(n,d&&d.node,null,v[g],t),g++);for(;y<=w;)null==a(d=m[y++])&&n.removeChild(d.node);for(var o in i)null==s[o]&&n.removeChild(i[o].node)}}return r.node=n},p=(e,n)=>{var l=3===e.type?o.createTextNode(e.name):(n=n||"svg"===e.name)?o.createElementNS("http://www.w3.org/2000/svg",e.name):o.createElement(e.name);u(l,e.props,{},n);for(var r=0,t=e.children.length;r<t;r++)l.appendChild(p(e.children[r],n));return e.node=l},h=(e,n,l,r,t,o)=>({name:e,props:n,children:l,node:r,type:o,key:t}),c=(l,r)=>h(l,e,n,r,null,3),m=(n,r)=>3===n.nodeType?c(n.nodeValue,n):h(n.nodeName.toLowerCase(),e,l.call(n.childNodes,m),n,null,1),v=e=>e.children,y=(n,l,r)=>{let t=l.vdom||m(l);return n=h(t.name,e,[].concat(n),t.node),(l=f(l.parentNode,l,t,n)).vdom=n,l},g=(e,n)=>{t(e)||(e=[e]);for(var l=e.length;l--;)n.insertBefore(p(e[l]),n.firstChild)},w=function(e,n){for(var l,r=[],o=[],i=arguments.length;i-- >2;)r.push(arguments[i]);for(null!=(n=null==n?{}:n).children&&(r.length<=0&&r.push(n.children),delete n.children);r.length>0;)if(t(l=r.pop()))for(i=l.length;i-- >0;)r.push(l[i]);else!1===l||!0===l||null==l||o.push("object"==typeof l?l:c(l));return"function"==typeof e?(n.children=n.children||o)&&e(n):h(e,n,o,null,n.key)};export{v as Fragment,p as createNode,w as h,g as mount,y as render};
//# sourceMappingURL=index.js.map