diff --git a/frontend/packages/dashboard/build.mjs b/frontend/packages/dashboard/build.mjs index 35427bf0..7276a80a 100644 --- a/frontend/packages/dashboard/build.mjs +++ b/frontend/packages/dashboard/build.mjs @@ -74,9 +74,9 @@ await build({ target: ['es2022'], sourcemap: true, logLevel: 'info', - // `@hive/shared/modal.js` imports its shadow-DOM component CSS - // (hive-dialog.css, hive-toast.css, component-common.css) as raw text - // via a plain `import css from './foo.css'` — the `text` loader turns + // `@hive/shared/modal.js` and `hive-btn.js` import their shadow-DOM + // component CSS (hive-dialog.css, hive-toast.css, hive-btn.css) as raw + // text via a plain `import css from './foo.css'` — the `text` loader turns // that into a string constant at bundle time instead of erroring on an // unrecognised extension. None of these JS entries import a `.css` // file any other way, so this doesn't collide with the separate diff --git a/frontend/packages/shared/package.json b/frontend/packages/shared/package.json index cfd034d9..333bcd63 100644 --- a/frontend/packages/shared/package.json +++ b/frontend/packages/shared/package.json @@ -17,8 +17,7 @@ "./chrome.css": "./src/chrome.css", "./forms.js": "./src/forms.js", "./dom.js": "./src/dom.js", - "./modal.js": "./src/modal.js", - "./component-styles.js": "./src/component-styles.js" + "./modal.js": "./src/modal.js" }, "files": [ "src/" diff --git a/frontend/packages/shared/src/component-common.css b/frontend/packages/shared/src/component-common.css deleted file mode 100644 index 2cc892f0..00000000 --- a/frontend/packages/shared/src/component-common.css +++ /dev/null @@ -1,46 +0,0 @@ -/* component-common.css — the shared stylesheet adopted alongside every - shadow-DOM custom element's own scoped CSS (`adoptedStyleSheets`), the - native equivalent of a Sass `@include`. Loaded as raw text at build time - (esbuild's `text` loader — see build.mjs) and turned into a - `CSSStyleSheet` via `replaceSync()` in component-styles.js; a real .css - file, not a JS template string, so it gets normal editor tooling and - stays syntactically obvious as CSS. - - NOTE: `.btn` here is a near-duplicate of the app-wide `.btn` base rule - in dashboard/src/common.css and agent/src/agent.css, which already - differ slightly from each other. Shadow DOM can't see either — a - shadow component that wants the same button chrome needs its own copy, - so this is now a third copy. Picked dashboard's version (the fuller - one) as canonical for shadow components going forward. Unifying all - three into one source of truth is a separate follow-up (see - hyperhive's forge issue tracker: the `` component proposal), - not bundled into whichever component conversion first needed a - button. */ - -.btn { - font-family: inherit; - font-weight: bold; - text-transform: uppercase; - letter-spacing: 0.1em; - background: transparent; - -webkit-appearance: none; - appearance: none; - border: 1px solid; - padding: 0.25em 0.8em; - cursor: pointer; - text-shadow: 0 0 4px currentColor; - box-shadow: 0 0 0 0 currentColor; - transition: box-shadow 0.15s ease; -} -.btn:hover { - background: color-mix(in srgb, var(--fg) 6%, transparent); - text-shadow: 0 0 10px currentColor; - box-shadow: 0 0 10px -2px currentColor; -} -.btn:disabled, -.btn[disabled] { - opacity: 0.32; - cursor: not-allowed; - text-shadow: none; - box-shadow: none; -} diff --git a/frontend/packages/shared/src/component-styles.js b/frontend/packages/shared/src/component-styles.js deleted file mode 100644 index a488b36d..00000000 --- a/frontend/packages/shared/src/component-styles.js +++ /dev/null @@ -1,30 +0,0 @@ -// Shared, adopted-alongside-component-specific stylesheets for shadow-DOM -// custom elements — the native equivalent of a Sass `@include`: a -// `CSSStyleSheet` is parsed once and adopted by reference -// (`shadowRoot.adoptedStyleSheets = [sharedComponentStyleSheet(), ownSheet]`) -// into as many shadow roots as want it, rather than each component -// duplicating the rule text or re-fetching an external stylesheet. -// -// The CSS itself lives in `component-common.css` — a real stylesheet, not -// a JS template string — imported here as raw text via esbuild's `text` -// loader (see both packages' `build.mjs`) and turned into a -// `CSSStyleSheet` at module-init time. Component-scoped stylesheets -// (`hive-dialog.css`, `hive-toast.css` in modal.js) follow the same -// pattern. -// -// Start small: `.btn` is the one rule shadow-DOM components have needed so -// far (the dialog buttons in modal.js). Add more shared rules to -// component-common.css as more components need them — don't grow this -// into a full reset/utility layer preemptively. - -import componentCommonCss from './component-common.css'; - -let sheet = null; - -export function sharedComponentStyleSheet() { - if (!sheet) { - sheet = new CSSStyleSheet(); - sheet.replaceSync(componentCommonCss); - } - return sheet; -} diff --git a/frontend/packages/shared/src/dom.js b/frontend/packages/shared/src/dom.js index da314e69..b4b5f4ef 100644 --- a/frontend/packages/shared/src/dom.js +++ b/frontend/packages/shared/src/dom.js @@ -5,12 +5,18 @@ // used). // // `el(tag, attrs, ...children)` creates an element, applying `attrs` as -// either the `class`/`html` special cases or plain attributes, and +// either the `class`/`html`/`is` special cases or plain attributes, and // appending `children` (strings become text nodes, `null`/`undefined` // entries are skipped so callers can inline conditional children). +// `is: 'custom-name'` creates a customized built-in element (e.g. +// `el('button', { is: 'hive-btn' }, 'label')` → `