The Colophon and the Drive chooser on the spacing scale
The app rollout of Fiesta's stack found two pieces of estilo chrome off the scale (Paul approved the release and rollout, 2026-11-22): - credits.css: the Colophon (estilo/credits, /help/open-source) is a stack on estilo's terms, as the door's card is: a column whose children's block margins are reset at (0,2,0), so an app's own rule on the heading cannot bring a margin back; the list --rst-sp-2 under its heading (was the browser's 18.8px); an open entry's blocks --rst-sp-3 apart and a notice's text --rst-sp-2 under its name (were 14px). - googleimport: the chooser gets its own stylesheet, CSS(): Choose --rst-sp-4 under the disclosure, Cancel --rst-sp-2 under Choose (the door's rule for a button under another action), the status --rst-sp-3 under the buttons; margins, so a hidden button or an empty status takes no space. Apps link it and drop their own [estilo-google-import] rules (README, CSS()). - The rhythm drive audits the Colophon (closed, with an app heading rule; and an open entry from its own root) and the chooser (ready, idle, busy), and holds their gaps; each fails on main's CSS. Its rhythm.js is Fiesta v1.7.0's, and make test-spacing runs v1.7.0. Review: Fable, two rounds (2 Medium + 5 Low, then 2 Low fixed; one Low a state the script never reaches). make test and the browser suite pass in Chromium and WebKit; hub CI green at 55e6bce. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from colophon-drive-stack into main.
10 files changed,
+358
−47
Makefile+1 −1chrome/rhythm.browser.mjs+8 −5chrome/rhythm_browser_test.go+137 −19chrome/testdata/rhythm.js+124 −20credits/credits.css+16 −1credits/credits_test.go+19 −0googleimport/README.md+7 −1googleimport/google-import.css+18 −0googleimport/googleimport.go+12 −0googleimport/googleimport_test.go+16 −0
CI passed — run details
CI log
=== modcache === all modules verified === vet === CGO_ENABLED=0 go vet ./... CGO_ENABLED=0 go vet -tags browser ./... === fmt === === build === CGO_ENABLED=0 go build -buildvcs=false ./... === go-test === CGO_ENABLED=0 go test -count=1 ./... ok amadan.net/oficina/estilo.git/base 0.004s ok amadan.net/oficina/estilo.git/brand 0.004s ok amadan.net/oficina/estilo.git/busy 0.008s ok amadan.net/oficina/estilo.git/callui 0.005s ok amadan.net/oficina/estilo.git/chrome 1.030s ? amadan.net/oficina/estilo.git/cmd/oficina-notices [no test files] ok amadan.net/oficina/estilo.git/colophon 0.020s ok amadan.net/oficina/estilo.git/credits 0.006s ok amadan.net/oficina/estilo.git/credits/catalog 0.005s ok amadan.net/oficina/estilo.git/desk 0.005s ok amadan.net/oficina/estilo.git/googleimport 0.166s ok amadan.net/oficina/estilo.git/homeconnect 0.005s ok amadan.net/oficina/estilo.git/internal/lint 0.009s ? amadan.net/oficina/estilo.git/internal/tokencheck [no test files] ok amadan.net/oficina/estilo.git/menu 0.010s ok amadan.net/oficina/estilo.git/savestatus 0.107s ok amadan.net/oficina/estilo.git/side 0.141s ok amadan.net/oficina/estilo.git/sky 0.032s ok amadan.net/oficina/estilo.git/theme 0.013s === spacing === go run amadan.net/rastrillo/fiesta/cmd/fiesta@v1.7.0 spacing . go: downloading amadan.net/rastrillo/fiesta v1.7.0
landed from colophon-drive-stack
diff --git a/Makefile b/Makefile| index 945ee8d..3715240 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -76,7 +76,7 @@ test-go: |
| # require or a tool directive: estilo is imported by every app, and a |
| # Fiesta requirement here would join their module graphs and move the |
| # Fiesta their rastrillo was built against. |
| -FIESTA_VERSION := v1.6.0 |
| +FIESTA_VERSION := v1.7.0 |
| test-spacing: |
| go run amadan.net/rastrillo/fiesta/cmd/fiesta@$(FIESTA_VERSION) spacing . |
diff --git a/chrome/rhythm.browser.mjs b/chrome/rhythm.browser.mjs| index c9d7c95..c690fb0 100644 |
| --- a/chrome/rhythm.browser.mjs |
| +++ b/chrome/rhythm.browser.mjs |
| @@ -7,12 +7,14 @@ |
| // ESTILO_PLAYWRIGHT=<path to the playwright package> \ |
| // node rhythm.browser.mjs <job JSON> |
| // |
| -// Job: {origin, engines, viewports, pages, root, script, sizes, gaps, |
| -// shots}. Output: one entry per engine, {engine, version, error, pages: |
| +// Job: {origin, engines, viewports, pages, root, roots, script, sizes, |
| +// gaps, shots}; roots names a page's own root where it is not root. |
| +// Output: one entry per engine, {engine, version, error, pages: |
| // [{page, viewport, findings, sizes, gaps}]}: sizes is each selector's |
| // [width, height] and gaps the space above it from its previous |
| -// sibling, or null where the page has no such element. With shots set to a directory, each page is |
| -// also saved there as <engine>-<viewport>-<page>.png. |
| +// sibling, or null where the page has no such element. With shots set |
| +// to a directory, each page is also saved there as |
| +// <engine>-<viewport>-<page>.png. |
| import { createRequire } from 'node:module' |
| const require = createRequire(import.meta.url) |
| @@ -31,7 +33,8 @@ for (const engine of job.engines) { |
| for (const name of job.pages) { |
| await page.goto(job.origin + '/' + name) |
| await page.evaluate(() => document.fonts.ready) |
| - const findings = await page.evaluate(([script, root]) => (0, eval)(script)(root, {}), [job.script, job.root]) |
| + const root = (job.roots && job.roots[name]) || job.root |
| + const findings = await page.evaluate(([script, root]) => (0, eval)(script)(root, {}), [job.script, root]) |
| const sizes = await page.evaluate((sels) => Object.fromEntries(sels.map((s) => { |
| const el = document.querySelector(s) |
| const r = el ? el.getBoundingClientRect() : null |
diff --git a/chrome/rhythm_browser_test.go b/chrome/rhythm_browser_test.go| index cd95bf3..8d7cb0f 100644 |
| --- a/chrome/rhythm_browser_test.go |
| +++ b/chrome/rhythm_browser_test.go |
| @@ -1,13 +1,20 @@ |
| //go:build browser |
| // The door's rhythm, measured: Fiesta's rhythm audit (its check/rhythm, |
| -// v1.6.0, copied into testdata/rhythm.js because estilo does not require |
| +// v1.7.0, copied into testdata/rhythm.js because estilo does not require |
| // Fiesta; see the Makefile's test-spacing) over the card of every door |
| -// page, in real engines, on a desktop and a phone. It reports two blocks |
| -// whose gap is not a step of the spacing scale, text and a control less |
| -// than --rst-sp-2 apart, and a heading no closer to its content than to |
| -// what comes before it. Not part of `make test`: it needs Node 22+ and |
| -// Playwright (ESTILO_PLAYWRIGHT, ESTILO_BROWSERS as for the title check). |
| +// page, the Colophon and the Google Drive chooser, in real engines, on a |
| +// desktop and a phone. It reports two blocks whose gap is not a step of |
| +// the spacing scale, text and a control less than --rst-sp-2 apart, a |
| +// heading no closer to its content than to what comes before it, and a |
| +// stack (rst-stack) bent out of its column or holding a fixed or |
| +// absolute child it does not pass over; none of these pages is an |
| +// rst-stack, so the last two have nothing to find here. It does not read |
| +// past a closed <details>' summary, nor into a list (a text block), so |
| +// an open Colophon entry is audited from its own root. |
| +// |
| +// Not part of `make test`: it needs Node 22+ and Playwright |
| +// (ESTILO_PLAYWRIGHT, ESTILO_BROWSERS as for the title check). |
| // ESTILO_SHOTS=<dir> saves each page there to look at. |
| package chrome |
| @@ -15,6 +22,7 @@ import ( |
| "bytes" |
| "encoding/json" |
| "fmt" |
| + "html/template" |
| "net/http" |
| "net/http/httptest" |
| "os" |
| @@ -23,6 +31,8 @@ import ( |
| "testing" |
| "amadan.net/oficina/estilo.git/base" |
| + "amadan.net/oficina/estilo.git/credits" |
| + "amadan.net/oficina/estilo.git/googleimport" |
| "amadan.net/oficina/estilo.git/theme" |
| "github.com/carlosframework/rastrillo/ui" |
| ) |
| @@ -37,6 +47,8 @@ const doorPage = `<!doctype html> |
| <link rel="stylesheet" href="/base.css"> |
| <link rel="stylesheet" href="/brand.css"> |
| <link rel="stylesheet" href="/chrome.css"> |
| +<link rel="stylesheet" href="/credits.css"> |
| +<link rel="stylesheet" href="/google-import.css"> |
| </head> |
| <body> |
| <main id="main" rst-page> |
| @@ -108,14 +120,102 @@ var openGaps = map[string]float64{ |
| "#door-button": 16, // before a button |
| } |
| +// colophon renders estilo's Colophon (credits) with two entries, one |
| +// with its source and notices; open, every entry is open, as a reader |
| +// who opened them sees it. Closed, the page also carries an app's own |
| +// margin on the heading, which must not reach it. |
| +func colophon(t *testing.T, open bool) string { |
| + t.Helper() |
| + tpl := template.Must(template.ParseFS(credits.Templates(), "templates/*.html")) |
| + var out bytes.Buffer |
| + data := credits.PageData{Title: "Open source", MissingNoticeLabel: "No notice was found.", Components: []credits.Component{ |
| + {Name: "example.org/first", Version: "v1.2.3", SourceURL: "https://example.org/first", Notices: []credits.Notice{{Name: "LICENSE", Text: "Copyright the authors.\nPermission is granted."}, {Name: "NOTICE", Text: "Built with care."}}}, |
| + {Name: "example.org/second"}, |
| + }} |
| + if err := tpl.ExecuteTemplate(&out, "estilo/credits", data); err != nil { |
| + t.Fatal(err) |
| + } |
| + html := out.String() |
| + if !open { |
| + // An app's own rule on the heading, as Mapa's frame.css wrote |
| + // one before estilo spaced the Colophon: the stack outweighs it. |
| + html = `<style>[estilo-credits] > h1 { margin: 0 0 var(--rst-sp-2); } [estilo-credits] > ul { margin: 0; }</style>` + html |
| + } |
| + if open { |
| + html = strings.ReplaceAll(html, "<details>", "<details open>") |
| + } |
| + return html |
| +} |
| + |
| +// colophonGaps is the space above each of the Colophon's blocks: the |
| +// list --rst-sp-2 under its heading, and in an open entry its source |
| +// --rst-sp-3 under the summary, a notice's name --rst-sp-3 under what |
| +// is above it, and the notice's text --rst-sp-2 under its name. |
| +var colophonGaps = map[string]float64{ |
| + "[estilo-credits] > ul": 8, |
| + "[estilo-credits] li:first-child details > p": 12, |
| + "[estilo-credits] li:first-child details > pre": 8, |
| + "[estilo-credits] li:first-child details > p + pre + p": 12, |
| +} |
| + |
| +// chooser renders the Google Drive chooser as its script leaves it: |
| +// ready, the Choose button shown and the status empty; idle, the status |
| +// saying something under Choose (a refusal, or what was imported); |
| +// busy, Cancel under Choose and the status saying what is happening. |
| +func chooser(t *testing.T, state string) string { |
| + t.Helper() |
| + tpl := template.Must(template.New("root").Parse(googleimport.Template())) |
| + var out bytes.Buffer |
| + view := googleimport.View{Config: googleimport.Config{ClientID: "123456789-client.apps.googleusercontent.com", APIKey: "AIzaPublicBrowserKey123456789", AppID: "123456789"}, Kind: googleimport.Docs, FormID: "upload", InputID: "file", Labels: googleimport.Text("en")} |
| + if err := tpl.ExecuteTemplate(&out, "estilo-google-import", view); err != nil { |
| + t.Fatal(err) |
| + } |
| + html := strings.Replace(out.String(), "<span data-google-choose-wrap hidden>", "<span data-google-choose-wrap>", 1) |
| + switch state { |
| + case "busy": |
| + html = strings.Replace(html, "<span data-google-cancel-wrap hidden>", "<span data-google-cancel-wrap>", 1) |
| + html = strings.Replace(html, `aria-live="polite"></p>`, `aria-live="polite">Connecting to Google…</p>`, 1) |
| + case "idle": |
| + html = strings.Replace(html, `aria-live="polite"></p>`, `aria-live="polite">That file is too large to import.</p>`, 1) |
| + } |
| + return html |
| +} |
| + |
| +// chooserGaps is the space above each of the chooser's blocks: Choose |
| +// --rst-sp-4 under the disclosure, Cancel --rst-sp-2 under Choose, the |
| +// status --rst-sp-3 under the buttons. |
| +var chooserGaps = map[string]float64{ |
| + "[data-google-choose-wrap]": 16, |
| + "[data-google-cancel-wrap]": 8, |
| + "[data-google-status]": 12, |
| +} |
| + |
| +// chooserIdleGaps is the resting chooser: the status --rst-sp-3 under |
| +// Choose, past the hidden Cancel. |
| +var chooserIdleGaps = map[string]float64{ |
| + "[data-google-choose-wrap]": 16, |
| + "[data-google-status]": 12, |
| +} |
| + |
| func openGapNames() []string { |
| var names []string |
| - for id := range openGaps { |
| - names = append(names, id) |
| + for _, gaps := range []map[string]float64{openGaps, colophonGaps, chooserGaps} { |
| + for id := range gaps { |
| + names = append(names, id) |
| + } |
| } |
| return names |
| } |
| +// pageGaps is the table each page is held to, by page. |
| +var pageGaps = map[string]map[string]float64{ |
| + "open": openGaps, |
| + "colophon": {"[estilo-credits] > ul": 8}, |
| + "colophon-open": colophonGaps, |
| + "chooser-busy": chooserGaps, |
| + "chooser-idle": chooserIdleGaps, |
| +} |
| + |
| // doorPages is every page the door draws, with the states that change |
| // what the card holds (a lede, an error, the notices), and an app's own |
| // card drawn through estilo-door-open, holding every relation of the |
| @@ -139,9 +239,27 @@ func doorPages(t *testing.T) map[string]string { |
| "sent": render(t, "estilo-signin-sent", sent), |
| "signed-out": render(t, "estilo-signed-out", out), |
| "open": openCard(t), |
| + // Not door pages, but chrome every app draws: the Colophon under |
| + // Help and the Google Drive chooser, each audited from its own |
| + // root (pageRoots). |
| + "colophon": colophon(t, false), |
| + "colophon-open": colophon(t, true), |
| + "chooser-ready": chooser(t, "ready"), |
| + "chooser-idle": chooser(t, "idle"), |
| + "chooser-busy": chooser(t, "busy"), |
| } |
| } |
| +// pageRoots is the root each page that is not a door card is audited |
| +// from; a door card is audited from [estilo-signin]. |
| +var pageRoots = map[string]string{ |
| + "colophon": "[estilo-credits]", |
| + "colophon-open": "[estilo-credits] li:first-child details", |
| + "chooser-idle": "[estilo-google-import]", |
| + "chooser-ready": "[estilo-google-import]", |
| + "chooser-busy": "[estilo-google-import]", |
| +} |
| + |
| func TestTheDoorKeepsTheRhythm(t *testing.T) { |
| if _, err := exec.LookPath("node"); err != nil { |
| t.Fatal("node is required (Node 22+)") |
| @@ -160,7 +278,7 @@ func TestTheDoorKeepsTheRhythm(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - assets := map[string][]byte{"/tokens.css": ui.TokensCSS(), "/theme.css": theme.CSS(), "/base.css": base.CSS(), "/brand.css": brandCSS, "/chrome.css": CSS()} |
| + assets := map[string][]byte{"/tokens.css": ui.TokensCSS(), "/theme.css": theme.CSS(), "/base.css": base.CSS(), "/brand.css": brandCSS, "/chrome.css": CSS(), "/credits.css": credits.CSS(), "/google-import.css": googleimport.CSS()} |
| for path, body := range assets { |
| mux.HandleFunc("GET "+path, func(w http.ResponseWriter, r *http.Request) { |
| w.Header().Set("Content-Type", "text/css; charset=utf-8") |
| @@ -188,7 +306,7 @@ func TestTheDoorKeepsTheRhythm(t *testing.T) { |
| } |
| job, _ := json.Marshal(map[string]any{ |
| "origin": srv.URL, "engines": engines, "viewports": []int{1440, 390}, |
| - "pages": names, "root": "[estilo-signin]", "script": string(script), |
| + "pages": names, "root": "[estilo-signin]", "roots": pageRoots, "script": string(script), |
| "sizes": []string{"#door-img", "#door-button"}, |
| "gaps": openGapNames(), |
| "shots": os.Getenv("ESTILO_SHOTS"), |
| @@ -222,6 +340,15 @@ func TestTheDoorKeepsTheRhythm(t *testing.T) { |
| if report.Len() > 0 { |
| t.Errorf("%s %s, %s at %dpx:%s", r.Engine, r.Version, p.Page, p.Viewport, report.String()) |
| } |
| + for id, want := range pageGaps[p.Page] { |
| + got := p.Gaps[id] |
| + switch { |
| + case got == nil: |
| + t.Errorf("%s, %s's %s at %dpx: not measured", r.Engine, p.Page, id, p.Viewport) |
| + case *got < want-0.5 || *got > want+0.5: |
| + t.Errorf("%s, %s's %s at %dpx: %.1fpx above it, want %vpx", r.Engine, p.Page, id, p.Viewport, *got, want) |
| + } |
| + } |
| if p.Page != "open" { |
| continue |
| } |
| @@ -233,15 +360,6 @@ func TestTheDoorKeepsTheRhythm(t *testing.T) { |
| if b := p.Sizes["#door-button"]; len(b) != 2 || b[0] > 200 { |
| t.Errorf("%s, the card's lone button at %dpx is %v wide: stretched across the card", r.Engine, p.Viewport, b) |
| } |
| - for id, want := range openGaps { |
| - got := p.Gaps[id] |
| - switch { |
| - case got == nil: |
| - t.Errorf("%s, the card's %s at %dpx: not measured", r.Engine, id, p.Viewport) |
| - case *got < want-0.5 || *got > want+0.5: |
| - t.Errorf("%s, the card's %s at %dpx: %.1fpx above it, want %vpx", r.Engine, id, p.Viewport, *got, want) |
| - } |
| - } |
| } |
| } |
| } |
diff --git a/chrome/testdata/rhythm.js b/chrome/testdata/rhythm.js| index 7a6ce38..7167b1c 100644 |
| --- a/chrome/testdata/rhythm.js |
| +++ b/chrome/testdata/rhythm.js |
| @@ -1,16 +1,26 @@ |
| // Fiesta's rhythm audit: the runtime half of the spacing rule |
| -// (DESIGN.md, "Spacing"). It walks a page's content as the browser laid |
| -// it out and reports three things a reader sees and a stylesheet check |
| -// cannot: |
| +// (DESIGN.md, "Checking the rhythm"). It walks a page's content as the |
| +// browser laid it out and reports what a reader sees and a stylesheet |
| +// check cannot: |
| // |
| -// off-scale two blocks, one under the other, whose gap is not a |
| -// step of the spacing scale (0, or --rst-sp-1 to 6); |
| -// touching text directly above or below a control (a button, a |
| -// field, a disclosure) with less than --rst-sp-2 between, |
| -// unless the text is the control's own <label>; |
| -// heading a heading further from its own content than it is from |
| -// what comes before it, so it reads as belonging to the |
| -// block above. |
| +// off-scale two blocks, one under the other, whose gap is not a |
| +// step of the spacing scale (0, or --rst-sp-1 to 6); |
| +// touching text directly above or below a control (a button, a |
| +// field, a disclosure) with less than --rst-sp-2 |
| +// between, unless the text is the control's own <label>; |
| +// heading a heading further from its own content than it is |
| +// from what comes before it, so it reads as belonging to |
| +// the block above (a heading whose content opens with a |
| +// heading or a section is not held to it: the one that |
| +// follows takes its own opening, and is held instead); |
| +// bent a stack (rst-stack) that an app's own rule has made |
| +// something other than the stack's column: its display, |
| +// flex-direction, flex-wrap, align-items or gap is not |
| +// the stack's, which its margins are measured against; |
| +// out-of-flow a stack's child that is absolute or fixed and that the |
| +// stack does not pass over (rst-stack-out, the modal |
| +// overlay, .rst-sr-only, a dialog, a popover), so the stack gives it a margin or |
| +// reads it as the block before the next. |
| // |
| // It is one function expression, evaluated in the page: the Go package |
| // beside it wraps it as rhythm.Expression for a chromedp drive, and |
| @@ -21,14 +31,24 @@ |
| // holds blocks, except Fiesta's components (an element carrying an |
| // rst- name other than the layout ones), whose insides are Fiesta's to |
| // space and its own gates to check, text blocks (p, headings, lists, |
| -// tables, pre), controls, and whatever options.skip names. |
| +// tables, pre), controls, whatever options.skip names, and the content |
| +// of a closed <details>, which shows only its summary. The two stack |
| +// checks read every stack under the root, components' included, but |
| +// none in a skipped region or a closed <details>. |
| +// |
| +// It returns the findings. With options.result true it returns |
| +// { findings, pairs, headings, stacks } instead: the findings and how |
| +// much it read, the pairs of neighbouring blocks it measured, the |
| +// headings it held to the heading rule and the stacks it checked, so a |
| +// test can tell a page that passed from one it barely saw. |
| (function fiestaRhythm(root, options) { |
| options = options || {}; |
| var tolerance = typeof options.tolerance === "number" && options.tolerance > 0 ? options.tolerance : 0.5; |
| var skip = options.skip || []; |
| var start = typeof root === "string" ? document.querySelector(root) : root; |
| if (!start) { |
| - return [{ kind: "missing", gap: 0, before: "", after: "", message: "no element matches " + root }]; |
| + var missing = [{ kind: "missing", gap: 0, before: "", after: "", message: "no element matches " + root }]; |
| + return options.result ? { findings: missing, pairs: 0, headings: 0, stacks: 0 } : missing; |
| } |
| var htmlStyle = getComputedStyle(document.documentElement); |
| @@ -92,6 +112,22 @@ |
| return !!headingTags[el.tagName] || el.getAttribute("role") === "heading"; |
| } |
| + function opensSection(el) { |
| + return el.hasAttribute("rst-section") || el.classList.contains("rst-section"); |
| + } |
| + |
| + // closed is a <details> that is shut: of its children only the |
| + // summary is shown, and the rest is not the page's to measure. |
| + function closed(el) { |
| + return el.tagName === "DETAILS" && !el.open; |
| + } |
| + |
| + // shows says whether a child of parent is drawn as far as a closed |
| + // <details> goes. |
| + function shows(parent, child) { |
| + return !closed(parent) || child.tagName === "SUMMARY"; |
| + } |
| + |
| function shown(el) { |
| var style = getComputedStyle(el); |
| if (style.display === "none" || style.visibility === "hidden") return false; |
| @@ -110,6 +146,7 @@ |
| function flow(container) { |
| var out = []; |
| for (var el = container.firstElementChild; el; el = el.nextElementSibling) { |
| + if (!shows(container, el)) continue; |
| var style = getComputedStyle(el); |
| if (style.display === "contents") { |
| if (skipped(el) || isComponent(el)) { |
| @@ -151,12 +188,12 @@ |
| for (var k = 0; k < nodes.length; k++) { |
| var node = nodes[first ? k : nodes.length - 1 - k]; |
| if (node.nodeType === 3) { |
| - if (node.textContent.trim() === "") continue; |
| + if (closed(el) || node.textContent.trim() === "") continue; |
| var box = lineBox(node); |
| if (box) return { kind: "text", node: node, box: box }; |
| continue; |
| } |
| - if (node.nodeType !== 1) continue; |
| + if (node.nodeType !== 1 || !shows(el, node)) continue; |
| var style = getComputedStyle(node); |
| if (style.display === "none" || style.visibility === "hidden") continue; |
| var found = edge(node, first); |
| @@ -213,7 +250,7 @@ |
| return { el: el, top: r.top, bottom: r.bottom }; |
| } |
| var text = !!textTags[el.tagName]; |
| - for (var n = el.firstChild; n && !text; n = n.nextSibling) { |
| + for (var n = el.firstChild; n && !text && !closed(el); n = n.nextSibling) { |
| if (n.nodeType === 3 && n.textContent.trim() !== "") text = true; |
| } |
| var kids = text ? [] : flow(el); |
| @@ -245,6 +282,8 @@ |
| var lastChildOf = new Map(); |
| var excludedBefore = new Set(); |
| var headings = []; |
| + var pairs = 0; |
| + var held = 0; |
| function walk(container) { |
| var kids = flow(container); |
| @@ -266,6 +305,7 @@ |
| var stacked = rb.top >= ra.bottom - tolerance && rb.left < ra.right && ra.left < rb.right; |
| if (!stacked || skipped(a) || skipped(b)) return; |
| var gap = rb.top - ra.bottom; |
| + pairs++; |
| gapBefore.set(b, { gap: gap, from: a }); |
| nextOf.set(a, b); |
| if (!onScale(gap)) { |
| @@ -309,12 +349,18 @@ |
| // after is the block a heading's content starts with and the space |
| // to it: its next block, or, when it ends a wrapper (a header |
| - // holding only the heading), the block after the wrapper. |
| + // holding only the heading), the block after the wrapper. It is null |
| + // when that content opens with a heading or a section: a heading or |
| + // a section after a heading takes its own opening (DESIGN.md, "The |
| + // stack"), and the heading that follows is held to its content. |
| function after(h) { |
| for (var at = h; at && at !== start; at = lastChildOf.get(at)) { |
| if (nextOf.has(at)) { |
| - var next = content(nextOf.get(at), true); |
| - return next ? { el: next.el, gap: next.top - h.getBoundingClientRect().bottom } : null; |
| + var block = nextOf.get(at); |
| + if (isHeading(block) || opensSection(block)) return null; |
| + var next = content(block, true); |
| + if (!next || isHeading(next.el)) return null; |
| + return { el: next.el, gap: next.top - h.getBoundingClientRect().bottom }; |
| } |
| if (!lastChildOf.has(at)) return null; |
| } |
| @@ -340,6 +386,7 @@ |
| if (open === null) return; |
| if (open === undefined) open = opening[h.tagName]; |
| if (open === undefined) return; |
| + held++; |
| if (next.gap >= open - tolerance) { |
| findings.push({ |
| kind: "heading", gap: round(next.gap), before: describe(h), after: describe(next.el), |
| @@ -348,5 +395,62 @@ |
| }); |
| } |
| }); |
| - return findings; |
| + |
| + // The stacks under the root, the root included, that are drawn and |
| + // the page's: none in a skipped region or a closed <details>. |
| + function outside(el) { |
| + if (el.closest("details:not([open]) > :not(summary)")) return true; |
| + for (var at = el; at; at = at === start ? null : at.parentElement) { |
| + if (skipped(at)) return true; |
| + } |
| + return false; |
| + } |
| + var stackSel = "[rst-stack], .rst-stack"; |
| + var stacks = Array.prototype.slice.call(start.querySelectorAll(stackSel)); |
| + if (start.matches(stackSel)) stacks.unshift(start); |
| + stacks = stacks.filter(function (el) { |
| + return el.getClientRects().length > 0 && getComputedStyle(el).visibility !== "hidden" && !outside(el); |
| + }); |
| + |
| + // passedOver is what the stack's own rules pass over (tokens.css): |
| + // not drawn, or marked as out of the column. Each spelling of the |
| + // stack passes over its own spelling of the marks, so a child is |
| + // passed over only if every spelling the stack carries passes it: |
| + // under class="rst-stack", [rst-stack-out] still takes the margin. |
| + var passed = ', .rst-sr-only, dialog, [popover], script, style, template'; |
| + var passedBy = { |
| + attr: '[hidden], [type="hidden"], [rst-stack-out], [rst-modal-overlay]' + passed, |
| + cls: '[hidden], [type="hidden"], .rst-stack-out, .rst-modal-overlay' + passed |
| + }; |
| + function passedOver(stack, child) { |
| + if (stack.hasAttribute("rst-stack") && !child.matches(passedBy.attr)) return false; |
| + if (stack.classList.contains("rst-stack") && !child.matches(passedBy.cls)) return false; |
| + return true; |
| + } |
| + stacks.forEach(function (stack) { |
| + var s = getComputedStyle(stack); |
| + var gap = parseFloat(s.rowGap); |
| + if (s.display !== "flex" || s.flexDirection !== "column" || s.flexWrap !== "nowrap" || |
| + (s.alignItems !== "normal" && s.alignItems !== "stretch") || !(Math.abs(gap - scale[2]) <= tolerance)) { |
| + findings.push({ |
| + kind: "bent", gap: isNaN(gap) ? 0 : round(gap), before: describe(stack), after: "", |
| + message: "a stack is " + s.display + ", " + s.flexDirection + ", " + s.flexWrap + ", align-items " + s.alignItems + |
| + ", gap " + s.rowGap + "; the stack is a flex column, nowrap, align-items normal, gap " + round(scale[2]) + |
| + "px: an app rule overrides it" |
| + }); |
| + } |
| + for (var child = stack.firstElementChild; child; child = child.nextElementSibling) { |
| + var cs = getComputedStyle(child); |
| + if (!shows(stack, child) || cs.display === "none" || |
| + (cs.position !== "absolute" && cs.position !== "fixed") || passedOver(stack, child)) continue; |
| + var margin = parseFloat(cs.marginBlockStart) || 0; |
| + findings.push({ |
| + kind: "out-of-flow", gap: round(margin), before: describe(child), after: "", |
| + message: "a stack's child is " + cs.position + " and the stack does not pass it over, so it takes a margin (" + |
| + round(margin) + "px) or stands for the block before the next; mark it rst-stack-out" |
| + }); |
| + } |
| + }); |
| + |
| + return options.result ? { findings: findings, pairs: pairs, headings: held, stacks: stacks.length } : findings; |
| }) |
diff --git a/credits/credits.css b/credits/credits.css| index 0d696f7..72d6ab9 100644 |
| --- a/credits/credits.css |
| +++ b/credits/credits.css |
| @@ -1,7 +1,22 @@ |
| -[estilo-credits] { min-inline-size: 0; overflow-wrap: anywhere; } |
| +/* credits/credits.css: the Colophon under Help (estilo/credits). The |
| + section is a stack on estilo's terms, as the door's card is |
| + (chrome.css): a column whose children bring no block margins of their |
| + own, spaced by the table Fiesta's rst-stack uses (DESIGN.md, "The |
| + stack"). It holds a heading and its list, and what follows a heading |
| + is --rst-sp-2 under it, the column's gap; so the browser's own |
| + margins (18.8px under the heading, 14px around the list) are gone. |
| + The reset weighs (0,2,0), so an app's own rule on the heading or the |
| + list, such as h1 { margin } at (0,1,1), cannot put a margin back. |
| + An open entry is spaced by the same table: its first block, its |
| + source, and each notice's name are anything else, --rst-sp-3; a |
| + notice's text is its name's content, --rst-sp-2 under it. */ |
| +[estilo-credits] { display: flex; flex-direction: column; gap: var(--rst-sp-2); min-inline-size: 0; overflow-wrap: anywhere; } |
| +[estilo-credits] > :not([hidden]) { margin-block: 0; } |
| [estilo-credits] > ul { list-style: none; padding: 0; } |
| [estilo-credits] > ul > li { border-block-end: 1px solid var(--rst-line); padding-block: var(--rst-sp-2); } |
| [estilo-credits] summary { min-block-size: 24px; padding-block: var(--rst-sp-2); cursor: pointer; } |
| +[estilo-credits] details > :not(summary) { margin-block: var(--rst-sp-3) 0; } |
| +[estilo-credits] details > p + pre { margin-block-start: var(--rst-sp-2); } |
| [estilo-credits] a { display: inline-block; min-block-size: 24px; max-inline-size: 100%; } |
| [estilo-credits] pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; } |
| [estilo-credits-version] { font-size: .875em; } |
diff --git a/credits/credits_test.go b/credits/credits_test.go| index 514a24e..397b559 100644 |
| --- a/credits/credits_test.go |
| +++ b/credits/credits_test.go |
| @@ -68,3 +68,22 @@ func TestNoticeFormattingAndMissingLabel(t *testing.T) { |
| t.Fatal("missing-notice label lost, repeated or interpreted") |
| } |
| } |
| + |
| +// The Colophon is a stack on estilo's terms (credits.css): a column |
| +// whose children bring no margins, whatever an app's rule on its |
| +// heading says, and the list a step under its heading. |
| +// Before, the browser's margins put the list 18.8px under it. |
| +// chrome/rhythm_browser_test.go measures it in real engines. |
| +func TestTheColophonIsAStack(t *testing.T) { |
| + css := string(CSS()) |
| + for _, rule := range []string{ |
| + "[estilo-credits] { display: flex; flex-direction: column; gap: var(--rst-sp-2);", |
| + "[estilo-credits] > :not([hidden]) { margin-block: 0; }", |
| + "[estilo-credits] details > :not(summary) { margin-block: var(--rst-sp-3) 0; }", |
| + "[estilo-credits] details > p + pre { margin-block-start: var(--rst-sp-2); }", |
| + } { |
| + if !strings.Contains(css, rule) { |
| + t.Errorf("credits.css lacks %q", rule) |
| + } |
| + } |
| +} |
diff --git a/googleimport/README.md b/googleimport/README.md| index 2da6d78..5fb90a8 100644 |
| --- a/googleimport/README.md |
| +++ b/googleimport/README.md |
| @@ -59,7 +59,13 @@ Labels: Text(locale)}`. The file input must belong to the named same-origin |
| multipart POST form. Existing hidden fields, including creation tokens, remain |
| intact. The app owns permissions, CSRF, upload limits, conversion and reports. |
| -Serve `JS()` as JavaScript at `JSName()` and load it with a module script only |
| +Serve `CSS()` as a stylesheet and link it on the page that renders the |
| +chooser; it spaces the chooser's disclosure, buttons and status on the spacing |
| +scale. Remove any `[estilo-google-import]` rules of the app's own when you link |
| +it: a column gap of the app's would add to its margins. It has no hashed name, |
| +so serve and cache it as the app serves its other estilo stylesheets; the |
| +immutable caching below is the script's. Serve `JS()` as |
| +JavaScript at `JSName()` and load it with a module script only |
| on configured import pages. The name contains the asset's hash and may be |
| cached as immutable. Call `Headers(w, ContentSecurityPolicy)` before rendering |
| the opted-in import page, including a refused POST's re-render. Handle errors |
diff --git a/googleimport/google-import.css b/googleimport/google-import.css| new file mode 100644 |
| index 0000000..2fcc8a3 |
| --- /dev/null |
| +++ b/googleimport/google-import.css |
| @@ -0,0 +1,18 @@ |
| +/* googleimport/google-import.css: the Google Drive chooser |
| + (estilo-google-import), on the spacing scale. Its blocks are spaced |
| + by the table Fiesta's rst-stack uses (DESIGN.md, "The stack"): the |
| + disclosure, then the Choose button --rst-sp-4 under it (text sits |
| + that far clear of the button under it), Cancel --rst-sp-2 under |
| + Choose while both show (a button under another action, as the |
| + door's card has it, chrome.css), and the status line --rst-sp-3 |
| + under whatever is above it. Margins, not a column gap: the script shows |
| + and hides the buttons and fills the status, and a hidden button or |
| + an empty status then takes no space at all, where a gap would still |
| + fall beside an empty one. The buttons keep their own width. */ |
| +[estilo-google-import] { display: flex; flex-direction: column; align-items: flex-start; } |
| +[estilo-google-import] > * { margin-block: 0; } |
| +[estilo-google-import] > noscript > p { margin-block: 0; } |
| +[estilo-google-import] > * + * { margin-block-start: var(--rst-sp-3); } |
| +[estilo-google-import] > * + [data-google-choose-wrap] { margin-block-start: var(--rst-sp-4); } |
| +[estilo-google-import] > [data-google-choose-wrap]:not([hidden]) + [data-google-cancel-wrap] { margin-block-start: var(--rst-sp-2); } |
| +[estilo-google-import] > [data-google-status]:empty { margin-block-start: 0; } |
diff --git a/googleimport/googleimport.go b/googleimport/googleimport.go| index f28f756..ca00e59 100644 |
| --- a/googleimport/googleimport.go |
| +++ b/googleimport/googleimport.go |
| @@ -62,9 +62,21 @@ var templates embed.FS |
| //go:embed google-import.mjs |
| var javascript []byte |
| +//go:embed google-import.css |
| +var stylesheet []byte |
| + |
| func Templates() fs.FS { return templates } |
| func Template() string { b, _ := templates.ReadFile("templates/google-import.html"); return string(b) } |
| func JS() []byte { return append([]byte(nil), javascript...) } |
| + |
| +// CSS is the chooser's stylesheet: its blocks on the spacing scale. An |
| +// app links it on the page that renders the chooser, beside JSName's |
| +// script, and drops any [estilo-google-import] rules of its own, which |
| +// would add their gap to these margins. Without it the chooser's |
| +// paragraphs keep the browser's margins. It has no hashed name: serve |
| +// it under whatever path and cache policy the app gives its other |
| +// estilo stylesheets. |
| +func CSS() []byte { return append([]byte(nil), stylesheet...) } |
| func JSName() string { |
| h := sha256.Sum256(javascript) |
| return fmt.Sprintf("google-import.%x.mjs", h[:8]) |
diff --git a/googleimport/googleimport_test.go b/googleimport/googleimport_test.go| index a8f0794..956ae2e 100644 |
| --- a/googleimport/googleimport_test.go |
| +++ b/googleimport/googleimport_test.go |
| @@ -119,3 +119,19 @@ func TestBrowserModuleLogic(t *testing.T) { |
| t.Fatalf("node: %v\n%s", err, out) |
| } |
| } |
| + |
| +// The chooser brings its own spacing (google-import.css): before, it |
| +// had none, and Docs and Sheets each spaced it in their own CSS. |
| +// chrome/rhythm_browser_test.go measures it in real engines. |
| +func TestTheChooserHasItsSpacing(t *testing.T) { |
| + css := string(CSS()) |
| + for _, rule := range []string{ |
| + "[estilo-google-import] { display: flex; flex-direction: column; align-items: flex-start; }", |
| + "[estilo-google-import] > * + [data-google-choose-wrap] { margin-block-start: var(--rst-sp-4); }", |
| + "[estilo-google-import] > [data-google-status]:empty { margin-block-start: 0; }", |
| + } { |
| + if !strings.Contains(css, rule) { |
| + t.Errorf("google-import.css lacks %q", rule) |
| + } |
| + } |
| +} |