oficina / estilo Public

chrome.js: never publish a compact bar's measured height

Fable's delta review of 4757ccc, MEDIUM: the script published the measured
height of any stacked bar below 800px, compact ones included, so a
compact bar loaded below 704px (52px) and widened into the 704-799px band
stayed 52px tall instead of being the 56px header. A compact bar's height
is the CSS's own at every width, so the script now publishes only for a
stacked bar that is not compact. The browser check loads a compact bar at
650px, widens it to 768px and expects 52 then 56: 52 then 52 before this.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 21f9bc1d593241d21280d24629b891a98c8dda35 parent 4757ccc
4 files changed, +84 −2
  • chrome/chrome.js +6 −1
  • chrome/compact.browser.mjs +34 −1
  • chrome/compact_browser_test.go +41 −0
  • chrome/compact_test.go +3 −0
diff --git a/chrome/chrome.js b/chrome/chrome.js
index 0c3e7a3..a1918f0 100644
--- a/chrome/chrome.js
+++ b/chrome/chrome.js
@@ -146,7 +146,12 @@
// 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"]')
+ // Not a compact bar's: its height is the CSS's own at every width (52px
+ // as one row, 56px as the header from 704px), and a measure published
+ // while it was one row held it at 52px once widened into the 704-799px
+ // band, where it is the 56px header (Fable, on 4757ccc).
+ const stacked = Array.prototype.find.call(document.querySelectorAll('[estilo-bar~="stacked"]'),
+ (bar) => (' ' + bar.getAttribute('estilo-bar') + ' ').indexOf(' compact ') < 0)
const narrow = window.matchMedia && window.matchMedia('(max-width: 799.98px)')
if (stacked && narrow && typeof ResizeObserver === 'function') {
const root = document.documentElement
diff --git a/chrome/compact.browser.mjs b/chrome/compact.browser.mjs
index b765d3a..41ae1ff 100644
--- a/chrome/compact.browser.mjs
+++ b/chrome/compact.browser.mjs
@@ -55,7 +55,7 @@ function measure() {
back: shown(q('[estilo-bar-back]')), name: shown(q('[estilo-bar-name]')),
title: shown(input), lead: shown(q('[estilo-bar-lead]')), trail: shown(q('[estilo-bar-trail]')),
},
- boxes: { back: box(q('[estilo-bar-brand]')), title: box(q('[estilo-bar-title]')), end: box(q('[estilo-bar-end]')) },
+ boxes: { back: box(q('[estilo-bar-brand]')), title: box(q('[estilo-bar-title]')), end: box(q('[estilo-bar-end]')), menubar: box(q('[estilo-bar-menubar]')) },
ellipsis: getComputedStyle(input).textOverflow,
}
Array.prototype.filter.call(document.querySelectorAll('[estilo-bar-tool]'), shown).forEach((el, i) => { out.boxes['tool-' + i] = box(el) })
@@ -148,6 +148,39 @@ for (const engine of job.engines) {
result.cases.push({ name: c.name, width: c.w, touch: c.touch, error: String(e && e.message || e).split('\n')[0] })
}
}
+ // A compact bar loaded narrow and widened into the 704-800px band is
+ // the 56px header there; and in forced colours the band's controls
+ // keep the border the forced-colors rule gives them, as from 800px.
+ result.extra = {}
+ try {
+ const ctx = await browser.newContext({ viewport: { width: 650, height: 900 }, deviceScaleFactor: 2, hasTouch: true, isMobile: engine !== 'firefox' })
+ const page = await ctx.newPage()
+ await page.goto(`${job.origin}/?lang=en&scheme=light`, { waitUntil: 'load' })
+ await page.evaluate(() => document.fonts.ready)
+ const at650 = await page.evaluate(measure)
+ await page.setViewportSize({ width: 768, height: 1024 })
+ await page.waitForTimeout(300)
+ const at768 = await page.evaluate(measure)
+ result.extra.resized = { from: at650.header, header: at768.header, var: at768.var }
+ await ctx.close()
+ } catch (e) {
+ result.extra.resizedError = String(e && e.message || e).split('\n')[0]
+ }
+ result.extra.forced = {}
+ for (const w of [768, 1280]) {
+ try {
+ const ctx = await browser.newContext({ viewport: { width: w, height: 800 }, forcedColors: 'active' })
+ const page = await ctx.newPage()
+ await page.goto(`${job.origin}/?lang=en&scheme=light`, { waitUntil: 'load' })
+ result.extra.forced[w] = await page.evaluate(() => {
+ const el = document.querySelector('[estilo-bar-control~="primary"] > a')
+ return { border: parseFloat(getComputedStyle(el).borderTopWidth), forced: matchMedia('(forced-colors: active)').matches }
+ })
+ await ctx.close()
+ } catch (e) {
+ result.extra.forced[w] = { error: String(e && e.message || e).split('\n')[0] }
+ }
+ }
// Mapa and Fichas, as stand-ins: stacked bars with nav, not compact.
result.standIns = []
for (const kind of ['mapa', 'fichas']) {
diff --git a/chrome/compact_browser_test.go b/chrome/compact_browser_test.go
index b4bd925..4de60b5 100644
--- a/chrome/compact_browser_test.go
+++ b/chrome/compact_browser_test.go
@@ -165,6 +165,17 @@ type compactCase struct {
} `json:"public"`
} `json:"cases"`
StandIns []standInCase `json:"standIns"`
+ Extra struct {
+ Resized struct {
+ From, Header, Var float64
+ } `json:"resized"`
+ ResizedError string `json:"resizedError"`
+ Forced map[string]struct {
+ Border float64 `json:"border"`
+ Forced bool `json:"forced"`
+ Error string `json:"error"`
+ } `json:"forced"`
+ } `json:"extra"`
}
type largeTitle struct {
@@ -353,6 +364,10 @@ func TestTheCompactBarInRealEngines(t *testing.T) {
t.Errorf("%s: %s is shown from 44rem", where, hidden)
}
}
+ // The stack is the title over the menu row, never one row.
+ if ti, mb := c.Boxes["title"], c.Boxes["menubar"]; len(ti) != 4 || len(mb) != 4 || mb[1] < ti[1]+ti[3]/2 { // the title row sits 2.5px low by design
+ t.Errorf("%s: the title %v is not over the menu row %v", where, ti, mb)
+ }
for _, shown := range []string{"menubar", "actions", "account", "switcher", "icon"} {
if !c.Shown[shown] {
t.Errorf("%s: %s is not shown from 44rem", where, shown)
@@ -415,4 +430,30 @@ func TestTheCompactBarInRealEngines(t *testing.T) {
}
}
}
+ // A compact bar loaded below 704px and widened to 768px is the 56px
+ // header: the script must not hold it at the 52px it measured (Fable's
+ // delta review, item 1). And in forced colours the band's controls
+ // keep their border, as from 800px (item 2).
+ for _, r := range results {
+ if r.Error != "" {
+ continue
+ }
+ x := r.Extra
+ if x.ResizedError != "" {
+ t.Errorf("%s: the resize could not be driven: %s", r.Engine, x.ResizedError)
+ } else if x.Resized.From < 51.5 || x.Resized.From > 52.5 || x.Resized.Header < 55.5 || x.Resized.Header > 56.5 || x.Resized.Var < 55.5 || x.Resized.Var > 56.5 {
+ t.Errorf("%s: 650px then 768px: the bar went from %.1fpx to %.1fpx (publishing %.1f); want 52 then 56", r.Engine, x.Resized.From, x.Resized.Header, x.Resized.Var)
+ }
+ for _, w := range []string{"768", "1280"} {
+ f := x.Forced[w]
+ switch {
+ case f.Error != "":
+ t.Errorf("%s: forced colours at %s could not be driven: %s", r.Engine, w, f.Error)
+ case !f.Forced:
+ t.Errorf("%s: forced colours at %s were not emulated; the check is blind", r.Engine, w)
+ case f.Border < 1:
+ t.Errorf("%s: in forced colours at %spx the primary control's border is %.1fpx: it has no edge", r.Engine, w, f.Border)
+ }
+ }
+ }
}
diff --git a/chrome/compact_test.go b/chrome/compact_test.go
index eaf5b5c..9d24b6f 100644
--- a/chrome/compact_test.go
+++ b/chrome/compact_test.go
@@ -177,6 +177,9 @@ func TestTheScriptUsesTheCSSBreakpoints(t *testing.T) {
if !strings.Contains(js, "matchMedia('(max-width: 799.98px)')") {
t.Error("chrome.js no longer publishes the stacked bar's height below 800px")
}
+ if !strings.Contains(js, `(bar) => (' ' + bar.getAttribute('estilo-bar') + ' ').indexOf(' compact ') < 0)`) {
+ t.Error("chrome.js publishes a compact bar's measured height, which holds it at 52px past 704px")
+ }
css := string(CSS())
if !strings.Contains(css, narrowQuery+" {") || !strings.Contains(css, bandQuery+" {") {
t.Error("chrome.css does not use the compact pair")