UNPKG

tivex

Version:

A Small, JSX library for creating Reactive-UIs.

3 lines (2 loc) 2.47 kB
import{options as t,isValidElement as e}from"tivex";const r=null,o="dangerouslySetInnerHTML",n=t=>"function"==typeof t,i=Array.isArray,a=t=>"number"==typeof t,s=t=>t!=r,c=/^(area|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/,l={acceptCharset:"accept-charset",httpEquiv:"http-equiv",htmlFor:"for",className:"class"},u=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,p=(t,e)=>{let r="";for(let o in t){let n=t[o];if(s(n)&&""!==n){let t=o.replace(/[A-Z]/g,"-$&").toLowerCase(),i=";";"style"!==e||!a(n)||t.startsWith("--")||u.test(t)||(i="px;"),r=r+t+":"+n+i}}return r},h=/["'&<>]/;const f=(t={})=>{var e;let a="";for(const f in t){let d=t[f];if(d==r||!1===d||f===o||"key"===f||"ref"===f||"children"===f||n(d))continue;const $=null!==(e=l[f])&&void 0!==e?e:f.toLowerCase();!0===d?a+=` ${$}`:(s(u=d)&&"object"==typeof u&&!i(u)&&(d=p(d,$)),a+=` ${$}="${c=String(d),h.test(c)?(()=>{let t="",e=0,r=0,o="";for(;e<c.length;e++){switch(c.charCodeAt(e)){case 34:t="&quot;";break;case 38:t="&amp;";break;case 39:t="&#39;";break;case 60:t="&lt;";break;case 62:t="&gt;";break;default:continue}e!==r&&(o+=c.substring(r,e)),o+=t,r=e+1}return e!==r&&(o+=c.substring(r,e)),o})():c}"`)}var c,u;return a};function d(t){if(t==r||"boolean"==typeof t)return"";if(n(t))return d(t());if(a(t)||"string"==typeof t)return t.toString();if(i(t))return t.map((t=>d(t))).join("");if(e(t)){let{type:e,props:r}=t;if(n(e))return d(e(((t={})=>new Proxy(t,{get:(e,r)=>"$props"===r?t:"$set"===r?t=>{const r=(t,r)=>{const o=e[t];e[t]=n(r)?r(o):r};for(let e in t)r(e,t[e])}:"$default"===r?e=>{for(let r in e)r in t||(t[r]=e[r])}:e[r],set:(t,e,r)=>(t[e]=r,!0)}))(r)));const i=f(r);if(c.test(e))return`<${e}${i}>`;if(s(r[o]))return`<${e}${i}>${r[o].__html}</${e}>`;return`<${e}${i}>${d(r.children)}</${e}>`}return String(t)}t.renderToString=d;const $=(t,e={})=>{var r,o,n,i;null!==(r=e.docType)&&void 0!==r||(e.docType="<!DOCTYPE html>"),null!==(o=e.charset)&&void 0!==o||(e.charset="UTF-8"),null!==(n=e.viewport)&&void 0!==n||(e.viewport="width=device-width, initial-scale=1.0");const a=null!==(i=e.attribute)&&void 0!==i?i:{};return e.docType+`<html${f(a.html)}><head>`+(e.charset?`<meta charset="${e.charset}">`:"")+(e.viewport?`<meta name="viewport" content="${e.viewport}">`:"")+(e.head?d(e.head):"")+`</head><body${f(a.body)}>${d(t)}`+(e.footer?d(e.footer):"")+"</body></html>"};export{$ as renderToHtml,d as renderToString}; //# sourceMappingURL=server.js.map