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