Skip to content

feat(map): let map mode be contained by an element, not only the viewport - #170

Merged
Ardnived merged 6 commits into
mainfrom
feat/contained-map
Aug 26, 2026
Merged

Ardnived merged 6 commits into
mainfrom
feat/contained-map

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

  • A map embed can now live inside an element on the host's page instead of only filling the browser window. Give <sahaj-atlas> a display: block and a height and the map stays in that box — the site's own header above it, content below, nothing painting over either.
  • The mechanism already existed and was generalized, not built. feat(widget): degrade to a compact card in a slot too small for the interface #161 solved both obstacles the old "this is intractable" comment named, for the compact card's expanded dialog. This turns "a modal dialog we own" into "whichever element has taken the containing block".
  • Sizing the element is the opt-in, which is what stops "contained map" and "compact card" both firing. An unsized map embed is bit-for-bit unchanged.

Changes

The frame is one element carrying contain: layout, which makes it the containing block for every fixed descendant. Nothing below it changes — the canvas, drawers and peek strips are byte-identical in both modes.

  • src/lib/overlay.ts — setDialog/expandedDialog become setFrame/frameElement: one singleton, two producers. Adds frameCollision().
  • src/views/MapFrame.tsx + src/hooks/use-frame.ts — the frame, and the adoption contract it shares with the dialog (node in state, children gated on it, published in the layout phase because overlayContainer() is read in render bodies).
  • src/lib/embed-slot.ts — mapMode() returns 'none' | 'viewport' | 'contained'; embedLayout takes it. Two booleans could express "contained, with no map".
  • src/styles/globals.css — --sy-frame-h: 100% keys off data-sy-frame; data-sy-expanded stays the narrower, dialog-only marker.
  • src/views/DrawerStack/DrawerStack.tsx — vaul's snap box, the --sy-sheet-top offset, the drawer direction and the cog offset all move onto the frame.
  • src/hooks/use-map-controller-real.tsx — camera padding leaves useIsWideViewport() for the same signal: it pads around a panel the frame now decides.

z-index

contain: layout makes the frame a stacking context, so the widget's z-30…z-50 stop competing with the host's CSS and their page orders the atlas as one element. A sticky header floats over the map the way it floats over any other content.

Verification

  • Lint OK · Types OK · Unit lane OK (1381) · Build OK · pnpm size OK (embed 302.7 / 310 KiB)

Measured in a browser

A new review page (pnpm review:embed -> contained-map.html) models the shape this exists for: a sticky z-index: 100 header, then a height: 640px element.

Result
Frame box 1228x640 — exactly the host's content box, in a 1280x900 viewport
Canvas, drawer, cog all resolve against the frame, not the viewport
Sticky header paints above the map; the map scrolls with the page
Narrow (600x560) bottom sheet; vaul's snap offset 260 = 560 - 300. Against the window it would be 600 — the sheet entirely below the box (#161's inversion)
--sy-sheet-top 260px, frame-relative, not the viewport's 479
Cog offset 400px with a panel, 12px with a bottom sheet (was 384px — clipped away at a 400px frame)
Unboxed map unchanged: no frame, canvas 1280x900, --sy-frame-h: 100dvh
Compact card dialog inset 16px, contained, focus restore and the Escape ladder intact

Notes for reviewer

Two defects both review passes found independently, and one changed the fix. A host writing min-height: 640px has a non-zero rect, so containment engaged — but height: 100% resolves against the parent's computed height, which is auto. Measured: frame 1148x0, everything gone, and the readiness marker still true. A warning alone would have been insufficient because it is a regression: that host got a working compact card before this. So the frame verifies its own box in the callback ref and refuses — releasing, rendering uncontained, and naming the rule to change.

One mistake worth flagging. I fixed the Radix popper collision boundary at two call sites; there were five across four components — the same "applied one place and not the other" error I had already made with the cog. It is now one helper with the inventory pinned by overlay.popper.test.ts, which immediately caught a fifth file I had missed.

Every new assertion was made to fail at its real site before being kept. One exception, stated rather than implied: contained: layout === 'contained' does not fail when reverted — the two expressions are equivalent on every current path. It removes a latent second representation, not a live bug, and no test covers it.

