UNPKG

preact

Version:

Fast 3kb React-compatible Virtual DOM library.

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