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