forked from WebReflection/hyperHTML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
umd.js
3 lines (3 loc) · 16 KB
/
umd.js
1
2
3
(function(A,G){if(typeof define=='function'&&define.amd)define([],G);else if(typeof module=='object'&&module.exports)module.exports=G();else A.hyperHTML=G()}(typeof self!='undefined'?self:this,function(){
/*! (c) Andrea Giammarchi (ISC) */var hyperHTML=function(j){"use strict";const W=[]["indexOf"],A=(e,t,n,r,a,i)=>{var o="selectedIndex"in t;let l=o;for(;r<a;){var s,c=e(n[r],1);t.insertBefore(c,i),o&&l&&c.selected&&(l=!l,s=t["selectedIndex"],t.selectedIndex=s<0?r:W.call(t.querySelectorAll("option"),c)),r++}},$=(e,t)=>e==t,F=e=>e,p=(n,r,a,i,o,l,s)=>{var e=l-o;if(!(e<1))for(;e<=a-r;){let e=r,t=o;for(;e<a&&t<l&&s(n[e],i[t]);)e++,t++;if(t===l)return r;r=e+1}return-1},R=(e,t,n,r,a,i)=>{for(;r<a&&i(n[r],e[t-1]);)r++,t--;return 0===t},v=(e,t,n,r,a)=>n<r?e(t[n],0):0<n?e(t[n-1],-0).nextSibling:a,O=(e,t,n,r)=>{for(;n<r;)((a=e(t[n++],-1)).remove||function(){var e=this["parentNode"];e&&e.removeChild(this)}).call(a);var a},I=(n,r,a,i,o,l,s,c,u,f,h,d,p)=>{{var v=((e,t,n,r,a,i,o)=>{var l=n+i,s=[];let c,u,f,h,d,p,v;e:for(c=0;c<=l;c++){if(50<c)return null;for(v=c-1,d=c?s[c-1]:[0,0],p=s[c]=[],u=-c;u<=c;u+=2){for(h=u===-c||u!==c&&d[v+u-1]<d[v+u+1]?d[v+u+1]:d[v+u-1]+1,f=h-u;h<i&&f<n&&o(r[a+h],e[t+f]);)h++,f++;if(h===i&&f===n)break e;p[c+u]=h}}var g=Array(c/2+l/2);let m=g.length-1;for(c=s.length-1;0<=c;c--){for(;0<h&&0<f&&o(r[a+h-1],e[t+f-1]);)g[m--]=0,h--,f--;if(!c)break;v=c-1,d=c?s[c-1]:[0,0],(u=h-f)===-c||u!==c&&d[v+u-1]<d[v+u+1]?(f--,g[m--]=1):(h--,g[m--]=-1)}return g})(a,i,l,s,c,f,d)||((t,n,r,e,a,i,o,l)=>{let s=0,c=e<l?e:l;var u=Array(c++),f=Array(c);f[0]=-1;for(let e=1;e<c;e++)f[e]=o;var h=a.slice(i,o);for(let e=n;e<r;e++){var d=h.indexOf(t[e]);-1<d&&(d=d+i,-1<(s=((e,t,n)=>{let r=1,a=t;while(r<a){const i=(r+a)/2>>>0;if(n<e[i])a=i;else r=i+1}return r})(f,c,d)))&&(f[s]=d,u[s]={newi:e,oldi:d,prev:u[s-1]})}for(s=--c,--o;f[s]>o;)--s;c=l+e-s;var p=Array(c);let v=u[s];for(--r;v;){for(var{newi:g,oldi:m}=v;g<r;)p[--c]=1,--r;for(;m<o;)p[--c]=-1,--o;p[--c]=0,--r,--o,v=v.prev}for(;n<=r;)p[--c]=1,--r;for(;i<=o;)p[--c]=-1,--o;return p})(a,i,o,l,s,c,u,f),g=n,m=r,y=a,b=i,w=s,N=c,x=h,E=p,k=[],C=v.length;let e=N,t=0;for(;t<C;)switch(v[t++]){case 0:b++,e++;break;case 1:k.push(y[b]),A(g,m,y,b++,b,e<x?g(w[e],0):E);break;case-1:e++}for(t=0;t<C;)switch(v[t++]){case 0:N++;break;case-1:-1<k.indexOf(w[N])?N++:O(g,w,N++,N)}}};const c=(t,n,r,a)=>{var i=(a=a||{}).compare||$,o=a.node||F,a=null==a.before?null:o(a.before,0),l=n.length;let s=l,c=0,u=r.length,f=0;for(;c<s&&f<u&&i(n[c],r[f]);)c++,f++;for(;c<s&&f<u&&i(n[s-1],r[u-1]);)s--,u--;var h=c===s,d=f===u;if(!h||!d)if(h&&f<u)A(o,t,r,f,u,v(o,n,c,l,a));else if(d&&c<s)O(o,n,c,s);else{h=s-c,d=u-f;let e=-1;if(h<d){if(-1<(e=p(r,f,u,n,c,s,i)))return A(o,t,r,f,e,o(n[c],0)),A(o,t,r,e+h,u,v(o,n,s,l,a)),r}else if(d<h&&-1<(e=p(n,c,s,r,f,u,i)))return O(o,n,c,e),O(o,n,e+d,s),r;h<2||d<2?(A(o,t,r,f,u,o(n[c],0)),O(o,n,c,s)):h==d&&R(r,u,n,c,s,i)?A(o,t,r,f,u,v(o,n,s,l,a)):I(o,t,r,f,u,d,n,c,s,h,l,i,a)}return r};class e{}const t=(e,t)=>{const n="_"+e+"$";return{get(){return this[n]||z(this,n,t.call(this,e))},set(e){z(this,n,e)}}},z=(e,t,n)=>Object.defineProperty(e,t,{configurable:!0,value:"function"==typeof n?function(){return e._wire$=n.apply(this,arguments)}:n})[t],H=(Object.defineProperties(e.prototype,{ELEMENT_NODE:{value:1},nodeType:{value:-1}}),{}),a={},V=[],Z=a.hasOwnProperty;let G=0;var f={attributes:H,define:(e,t)=>{e.indexOf("-")<0?(e in a||(G=V.push(e)),a[e]=t):H[e]=t},invoke:(t,n)=>{for(let e=0;e<G;e++){var r=V[e];if(Z.call(t,r))return a[r](t[r],n)}}};var B,n,q,r={};try{r.WeakMap=WeakMap}catch(e){r.WeakMap=(B=Math.random(),i=Object,n=i.defineProperty,q=i.hasOwnProperty,(i=J.prototype).delete=function(e){return this.has(e)&&delete e[this._]},i.get=function(e){return this.has(e)?e[this._]:void 0},i.has=function(e){return q.call(e,this._)},i.set=function(e,t){return n(e,this._,{configurable:!0,value:t}),this},J)}function J(e){n(this,"_",{value:"_@ungap/weakmap"+B++}),e&&e.forEach(K,this)}function K(e){this.set(e[0],e[1])}var l,s,i,Q=r.WeakMap,U=(l="appendChild",s="cloneNode",i="createTextNode",u=(r="importNode")in(h=j),(o=h.createDocumentFragment())[l](h[i]("g")),o[l](h[i]("")),(u?h[r](o,!0):o[s](!0)).childNodes.length<2?function e(t,n){for(var r=t[s](),a=t.childNodes||[],i=a.length,o=0;n&&o<i;o++)r[l](e(a[o],n));return r}:u?h[r]:function(e,t){return e[s](!!t)}),X="".trim||function(){return String(this).replace(/^\s+|\s+/g,"")},M="-"+Math.random().toFixed(6)+"%",_=!1;try{d=j.createElement("template"),y="tabindex",(m="content")in d&&(d.innerHTML="<p "+y+'="'+M+'"></p>',d[m].childNodes[0].getAttribute(y)==M)||(M="_dt: "+M.slice(1,-1)+";",_=!0)}catch(e){}var L="\x3c!--"+M+"--\x3e",Y=/^(?:plaintext|script|style|textarea|title|xmp)$/i,ee=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;function te(e){return e.join(L).replace(re,le).replace(ne,ie)}var o=" \\f\\n\\r\\t",u="[^"+o+"\\/>\"'=]+",h="["+o+"]+"+u,r="<([A-Za-z]+[A-Za-z0-9:._-]*)((?:",d="(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|<[^>]*?>|"+u.replace("\\/","")+"))?)",ne=new RegExp(r+h+d+"+)(["+o+"]*/?>)","g"),re=new RegExp(r+h+d+"*)(["+o+"]*/>)","g"),ae=new RegExp("("+h+"\\s*=\\s*)(['\"]?)"+L+"\\2","gi");function ie(e,t,n,r){return"<"+t+n.replace(ae,oe)+r}function oe(e,t,n){return t+(n||'"')+M+(n||'"')}function le(e,t,n){return ee.test(t)?e:"<"+t+n+"></"+t+">"}var se=_?function(e,t){var n=t.join(" ");return t.slice.call(e,0).sort(function(e,t){return n.indexOf(e.name)<=n.indexOf(t.name)?-1:1})}:function(e,t){return t.slice.call(e,0)};function ce(e,t,n,r){for(var a=e.childNodes,i=a.length,o=0;o<i;){var l=a[o];switch(l.nodeType){case 1:for(var s,c=r.concat(o),u=(T=O=A=C=k=E=x=s=N=w=b=y=m=g=v=p=d=h=f=u=void 0,l),f=t,h=n,d=c,p=u.attributes,v=[],g=[],m=se(p,h),y=m.length,b=0;b<y;){var w=m[b++],N=w.value===M;if(N||1<(s=w.value.split(L)).length){var x=w.name;if(v.indexOf(x)<0){v.push(x);var x=h.shift().replace(N?/^(?:|[\S\s]*?\s)(\S+?)\s*=\s*('|")?$/:new RegExp("^(?:|[\\S\\s]*?\\s)("+x+")\\s*=\\s*('|\")[\\S\\s]*","i"),"$1"),E=p[x]||p[x.toLowerCase()];if(N)f.push(ue(E,d,x,null));else{for(var k=s.length-2;k--;)h.shift();f.push(ue(E,d,x,s))}}g.push(w)}}for(var C=((b=0)<(y=g.length)&&_&&!("ownerSVGElement"in u));b<y;){var A=g[b++];C&&(A.value=""),u.removeAttribute(A.name)}var O=u.nodeName;if(/^script$/i.test(O)){var T=j.createElement(O);for(y=p.length,b=0;b<y;)T.setAttributeNode(p[b++].cloneNode(!0));T.textContent=u.textContent,u.parentNode.replaceChild(T,u)}ce(l,t,n,c);break;case 8:var S=l.textContent;if(S===M)n.shift(),t.push(Y.test(e.nodeName)?fe(e,r):{type:"any",node:l,path:r.concat(o)});else switch(S.slice(0,2)){case"/*":if("*/"!==S.slice(-2))break;case"👻":e.removeChild(l),o--,i--}break;case 3:Y.test(e.nodeName)&&X.call(l.textContent)===L&&(n.shift(),t.push(fe(e,r)))}o++}}function ue(e,t,n,r){return{type:"attr",node:e,path:t,name:n,sparse:r}}function fe(e,t){return{type:"text",node:e,path:t}}g=new Q;var g,he={get:e=>g.get(e),set:(e,t)=>(g.set(e,t),t)};function de(o,f){var e=(o.convert||te)(f),t=o.transform,t=(t&&(e=t(e)),Le(e,o.type)),l=(ge(t),[]);return ce(t,l,f.slice(0),[]),{content:t,updates:function(s){for(var c=[],u=l.length,e=0,t=0;e<u;){var n=l[e++],r=function(e,t){for(var n=t.length,r=0;r<n;)e=e.childNodes[t[r++]];return e}(s,n.path);switch(n.type){case"any":c.push({fn:o.any(r,[]),sparse:!1});break;case"attr":var a=n.sparse,i=o.attribute(r,n.name,n.node);null===a?c.push({fn:i,sparse:!1}):(t+=a.length-2,c.push({fn:i,sparse:!0,values:a}));break;case"text":c.push({fn:o.text(r),sparse:!1}),r.textContent=""}}return u+=t,function(){var e=arguments.length;if(u!==e-1)throw new Error(e-1+" values instead of "+u+"\n"+f.join("${value}"));for(var t=1,n=1;t<e;){var r=c[t-n];if(r.sparse){var a=r.values,i=a[0],o=1,l=a.length;for(n+=l-2;o<l;)i+=arguments[t++]+a[o++];r.fn(i)}else r.fn(arguments[t++])}return s}}}}var pe=[];function ve(n){var r=pe,a=ge;return function(e){var t;return r!==e&&(t=n,e=r=e,a=(t=he.get(e)||he.set(e,de(t,e))).updates(U.call(j,t.content,!0))),a.apply(null,arguments)}}function ge(e){for(var t=e.childNodes,n=t.length;n--;){var r=t[n];1!==r.nodeType&&0===X.call(r.textContent).length&&e.removeChild(r)}}me=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,ye=/([^A-Z])([A-Z]+)/g;var me,ye,be=function(e,t){var n;return"ownerSVGElement"in e?(n=e,(t=(t=t)?t.cloneNode(!0):(n.setAttribute("style","--hyper:style;"),n.getAttributeNode("style"))).value="",n.setAttributeNode(t),Ne(t,!0)):Ne(e.style,!1)};function we(e,t,n){return t+"-"+n.toLowerCase()}function Ne(a,i){var o,l;return function(e){var t,n,r;switch(typeof e){case"object":if(e){if("object"===o){if(!i&&l!==e)for(n in l)n in e||(a[n]="")}else i?a.value="":a.cssText="";for(n in t=i?{}:a,e)r="number"!=typeof(r=e[n])||me.test(n)?r:r+"px",!i&&/^--/.test(n)?t.setProperty(n,r):t[n]=r;o="object",i?a.value=function(e){var t,n=[];for(t in e)n.push(t.replace(ye,we),":",e[t],";");return n.join("")}(l=t):l=e;break}default:l!=e&&(o="string",l=e,i?a.value=e||"":a.cssText=e||"")}}}xe=[].slice,(m=Ce.prototype).ELEMENT_NODE=1,m.nodeType=111,m.remove=function(e){var t,n=this.childNodes,r=this.firstChild,a=this.lastChild;return this._=null,e&&2===n.length?a.parentNode.removeChild(a):((t=this.ownerDocument.createRange()).setStartBefore(e?n[1]:r),t.setEndAfter(a),t.deleteContents()),r},m.valueOf=function(e){var t=this._,n=null==t;if(n&&(t=this._=this.ownerDocument.createDocumentFragment()),n||e)for(var r=this.childNodes,a=0,i=r.length;a<i;a++)t.appendChild(r[a]);return t};var xe,m,y,Ee,b,w,N,ke=Ce;function Ce(e){e=this.childNodes=xe.call(e,0);this.firstChild=e[0],this.lastChild=e[e.length-1],this.ownerDocument=e[0].ownerDocument,this._=null}const x="ownerSVGElement",Ae="connected",Oe=(Ae,Array["isArray"]),{createDocumentFragment:Te,createElement:Se,createElementNS:je}=new Proxy({},{get:(e,t)=>j[t].bind(j)}),Me=e=>{var t=Se("template");return t.innerHTML=e,t.content};let E;const _e=e=>{(E=E||je("http://www.w3.org/2000/svg","svg")).innerHTML=e;e=Te();return e.append(...E.childNodes),e},Le=(e,t)=>("svg"==t?_e:Me)(e),De=e.prototype.nodeType,Pe=ke.prototype.nodeType,We=(y={Event:CustomEvent,WeakSet:WeakSet},Ee=y.Event,b=y.WeakSet,w=!0,N=null,function(e){if(w){w=!w,N=new b;var t=e.ownerDocument,a=new b,i=new b;try{new MutationObserver(l).observe(t,{subtree:!0,childList:!0})}catch(e){var n=0,r=[],o=function(e){r.push(e),clearTimeout(n),n=setTimeout(function(){l(r.splice(n=0,r.length))},0)};t.addEventListener("DOMNodeRemoved",function(e){o({addedNodes:[],removedNodes:[e.target]})},!0),t.addEventListener("DOMNodeInserted",function(e){o({addedNodes:[e.target],removedNodes:[]})},!0)}function l(e){for(var t,n=e.length,r=0;r<n;r++)s((t=e[r]).removedNodes,"disconnected",i,a),s(t.addedNodes,"connected",a,i)}function s(e,t,n,r){for(var a,i=new Ee(t),o=e.length,l=0;l<o;1===(a=e[l++]).nodeType&&function e(t,n,r,a,i){N.has(t)&&!a.has(t)&&(i.delete(t),a.add(t),t.dispatchEvent(n));for(var o=t.children||[],l=o.length,s=0;s<l;e(o[s++],n,r,a,i));}(a,i,t,n,r));}}return N.add(e),e}),$e=e=>({html:e}),Fe=(e,t)=>{switch(e.nodeType){case Pe:return 1/t<0?t?e.remove(!0):e.lastChild:t?e.valueOf(!0):e.firstChild;case De:return Fe(e.render(),t);default:return e}},Re=(e,t)=>{t(e.placeholder),("text"in e?Promise.resolve(e.text).then(String):"any"in e?Promise.resolve(e.any):"html"in e?Promise.resolve(e.html).then($e):Promise.resolve(f.invoke(e,t))).then(t)},k=e=>null!=e&&"then"in e,Ie=/^(?:form|list)$/i,C=[].slice;function T(e){return this.type=e,ve(this)}var ze=!(T.prototype={attribute(n,r,e){var t,a,i,o,l,s=x in n;let c;if("style"===r)return be(n,e,s);if("."===r.slice(0,1))return o=n,l=r.slice(1),s?t=>{try{o[l]=t}catch(e){o.setAttribute(l,t)}}:e=>{o[l]=e};if("?"===r.slice(0,1))return t=n,a=r.slice(1),e=>{i!==!!e&&((i=!!e)?t.setAttribute(a,""):t.removeAttribute(a))};if(/^on/.test(r)){let t=r.slice(2);return t===Ae||"disconnected"===t?We(n):r.toLowerCase()in n&&(t=t.toLowerCase()),e=>{c!==e&&(c&&n.removeEventListener(t,c,!1),c=e)&&n.addEventListener(t,e,!1)}}if("data"===r||!s&&r in n&&!Ie.test(r))return e=>{c!==e&&(c=e,n[r]!==e&&null==e?(n[r]="",n.removeAttribute(r)):n[r]=e)};if(r in f.attributes)return e=>{e=f.attributes[r](n,e);c!==e&&(null==(c=e)?n.removeAttribute(r):n.setAttribute(r,e))};{let t=!1;const u=e.cloneNode(!0);return e=>{c!==e&&(c=e,u.value!==e)&&(null==e?(t&&(t=!1,n.removeAttributeNode(u)),u.value=e):(u.value=e,t||(t=!0,n.setAttributeNode(u))))}}},any(n,r){const a={node:Fe,before:n},i=x in n?"svg":"html";let o=!1,l;const s=e=>{switch(typeof e){case"string":case"number":case"boolean":o?l!==e&&(l=e,r[0].textContent=e):(o=!0,l=e,r=c(n.parentNode,r,[(t=e,n.ownerDocument.createTextNode(t))],a));break;case"function":s(e(n));break;case"object":case"undefined":if(null==e){o=!1,r=c(n.parentNode,r,[],a);break}default:if(o=!1,l=e,Oe(e))if(0===e.length)r.length&&(r=c(n.parentNode,r,[],a));else switch(typeof e[0]){case"string":case"number":case"boolean":s({html:e});break;case"object":if(Oe(e[0])&&(e=e.concat.apply([],e)),k(e[0])){Promise.all(e).then(s);break}default:r=c(n.parentNode,r,e,a)}else"ELEMENT_NODE"in e?r=c(n.parentNode,r,11===e.nodeType?C.call(e.childNodes):[e],a):k(e)?e.then(s):"placeholder"in e?Re(e,s):"text"in e?s(String(e.text)):"any"in e?s(e.any):"html"in e?r=c(n.parentNode,r,C.call(Le([].concat(e.html).join(""),i).childNodes),a):"length"in e?s(C.call(e)):s(f.invoke(e,s))}var t};return s},text(n){let r;const a=e=>{var t;r!==e&&("object"==(t=typeof(r=e))&&e?k(e)?e.then(a):"placeholder"in e?Re(e,a):"text"in e?a(String(e.text)):"any"in e?a(e.any):"html"in e?a([].concat(e.html).join("")):"length"in e?a(C.call(e).join("")):a(f.invoke(e,a)):"function"==t?a(e(n)):n.textContent=null==e?"":e)};return a}}),He=function(e){i=(j.defaultView.navigator||{}).userAgent;var r,t,n,a,i=/(Firefox|Safari)\/(\d+)/.test(i)&&!/(Chrom[eium]+|Android)\/(\d+)/.test(i),o=!("raw"in e)||e.propertyIsEnumerable("raw")||!Object.isFrozen(e.raw);return i||o?(r={},t=function(e){for(var t=".",n=0;n<e.length;n++)t+=e[n].length+"."+e[n];return r[t]||(r[t]=e)},He=o?t:(n=new Q,a=function(e,t){return n.set(e,t),t},function(e){return n.get(e)||a(e,t(e))})):ze=!0,Ve(e)};function Ve(e){return ze?e:He(e)}function Ze(e){for(var t=arguments.length,n=[Ve(e)],r=1;r<t;)n.push(arguments[r++]);return n}const Ge=new WeakMap;const S=t=>{let n,r,a;return function(){var e=Ze.apply(null,arguments);return a!==e[0]?(a=e[0],r=new T(t),n=qe(r.apply(r,e))):r.apply(r,e),n}},Be=(e,t)=>{var n=t.indexOf(":");let r=Ge.get(e),a=t;return-1<n&&(a=t.slice(n+1),t=t.slice(0,n)||"html"),r||Ge.set(e,r={}),r[a]||(r[a]=S(t))},qe=e=>{var t=e.childNodes,n=t["length"];return 1===n?t[0]:n?new ke(t):e},Je=new WeakMap;function Ke(){var e=Je.get(this),t=Ze.apply(null,arguments);return e&&e.template===t[0]?e.tagger.apply(null,t):function(e){var t=x in this?"svg":"html",t=new T(t);Je.set(this,{tagger:t,template:e}),this.textContent="",this.appendChild(t.apply(null,arguments))}.apply(this,t),this}u=f.define,r=T.prototype;D.Component=e,D.bind=e=>Ke.bind(e),D.define=u,D.diff=c,(D.hyper=D).observe=We,D.tagger=r,D.wire=(e,t)=>null==e?S(t||"html"):Be(e,t||"html");{o=S;const P=new WeakMap,Qe=Object.create;Object.defineProperties(e,{for:{configurable:!0,value(e,t){var n,r,a,i=this,o=P.get(e)||(o=e,a=new Map,P.set(o,a),a),l=e,s=null==t?"default":t,c=o.get(i)||((e,t)=>{const n={w:null,p:null};return t.set(e,n),n})(i,o);switch(typeof s){case"object":case"function":var u=c.w||(c.w=new WeakMap);return u.get(s)||(u=u,n=s,r=new i(l),u.set(n,r),r);default:u=c.p||(c.p=Qe(null));return u[s]||(u[s]=new i(l))}}}}),Object.defineProperties(e.prototype,{handleEvent:{value(e){var t=e.currentTarget;this["getAttribute"in t&&t.getAttribute("data-call")||"on"+e.type](e)}},html:t("html",o),svg:t("svg",o),state:t("state",function(){return this.defaultState}),defaultState:{get(){return{}}},dispatch:{value(e,t){var n=this["_wire$"];return!!n&&((e=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:t})).component=this,(n.dispatchEvent?n:n.firstChild).dispatchEvent(e))}},setState:{value(e,t){var n=this.state,r="function"==typeof e?e.call(this,n):e;for(const a in r)n[a]=r[a];return!1!==t&&this.render(),this}}})}function D(e){return arguments.length<2?null==e?S("html"):"string"==typeof e?D.wire(null,e):"raw"in e?S("html")(e):"nodeType"in e?D.bind(e):Be(e,"html"):("raw"in e?S("html"):D.wire).apply(null,arguments)}return D}(document);
return hyperHTML}));