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