Add special shadowRoot semantics
This commit is contained in:
parent
3c7109155e
commit
a9c4877198
1 changed files with 5 additions and 3 deletions
|
@ -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]))
|
||||||
|
|
Loading…
Reference in a new issue