function renderNode(nodeName, attributes) { let {children, ...attrs} = attributes // It's a node if (nodeName === "text") { // Join all children into one string if (Array.isArray(children)) { attrs["content"] = children.map(x => String(x)).join("") children = [] } else { attrs["content"] = String(children) children = [] } } else { if (!children) { children = [] } else if (!Array.isArray(children)) { children = [children] } } return { type: "node", nodeName, children, attrs, } } export function jsx(nodeName, attributes) { // Set default weight let { weight, size, margin, padding, cornerRadius, fontSize, ...attrs } = attributes const style = { weight: weight || 1, size: size || 0, margin: margin || 0, padding: padding || 0, cornerRadius: cornerRadius || 0, fontSize: fontSize || 0, } // Text node if (typeof nodeName === "string") { return { ...renderNode(nodeName, attrs), style, } } // Module node return { type: "module", module: nodeName, style, attrs, } } export function jsxs(nodeName, attributes) { return jsx(nodeName, attributes) }