UNPKG

hyperapp-render

Version:

Render Hyperapp to an HTML string with SSR and Node.js streaming support

4 lines (3 loc) 2.6 kB
/*! Hyperapp Render v4.0.1 | MIT Licence | https://github.com/kriasoft/hyperapp-render */ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).hyperappRender={})}(this,(function(e){"use strict";var r=Array.isArray,n=Object.prototype.hasOwnProperty,t=new Map,a=/[A-Z]/g,o=/^ms-/,i=/["&'<>]/,l=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function f(e){if(null==e)return"";var r=""+e;if("number"==typeof e)return r;var n=i.exec(r);if(!n)return r;for(var t=n.index,a=0,o="",l="";t<r.length;t++){switch(r.charCodeAt(t)){case 34:l="&quot;";break;case 38:l="&amp;";break;case 39:l="&#39;";break;case 60:l="&lt;";break;case 62:l="&gt;";break;default:continue}a!==t&&(o+=r.substring(a,t)),a=t+1,o+=l}return a!==t?o+r.substring(a,t):o}function c(e){if("string"==typeof e||"number"==typeof e)return e||"";var t="",a="";if(r(e))for(var o=0;o<e.length;o++){var i=c(e[o]);""!==i&&(t+=a+i,a=" ")}else for(var l in e)n.call(e,l)&&e[l]&&(t+=a+l,a=" ");return t}function u(e){if(!t.has(e)){var r=e.replace(a,"-$&").toLowerCase().replace(o,"-ms-");t.set(e,r)}return t.get(e)}function s(e){var r="",t="";for(var a in e)if(n.call(e,a)){var o=e[a];null!=o&&(r+="cssText"===a?t+o:t+u(a)+":"+o,t=";")}return r}function p(e,r,t,a){var o="",i="";if(e){for(var u in o+="<"+e,r)if(n.call(r,u)){var p=r[u];null==p||"key"===u||"innerHTML"===u||"__source"===u||"o"===u[0]&&"n"===u[1]||("class"===u||"className"===u?(u="class",p=c(p)||!1):"style"===u&&"object"==typeof p&&(p=s(p)||!1),!1!==p&&(o+=" "+u,!0!==p&&(o+='="'+f(p)+'"')))}l.has(e)?o+="/>":(o+=">",i="</"+e+">")}if(t.length>0)a.push({childIndex:0,children:t,footer:i});else{var d=r.innerHTML;null!=d&&(o+=d),o+=i}return o}function d(e,r,n){return"function"==typeof e?d(e(r,n),r,n):e&&2===e.type?d(e.lazy.view(e.lazy),r,n):e}e.renderToString=function(e,n,t){return function(e,n,t){var a=[{childIndex:0,children:[e],footer:""}],o=!1;return function(e){if(o)return null;for(var i="";i.length<e;){if(0===a.length){o=!0;break}var l=a[a.length-1];if(l.childIndex>=l.children.length)i+=l.footer,a.pop();else{var c=d(l.children[l.childIndex++],n,t);null!=c&&"boolean"!=typeof c&&(r(c)?a.push({childIndex:0,children:c,footer:""}):3===c.type?i+=f(c.tag||c.name):i+="object"==typeof c?p(c.tag||c.nodeName,c.props||c.attributes,c.children,a):f(c))}}return i}}(e,n,t)(1/0)},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=hyperapp-render.min.js.map