day-card 0.3.4: the Background menu stays on the page where the toolbar wraps

The menu hangs from the Background button's right edge. Where the page is
narrow enough for the toolbar to wrap (about 1000px and less), the button
sits at the left and the 292px menu ran off the page's left edge: at
900px it spanned -105..185, and the first column, the reader's own
picture with its new remove badge among them, couldn't be reached. On
open it now hangs from the button's left edge (#bg-pop.left, origin top
left) when the button's right edge has less room than the menu's width.
Found while checking 0.3.3's badge.

Run on mote at 4191c523 + this change:
- bg-delete.gui.mjs, now at 1200, 900 and 420 wide with a check that the
  menu is within the page: 600 ok, all ok (Chromium and WebKit, five
  languages, mouse and touch).
- HOME=$(mktemp -d) bun test packages/day-card: 19 pass, 0 fail.
- bun scripts/check.mjs: exit 0.
The whole repo's bun test ran green at 4191c523 (8662 pass); this change
touches only day-card's page and its GUI script.
Broken by hand: without the toggle, "menu within the page" FAILs at
900px (-105..185).
Not tried: the live magpie window.
This commit is contained in:
yetone
2026-11-13 22:50:33 +08:00
parent 4191c52328
commit 8647819cd1
4 changed files with 14 additions and 5 deletions
+8 -4
View File
@@ -2,7 +2,8 @@
// at the picture's top-right corner, shown on hover with a mouse, on focus
// from the keyboard, and always on a touch screen. Removing it drops the
// picture from the saved options and a card drawn on it goes back to teal,
// with the menu left open. Drives the real page in Chromium and WebKit, in
// with the menu left open. The menu stays on the page where the toolbar
// wraps. Drives the real page in Chromium and WebKit, in
// every language, against a stub bridge.
// Run: NODE_PATH=<playwright's node_modules> node bg-delete.gui.mjs
import { readFileSync, existsSync } from "node:fs"
@@ -30,8 +31,9 @@ await (async () => {
const ok = (c, m) => { console.log((c ? "ok " : "FAIL ") + m); if (!c) bad++; };
for (const [name, type] of [["chromium", chromium], ["webkit", webkit]]) {
const browser = await type.launch();
for (const lang of Object.keys(words)) for (const touch of [false, true]) {
const ctx = await browser.newContext({ viewport: { width: 1200, height: 800 }, hasTouch: touch, isMobile: touch && name === "chromium" });
// 900 and 420 wrap the toolbar, so the Background button sits at the left
for (const width of [1200, 900, 420]) for (const lang of Object.keys(words)) for (const touch of [false, true]) {
const ctx = await browser.newContext({ viewport: { width, height: 800 }, hasTouch: touch, isMobile: touch && name === "chromium" });
const p = await ctx.newPage();
const errs = [];
p.on("pageerror", (e) => errs.push(String(e)));
@@ -46,7 +48,9 @@ await (async () => {
await p.goto("http://day.test/day/index.html");
await p.click("#bg");
await p.waitForSelector("#bg-del");
const tag = `${name} ${lang} ${touch ? "touch" : "mouse"}`;
const tag = `${name} ${width} ${lang} ${touch ? "touch" : "mouse"}`;
const pb = await p.locator("#bg-pop").boundingBox();
ok(pb.x >= 0 && pb.x + pb.width <= width, `${tag}: menu within the page (${Math.round(pb.x)}..${Math.round(pb.x + pb.width)})`);
const del = p.locator("#bg-del");
ok((await del.getAttribute("aria-label")) === words[lang], `${tag}: badge named ${words[lang]}`);
ok((await p.locator('.sw[data-bg="custom"]').getAttribute("aria-checked")) === "true", `${tag}: custom picked`);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/page-day-card",
"version": "0.3.3",
"version": "0.3.4",
"description": "A page in magpie's window that draws a day, week, month or all of your AI usage as a card: tokens, cost, each agent and its models, your streak and your average day. Copy it as a picture or save it as a PNG",
"files": ["page", "README.md", "NOTICE"],
"keywords": ["magpie", "magpie-page", "usage", "tokens", "cost", "card"],
+4
View File
@@ -694,6 +694,10 @@
function openPop() {
if (!grid.childElementCount) buildGrid();
pop.hidden = false;
// the menu hangs from the button's right edge; where the toolbar wrapped
// and the button sits at the left, that runs off the page, so it hangs
// from the button's left edge instead
pop.classList.toggle("left", $("bg").getBoundingClientRect().right < pop.offsetWidth + 8);
pop.classList.remove("closing");
pop.classList.add("opening");
$("bg").setAttribute("aria-expanded", "true");
+1
View File
@@ -41,6 +41,7 @@ canvas { display: block; width: 100%; height: auto; margin: 0 auto; border-radiu
#bg-chip { width: 14px; height: 14px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
#bg-pop { position: absolute; z-index: 2; top: calc(100% + 4px); right: 0; width: 292px; padding: 12px; display: flex; flex-direction: column; gap: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .18); transform-origin: top right; transition: opacity .18s cubic-bezier(.23, 1, .32, 1), transform .18s cubic-bezier(.23, 1, .32, 1); }
#bg-pop[hidden] { display: none; }
#bg-pop.left { right: auto; left: 0; transform-origin: top left; }
#bg-pop.closing, #bg-pop.opening { opacity: 0; transform: scale(.96); }
#bg-pop.closing { transition-duration: .12s; }
#bg-grid { display: grid; grid-template-columns: repeat(4, 60px); gap: 8px; justify-content: space-between; }