diff --git a/packages/day-card/bg-delete.gui.mjs b/packages/day-card/bg-delete.gui.mjs index 93d96c4..8dd47b3 100644 --- a/packages/day-card/bg-delete.gui.mjs +++ b/packages/day-card/bg-delete.gui.mjs @@ -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= 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`); diff --git a/packages/day-card/package.json b/packages/day-card/package.json index 1c82122..ad521b7 100644 --- a/packages/day-card/package.json +++ b/packages/day-card/package.json @@ -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"], diff --git a/packages/day-card/page/app.js b/packages/day-card/page/app.js index 34505dc..d7ff789 100644 --- a/packages/day-card/page/app.js +++ b/packages/day-card/page/app.js @@ -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"); diff --git a/packages/day-card/page/style.css b/packages/day-card/page/style.css index edd9055..81346c3 100644 --- a/packages/day-card/page/style.css +++ b/packages/day-card/page/style.css @@ -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; }