Declined findings. All four cleanup agents flagged that DrawerStack and the camera provider each mount a ResizeObserver on the same node. Every fix either moves setPadding outside the MapController seam or makes DrawerStack conditionally consume-vs-measure, rebuilding the two-sources-that-can-disagree shape WidgetWidthContext exists to prevent. Also declined: decideSlot's fail-open catch returns a viewport takeover — pre-existing, and changing that default is a behaviour decision beyond this ticket.

Not in scope, flagged. Wheel-zoom over a contained map will capture host page scroll. cooperativeGestures is the standard answer but costs one-finger pan on touch and needs locale strings across ten locales — its own decision.

Closes #169

🤖 Generated with Claude Code

Ardnived and others added 6 commits August 26, 2026 14:02
Map mode rendered the canvas `position: fixed; inset: 0` with every drawer
over it fixed too, so it filled the browser window whatever slot the host
gave `<sahaj-atlas>`. A site's own header could not sit above the atlas: a
static one was painted over, a sticky one floated above the map AND above
the widget's drawers.

Generalize the FRAME — the element the fixed layer resolves against — from
"the compact card's dialog" to "whichever element has taken the containing
block", and add a second one on the host's page. `contain: layout` does the
re-parenting, so nothing below changes: the canvas, the drawers and the peek
strips are byte-identical in both modes.

- `lib/overlay.ts`: `setDialog`/`expandedDialog` become `setFrame`/
  `frameElement`, one singleton with two reasons.
- `views/MapFrame.tsx`: the contained embed's own box. Publishes itself in a
  callback ref and holds its children back until it has, because
  `overlayContainer()` is read in render bodies.
- `--sy-frame-h: 100%` keys off `data-sy-frame`; `data-sy-expanded` stays the
  narrower, dialog-only marker.
- `DrawerStack` measures the frame for vaul's snap ladder, subtracts its top
  from `--sy-sheet-top`, and reads its width for the drawer direction.
- The camera padding leaves `useIsWideViewport` for the same frame signal: it
  pads around a panel the frame now decides, and the two boxes were only ever
  equal because map mode spanned the viewport.

Sizing the element is the opt-in, which is what stops "contained map" and
"compact card" both firing: a contained map is container-relative, so it asks
the floors question and never the viewport-ownership one. An unsized map
embed is bit-for-bit unchanged.

Closes #169

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The shape #169 exists for: a site's own sticky header, then the atlas
below it, with an explicit height on the element. Every page in this
server is a shape that has produced a bug, and this is the one where
containment is verifiable at all.

Also corrects `sidebar-map.html`'s note: its 300×520 element is now a
CONTAINED map, so its card is earned by the 360px width floor rather
than by map mode not owning the viewport — and the console says so.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The host-facing contract changed, so `docs/embedding.md` and `CHANGELOG.md`
change with it — including the reversal worth calling out: an explicit
height on `<sahaj-atlas>` used to produce the compact card, and now
produces a map inside that box.

