3 lines
8.7 KiB
JavaScript
3 lines
8.7 KiB
JavaScript
var e=require("preact"),t=/[\s\n\\/='"\0<>]/,r=/^(xlink|xmlns|xml)([A-Z])/,n=/^(?:accessK|auto[A-Z]|cell|ch|col|cont|cross|dateT|encT|form[A-Z]|frame|hrefL|inputM|maxL|minL|noV|playsI|popoverT|readO|rowS|src[A-Z]|tabI|useM|item[A-Z])/,o=/^ac|^ali|arabic|basel|cap|clipPath$|clipRule$|color|dominant|enable|fill|flood|font|glyph[^R]|horiz|image|letter|lighting|marker[^WUH]|overline|panose|pointe|paint|rendering|shape|stop|strikethrough|stroke|text[^L]|transform|underline|unicode|units|^v[^i]|^w|^xH/,i=new Set(["draggable","spellcheck"]),a=/["&<]/;function s(e){if(0===e.length||!1===a.test(e))return e;for(var t=0,r=0,n="",o="";r<e.length;r++){switch(e.charCodeAt(r)){case 34:o=""";break;case 38:o="&";break;case 60:o="<";break;default:continue}r!==t&&(n+=e.slice(t,r)),n+=o,t=r+1}return r!==t&&(n+=e.slice(t,r)),n}var c={},l=new Set(["animation-iteration-count","border-image-outset","border-image-slice","border-image-width","box-flex","box-flex-group","box-ordinal-group","column-count","fill-opacity","flex","flex-grow","flex-negative","flex-order","flex-positive","flex-shrink","flood-opacity","font-weight","grid-column","grid-row","line-clamp","line-height","opacity","order","orphans","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-miterlimit","stroke-opacity","stroke-width","tab-size","widows","z-index","zoom"]),u=/[A-Z]/g;function p(e){var t="";for(var r in e){var n=e[r];if(null!=n&&""!==n){var o="-"==r[0]?r:c[r]||(c[r]=r.replace(u,"-$&").toLowerCase()),i=";";"number"!=typeof n||o.startsWith("--")||l.has(o)||(i="px;"),t=t+o+":"+n+i}}return t||void 0}function f(){this.__d=!0}function d(e,t){return{__v:e,context:t,props:e.props,setState:f,forceUpdate:f,__d:!0,__h:new Array(0)}}var h,v,m,_,g=function(){var e=this;this.promise=new Promise(function(t,r){e.resolve=t,e.reject=r})},y={},b=[],x=Array.isArray,k=Object.assign;function w(t,r,n){var o=e.options.__s;e.options.__s=!0,h=e.options.__b,v=e.options.diffed,m=e.options.__r,_=e.options.unmount;var i=e.h(e.Fragment,null);i.__k=[t];try{var a=S(t,r||y,!1,void 0,i,!1,n);return x(a)?a.join(""):a}catch(e){if(e.then)throw new Error('Use "renderToStringAsync" for suspenseful rendering.');throw e}finally{e.options.__c&&e.options.__c(t,b),e.options.__s=o,b.length=0}}function C(e,t){var r,n=e.type,o=!0;return e.__c?(o=!1,(r=e.__c).state=r.__s):r=new n(e.props,t),e.__c=r,r.__v=e,r.props=e.props,r.context=t,r.__d=!0,null==r.state&&(r.state=y),null==r.__s&&(r.__s=r.state),n.getDerivedStateFromProps?r.state=k({},r.state,n.getDerivedStateFromProps(r.props,r.state)):o&&r.componentWillMount?(r.componentWillMount(),r.state=r.__s!==r.state?r.__s:r.state):!o&&r.componentWillUpdate&&r.componentWillUpdate(),m&&m(e),r.render(r.props,r.state,t)}function S(a,c,l,u,f,g,b){if(null==a||!0===a||!1===a||""===a)return"";var w=typeof a;if("object"!=w)return"function"==w?"":"string"==w?s(a):a+"";if(x(a)){var E,L="";f.__k=a;for(var P=a.length,F=0;F<P;F++){var T=a[F];if(null!=T&&"boolean"!=typeof T){var j,W=S(T,c,l,u,f,g,b);"string"==typeof W?L+=W:(E||(E=new Array(P)),L&&E.push(L),L="",x(W)?(j=E).push.apply(j,W):E.push(W))}}return E?(L&&E.push(L),E):L}if(void 0!==a.constructor)return"";a.__=f,h&&h(a);var D=a.type,N=a.props;if("function"==typeof D){var M,U,Z,q=c;if(D===e.Fragment){if("tpl"in N){for(var $="",H=0;H<N.tpl.length;H++)if($+=N.tpl[H],N.exprs&&H<N.exprs.length){var R=N.exprs[H];if(null==R)continue;"object"!=typeof R||void 0!==R.constructor&&!x(R)?$+=R:$+=S(R,c,l,u,a,g,b)}return $}if("UNSTABLE_comment"in N)return"\x3c!--"+s(N.UNSTABLE_comment)+"--\x3e";U=N.children}else{if(null!=(M=D.contextType)){var z=c[M.__c];q=z?z.props.value:M.__}var I=D.prototype&&"function"==typeof D.prototype.render;if(I)U=C(a,q),Z=a.__c;else{a.__c=Z=d(a,q);for(var B=0;Z.__d&&B++<25;)Z.__d=!1,m&&m(a),U=D.call(Z,N,q);Z.__d=!0}if(null!=Z.getChildContext&&(c=k({},c,Z.getChildContext())),I&&e.options.errorBoundaries&&(D.getDerivedStateFromError||Z.componentDidCatch)){U=null!=U&&U.type===e.Fragment&&null==U.key&&null==U.props.tpl?U.props.children:U;try{return S(U,c,l,u,a,g,b)}catch(t){return D.getDerivedStateFromError&&(Z.__s=D.getDerivedStateFromError(t)),Z.componentDidCatch&&Z.componentDidCatch(t,y),Z.__d?(U=C(a,c),null!=(Z=a.__c).getChildContext&&(c=k({},c,Z.getChildContext())),S(U=null!=U&&U.type===e.Fragment&&null==U.key&&null==U.props.tpl?U.props.children:U,c,l,u,a,g,b)):""}finally{v&&v(a),_&&_(a)}}}U=null!=U&&U.type===e.Fragment&&null==U.key&&null==U.props.tpl?U.props.children:U;try{var O=S(U,c,l,u,a,g,b);return v&&v(a),e.options.unmount&&e.options.unmount(a),O}catch(t){if(!g&&b&&b.onError){var V=b.onError(t,a,function(e,t){return S(e,c,l,u,t,g,b)});if(void 0!==V)return V;var K=e.options.__e;return K&&K(t,a),""}if(!g)throw t;if(!t||"function"!=typeof t.then)throw t;return t.then(function e(){try{return S(U,c,l,u,a,g,b)}catch(t){if(!t||"function"!=typeof t.then)throw t;return t.then(function(){return S(U,c,l,u,a,g,b)},e)}})}}var G,J="<"+D,Q="";for(var X in N){var Y=N[X];if("function"!=typeof Y||"class"===X||"className"===X){switch(X){case"children":G=Y;continue;case"key":case"ref":case"__self":case"__source":continue;case"htmlFor":if("for"in N)continue;X="for";break;case"className":if("class"in N)continue;X="class";break;case"defaultChecked":X="checked";break;case"defaultSelected":X="selected";break;case"defaultValue":case"value":switch(X="value",D){case"textarea":G=Y;continue;case"select":u=Y;continue;case"option":u!=Y||"selected"in N||(J+=" selected")}break;case"dangerouslySetInnerHTML":Q=Y&&Y.__html;continue;case"style":"object"==typeof Y&&(Y=p(Y));break;case"acceptCharset":X="accept-charset";break;case"httpEquiv":X="http-equiv";break;default:if(r.test(X))X=X.replace(r,"$1:$2").toLowerCase();else{if(t.test(X))continue;"-"!==X[4]&&!i.has(X)||null==Y?l?o.test(X)&&(X="panose1"===X?"panose-1":X.replace(/([A-Z])/g,"-$1").toLowerCase()):n.test(X)&&(X=X.toLowerCase()):Y+=""}}null!=Y&&!1!==Y&&(J=!0===Y||""===Y?J+" "+X:J+" "+X+'="'+("string"==typeof Y?s(Y):Y+"")+'"')}}if(t.test(D))throw new Error(D+" is not a valid HTML tag name in "+J+">");if(Q||("string"==typeof G?Q=s(G):null!=G&&!1!==G&&!0!==G&&(Q=S(G,c,"svg"===D||"foreignObject"!==D&&l,u,a,g,b))),v&&v(a),_&&_(a),!Q&&A.has(D))return J+"/>";var ee="</"+D+">",te=J+">";return x(Q)?[te].concat(Q,[ee]):"string"!=typeof Q?[te,Q,ee]:te+Q+ee}var A=new Set(["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]);function E(e,t){return'<preact-island hidden data-target="'+e+'">'+t+"</preact-island>"}var L=function e(t){try{var r=function(){if(t.suspended.length>0){var r=[].concat(t.suspended);return Promise.resolve(Promise.all(t.suspended.map(function(e){return e.promise}))).then(function(){return t.suspended=t.suspended.filter(function(e){return!r.includes(e)}),Promise.resolve(e(t)).then(function(){})})}}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},P=function(e,t){var r=t.context,n=t.onWrite,o=t.abortSignal;try{r=r||{};var i={start:Date.now(),abortSignal:o,onWrite:n,onError:F,suspended:[]},a=w(e,r,i);n(a);var s=i.suspended.length,c=function(){if(s>0)return n("<div hidden>"),n('<script>(function(){class e extends HTMLElement{connectedCallback(){var e=this;if(!e.isConnected)return;let t=this.getAttribute("data-target");if(t){for(var r,a,i=document.createNodeIterator(document,128);i.nextNode();){let e=i.referenceNode;if(e.data=="preact-island:"+t?r=e:e.data=="/preact-island:"+t&&(a=e),r&&a)break}r&&a&&requestAnimationFrame((()=>{for(var t=a.previousSibling;t!=r&&t&&t!=r;)a.parentNode.removeChild(t),t=a.previousSibling;for(i=r;e.firstChild;)r=e.firstChild,e.removeChild(r),i.after(r),i=r;e.parentNode.removeChild(e)}))}}}customElements.define("preact-island",e);}())<\/script>'),Promise.resolve(L(i)).then(function(){n("</div>")})}();return Promise.resolve(c&&c.then?c.then(function(){}):void 0)}catch(e){return Promise.reject(e)}};function F(e,t,r){var n=this;if(e&&e.then){for(;t=t.__;){var o=t.__c;if(o&&o.__c)break}if(t){var i=t.__v,a=this.suspended.find(function(e){return e.id===i}),s=new g,c=this.abortSignal;c&&(c.aborted?s.resolve():c.addEventListener("abort",s.resolve));var l=e.then(function(){if(!c||!c.aborted){var e=r(t.props.children,t);e&&n.onWrite(E(i,e))}},this.onError);this.suspended.push({id:i,vnode:t,promise:Promise.race([l,s.promise])});var u=r(t.props.fallback);return a?"":"\x3c!--preact-island:"+i+"--\x3e"+u+"\x3c!--/preact-island:"+i+"--\x3e"}}}exports.renderToReadableStream=function(e,t){var r=new g,n=new TextEncoder("utf-8"),o=new ReadableStream({start:function(o){P(e,{context:t,onError:function(e){r.reject(e),o.abort(e)},onWrite:function(e){o.enqueue(n.encode(e))}}).then(function(){o.close(),r.resolve()}).catch(function(e){o.error(e),r.reject(e)})}});return o.allReady=r.promise,o};
|
|
//# sourceMappingURL=index.js.map
|