UNPKG

preact

Version:

Fast 3kb React-compatible Virtual DOM library.

3 lines (2 loc) 9.32 kB
!function(n,l){"object"==typeof exports&&"undefined"!=typeof module?l(exports):"function"==typeof define&&define.amd?define(["exports"],l):l(n.preact={})}(this,function(n){var l,u,t,i,o,r,f,e={},c=[],s=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i;function a(n,l){for(var u in l)n[u]=l[u];return n}function h(n){var l=n.parentNode;l&&l.removeChild(n)}function v(n,l,u){var t,i,o,r,f=arguments;if(l=a({},l),arguments.length>3)for(u=[u],t=3;t<arguments.length;t++)u.push(f[t]);if(null!=u&&(l.children=u),null!=n&&null!=n.defaultProps)for(i in n.defaultProps)void 0===l[i]&&(l[i]=n.defaultProps[i]);return r=l.key,null!=(o=l.ref)&&delete l.ref,null!=r&&delete l.key,p(n,l,r,o)}function p(n,u,t,i){var o={type:n,props:u,key:t,ref:i,__k:null,__p:null,__b:0,__e:null,l:null,__c:null,constructor:void 0};return l.vnode&&l.vnode(o),o}function d(n){return n.children}function y(n){if(null==n||"boolean"==typeof n)return null;if("string"==typeof n||"number"==typeof n)return p(null,n,null,null);if(null!=n.__e||null!=n.__c){var l=p(n.type,n.props,n.key,null);return l.__e=n.__e,l}return n}function m(n,l){this.props=n,this.context=l}function w(n,l){if(null==l)return n.__p?w(n.__p,n.__p.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return"function"==typeof n.type?w(n):null}function g(n){var l,u;if(null!=(n=n.__p)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return g(n)}}function k(n){(!n.__d&&(n.__d=!0)&&1===t.push(n)||o!==l.debounceRendering)&&(o=l.debounceRendering,(l.debounceRendering||i)(b))}function b(){var n,l,u,i,o,r,f,e;for(t.sort(function(n,l){return l.__v.__b-n.__v.__b});n=t.pop();)n.__d&&(u=void 0,i=void 0,r=(o=(l=n).__v).__e,f=l.__P,e=l.u,l.u=!1,f&&(u=[],i=T(f,o,a({},o),l.__n,void 0!==f.ownerSVGElement,null,u,e,null==r?w(o):r),$(u,o),i!=r&&g(o)))}function _(n,l,u,t,i,o,r,f,s){var a,v,p,d,y,m,g,k=u&&u.__k||c,b=k.length;if(f==e&&(f=null!=o?o[0]:b?w(u,0):null),a=0,l.__k=x(l.__k,function(u){if(null!=u){if(u.__p=l,u.__b=l.__b+1,null===(p=k[a])||p&&u.key==p.key&&u.type===p.type)k[a]=void 0;else for(v=0;v<b;v++){if((p=k[v])&&u.key==p.key&&u.type===p.type){k[v]=void 0;break}p=null}if(d=T(n,u,p=p||e,t,i,o,r,null,f,s),(v=u.ref)&&p.ref!=v&&(g||(g=[])).push(v,u.__c||d,u),null!=d){if(null==m&&(m=d),null!=u.l)d=u.l,u.l=null;else if(o==p||d!=f||null==d.parentNode){n:if(null==f||f.parentNode!==n)n.appendChild(d);else{for(y=f,v=0;(y=y.nextSibling)&&v<b;v+=2)if(y==d)break n;n.insertBefore(d,f)}"option"==l.type&&(n.value="")}f=d.nextSibling,"function"==typeof l.type&&(l.l=d)}}return a++,u}),l.__e=m,null!=o&&"function"!=typeof l.type)for(a=o.length;a--;)null!=o[a]&&h(o[a]);for(a=b;a--;)null!=k[a]&&D(k[a],k[a]);if(g)for(a=0;a<g.length;a++)A(g[a],g[++a],g[++a])}function x(n,l,u){if(null==u&&(u=[]),null==n||"boolean"==typeof n)l&&u.push(l(null));else if(Array.isArray(n))for(var t=0;t<n.length;t++)x(n[t],l,u);else u.push(l?l(y(n)):n);return u}function C(n,l,u,t,i){var o;for(o in u)o in l||N(n,o,null,u[o],t);for(o in l)i&&"function"!=typeof l[o]||"value"===o||"checked"===o||u[o]===l[o]||N(n,o,l[o],u[o],t)}function P(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]="number"==typeof u&&!1===s.test(l)?u+"px":null==u?"":u}function N(n,l,u,t,i){var o,r,f,e,c;if("key"===(l=i?"className"===l?"class":l:"class"===l?"className":l)||"children"===l);else if("style"===l)if(o=n.style,"string"==typeof u)o.cssText=u;else{if("string"==typeof t&&(o.cssText="",t=null),t)for(r in t)u&&r in u||P(o,r,"");if(u)for(f in u)t&&u[f]===t[f]||P(o,f,u[f])}else"o"===l[0]&&"n"===l[1]?(e=l!==(l=l.replace(/Capture$/,"")),c=l.toLowerCase(),l=(c in n?c:l).slice(2),u?(t||n.addEventListener(l,j,e),(n.t||(n.t={}))[l]=u):n.removeEventListener(l,j,e)):"list"!==l&&"tagName"!==l&&"form"!==l&&!i&&l in n?n[l]=null==u?"":u:"function"!=typeof u&&"dangerouslySetInnerHTML"!==l&&(l!==(l=l.replace(/^xlink:?/,""))?null==u||!1===u?n.removeAttributeNS("http://www.w3.org/1999/xlink",l.toLowerCase()):n.setAttributeNS("http://www.w3.org/1999/xlink",l.toLowerCase(),u):null==u||!1===u?n.removeAttribute(l):n.setAttribute(l,u))}function j(n){return this.t[n.type](l.event?l.event(n):n)}function T(n,u,t,i,o,r,f,e,c,s){var h,v,p,y,w,g,k,b,C,P,N=u.type;if(void 0!==u.constructor)return null;(h=l.__b)&&h(u);try{n:if("function"==typeof N){if(b=u.props,C=(h=N.contextType)&&i[h.__c],P=h?C?C.props.value:h.__p:i,t.__c?k=(v=u.__c=t.__c).__p=v.__E:("prototype"in N&&N.prototype.render?u.__c=v=new N(b,P):(u.__c=v=new m(b,P),v.constructor=N,v.render=H),C&&C.sub(v),v.props=b,v.state||(v.state={}),v.context=P,v.__n=i,p=v.__d=!0,v.__h=[]),null==v.__s&&(v.__s=v.state),null!=N.getDerivedStateFromProps&&a(v.__s==v.state?v.__s=a({},v.__s):v.__s,N.getDerivedStateFromProps(b,v.__s)),p)null==N.getDerivedStateFromProps&&null!=v.componentWillMount&&v.componentWillMount(),null!=v.componentDidMount&&f.push(v);else{if(null==N.getDerivedStateFromProps&&null==e&&null!=v.componentWillReceiveProps&&v.componentWillReceiveProps(b,P),!e&&null!=v.shouldComponentUpdate&&!1===v.shouldComponentUpdate(b,v.__s,P)){for(v.props=b,v.state=v.__s,v.__d=!1,v.__v=u,u.__e=null!=c?c!==t.__e?c:t.__e:null,u.__k=t.__k,h=0;h<u.__k.length;h++)u.__k[h]&&(u.__k[h].__p=u);break n}null!=v.componentWillUpdate&&v.componentWillUpdate(b,v.__s,P)}for(y=v.props,w=v.state,v.context=P,v.props=b,v.state=v.__s,(h=l.__r)&&h(u),v.__d=!1,v.__v=u,v.__P=n,h=v.render(v.props,v.state,v.context),u.__k=x(null!=h&&h.type==d&&null==h.key?h.props.children:h),null!=v.getChildContext&&(i=a(a({},i),v.getChildContext())),p||null==v.getSnapshotBeforeUpdate||(g=v.getSnapshotBeforeUpdate(y,w)),_(n,u,t,i,o,r,f,c,s),v.base=u.__e;h=v.__h.pop();)v.__s&&(v.state=v.__s),h.call(v);p||null==y||null==v.componentDidUpdate||v.componentDidUpdate(y,w,g),k&&(v.__E=v.__p=null)}else u.__e=z(t.__e,u,t,i,o,r,f,s);(h=l.diffed)&&h(u)}catch(n){l.__e(n,u,t)}return u.__e}function $(n,u){for(var t;t=n.pop();)try{t.componentDidMount()}catch(n){l.__e(n,t.__v)}l.__c&&l.__c(u)}function z(n,l,u,t,i,o,r,f){var s,a,h,v,p=u.props,d=l.props;if(i="svg"===l.type||i,null==n&&null!=o)for(s=0;s<o.length;s++)if(null!=(a=o[s])&&(null===l.type?3===a.nodeType:a.localName===l.type)){n=a,o[s]=null;break}if(null==n){if(null===l.type)return document.createTextNode(d);n=i?document.createElementNS("http://www.w3.org/2000/svg",l.type):document.createElement(l.type),o=null}return null===l.type?p!==d&&(null!=o&&(o[o.indexOf(n)]=null),n.data=d):l!==u&&(null!=o&&(o=c.slice.call(n.childNodes)),h=(p=u.props||e).dangerouslySetInnerHTML,v=d.dangerouslySetInnerHTML,f||(v||h)&&(v&&h&&v.__html==h.__html||(n.innerHTML=v&&v.__html||"")),C(n,d,p,i,f),l.__k=l.props.children,v||_(n,l,u,t,"foreignObject"!==l.type&&i,o,r,e,f),f||("value"in d&&void 0!==d.value&&d.value!==n.value&&(n.value=null==d.value?"":d.value),"checked"in d&&void 0!==d.checked&&d.checked!==n.checked&&(n.checked=d.checked))),n}function A(n,u,t){try{"function"==typeof n?n(u):n.current=u}catch(n){l.__e(n,t)}}function D(n,u,t){var i,o,r;if(l.unmount&&l.unmount(n),(i=n.ref)&&A(i,null,u),t||"function"==typeof n.type||(t=null!=(o=n.__e)),n.__e=n.l=null,null!=(i=n.__c)){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(n){l.__e(n,u)}i.base=i.__P=null}if(i=n.__k)for(r=0;r<i.length;r++)i[r]&&D(i[r],u,t);null!=o&&h(o)}function H(n,l,u){return this.constructor(n,u)}function I(n,u,t){var i,o,f;l.__p&&l.__p(n,u),o=(i=t===r)?null:t&&t.__k||u.__k,n=v(d,null,[n]),f=[],T(u,i?u.__k=n:(t||u).__k=n,o||e,e,void 0!==u.ownerSVGElement,t&&!i?[t]:o?null:c.slice.call(u.childNodes),f,!1,t||e,i),$(f,n)}l={},u=function(n){return null!=n&&void 0===n.constructor},m.prototype.setState=function(n,l){var u=this.__s!==this.state&&this.__s||(this.__s=a({},this.state));("function"!=typeof n||(n=n(u,this.props)))&&a(u,n),null!=n&&this.__v&&(this.u=!1,l&&this.__h.push(l),k(this))},m.prototype.forceUpdate=function(n){this.__v&&(n&&this.__h.push(n),this.u=!0,k(this))},m.prototype.render=d,t=[],i="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,o=l.debounceRendering,l.__e=function(n,l,u){for(var t;l=l.__p;)if((t=l.__c)&&!t.__p)try{if(t.constructor&&null!=t.constructor.getDerivedStateFromError)t.setState(t.constructor.getDerivedStateFromError(n));else{if(null==t.componentDidCatch)continue;t.componentDidCatch(n)}return k(t.__E=t)}catch(l){n=l}throw n},r=e,f=0,n.render=I,n.hydrate=function(n,l){I(n,l,r)},n.createElement=v,n.h=v,n.Fragment=d,n.createRef=function(){return{}},n.isValidElement=u,n.Component=m,n.cloneElement=function(n,l){return l=a(a({},n.props),l),arguments.length>2&&(l.children=c.slice.call(arguments,2)),p(n.type,l,l.key||n.key,l.ref||n.ref)},n.createContext=function(n){var l={},u={__c:"__cC"+f++,__p:n,Consumer:function(n,l){return n.children(l)},Provider:function(n){var t,i=this;return this.getChildContext||(t=[],this.getChildContext=function(){return l[u.__c]=i,l},this.shouldComponentUpdate=function(i){n.value!==i.value&&(l[u.__c].props.value=i.value,t.some(function(n){n.__P&&(n.context=i.value,k(n))}))},this.sub=function(n){t.push(n);var l=n.componentWillUnmount;n.componentWillUnmount=function(){t.splice(t.indexOf(n),1),l&&l.call(n)}}),n.children}};return u.Consumer.contextType=u,u},n.toChildArray=x,n._e=D,n.options=l}); //# sourceMappingURL=preact.umd.js.map