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