Add special shadowRoot semantics

This commit is contained in:
Talia 2021-07-21 11:58:44 +02:00
parent d670416c7a
commit f8db2ca876
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E

View file

@ -19,7 +19,7 @@ const parseAttribute = (attribute) => {
return JSON.stringify(attribute)
}
const parseArgs = (element, args) => {
const parseArgs = (element, ...args) => {
if (element.content) element = element.content
for (let arg of args)
if (typeof arg == "string" || typeof arg == "number")
@ -27,10 +27,12 @@ const parseArgs = (element, args) => {
else if ("nodeName" in arg)
element.appendChild(arg)
else if ("length" in arg)
parseArgs(element, arg)
parseArgs(element, ...arg)
else
for (let key in arg)
if (typeof arg[key] == "function")
if (key == "shadowRoot")
parseArgs((element.shadowRoot || element.attachShadow({mode: "open"})), arg[key])
else if (typeof arg[key] == "function")
element.addEventListener(key.replace(/^on[A-Z]/, x => x.charAt(x.length-1).toLowerCase()), e => e.preventDefault() || arg[key](e))
else
element.setAttribute(key, parseAttribute(arg[key]))