hyperhive/frontend/packages/shared/src/shadow-css.js
atlas 39b95c2ede treefmt: apply prettier
Pure `nix fmt` output from the commit before this one — no hand edits.
203 files: 52 md, 42 tsx, 32 js, 32 css, 21 ts, 13 html, 8 json, 3 mjs.

Reproduce with `nix develop -c nix fmt` on the parent commit; the result
should be byte-identical to this tree.

None of the 13 `.prettierignore` entries appears here — verified by
intersecting the changed-file list against the ignore file, with a
control proving the intersection finds a match when one exists.
2026-09-02 15:25:07 +02:00

21 lines
1.1 KiB
JavaScript

// attachShadowCss(host, cssText, shadowInit) — attach an open shadow root
// to `host`, append `cssText` as a plain `<style>` element, and return the
// root. Shared by every shadow-DOM custom element (hive-dialog, hive-toast,
// hive-btn) so the boilerplate lives in one place instead of being
// copy-pasted per component.
//
// A `<style>` element rather than a constructed `CSSStyleSheet` +
// `adoptedStyleSheets` — mara's call on review, and the right one: each
// component instance was already building its own fresh `CSSStyleSheet()`
// per connect (no sharing across instances), so `adoptedStyleSheets` bought
// nothing here over the plain, universally-understood `<style>` tag. Reach
// for `adoptedStyleSheets` again only if a future component actually shares
// one parsed stylesheet object across many instances — that's the case it
// exists for.
export function attachShadowCss(host, cssText, shadowInit = {}) {
const root = host.attachShadow({ mode: "open", ...shadowInit });
const style = document.createElement("style");
style.textContent = cssText;
root.append(style);
return root;
}