oficina / estilo Public

chrome: publish a narrow stacked bar's real height; hang panels at 55px

Measured in Chromium and WebKit: below 800px the menu row wraps where
the menus do not fit (English at 320px), so the header is 117px, not
the 84px CSS publishes, and Docs' sticky strip would slide under it.
chrome.js now writes the header's real height to
--estilo-bar-block-size below 800px (ResizeObserver) and removes it
from 800px, where the header's height is the variable itself. 84px
stays the no-script value.

The stack is centred in the 55px inside the border, so the menu row
ends at 50.5; a panel at +4.5px starts at 55, 1px above the edge, as
the mock-up had it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 38da68f65ced92f553522b68e73ab4790e66f8e0 parent e74051f
4 files changed, +69 −9
  • chrome/chrome.css +4 −3
  • chrome/chrome.js +20 −0
  • chrome/chrome.test.mjs +44 −5
  • chrome/stack_test.go +1 −1

CI passed — run details

diff --git a/chrome/chrome.css b/chrome/chrome.css
index 2af42f8..4fb95fb 100644
--- a/chrome/chrome.css
+++ b/chrome/chrome.css
@@ -346,8 +346,9 @@
stays today's one row, and the app's menus are a full-width second
row under it: the stack dissolves and the same markup lays out on a
grid. The header grows by that row, and the published block size
- with it; a menubar that wraps (a long locale at 320px) grows it
- further, beyond what is published. */
+ with it. A menubar that wraps (English at 320px; a long locale
+ sooner) grows it further: chrome.js then publishes the header's real
+ height, and 84px is what a page without script gets. */
@media (max-width: 799.98px) {
:root:has([estilo-bar~="stacked"]) { --estilo-bar-block-size: calc(3.25rem + 2rem); } /* 84px: the bar's row and one menubar row. PUBLIC */
[estilo-bar~="stacked"] {
@@ -474,7 +475,7 @@
}
[estilo-bar~="stacked"] [estilo-menubar-title]:hover,
[estilo-bar~="stacked"] [open] > [estilo-menubar-title] { color: var(--rst-text); }
- [estilo-bar~="stacked"] [estilo-menubar-menu] > [estilo-menu] { inset-block-start: calc(100% + 4px); } /* 51 + 4: 1px above the 56px edge */
+ [estilo-bar~="stacked"] [estilo-menubar-menu] > [estilo-menu] { inset-block-start: calc(100% + 4.5px); } /* the row ends at 50.5 (the stack is centred in 55px inside the border): 55, 1px above the 56px edge */
/* Every panel in the stacked header matches it: 28px rows, 13px type,
shortcuts muted, 4px padding and a 10px radius. */
diff --git a/chrome/chrome.js b/chrome/chrome.js
index f12257c..b86c1ed 100644
--- a/chrome/chrome.js
+++ b/chrome/chrome.js
@@ -119,6 +119,26 @@
if (document.fonts && document.fonts.ready) document.fonts.ready.then(fitAll)
fitAll()
+ // Below 800px a stacked bar is the one-row bar with the app's menus as a
+ // second row, and that row wraps where the menus do not fit (English
+ // at 320px). CSS publishes the one-row-of-menus height; this publishes
+ // the header's real one, so whatever sticks under it (Docs' strip)
+ // sticks under all of it. Only below 800px: from there the header's
+ // height is the variable itself, and publishing its measure back would
+ // hold it at whatever it measured last.
+ const stacked = document.querySelector('[estilo-bar~="stacked"]')
+ const narrow = window.matchMedia && window.matchMedia('(max-width: 799.98px)')
+ if (stacked && narrow && typeof ResizeObserver === 'function') {
+ const root = document.documentElement
+ const publish = () => {
+ const h = stacked.getBoundingClientRect().height
+ if (narrow.matches && h > 0) root.style.setProperty('--estilo-bar-block-size', h + 'px')
+ else root.style.removeProperty('--estilo-bar-block-size')
+ }
+ new ResizeObserver(publish).observe(stacked)
+ if (narrow.addEventListener) narrow.addEventListener('change', publish)
+ }
+
// Appearance switches at once (Paul: "They're not doing an action ...
// they should just switch immediately"). The page takes the scheme as
// chrome.ThemeAttr writes it, data-theme="light" or "dark" on <html> and
diff --git a/chrome/chrome.test.mjs b/chrome/chrome.test.mjs
index 01ca9c0..caff96a 100644
--- a/chrome/chrome.test.mjs
+++ b/chrome/chrome.test.mjs
@@ -9,15 +9,17 @@ import vm from "node:vm";
const src = fs.readFileSync(new URL("./chrome.js", import.meta.url), "utf8");
-// A compound selector: tag, [attr] and [attr="value"], comma-separated.
+// A compound selector: tag, [attr], [attr="value"] and [attr~="token"],
+// comma-separated.
function matches(el, selector) {
return selector.split(",").some((part) => {
const m = part.trim().match(/^([a-z]*)((?:\[[^\]]+\])*)$/);
if (!m) throw new Error("unsupported selector " + part);
if (m[1] && el.tag !== m[1]) return false;
- for (const [, name, value] of m[2].matchAll(/\[([^=\]]+)(?:="([^"]*)")?\]/g)) {
+ for (const [, name, op, value] of m[2].matchAll(/\[([^~=\]]+)(?:(~?=)"([^"]*)")?\]/g)) {
if (!el.attrs.has(name)) return false;
- if (value !== undefined && el.attrs.get(name) !== value) return false;
+ if (op === "=" && el.attrs.get(name) !== value) return false;
+ if (op === "~=" && !el.attrs.get(name).split(/\s+/).includes(value)) return false;
}
return true;
});
@@ -60,14 +62,14 @@ function load(root, globals = {}) {
const winListeners = [];
doc = {
activeElement: null,
- documentElement: new El("html"),
+ documentElement: Object.assign(new El("html"), { style: fakeStyle() }),
fonts: globals.fonts,
querySelector: (s) => root.querySelector(s),
querySelectorAll: (s) => root.querySelectorAll(s),
getElementById: () => null,
addEventListener: (type, fn, capture) => listeners.push({ type, fn, capture: !!capture }),
};
- const window = { addEventListener: (type, fn) => winListeners.push({ type, fn }) };
+ const window = { addEventListener: (type, fn) => winListeners.push({ type, fn }), matchMedia: globals.matchMedia };
vm.runInNewContext(src, {
document: doc,
window,
@@ -76,6 +78,7 @@ function load(root, globals = {}) {
fetch: globals.fetch ?? (() => Promise.resolve()),
FormData: globals.FormData ?? FakeFormData,
URLSearchParams,
+ ResizeObserver: globals.ResizeObserver,
});
const dispatch = (type, target, init = {}) => {
const e = { type, target, defaultPrevented: false, preventDefault() { this.defaultPrevented = true; }, ...init };
@@ -87,6 +90,11 @@ function load(root, globals = {}) {
return dispatch;
}
+function fakeStyle() {
+ const props = new Map();
+ return { props, setProperty: (k, v) => props.set(k, v), removeProperty: (k) => props.delete(k), getPropertyValue: (k) => props.get(k) ?? "" };
+}
+
// new FormData(form): the form's named inputs, as a submit sends them
// (never its buttons; the submitter is the script's to add).
class FakeFormData {
@@ -254,3 +262,34 @@ test("any other form, or a submit already handled, posts as it always has", () =
assert.equal(dispatch("submit", form, {}).defaultPrevented, false);
assert.equal(fetched, 0);
});
+
+// A stacked bar below 800px whose menu row wraps is taller than the 84px
+// CSS publishes; the script publishes its real height there, and stands
+// down from 800px, where the header's height is the variable itself.
+test("below 800px a stacked bar publishes its real height", () => {
+ const header = new El("header", { "estilo-bar": "stacked" });
+ let height = 117;
+ header.getBoundingClientRect = () => ({ height });
+ const media = { matches: true, listeners: [], addEventListener(t, fn) { this.listeners.push(fn); } };
+ let observed = null;
+ class RO { constructor(fn) { this.fn = fn; } observe(el) { observed = { el, fn: this.fn }; } }
+ load(new El("", {}, [header]), { matchMedia: () => media, ResizeObserver: RO });
+ assert.equal(observed.el, header);
+ observed.fn();
+ const style = doc.documentElement.style;
+ assert.equal(style.getPropertyValue("--estilo-bar-block-size"), "117px");
+ height = 85;
+ observed.fn();
+ assert.equal(style.getPropertyValue("--estilo-bar-block-size"), "85px");
+ // Wide: the CSS value stands, with nothing written over it.
+ media.matches = false;
+ for (const fn of media.listeners) fn();
+ assert.equal(style.props.has("--estilo-bar-block-size"), false);
+});
+
+test("a bar that is not stacked publishes nothing", () => {
+ let observed = false;
+ class RO { observe() { observed = true; } }
+ load(new El("", {}, [new El("header", { "estilo-bar": "sticky" })]), { matchMedia: () => ({ matches: true }), ResizeObserver: RO });
+ assert.equal(observed, false);
+});
diff --git a/chrome/stack_test.go b/chrome/stack_test.go
index 33b0195..865eff6 100644
--- a/chrome/stack_test.go
+++ b/chrome/stack_test.go
@@ -278,7 +278,7 @@ func TestTheStackedBarPublishesItsHeight(t *testing.T) {
`@media \(max-width: 63\.99rem\) \{\s*\[estilo-bar-actions\] \[estilo-bar-wide\],\s*\[estilo-bar-actions\] \[estilo-bar-control~="wide"\] \{ display: none; \}`,
`\[estilo-bar~="stacked"\] \[estilo-menubar\] \{[^}]*min-block-size: 0;`,
`\[estilo-bar~="stacked"\] \[estilo-bar-brand\] img \{ inline-size: 32px; block-size: 32px; \}`,
- `\[estilo-bar~="stacked"\] \[estilo-menubar-menu\] > \[estilo-menu\] \{ inset-block-start: calc\(100% \+ 4px\); \}`,
+ `\[estilo-bar~="stacked"\] \[estilo-menubar-menu\] > \[estilo-menu\] \{ inset-block-start: calc\(100% \+ 4\.5px\); \}`,
} {
if !regexp.MustCompile(re).MatchString(src) {
t.Errorf("chrome.css lacks %s", re)