UNPKG

preact

Version:

Fast 3kb React-compatible Virtual DOM library.

3 lines (2 loc) 11.5 kB
var n,l,t,u,r,i,o,e,f,c,s,p,h,a={},v=[],y=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,d=Array.isArray;function w(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)void 0===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){if(n.__P&&n.__d){var t=n.__v,u=t.__e,r=[],i=[],o=w({},t);o.__v=t.__v+1,l.vnode&&l.vnode(o),F(n.__P,o,t,n.__n,n.__P.namespaceURI,32&t.__u?[u]:null,r,null==u?k(t):u,!!(32&t.__u),i),o.__v=t.__v,o.__.__k[o.__i]=o,z(r,o,i),t.__e=t.__=null,o.__e!=u&&M(o)}}function M(n){if(null!=(n=n.__)&&null!=n.__c)return n.__e=n.__c.base=null,n.__k.some(function(l){if(null!=l&&null!=l.__e)return n.__e=n.__c.base=l.__e}),M(n)}function $(n){(!n.__d&&(n.__d=!0)&&r.push(n)&&!C.__r++||i!=l.debounceRendering)&&((i=l.debounceRendering)||o)(C)}function C(){for(var n,l=1;r.length;)r.length>l&&r.sort(e),n=r.shift(),l=r.length,S(n);C.__r=0}function I(n,l,t,u,r,i,o,e,f,c,s){var p,h,y,d,w,g,_,x=u&&u.__k||v,m=l.length;for(f=P(t,l,x,f,m),p=0;p<m;p++)null!=(y=t.__k[p])&&(h=-1!=y.__i&&x[y.__i]||a,y.__i=p,g=F(n,y,h,r,i,o,e,f,c,s),d=y.__e,y.ref&&h.ref!=y.ref&&(h.ref&&q(h.ref,null,y),s.push(y.ref,y.__c||d,y)),null==w&&null!=d&&(w=d),(_=!!(4&y.__u))||h.__k===y.__k?f=A(y,f,n,_):"function"==typeof y.type&&void 0!==g?f=g:d&&(f=d.nextSibling),y.__u&=-7);return t.__e=w,f}function P(n,l,t,u,r){var i,o,e,f,c,s=t.length,p=s,h=0;for(n.__k=new Array(r),i=0;i<r;i++)null!=(o=l[i])&&"boolean"!=typeof o&&"function"!=typeof o?("string"==typeof o||"number"==typeof o||"bigint"==typeof o||o.constructor==String?o=n.__k[i]=x(null,o,null,null,null):d(o)?o=n.__k[i]=x(m,{children:o},null,null,null):void 0===o.constructor&&o.__b>0?o=n.__k[i]=x(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):n.__k[i]=o,f=i+h,o.__=n,o.__b=n.__b+1,e=null,-1!=(c=o.__i=H(o,t,f,p))&&(p--,(e=t[c])&&(e.__u|=2)),null==e||null==e.__v?(-1==c&&(r>s?h--:r<s&&h++),"function"!=typeof o.type&&(o.__u|=4)):c!=f&&(c==f-1?h--:c==f+1?h++:(c>f?h--:h++,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)),B(e,e));return u}function A(n,l,t,u){var r,i;if("function"==typeof n.type){for(r=n.__k,i=0;r&&i<r.length;i++)r[i]&&(r[i].__=n,l=A(r[i],l,t,u));return l}n.__e!=l&&(u&&(l&&n.type&&!l.parentNode&&(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 H(n,l,t,u){var r,i,o,e=n.key,f=n.type,c=l[t],s=null!=c&&0==(2&c.__u);if(null===c&&null==e||s&&e==c.key&&f==c.type)return t;if(u>(s?1:0))for(r=t-1,i=t+1;r>=0||i<l.length;)if(null!=(c=l[o=r>=0?r--:i++])&&0==(2&c.__u)&&e==c.key&&f==c.type)return o;return-1}function L(n,l,t){"-"==l[0]?n.setProperty(l,null==t?"":t):n[l]=null==t?"":"number"!=typeof t||y.test(l)?t:t+"px"}function T(n,l,t,u,r){var i,o;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||L(n.style,l,"");if(t)for(l in t)u&&t[l]==u[l]||L(n.style,l,t[l])}else if("o"==l[0]&&"n"==l[1])i=l!=(l=l.replace(f,"$1")),o=l.toLowerCase(),l=o in n||"onFocusOut"==l||"onFocusIn"==l?o.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 j(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 F(n,t,u,r,i,o,e,f,c,s){var p,h,a,y,_,x,k,S,M,$,C,P,A,H,L,T=t.type;if(void 0!==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 T)try{if(S=t.props,M="prototype"in T&&T.prototype.render,$=(p=T.contextType)&&r[p.__c],C=p?$?$.props.value:p.__:r,u.__c?k=(h=t.__c=u.__c).__=h.__E:(M?t.__c=h=new T(S,C):(t.__c=h=new b(S,C),h.constructor=T,h.render=D),$&&$.sub(h),h.state||(h.state={}),h.__n=r,a=h.__d=!0,h.__h=[],h._sb=[]),M&&null==h.__s&&(h.__s=h.state),M&&null!=T.getDerivedStateFromProps&&(h.__s==h.state&&(h.__s=w({},h.__s)),w(h.__s,T.getDerivedStateFromProps(S,h.__s))),y=h.props,_=h.state,h.__v=t,a)M&&null==T.getDerivedStateFromProps&&null!=h.componentWillMount&&h.componentWillMount(),M&&null!=h.componentDidMount&&h.__h.push(h.componentDidMount);else{if(M&&null==T.getDerivedStateFromProps&&S!==y&&null!=h.componentWillReceiveProps&&h.componentWillReceiveProps(S,C),t.__v==u.__v||!h.__e&&null!=h.shouldComponentUpdate&&!1===h.shouldComponentUpdate(S,h.__s,C)){t.__v!=u.__v&&(h.props=S,h.state=h.__s,h.__d=!1),t.__e=u.__e,t.__k=u.__k,t.__k.some(function(n){n&&(n.__=t)}),v.push.apply(h.__h,h._sb),h._sb=[],h.__h.length&&e.push(h);break n}null!=h.componentWillUpdate&&h.componentWillUpdate(S,h.__s,C),M&&null!=h.componentDidUpdate&&h.__h.push(function(){h.componentDidUpdate(y,_,x)})}if(h.context=C,h.props=S,h.__P=n,h.__e=!1,P=l.__r,A=0,M)h.state=h.__s,h.__d=!1,P&&P(t),p=h.render(h.props,h.state,h.context),v.push.apply(h.__h,h._sb),h._sb=[];else do{h.__d=!1,P&&P(t),p=h.render(h.props,h.state,h.context),h.state=h.__s}while(h.__d&&++A<25);h.state=h.__s,null!=h.getChildContext&&(r=w(w({},r),h.getChildContext())),M&&!a&&null!=h.getSnapshotBeforeUpdate&&(x=h.getSnapshotBeforeUpdate(y,_)),H=null!=p&&p.type===m&&null==p.key?N(p.props.children):p,f=I(n,d(H)?H:[H],t,u,r,i,o,e,f,c,s),h.base=t.__e,t.__u&=-161,h.__h.length&&e.push(h),k&&(h.__E=h.__=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(L=o.length;L--;)g(o[L]);O(t)}else t.__e=u.__e,t.__k=u.__k,n.then||O(t);l.__e(n,t,u)}else null==o&&t.__v==u.__v?(t.__k=u.__k,t.__e=u.__e):f=t.__e=V(u.__e,t,u,r,i,o,e,c,s);return(p=l.diffed)&&p(t),128&t.__u?void 0:f}function O(n){n&&(n.__c&&(n.__c.__e=!0),n.__k&&n.__k.some(O))}function z(n,t,u){for(var r=0;r<u.length;r++)q(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 N(n){return"object"!=typeof n||null==n||n.__b>0?n:d(n)?n.map(N):w({},n)}function V(t,u,r,i,o,e,f,c,s){var p,h,v,y,w,_,x,m=r.props||a,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((w=e[p])&&"setAttribute"in w==!!S&&(S?w.localName==S:3==w.nodeType)){t=w,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),!c&&null!=e)for(m={},p=0;p<t.attributes.length;p++)m[(w=t.attributes[p]).name]=w.value;for(p in m)w=m[p],"dangerouslySetInnerHTML"==p?v=w:"children"==p||p in b||"value"==p&&"defaultValue"in b||"checked"==p&&"defaultChecked"in b||T(t,p,null,w,o);for(p in b)w=b[p],"children"==p?y=w:"dangerouslySetInnerHTML"==p?h=w:"value"==p?_=w:"checked"==p?x=w:c&&"function"!=typeof w||m[p]===w||T(t,p,w,m[p],o);if(h)c||v&&(h.__html==v.__html||h.__html==t.innerHTML)||(t.innerHTML=h.__html),u.__k=[];else if(v&&(t.innerHTML=""),I("template"==u.type?t.content:t,d(y)?y:[y],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])&&T(t,p,_,m[p],o),p="checked",null!=x&&x!=t[p]&&T(t,p,x,m[p],o))}return t}function q(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 B(n,t,u){var r,i;if(l.unmount&&l.unmount(n),(r=n.ref)&&(r.current&&r.current!=n.__e||q(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]&&B(r[i],t,u||"function"!=typeof n.type);u||g(n.__e),n.__c=n.__=n.__e=void 0}function D(n,l,t){return this.constructor(n,t)}function E(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=[],F(u,t=(!i&&r||u).__k=_(m,null,[t]),o||a,a,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),z(e,t,f)}n=v.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&&void 0===n.constructor},b.prototype.setState=function(n,l){var t;t=null!=this.__s&&this.__s!=this.state?this.__s:this.__s=w({},this.state),"function"==typeof n&&(n=n(w({},t),this.props)),n&&w(t,n),null!=n&&this.__v&&(l&&this._sb.push(l),$(this))},b.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),$(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},C.__r=0,f=/(PointerCapture)$|Capture$/i,c=0,s=j(!1),p=j(!0),h=0,exports.Component=b,exports.Fragment=m,exports.cloneElement=function(l,t,u){var r,i,o,e,f=w({},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]=void 0===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,$(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"+h++,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){E(l,t,n)},exports.isValidElement=u,exports.options=l,exports.render=E,exports.toChildArray=function n(l,t){return t=t||[],null==l||"boolean"==typeof l||(d(l)?l.some(function(l){n(l,t)}):t.push(l)),t}; //# sourceMappingURL=preact.js.map