UNPKG

preact

Version:

Fast 3kb React-compatible Virtual DOM library.

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