Smooth nav: a block link lands without a jump
A block chip's #b-… address put the block at the window's top edge, under the sticky bar. Now every in-page target clears the bar (scroll-padding on html), and a block lands 40% of the way down the view below the bar, so one already in the first screen's upper part is not scrolled to at all. The block is tinted once and the tint fades (held, then gone, under reduced motion). CSS only, so it works without script; :target matches again after the editor's mount. Build note 58; TestABlockLinkLandsWithoutAJump gates it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+159
−1
docs/superpowers/specs/2026-11-14-mapa-level-up.md+4 −0internal/mapa/static/frame.css+6 −1internal/mapa/static/prose.css+40 −0internal/mapatest/navigation_browser_test.go+109 −0
diff --git a/docs/superpowers/specs/2026-11-14-mapa-level-up.md b/docs/superpowers/specs/2026-11-14-mapa-level-up.md| index 090c19a..7b56046 100644 |
| --- a/docs/superpowers/specs/2026-11-14-mapa-level-up.md |
| +++ b/docs/superpowers/specs/2026-11-14-mapa-level-up.md |
| @@ -1110,6 +1110,10 @@ Phase 1's choices where this spec was silent, or where the build chose different |
| 56. **The draft bar's "Show the saved version" does not commit.** It is a link inside Mapa, so leaving would commit an own draft first, and `pagehide` would too; a plain click on a link in the bar stops the editor for that page instead, and the draft is left as it was. |
| 57. **A new page opens with the caret in its body** (§4.7): the editor takes focus at mount when the page's text is empty, except on a day (the home page), where focus would raise a phone's keyboard on every visit. |
| +**Smooth navigation** (Paul, 14 November: "clicking links should feel very smooth and solid"; §6.9): |
| + |
| +58. **A block link lands without a jump, and without script.** A block chip's address is `/p/{id}#b-…`, and the browser's own fragment scroll used to put the block at the window's top edge, under the 56px sticky bar, with nothing to say why the page had moved. Now `html` has `scroll-padding-block-start` of the bar plus 16px, so any in-page target (`#main`, a heading) clears the bar, and a block (`[id^="b-"]` in the page's body, so pages, days, scratch pages and History's versions alike) has a `scroll-margin-block-start` that puts its top 40% of the way down the view the bar leaves: 353px of a 1280×800 window, 389px of a 390×844 phone. 40% because a block starting there or above in the first screen (a page's title and its first few blocks, the usual target on Mapa's short pages) is not scrolled to at all, while a deep block still arrives in the upper part of the view, with what leads to it above and room for what follows; a page too short to scroll never moves. CSS cannot say "only if it is not already in view": a fragment always aligns the start, so a block starting between 40% and the first screen's foot is still moved up to 40%, by less than the screen. The block is tinted with the accent's soft fill, which holds and then fades over 1.8s; under `prefers-reduced-motion` it holds 1.5s and goes, without a fade. The tint is a box shadow (inset for the fill, spread 4px for its rim), so nothing is laid out again and a code block's own background stays under it. The editor draws the block anew as it mounts (here the server's `<ul>` is replaced before first paint); in Chromium and WebKit the new element does not match `:target` at `DOMContentLoaded`, but both match it again by the end of the load, and the tint's animation starts then, once (measured: one `mapa-arrive` animation, current time equal to the time since load). The gate (`TestABlockLinkLandsWithoutAJump`, `make browser`) clicks a chip to an early and a deep block at 1280×800 and 390×844, scripts off and on: the early one scrolls nothing, the deep one's top is within 2px of the 40% line, and both match `:target` and are tinted. Without the change it lands every block 0px under the bar's edge, which the gate catches. |
| + |
| ## 14. Findings and what changed |
diff --git a/internal/mapa/static/frame.css b/internal/mapa/static/frame.css| index a838310..fd1f70a 100644 |
| --- a/internal/mapa/static/frame.css |
| +++ b/internal/mapa/static/frame.css |
| @@ -9,7 +9,12 @@ |
| * stacks and the sidebar appears, and 64rem, where floating panels do. |
| */ |
| -html { scrollbar-gutter: stable; } |
| +/* Any in-page target (#main, a heading) lands clear of the sticky bar; |
| + a block (#b-…) lands lower still (prose.css). */ |
| +html { |
| + scrollbar-gutter: stable; |
| + scroll-padding-block-start: calc(var(--estilo-bar-block-size, 56px) + 16px); |
| +} |
| body { |
| --mapa-side-w: 224px; |
| --mapa-rail-w: 56px; |
diff --git a/internal/mapa/static/prose.css b/internal/mapa/static/prose.css| index 55c7ab4..4dfa1ce 100644 |
| --- a/internal/mapa/static/prose.css |
| +++ b/internal/mapa/static/prose.css |
| @@ -219,3 +219,43 @@ span[mapa-chip="embed"] { |
| white-space: nowrap; |
| } |
| span[mapa-chip="embed"] > svg[mapa-i] { color: var(--rst-text-faint); } |
| + |
| +/* ---- Arriving at a block (#b-…, a block chip's address). |
| + * Every in-page target clears the sticky bar (html, frame.css). A block |
| + * lands lower: 40% of the way down the view the bar leaves (353px of a |
| + * 1280x800 window, 389px of a 390x844 phone). So a block that starts |
| + * there or above in the first screen (a page's title and first few |
| + * blocks) is not scrolled to at all, and a deeper one arrives in the |
| + * upper part of the view, with what leads up to it above and room for |
| + * what follows. A page too short to scroll never moves. The browser |
| + * does all this before paint, without script. |
| + * The block is then tinted once, and the tint fades: a shadow, inset |
| + * for the tint and spread for its rim, so nothing is laid out again |
| + * and a code block's own background stays under it. The editor draws |
| + * the block anew as it mounts; the browser matches :target again by |
| + * the end of the load, so the tint is not lost (build note 58). */ |
| +:is([mapa-body], [mapa-prose]) [id^="b-"] { |
| + scroll-margin-block-start: max(0px, |
| + (100vh - var(--estilo-bar-block-size, 56px)) * 0.4 - 16px); |
| +} |
| +:is([mapa-body], [mapa-prose]) [id^="b-"]:target { |
| + border-radius: 6px; |
| + animation: mapa-arrive 1.8s ease-out; |
| +} |
| +@keyframes mapa-arrive { |
| + 0%, 35% { |
| + box-shadow: inset 0 0 0 100vmax var(--rst-accent-soft), |
| + 0 0 0 4px var(--rst-accent-soft); |
| + } |
| + 100% { |
| + box-shadow: inset 0 0 0 100vmax transparent, |
| + 0 0 0 4px transparent; |
| + } |
| +} |
| +/* No fade: the tint shows, still, and goes. */ |
| +@media (prefers-reduced-motion: reduce) { |
| + :is([mapa-body], [mapa-prose]) [id^="b-"]:target { |
| + animation-duration: 1.5s; |
| + animation-timing-function: step-end; |
| + } |
| +} |
diff --git a/internal/mapatest/navigation_browser_test.go b/internal/mapatest/navigation_browser_test.go| new file mode 100644 |
| index 0000000..3c50d46 |
| --- /dev/null |
| +++ b/internal/mapatest/navigation_browser_test.go |
| @@ -0,0 +1,109 @@ |
| +//go:build browser |
| + |
| +package mapatest |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "fmt" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/rastrillo/rastrillo/harness" |
| + "github.com/chromedp/chromedp" |
| + |
| + "amadan.net/oficina/mapa/internal/mapa" |
| +) |
| + |
| +// Navigation that feels solid (build note 58): a block link lands |
| +// without a jump. |
| + |
| +// longBody is forty paragraphs, ^early in the second and ^deep in the |
| +// thirtieth. |
| +func longBody() string { |
| + var paragraphs []string |
| + for number := 1; number <= 40; number++ { |
| + marker := map[int]string{2: " ^early", 30: " ^deep"}[number] |
| + paragraphs = append(paragraphs, fmt.Sprintf("Paragraph %d. %s%s", |
| + number, strings.Repeat("The quick brown fox jumps over "+ |
| + "the lazy dog. ", 3), marker)) |
| + } |
| + return strings.Join(paragraphs, "\n\n") |
| +} |
| + |
| +// landing is where the browser left the target block, and whether it |
| +// is tinted. |
| +type landing struct { |
| + ScrollY, Top, Bar, View float64 |
| + Target, Tinted bool |
| +} |
| + |
| +const readLanding = `JSON.stringify((function () { |
| + var block = document.querySelector(location.hash); |
| + var bar = document.querySelector("header[estilo-bar]"); |
| + return { scrollY: scrollY, top: block.getBoundingClientRect().top, |
| + bar: bar.getBoundingClientRect().height, view: innerHeight, |
| + target: block.matches(":target"), |
| + tinted: block.getAnimations().some(function (animation) { |
| + return animation.animationName === "mapa-arrive"; }) }; |
| +})())` |
| + |
| +// Block chips land the block without a jump: one in the first screen's |
| +// upper part scrolls nothing, a deep one lands 40% down the view below |
| +// the sticky bar, never under it, and both are tinted, with scripts |
| +// off and on (the editor redraws the block as it mounts). |
| +func TestABlockLinkLandsWithoutAJump(t *testing.T) { |
| + rig, store := browserRig(t, 0) |
| + ctx := context.Background() |
| + if _, err := store.CreateTeamPage(ctx, Bo, "Long notes", |
| + longBody()); err != nil { |
| + t.Fatal(err) |
| + } |
| + from, err := store.CreateTeamPage(ctx, Bo, "Jumper", |
| + "Early: [[Long notes#^early]]\n\nDeep: [[Long notes#^deep]]") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, live := range []bool{false, true} { |
| + for _, size := range [][2]int64{{1280, 800}, {390, 844}} { |
| + name := fmt.Sprintf("%dx%d scripts %v", size[0], size[1], live) |
| + early := land(t, rig, mapa.PagePath(from), "early", size, live) |
| + if early.ScrollY != 0 || !early.Target || !early.Tinted { |
| + t.Errorf("%s: the early block %+v", name, early) |
| + } |
| + deep := land(t, rig, mapa.PagePath(from), "deep", size, live) |
| + want := deep.Bar + (deep.View-deep.Bar)*0.4 |
| + if deep.ScrollY == 0 || deep.Top < want-2 || deep.Top > want+2 || |
| + !deep.Target || !deep.Tinted { |
| + t.Errorf("%s: the deep block %+v, want its top at %.0f", |
| + name, deep, want) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// land clicks the chip to a block and reads where the block is. |
| +func land(t *testing.T, rig *harness.Rig, from, block string, |
| + size [2]int64, live bool) landing { |
| + t.Helper() |
| + chip := `article[mapa-body] a[href$="#b-` + block + `"]` |
| + drive(t, rig, scripts(live), chromedp.EmulateViewport(size[0], size[1]), |
| + chromedp.Navigate(rig.Origin+from), chromedp.WaitVisible(chip)) |
| + if live { |
| + drive(t, rig, chromedp.WaitVisible(mounted)) |
| + } |
| + drive(t, rig, chromedp.Click(chip), |
| + chromedp.WaitVisible(`[id="b-`+block+`"]`)) |
| + if live { |
| + drive(t, rig, chromedp.WaitVisible(mounted)) |
| + } |
| + var seen landing |
| + eventually(t, "the block is the target", func() bool { |
| + raw := read(t, rig, chromedp.Evaluate[string](readLanding)) |
| + if err := json.Unmarshal([]byte(raw), &seen); err != nil { |
| + t.Fatal(err) |
| + } |
| + return seen.Target |
| + }) |
| + return seen |
| +} |