Sizing is now one rule for both modes ("give the element a height and the
widget lives inside it"), with a table for what map mode does when you
don't. Adds the stacking answer a contained embed needs, and corrects the
`transform`/`filter`/`contain` warning: a contained map establishes that
containing block itself, so an outer one changes nothing — and reaching
for one to stop a map painting over the page now has a supported
alternative.

The rule files carry the argument rather than the conclusion.
`components.md`'s "map mode requires a full-page slot" section had gone
stale exactly as the ticket said, so it now records which premise was
retired where — every one of them in #161, for the expanded dialog —
and keeps the unchanged half: `contain: layout` still must never sit on
the scope root.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The harness comment said map mode needs a full-page slot and that giving
the element a height paints over the page. Both halves are now the
opposite of true.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Four cleanup agents over the branch diff. Substantive fixes:

- **`hasMap` + `contained` collapse into one `MapMode`.** Two booleans could
  express "contained, with no map", which is meaningless — the same argument
  `CompactAction` already makes for its own shape. `decideSlot` now derives
  `contained` from the layout `embedLayout` returned rather than from what it
  passed in, so one fact has one representation in the module whose whole
  justification is that the join is where the bug was. No behavioural
  difference today: the two expressions are equivalent on every current path,
  which is exactly why the second one is worth deleting before they diverge.
- **The frame-adoption block was hand-copied and had already drifted** within
  this branch — `MapFrame` grew an unmount effect its sibling never had, which
  could only ever be a second unconditional clear of a singleton. Extracted to
  `hooks/use-frame.ts`; the timing contract is stated once and `MapFrame`'s
  spec now covers both frames.
- **The cog offset stayed on the viewport** while the panel it clears moved to
  the frame — the identical argument this branch wrote out for the camera
  padding, applied one place and not the other. A 600px contained map pushed it
  384px right for a panel that is not there; a 400px frame clipped it away.
- **`100vw` on the fixed layer** (Modal, anchored panel, peek strip) describes a
  box those elements are not in once a frame contains them. `100%` on a fixed
  element already resolves against its containing block, so it is the same
  number outside a frame — the width half of what `--sy-frame-h` did for height.
  `max-w-md` is 448px and a frame can be 360.
- `data-sy-frame` is the whole JS↔CSS contract as a bare literal in three
  files; pinned, with the `WIDGET_SCOPE_CLASS` precedent.
- Three rows of the responsive decision table kept a premise this branch
  falsified ("viewport == container wherever they apply"). Prose is the only
  guard there — `responsive.test.ts` cannot see Tailwind variants.
- "A height cannot appear by accident" was one layout mode too strong: a
  stretched flex/grid item is sized with no rule naming the element. The signal
  is still right — that IS the host's layout saying where the widget goes — but
  hosts are told, since it is the one case where "unchanged unless you gave it
  a height" is not literally true.

Declined: hoisting the width measurement so `DrawerStack` and the camera
provider share one ResizeObserver. All four agents flagged the duplicate, and
it is real — but every variant either moves `setPadding` out of the
`MapController` seam or makes `DrawerStack` conditionally consume-vs-measure,
which reintroduces the two-sources-that-can-disagree shape `WidgetWidthContext`
exists to prevent, one level over. Two observers on a node that resizes with
the host's column is the cheaper of the two costs.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Two findings both review passes reached independently, plus their tail.

**A rect is not a fillable box.** `mapMode` opts an embed into containment
from `getBoundingClientRect().height`, which is non-zero for
`min-height: 640px` — while `height: 100%` on the frame resolves against the
parent's COMPUTED height, which is `auto`. The frame computed to 0, and since
it carries `contain: layout` the entire fixed layer resolved against a
zero-height containing block: map, drawers and cog all gone, with
`data-sahaj-atlas-ready` still attesting a healthy embed. Measured in Chrome
151 on a real host page (frame 1148x0, canvas collapsed, marker true).

Reporting alone would not have been enough, because it is a REGRESSION: that
same host got the compact card before #169 — a working button and the right
advice. So `ContainedFrame` verifies its own box in the callback ref, during
the layout phase and before any child has rendered into it, and refuses:
it releases the frame, renders its children uncontained (the viewport map
they would have had), and says which rule to change. `mapMode` additionally
requires both axes, which covers `display: inline-block; height: 640px` —
0x640, where the parent-column width fallback would otherwise clear the
floors and contain the map in a box with no width.

**Radix poppers still flipped against the window.** Their default collision
boundary is empty, which Floating UI reads as the viewport — correct while
the widget owned one. In a contained map a menu near the frame's bottom edge
places itself into the free browser window below and `overflow-hidden`
erases it: a control that does nothing, silently. `frameCollision()` is one
helper spread at all five surfaces, and `overlay.popper.test.ts` pins the
inventory — because this branch had already made exactly that mistake once,
moving the cog offset onto the measured signal in one place and leaving it a
viewport media query 480 lines away. The scan immediately caught a fifth file
I had missed, then caught itself matching a comment, which is why it strips
them like `responsive.test.ts` does.

Also: scope the `[data-vaul-drawer]` lookup to our own portal target rather
than the host's whole document (a host shipping vaul would win on document
order and we would write `--sy-sheet-top` onto their node every frame);
guard the rAF rect reads, where a patched `getBoundingClientRect` could kill
the loop permanently or a NaN could stop it ever parking; and replace the
sheet's last `3dvh`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: ee793f2
Status: ✅  Deploy successful!
Preview URL: https://0ec3bc52.sahajatlas.pages.dev
Branch Preview URL: https://feat-contained-map.sahajatlas.pages.dev

View logs

@Ardnived Ardnived closed this Aug 26, 2026
@Ardnived Ardnived reopened this Aug 26, 2026
@Ardnived
Ardnived merged commit a867929 into main Aug 26, 2026
8 checks passed
@Ardnived
Ardnived deleted the feat/contained-map branch August 26, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(map): let map mode be contained by an element, not only the viewport

1 participant