jsx-async-runtime
Advanced tools
Comparing version 0.0.3 to 0.1.0
@@ -1,3 +0,5 @@ | ||
function x(t,e,...i){e??={};let n=[];for(let r of i)g(r,n);return e?.children&&g(e.children,n),e.children=n,Object.freeze(n),Object.freeze(e),{type:"tag",tag:t,props:e}}function g(t,e){switch(typeof t){case"string":e.push({type:"textNode",text:t});break;case"number":e.push({type:"textNode",text:t.toString()});break;case"object":if(Array.isArray(t))for(let i of t)g(i,e);else t!=null&&e.push(t);break}}function $(t){return typeof t=="string"?t.replace(J,e=>h[e]):t}var h={"&":"&","<":"<",">":">",'"':""","'":"'"},J=new RegExp(`[${Object.keys(h).join("")}]`,"g");function m(t){let e=[];for(let i of t){let n=X(i);n.length>0&&e.push(n)}return e.join(" ")}function X([t,e]){if(e===!0)return t;if(e===!1||e===null||e===void 0)return"";if(typeof e=="object")switch(t){case"style":let i=Object.entries(e).map(([r,s])=>`${r}: ${s}`);return`style="${f(i.join("; "))}"`;case"class":let n=Object.entries(e).filter(([r,s])=>s).map(([r,s])=>r);return`class="${f(n.join(" "))}"`;default:return`${t}="${f(JSON.stringify(e))}"`}return`${t}="${f(e.toString())}"`}function f(t){return t.replaceAll('"',""")}function S(t){return{tag:t.tag.toString(),attributes:T(t),children:E(t)}}function T(t){let e=[];for(let[i,n]of Object.entries(t.props))i!=="children"&&e.push([i,n]);return e}function E(t){return t.props.children?Array.isArray(t.props.children)?t.props.children:[t.props.children]:[]}var A=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);async function a(t,e){if(t===null)return"";switch(typeof t){case"string":return t;case"bigint":case"number":return String(t);case"boolean":case"function":case"symbol":case"undefined":return""}let{currentIndent:i=0,indent:n=2}=e??{};if(t.type==="textNode")return`${" ".repeat(i)}${t.text}`;if(typeof t.tag=="string"){let r=S(t);if(r.tag===""){let s=[];for(let o of r.children){let c=await a(o,{indent:n,currentIndent:i+n});c.length>0&&s.push(c)}return s.join(` | ||
`)}else{let s=" ".repeat(i),o=m(r.attributes),c=o.length?" ":"";if(r.children.length===0&&A.has(r.tag))return`${s}<${r.tag}${c}${o}>`;let u=r.children.length===0||r.children.every(j),l=`${s}<${r.tag}${c}${o}>`,d=`${u?"":s}</${r.tag}>`,p=[];for(let y of r.children){let b=await a(y,{indent:u?0:n,currentIndent:u?0:i+n});b.length>0&&p.push(b)}return u?`${l}${p.join("")}${d}`:[l,...p,d].join(` | ||
`)}}else{let r=await t.tag(t.props);return await a(r,{indent:n,currentIndent:i})}}function j(t){return typeof t=="object"&&t!=null&&"type"in t&&t.type==="textNode"}async function w(t,e){return await a(await t,e)}export{x as createElement,$ as escapeEntities,w as renderToString}; | ||
function $(t,e,...i){e??={};let n=[];for(let s of i)p(s,n);return e?.children&&p(e.children,n),e.children=n,Object.freeze(n),Object.freeze(e),{type:"tag",tag:t,props:e}}function p(t,e){switch(typeof t){case"string":e.push({type:"textNode",text:t});break;case"number":e.push({type:"textNode",text:t.toString()});break;case"object":if(Array.isArray(t))for(let i of t)p(i,e);else t!=null&&e.push(t);break}}function x(t){return typeof t=="string"?t.replace(J,e=>h[e]||e):t}var h={"&":"&","<":"<",">":">",'"':""","'":"'"},J=new RegExp(`[${Object.keys(h).join("")}]`,"g");function m(t){let e=[];for(let i of t){let n=T(i);n.length>0&&e.push(n)}return e.join(" ")}function T([t,e]){if(e===!0)return t;if(e===!1||e===null||e===void 0)return"";if(typeof e=="object")switch(t){case"style":let i=Object.entries(e).map(([s,r])=>`${s}: ${r}`);return`style="${u(i.join("; "))}"`;case"class":let n=Object.entries(e).filter(([s,r])=>r).map(([s,r])=>s);return`class="${u(n.join(" "))}"`;default:return`${t}="${u(JSON.stringify(e))}"`}return`${t}="${u(e.toString())}"`}function u(t){return t.replaceAll('"',""")}function S(t){return{tag:t.tag.toString(),attributes:E(t),children:X(t)}}function E(t){let e=[];for(let[i,n]of Object.entries(t.props))i!=="children"&&e.push([i,n]);return e}function X(t){return t.props.children?Array.isArray(t.props.children)?t.props.children:[t.props.children]:[]}var j=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);async function a(t,e){if(t===null||typeof t!="object")return String(t);let{currentIndent:i=0,indent:n=2}=e??{},s=" ".repeat(i);if(t.type==="textNode")return`${s}${t.text}`;if(typeof t.tag=="string"){let r=S(t);if(r.tag===""){let c=[];for(let f of r.children){let o=await a(f,{indent:n,currentIndent:i});o.length>0&&c.push(o)}return c.join(` | ||
`)}else{let c=m(r.attributes),f=c.length?" ":"";if(r.children.length===0&&j.has(r.tag))return`${s}<${r.tag}${f}${c}>`;let o=r.children.length===0||r.children.every(A),l=`${s}<${r.tag}${f}${c}>`,d=`${o?"":s}</${r.tag}>`,g=[];for(let y of r.children){let b=await a(y,{indent:o?0:n,currentIndent:o?0:i+n});b.length>0&&g.push(b)}return o?`${l}${g.join("")}${d}`:`${l} | ||
${g.join(` | ||
`)} | ||
${d}`}}else{let r=await t.tag(t.props);return await a(r,{indent:n,currentIndent:i})}}function A(t){return t!=null&&typeof t=="object"&&"type"in t&&t.type==="textNode"}async function w(t,e){return await a(await t,e)}export{$ as createElement,x as escapeEntities,w as renderToString}; |
{ | ||
"name": "jsx-async-runtime", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "An asynchronous JSX runtime without dependencies to be used as server-side template engine.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
753
32634