preact
Version:
Fast 4kb React-compatible Virtual DOM library.
3 lines (2 loc) • 12.1 kB
JavaScript
var n,t,r,i,u,f,e,o,l,c,a,s,h=Symbol.for("pv"),p={},v=[],y=/^m(i|n|o|s|text|space)$/,w=Array.isArray,d=v.slice,_=Object.assign;function g(n){n&&n.parentNode&&n.remove()}function k(n,t,r){var i,u,f,e={},o=arguments.length;for(f in t)"key"==f?i=t[f]:"ref"==f&&"function"!=typeof n?u=t[f]:e[f]=t[f];return o>2&&(e.children=o>3?d.call(arguments,2):r),m(n,e,i,u,null)}function b(n,t,r){var i,u,f,e=_({},n.props),o=arguments.length;for(f in t)"key"==f?i=t[f]:"ref"==f&&"function"!=typeof n.type?u=t[f]:e[f]=t[f];return o>2&&(e.children=o>3?d.call(arguments,2):r),m(n.type,e,void 0!==i?i:n.key,void 0!==u?u:n.ref,null)}function m(r,i,u,f,e){var o={type:r,props:i,key:u,ref:f,__k:null,__:null,__b:0,__e:null,__c:null,constructor:h,__v:e||++t,__i:-1,__u:0};return!e&&n.vnode&&n.vnode(o),o}function $(){return{current:null}}function M(n){return n.children}function x(n,t){this.props=n,this.context=t,this.__g=0}function S(n,t){if(null==t)return n.__&&S(n.__,n.__i+1);for(var r;t<n.__k.length;t++)if((r=n.__k[t])&&r.__e)return r.__e;return"function"!=typeof n.type||n.props.__P?null:S(n)}function C(n){if((n=n.__)&&n.__c&&!n.props.__P)return n.__e=null,n.__k.some(function(t){return t&&(n.__e=t.__e)}),C(n)}function j(t){(8&t.__g||(t.__g|=8,i.push(t),f++))&&u==n.debounceRendering||((u=n.debounceRendering)||queueMicrotask)(L)}function L(){var t,r,o,l,c,a,s,p,v;try{for(r=1;i.length;)i.length>r&&i.sort(e),t=i.shift(),r=i.length,8&t.__g&&(l=void 0,c=void 0,a=(c=(o=t).__v).__e,s=[],p=[],(v=o.__P)&&((l=_({constructor:h},c)).__v=c.__v+1,n.vnode&&n.vnode(l),V(v,l,c,o.__n,v.namespaceURI,32&c.__u?[a]:null,s,a||S(c),32&c.__u,p),l.__v=c.__v,l.__.__k[l.__i]=l,D(s,l,p),c.__=c.__e=null,l.__e!=a&&C(l)))}finally{(f=i.length)&&(u||queueMicrotask)(L)}}function H(n,t,r,i,u,f,e,o,l,c,a){var s,h,y,w,d,_,g=i.__k||v,k=t.length;for(l=I(r,t,g,l,k),s=0;s<k;s++)null!=(y=r.__k[s])&&(h=~y.__i&&g[y.__i]||p,y.__i=s,_=V(n,y,h,u,f,e,o,l,c,a),w=y.__e,(h.ref!=y.ref||8&h.__u)&&(h.ref&&F(h.ref,null,y,h),y.ref&&a.push(y.ref,y.__c||w,y)),d=d||w,4&y.__u?(l=q(y,l,n,!h.__v),h.__e&&(h.__e=null)):"function"==typeof y.type&&void 0!==_?l=_:w&&(l=w.nextSibling),y.__u&=-21);return r.__e=d,l}function I(n,t,r,i,u){var f,e,o,l,c,a,s,p,v,y=r.length,d=y,_=0,g=0,k=n.__k=Array(u);for(f=0;f<u;f++)null!=(e=t[f])&&"boolean"!=typeof e&&"function"!=typeof e?("object"!=typeof e||e.constructor===String?e=k[f]=m(null,e):w(e)?e=k[f]=m(M,{children:e}):e.constructor===h&&e.__b?e=k[f]=m(e.type,e.props,e.key,e.ref,e.__v):k[f]=e,l=f+_,e.__=n,e.__b=n.__b+1,o=null,~(c=e.__i=O(e,r,l,d))&&(d--,(o=r[c])&&(o.__u|=2)),o&&o.__v?(e.__u|=16,c==l-1?_--:c==l+1?_++:c!=l&&(c>l?_--:_++,g=1)):(~c||(u>y?_--:u<y&&_++),"function"!=typeof e.type&&(e.__u|=4))):k[f]=null;if(g){for(a=[],s=[],f=0;f<u;f++)if((e=k[f])&&16&e.__u){for(_=0,p=a.length;_<p;)a[v=_+p>>1]<e.__i?_=v+1:p=v;a[_]=e.__i,s[f]=_+1}for(_=a.length;f--;)s[f]&&(s[f]==_?_--:k[f].__u|=4)}if(d)for(f=0;f<y;f++)!(o=r[f])||2&o.__u||(o.__e==i&&(i=S(o)),G(o,o));return i}function q(n,t,r,i){var u,f,e,o;if("function"==typeof n.type){if(n.props.__P)return t;if(u=n.__k)for(f=0;f<u.length;f++)u[f]&&(u[f].__=n,t=q(u[f],t,r,!1));return t}for(t&&!t.parentNode&&(t=S(n))&&!t.parentNode&&(t=null),e=n.__e,o=t;o&&8==o.nodeType;)o=o.nextSibling;for(e!=o&&(!i&&r.moveBefore&&e.parentNode?r.moveBefore(e,t):r.insertBefore(e,t||null)),t=e;(t=t&&t.nextSibling)&&8==t.nodeType&&!t.data.startsWith("$s"););return t}function A(n,t){return t=t||[],null!=n&&"boolean"!=typeof n&&(w(n)?n.some(function(n){A(n,t)}):t.push(n)),t}function O(n,t,r,i){var u,f=n.key,e=n.type,o=t[r],l=o&&!(2&o.__u);if(null===o&&null==f||l&&f==o.key&&e==o.type)return r;if(i>(l?1:0)){for(u=r-1;u>=0;u--)if((o=t[u])&&!(2&o.__u)&&f==o.key&&e==o.type)return u;for(u=r+1;u<t.length;u++)if((o=t[u])&&!(2&o.__u)&&f==o.key&&e==o.type)return u}return-1}function P(n,t,r){null==r&&(r=""),"-"==t[0]?n.setProperty(t,r):n[t]=r}function T(n,t,r,i,u){var f,e;if("style"==t)if("string"==typeof r)n.style.cssText=r;else{if("string"==typeof i&&(n.style.cssText=i=""),i)for(t in i)r&&t in r||P(n.style,t);if(r)for(t in r)i&&r[t]==i[t]||P(n.style,t,r[t])}else if("o"==t[0]&&"n"==t[1])(n.__e||(n.__e={}))[t]=r,r&&i||(e=a[t]||(a[t]=N(t)),(n.__a||(n.__a={}))[t]=c,f=t!=(t=t.replace(l,"$1")),(t=t.slice(2))[0]<"a"&&(t=t.toLowerCase()),r?n.addEventListener(t,e,f):n.removeEventListener(t,e,f));else{if("http://www.w3.org/2000/svg"==u)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{return void(n[t]=null==r?"":r)}catch(n){}if("function"==typeof r)return;null==r||!1===r&&"-"!=t[4]?n.removeAttribute(t):n.setAttribute(t,"popover"==t&&1==r?"":r)}}function N(t){return function(r){var i=this.__e;if(i){if(i=i[t],null==r[o])r[o]=c++;else if(r[o]<this.__a[t])return;return i(n.event?n.event(r):r)}}}function V(t,r,i,u,f,e,o,l,c,a){var s,p,y,d,k,b,m,$,C,j,L,I,q,A,O,P,T,N,V=r.type;if(r.constructor!==h)return null;128&i.__u&&(c=32&i.__u,s=i.__c.__z)&&(r.__u|=c,p=e=[],8==s.nodeType?l=z(s,e):e.push(s),l=e[0]||l),(s=n.__b)&&s(r);n:if("function"==typeof V){y=o.length;try{if($=r.props,C=(s=V.prototype)&&s.render,j=(s=V.contextType)&&u[s.__c],L=s?j?j.props.value:s.__:u,(d=i.__c)?(r.__c=d,2&d.__g&&(d.__g|=1)):(C?r.__c=d=new V($,L):(r.__c=d=new x($,L),d.constructor=V,d.render=J),j&&j.sub(d),d.state||(d.state={}),d.__n=u,d.__g|=8,d.__h=[],d.__k=[]),C&&(d.__s||(d.__s=d.state),V.getDerivedStateFromProps&&(d.__s==d.state&&(d.__s=_({},d.__s)),_(d.__s,V.getDerivedStateFromProps($,d.__s)))),k=d.props,b=d.state,d.__v=r,i.__c){if($!==k&&C&&!V.getDerivedStateFromProps&&d.componentWillReceiveProps&&d.componentWillReceiveProps($,L),r.__v==i.__v&&!(8&d.__g)||!(4&d.__g)&&d.shouldComponentUpdate&&!1===d.shouldComponentUpdate($,d.__s,L)){r.__v!=i.__v&&(d.props=$,d.state=d.__s,d.__g&=-9),r.__e=i.__e,r.__k=i.__k,r.__k.some(function(n){n&&(n.__=r)}),v.push.apply(d.__h,d.__k),d.__k=[],d.__h.length&&o.push(d),l=S(i);break n}d.componentWillUpdate&&d.componentWillUpdate($,d.__s,L),C&&d.componentDidUpdate&&d.__h.push(function(){d.componentDidUpdate(k,b,m)})}else C&&!V.getDerivedStateFromProps&&d.componentWillMount&&d.componentWillMount(),C&&d.componentDidMount&&d.__h.push(d.componentDidMount);if(d.context=L,d.props=$,d.__P=t,d.__g&=-5,I=n.__r,q=0,C)d.state=d.__s,d.__g&=-9,I&&I(r),s=d.render(d.props,d.state,d.context),v.push.apply(d.__h,d.__k),d.__k=[];else do{d.__g&=-9,I&&I(r),s=d.render(d.props,d.state,d.context),d.state=d.__s}while(8&d.__g&&++q<25);d.state=d.__s,d.getChildContext&&(u=_({},u,d.getChildContext())),C&&i.__c&&d.getSnapshotBeforeUpdate&&(m=d.getSnapshotBeforeUpdate(k,b)),A=s&&s.type===M&&null==s.key?s.props.children:s,$.__P&&(s=l,f=(t=$.__P).namespaceURI,c=e=null,i.props&&i.props.__P!=t&&(i.__k.some(function(n){n&&G(n,n)}),i.__k=null),l=i.__k?S(i,0):null),l=H(t,w(A)?A:[A],r,i,u,f,e,o,l,c,a),$.__P&&(r.__e=null,l=s),r.__u&=-161,p&&p.some(g),d.__h.length&&o.push(d),1&d.__g&&(d.__g&=-4)}catch(t){if(o.length=y,r.__v=null,c||e)if(t.then){if(O=0,r.__u|=128|c,e){for(~(T=e.indexOf(l||void 0))||(T=e.length);(N=e[T-1])&&8==N.nodeType;)T--;for(;T<e.length;T++)if(N=e[T])if(e[T]=null,8==N.nodeType){if(N.data.startsWith("$s"))O++||(P=N);else if(O&&N.data.startsWith("/$s")&&!--O)break}else if(!O)break}if(!P){for(;l&&8==l.nodeType&&l.nextSibling;)l=l.nextSibling;P=l}(s=z(P=r.__c.__z||(r.__c.__z=P)))?(r.__e=P,l=s):r.__e=l,l=l&&l.nextSibling}else e&&e.some(g);else r.__e=i.__e;r.__k||(r.__k=i.__k||[]),t.then||B(r),n.__e(t,r,i)}}else l=r.__e=E(i.__e,r,i,u,f,e,o,c,a,t);return(s=n.diffed)&&s(r),l}function z(n,t){if(n&&8==n.nodeType&&n.data.startsWith("$s"))for(var r=1;n=n.nextSibling;){if(8==n.nodeType)if(n.data.startsWith("$s"))r++;else if(n.data.startsWith("/$s")&&!--r)return n;t&&t.push(n)}}function B(n){n&&(n.__c&&(n.__c.__g|=4),n.__k&&n.__k.some(B))}function D(t,r,i){for(var u=0;u<i.length;)F(i[u++],i[u++],i[u++]);n.__c&&n.__c(r,t),t.some(function(r){try{t=r.__h,r.__h=[],t.some(function(n){n.call(r)})}catch(t){n.__e(t,r.__v)}})}function E(t,r,i,u,f,e,o,l,c,a){var s,h,v,_,k,b,m,$,M,x=i.props||p,C=r.props,j=r.type;if("svg"==j?f="http://www.w3.org/2000/svg":"math"==j?f="http://www.w3.org/1998/Math/MathML":f||(f="http://www.w3.org/1999/xhtml"),e)for(s=0;s<e.length;s++)if((k=e[s])&&(j?k.localName==j:3==k.nodeType)){t=k,e[s]=null;break}if(!t){if($=a.ownerDocument||document,!j)return $.createTextNode(C);t=$.createElementNS(f,j,C.is&&C),l&&(n.__m&&n.__m(r,e),l=!1),e=null}if(j){if(a="template"==j?t.content:t,e="textarea"==j&&null!=C.defaultValue?null:e&&d.call(a.childNodes),!l&&e)for(x={},s=0;s<t.attributes.length;s++)x[(k=t.attributes[s]).name]=k.value;for(s in x)k=x[s],"dangerouslySetInnerHTML"==s?v=k:"children"==s||s in C||"value"==s&&"defaultValue"in C||"checked"==s&&"defaultChecked"in C||T(t,s,null,k,f);for(s in M=1&i.__u,C)k=C[s],"children"==s?_=k:"dangerouslySetInnerHTML"==s?h=k:"value"==s?b=k:"checked"==s?m=k:l&&"function"!=typeof k||!(x[s]!==k||M&&null!=k)||T(t,s,k,x[s],f);h?(l||v&&(h.__html==v.__html||h.__html==t.innerHTML)||(t.innerHTML=h.__html),r.__k=[]):(v&&(t.textContent=""),("foreignObject"==j||"http://www.w3.org/1998/Math/MathML"==f&&y.test(j))&&(f="http://www.w3.org/1999/xhtml"),H(a,w(_)?_:[_],r,i,u,f,e,o,e?e[0]:i.__k&&S(i,0),l,c),e&&e.some(g)),l&&"textarea"!=j||(s="value","progress"==j&&null==b?t.removeAttribute(s):null==b||b===t[s]&&("progress"!=j||b)||T(t,s,b,x[s],f),s="checked",null!=m&&m!=t[s]&&T(t,s,m,x[s],f))}else x===C||l&&t.data==C||(t.data=C);return t}function F(t,r,i,u){try{"function"==typeof t?r?r.__x=t(r)||1:u&&(u=u.__c||u.__e)&&(r=u.__x)&&(u.__x=null,"function"==typeof r?r():t(null)):t.current=r}catch(t){n.__e(t,i)}}function G(t,r,i){var u,f,e,o;if(n.unmount&&n.unmount(t),!(u=t.ref)||u.current&&u.current!=t.__e||F(u,null,r,t),u=t.__c){if(u.componentWillUnmount)try{u.componentWillUnmount()}catch(t){n.__e(t,r)}u.__P=u.__n=null}if(u=t.__k)for(o=0;o<u.length;o++)u[o]&&G(u[o],r,"function"!=typeof t.type||i&&!t.props.__P);!i&&(u=t.__c)&&(u=u.__z)&&(f=z(u,e=[]))&&(u==t.__e&&e.some(g),g(f),g(u)),(u=t.__e)&&(i||g(u),u.__e&&(u.__e=null)),t.__e=t.__c=t.__=null}function J(n,t,r){return this.constructor(n,r)}function K(t,r){var i,u,f,e;n.__&&n.__(t,r),9==r.nodeType&&(r=r.documentElement),u=(i=t&&32&t.__u)?null:r.__k,r.__k=m(M,{children:[t]}),f=[],e=[],V(r,r.__k,u||p,p,r.namespaceURI,u?null:r.firstChild?d.call(r.childNodes):null,f,u?u.__e:r.firstChild,i,e),D(f,r.__k,e),r.__k.props.children=null}function Q(n,t){n&&"object"==typeof n&&(n.__u|=32),K(n,t)}function R(n){function t(n){var r,i;return this.getChildContext||(r=new Set,(i={})[t.__c]=this,this.getChildContext=function(){return i},this.shouldComponentUpdate=function(n){this.props.value!=n.value&&r.forEach(function(n){n.__g|=4,j(n)})},this.sub=function(n){r.add(n);var t=n.componentWillUnmount;n.componentWillUnmount=function(){r.delete(n),t&&t.call(n)}}),n.children}return t.__c="__cC"+s++,t.__=n,t.Provider=(t.Consumer=function(n,t){return n.children(t)}).contextType=t,t}function U(n){return n.children}function W(n,t){return m(U,{__P:t,children:n})}n={__e:function(n,t,r,i){for(var u,e,o;t=t.__;)if((u=t.__c)&&!(1&u.__g)){u.__g|=4;try{if((o=(e=u.constructor)&&e.getDerivedStateFromError)&&u.setState(e.getDerivedStateFromError(n)),u.componentDidCatch&&(u.componentDidCatch(n,i||{}),o=1),o&&8&u.__g)return void(u.__g|=2)}catch(t){n=t}}throw f=0,n}},t=0,r=function(n){return null!=n&&n.constructor===h},x.prototype.setState=function(n,t){var r=this.__s;r&&r!=this.state||(r=this.__s=_({},this.state)),"function"==typeof n&&(n=n(_({},r),this.props)),n&&(_(r,n),this.__v&&(t&&this.__k.push(t),j(this)))},x.prototype.forceUpdate=function(n){this.__v&&(this.__g|=4,n&&this.__h.push(n),j(this))},x.prototype.render=M,i=[],f=0,e=function(n,t){return n.__v.__b-t.__v.__b},o=Symbol(),l=/(PointerCapture)$|Capture$/i,c=0,a={},s=0;export{x as Component,M as Fragment,b as cloneElement,R as createContext,k as createElement,W as createPortal,$ as createRef,k as h,Q as hydrate,r as isValidElement,n as options,K as render,A as toChildArray};
//# sourceMappingURL=preact.mjs.map