UNPKG

preact

Version:

Fast 3kb React-compatible Virtual DOM library.

3 lines (2 loc) 11.6 kB
var n,l,t,u,r,i,o,e,f,c,s,p,a,h={},y=[],v=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,w=Array.isArray;function d(n,l){for(var t in l)n[t]=l[t];return n}function g(n){n&&n.parentNode&&n.parentNode.removeChild(n)}function _(l,t,u){var r,i,o,e={};for(o in t)"key"==o?r=t[o]:"ref"==o?i=t[o]:e[o]=t[o];if(arguments.length>2&&(e.children=arguments.length>3?n.call(arguments,2):u),"function"==typeof l&&null!=l.defaultProps)for(o in l.defaultProps)null==e[o]&&(e[o]=l.defaultProps[o]);return x(l,e,r,i,null)}function x(n,u,r,i,o){var e={type:n,props:u,key:r,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==o?++t:o,__i:-1,__u:0};return null==o&&null!=l.vnode&&l.vnode(e),e}function m(n){return n.children}function b(n,l){this.props=n,this.context=l}function k(n,l){if(null==l)return n.__?k(n.__,n.__i+1):null;for(var t;l<n.__k.length;l++)if(null!=(t=n.__k[l])&&null!=t.__e)return t.__e;return"function"==typeof n.type?k(n):null}function S(n){var l,t;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(t=n.__k[l])&&null!=t.__e){n.__e=n.__c.base=t.__e;break}return S(n)}}function M(n){(!n.__d&&(n.__d=!0)&&r.push(n)&&!$.__r++||i!=l.debounceRendering)&&((i=l.debounceRendering)||o)($)}function $(){for(var n,t,u,i,o,f,c,s=1;r.length;)r.length>s&&r.sort(e),n=r.shift(),s=r.length,n.__d&&(u=void 0,o=(i=(t=n).__v).__e,f=[],c=[],t.__P&&((u=d({},i)).__v=i.__v+1,l.vnode&&l.vnode(u),j(t.__P,u,i,t.__n,t.__P.namespaceURI,32&i.__u?[o]:null,f,null==o?k(i):o,!!(32&i.__u),c),u.__v=i.__v,u.__.__k[u.__i]=u,F(f,u,c),u.__e!=o&&S(u)));$.__r=0}function C(n,l,t,u,r,i,o,e,f,c,s){var p,a,v,w,d,g,_=u&&u.__k||y,x=l.length;for(f=I(t,l,_,f,x),p=0;p<x;p++)null!=(v=t.__k[p])&&(a=-1==v.__i?h:_[v.__i]||h,v.__i=p,g=j(n,v,a,r,i,o,e,f,c,s),w=v.__e,v.ref&&a.ref!=v.ref&&(a.ref&&N(a.ref,null,v),s.push(v.ref,v.__c||w,v)),null==d&&null!=w&&(d=w),4&v.__u||a.__k===v.__k?f=P(v,f,n):"function"==typeof v.type&&void 0!==g?f=g:w&&(f=w.nextSibling),v.__u&=-7);return t.__e=d,f}function I(n,l,t,u,r){var i,o,e,f,c,s=t.length,p=s,a=0;for(n.__k=new Array(r),i=0;i<r;i++)null!=(o=l[i])&&"boolean"!=typeof o&&"function"!=typeof o?(f=i+a,(o=n.__k[i]="string"==typeof o||"number"==typeof o||"bigint"==typeof o||o.constructor==String?x(null,o,null,null,null):w(o)?x(m,{children:o},null,null,null):null==o.constructor&&o.__b>0?x(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):o).__=n,o.__b=n.__b+1,e=null,-1!=(c=o.__i=A(o,t,f,p))&&(p--,(e=t[c])&&(e.__u|=2)),null==e||null==e.__v?(-1==c&&(r>s?a--:r<s&&a++),"function"!=typeof o.type&&(o.__u|=4)):c!=f&&(c==f-1?a--:c==f+1?a++:(c>f?a--:a++,o.__u|=4))):n.__k[i]=null;if(p)for(i=0;i<s;i++)null!=(e=t[i])&&0==(2&e.__u)&&(e.__e==u&&(u=k(e)),V(e,e));return u}function P(n,l,t){var u,r;if("function"==typeof n.type){for(u=n.__k,r=0;u&&r<u.length;r++)u[r]&&(u[r].__=n,l=P(u[r],l,t));return l}n.__e!=l&&(l&&n.type&&!t.contains(l)&&(l=k(n)),t.insertBefore(n.__e,l||null),l=n.__e);do{l=l&&l.nextSibling}while(null!=l&&8==l.nodeType);return l}function A(n,l,t,u){var r,i,o=n.key,e=n.type,f=l[t];if(null===f&&null==n.key||f&&o==f.key&&e==f.type&&0==(2&f.__u))return t;if(u>(null!=f&&0==(2&f.__u)?1:0))for(r=t-1,i=t+1;r>=0||i<l.length;){if(r>=0){if((f=l[r])&&0==(2&f.__u)&&o==f.key&&e==f.type)return r;r--}if(i<l.length){if((f=l[i])&&0==(2&f.__u)&&o==f.key&&e==f.type)return i;i++}}return-1}function H(n,l,t){"-"==l[0]?n.setProperty(l,null==t?"":t):n[l]=null==t?"":"number"!=typeof t||v.test(l)?t:t+"px"}function L(n,l,t,u,r){var i;n:if("style"==l)if("string"==typeof t)n.style.cssText=t;else{if("string"==typeof u&&(n.style.cssText=u=""),u)for(l in u)t&&l in t||H(n.style,l,"");if(t)for(l in t)u&&t[l]==u[l]||H(n.style,l,t[l])}else if("o"==l[0]&&"n"==l[1])i=l!=(l=l.replace(f,"$1")),l=l.toLowerCase()in n||"onFocusOut"==l||"onFocusIn"==l?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+i]=t,t?u?t.t=u.t:(t.t=c,n.addEventListener(l,i?p:s,i)):n.removeEventListener(l,i?p:s,i);else{if("http://www.w3.org/2000/svg"==r)l=l.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=l&&"height"!=l&&"href"!=l&&"list"!=l&&"form"!=l&&"tabIndex"!=l&&"download"!=l&&"rowSpan"!=l&&"colSpan"!=l&&"role"!=l&&"popover"!=l&&l in n)try{n[l]=null==t?"":t;break n}catch(n){}"function"==typeof t||(null==t||!1===t&&"-"!=l[4]?n.removeAttribute(l):n.setAttribute(l,"popover"==l&&1==t?"":t))}}function T(n){return function(t){if(this.l){var u=this.l[t.type+n];if(null==t.u)t.u=c++;else if(t.u<u.t)return;return u(l.event?l.event(t):t)}}}function j(n,t,u,r,i,o,e,f,c,s){var p,a,h,y,v,_,x,k,S,M,$,I,P,A,H,L,T,j=t.type;if(null!=t.constructor)return null;128&u.__u&&(c=!!(32&u.__u),o=[f=t.__e=u.__e]),(p=l.__b)&&p(t);n:if("function"==typeof j)try{if(k=t.props,S="prototype"in j&&j.prototype.render,M=(p=j.contextType)&&r[p.__c],$=p?M?M.props.value:p.__:r,u.__c?x=(a=t.__c=u.__c).__=a.__E:(S?t.__c=a=new j(k,$):(t.__c=a=new b(k,$),a.constructor=j,a.render=q),M&&M.sub(a),a.props=k,a.state||(a.state={}),a.context=$,a.__n=r,h=a.__d=!0,a.__h=[],a._sb=[]),S&&null==a.__s&&(a.__s=a.state),S&&null!=j.getDerivedStateFromProps&&(a.__s==a.state&&(a.__s=d({},a.__s)),d(a.__s,j.getDerivedStateFromProps(k,a.__s))),y=a.props,v=a.state,a.__v=t,h)S&&null==j.getDerivedStateFromProps&&null!=a.componentWillMount&&a.componentWillMount(),S&&null!=a.componentDidMount&&a.__h.push(a.componentDidMount);else{if(S&&null==j.getDerivedStateFromProps&&k!==y&&null!=a.componentWillReceiveProps&&a.componentWillReceiveProps(k,$),!a.__e&&null!=a.shouldComponentUpdate&&!1===a.shouldComponentUpdate(k,a.__s,$)||t.__v==u.__v){for(t.__v!=u.__v&&(a.props=k,a.state=a.__s,a.__d=!1),t.__e=u.__e,t.__k=u.__k,t.__k.some(function(n){n&&(n.__=t)}),I=0;I<a._sb.length;I++)a.__h.push(a._sb[I]);a._sb=[],a.__h.length&&e.push(a);break n}null!=a.componentWillUpdate&&a.componentWillUpdate(k,a.__s,$),S&&null!=a.componentDidUpdate&&a.__h.push(function(){a.componentDidUpdate(y,v,_)})}if(a.context=$,a.props=k,a.__P=n,a.__e=!1,P=l.__r,A=0,S){for(a.state=a.__s,a.__d=!1,P&&P(t),p=a.render(a.props,a.state,a.context),H=0;H<a._sb.length;H++)a.__h.push(a._sb[H]);a._sb=[]}else do{a.__d=!1,P&&P(t),p=a.render(a.props,a.state,a.context),a.state=a.__s}while(a.__d&&++A<25);a.state=a.__s,null!=a.getChildContext&&(r=d(d({},r),a.getChildContext())),S&&!h&&null!=a.getSnapshotBeforeUpdate&&(_=a.getSnapshotBeforeUpdate(y,v)),L=p,null!=p&&p.type===m&&null==p.key&&(L=O(p.props.children)),f=C(n,w(L)?L:[L],t,u,r,i,o,e,f,c,s),a.base=t.__e,t.__u&=-161,a.__h.length&&e.push(a),x&&(a.__E=a.__=null)}catch(n){if(t.__v=null,c||null!=o)if(n.then){for(t.__u|=c?160:128;f&&8==f.nodeType&&f.nextSibling;)f=f.nextSibling;o[o.indexOf(f)]=null,t.__e=f}else for(T=o.length;T--;)g(o[T]);else t.__e=u.__e,t.__k=u.__k;l.__e(n,t,u)}else null==o&&t.__v==u.__v?(t.__k=u.__k,t.__e=u.__e):f=t.__e=z(u.__e,t,u,r,i,o,e,c,s);return(p=l.diffed)&&p(t),128&t.__u?void 0:f}function F(n,t,u){for(var r=0;r<u.length;r++)N(u[r],u[++r],u[++r]);l.__c&&l.__c(t,n),n.some(function(t){try{n=t.__h,t.__h=[],n.some(function(n){n.call(t)})}catch(n){l.__e(n,t.__v)}})}function O(n){return"object"!=typeof n||null==n||n.__b&&n.__b>0?n:w(n)?n.map(O):d({},n)}function z(t,u,r,i,o,e,f,c,s){var p,a,y,v,d,_,x,m=r.props,b=u.props,S=u.type;if("svg"==S?o="http://www.w3.org/2000/svg":"math"==S?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),null!=e)for(p=0;p<e.length;p++)if((d=e[p])&&"setAttribute"in d==!!S&&(S?d.localName==S:3==d.nodeType)){t=d,e[p]=null;break}if(null==t){if(null==S)return document.createTextNode(b);t=document.createElementNS(o,S,b.is&&b),c&&(l.__m&&l.__m(u,e),c=!1),e=null}if(null==S)m===b||c&&t.data==b||(t.data=b);else{if(e=e&&n.call(t.childNodes),m=r.props||h,!c&&null!=e)for(m={},p=0;p<t.attributes.length;p++)m[(d=t.attributes[p]).name]=d.value;for(p in m)if(d=m[p],"children"==p);else if("dangerouslySetInnerHTML"==p)y=d;else if(!(p in b)){if("value"==p&&"defaultValue"in b||"checked"==p&&"defaultChecked"in b)continue;L(t,p,null,d,o)}for(p in b)d=b[p],"children"==p?v=d:"dangerouslySetInnerHTML"==p?a=d:"value"==p?_=d:"checked"==p?x=d:c&&"function"!=typeof d||m[p]===d||L(t,p,d,m[p],o);if(a)c||y&&(a.__html==y.__html||a.__html==t.innerHTML)||(t.innerHTML=a.__html),u.__k=[];else if(y&&(t.innerHTML=""),C("template"==u.type?t.content:t,w(v)?v:[v],u,r,i,"foreignObject"==S?"http://www.w3.org/1999/xhtml":o,e,f,e?e[0]:r.__k&&k(r,0),c,s),null!=e)for(p=e.length;p--;)g(e[p]);c||(p="value","progress"==S&&null==_?t.removeAttribute("value"):null!=_&&(_!==t[p]||"progress"==S&&!_||"option"==S&&_!=m[p])&&L(t,p,_,m[p],o),p="checked",null!=x&&x!=t[p]&&L(t,p,x,m[p],o))}return t}function N(n,t,u){try{if("function"==typeof n){var r="function"==typeof n.__u;r&&n.__u(),r&&null==t||(n.__u=n(t))}else n.current=t}catch(n){l.__e(n,u)}}function V(n,t,u){var r,i;if(l.unmount&&l.unmount(n),(r=n.ref)&&(r.current&&r.current!=n.__e||N(r,null,t)),null!=(r=n.__c)){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(n){l.__e(n,t)}r.base=r.__P=null}if(r=n.__k)for(i=0;i<r.length;i++)r[i]&&V(r[i],t,u||"function"!=typeof n.type);u||g(n.__e),n.__c=n.__=n.__e=void 0}function q(n,l,t){return this.constructor(n,t)}function B(t,u,r){var i,o,e,f;u==document&&(u=document.documentElement),l.__&&l.__(t,u),o=(i="function"==typeof r)?null:r&&r.__k||u.__k,e=[],f=[],j(u,t=(!i&&r||u).__k=_(m,null,[t]),o||h,h,u.namespaceURI,!i&&r?[r]:o?null:u.firstChild?n.call(u.childNodes):null,e,!i&&r?r:o?o.__e:u.firstChild,i,f),F(e,t,f)}n=y.slice,l={__e:function(n,l,t,u){for(var r,i,o;l=l.__;)if((r=l.__c)&&!r.__)try{if((i=r.constructor)&&null!=i.getDerivedStateFromError&&(r.setState(i.getDerivedStateFromError(n)),o=r.__d),null!=r.componentDidCatch&&(r.componentDidCatch(n,u||{}),o=r.__d),o)return r.__E=r}catch(l){n=l}throw n}},t=0,u=function(n){return null!=n&&null==n.constructor},b.prototype.setState=function(n,l){var t;t=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=d({},this.state),"function"==typeof n&&(n=n(d({},t),this.props)),n&&d(t,n),null!=n&&this.__v&&(l&&this._sb.push(l),M(this))},b.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),M(this))},b.prototype.render=m,r=[],o="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,e=function(n,l){return n.__v.__b-l.__v.__b},$.__r=0,f=/(PointerCapture)$|Capture$/i,c=0,s=T(!1),p=T(!0),a=0,exports.Component=b,exports.Fragment=m,exports.cloneElement=function(l,t,u){var r,i,o,e,f=d({},l.props);for(o in l.type&&l.type.defaultProps&&(e=l.type.defaultProps),t)"key"==o?r=t[o]:"ref"==o?i=t[o]:f[o]=null==t[o]&&null!=e?e[o]:t[o];return arguments.length>2&&(f.children=arguments.length>3?n.call(arguments,2):u),x(l.type,f,r||l.key,i||l.ref,null)},exports.createContext=function(n){function l(n){var t,u;return this.getChildContext||(t=new Set,(u={})[l.__c]=this,this.getChildContext=function(){return u},this.componentWillUnmount=function(){t=null},this.shouldComponentUpdate=function(n){this.props.value!=n.value&&t.forEach(function(n){n.__e=!0,M(n)})},this.sub=function(n){t.add(n);var l=n.componentWillUnmount;n.componentWillUnmount=function(){t&&t.delete(n),l&&l.call(n)}}),n.children}return l.__c="__cC"+a++,l.__=n,l.Provider=l.__l=(l.Consumer=function(n,l){return n.children(l)}).contextType=l,l},exports.createElement=_,exports.createRef=function(){return{current:null}},exports.h=_,exports.hydrate=function n(l,t){B(l,t,n)},exports.isValidElement=u,exports.options=l,exports.render=B,exports.toChildArray=function n(l,t){return t=t||[],null==l||"boolean"==typeof l||(w(l)?l.some(function(l){n(l,t)}):t.push(l)),t}; //# sourceMappingURL=preact.js.map