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