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