diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2024-06-13 23:53:36 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2024-06-13 23:53:36 +0100 |
commit | 483ab48f3ecd34af451dd38235ed791d81436cd4 (patch) | |
tree | 1cb16c80c3d64e6883fadbd3821bb559f7263815 /priv/static/lustre-server-component.mjs | |
parent | 4081a0941fcf55ce60866d4dcd60fc6fc99e7e8b (diff) | |
download | lustre-483ab48f3ecd34af451dd38235ed791d81436cd4.tar.gz lustre-483ab48f3ecd34af451dd38235ed791d81436cd4.zip |
:rocket: Build server component runtime.
Diffstat (limited to 'priv/static/lustre-server-component.mjs')
-rw-r--r-- | priv/static/lustre-server-component.mjs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/priv/static/lustre-server-component.mjs b/priv/static/lustre-server-component.mjs index 8913469..0892fb5 100644 --- a/priv/static/lustre-server-component.mjs +++ b/priv/static/lustre-server-component.mjs @@ -353,8 +353,10 @@ var LustreServerComponent = class extends HTMLElement { #observer = null; #root = null; #socket = null; + #shadow = null; constructor() { super(); + this.#shadow = this.attachShadow({ mode: "closed" }); this.#observer = new MutationObserver((mutations) => { const changed = []; for (const mutation of mutations) { @@ -377,7 +379,15 @@ var LustreServerComponent = class extends HTMLElement { } connectedCallback() { this.#root = document.createElement("div"); - this.appendChild(this.#root); + this.#shadow.appendChild(this.#root); + const sheet = new CSSStyleSheet(); + for (const { cssRules } of document.styleSheets) { + for (const rule of cssRules) { + console.log(rule); + sheet.insertRule(rule.cssText); + } + } + this.#shadow.adoptedStyleSheets = [sheet]; } attributeChangedCallback(name, prev, next) { switch (name) { @@ -471,6 +481,12 @@ var LustreServerComponent = class extends HTMLElement { disconnectedCallback() { this.#socket?.close(); } + get adoptedStyleSheets() { + return this.#shadow.adoptedStyleSheets; + } + set adoptedStyleSheets(value) { + this.#shadow.adoptedStyleSheets = value; + } }; window.customElements.define("lustre-server-component", LustreServerComponent); export { |