2021-02-19 20:37:13 +00:00
|
|
|
const parseAttribute = (attribute) => {
|
|
|
|
if (typeof(attribute) == "string")
|
|
|
|
return attribute
|
|
|
|
else if ("join" in attribute)
|
|
|
|
return attribute.join(" ")
|
|
|
|
else
|
|
|
|
return JSON.stringify(attribute)
|
|
|
|
}
|
|
|
|
|
2021-02-17 10:03:21 +00:00
|
|
|
const parseArgs = (element, args) => {
|
2021-02-23 17:55:32 +00:00
|
|
|
if (element.content) element = element.content
|
2021-02-17 10:03:21 +00:00
|
|
|
for (arg of args)
|
|
|
|
if (typeof(arg) == "string")
|
|
|
|
element.appendChild(document.createTextNode(arg))
|
|
|
|
else if ("nodeName" in arg)
|
|
|
|
element.appendChild(arg)
|
|
|
|
else if ("length" in arg)
|
|
|
|
parseArgs(element, arg)
|
|
|
|
else
|
|
|
|
for (key in arg)
|
2021-02-19 20:37:13 +00:00
|
|
|
element.setAttribute(key.replace("_", "-"), parseAttribute(arg[key]))
|
2021-02-17 10:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const node = (name, args) => {
|
2021-02-19 20:37:13 +00:00
|
|
|
const element = document.createElement(name.replace("_", "-"))
|
2021-02-17 10:03:21 +00:00
|
|
|
parseArgs(element, args)
|
|
|
|
return element
|
|
|
|
}
|
|
|
|
|
2021-02-22 19:23:41 +00:00
|
|
|
export const html = new Proxy(Window, { get: (target, prop, receiver) => { return (...args) => node(prop, args) }})
|