@hyperapp/render
Version:
Render Hyperapp to an HTML string with SSR and Node.js streaming support
4 lines (3 loc) • 2.1 kB
JavaScript
/*! Hyperapp Render | MIT Licence | https://github.com/hyperapp/render */
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.hyperappRender={})}(this,function(e){"use strict";var l=new Map,f=/([A-Z])/g,a=/^ms-/,p=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),s=new Set(["key","innerHTML","__source"]),n=/["&'<>]/g,t=new Map([['"',"""],["&","&"],["'","'"],["<","<"],[">",">"]]);function r(e){return t.get(e)}function h(e){return"number"==typeof e?""+e:(""+e).replace(n,r)}function g(e){for(var n,t="",r="",o=Object.keys(e),i=0;i<o.length;i++){var u=o[i],c=e[u];null!=c&&(t+="cssText"===u?r+c:r+(n=u,l.get(n)||l.set(n,n.replace(f,"-$&").toLowerCase().replace(a,"-ms-")).get(n))+":"+c,r=";")}return t||null}function d(e,n){var t=e.nodeName,r=e.attributes,o=e.children,i="",u="";if(t){i+="<"+t;for(var c=Object.keys(r),l=0;l<c.length;l++){var f=c[l],a=r[f];"style"===f&&a&&"object"==typeof a&&(a=g(a)),null==a||!1===a||"function"==typeof a||s.has(f)||(i+=" "+f,!0!==a&&(i+='="'+h(a)+'"'))}p.has(t)?i+="/>":(i+=">",u="</"+t+">")}var d=r.innerHTML;return null!=d&&(i+=d),0<o.length?n.push({childIndex:0,children:o,footer:u}):i+=u,i}function b(e,n,t){return"function"==typeof e?b(e(n,t),n,t):e}function u(e,n,t){return o=n,i=t,c=!(u=[{childIndex:0,children:[e],footer:""}]),function(e){if(c)return null;for(var n="";n.length<e;){if(0===u.length){c=!0;break}var t=u[u.length-1];if(t.childIndex>=t.children.length)n+=t.footer,u.pop();else{var r=b(t.children[t.childIndex++],o,i);null!=r&&"boolean"!=typeof r&&(r.pop?u.push({childIndex:0,children:r,footer:""}):r.attributes?n+=d(r,u):n+=h(r))}}return n}(1/0);var o,i,u,c}e.renderToString=u,e.withRender=function(i){return function(e,n,t,r){var o=i(e,Object.assign({},n,{getState:function(){return function(e){return e}}}),t,r);return o.toString=function(){return u(t,o.getState(),o)},o}},Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=hyperapp-render.min.js.map