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