export type VNode = | { type: string; namespaceURI?: string; attributes: { [key: string]: string }; children: VNode[]; } | { text: string }; export function h( type: string, attributes: { [key: string]: string }, ...children: (VNode | null | undefined | false)[] ): VNode { let namespaceURI: string | undefined; if (mathmlTagNames.includes(type)) { namespaceURI = "http://www.w3.org/1998/Math/MathML"; } else if (svgTagNames.includes(type)) { namespaceURI = "http://www.w3.org/2000/svg"; } return { type, namespaceURI, attributes, children: children.filter((child) => !!child), }; } export function t(text: string): VNode { return { text }; } const svgTagNames = [ "a", "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "animation", "audio", "canvas", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "discard", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "handler", "hkern", "iframe", "image", "line", "linearGradient", "listener", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "prefetch", "radialGradient", "rect", "script", "set", "solidColor", "stop", "style", "svg", "switch", "symbol", "tbreak", "text", "textArea", "textPath", "title", "tref", "tspan", "unknown", "use", "video", "view", "vkern", ]; const mathmlTagNames = [ "abs", "and", "annotation", "annotation-xml", "apply", "approx", "arccos", "arccosh", "arccot", "arccoth", "arccsc", "arccsch", "arcsec", "arcsech", "arcsin", "arcsinh", "arctan", "arctanh", "arg", "bind", "bvar", "card", "cartesianproduct", "cbytes", "ceiling", "cerror", "ci", "cn", "codomain", "complexes", "compose", "condition", "conjugate", "cos", "cosh", "cot", "coth", "cs", "csc", "csch", "csymbol", "curl", "declare", "degree", "determinant", "diff", "divergence", "divide", "domain", "domainofapplication", "emptyset", "encoding", "eq", "equivalent", "eulergamma", "exists", "exp", "exponentiale", "factorial", "factorof", "false", "floor", "fn", "forall", "function", "gcd", "geq", "grad", "gt", "ident", "image", "imaginary", "imaginaryi", "implies", "in", "infinity", "int", "integers", "intersect", "interval", "inverse", "lambda", "laplacian", "lcm", "leq", "limit", "list", "ln", "log", "logbase", "lowlimit", "lt", "maction", "malign", "maligngroup", "malignmark", "malignscope", "math", "matrix", "matrixrow", "max", "mean", "median", "menclose", "merror", "mfenced", "mfrac", "mfraction", "mglyph", "mi", "min", "minus", "mlabeledtr", "mlongdiv", "mmultiscripts", "mn", "mo", "mode", "moment", "momentabout", "mover", "mpadded", "mphantom", "mprescripts", "mroot", "mrow", "ms", "mscarries", "mscarry", "msgroup", "msline", "mspace", "msqrt", "msrow", "mstack", "mstyle", "msub", "msubsup", "msup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "naturalnumbers", "neq", "none", "not", "notanumber", "notin", "notprsubset", "notsubset", "or", "otherwise", "outerproduct", "partialdiff", "pi", "piece", "piecewice", "piecewise", "plus", "power", "primes", "product", "prsubset", "quotient", "rationals", "real", "reals", "reln", "rem", "root", "scalarproduct", "sdev", "sec", "sech", "select", "selector", "semantics", "sep", "set", "setdiff", "share", "sin", "sinh", "subset", "sum", "tan", "tanh", "tendsto", "times", "transpose", "true", "union", "uplimit", "var", "variance", "vector", "vectorproduct", "xor", ];