refactor(primitives): place compact hover cards by CSS anchor positioning

The compact card's side and bottom hold were computed in script from the
window size and the anchor's rect, measured again after the card mounted, and
kept current by scroll and resize listeners. The stylesheet now anchors the
card to its wrapper: beside the end edge, else the start edge, each also with
the card's bottom held at the viewport's margin.

A card that fits on neither side used to sit over its anchor, which left the
row under it unclickable. It now opens below the anchor from the anchor's
start edge, or above it; a card too tall for either stays in the viewport's
bottom end corner.
This commit is contained in:
LegGasai committed 2026-11-15 18:34:14 +08:00
1 parent 26a0c6ae02
commit 1d200479dc
10 files changed
+239 -147

No files matched your search

@@ -17,6 +17,48 @@
box-shadow: var(--dsw-shadow-lv3);
}
/* A compact card sits beside its anchor's end edge with its top on the
anchor's top: the insets keep it 8px from the anchor and from the viewport's
edges. When that would cross the viewport, the first fallback that fits
places it: beside the start edge; on either side with its bottom at the
viewport's margin; then, with room on neither side, below the anchor from
the anchor's start edge, or above it, so the card does not cover its anchor.
A card too tall for that holds the viewport's bottom and end margins.
Chromium tries five fallbacks, so there the browser's own overflow shift
keeps such a card inside the viewport instead, against its edges. */
.compact {
position-area: inline-end span-block-end;
inset: 0 8px 8px;
position-try-fallbacks:
flip-inline,
--dsh-hover-card-low,
--dsh-hover-card-low flip-inline,
--dsh-hover-card-below,
--dsh-hover-card-above,
--dsh-hover-card-held;
}
@position-try --dsh-hover-card-low {
position-area: inline-end span-all;
align-self: end;
}
@position-try --dsh-hover-card-below {
position-area: block-end span-inline-end;
inset: 8px 8px 8px 0;
}
@position-try --dsh-hover-card-above {
position-area: block-start span-inline-end;
inset: 8px 8px 8px 0;
}
@position-try --dsh-hover-card-held {
position-area: span-all;
justify-self: end;
align-self: end;
}
.copyable {
cursor: pointer;
}