From ba8baf0dde0c9023a173b8c090065129645645c6 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Wed, 10 Jan 2024 21:34:43 -0500 Subject: [PATCH] refactor DOM methods to correct base class implementation (#139) --- src/dom-shim.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/dom-shim.js b/src/dom-shim.js index 389b996..39579fc 100644 --- a/src/dom-shim.js +++ b/src/dom-shim.js @@ -31,6 +31,18 @@ class Element extends Node { this.attributes = {}; } + attachShadow(options) { + this.shadowRoot = new ShadowRoot(options); + + return this.shadowRoot; + } + + // https://github.com/mfreed7/declarative-shadow-dom/blob/master/README.md#serialization + // eslint-disable-next-line + getInnerHTML() { + return this.shadowRoot ? this.shadowRoot.innerHTML : this.innerHTML; + } + setAttribute(name, value) { this.attributes[name] = value; } @@ -68,19 +80,7 @@ class Document extends Node { // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement // EventTarget <- Node <- Element <- HTMLElement class HTMLElement extends Element { - attachShadow(options) { - this.shadowRoot = new ShadowRoot(options); - - return this.shadowRoot; - } - connectedCallback() { } - - // https://github.com/mfreed7/declarative-shadow-dom/blob/master/README.md#serialization - // eslint-disable-next-line - getInnerHTML(options = {}) { - return this.shadowRoot.innerHTML; - } } // https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment