UNPKG

preact

Version:

Fast 3kb React-compatible Virtual DOM library.

3 lines (2 loc) 11.6 kB
var n,l,t,u,i,r,e,o,f,c,a,s,h,p,y,v,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,r,e,o={};for(e in t)"key"==e?i=t[e]:"ref"==e?r=t[e]:o[e]=t[e];if(arguments.length>2&&(o.children=arguments.length>3?n.call(arguments,2):u),"function"==typeof l&&null!=l.defaultProps)for(e in l.defaultProps)void 0===o[e]&&(o[e]=l.defaultProps[e]);return C(l,o,i,r,null)}function C(n,u,i,r,e){var o={type:n,props:u,key:i,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==e?++t:e,__i:-1,__u:0};return null==e&&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=[],r=[],e=b({},t);e.__v=t.__v+1,l.vnode&&l.vnode(e),z(n.__P,e,t,n.__n,n.__P.namespaceURI,32&t.__u?[u]:null,i,null==u?$(t):u,!!(32&t.__u),r),e.__v=t.__v,e.__.__k[e.__i]=e,R(i,e,r),t.__e=t.__=null,e.__e!=u&&I(e)}}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++||r!=l.debounceRendering)&&((r=l.debounceRendering)||e)(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,r,e,o,f,c,a){var s,h,p,y,v,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,r,e,o,f,c,a),y=p.__e,p.ref&&h.ref!=p.ref&&(h.ref&&D(h.ref,null,p),a.push(p.ref,p.__c||y,p)),null==v&&null!=y&&(v=y),(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:y&&(f=y.nextSibling),p.__u&=-7);return t.__e=v,f}function H(n,l,t,u,i){var r,e,o,f,c,a=t.length,s=a,h=0;for(n.__k=new Array(i),r=0;r<i;r++)null!=(e=l[r])&&"boolean"!=typeof e&&"function"!=typeof e?("string"==typeof e||"number"==typeof e||"bigint"==typeof e||e.constructor==String?e=n.__k[r]=C(null,e,null,null,null):g(e)?e=n.__k[r]=C(M,{children:e},null,null,null):void 0===e.constructor&&e.__b>0?e=n.__k[r]=C(e.type,e.props,e.key,e.ref?e.ref:null,e.__v):n.__k[r]=e,f=r+h,e.__=n,e.__b=n.__b+1,o=null,-1!=(c=e.__i=T(e,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 e.type&&(e.__u|=4)):c!=f&&(c==f-1?h--:c==f+1?h++:(c>f?h--:h++,e.__u|=4))):n.__k[r]=null;if(s)for(r=0;r<a;r++)null!=(o=t[r])&&0==(2&o.__u)&&(o.__e==u&&(u=$(o)),G(o,o));return u}function L(n,l,t,u){var i,r;if("function"==typeof n.type){for(i=n.__k,r=0;i&&r<i.length;r++)i[r]&&(i[r].__=n,l=L(i[r],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,r,e,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,r=t+1;i>=0||r<l.length;)if(null!=(c=l[e=i>=0?i--:r++])&&0==(2&c.__u)&&o==c.key&&f==c.type)return e;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 r,e;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])r=l!=(l=l.replace(s,"$1")),e=l.toLowerCase(),l=e in n||"onFocusOut"==l||"onFocusIn"==l?e.slice(2):l.slice(2),n.l||(n.l={}),n.l[l+r]=t,t?u?t[a]=u[a]:(t[a]=h,n.addEventListener(l,r?y:p,r)):n.removeEventListener(l,r?y:p,r);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,r,e,o,f,c,a){var s,h,p,y,v,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),e=[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))),y=h.props,v=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!==y&&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(y,v,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(y,v)),P=null!=s&&s.type===M&&null==s.key?q(s.props.children):s,f=F(n,g(P)?P:[P],t,u,i,r,e,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!=e)if(n.then){for(t.__u|=c?160:128;f&&8==f.nodeType&&f.nextSibling;)f=f.nextSibling;e[e.indexOf(f)]=null,t.__e=f}else{for(E=e.length;E--;)k(e[E]);N(t)}else t.__e=u.__e,t.__k=u.__k,n.then||N(t);l.__e(n,t,u)}else null==e&&t.__v==u.__v?(t.__k=u.__k,t.__e=u.__e):f=t.__e=B(u.__e,t,u,i,r,e,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):b({},n)}function B(t,u,i,r,e,o,f,c,a){var s,h,p,y,v,d,_,m=i.props||w,b=u.props,x=u.type;if("svg"==x?e="http://www.w3.org/2000/svg":"math"==x?e="http://www.w3.org/1998/Math/MathML":e||(e="http://www.w3.org/1999/xhtml"),null!=o)for(s=0;s<o.length;s++)if((v=o[s])&&"setAttribute"in v==!!x&&(x?v.localName==x:3==v.nodeType)){t=v,o[s]=null;break}if(null==t){if(null==x)return document.createTextNode(b);t=document.createElementNS(e,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=o&&n.call(t.childNodes),!c&&null!=o)for(m={},s=0;s<t.attributes.length;s++)m[(v=t.attributes[s]).name]=v.value;for(s in m)v=m[s],"dangerouslySetInnerHTML"==s?p=v:"children"==s||s in b||"value"==s&&"defaultValue"in b||"checked"==s&&"defaultChecked"in b||O(t,s,null,v,e);for(s in b)v=b[s],"children"==s?y=v:"dangerouslySetInnerHTML"==s?h=v:"value"==s?d=v:"checked"==s?_=v:c&&"function"!=typeof v||m[s]===v||O(t,s,v,m[s],e);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(y)?y:[y],u,i,r,"foreignObject"==x?"http://www.w3.org/1999/xhtml":e,o,f,o?o[0]:i.__k&&$(i,0),c,a),null!=o)for(s=o.length;s--;)k(o[s]);c||(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],e),s="checked",null!=_&&_!=t[s]&&O(t,s,_,m[s],e))}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,r;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(r=0;r<i.length;r++)i[r]&&G(i[r],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 r,e,o,f;u==document&&(u=document.documentElement),l.__&&l.__(t,u),e=(r="function"==typeof i)?null:i&&i.__k||u.__k,o=[],f=[],z(u,t=(!r&&i||u).__k=x(M,null,[t]),e||w,w,u.namespaceURI,!r&&i?[i]:e?null:u.firstChild?n.call(u.childNodes):null,o,!r&&i?i:e?e.__e:u.firstChild,r,f),R(o,t,f)}n=_.slice,l={__e:function(n,l,t,u){for(var i,r,e;l=l.__;)if((i=l.__c)&&!i.__)try{if((r=i.constructor)&&null!=r.getDerivedStateFromError&&(i.setState(r.getDerivedStateFromError(n)),e=i.__d),null!=i.componentDidCatch&&(i.componentDidCatch(n,u||{}),e=i.__d),e)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=[],e="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),y=V(!0),v=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,r,e,o,f=b({},l.props);for(e in l.type&&l.type.defaultProps&&(o=l.type.defaultProps),t)"key"==e?i=t[e]:"ref"==e?r=t[e]:f[e]=void 0===t[e]&&null!=o?o[e]:t[e];return arguments.length>2&&(f.children=arguments.length>3?n.call(arguments,2):u),C(l.type,f,i||l.key,r||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"+v++,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