Bar stack: stacked header slots (Menubar, Lead), controls set, WideOnly and toggle actions, title sizing, Appearance switched in place, rastrillo shim re-vendored. Reviewed by Claude Fable in oficina/estilo discussion 34 (APPROVED WITH CHANGES, then delta APPROVED); CI green.
Squashed from bar-stack into main.
24 files changed,
+1,856
−79
README.md+15 −0busy/busy.go+9 −4busy/busy_test.go+47 −2busy/provenance.json+6 −3busy/rastrillo.js+197 −22chrome/chrome.css+378 −0chrome/chrome.go+69 −7chrome/chrome.js+108 −1chrome/chrome.test.mjs+252 −6chrome/chrome_test.go+5 −2chrome/stack_test.go+385 −0chrome/templates/account.html+9 −5chrome/templates/bar.html+56 −15chrome/templates/icons.html+5 −1chrome/testdata/unchanged-dialog.html+37 −0chrome/testdata/unchanged-public.html+6 −0chrome/testdata/unchanged-signed-in.html+37 −0chrome/testdata/unchanged-signed-out.html+6 −0chrome/testdata/unchanged-sticky.html+37 −0chrome/unchanged_test.go+148 −0go.mod+4 −2menu/menu.go+16 −4menu/menu_test.go+17 −0menu/templates/menu.html+7 −5
CI passed — run details
diff --git a/README.md b/README.md| index a356674..86463d5 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -40,6 +40,21 @@ platform's invoker command (`menu.Item.Dialog`); `Bar.Actions` is |
| the one `estilo-menus` group, menubar menus included, on Escape (in the |
| capture phase) and an outside click. |
| +Docs' I2 editor added two slots to `chrome.Bar` (spec |
| +`docs/superpowers/specs/2026-11-11-editor-i2-design.md` in Docs). |
| +`Menubar` takes the app's own `estilo-menubar` markup and makes the bar |
| +stacked (`estilo-bar~="stacked"`): from 800px a 56px header with the title |
| +over the menus, below it the one-row bar with the menus as a second row; |
| +`--estilo-bar-block-size` is published either way. `Lead` takes app markup |
| +for the start of the end group (Docs' undo/redo), which the app must hide |
| +on narrow screens itself. A bar with either slot |
| +draws its end group as one set of controls; a bar with neither is |
| +unchanged, byte for byte. `Action.WideOnly` hides an action below 64rem |
| +and keeps it out of the Menu sheet, and `menu.Item.Controls` is a toggle |
| +(`aria-expanded`, `aria-controls`, disabled until the app binds it). The |
| +account menu's Appearance is a three-way segmented selector that |
| +`chrome.js` switches in place. |
| + |
| `colophon` is the suite's Colophon, reached from Help: every open-source |
| project an app is made with, in sections (typefaces, libraries by |
| runtime, icons and artwork, data, tools), each with a sentence or two on |
diff --git a/busy/busy.go b/busy/busy.go| index 3421281..6dab46c 100644 |
| --- a/busy/busy.go |
| +++ b/busy/busy.go |
| @@ -20,10 +20,15 @@ |
| // carries three byte-exact copies instead, each recorded in |
| // provenance.json and checked against it: |
| // |
| -// - ShimJS: rastrillo.js as it is now the busy rule has left it. An app |
| -// replaces its vendored static/rastrillo.js with these bytes — its old |
| -// copy still carries the old busy rule, and two busy rules on one |
| -// page fight over every submit. |
| +// - ShimJS: rastrillo.js as it is now the busy rule has left it, at the |
| +// rastrillo Docs pins (v0.29.1-0.20261027164201-054787952dd2), so the |
| +// rst-switch drag it carries and the switch CSS in that rastrillo's |
| +// tokens.css come from one tree. It also applies rastrillo's |
| +// colour-scheme menu ([rst-scheme]) in place, its only submit |
| +// listener, which no other form reaches. An app replaces its vendored |
| +// static/rastrillo.js with these bytes — its old copy still carries |
| +// the old busy rule, and two busy rules on one page fight over every |
| +// submit. |
| // - JS: busy.js, the rule itself, from Fiesta. |
| // - CSS: the spinner-in-place block from rastrillo's tokens.css, for a |
| // tokens.css that predates it. Link it after tokens.css. |
diff --git a/busy/busy_test.go b/busy/busy_test.go| index dac0331..ab53fb6 100644 |
| --- a/busy/busy_test.go |
| +++ b/busy/busy_test.go |
| @@ -7,6 +7,7 @@ import ( |
| "net/http" |
| "net/http/httptest" |
| "os" |
| + "regexp" |
| "strings" |
| "testing" |
| ) |
| @@ -39,8 +40,25 @@ func TestFilesAreTheRecordedCopies(t *testing.T) { |
| // The point of the package: the shim it hands out has no busy rule left in |
| // it (or it would fight busy.js), and busy.js has the minimum. |
| func TestTheShimLeftTheRuleToBusyJS(t *testing.T) { |
| - if strings.Contains(string(ShimJS()), "busySubmit") || strings.Contains(string(ShimJS()), `"submit"`) { |
| - t.Error("the shim still carries a busy rule; two on one page fight over every submit") |
| + shim := string(ShimJS()) |
| + for _, rule := range []string{"busySubmit", "aria-busy", "rst-spin", "HOLD_MS", "data-busy"} { |
| + if strings.Contains(shim, rule) { |
| + t.Errorf("the shim still carries a busy rule (%q); two on one page fight over every submit", rule) |
| + } |
| + } |
| + // It hears submit exactly once, for the colour-scheme menu's forms |
| + // ([rst-scheme]), which it applies in place; any other form it leaves |
| + // to the browser and busy.js. (The shim at rastrillo 0547879, which |
| + // Docs pins, added this; the switch drag came with it.) |
| + if n := submitHooks(shim); n != 1 { |
| + t.Fatalf("the shim listens for submit %d times; only the scheme switch should", n) |
| + } |
| + scheme := shim[strings.Index(shim, `addEventListener("submit"`):] |
| + if !strings.Contains(scheme[:strings.Index(scheme, "e.preventDefault()")], `f.closest("[rst-scheme],.rst-scheme")`) { |
| + t.Error("the shim's submit listener prevents a submit outside the scheme menu") |
| + } |
| + if !strings.Contains(shim, "[rst-switch-track]") { |
| + t.Error("the shim lacks the rst-switch drag Docs' share switches need") |
| } |
| // Both timings: a POST's 650ms hold and a GET's 500ms wait before it |
| // shows anything. A copy with only the first holds every search. |
| @@ -54,6 +72,33 @@ func TestTheShimLeftTheRuleToBusyJS(t *testing.T) { |
| } |
| } |
| +// submitHooks counts the ways a script can hear a submit: |
| +// addEventListener with the type in any of JavaScript's three quotes, and |
| +// an onsubmit handler, assigned or as an attribute. |
| +func submitHooks(js string) int { |
| + return len(regexp.MustCompile("addEventListener\\(\\s*[\"'`]submit[\"'`]|\\bonsubmit\\b").FindAllString(js, -1)) |
| +} |
| + |
| +// The guard above must see a second submit listener however it is |
| +// spelled, or a re-vendored shim with a busy rule written another way |
| +// would pass it (Fable, estilo #34: it caught only "submit" in double |
| +// quotes). |
| +func TestTheSubmitGuardSeesEverySpelling(t *testing.T) { |
| + shim := string(ShimJS()) |
| + for _, extra := range []string{ |
| + `document.addEventListener("submit", busy, true)`, |
| + `document.addEventListener('submit', busy, true)`, |
| + "document.addEventListener(`submit`, busy, true)", |
| + `document.addEventListener( "submit", busy)`, |
| + `form.onsubmit = busy`, |
| + `document.body.setAttribute("onsubmit", "busy()")`, |
| + } { |
| + if n := submitHooks(shim + "\n" + extra + "\n"); n != 2 { |
| + t.Errorf("the guard counts %d submit listeners with %s added; want 2", n, extra) |
| + } |
| + } |
| +} |
| + |
| func TestHandlerServesOnlyItsTwoFiles(t *testing.T) { |
| h := Handler() |
| for path, want := range map[string]int{ |
diff --git a/busy/provenance.json b/busy/provenance.json| index 3e6e269..7308784 100644 |
| --- a/busy/provenance.json |
| +++ b/busy/provenance.json |
| @@ -1,12 +1,15 @@ |
| { |
| "repository": "https://amadan.net/rastrillo/rastrillo", |
| "commit": "eda484d4822c5a954b68411375075552c9aeda3e", |
| - "note": "rastrillo.js and busy.css: rastrillo main, after busy-hold-needs-a-button (discussion 51). busy.js has its own source below.", |
| + "note": "busy.css: rastrillo main at the commit above, after busy-hold-needs-a-button (discussion 51). rastrillo.js and busy.js have their own sources below.", |
| "files": { |
| "rastrillo.js": { |
| + "repository": "https://amadan.net/rastrillo/rastrillo", |
| + "commit": "054787952dd28c6cb2dd7e6257882ef8a29381db", |
| + "note": "ui/rastrillo.js (ui.ShimJS()) at module version v0.29.1-0.20261027164201-054787952dd2, the rastrillo Docs pins, so the switch drag here and the switch CSS in Docs' tokens.css come from one tree. Busy-less; adds the rst-switch drag and the rst-scheme in-place switch. Re-vendored on estilo bar-stack (Docs I2 spec, revision 2.1).", |
| "from": "ui/rastrillo.js", |
| - "sha256": "b1eac44b25a98ca8144c59dc792ac6c5f66570b40b14f5b428c6838f88e137a3", |
| - "bytes": 9784 |
| + "sha256": "13a8ca6fa9ac25833f6485ab50a521dff7bd811372025dc5141b96522b60098b", |
| + "bytes": 19434 |
| }, |
| "busy.js": { |
| "repository": "https://amadan.net/rastrillo/fiesta", |
diff --git a/busy/rastrillo.js b/busy/rastrillo.js| index 2c9cd5a..d9a9063 100644 |
| --- a/busy/rastrillo.js |
| +++ b/busy/rastrillo.js |
| @@ -38,10 +38,16 @@ |
| direct navigation. Reserved: the framework's own handlers do not |
| read it today. |
| - Menus: an open <details rst-dropdown>, <details rst-row-menu> or a |
| - nested <details rst-menu-group> closes on an outside click and on |
| - Escape, in EITHER spelling, so upgrading this file before running |
| - `rastrillo markup` leaves no dead menus. Exclusivity stays native. |
| + Menus: an open <details rst-dropdown>, <details rst-row-menu>, a |
| + nested <details rst-menu-group>, or the topbar's and console's narrow |
| + <details rst-shell-menu> card (whose content is its next sibling, the |
| + tail) closes on an outside click and on Escape, in EITHER spelling, |
| + so upgrading this file before running `rastrillo markup` leaves no |
| + dead menus. Exclusivity stays native. (anchor.js, beside this file, |
| + keeps a dropdown's menu on the screen where CSS anchor positioning |
| + is missing.) A switch's knob can be dragged along its track, and |
| + snaps to the nearer end. The colour-scheme menu's forms apply in |
| + place and write the server's cookie, instead of posting. |
| A polled response may answer 204 with a Rastrillo-Location header |
| instead of a fragment; the shim navigates there, but only to a local |
| @@ -157,19 +163,51 @@ |
| // clicking elsewhere INSIDE the parent closing the submenu — the |
| // contains(except) test below already draws that line for free. |
| // |
| - // Shell chrome and the toggle-block are deliberately absent from |
| - // MENUS. A sidebar's disclosure strip and a settings switch are not |
| - // menus; closing them because a click landed elsewhere would fight the |
| - // user rather than help. |
| + // The old sidebar drawer and the toggle-block are deliberately absent |
| + // from MENUS: neither is a menu, and closing one because a click |
| + // landed elsewhere would fight the user. The topbar's and console's |
| + // narrow Menu IS in, since it became a floating card: an overlay, which |
| + // is what this list is for. It is not in the rst-menus name group, |
| + // which is document-wide; there, opening the account menu inside the |
| + // card would close the card around it. |
| var MENUS = "[rst-dropdown][open],[rst-menu-group][open],[rst-row-menu][open]"; |
| MENUS += "," + MENUS.replace(/\[(rst[-\w]+)\]/g, ".$1"); |
| + // Written out rather than derived: the class spelling of rst-shell-menu |
| + // is .rst-shell__menu, which the rewrite above would spell wrong. Only |
| + // in a topbar, or a console whose root names its view: a console |
| + // layout from before the phone index gates its RAIL on this [open], |
| + // and dismissing it there closed the whole navigation on a tap at a |
| + // group label. No :is(), so an older engine still parses the list. |
| + MENUS += ",[rst-shell-topbar] [rst-shell-menu][open],[rst-shell-console~=page] [rst-shell-menu][open],[rst-shell-console~=index] [rst-shell-menu][open]"; |
| + MENUS += ",.rst-shell-topbar .rst-shell__menu[open],.rst-shell-console--page .rst-shell__menu[open],.rst-shell-console--index .rst-shell__menu[open]"; |
| + var TAIL = "[rst-shell-tail],.rst-shell__tail"; |
| - // except is the clicked node: the menu containing it stays open, which |
| - // is what keeps a click on a menu item — or on the summary of a menu |
| - // being opened right now — from closing the thing being used. |
| + // menuAround is closest(MENUS) plus one logical parent. The card's |
| + // content (the tail) is the shell menu's next SIBLING, not its child, |
| + // so without this a click on the account menu inside the card would |
| + // close the card, and Escape from a plain nav link in it would find no |
| + // menu at all. Only while the Menu summary is rendered: at 800px and |
| + // up it is display: none, while a <details> opened at 390 and then |
| + // widened keeps [open], and climbing to it would hand focus to a |
| + // summary nobody can see. |
| + function menuAround(node) { |
| + var d = node.closest(MENUS), t, s; |
| + if (d) return d; |
| + t = node.closest(TAIL); |
| + d = t && t.previousElementSibling; |
| + s = d && d.matches(MENUS) && d.querySelector("summary"); |
| + return s && s.getClientRects().length ? d : null; |
| + } |
| + |
| + // except is the clicked node: every menu around it, directly or through |
| + // menuAround's climb, stays open, which is what keeps a click on a menu |
| + // item, or on the summary of a menu being opened right now, from |
| + // closing the thing being used. |
| function closeMenus(except) { |
| + var keep = [], m; |
| + for (m = except && except.closest && menuAround(except); m; m = m.parentElement && menuAround(m.parentElement)) keep.push(m); |
| document.querySelectorAll(MENUS).forEach(function (d) { |
| - if (!except || !d.contains(except)) d.open = false; |
| + if (keep.indexOf(d) < 0 && !(except && d.contains(except))) d.open = false; |
| }); |
| } |
| @@ -180,14 +218,14 @@ |
| // which strands a keyboard user at the top of the document. Hand it |
| // back to the summary that opened the menu. |
| var el = document.activeElement; |
| - var host = el && el.closest ? el.closest(MENUS) : null; |
| - // Climb to the OUTERMOST open menu around the focus. closest() finds |
| - // the innermost, which for focus inside a submenu is the submenu — |
| - // and its summary is inside the parent that is about to close too, so |
| - // focusing it would hand focus to something no longer rendered, which |
| - // is no hand-back at all. |
| - while (host && host.parentElement && host.parentElement.closest(MENUS)) { |
| - host = host.parentElement.closest(MENUS); |
| + var host = el && el.closest ? menuAround(el) : null; |
| + // Climb to the OUTERMOST open menu around the focus. menuAround |
| + // finds the innermost, which for focus inside a submenu is the |
| + // submenu, and for focus in the account menu inside the card is the |
| + // account menu: their summaries are inside the thing about to close, |
| + // so focusing one would hand focus to something no longer rendered. |
| + while (host && host.parentElement && menuAround(host.parentElement)) { |
| + host = menuAround(host.parentElement); |
| } |
| closeMenus(null); |
| if (host) { |
| @@ -199,13 +237,150 @@ |
| document.addEventListener("click", dismissMenus, true); |
| document.addEventListener("keydown", dismissMenus, true); |
| + // A switch slides. A press on its track that moves 4px drags the knob |
| + // (the CSS reads its share of the travel, --rst-switch-p, and the on |
| + // colour's share, --rst-switch-on, off the track) and on release the |
| + // knob goes to the nearer end (half way is on) with the firm release |
| + // curve, which the CSS keys off data-rst-settle on the label for the |
| + // 0.18s it takes and a little slack; if that end is the other state, |
| + // the checkbox is clicked, so input and change fire as for a tap. A |
| + // press that does not move is the label's, which toggles as it always |
| + // has; after a drag the label's own click is cancelled (never the |
| + // checkbox's, which Space and the drop above send), so nothing |
| + // toggles twice. The checkbox stays the state. |
| + var TRACK = "[rst-switch-track],.rst-switch__track", drag = null, after = null, settling = null, settleT = 0, releasing = false; |
| + function unsettle() { |
| + if (settling) settling.removeAttribute("data-rst-settle"); |
| + settling = null; |
| + clearTimeout(settleT); |
| + } |
| + function settle(l) { |
| + unsettle(); |
| + settling = l; |
| + l.setAttribute("data-rst-settle", ""); |
| + settleT = setTimeout(unsettle, 300); |
| + } |
| + // A toggle while a switch settles takes a toggle's own curve: the |
| + // mark goes on change, bar the release's own click. |
| + document.addEventListener("change", function (e) { if (settling && !releasing && settling.contains(e.target)) unsettle(); }, true); |
| + // One drag at a time: a second finger is ignored until the first |
| + // lifts, and a drag ends (cleaned up, committed only on pointerup) |
| + // however its pointer goes. A press by the same pointer means its |
| + // release was missed, so that drag is over. |
| + document.addEventListener("pointerdown", function (e) { |
| + if (drag && e.pointerId !== drag.id) return; |
| + // A toggle block's head is a switch too; its own input is first. |
| + var t = e.target.closest && e.target.closest(TRACK), l = t && t.closest("[rst-switch],.rst-switch,[rst-tblock-head],.rst-tblock__head"), box = l && l.querySelector("input"); |
| + if (drag) drop({ type: "lost", pointerId: drag.id }); |
| + after = null; |
| + // :disabled, not .disabled: a disabled fieldset disables the box |
| + // without setting its property, and a click on it does nothing. |
| + if (!box || box.matches(":disabled") || e.button) return; |
| + var r = t.getBoundingClientRect(), max = r.width - r.height; |
| + drag = { l: l, t: t, box: box, id: e.pointerId, x: e.clientX, max: max, at: box.checked ? max : 0, pos: -1, |
| + dir: getComputedStyle(t).direction === "rtl" ? -1 : 1 }; |
| + }); |
| + document.addEventListener("pointermove", function (e) { |
| + var g = drag, d; |
| + if (!g || e.pointerId !== g.id) return; |
| + d = (e.clientX - g.x) * g.dir; |
| + if (g.pos < 0) { |
| + if (Math.abs(d) < 4) return; |
| + // A drag on a settling switch takes over: no mark. |
| + if (settling === g.l) unsettle(); |
| + g.l.setAttribute("data-rst-drag", ""); |
| + g.t.setPointerCapture(e.pointerId); |
| + } |
| + g.pos = Math.min(g.max, Math.max(0, g.at + d)); |
| + d = g.pos / g.max; |
| + g.t.style.setProperty("--rst-switch-p", d); |
| + g.t.style.setProperty("--rst-switch-on", d * 100 + "%"); |
| + }); |
| + function drop(e) { |
| + var g = drag; |
| + if (!g || e.pointerId !== g.id) return; |
| + drag = null; |
| + if (g.pos < 0) return; |
| + g.l.removeAttribute("data-rst-drag"); |
| + settle(g.l); |
| + g.t.style.removeProperty("--rst-switch-p"); |
| + g.t.style.removeProperty("--rst-switch-on"); |
| + after = g.l; |
| + releasing = true; |
| + if (e.type === "pointerup" && !g.box.matches(":disabled") && g.pos >= g.max / 2 !== g.box.checked) g.box.click(); |
| + releasing = false; |
| + } |
| + document.addEventListener("pointerup", drop); |
| + document.addEventListener("pointercancel", drop); |
| + document.addEventListener("lostpointercapture", drop); |
| + document.addEventListener("click", function (e) { |
| + if (after && after.contains(e.target) && e.target.tagName !== "INPUT") { |
| + e.preventDefault(); |
| + after = null; |
| + } |
| + }, true); |
| + |
| + // iOS applies :active on a tap only when a touch listener exists. This |
| + // file owns the listener, not light.js, so an app that deletes |
| + // light.js keeps its pressed states. |
| + document.addEventListener("touchstart", function () {}, { passive: true }); |
| + |
| + // The colour-scheme switch's forms ([rst-scheme], POST /_theme) apply |
| + // here instead of round-tripping: data-theme on <html> is what the |
| + // themes read, and the cookie is the server's own (name, path, age, |
| + // SameSite), so the next render paints the same scheme first. System |
| + // is no attribute and no cookie, as on the server. |
| + document.addEventListener("submit", function (e) { |
| + var f = e.target, m = f.closest("[rst-scheme],.rst-scheme"), s = m && f.elements.scheme && f.elements.scheme.value, on = s === "light" || s === "dark"; |
| + if (!s) return; |
| + e.preventDefault(); |
| + if (on) document.documentElement.setAttribute("data-theme", s); else document.documentElement.removeAttribute("data-theme"); |
| + land(); |
| + document.cookie = "rastrillo_scheme=" + (on ? s + "; Max-Age=31536000" : "; Max-Age=0") + "; Path=/; SameSite=Lax" + (location.protocol === "https:" ? "; Secure" : ""); |
| + // Not toggleAttribute: aria-current="" reads as false. |
| + m.querySelectorAll("button").forEach(function (b) { if (b.form === f) b.setAttribute("aria-current", "true"); else b.removeAttribute("aria-current"); }); |
| + m.open = false; |
| + }, true); |
| + |
| + // A scheme change lands in the frame it happens in. The shipped |
| + // tints need no help: at rest nothing fades its background, and a |
| + // hovered row's, tile's or rail item's tint rides a registered |
| + // percentage, so a change of scheme re-resolves its colour at once. |
| + // What this lands is everything else still running: an app's own |
| + // colour transitions, or a switch track mid-toggle, which a change |
| + // of scheme would otherwise retarget while the text changes at |
| + // once. getAnimations() flushes style, which starts the transitions, |
| + // and cancelling one lands it on its end value. Transitions only, |
| + // told by transitionProperty: cancelling an animation would stop a |
| + // spinner for good. |
| + function land() { |
| + if (!document.getAnimations) return; |
| + document.getAnimations().forEach(function (a) { if (typeof a.transitionProperty === "string") a.cancel(); }); |
| + } |
| + |
| + // The OS flipping under a page on System is the same change with no |
| + // click: light-dark() repaints with no script involved. The change |
| + // event reaches script a frame after the style update that started |
| + // the fade, so this lands it a frame late rather than 200ms late. |
| + var osScheme = window.matchMedia && matchMedia("(prefers-color-scheme: dark)"); |
| + if (osScheme) osScheme.onchange = function () { if (!document.documentElement.hasAttribute("data-theme")) land(); }; |
| + |
| function scan() { |
| document.querySelectorAll("[data-poll]").forEach(poll); |
| } |
| + // A prerendered page runs this before anyone is looking at it, and |
| + // may never be shown: polling there would fetch on a timer, or hold an |
| + // EventSource open, for a page the reader only hovered a link to. It |
| + // starts when the page is activated instead. |
| + function start() { |
| + if (document.prerendering) document.addEventListener("prerenderingchange", scan, { once: true }); |
| + else scan(); |
| + } |
| + |
| if (document.readyState === "loading") { |
| - document.addEventListener("DOMContentLoaded", scan); |
| + document.addEventListener("DOMContentLoaded", start); |
| } else { |
| - scan(); |
| + start(); |
| } |
| })(); |
diff --git a/chrome/chrome.css b/chrome/chrome.css| index d16395d..548c881 100644 |
| --- a/chrome/chrome.css |
| +++ b/chrome/chrome.css |
| @@ -299,3 +299,381 @@ |
| :where([estilo-signin]) a { color: var(--rst-accent); text-underline-offset: 0.15em; } |
| [estilo-signin-foot] a { color: inherit; } |
| [estilo-signin-foot] a:hover, [estilo-signin-foot] a:focus-visible { color: var(--rst-text); } |
| + |
| +/* ── Bar stack (Docs' I2 editor header, spec 2026-11-11) ──────────────── |
| + Everything below is opt-in. Each rule is keyed on a hook only a bar |
| + with a slot, a WideOnly action or the Appearance form renders, so a bar |
| + with neither Menubar nor Lead looks exactly as it did |
| + (TestEverythingAfterTheMarkerIsOptIn holds this, and that main's rules |
| + above are unchanged). |
| + |
| + The hooks: [estilo-bar~="stacked"] (Bar.Menubar), [estilo-bar-stack] |
| + and [estilo-bar-menubar] inside it, [estilo-bar-lead] (Bar.Lead), |
| + [estilo-bar-control] (each action in a bar with a slot), |
| + [estilo-bar-wide] (Action.WideOnly) and [estilo-appearance]. |
| + |
| + Breakpoints: 800px is rastrillo's shell breakpoint, the rule above |
| + this section and every app's, so it stays in px: restated in rem it |
| + would move apart from them whenever the reader's default font size is |
| + not 16px. 64rem is where a WideOnly action appears, the same 64rem |
| + Docs' inspector uses. */ |
| + |
| +/* A WideOnly action exists only from 64rem (Docs' Format: the inspector |
| + it toggles exists only there). It is also left out of the Menu sheet |
| + (the template). (0,2,0), so it outweighs a POST action's display: |
| + contents form. */ |
| +@media (max-width: 63.99rem) { |
| + [estilo-bar-actions] [estilo-bar-wide], |
| + [estilo-bar-actions] [estilo-bar-control~="wide"] { display: none; } |
| +} |
| + |
| +/* Each action in a bar with a slot sits in its own wrapper, which lays |
| + out as its control. */ |
| +[estilo-bar-control] { display: contents; } |
| +[estilo-bar-lead] { display: flex; align-items: center; gap: var(--rst-sp-2); } |
| + |
| +/* The stacked bar's title is as wide as its title, never the bar's |
| + room: its size attribute is the first paint's guess, chrome.js |
| + measures the field and corrects it, and it is capped at the space it |
| + has, where a longer title scrolls inside the field as it always has. |
| + No ellipsis: the field is as wide as its title, so one would only ever |
| + mark a guess that came out short, not a title cut off. */ |
| +[estilo-bar~="stacked"] [estilo-bar-title] { flex: none; max-inline-size: 100%; } |
| +[estilo-bar~="stacked"] [estilo-bar-title-input] { flex: 0 1 auto; inline-size: auto; min-inline-size: 0; max-inline-size: 100%; text-overflow: clip; } |
| +[estilo-bar~="stacked"] [estilo-bar-context] { max-inline-size: 100%; } |
| +[estilo-bar~="stacked"] [estilo-menubar-title] { cursor: pointer; } |
| + |
| +/* Below 800px the stacked header does not fit a phone (spec C6: File to |
| + Help needs 261px, and at 320px the title fell to "U…"). So the bar |
| + 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 (English at 320px; a long locale |
| + sooner) grows it further: chrome.js then publishes the header's real |
| + height, and 85px 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 + 1px); } /* 85px: the bar's row, one menubar row and the bottom border. PUBLIC */ |
| + [estilo-bar~="stacked"] { |
| + display: grid; |
| + grid-template-columns: auto minmax(0, 1fr) auto; |
| + grid-template-rows: 3.25rem auto; |
| + grid-template-areas: "brand title end" "menus menus menus"; |
| + column-gap: var(--rst-sp-3); |
| + row-gap: 0; |
| + align-items: center; |
| + block-size: auto; |
| + } |
| + [estilo-bar~="stacked"] > [estilo-bar-brand] { grid-area: brand; } |
| + [estilo-bar~="stacked"] > [estilo-bar-end] { grid-area: end; } |
| + [estilo-bar~="stacked"] [estilo-bar-stack] { display: contents; } |
| + [estilo-bar~="stacked"] [estilo-bar-title], |
| + [estilo-bar~="stacked"] [estilo-bar-context] { grid-area: title; justify-self: start; } |
| + [estilo-bar~="stacked"] [estilo-bar-menubar] { |
| + grid-area: menus; |
| + align-self: stretch; |
| + min-inline-size: 0; |
| + margin-inline: calc(var(--rst-sp-3) - var(--rst-sp-4)); /* the menus' edge 12px in, as Docs' own row had it */ |
| + } |
| +} |
| + |
| +/* From 800px, the 56px stacked header: a 32px icon 12px in, and beside |
| + it a 44px stack, the 24px title row (16px, 600) over the 20px menu row |
| + (13px, muted), both starting at 56px (12 + 32 + 12). The app's name |
| + goes: the icon is the brand. Optical balance, measured at 2x in WebKit |
| + on the mock-up: the title's capitals start at the icon's top, so its |
| + row sits 2.5px low; the menu row sits 1px low, its 24px highlight |
| + stops 3px above the header's bottom edge, and an open panel hangs from |
| + 1px above that edge. */ |
| +@media (min-width: 800px) { |
| + :root:has([estilo-bar~="stacked"]) { --estilo-bar-block-size: 56px; } /* PUBLIC */ |
| + [estilo-bar~="stacked"] { gap: 12px; padding-inline: 12px; } |
| + [estilo-bar~="stacked"] [estilo-bar-brand] img { inline-size: 32px; block-size: 32px; } |
| + [estilo-bar~="stacked"] [estilo-bar-name] { display: none; } |
| + [estilo-bar-stack] { |
| + display: flex; |
| + flex-direction: column; |
| + justify-content: center; |
| + align-items: flex-start; |
| + flex: 1 1 auto; |
| + min-inline-size: 0; |
| + block-size: 44px; |
| + } |
| + [estilo-bar~="stacked"] [estilo-bar-title] { |
| + position: relative; |
| + inset-block-start: 2.5px; |
| + block-size: 24px; |
| + margin: 0; |
| + padding: 0; |
| + border: 0; |
| + } |
| + [estilo-bar~="stacked"] [estilo-bar-title-input] { |
| + block-size: 24px; |
| + padding-block: 0; |
| + margin-inline-start: calc(-0.4rem - 1px); /* the field's padding and border pulled back: the text sits on the edge */ |
| + max-inline-size: calc(100% + 0.4rem + 1px); /* the form is that much narrower than the field: the cap gives it back */ |
| + font-size: 16px; |
| + line-height: 24px; |
| + font-weight: 600; |
| + letter-spacing: -0.01em; |
| + } |
| + [estilo-bar~="stacked"] [estilo-bar-context] { |
| + position: relative; |
| + inset-block-start: 2.5px; |
| + padding: 0; |
| + border: 0; |
| + font-size: 16px; |
| + line-height: 24px; |
| + font-weight: 600; |
| + letter-spacing: -0.01em; |
| + } |
| + /* Rename, while the title is being edited: a 22px pill in the |
| + accent's tint inside the 24px title row, not the 2rem button. The |
| + box is the row's 24px, the 24px target floor (AGENTS.md); a |
| + transparent 1px border with the fill clipped inside it paints the |
| + 22px pill. */ |
| + [estilo-bar~="stacked"] [estilo-bar-title]:focus-within [estilo-bar-title-submit] { |
| + align-self: center; |
| + box-sizing: border-box; |
| + block-size: 24px; |
| + min-block-size: 0; |
| + min-inline-size: 0; |
| + margin: 0; |
| + padding: 0 10px; |
| + border: 1px solid transparent; |
| + border-radius: 999px; |
| + background-color: var(--rst-accent-soft); |
| + background-image: none; |
| + background-clip: padding-box; |
| + box-shadow: none; |
| + color: var(--rst-accent); |
| + font: 600 12px/22px var(--rst-font); |
| + } |
| + [estilo-bar~="stacked"] [estilo-bar-title]:focus-within [estilo-bar-title-submit]:hover { |
| + border-color: transparent; |
| + background-color: var(--rst-accent); |
| + color: var(--rst-on-accent); |
| + } |
| + |
| + /* The menu row. estilo's 32px menubar floor goes here, and only here: |
| + the row is 20px, and each title's highlight is a 24px pill with a 6px |
| + radius, 2px over each edge by negative margins, so it takes no room. */ |
| + [estilo-bar-menubar] { |
| + position: relative; |
| + inset-block-start: 1px; |
| + block-size: 20px; |
| + max-inline-size: calc(100% + 7px); |
| + margin-inline-start: -7px; /* the titles' padding pulled back: the first title's text sits on the edge */ |
| + } |
| + [estilo-bar~="stacked"] [estilo-menubar] { block-size: 20px; min-block-size: 0; align-items: center; flex-wrap: nowrap; } |
| + [estilo-bar~="stacked"] [estilo-menubar-menu] { block-size: 20px; } |
| + [estilo-bar~="stacked"] [estilo-menubar-title] { |
| + block-size: 24px; |
| + min-block-size: 0; |
| + margin-block: -2px; |
| + padding-inline: 7px; |
| + border-radius: 6px; |
| + color: var(--rst-text-muted); |
| + font-size: 13px; |
| + line-height: 24px; |
| + } |
| + [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% + 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. */ |
| + [estilo-bar~="stacked"] [estilo-menu] { |
| + --estilo-float-padding: 4px; |
| + --estilo-item-padding-block: 4px; |
| + --estilo-item-padding-inline: 10px; |
| + border-radius: 10px; |
| + font-size: 13px; |
| + } |
| + [estilo-bar~="stacked"] [estilo-menu-item] { min-block-size: 28px; border-radius: 6px; } |
| + [estilo-bar~="stacked"] [estilo-menu] hr { margin-block: 4px; } |
| + [estilo-bar~="stacked"] [estilo-menu-key] { color: var(--rst-text-muted); font-size: 12px; } |
| + |
| + /* The controls set, in a bar with a slot: every action a 28px pill, |
| + 13px semibold, 8px apart; the primary the one filled pill; the |
| + account its circle; and a divider between the page's controls and |
| + the person's. Lit from above as the index's New document is, and far |
| + fainter in dark. */ |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-bar-end], |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-bar-actions] { gap: 8px; } |
| + :is([estilo-bar-control] > a, [estilo-bar-control] > button, [estilo-bar-control] > form > button) { |
| + display: inline-flex; |
| + align-items: center; |
| + gap: 6px; |
| + box-sizing: border-box; |
| + block-size: 28px; |
| + min-block-size: 28px; |
| + min-inline-size: 28px; |
| + padding: 0 12px; |
| + border: 0; |
| + border-radius: 999px; |
| + background-color: transparent; |
| + box-shadow: inset 0 1px 0 light-dark(rgb(255 255 255 / 0.7), rgb(255 255 255 / 0.06)); |
| + color: var(--rst-text-muted); |
| + font: 600 13px/1 var(--rst-font); |
| + text-decoration: none; |
| + white-space: nowrap; |
| + } |
| + :is([estilo-bar-control] > a, [estilo-bar-control] > button, [estilo-bar-control] > form > button) svg { flex: none; inline-size: 15px; block-size: 15px; } |
| + :is([estilo-bar-control] > a, [estilo-bar-control] > button, [estilo-bar-control] > form > button):hover:not(:disabled) { |
| + background-color: var(--rst-surface-2); |
| + color: var(--rst-text); |
| + box-shadow: inset 0 1px 0 light-dark(rgb(255 255 255 / 0.8), rgb(255 255 255 / 0.08)), 0 1px 2px rgb(23 32 60 / 0.08); |
| + } |
| + /* A toggle whose region is shown takes the accent's tint. */ |
| + :is([estilo-bar-control] > a, [estilo-bar-control] > button, [estilo-bar-control] > form > button)[aria-expanded="true"] { |
| + background-color: var(--rst-accent-soft); |
| + color: var(--rst-accent); |
| + box-shadow: inset 0 1px 0 light-dark(rgb(255 255 255 / 0.8), rgb(255 255 255 / 0.08)), 0 1px 2px rgb(23 32 60 / 0.08); |
| + } |
| + /* The primary: the one filled pill, a fine highlight on its top edge |
| + and a shadow tinted with its own accent, 0 5px 12px -5px. */ |
| + :is([estilo-bar-control~="primary"] > a, [estilo-bar-control~="primary"] > button, [estilo-bar-control~="primary"] > form > button), |
| + :is([estilo-bar-control~="primary"] > a, [estilo-bar-control~="primary"] > button, [estilo-bar-control~="primary"] > form > button):hover:not(:disabled) { |
| + padding-inline: 14px; |
| + background-color: var(--rst-accent); |
| + color: var(--rst-on-accent); |
| + box-shadow: |
| + inset 0 1px 0 rgb(255 255 255 / 0.22), |
| + 0 1px 1px rgb(23 32 60 / 0.10), |
| + 0 5px 12px -5px light-dark(color-mix(in srgb, var(--rst-accent) 75%, transparent), color-mix(in srgb, var(--rst-accent) 25%, transparent)); |
| + } |
| + :is([estilo-bar-control~="primary"] > a, [estilo-bar-control~="primary"] > button, [estilo-bar-control~="primary"] > form > button):hover:not(:disabled) { |
| + background-color: var(--rst-accent-strong); |
| + } |
| + |
| + /* The account is its circle: no square box behind it on hover or |
| + open. The avatar darkens on hover and takes a 2px ring while its menu |
| + is open; with no initials the glyph's own circle does the same. */ |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account] > [estilo-bar-trigger] { |
| + inline-size: 28px; |
| + min-inline-size: 0; |
| + block-size: 28px; |
| + padding: 0; |
| + border-radius: 50%; |
| + background: none; |
| + } |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account] > [estilo-bar-trigger]:focus-visible { outline-offset: 2px; } |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account] [estilo-avatar] { |
| + inline-size: 28px; |
| + block-size: 28px; |
| + font-size: 12px; |
| + box-shadow: inset 0 1px 0 light-dark(rgb(255 255 255 / 0.8), rgb(255 255 255 / 0.06)), 0 1px 2px rgb(23 32 60 / 0.08); |
| + transition: background-color 120ms ease, box-shadow 120ms ease; |
| + } |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account] > [estilo-bar-trigger]:hover [estilo-avatar] { |
| + background: color-mix(in srgb, var(--rst-accent) 18%, var(--rst-surface)); |
| + } |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account][open] [estilo-avatar], |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account][open] > [estilo-bar-trigger]:not(:has([estilo-avatar])) { |
| + box-shadow: 0 0 0 2px var(--rst-surface), 0 0 0 4px color-mix(in srgb, var(--rst-accent) 45%, transparent); |
| + } |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account] > [estilo-bar-trigger]:not(:has([estilo-avatar])):hover { |
| + background: var(--rst-surface-2); |
| + } |
| + |
| + /* The divider: a 20px hairline before the account, 12px either side |
| + (the set's 8px gap and 4px more, then 12px of padding), drawn as the |
| + account's own background so it takes no element. Only when something |
| + of the page's precedes it: never on a bar with no actions and no |
| + lead. Below 64rem a WideOnly action is hidden, so it does not count |
| + there. */ |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-bar-end]:has(> [estilo-bar-lead], > [estilo-bar-actions] > :not([estilo-bar-control~="wide"])) > [estilo-account] { |
| + margin-inline-start: 4px; |
| + padding-inline-start: 12px; |
| + background: linear-gradient(var(--rst-line), var(--rst-line)) left center / 1px 20px no-repeat; |
| + } |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-bar-end]:has(> [estilo-bar-lead], > [estilo-bar-actions] > :not([estilo-bar-control~="wide"])) > [estilo-account]:dir(rtl) { |
| + background-position: right center; |
| + } |
| + |
| + /* Coarse pointers: the header's controls rise to 32px, and the menubar |
| + titles keep their 24px look in the 20px row but take 32px of hit |
| + area, 4px over each edge, drawn by nothing and taking no room. Where |
| + that reaches up under the title field, the field stays on top |
| + (z-index): it keeps all of its own 24px, and a menu under it keeps |
| + 24px from the field's foot to the header's edge. */ |
| + @media (pointer: coarse) { |
| + :is([estilo-bar-control] > a, [estilo-bar-control] > button, [estilo-bar-control] > form > button) { block-size: 32px; min-block-size: 32px; } |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account] > [estilo-bar-trigger], |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account] [estilo-avatar] { inline-size: 32px; block-size: 32px; } |
| + [estilo-bar~="stacked"] [estilo-menubar-title] { position: relative; } |
| + [estilo-bar~="stacked"] [estilo-menubar-title]::before { content: ""; position: absolute; inset-inline: 0; inset-block: -4px; } |
| + [estilo-bar~="stacked"] [estilo-bar-title] { z-index: 1; } |
| + } |
| +} |
| +@media (min-width: 64rem) { |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-bar-end]:has(> [estilo-bar-actions]) > [estilo-account] { |
| + margin-inline-start: 4px; |
| + padding-inline-start: 12px; |
| + background: linear-gradient(var(--rst-line), var(--rst-line)) left center / 1px 20px no-repeat; |
| + } |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-bar-end]:has(> [estilo-bar-actions]) > [estilo-account]:dir(rtl) { |
| + background-position: right center; |
| + } |
| +} |
| +/* Forced colours drop the controls' fills and shadows, leaving their |
| + border to draw them, and the set's border: 0 above outweighs |
| + rastrillo's own forced-colors border on its buttons: Share and Format |
| + would lose every edge. So the set gives it back, at its own weight and |
| + after it. An expanded toggle's tint is gone too, so it is drawn in Highlight, |
| + two pixels deep with the outline (left to the focus ring while that |
| + shows). At every width: below 800px the same border is rastrillo's. */ |
| +@media (forced-colors: active) { |
| + :is([estilo-bar-control] > a, [estilo-bar-control] > button, [estilo-bar-control] > form > button) { border: 1px solid ButtonBorder; } |
| + :is([estilo-bar-control] > a, [estilo-bar-control] > button, [estilo-bar-control] > form > button)[aria-expanded="true"] { border-color: Highlight; } |
| + :is([estilo-bar-control] > a, [estilo-bar-control] > button, [estilo-bar-control] > form > button)[aria-expanded="true"]:not(:focus-visible) { outline: 1px solid Highlight; } |
| +} |
| +@media (prefers-reduced-motion: reduce) { |
| + :is([estilo-bar~="stacked"], [estilo-bar]:has([estilo-bar-lead])) [estilo-account] [estilo-avatar] { transition: none; } |
| +} |
| + |
| +/* Appearance, in every app's account menu: Light, Dark and System as |
| + three equal segments in one well, an icon over each word. The one in |
| + force is raised (the surface, a step lighter in dark, where the |
| + surface is barely off the well), bold, with its icon in the accent: |
| + raised and bold, so more than colour says which. aria-pressed is the |
| + state. chrome.js switches it in place. */ |
| +[estilo-appearance] { |
| + display: grid; |
| + grid-template-columns: repeat(3, minmax(0, 1fr)); |
| + gap: 2px; |
| + margin: 2px 6px 6px; |
| + padding: 3px; |
| + border-radius: 10px; |
| + background: var(--rst-surface-2); |
| + box-shadow: inset 0 1px 2px light-dark(rgb(23 32 60 / 0.06), rgb(0 0 0 / 0.25)); |
| +} |
| +[estilo-appearance] [estilo-menu-item] { |
| + flex-direction: column; |
| + justify-content: center; |
| + gap: 4px; |
| + min-block-size: 46px; |
| + padding: 6px 4px; |
| + border-radius: 8px; |
| + background: none; |
| + color: var(--rst-text-muted); |
| + font-size: 12px; |
| + text-align: center; |
| +} |
| +[estilo-appearance] [estilo-menu-label] { flex: none; max-inline-size: 100%; overflow-wrap: anywhere; } |
| +[estilo-appearance-icon] { display: inline-flex; flex: none; inline-size: 16px; block-size: 16px; } |
| +[estilo-appearance-icon] svg { inline-size: 100%; block-size: 100%; } |
| +[estilo-appearance] [estilo-menu-item]:hover:not([aria-pressed="true"]) { |
| + background: light-dark(rgb(255 255 255 / 0.5), rgb(255 255 255 / 0.04)); |
| + color: var(--rst-text); |
| +} |
| +[estilo-appearance] [estilo-menu-item][aria-pressed="true"] { |
| + background: light-dark(var(--rst-surface), #2f333d); |
| + color: var(--rst-text); |
| + font-weight: 600; |
| + box-shadow: |
| + inset 0 1px 0 light-dark(rgb(255 255 255 / 0.9), rgb(255 255 255 / 0.06)), |
| + 0 1px 2px rgb(23 32 60 / 0.12), |
| + 0 0 0 1px light-dark(rgb(23 32 60 / 0.06), rgb(255 255 255 / 0.06)); |
| +} |
| +[estilo-appearance] [estilo-menu-item][aria-pressed="true"] [estilo-appearance-icon] { color: var(--rst-accent); } |
diff --git a/chrome/chrome.go b/chrome/chrome.go| index a51b5b4..4be639a 100644 |
| --- a/chrome/chrome.go |
| +++ b/chrome/chrome.go |
| @@ -21,11 +21,14 @@ package chrome |
| import ( |
| "embed" |
| + "html/template" |
| "net/http" |
| "strings" |
| "time" |
| "unicode" |
| + "golang.org/x/text/width" |
| + |
| "amadan.net/oficina/estilo.git/menu" |
| "amadan.net/oficina/estilo.git/sky" |
| "github.com/carlosframework/rastrillo/sessions" |
| @@ -44,12 +47,15 @@ var templateFS embed.FS |
| func CSS() []byte { return append([]byte(nil), css...) } |
| // JS returns chrome.js, an optional classic script (defer) that closes an |
| -// open bar panel on Escape or an outside click, and restores the |
| -// editable title on Escape. Nothing depends on it. |
| +// open bar panel on Escape or an outside click, restores the editable |
| +// title on Escape, fits a stacked bar's title field to its title, and |
| +// switches Appearance in place (saving it with a background POST). |
| +// Nothing depends on it: without it the title keeps its server-rendered |
| +// size and Appearance posts and redirects. |
| func JS() []byte { return append([]byte(nil), js...) } |
| -// Templates holds estilo-bar, estilo-bar-title, estilo-bar-actions, |
| -// estilo-account, estilo-switcher, estilo-error, estilo-signin, |
| +// Templates holds estilo-bar, estilo-bar-title, estilo-bar-title-fit, |
| +// estilo-bar-actions, estilo-bar-action, estilo-account, estilo-switcher, estilo-error, estilo-signin, |
| // estilo-signin-sent, estilo-signed-out and the bar's icons. |
| func Templates() embed.FS { return templateFS } |
| @@ -76,10 +82,38 @@ type TitleEdit struct { |
| Label, Submit string |
| } |
| +// Size is the title field's size attribute in a stacked bar |
| +// (Bar.Menubar set), where the field is as wide as its title rather than |
| +// the bar's room. It is the first paint's guess, before any script runs, |
| +// and with scripts off the only width the field gets, so it errs wide: a |
| +// field too wide only puts its (unpainted) edge further out, and one too |
| +// narrow cuts the title off. A size unit is about one average Latin |
| +// character, so the title is counted in columns: an East Asian wide or |
| +// fullwidth character (CJK, kana, Hangul, most emoji) is two, a capital |
| +// one and a half (20 Ws need 1.7 each), anything else one; then a |
| +// quarter more, rounded up, and never under 4, so an empty or one-letter |
| +// title still leaves something to click. chrome.js then measures the |
| +// field and corrects its width; nothing after the title on its row moves |
| +// when it does. |
| +func (t TitleEdit) Size() int { |
| + halves := 0 // half-columns, so a capital's one and a half stays whole |
| + for _, r := range t.Value { |
| + switch k := width.LookupRune(r).Kind(); { |
| + case k == width.EastAsianWide || k == width.EastAsianFullwidth: |
| + halves += 4 |
| + case unicode.IsUpper(r): |
| + halves += 3 |
| + default: |
| + halves += 2 |
| + } |
| + } |
| + return max(4, (halves*5+7)/8) // halves/2 columns, times 5/4, rounded up |
| +} |
| + |
| // Action is one page action. Its Item says what activating it does (a |
| -// link, a POST or a dialog; see menu.Item), so the bar's button and the |
| -// Menu sheet's row are the same element kind and cannot disagree. Primary |
| -// marks the page's main action, drawn as the primary button. |
| +// link, a POST, a dialog or a toggle; see menu.Item), so the bar's button |
| +// and the Menu sheet's row are the same element kind and cannot disagree. |
| +// Primary marks the page's main action, drawn as the primary button. |
| // |
| // Docs' actions were all links (chrome.Link). Sheets' Create is a POST, |
| // and a link in the sheet would be a GET to the list that creates |
| @@ -87,6 +121,15 @@ type TitleEdit struct { |
| type Action struct { |
| menu.Item |
| Primary bool |
| + // WideOnly is an action that only means something on a wide screen |
| + // (Docs' Format, which toggles an inspector that exists only from |
| + // 64rem): the bar hides it below 64rem (estilo-bar-wide) and the |
| + // narrow Menu sheet leaves it out. |
| + WideOnly bool |
| + // Icon is an optional decorative glyph drawn before the label in the |
| + // bar (not in the sheet): the app's own inline <svg aria-hidden="true">, |
| + // trusted markup the app renders itself. The label still names it. |
| + Icon template.HTML |
| } |
| // BarLabels are the bar's own strings: the skip link (rendered by the |
| @@ -118,6 +161,25 @@ type Bar struct { |
| // Sticky pins the bar to the top of the viewport. |
| Sticky bool |
| Labels BarLabels |
| + // Menubar is the app's menu bar ([estilo-menubar] markup it rendered |
| + // itself, File, Edit...). Set, it makes the bar stacked |
| + // (estilo-bar~="stacked"): from 800px the 56px header with the title |
| + // over the menus beside a 32px icon, and below 800px the one-row bar |
| + // with the menus as a full-width second row under it. The bar's height |
| + // is published as --estilo-bar-block-size either way. Trusted markup: |
| + // the app's own template output, never user input. |
| + Menubar template.HTML |
| + // Lead is app markup drawn at the start of the end group, before the |
| + // actions, at every width (Docs' undo/redo pair). It never goes into |
| + // the Menu sheet, and the bar never hides it, so the app MUST hide it |
| + // on narrow screens (Docs hides it below 800px): the end group does |
| + // not shrink, and at 320px a lead squeezes the title to nothing. |
| + // Trusted markup, like Menubar. |
| + // |
| + // A bar with Menubar or Lead set draws its end group as one set of |
| + // controls (28px pills, the avatar as a circle, a divider before the |
| + // account); a bar with neither is unchanged. |
| + Lead template.HTML |
| } |
| // AccountLabels are the account menu's headings. |
diff --git a/chrome/chrome.js b/chrome/chrome.js| index 1f583c6..9b39c8c 100644 |
| --- a/chrome/chrome.js |
| +++ b/chrome/chrome.js |
| @@ -12,7 +12,14 @@ |
| // - a row or button that opens a dialog (command="show-modal") closes |
| // the menu it sat in, returns focus to that menu's title when the |
| // dialog closes, and opens the dialog itself on an engine without |
| -// invoker commands. |
| +// invoker commands; |
| +// - a stacked bar's title field (the one with a size attribute) is |
| +// fitted to its title: the size the server rendered is the first |
| +// paint's guess, and this measures the field and corrects it; |
| +// - Appearance switches in place: the page takes the scheme at once and |
| +// the choice is saved by the same POST, sent in the background, with |
| +// no navigation and no spinner. With scripts off the form posts and |
| +// redirects as it always has. |
| // |
| // The group is one group in every app, so closing it is estilo's job, not |
| // each app's: Sheets' menubar lost Escape and outside-click entirely when |
| @@ -47,6 +54,7 @@ |
| const input = e.target.closest && e.target.closest('[estilo-bar-title-input]') |
| if (input) { |
| input.value = input.defaultValue |
| + if (input.hasAttribute('size')) fit(input) |
| input.blur() |
| e.preventDefault() |
| return |
| @@ -79,4 +87,103 @@ |
| dialog.showModal() |
| e.preventDefault() |
| }) |
| + |
| + // The stacked bar's title field is as wide as its title (Paul: "It |
| + // should grow according to the title, not start out full-width"). The |
| + // field measures itself: at zero width its scroll width is its own text |
| + // as it draws it with both its paddings (Chromium and WebKit alike), so |
| + // only the borders go on top, and 2px for the caret at the end of the |
| + // text. field-sizing: content, a canvas and a mirror span in the same |
| + // font all came out short in WebKit; this did not. CSS caps the width |
| + // at the room the field has (max-inline-size, which from 800px allows |
| + // for the field's pulled-back start margin), so a longer title still |
| + // scrolls inside the field. Nothing after the title on its row moves |
| + // when it changes: the stack takes the room. |
| + const FIT = '[estilo-bar-title-input][size]' |
| + const CARET = 2 |
| + const fit = (input) => { |
| + const cs = getComputedStyle(input) |
| + const px = (v) => parseFloat(v) || 0 |
| + input.style.inlineSize = '0px' |
| + const w = input.scrollWidth + px(cs.borderInlineStartWidth) + px(cs.borderInlineEndWidth) |
| + input.style.inlineSize = Math.ceil(w + CARET) + 'px' |
| + } |
| + const fitAll = () => { Array.prototype.forEach.call(document.querySelectorAll(FIT), fit) } |
| + document.addEventListener('input', (e) => { |
| + const input = e.target.closest && e.target.closest(FIT) |
| + if (input) fit(input) |
| + }) |
| + // Again on resize, once everything has loaded, and once fonts settle: |
| + // the first measure, at script time, can come out a few pixels short. |
| + window.addEventListener('resize', fitAll) |
| + window.addEventListener('load', fitAll) |
| + 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 |
| + // no attribute for System; whatever was mid-transition lands in it at |
| + // once; the pressed segment moves; and the same form data is POSTed to |
| + // the form's action in the background to save it, without following |
| + // the server's redirect back to the page. The form is |
| + // data-busy="false", so the busy rule holds nothing. If the POST fails |
| + // the page stays switched for this visit and says nothing; the next load |
| + // shows the saved choice (spec, P3). Each switch aborts the save before |
| + // it, so two quick clicks cannot reach the server in the wrong order |
| + // and leave the first choice saved. Capture phase, like the rest: an |
| + // app's own submit handler cannot swallow it. |
| + // |
| + // land() is rastrillo's shim's, for its own scheme menu: a change of |
| + // scheme would otherwise retarget running colour transitions while the |
| + // text changes at once. getAnimations() flushes style, which starts the |
| + // transitions the change causes, and cancelling one lands it on its end |
| + // value. Transitions only, told by transitionProperty: cancelling an |
| + // animation would stop a spinner for good. |
| + const land = () => { |
| + if (!document.getAnimations) return |
| + document.getAnimations().forEach((a) => { if (typeof a.transitionProperty === 'string') a.cancel() }) |
| + } |
| + let saving = null |
| + document.addEventListener('submit', (e) => { |
| + const form = e.target |
| + const button = e.submitter |
| + if (e.defaultPrevented || !form.hasAttribute || !form.hasAttribute('estilo-appearance')) return |
| + if (!button || button.getAttribute('name') !== 'mode') return |
| + const mode = button.value |
| + if (mode !== 'light' && mode !== 'dark' && mode !== 'system') return |
| + e.preventDefault() |
| + const root = document.documentElement |
| + if (mode === 'system') root.removeAttribute('data-theme') |
| + else root.setAttribute('data-theme', mode) |
| + land() |
| + Array.prototype.forEach.call(form.querySelectorAll('button[name="mode"]'), (b) => { |
| + b.setAttribute('aria-pressed', b === button ? 'true' : 'false') |
| + }) |
| + const body = new URLSearchParams(new FormData(form)) |
| + body.set('mode', mode) |
| + if (saving) saving.abort() |
| + saving = typeof AbortController === 'function' ? new AbortController() : null |
| + fetch(form.getAttribute('action'), { method: 'POST', body, credentials: 'same-origin', redirect: 'manual', signal: saving ? saving.signal : undefined }).catch(() => {}) |
| + }, true) |
| })() |
diff --git a/chrome/chrome.test.mjs b/chrome/chrome.test.mjs| index bf8f924..983c76d 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; |
| }); |
| @@ -33,6 +35,11 @@ class El { |
| } |
| hasAttribute(n) { return this.attrs.has(n); } |
| getAttribute(n) { return this.attrs.has(n) ? this.attrs.get(n) : null; } |
| + setAttribute(n, v) { this.attrs.set(n, String(v)); } |
| + removeAttribute(n) { this.attrs.delete(n); } |
| + get value() { return this.attrs.get("value") ?? ""; } |
| + set value(v) { this.attrs.set("value", v); } |
| + blur() { if (doc.activeElement === this) doc.activeElement = null; } |
| get open() { return this.attrs.has("open"); } |
| set open(v) { if (v) this.attrs.set("open", ""); else this.attrs.delete("open"); } |
| get tabIndex() { return Number(this.attrs.get("tabindex") ?? 0); } |
| @@ -46,21 +53,57 @@ class El { |
| } |
| let doc; |
| -function load(root) { |
| +// load runs chrome.js against root. The returned dispatch sends an event |
| +// to document's listeners; dispatch.window sends one to window's. |
| +// globals adds to (or replaces) what the script sees: fetch, |
| +// getComputedStyle, document.fonts. |
| +function load(root, globals = {}) { |
| const listeners = []; |
| + const winListeners = []; |
| doc = { |
| activeElement: null, |
| + documentElement: Object.assign(new El("html"), { style: fakeStyle() }), |
| + fonts: globals.fonts, |
| + getAnimations: globals.getAnimations, |
| querySelector: (s) => root.querySelector(s), |
| + querySelectorAll: (s) => root.querySelectorAll(s), |
| getElementById: () => null, |
| addEventListener: (type, fn, capture) => listeners.push({ type, fn, capture: !!capture }), |
| }; |
| - vm.runInNewContext(src, { document: doc, HTMLButtonElement: function () {} }); |
| - return (type, target, init = {}) => { |
| + const window = { addEventListener: (type, fn) => winListeners.push({ type, fn }), matchMedia: globals.matchMedia }; |
| + vm.runInNewContext(src, { |
| + document: doc, |
| + window, |
| + HTMLButtonElement: function () {}, |
| + getComputedStyle: globals.getComputedStyle ?? (() => ({})), |
| + fetch: globals.fetch ?? (() => Promise.resolve()), |
| + FormData: globals.FormData ?? FakeFormData, |
| + URLSearchParams, |
| + ResizeObserver: globals.ResizeObserver, |
| + AbortController, |
| + }); |
| + const dispatch = (type, target, init = {}) => { |
| const e = { type, target, defaultPrevented: false, preventDefault() { this.defaultPrevented = true; }, ...init }; |
| for (const l of listeners.filter((l) => l.type === type && l.capture)) l.fn(e); |
| for (const l of listeners.filter((l) => l.type === type && !l.capture)) l.fn(e); |
| return e; |
| }; |
| + dispatch.window = (type) => { for (const l of winListeners.filter((l) => l.type === type)) l.fn({ type }); }; |
| + 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 { |
| + constructor(form) { |
| + this.entries = form.querySelectorAll("input").filter((i) => i.hasAttribute("name")).map((i) => [i.getAttribute("name"), i.value]); |
| + } |
| + [Symbol.iterator]() { return this.entries[Symbol.iterator](); } |
| } |
| function menubar(tabindex) { |
| @@ -101,3 +144,206 @@ test("Escape is heard before a menu that stops propagation", () => { |
| dispatch("keydown", menus[0].querySelector("button"), { key: "Escape" }); |
| assert.equal(menus[0].open, false); |
| }); |
| + |
| +// The stacked bar's title field. Its text draws 140px wide with 6px of |
| +// padding each side and 1px borders. As a field does in Chromium and |
| +// WebKit (measured), its scroll width at zero width is the text and both |
| +// its paddings (152), and at any other width at least that width, so a |
| +// measure that skips the zeroing reads the old width back instead. |
| +function titleField(attrs = { size: "17" }) { |
| + const input = new El("input", { "estilo-bar-title-input": "", value: "Untitled document", ...attrs }); |
| + input.text = 140; |
| + input.style = { inlineSize: "" }; |
| + Object.defineProperty(input, "scrollWidth", { |
| + get() { |
| + const w = parseFloat(this.style.inlineSize); |
| + return Number.isNaN(w) || w > 0 ? Math.max(400, this.text + 12) : this.text + 12; |
| + }, |
| + }); |
| + return input; |
| +} |
| +const fieldStyle = () => ({ paddingInlineEnd: "6px", borderInlineStartWidth: "1px", borderInlineEndWidth: "1px" }); |
| + |
| +test("a stacked title field is fitted to its text when the script runs", () => { |
| + const fitted = titleField(); |
| + const plain = titleField({}); |
| + load(new El("", {}, [fitted, plain]), { getComputedStyle: fieldStyle }); |
| + // 152 at zero width (the end padding already in it), + 2 border + 2 |
| + // for the caret. |
| + assert.equal(fitted.style.inlineSize, "156px"); |
| + assert.equal(plain.style.inlineSize, "", "a one-row bar's title (no size) is left alone"); |
| +}); |
| + |
| +test("the title is fitted again as it is typed, on resize, at load and when fonts settle", async () => { |
| + const input = titleField(); |
| + let settle; |
| + const fonts = { ready: new Promise((r) => { settle = r; }) }; |
| + const dispatch = load(new El("", {}, [input]), { getComputedStyle: fieldStyle, fonts }); |
| + input.text = 200; |
| + dispatch("input", input); |
| + assert.equal(input.style.inlineSize, "216px", "input"); |
| + input.text = 100; |
| + dispatch.window("resize"); |
| + assert.equal(input.style.inlineSize, "116px", "resize"); |
| + input.text = 120; |
| + dispatch.window("load"); |
| + assert.equal(input.style.inlineSize, "136px", "load"); |
| + input.text = 130; |
| + settle(); |
| + await fonts.ready; |
| + await null; |
| + assert.equal(input.style.inlineSize, "146px", "document.fonts.ready"); |
| +}); |
| + |
| +test("Escape restores the title and fits the field to it again", () => { |
| + const input = titleField(); |
| + const dispatch = load(new El("", {}, [input]), { getComputedStyle: fieldStyle }); |
| + input.defaultValue = "Untitled document"; |
| + input.value = "Something much longer"; |
| + input.text = 300; |
| + dispatch("input", input); |
| + input.text = 140; |
| + const e = dispatch("keydown", input, { key: "Escape" }); |
| + assert.equal(input.value, "Untitled document"); |
| + assert.equal(input.style.inlineSize, "156px"); |
| + assert.equal(e.defaultPrevented, true); |
| +}); |
| + |
| +function appearance() { |
| + const buttons = ["light", "dark", "system"].map((m) => new El("button", { "estilo-menu-item": "", type: "submit", name: "mode", value: m, "aria-pressed": m === "dark" ? "true" : "false" })); |
| + const form = new El("form", { "estilo-appearance": "", method: "post", action: "/appearance", "data-busy": "false" }, [new El("input", { type: "hidden", name: "return_to", value: "/d/abc" }), ...buttons]); |
| + return { form, buttons }; |
| +} |
| + |
| +test("Appearance switches in place and saves in the background", () => { |
| + const { form, buttons } = appearance(); |
| + const sent = []; |
| + const dispatch = load(new El("", {}, [form]), { fetch: (url, init) => { sent.push({ url, init }); return Promise.resolve({}); } }); |
| + doc.documentElement.setAttribute("data-theme", "dark"); |
| + |
| + let e = dispatch("submit", form, { submitter: buttons[0] }); |
| + assert.equal(e.defaultPrevented, true, "no navigation"); |
| + assert.equal(doc.documentElement.getAttribute("data-theme"), "light"); |
| + assert.deepEqual(buttons.map((b) => b.getAttribute("aria-pressed")), ["true", "false", "false"]); |
| + assert.equal(sent.length, 1); |
| + assert.equal(sent[0].url, "/appearance"); |
| + assert.equal(sent[0].init.method, "POST"); |
| + assert.equal(sent[0].init.credentials, "same-origin"); |
| + // Not followed: the server's answer is a 303 back to the page, and a |
| + // followed redirect would fetch the whole page again for nothing. |
| + assert.equal(sent[0].init.redirect, "manual"); |
| + assert.equal(String(sent[0].init.body), "return_to=%2Fd%2Fabc&mode=light", "the same form data the form would post"); |
| + |
| + // System is no attribute at all, as chrome.ThemeAttr writes it. |
| + dispatch("submit", form, { submitter: buttons[2] }); |
| + assert.equal(doc.documentElement.hasAttribute("data-theme"), false); |
| + assert.deepEqual(buttons.map((b) => b.getAttribute("aria-pressed")), ["false", "false", "true"]); |
| + assert.equal(String(sent[1].init.body), "return_to=%2Fd%2Fabc&mode=system"); |
| +}); |
| + |
| +// Two quick clicks are two POSTs with no order between them, so the |
| +// server could save the first choice last. Each switch aborts the save |
| +// before it; the aborted one fails quietly, like any failed save. |
| +test("a second switch aborts the first save, quietly", async () => { |
| + const { form, buttons } = appearance(); |
| + const sent = []; |
| + const fetch = (url, init) => { |
| + sent.push(init); |
| + return new Promise((resolve, reject) => { |
| + if (init.signal) init.signal.addEventListener("abort", () => reject(new DOMException("aborted", "AbortError"))); |
| + }); |
| + }; |
| + const dispatch = load(new El("", {}, [form]), { fetch }); |
| + let unhandled = null; |
| + const onUnhandled = (r) => { unhandled = r; }; |
| + process.on("unhandledRejection", onUnhandled); |
| + dispatch("submit", form, { submitter: buttons[0] }); |
| + dispatch("submit", form, { submitter: buttons[1] }); |
| + await new Promise((r) => setTimeout(r, 10)); |
| + process.off("unhandledRejection", onUnhandled); |
| + assert.equal(sent.length, 2); |
| + assert.ok(sent[0].signal, "the save can be aborted"); |
| + assert.equal(sent[0].signal.aborted, true, "the first save is aborted by the second"); |
| + assert.equal(sent[1].signal.aborted, false, "the last save stands"); |
| + assert.equal(String(sent[1].body), "return_to=%2Fd%2Fabc&mode=dark"); |
| + assert.equal(unhandled, null, "the aborted save surfaced"); |
| + assert.equal(doc.documentElement.getAttribute("data-theme"), "dark"); |
| +}); |
| + |
| +// A switch lands everything mid-transition in the new scheme at once, as |
| +// rastrillo's shim does for its own scheme menu (land()): transitions are |
| +// cancelled, which puts each on its end value, after the attribute has |
| +// changed (getAnimations() flushes style, starting the new ones); an |
| +// animation, a spinner, is left running. |
| +test("a switch lands running transitions and leaves animations alone", () => { |
| + const { form, buttons } = appearance(); |
| + const cancelled = []; |
| + let themeAtCall; |
| + const transition = { transitionProperty: "background-color", cancel() { cancelled.push("transition"); } }; |
| + const spinner = { animationName: "spin", cancel() { cancelled.push("spinner"); } }; |
| + const dispatch = load(new El("", {}, [form]), { |
| + getAnimations: () => { themeAtCall = doc.documentElement.getAttribute("data-theme"); return [transition, spinner]; }, |
| + }); |
| + dispatch("submit", form, { submitter: buttons[1] }); |
| + assert.equal(themeAtCall, "dark", "the transitions were read before the scheme changed"); |
| + assert.deepEqual(cancelled, ["transition"]); |
| +}); |
| + |
| +test("a failed save leaves the page switched and says nothing", async () => { |
| + const { form, buttons } = appearance(); |
| + const dispatch = load(new El("", {}, [form]), { fetch: () => Promise.reject(new TypeError("offline")) }); |
| + let unhandled = null; |
| + const onUnhandled = (r) => { unhandled = r; }; |
| + process.on("unhandledRejection", onUnhandled); |
| + dispatch("submit", form, { submitter: buttons[1] }); |
| + await new Promise((r) => setTimeout(r, 10)); |
| + process.off("unhandledRejection", onUnhandled); |
| + assert.equal(unhandled, null, "the failure surfaced"); |
| + assert.equal(doc.documentElement.getAttribute("data-theme"), "dark"); |
| + assert.deepEqual(buttons.map((b) => b.getAttribute("aria-pressed")), ["false", "true", "false"]); |
| +}); |
| + |
| +test("any other form, or a submit already handled, posts as it always has", () => { |
| + const { form, buttons } = appearance(); |
| + const other = new El("form", { method: "post", action: "/rename" }, [new El("button", { type: "submit", name: "mode", value: "dark" })]); |
| + let fetched = 0; |
| + const dispatch = load(new El("", {}, [form, other]), { fetch: () => { fetched++; return Promise.resolve(); } }); |
| + assert.equal(dispatch("submit", other, { submitter: other.children[0] }).defaultPrevented, false); |
| + const handled = dispatch("submit", form, { submitter: buttons[0], defaultPrevented: true }); |
| + assert.equal(handled.defaultPrevented, true); |
| + assert.equal(doc.documentElement.hasAttribute("data-theme"), false); |
| + // No submitter (form.submit() or an engine without it): a plain POST. |
| + assert.equal(dispatch("submit", form, {}).defaultPrevented, false); |
| + assert.equal(fetched, 0); |
| +}); |
| + |
| +// A stacked bar below 800px whose menu row wraps is taller than the 85px |
| +// 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/chrome_test.go b/chrome/chrome_test.go| index fd3a4b2..e3c8978 100644 |
| --- a/chrome/chrome_test.go |
| +++ b/chrome/chrome_test.go |
| @@ -44,7 +44,8 @@ func TestBarHeightIsFixedAndPublic(t *testing.T) { |
| // Narrow: the title field may shrink to nothing and the Rename button |
| // floats under it rather than taking room from Menu and the switcher. |
| // The browser proof is polish-audit/r2-chrome-check.mjs's reach checks. |
| - narrow := src[strings.LastIndex(src, "@media (max-width: 799.98px)"):] |
| + main := src[:strings.Index(src, barStackMarker)] |
| + narrow := main[strings.LastIndex(main, "@media (max-width: 799.98px)"):] |
| for _, want := range []string{"[estilo-bar-title-input] { min-inline-size: 0; }", "[estilo-bar-title]:focus-within [estilo-bar-title-submit] {\n position: absolute;"} { |
| if !strings.Contains(narrow, want) { |
| t.Errorf("the narrow title layout lost %q", want) |
| @@ -426,7 +427,9 @@ func TestScriptIsClassicAndSelfContained(t *testing.T) { |
| // group, the menubar's menus included: Sheets' menubar lost both when |
| // it left rastrillo's dropdown. And an invoker row closes the menu it |
| // was in, with a fallback where the platform lacks invoker commands. |
| - for _, want := range []string{"Escape", "estilo-bar-title-input", "defaultValue", `details[name="estilo-menus"][open]`, "commandfor", "showModal"} { |
| + // It fits a stacked title by the field's own scroll width, and switches |
| + // Appearance in place on the form's own hook. |
| + for _, want := range []string{"Escape", "estilo-bar-title-input", "defaultValue", `details[name="estilo-menus"][open]`, "commandfor", "showModal", "scrollWidth", "document.fonts", "estilo-appearance", "data-theme"} { |
| if !strings.Contains(src, want) { |
| t.Errorf("chrome.js lost %q", want) |
| } |
diff --git a/chrome/stack_test.go b/chrome/stack_test.go| new file mode 100644 |
| index 0000000..60ccdb5 |
| --- /dev/null |
| +++ b/chrome/stack_test.go |
| @@ -0,0 +1,385 @@ |
| +package chrome |
| + |
| +import ( |
| + "html/template" |
| + "regexp" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/estilo.git/menu" |
| +) |
| + |
| +// What Docs puts in the slots: its own menu bar and its undo/redo pair, |
| +// markup it rendered itself. |
| +const ( |
| + testMenubar = template.HTML(`<nav estilo-menubar aria-label="Menus"><details estilo-menubar-menu name="estilo-menus"><summary estilo-menubar-title>File</summary><div estilo-menu></div></details></nav>`) |
| + testLead = template.HTML(`<button type="button" data-docs-command="undo" aria-label="Undo"></button>`) |
| +) |
| + |
| +func stacked() Bar { |
| + b := signedIn("x") |
| + b.Menubar = testMenubar |
| + return b |
| +} |
| + |
| +func header(html string) string { return html[:strings.Index(html, ">")+1] } |
| + |
| +// The Menubar slot makes the bar stacked, and only it does: the title and |
| +// the app's menus share one stack, so the same markup serves the 56px |
| +// header from 800px and the two-row bar below it. |
| +func TestTheMenubarSlotStacksTheBar(t *testing.T) { |
| + b := stacked() |
| + html := render(t, "estilo-bar", b) |
| + if got := header(html); got != `<header estilo-bar="stacked">` { |
| + t.Errorf("a bar with a menubar opens %s", got) |
| + } |
| + stack := html[strings.Index(html, "<div estilo-bar-stack>"):strings.Index(html, "<div estilo-bar-end>")] |
| + title := strings.Index(stack, "<form estilo-bar-title") |
| + menus := strings.Index(stack, "<div estilo-bar-menubar>"+string(testMenubar)+"</div>") |
| + if title < 0 || menus < 0 || menus < title { |
| + t.Fatalf("the stack is not the title over the app's menubar, verbatim:\n%s", stack) |
| + } |
| + if strings.Count(html, "estilo-menubar-title") != 1 { |
| + t.Error("the menubar is drawn more than once; the narrow row must be the same markup") |
| + } |
| + |
| + b.Sticky = true |
| + if got := header(render(t, "estilo-bar", b)); got != `<header estilo-bar="sticky stacked">` { |
| + t.Errorf("a sticky stacked bar opens %s", got) |
| + } |
| + |
| + // A read-only title (a public page) stacks the same way. |
| + b.ContextEdit, b.Context = nil, "A document" |
| + html = render(t, "estilo-bar", b) |
| + if !strings.Contains(html, "<div estilo-bar-stack>\n <span estilo-bar-context dir=\"auto\" title=\"A document\">A document</span>\n <div estilo-bar-menubar>") { |
| + t.Errorf("the read-only title is not in the stack:\n%s", html) |
| + } |
| + |
| + // Lead alone does not stack the bar, and neither slot set draws no |
| + // stack at all. |
| + b = signedIn("x") |
| + b.Lead = testLead |
| + html = render(t, "estilo-bar", b) |
| + if strings.Contains(header(html), "stacked") || strings.Contains(html, "estilo-bar-stack") || strings.Contains(html, "estilo-bar-menubar") { |
| + t.Errorf("a bar with only a lead is stacked:\n%s", header(html)) |
| + } |
| + html = render(t, "estilo-bar", signedIn("x")) |
| + if strings.Contains(html, "stacked") || strings.Contains(html, "estilo-bar-stack") { |
| + t.Error("a bar with no slots is stacked") |
| + } |
| +} |
| + |
| +// The lead opens the end group, before the actions, at every width, and |
| +// never goes into the Menu sheet: it is the app's, not an action. |
| +func TestTheLeadSlotOpensTheEndGroup(t *testing.T) { |
| + b := stacked() |
| + b.Lead = testLead |
| + html := render(t, "estilo-bar", b) |
| + end := html[strings.Index(html, "<div estilo-bar-end>"):] |
| + if !strings.HasPrefix(end, "<div estilo-bar-end>\n <div estilo-bar-lead>"+string(testLead)+"</div>\n <div estilo-bar-actions>") { |
| + t.Errorf("the lead is not first in the end group, before the actions:\n%s", end) |
| + } |
| + sheet := html[strings.Index(html, `<div estilo-menu="sheet">`):] |
| + sheet = sheet[:strings.Index(sheet, "</details>")] |
| + if strings.Contains(sheet, "data-docs-command") { |
| + t.Error("the lead went into the Menu sheet") |
| + } |
| + // The end group's order stands with a lead in it. |
| + order := []string{"<div estilo-bar-lead>", "<div estilo-bar-actions>", "<details estilo-bar-more", "<details estilo-switcher", "<details estilo-account"} |
| + last := -1 |
| + for _, marker := range order { |
| + i := strings.Index(html, marker) |
| + if i < 0 || i < last { |
| + t.Fatalf("%q is missing or out of order", marker) |
| + } |
| + last = i |
| + } |
| +} |
| + |
| +// Format toggles an inspector that exists only from 64rem: the bar marks |
| +// it estilo-bar-wide (hidden below 64rem) and the narrow sheet leaves it |
| +// out. A sheet with nothing left in it is not drawn. |
| +func TestAWideOnlyActionStaysOutOfTheSheet(t *testing.T) { |
| + b := stacked() |
| + b.Actions = []Action{ |
| + {Item: menu.Item{Controls: "docs-inspector", Expanded: true, Label: "x-format"}, WideOnly: true}, |
| + {Item: menu.Item{Href: "/d/abc/share", Label: "x-share"}, Primary: true}, |
| + } |
| + html := render(t, "estilo-bar", b) |
| + actions := html[strings.Index(html, "<div estilo-bar-actions>"):strings.Index(html, "<details estilo-bar-more")] |
| + if !strings.Contains(actions, `<div estilo-bar-control="wide"><button rst-btn type="button" aria-expanded="true" aria-controls="docs-inspector" disabled data-estilo-toggle estilo-bar-wide>x-format</button></div>`) { |
| + t.Errorf("the wide-only toggle is not marked in the bar:\n%s", actions) |
| + } |
| + sheet := html[strings.Index(html, `<div estilo-menu="sheet">`):strings.Index(html, "<details estilo-switcher")] |
| + if strings.Contains(sheet, "x-format") { |
| + t.Errorf("the wide-only action is in the Menu sheet:\n%s", sheet) |
| + } |
| + if !strings.Contains(sheet, "x-share") { |
| + t.Errorf("an ordinary action left the Menu sheet:\n%s", sheet) |
| + } |
| + |
| + // Only wide-only actions and no nav: no Menu at all, not an empty one. |
| + b.Nav = nil |
| + b.Actions = b.Actions[:1] |
| + html = render(t, "estilo-bar", b) |
| + if strings.Contains(html, "estilo-bar-more") { |
| + t.Error("a Menu sheet was drawn with nothing in it") |
| + } |
| + if !strings.Contains(html, "x-format") { |
| + t.Error("the wide-only action left the bar too") |
| + } |
| + // Nav and only wide-only actions: the nav, and no rule after it. |
| + b.Nav = []Link{{Href: "/", Label: "x-nav"}} |
| + html = render(t, "estilo-bar", b) |
| + if !strings.Contains(html, "estilo-bar-more") { |
| + t.Fatal("the nav's Menu sheet is gone") |
| + } |
| + sheet = html[strings.Index(html, `<div estilo-menu="sheet">`):strings.Index(html, "<details estilo-switcher")] |
| + if strings.Contains(sheet, "<hr>") { |
| + t.Errorf("the sheet rules off actions it does not hold:\n%s", sheet) |
| + } |
| + |
| + // Every kind carries the mark, on its outermost element. |
| + for _, it := range []menu.Item{{Href: "/h", Label: "l"}, {Action: "/p", Label: "l"}, {Dialog: "d", Label: "l"}, {Controls: "c", Label: "l"}} { |
| + html := render(t, "estilo-bar-action", Action{Item: it, WideOnly: true}) |
| + if open := html[:strings.Index(html, ">")+1]; !strings.HasSuffix(open, " estilo-bar-wide>") { |
| + t.Errorf("%+v: the outermost element %s is not marked", it, open) |
| + } |
| + } |
| +} |
| + |
| +// The toggle kind in the bar: a button that names its region and its |
| +// state and is disabled as rendered, until the app's script binds it. |
| +func TestAToggleActionIsDisabledUntilBound(t *testing.T) { |
| + for _, c := range []struct { |
| + a Action |
| + want string |
| + }{ |
| + {Action{Item: menu.Item{Controls: "docs-inspector", Label: "Format"}}, `<button rst-btn type="button" aria-expanded="false" aria-controls="docs-inspector" disabled data-estilo-toggle>Format</button>`}, |
| + {Action{Item: menu.Item{Controls: "docs-inspector", Expanded: true, Label: "Format"}}, `<button rst-btn type="button" aria-expanded="true" aria-controls="docs-inspector" disabled data-estilo-toggle>Format</button>`}, |
| + {Action{Item: menu.Item{Controls: "p", Label: "Panel"}, Primary: true}, `<button rst-btn="primary" type="button" aria-expanded="false" aria-controls="p" disabled data-estilo-toggle>Panel</button>`}, |
| + } { |
| + if got := render(t, "estilo-bar-action", c.a); got != c.want { |
| + t.Errorf("got %s\nwant %s", got, c.want) |
| + } |
| + } |
| + // The icon is the app's own markup, drawn before the label in the bar, |
| + // whatever kind the action is. |
| + icon := template.HTML(`<svg aria-hidden="true"></svg>`) |
| + for kind, c := range map[string]struct { |
| + item menu.Item |
| + want string |
| + }{ |
| + "toggle": {menu.Item{Controls: "c", Label: "Format"}, `data-estilo-toggle><svg aria-hidden="true"></svg>Format</button>`}, |
| + "link": {menu.Item{Href: "/s", Label: "Format"}, `<a rst-btn href="/s"><svg aria-hidden="true"></svg>Format</a>`}, |
| + "post": {menu.Item{Action: "/p", Label: "Format"}, `type="submit"><svg aria-hidden="true"></svg>Format</button></form>`}, |
| + "dialog": {menu.Item{Dialog: "d", Label: "Format"}, `command="show-modal"><svg aria-hidden="true"></svg>Format</button>`}, |
| + } { |
| + if got := render(t, "estilo-bar-action", Action{Item: c.item, Icon: icon}); !strings.HasSuffix(got, c.want) { |
| + t.Errorf("%s: the icon is not before the label: %s", kind, got) |
| + } |
| + } |
| +} |
| + |
| +// In a bar with a slot each action sits in a display: contents wrapper |
| +// the controls set is styled on (estilo's CSS never selects rst-btn), and |
| +// the primary one says so. A bar without a slot draws them bare |
| +// (TestABarWithoutSlotsIsByteForByteUnchanged). |
| +func TestSlottedBarsWrapEachActionAsAControl(t *testing.T) { |
| + for name, b := range map[string]Bar{"menubar": stacked(), "lead": func() Bar { b := signedIn("x"); b.Lead = testLead; return b }()} { |
| + html := render(t, "estilo-bar", b) |
| + actions := html[strings.Index(html, "<div estilo-bar-actions>"):strings.Index(html, "<details estilo-bar-more")] |
| + for _, want := range []string{ |
| + `<div estilo-bar-control><a rst-btn href="/d/abc/share">x-share</a></div>`, |
| + `<div estilo-bar-control="primary"><form method="post" action="/d/new"><button rst-btn="primary" type="submit">x-create</button></form></div>`, |
| + } { |
| + if !strings.Contains(actions, want) { |
| + t.Errorf("%s: the actions lack %s in\n%s", name, want, actions) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// The first paint's width for the title field: a guess in columns, with |
| +// room to spare, since a guess too wide only leaves the field's edge |
| +// further out and a guess too narrow cuts the title off with scripts off. |
| +// A wide or fullwidth character (CJK, kana, Hangul, most emoji) takes two |
| +// columns and a capital one and a half, and the whole is a quarter wider |
| +// again; never under 4. Measured at ecb81fc, where Size counted runes: |
| +// 11 kanji painted 121px against the 206px they need, 20 capital Ws 193px |
| +// against 326px. |
| +func TestTheTitleSizeIsItsWidthInColumnsWithAMargin(t *testing.T) { |
| + for value, want := range map[string]int{ |
| + "": 4, |
| + "Q3": 4, |
| + "Untitled document": 22, // 1 capital + 16: 17.5 columns |
| + "Café plans": 14, // 1 capital + 9: 10.5 |
| + "日本語のタイトル": 20, // 8 wide: 16 |
| + "Wide": 10, // 4 fullwidth: 8 |
| + "Plans 🎉🎉🎉": 16, // 1 capital + 5 + 3 wide emoji: 12.5 |
| + "WWWWWWWWWWWWWWWWWWWW": 38, // 20 capitals: 30 |
| + "مستند بلا عنوان": 19, // 15: Arabic has no capitals |
| + } { |
| + if got := (TitleEdit{Value: value}).Size(); got != want { |
| + t.Errorf("Size(%q) = %d, want %d", value, got, want) |
| + } |
| + } |
| + b := stacked() |
| + b.ContextEdit.Value = "Café plans" |
| + html := render(t, "estilo-bar", b) |
| + if !strings.Contains(html, `<input estilo-bar-title-input name="title" value="Café plans" size="14" aria-label=`) { |
| + t.Errorf("the stacked title has no size from its length:\n%s", html) |
| + } |
| + // Only a stacked bar sizes its title to the text. |
| + if strings.Contains(render(t, "estilo-bar", signedIn("x")), " size=") { |
| + t.Error("a one-row bar's title has a size") |
| + } |
| +} |
| + |
| +// The two title forms are one form: the fitted one is the plain one plus |
| +// its size attribute, so they cannot drift apart. |
| +func TestTheFittedTitleIsTheTitlePlusASize(t *testing.T) { |
| + edit := signedIn("x").ContextEdit |
| + plain := render(t, "estilo-bar-title", edit) |
| + fit := render(t, "estilo-bar-title-fit", edit) |
| + if got := strings.Replace(fit, ` size="`+strconv.Itoa(edit.Size())+`"`, "", 1); got != plain { |
| + t.Errorf("estilo-bar-title-fit is not estilo-bar-title plus size:\n%s\n%s", fit, plain) |
| + } |
| +} |
| + |
| +// The stacked bar's whole markup stays free of script, and every bar |
| +// trigger, menubar menus included, stays in the one group. |
| +func TestTheStackedBarKeepsTheOneMenuGroup(t *testing.T) { |
| + b := stacked() |
| + b.Lead = testLead |
| + html := render(t, "estilo-bar", b) |
| + if strings.Contains(html, "<script") { |
| + t.Fatal("the bar requires no script") |
| + } |
| + for _, d := range regexp.MustCompile(`<details [^>]*>`).FindAllString(html, -1) { |
| + if !strings.Contains(d, `name="estilo-menus"`) { |
| + t.Errorf("%s is not in the estilo-menus group", d) |
| + } |
| + } |
| +} |
| + |
| +// Appearance is three equal segments, an icon over each word, the current |
| +// one pressed; the form opts out of the busy rule (a view switch holds |
| +// nothing), and it is still a plain POST form for a page without script. |
| +func TestAppearanceIsASegmentedSelectorSwitchedInPlace(t *testing.T) { |
| + html := render(t, "estilo-account", signedIn("x").Account) |
| + form := regexp.MustCompile(`<form estilo-appearance [^>]*>`).FindString(html) |
| + if form != `<form estilo-appearance method="post" action="/appearance" role="group" aria-labelledby="estilo-appearance" data-busy="false">` { |
| + t.Errorf("the Appearance form opens %q", form) |
| + } |
| + if !strings.Contains(html, `<input type="hidden" name="return_to" value="/d/abc">`) { |
| + t.Error("the Appearance form lost return_to, which the script-off POST needs") |
| + } |
| + for mode, icon := range map[string]string{"light": `<circle cx="12" cy="12" r="4"/>`, "dark": `<path d="M20.985 12.486`, "system": `<rect width="20" height="14" x="2" y="3" rx="2"/>`} { |
| + button := regexp.MustCompile(`<button estilo-menu-item type="submit" name="mode" value="` + mode + `" aria-pressed="(true|false)"><span estilo-appearance-icon aria-hidden="true"><svg [^>]*>(.*?)</svg></span><span estilo-menu-label>x-` + mode + `</span></button>`).FindStringSubmatch(html) |
| + if button == nil { |
| + t.Errorf("no %s segment with an icon over its word in\n%s", mode, html) |
| + continue |
| + } |
| + if (button[1] == "true") != (mode == "dark") { |
| + t.Errorf("%s is aria-pressed=%s; only the current mode is pressed", mode, button[1]) |
| + } |
| + if !strings.HasPrefix(button[2], icon) { |
| + t.Errorf("%s has the wrong icon: %s", mode, button[2]) |
| + } |
| + } |
| + if strings.Contains(html[strings.Index(html, "<form estilo-appearance"):strings.Index(html, "</form>")], "estilo-menu-check") { |
| + t.Error("the segments still carry the check column") |
| + } |
| +} |
| + |
| +// The stacked header's public numbers: 56px from 800px, the one-row bar |
| +// plus its menu row and its 1px bottom border below (85px, as measured in |
| +// Chromium and WebKit; 84 left the border out), and WideOnly's 64rem. The 32px menubar floor |
| +// goes only inside the stacked header. |
| +func TestTheStackedBarPublishesItsHeight(t *testing.T) { |
| + src := string(CSS()) |
| + src = src[strings.Index(src, barStackMarker):] |
| + for _, re := range []string{ |
| + `@media \(min-width: 800px\) \{\s*:root:has\(\[estilo-bar~="stacked"\]\) \{ --estilo-bar-block-size: 56px; \}`, |
| + `@media \(max-width: 799\.98px\) \{\s*:root:has\(\[estilo-bar~="stacked"\]\) \{ --estilo-bar-block-size: calc\(3\.25rem \+ 2rem \+ 1px\); \}`, |
| + `@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% \+ 4\.5px\); \}`, |
| + } { |
| + if !regexp.MustCompile(re).MatchString(src) { |
| + t.Errorf("chrome.css lacks %s", re) |
| + } |
| + } |
| + // Coarse pointers: the menubar titles keep their 24px look but take |
| + // 32px of hit area, 4px over each edge, with no change to layout. |
| + coarse := src[strings.Index(src, "@media (min-width: 800px) {"):] |
| + coarse = coarse[strings.Index(coarse, "@media (pointer: coarse) {"):] |
| + coarse = coarse[:strings.Index(coarse, "\n }\n")] |
| + for _, want := range []string{ |
| + `[estilo-bar~="stacked"] [estilo-menubar-title] { position: relative; }`, |
| + `[estilo-bar~="stacked"] [estilo-menubar-title]::before { content: ""; position: absolute; inset-inline: 0; inset-block: -4px; }`, |
| + `[estilo-bar~="stacked"] [estilo-bar-title] { z-index: 1; }`, // the title field keeps its own 24px on top |
| + } { |
| + if !strings.Contains(coarse, want) { |
| + t.Errorf("the coarse-pointer rules lack %s", want) |
| + } |
| + } |
| + // Coarse pointers raise the controls to 32px. |
| + if !regexp.MustCompile(`@media \(pointer: coarse\) \{\s*:is\(\[estilo-bar-control\] > a, [^)]*\) \{ block-size: 32px; min-block-size: 32px; \}`).MatchString(src) { |
| + t.Error("the controls do not rise to 32px on a coarse pointer") |
| + } |
| +} |
| + |
| +// A stacked title's field is sized to its title, from a guess before the |
| +// script runs: an ellipsis there would say the title was cut short when |
| +// only the guess was. The one-row bar keeps its ellipsis. |
| +func TestAStackedTitleNeverShowsAnEllipsis(t *testing.T) { |
| + src := string(CSS()) |
| + if !regexp.MustCompile(`\n\[estilo-bar~="stacked"\] \[estilo-bar-title-input\] \{[^}]*text-overflow: clip;`).MatchString(src[strings.Index(src, barStackMarker):]) { |
| + t.Error("the stacked title field still ends a short guess with an ellipsis") |
| + } |
| +} |
| + |
| +// Forced colours drop the controls' fills and shadows, so their border is |
| +// all that is left to draw them, and rastrillo's forced-colors border on |
| +// [rst-btn] loses to the controls set's border: 0. The set restores it |
| +// itself, after that rule and at its weight, and marks an expanded toggle |
| +// (Format with the inspector open) in Highlight, since its tint is gone. |
| +func TestTheControlsKeepTheirBoundaryInForcedColours(t *testing.T) { |
| + src := string(CSS()) |
| + src = src[strings.Index(src, barStackMarker):] |
| + controls := `:is([estilo-bar-control] > a, [estilo-bar-control] > button, [estilo-bar-control] > form > button)` |
| + set := strings.Index(src, controls+" {\n display: inline-flex;") |
| + at := strings.Index(src, "@media (forced-colors: active) {") |
| + if set < 0 || at < 0 || at < set { |
| + t.Fatal("no forced-colors block after the controls set's rules") |
| + } |
| + block := src[at:] |
| + block = block[:strings.Index(block, "\n}\n")] |
| + for _, want := range []string{ |
| + controls + " { border: 1px solid ButtonBorder; }", |
| + controls + `[aria-expanded="true"] { border-color: Highlight; }`, |
| + controls + `[aria-expanded="true"]:not(:focus-visible) { outline: 1px solid Highlight; }`, |
| + } { |
| + if !strings.Contains(block, want) { |
| + t.Errorf("the forced-colors block lacks %s in\n%s", want, block) |
| + } |
| + } |
| +} |
| + |
| +// From 800px the title field is pulled back by its padding and border |
| +// (a negative start margin), so its form is that much narrower than the |
| +// field, and a cap of 100% of the form trimmed chrome.js's fitted width |
| +// by 7.4px. The cap allows for the margin, so the fit stands as measured. |
| +func TestTheWideTitleCapAllowsForItsPulledBackMargin(t *testing.T) { |
| + src := string(CSS()) |
| + src = src[strings.Index(src, barStackMarker):] |
| + wide := src[strings.Index(src, "@media (min-width: 800px) {"):] |
| + rule := regexp.MustCompile(`\[estilo-bar~="stacked"\] \[estilo-bar-title-input\] \{[^}]*\}`).FindString(wide) |
| + if !strings.Contains(rule, "margin-inline-start: calc(-0.4rem - 1px);") || !strings.Contains(rule, "max-inline-size: calc(100% + 0.4rem + 1px);") { |
| + t.Errorf("the wide title field's cap does not give back its pulled-back margin:\n%s", rule) |
| + } |
| +} |
diff --git a/chrome/templates/account.html b/chrome/templates/account.html| index 0b5b20d..a692ab1 100644 |
| --- a/chrome/templates/account.html |
| +++ b/chrome/templates/account.html |
| @@ -3,9 +3,13 @@ |
| Order: who is signed in (not interactive), the app's account-scoped |
| items, Appearance, Help, then Sign out, which appears exactly once in |
| - the app. Appearance is a form of three buttons; the current one is |
| - aria-pressed="true" and every other "false", and the check glyph, not |
| - colour, shows which. |
| + the app. Appearance is a form of three buttons, drawn as three equal |
| + segments in one well, an icon (sun, moon, display) over each word; |
| + the current one is aria-pressed="true" and every other "false", and |
| + it is raised, in bold, so more than colour shows which. The form is |
| + data-busy="false": choosing a scheme is a view switch, not an action |
| + held for the busy rule. chrome.js applies it in place and saves it |
| + with a background POST; with scripts off it posts and redirects. |
| Rail (Account.Rail) puts it at a sidebar rail's foot instead: the |
| trigger is a row naming who is signed in, and the panel opens upward |
| @@ -25,10 +29,10 @@ |
| {{- with .Appearance}} |
| <hr> |
| <p estilo-menu-heading id="estilo-appearance">{{$.Labels.Appearance}}</p> |
| - <form method="post" action="{{.Action}}" role="group" aria-labelledby="estilo-appearance"> |
| + <form estilo-appearance method="post" action="{{.Action}}" role="group" aria-labelledby="estilo-appearance" data-busy="false"> |
| <input type="hidden" name="return_to" value="{{.Return}}"> |
| {{- range .Options}} |
| - <button estilo-menu-item type="submit" name="mode" value="{{.Value}}" aria-pressed="{{if .Current}}true{{else}}false{{end}}"><span estilo-menu-check aria-hidden="true">{{template "estilo-icon-check"}}</span><span estilo-menu-label>{{.Label}}</span></button> |
| + <button estilo-menu-item type="submit" name="mode" value="{{.Value}}" aria-pressed="{{if .Current}}true{{else}}false{{end}}"><span estilo-appearance-icon aria-hidden="true">{{if eq .Value "light"}}{{template "estilo-icon-sun"}}{{else if eq .Value "dark"}}{{template "estilo-icon-moon"}}{{else}}{{template "estilo-icon-display"}}{{end}}</span><span estilo-menu-label>{{.Label}}</span></button> |
| {{- end}} |
| </form> |
| {{- end}} |
diff --git a/chrome/templates/bar.html b/chrome/templates/bar.html| index 84bd9e8..2ab497f 100644 |
| --- a/chrome/templates/bar.html |
| +++ b/chrome/templates/bar.html |
| @@ -1,42 +1,64 @@ |
| -{{/* estilo-bar: the whole app header, one row at every width. |
| +{{/* estilo-bar: the whole app header, one row at every width unless it |
| + is stacked. |
| Data: chrome.Bar. Parse this package's templates together with |
| menu.Templates() and the app's own layout. The skip link and <main> |
| are the layout's; this is only the <header>. |
| - Order in the end group is fixed in every app: actions, then Menu |
| - (narrow only), then the switcher, then the account. The account is |
| - always the last thing at the inline end. |
| + Stacked (Bar.Menubar set, estilo-bar~="stacked"): the title and the |
| + app's menu bar share [estilo-bar-stack], the title over the menus. |
| + From 800px that is the 56px header; below it the stack dissolves |
| + (display: contents) and the menus become a full-width second row, so |
| + the markup is the same at every width. |
| + |
| + Order in the end group is fixed in every app: the lead (Bar.Lead), |
| + actions, then Menu (narrow only), then the switcher, then the |
| + account. The account is always the last thing at the inline end. |
| The brand is a link to the app root, except on public read-only |
| pages, where App.Home is empty and it is plain text. */}} |
| -{{define "estilo-bar"}}<header estilo-bar{{if .Sticky}}="sticky"{{end}}> |
| +{{define "estilo-bar"}}<header estilo-bar{{if and .Sticky .Menubar}}="sticky stacked"{{else if .Sticky}}="sticky"{{else if .Menubar}}="stacked"{{end}}> |
| {{- if .App.Home}} |
| <a estilo-bar-brand href="{{.App.Home}}"><img estilo-brand-icon src="{{.App.Icon}}" alt="" width="28" height="28"><span estilo-bar-name>{{.App.Name}}</span></a> |
| {{- else}} |
| <span estilo-bar-brand><img estilo-brand-icon src="{{.App.Icon}}" alt="" width="28" height="28"><span estilo-bar-name>{{.App.Name}}</span></span> |
| {{- end}} |
| + {{- if .Menubar}} |
| + <div estilo-bar-stack> |
| + {{- with .ContextEdit}} |
| + {{template "estilo-bar-title-fit" .}} |
| + {{- else}}{{with .Context}} |
| + <span estilo-bar-context dir="auto" title="{{.}}">{{.}}</span> |
| + {{- end}}{{end}} |
| + <div estilo-bar-menubar>{{.Menubar}}</div> |
| + </div> |
| + {{- else}} |
| {{- with .ContextEdit}} |
| {{template "estilo-bar-title" .}} |
| {{- else}}{{with .Context}} |
| <span estilo-bar-context dir="auto" title="{{.}}">{{.}}</span> |
| {{- end}}{{end}} |
| + {{- end}} |
| {{- if .Nav}} |
| <nav estilo-bar-nav aria-label="{{.NavLabel}}"> |
| {{- range .Nav}}<a href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}>{{.Label}}</a>{{end}} |
| </nav> |
| {{- end}} |
| <div estilo-bar-end> |
| + {{- with .Lead}} |
| + <div estilo-bar-lead>{{.}}</div> |
| + {{- end}} |
| {{- if .Actions}} |
| <div estilo-bar-actions>{{template "estilo-bar-actions" .}}</div> |
| {{- end}} |
| - {{- if or .Nav .Actions}} |
| + {{- $sheet := false}}{{range .Actions}}{{if not .WideOnly}}{{$sheet = true}}{{end}}{{end}} |
| + {{- if or .Nav $sheet}} |
| <details estilo-bar-more name="estilo-menus"> |
| <summary estilo-bar-trigger>{{template "estilo-icon-menu"}}<span>{{.Labels.Menu}}</span></summary> |
| <div estilo-menu="sheet"> |
| {{- range .Nav}}<a estilo-menu-item href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}><span estilo-menu-label>{{.Label}}</span></a>{{end}} |
| - {{- if and .Nav .Actions}}<hr>{{end}} |
| - {{- range .Actions}}{{template "estilo-menu-item" .Item}}{{end}} |
| + {{- if and .Nav $sheet}}<hr>{{end}} |
| + {{- range .Actions}}{{if not .WideOnly}}{{template "estilo-menu-item" .Item}}{{end}}{{end}} |
| </div> |
| </details> |
| {{- end}} |
| @@ -52,13 +74,22 @@ |
| </header>{{end}} |
| {{/* estilo-bar-actions: the wide-screen actions, from Bar.Actions, each |
| - the element its Item names: a link, a one-button POST form, or a |
| - button opening a dialog. The same items are rows in the narrow Menu |
| - sheet, so both stay one list. An app may redefine this after parsing |
| - to change how they are drawn, but the sheet always renders |
| - Bar.Actions. */}} |
| -{{define "estilo-bar-actions"}}{{range .Actions}}{{template "estilo-bar-action" .}}{{end}}{{end}} |
| -{{define "estilo-bar-action"}}{{if .Action}}<form method="post" action="{{.Action}}"><button rst-btn{{if .Primary}}="primary"{{end}} type="submit">{{.Label}}</button></form>{{else if .Dialog}}<button rst-btn{{if .Primary}}="primary"{{end}} type="button" commandfor="{{.Dialog}}" command="show-modal">{{.Label}}</button>{{else}}<a rst-btn{{if .Primary}}="primary"{{end}} href="{{.Href}}">{{.Label}}</a>{{end}}{{end}} |
| + the element its Item names: a link, a one-button POST form, a button |
| + opening a dialog, or a toggle (aria-expanded, aria-controls) rendered |
| + disabled until the app's script binds it. The same items are rows in |
| + the narrow Menu sheet, so both stay one list; a WideOnly action is |
| + marked estilo-bar-wide, hidden below 64rem, and left out of the |
| + sheet. An app may redefine this after parsing to change how they are |
| + drawn, but the sheet always renders Bar.Actions. |
| + |
| + In a bar with a slot (Menubar or Lead) each action sits in its own |
| + <div estilo-bar-control> (display: contents), "primary" for the |
| + primary one and "wide" for a WideOnly one: the hooks the controls set |
| + is styled on, since estilo's CSS never selects rastrillo's rst- |
| + attributes (AGENTS.md, the prefix rule). A bar with no slot draws the |
| + actions bare, as it always has. */}} |
| +{{define "estilo-bar-actions"}}{{$controls := or .Menubar .Lead}}{{range .Actions}}{{if $controls}}<div estilo-bar-control{{if and .Primary .WideOnly}}="primary wide"{{else if .Primary}}="primary"{{else if .WideOnly}}="wide"{{end}}>{{template "estilo-bar-action" .}}</div>{{else}}{{template "estilo-bar-action" .}}{{end}}{{end}}{{end}} |
| +{{define "estilo-bar-action"}}{{if .Action}}<form method="post" action="{{.Action}}"{{if .WideOnly}} estilo-bar-wide{{end}}><button rst-btn{{if .Primary}}="primary"{{end}} type="submit">{{.Icon}}{{.Label}}</button></form>{{else if .Dialog}}<button rst-btn{{if .Primary}}="primary"{{end}} type="button" commandfor="{{.Dialog}}" command="show-modal"{{if .WideOnly}} estilo-bar-wide{{end}}>{{.Icon}}{{.Label}}</button>{{else if .Controls}}<button rst-btn{{if .Primary}}="primary"{{end}} type="button" aria-expanded="{{if .Expanded}}true{{else}}false{{end}}" aria-controls="{{.Controls}}" disabled data-estilo-toggle{{if .WideOnly}} estilo-bar-wide{{end}}>{{.Icon}}{{.Label}}</button>{{else}}<a rst-btn{{if .Primary}}="primary"{{end}} href="{{.Href}}"{{if .WideOnly}} estilo-bar-wide{{end}}>{{.Icon}}{{.Label}}</a>{{end}}{{end}} |
| {{/* estilo-bar-title: the open object's title, editable in place. A real |
| form, so Enter renames with scripts off. The submit button is visually |
| @@ -67,3 +98,13 @@ |
| <input estilo-bar-title-input name="{{.Name}}" value="{{.Value}}" aria-label="{{.Label}}" autocomplete="off" spellcheck="false" dir="auto"> |
| <button rst-btn="ghost" type="submit" estilo-bar-title-submit>{{.Submit}}</button> |
| </form>{{end}} |
| + |
| +{{/* estilo-bar-title-fit: the same form in a stacked bar, where the field |
| + is as wide as its title: the size attribute (TitleEdit.Size) is the |
| + first paint's approximation, and chrome.js measures the field and |
| + corrects it. It differs from estilo-bar-title only by that attribute |
| + (TestTheFittedTitleIsTheTitlePlusASize). Data: chrome.TitleEdit. */}} |
| +{{define "estilo-bar-title-fit"}}<form estilo-bar-title method="post" action="{{.Action}}"> |
| + <input estilo-bar-title-input name="{{.Name}}" value="{{.Value}}" size="{{.Size}}" aria-label="{{.Label}}" autocomplete="off" spellcheck="false" dir="auto"> |
| + <button rst-btn="ghost" type="submit" estilo-bar-title-submit>{{.Submit}}</button> |
| + </form>{{end}} |
diff --git a/chrome/templates/icons.html b/chrome/templates/icons.html| index c2a8762..99d5a93 100644 |
| --- a/chrome/templates/icons.html |
| +++ b/chrome/templates/icons.html |
| @@ -1,6 +1,10 @@ |
| -{{/* The bar's glyphs. Lucide "menu", "user" and "layout-grid" (ISC, |
| +{{/* The bar's glyphs. Lucide "menu", "user" and "layout-grid", and for |
| + Appearance "sun", "moon" and "monitor" (lucide-static 1.72.0) (ISC, |
| brand/LICENSE.lucide). Decorative: every trigger that carries one has |
| a text label or an aria-label of its own. */}} |
| {{define "estilo-icon-menu"}}<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M4 12h16M4 6h16M4 18h16"/></svg>{{end}} |
| {{define "estilo-icon-person"}}<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>{{end}} |
| {{define "estilo-icon-grid"}}<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg>{{end}} |
| +{{define "estilo-icon-sun"}}<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/></svg>{{end}} |
| +{{define "estilo-icon-moon"}}<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"/></svg>{{end}} |
| +{{define "estilo-icon-display"}}<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><rect width="20" height="14" x="2" y="3" rx="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/></svg>{{end}} |
diff --git a/chrome/testdata/unchanged-dialog.html b/chrome/testdata/unchanged-dialog.html| new file mode 100644 |
| index 0000000..732c4cf |
| --- /dev/null |
| +++ b/chrome/testdata/unchanged-dialog.html |
| @@ -0,0 +1,37 @@ |
| +<header estilo-bar> |
| + <a estilo-bar-brand href="/"><img estilo-brand-icon src="/static/estilo/brand/docs.svg" alt="" width="28" height="28"><span estilo-bar-name>x-app</span></a> |
| + <form estilo-bar-title method="post" action="/d/abc/title"> |
| + <input estilo-bar-title-input name="title" value="x-title" aria-label="x-title-label" autocomplete="off" spellcheck="false" dir="auto"> |
| + <button rst-btn="ghost" type="submit" estilo-bar-title-submit>x-rename</button> |
| + </form> |
| + <nav estilo-bar-nav aria-label="x-navlabel"><a href="/" aria-current="page">x-nav</a> |
| + </nav> |
| + <div estilo-bar-end> |
| + <div estilo-bar-actions><button rst-btn type="button" commandfor="help" command="show-modal">x-help</button><a rst-btn="primary" href="/n">x-new</a></div> |
| + <details estilo-bar-more name="estilo-menus"> |
| + <summary estilo-bar-trigger><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M4 12h16M4 6h16M4 18h16"/></svg><span>x-menu</span></summary> |
| + <div estilo-menu="sheet"><a estilo-menu-item href="/" aria-current="page"><span estilo-menu-label>x-nav</span></a><hr><button estilo-menu-item type="button" commandfor="help" command="show-modal"><span estilo-menu-label>x-help</span></button><a estilo-menu-item href="/n"><span estilo-menu-label>x-new</span></a> |
| + </div> |
| + </details> |
| + <details estilo-switcher name="estilo-menus"> |
| + <summary estilo-bar-trigger aria-label="x-apps"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg></summary> |
| + <div estilo-menu estilo-switcher-panel> |
| + <a estilo-menu-item href="https://oficina.example/"><span estilo-menu-label>x-allapps</span></a> |
| + </div> |
| + </details> |
| + <details estilo-account name="estilo-menus"> |
| + <summary estilo-bar-trigger aria-label="x-trigger"><span estilo-avatar aria-hidden="true">P</span></summary> |
| + <div estilo-menu estilo-account-panel> |
| + <div estilo-menu-identity> |
| + <span estilo-menu-identity-label>x-signedinas</span><span estilo-menu-identity-address dir="auto">paul@example.test</span> |
| + </div><hr><a estilo-menu-item href="/account/home"><span estilo-menu-label>x-connect</span></a> |
| + <hr> |
| + <p estilo-menu-heading>x-help</p><a estilo-menu-item href="/credits"><span estilo-menu-label>x-opensource</span></a> |
| + <hr> |
| + <form method="post" action="/signout"> |
| + <button estilo-menu-item type="submit"><span estilo-menu-label>x-signout</span></button> |
| + </form> |
| + </div> |
| + </details> |
| + </div> |
| +</header> |
| \ No newline at end of file |
diff --git a/chrome/testdata/unchanged-public.html b/chrome/testdata/unchanged-public.html| new file mode 100644 |
| index 0000000..2a32e05 |
| --- /dev/null |
| +++ b/chrome/testdata/unchanged-public.html |
| @@ -0,0 +1,6 @@ |
| +<header estilo-bar> |
| + <span estilo-bar-brand><img estilo-brand-icon src="/i.svg" alt="" width="28" height="28"><span estilo-bar-name>Docs</span></span> |
| + <span estilo-bar-context dir="auto" title="A document">A document</span> |
| + <div estilo-bar-end> |
| + </div> |
| +</header> |
| \ No newline at end of file |
diff --git a/chrome/testdata/unchanged-signed-in.html b/chrome/testdata/unchanged-signed-in.html| new file mode 100644 |
| index 0000000..9176c39 |
| --- /dev/null |
| +++ b/chrome/testdata/unchanged-signed-in.html |
| @@ -0,0 +1,37 @@ |
| +<header estilo-bar> |
| + <a estilo-bar-brand href="/"><img estilo-brand-icon src="/static/estilo/brand/docs.svg" alt="" width="28" height="28"><span estilo-bar-name>x-app</span></a> |
| + <form estilo-bar-title method="post" action="/d/abc/title"> |
| + <input estilo-bar-title-input name="title" value="x-title" aria-label="x-title-label" autocomplete="off" spellcheck="false" dir="auto"> |
| + <button rst-btn="ghost" type="submit" estilo-bar-title-submit>x-rename</button> |
| + </form> |
| + <nav estilo-bar-nav aria-label="x-navlabel"><a href="/" aria-current="page">x-nav</a> |
| + </nav> |
| + <div estilo-bar-end> |
| + <div estilo-bar-actions><a rst-btn href="/d/abc/share">x-share</a><form method="post" action="/d/new"><button rst-btn="primary" type="submit">x-create</button></form></div> |
| + <details estilo-bar-more name="estilo-menus"> |
| + <summary estilo-bar-trigger><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M4 12h16M4 6h16M4 18h16"/></svg><span>x-menu</span></summary> |
| + <div estilo-menu="sheet"><a estilo-menu-item href="/" aria-current="page"><span estilo-menu-label>x-nav</span></a><hr><a estilo-menu-item href="/d/abc/share"><span estilo-menu-label>x-share</span></a><form method="post" action="/d/new"><button estilo-menu-item type="submit"><span estilo-menu-label>x-create</span></button></form> |
| + </div> |
| + </details> |
| + <details estilo-switcher name="estilo-menus"> |
| + <summary estilo-bar-trigger aria-label="x-apps"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg></summary> |
| + <div estilo-menu estilo-switcher-panel> |
| + <a estilo-menu-item href="https://oficina.example/"><span estilo-menu-label>x-allapps</span></a> |
| + </div> |
| + </details> |
| + <details estilo-account name="estilo-menus"> |
| + <summary estilo-bar-trigger aria-label="x-trigger"><span estilo-avatar aria-hidden="true">P</span></summary> |
| + <div estilo-menu estilo-account-panel> |
| + <div estilo-menu-identity> |
| + <span estilo-menu-identity-label>x-signedinas</span><span estilo-menu-identity-address dir="auto">paul@example.test</span> |
| + </div><hr><a estilo-menu-item href="/account/home"><span estilo-menu-label>x-connect</span></a> |
| + <hr> |
| + <p estilo-menu-heading>x-help</p><a estilo-menu-item href="/credits"><span estilo-menu-label>x-opensource</span></a> |
| + <hr> |
| + <form method="post" action="/signout"> |
| + <button estilo-menu-item type="submit"><span estilo-menu-label>x-signout</span></button> |
| + </form> |
| + </div> |
| + </details> |
| + </div> |
| +</header> |
| \ No newline at end of file |
diff --git a/chrome/testdata/unchanged-signed-out.html b/chrome/testdata/unchanged-signed-out.html| new file mode 100644 |
| index 0000000..8cd9cce |
| --- /dev/null |
| +++ b/chrome/testdata/unchanged-signed-out.html |
| @@ -0,0 +1,6 @@ |
| +<header estilo-bar> |
| + <a estilo-bar-brand href="/"><img estilo-brand-icon src="/i.svg" alt="" width="28" height="28"><span estilo-bar-name>Docs</span></a> |
| + <div estilo-bar-end> |
| + <a rst-btn href="/signin?return_to=%2Fd%2Fabc" estilo-bar-signin>Sign in</a> |
| + </div> |
| +</header> |
| \ No newline at end of file |
diff --git a/chrome/testdata/unchanged-sticky.html b/chrome/testdata/unchanged-sticky.html| new file mode 100644 |
| index 0000000..2b69c2f |
| --- /dev/null |
| +++ b/chrome/testdata/unchanged-sticky.html |
| @@ -0,0 +1,37 @@ |
| +<header estilo-bar="sticky"> |
| + <a estilo-bar-brand href="/"><img estilo-brand-icon src="/static/estilo/brand/docs.svg" alt="" width="28" height="28"><span estilo-bar-name>x-app</span></a> |
| + <form estilo-bar-title method="post" action="/d/abc/title"> |
| + <input estilo-bar-title-input name="title" value="x-title" aria-label="x-title-label" autocomplete="off" spellcheck="false" dir="auto"> |
| + <button rst-btn="ghost" type="submit" estilo-bar-title-submit>x-rename</button> |
| + </form> |
| + <nav estilo-bar-nav aria-label="x-navlabel"><a href="/" aria-current="page">x-nav</a> |
| + </nav> |
| + <div estilo-bar-end> |
| + <div estilo-bar-actions><a rst-btn href="/d/abc/share">x-share</a><form method="post" action="/d/new"><button rst-btn="primary" type="submit">x-create</button></form></div> |
| + <details estilo-bar-more name="estilo-menus"> |
| + <summary estilo-bar-trigger><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M4 12h16M4 6h16M4 18h16"/></svg><span>x-menu</span></summary> |
| + <div estilo-menu="sheet"><a estilo-menu-item href="/" aria-current="page"><span estilo-menu-label>x-nav</span></a><hr><a estilo-menu-item href="/d/abc/share"><span estilo-menu-label>x-share</span></a><form method="post" action="/d/new"><button estilo-menu-item type="submit"><span estilo-menu-label>x-create</span></button></form> |
| + </div> |
| + </details> |
| + <details estilo-switcher name="estilo-menus"> |
| + <summary estilo-bar-trigger aria-label="x-apps"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg></summary> |
| + <div estilo-menu estilo-switcher-panel> |
| + <a estilo-menu-item href="https://oficina.example/"><span estilo-menu-label>x-allapps</span></a> |
| + </div> |
| + </details> |
| + <details estilo-account name="estilo-menus"> |
| + <summary estilo-bar-trigger aria-label="x-trigger"><span estilo-avatar aria-hidden="true">P</span></summary> |
| + <div estilo-menu estilo-account-panel> |
| + <div estilo-menu-identity> |
| + <span estilo-menu-identity-label>x-signedinas</span><span estilo-menu-identity-address dir="auto">paul@example.test</span> |
| + </div><hr><a estilo-menu-item href="/account/home"><span estilo-menu-label>x-connect</span></a> |
| + <hr> |
| + <p estilo-menu-heading>x-help</p><a estilo-menu-item href="/credits"><span estilo-menu-label>x-opensource</span></a> |
| + <hr> |
| + <form method="post" action="/signout"> |
| + <button estilo-menu-item type="submit"><span estilo-menu-label>x-signout</span></button> |
| + </form> |
| + </div> |
| + </details> |
| + </div> |
| +</header> |
| \ No newline at end of file |
diff --git a/chrome/unchanged_test.go b/chrome/unchanged_test.go| new file mode 100644 |
| index 0000000..9376b8d |
| --- /dev/null |
| +++ b/chrome/unchanged_test.go |
| @@ -0,0 +1,148 @@ |
| +package chrome |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "flag" |
| + "os" |
| + "path/filepath" |
| + "regexp" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/estilo.git/menu" |
| +) |
| + |
| +var update = flag.Bool("update", false, "rewrite testdata/unchanged-*.html from the current templates") |
| + |
| +// unchangedBars are bars with neither Menubar nor Lead set. Their markup |
| +// was recorded from main at f6d5605, before the slots existed |
| +// (testdata/unchanged-*.html), and must stay byte for byte what it was: |
| +// the slots are opt-in, so an app that sets neither sees nothing move. |
| +// |
| +// The account's Appearance group is left out on purpose. It changed for |
| +// every app on bar-stack (the segmented selector, switched in place), and |
| +// TestAppearanceIsASegmentedSelectorSwitchedInPlace holds that. |
| +func unchangedBars() map[string]any { |
| + full := signedIn("x") |
| + full.Account.Appearance = nil |
| + sticky := signedIn("x") |
| + sticky.Account.Appearance = nil |
| + sticky.Sticky = true |
| + dialog := signedIn("x") |
| + dialog.Account.Appearance = nil |
| + dialog.Actions = []Action{{Item: menu.Item{Dialog: "help", Label: "x-help"}}, {Item: menu.Item{Href: "/n", Label: "x-new"}, Primary: true}} |
| + return map[string]any{ |
| + "signed-in": full, |
| + "sticky": sticky, |
| + "dialog": dialog, |
| + "public": Bar{App: App{Name: "Docs", Icon: "/i.svg"}, Context: "A document"}, |
| + "signed-out": Bar{App: App{Name: "Docs", Home: "/", Icon: "/i.svg"}, SignIn: &Link{Href: "/signin?return_to=%2Fd%2Fabc", Label: "Sign in"}}, |
| + } |
| +} |
| + |
| +func TestABarWithoutSlotsIsByteForByteUnchanged(t *testing.T) { |
| + for name, bar := range unchangedBars() { |
| + t.Run(name, func(t *testing.T) { |
| + got := render(t, "estilo-bar", bar) |
| + path := filepath.Join("testdata", "unchanged-"+name+".html") |
| + if *update { |
| + if err := os.MkdirAll("testdata", 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(path, []byte(got), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + return |
| + } |
| + want, err := os.ReadFile(path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if got != string(want) { |
| + t.Errorf("a bar with no slots changed its markup.\ngot:\n%s\nwant:\n%s", got, want) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// barStackMarker opens chrome.css's opt-in section: everything bar-stack |
| +// added sits after it, and main's rules before it are untouched. |
| +const barStackMarker = "\n/* ── Bar stack" |
| + |
| +// mainCSS is the sha256 of chrome.css on main at f6d5605 (and of menu.css, |
| +// which bar-stack does not touch). A change to the bar's own rules for |
| +// every app is a design decision: make it deliberately, and update these |
| +// with the reason in the commit. |
| +const ( |
| + mainChromeCSS = "273cb84c55d6f28bff4cc03bcba9401b4cdfbee343fe01765159317beee5cab9" |
| + mainMenuCSS = "6b3435a18591d20ad62b40df3e64e159b501f9d1c183b2f42aa32b4faa9c0669" |
| +) |
| + |
| +// optInHooks are the attributes only a bar with a slot, a WideOnly action |
| +// or the Appearance form renders. |
| +var optInHooks = []string{ |
| + `[estilo-bar~="stacked"]`, "[estilo-bar-stack]", "[estilo-bar-menubar]", "[estilo-bar-lead]", |
| + "[estilo-bar-control", "[estilo-bar-wide]", "[estilo-appearance", |
| +} |
| + |
| +// A bar with no slot must look as it did, not only read as it did: main's |
| +// stylesheet rules are byte for byte where they were, and every rule |
| +// bar-stack added is keyed on an opt-in hook, in every selector of its |
| +// list. (Appearance is the deliberate exception that every app takes: |
| +// its hook is the form's own attribute.) |
| +func TestEverythingAfterTheMarkerIsOptIn(t *testing.T) { |
| + src := string(CSS()) |
| + at := strings.Index(src, barStackMarker) |
| + if at < 0 { |
| + t.Fatal("chrome.css lost its bar-stack marker") |
| + } |
| + if sum := sha256.Sum256([]byte(src[:at])); hex.EncodeToString(sum[:]) != mainChromeCSS { |
| + t.Error("main's chrome.css rules changed: every app's bar would look different") |
| + } |
| + if sum := sha256.Sum256(menu.CSS()); hex.EncodeToString(sum[:]) != mainMenuCSS { |
| + t.Error("menu.css changed: every app's menus would look different") |
| + } |
| + section := regexp.MustCompile(`(?s)/\*.*?\*/`).ReplaceAllString(src[at:], "") |
| + n := 0 |
| + for _, m := range regexp.MustCompile(`([^{};]+)\{`).FindAllStringSubmatch(section, -1) { |
| + list := strings.TrimSpace(m[1]) |
| + if strings.HasPrefix(list, "@") { |
| + continue |
| + } |
| + for _, sel := range splitSelectors(list) { |
| + n++ |
| + hooked := false |
| + for _, h := range optInHooks { |
| + hooked = hooked || strings.Contains(sel, h) |
| + } |
| + if !hooked { |
| + t.Errorf("%q styles every bar, not only one that opted in", sel) |
| + } |
| + } |
| + } |
| + if n < 20 { |
| + t.Fatalf("found only %d selectors after the marker; the check is not reading the section", n) |
| + } |
| +} |
| + |
| +// splitSelectors splits a selector list at its top-level commas, leaving |
| +// those inside :is(), :has() and the like. |
| +func splitSelectors(list string) []string { |
| + var out []string |
| + depth, start := 0, 0 |
| + for i, r := range list { |
| + switch r { |
| + case '(': |
| + depth++ |
| + case ')': |
| + depth-- |
| + case ',': |
| + if depth == 0 { |
| + out = append(out, strings.TrimSpace(list[start:i])) |
| + start = i + 1 |
| + } |
| + } |
| + } |
| + return append(out, strings.TrimSpace(list[start:])) |
| +} |
diff --git a/go.mod b/go.mod| index 3896316..9af7908 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -2,7 +2,10 @@ module amadan.net/oficina/estilo.git |
| go 1.25.0 |
| -require github.com/carlosframework/rastrillo v0.23.0 |
| +require ( |
| + github.com/carlosframework/rastrillo v0.23.0 |
| + golang.org/x/text v0.20.0 |
| +) |
| require ( |
| github.com/dustin/go-humanize v1.0.1 // indirect |
| @@ -13,7 +16,6 @@ require ( |
| github.com/ncruces/go-strftime v1.0.0 // indirect |
| github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect |
| golang.org/x/sys v0.46.0 // indirect |
| - golang.org/x/text v0.20.0 // indirect |
| gorm.io/gorm v1.31.2 // indirect |
| gorm.io/plugin/dbresolver v1.6.2 // indirect |
| modernc.org/libc v1.74.1 // indirect |
diff --git a/menu/menu.go b/menu/menu.go| index 9c21d78..478fca3 100644 |
| --- a/menu/menu.go |
| +++ b/menu/menu.go |
| @@ -30,8 +30,7 @@ func CSS() []byte { return append([]byte(nil), css...) } |
| func Templates() embed.FS { return templateFS } |
| // Item is one row rendered by estilo-menu-item. Set exactly one of Href, |
| -// Action and Dialog; each is a different element, and each works with |
| -// scripts off: |
| +// Action, Dialog and Controls; each is a different element: |
| // |
| // - Href: a link, <a href>, for a row that navigates. |
| // - Action: a one-button <form method="post"> to that path, for a row |
| @@ -40,9 +39,17 @@ func Templates() embed.FS { return templateFS } |
| // platform's invoker command (command="show-modal"), for a row that |
| // asks for more before anything happens ("Keyboard shortcuts…"). |
| // chrome.js opens it where the engine has no invoker commands. |
| +// - Controls: a toggle, <button aria-expanded aria-controls>, for a row |
| +// or bar action that shows and hides a region of the page (Docs' |
| +// Format, which shows the inspector). It is rendered disabled, with |
| +// data-estilo-toggle, and stays so until the app's own script binds |
| +// it: with scripts off nothing can toggle the region, and a disabled |
| +// control does not claim to. |
| // |
| -// Action and Dialog came with Sheets, the second adopter: Docs' rows were |
| -// all links, and Sheets' Help moved into the account menu as a dialog. |
| +// The first three work with scripts off. Action and Dialog came with |
| +// Sheets, the second adopter: Docs' rows were all links, and Sheets' Help |
| +// moved into the account menu as a dialog. Controls came with Docs' I2 |
| +// editor (spec 2026-11-11, revision 2.1 C1). |
| type Item struct { |
| Href, Label string |
| // Key is an already-formatted shortcut, from Shortcut. Optional. |
| @@ -51,6 +58,11 @@ type Item struct { |
| Action string |
| // Dialog is the id of the <dialog> a button row opens. |
| Dialog string |
| + // Controls is the id of the region a toggle shows and hides |
| + // (aria-controls); Expanded is whether that region is shown now, as |
| + // the server rendered it (aria-expanded). |
| + Controls string |
| + Expanded bool |
| // Danger draws a destructive row in the negative tone |
| // (estilo-menu-item="danger"). Calls, the fifth adopter, was the |
| // first with one in a menu: "End meeting for everyone". The row still |
diff --git a/menu/menu_test.go b/menu/menu_test.go| index 40b50c2..b06d4e8 100644 |
| --- a/menu/menu_test.go |
| +++ b/menu/menu_test.go |
| @@ -187,3 +187,20 @@ func TestADangerItemIsDrawnInTheNegativeTone(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// A toggle row shows and hides a region (Docs' Format, the inspector). It |
| +// is a button that says which region and whether it is shown, and it is |
| +// disabled as rendered: with scripts off nothing can toggle the region, |
| +// and a disabled control does not claim to. The app's script enables it. |
| +func TestAToggleRowNamesItsRegionAndStartsDisabled(t *testing.T) { |
| + for _, expanded := range []bool{true, false} { |
| + html := render(t, "estilo-menu-item", Item{Controls: "docs-inspector", Expanded: expanded, Label: "Format"}) |
| + want := `<button estilo-menu-item type="button" aria-expanded="false" aria-controls="docs-inspector" disabled data-estilo-toggle><span estilo-menu-label>Format</span></button>` |
| + if expanded { |
| + want = strings.Replace(want, `"false"`, `"true"`, 1) |
| + } |
| + if html != want { |
| + t.Errorf("expanded=%v:\ngot %s\nwant %s", expanded, html, want) |
| + } |
| + } |
| +} |
diff --git a/menu/templates/menu.html b/menu/templates/menu.html| index dd668ae..0f3cd43 100644 |
| --- a/menu/templates/menu.html |
| +++ b/menu/templates/menu.html |
| @@ -1,12 +1,14 @@ |
| {{/* estilo-menu-item: one row in any estilo-menu. Data: menu.Item, with |
| - exactly one of Href (a link), Action (a one-button POST form) or |
| - Dialog (a button opening the <dialog> with that id through the |
| - platform's invoker command). All three work with scripts off; chrome.js |
| - only adds the dialog for engines without invoker commands. Callers |
| + exactly one of Href (a link), Action (a one-button POST form), Dialog |
| + (a button opening the <dialog> with that id through the platform's |
| + invoker command) or Controls (a toggle for the region with that id, |
| + disabled until the app's script binds it). The first three work with |
| + scripts off; chrome.js only adds the dialog for engines without |
| + invoker commands. Callers |
| supply the label in their own locale; Key is an already-formatted |
| shortcut (menu.Shortcut). Danger marks a destructive row |
| (estilo-menu-item="danger"), drawn in the negative tone. */}} |
| -{{define "estilo-menu-item"}}{{if .Action}}<form method="post" action="{{.Action}}"><button estilo-menu-item{{if .Danger}}="danger"{{end}} type="submit">{{template "estilo-menu-item-body" .}}</button></form>{{else if .Dialog}}<button estilo-menu-item{{if .Danger}}="danger"{{end}} type="button" commandfor="{{.Dialog}}" command="show-modal">{{template "estilo-menu-item-body" .}}</button>{{else}}<a estilo-menu-item{{if .Danger}}="danger"{{end}} href="{{.Href}}">{{template "estilo-menu-item-body" .}}</a>{{end}}{{end}} |
| +{{define "estilo-menu-item"}}{{if .Action}}<form method="post" action="{{.Action}}"><button estilo-menu-item{{if .Danger}}="danger"{{end}} type="submit">{{template "estilo-menu-item-body" .}}</button></form>{{else if .Dialog}}<button estilo-menu-item{{if .Danger}}="danger"{{end}} type="button" commandfor="{{.Dialog}}" command="show-modal">{{template "estilo-menu-item-body" .}}</button>{{else if .Controls}}<button estilo-menu-item{{if .Danger}}="danger"{{end}} type="button" aria-expanded="{{if .Expanded}}true{{else}}false{{end}}" aria-controls="{{.Controls}}" disabled data-estilo-toggle>{{template "estilo-menu-item-body" .}}</button>{{else}}<a estilo-menu-item{{if .Danger}}="danger"{{end}} href="{{.Href}}">{{template "estilo-menu-item-body" .}}</a>{{end}}{{end}} |
| {{define "estilo-menu-item-body"}}<span estilo-menu-label>{{.Label}}</span>{{with .Key}}<kbd estilo-menu-key>{{.}}</kbd>{{end}}{{end}} |
| {{/* estilo-icon-check: the glyph inside an estilo-menu-check column. |
| Lucide "check" (ISC, brand/LICENSE.lucide). */}} |