oficina / estilo Public

busy: re-vendor the shim from the rastrillo Docs pins

busy/rastrillo.js is now ui.ShimJS() at amadan.net/rastrillo/rastrillo
v0.29.1-0.20261027164201-054787952dd2 (commit 0547879), so the
rst-switch drag Docs' share switches need and the switch CSS in that
rastrillo's tokens.css come from one tree. Recorded in provenance.json
with its own source.

It is busy-less. Its one submit listener applies the [rst-scheme]
colour menu in place and returns for any other form, so it does not
fight Fiesta 1.3.0's busy.js; the shim test now says exactly that
instead of refusing any "submit" substring.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev e74051fbbdf08154b99556bcd4d1443679d4c79b parent 9d5beba
4 files changed, +231 −31
  • busy/busy.go +9 −4
  • busy/busy_test.go +19 −2
  • busy/provenance.json +6 −3
  • busy/rastrillo.js +197 −22

CI passed — run details

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..44cbb73 100644
--- a/busy/busy_test.go
+++ b/busy/busy_test.go
@@ -39,8 +39,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 := strings.Count(shim, `addEventListener("submit"`); 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.
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();
}
})();