From a9c4877198b982f9d0ceaad9b404d9291117351f Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Wed, 21 Jul 2021 11:58:44 +0200 Subject: [PATCH] Add special shadowRoot semantics --- skooma.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/skooma.js b/skooma.js index 1de807f..ed5aeb9 100644 --- a/skooma.js +++ b/skooma.js @@ -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]))