Public: anyone can read this; the crew can change it.
Home tiles on a phone: thumbnails are 200×125 corner crops upscaled 1.8×, status badge stretches full width, hero CTA touches the grid #10038
scout/forge:scout/473-home-tiles-on-a-phone-thumbnails-are-200 → main 3 commits fork
8 files
changed +59
−12
src/core/looks.ts +17 −3
| @@ -16,15 +16,29 @@ export const isLookKind = (value: string): value is LookKind => | ||
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * The three widths, as a person holds them: a phone, a laptop's window, and |
| 19 | * a thumbnail — taken at the size a slot actually shows, at desktop's own | |
| 20 | * aspect, rather than a full picture squeezed into a small box. | |
| 19 | * a thumbnail — the picture's own pixel size. The window each is taken in | |
| 20 | * is `LOOK_VIEWPORTS`. | |
| 21 | 21 | */ |
| 22 | 22 | export const LOOK_SIZES: Readonly< |
| 23 | 23 | Record<LookKind, { readonly width: number; readonly height: number }> |
| 24 | 24 | > = { |
| 25 | 25 | phone: { width: 390, height: 844 }, |
| 26 | 26 | desktop: { width: 1280, height: 800 }, |
| 27 | thumb: { width: 200, height: 125 }, | |
| 27 | thumb: { width: 640, height: 400 }, | |
| 28 | }; | |
| 29 | ||
| 30 | /** | |
| 31 | * The window each picture is taken in, and the scale it is written at. A | |
| 32 | * thumb is the whole desktop window drawn at half size — 1280×800 seen at | |
| 33 | * 0.5 is 640×400 — not a corner of it, so a tile shows the page, and its 2× | |
| 34 | * is the desktop picture itself. | |
| 35 | */ | |
| 36 | export const LOOK_VIEWPORTS: Readonly< | |
| 37 | Record<LookKind, { readonly width: number; readonly height: number; readonly scale: number }> | |
| 38 | > = { | |
| 39 | phone: { width: 390, height: 844, scale: 1 }, | |
| 40 | desktop: { width: 1280, height: 800, scale: 1 }, | |
| 41 | thumb: { width: 1280, height: 800, scale: 0.5 }, | |
| 28 | 42 | }; |
| 29 | 43 | |
| 30 | 44 | /** A look with no page recorded — every row before `app.looks` existed. */ |
src/looks/capture.ts +3 −1
| @@ -46,6 +46,8 @@ export interface LookInput { | ||
| 46 | 46 | readonly out: string; |
| 47 | 47 | readonly width: number; |
| 48 | 48 | readonly height: number; |
| 49 | /** Device scale factor: 0.5 writes the window at half size. */ | |
| 50 | readonly scale?: number | undefined; | |
| 49 | 51 | /** A browser that has no picture by then is killed; the look fails. */ |
| 50 | 52 | readonly timeoutMs: number; |
| 51 | 53 | } |
| @@ -141,7 +143,7 @@ async function shoot( | ||
| 141 | 143 | // The app's hostname is the forge's own listener: no DNS, no edge. |
| 142 | 144 | `--host-resolver-rules=MAP ${host} 127.0.0.1`, |
| 143 | 145 | `--window-size=${input.width},${input.height}`, |
| 144 | "--force-device-scale-factor=1", | |
| 146 | `--force-device-scale-factor=${input.scale ?? 1}`, | |
| 145 | 147 | "--js-flags=--max-old-space-size=256", |
| 146 | 148 | `--timeout=${LOAD_MS}`, |
| 147 | 149 | `--screenshot=${input.out}`, |
src/looks/service.ts +2 −2
| @@ -34,7 +34,7 @@ import { | ||
| 34 | 34 | deleteLooks, |
| 35 | 35 | DEFAULT_PAGE, |
| 36 | 36 | LOOK_KINDS, |
| 37 | LOOK_SIZES, | |
| 37 | LOOK_VIEWPORTS, | |
| 38 | 38 | lookSlot, |
| 39 | 39 | looksForEnv, |
| 40 | 40 | recordLook, |
| @@ -319,7 +319,7 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle { | ||
| 319 | 319 | const taken = await capture({ |
| 320 | 320 | url, |
| 321 | 321 | out: staged, |
| 322 | ...LOOK_SIZES[kind], | |
| 322 | ...LOOK_VIEWPORTS[kind], | |
| 323 | 323 | timeoutMs: CAPTURE_TIMEOUT_MS, |
| 324 | 324 | }); |
| 325 | 325 | const row = { |
src/web/studio/home.ts +8
| @@ -227,11 +227,19 @@ export function studioDoor(ctx: Ctx): Response { | ||
| 227 | 227 | ); |
| 228 | 228 | const look = pictured(ofApp, "thumb") ?? pictured(ofApp, "desktop"); |
| 229 | 229 | const base = repoBase(repo); |
| 230 | // The thumb is half the desktop picture; the desktop one is its 2×. | |
| 231 | const sharp = | |
| 232 | look?.kind === "thumb" ? pictured(ofApp, "desktop") : undefined; | |
| 233 | const srcset = | |
| 234 | look !== undefined && sharp !== undefined | |
| 235 | ? `${lookUrl(base, "production", look.commitOid, DEFAULT_PAGE, "thumb")} 1x, ${lookUrl(base, "production", sharp.commitOid, DEFAULT_PAGE, "desktop")} 2x` | |
| 236 | : undefined; | |
| 230 | 237 | return html`<a class="app-tile" href="${base}"> |
| 231 | 238 | ${look |
| 232 | 239 | ? html`<img |
| 233 | 240 | class="app-tile-look" |
| 234 | 241 | src="${lookUrl(base, "production", look.commitOid, DEFAULT_PAGE, look.kind)}" |
| 242 | ${srcset === undefined ? null : html`srcset="${srcset}"`} | |
| 235 | 243 | width="${LOOK_SIZES[look.kind].width}" |
| 236 | 244 | height="${LOOK_SIZES[look.kind].height}" |
| 237 | 245 | alt="" |
src/web/style/content.ts +3 −2
| @@ -363,7 +363,7 @@ form.inline { display: inline; margin-left: auto; } | ||
| 363 | 363 | .lineage .row[aria-current="page"] { background: var(--muted); } |
| 364 | 364 | @media (max-width: 719px) { .lineage-children { margin-left: 12px; } } |
| 365 | 365 | |
| 366 | .hero { max-width: 620px; margin: 12dvh auto 0; text-align: center; } | |
| 366 | .hero { max-width: 620px; margin: 12dvh auto 32px; text-align: center; } | |
| 367 | 367 | .hero h1 { font-size: clamp(30px, 7vw, 44px); letter-spacing: -0.04em; line-height: 1.05; } |
| 368 | 368 | .hero p { margin: 12px 0 24px; font-size: 16px; color: var(--muted-fg); text-wrap: pretty; } |
| 369 | 369 | .hero-terminal { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 6px 14px; margin: -8px 0 28px; font-size: 14px; } |
| @@ -381,12 +381,13 @@ form.inline { display: inline; margin-left: auto; } | ||
| 381 | 381 | overflow: hidden; background: var(--card); color: inherit; text-decoration: none; |
| 382 | 382 | } |
| 383 | 383 | .app-tile:hover { border-color: var(--accent); } |
| 384 | .app-tile-look { display: block; width: 100%; height: auto; background: var(--muted); } | |
| 384 | .app-tile-look { display: block; width: 100%; height: auto; aspect-ratio: 8 / 5; object-fit: cover; object-position: top; background: var(--muted); } | |
| 385 | 385 | .app-tile-blank { |
| 386 | 386 | display: flex; align-items: center; justify-content: center; |
| 387 | 387 | aspect-ratio: 1280 / 800; background: var(--muted); color: var(--muted-fg); |
| 388 | 388 | } |
| 389 | 389 | .app-tile-body { display: grid; gap: 6px; padding: 10px 12px; } |
| 390 | .app-tile-body .badge { justify-self: start; } | |
| 390 | 391 | .app-tile-name { font-weight: 600; font-size: 14px; } |
| 391 | 392 | .app-tile-desc { color: var(--muted-fg); font-size: 12.5px; } |
| 392 | 393 |
test/home-tiles.test.ts added +21
| @@ -0,0 +1,21 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { LOOK_SIZES, LOOK_VIEWPORTS } from "../src/core/looks.ts"; | |
| 3 | import { content } from "../src/web/style/content.ts"; | |
| 4 | ||
| 5 | describe("home tiles", () => { | |
| 6 | test("a thumb is the whole desktop window at half size", () => { | |
| 7 | const v = LOOK_VIEWPORTS.thumb; | |
| 8 | expect(v).toEqual({ ...LOOK_VIEWPORTS.desktop, scale: 0.5 }); | |
| 9 | expect(LOOK_SIZES.thumb).toEqual({ | |
| 10 | width: v.width * v.scale, | |
| 11 | height: v.height * v.scale, | |
| 12 | }); | |
| 13 | }); | |
| 14 | ||
| 15 | test("the picture is covered from the top, the badge shrinks, the hero clears the grid", () => { | |
| 16 | expect(content).toMatch(/\.app-tile-look \{[^}]*object-fit: cover; object-position: top/); | |
| 17 | expect(content).toMatch(/\.app-tile-body \.badge \{ justify-self: start; \}/); | |
| 18 | const hero = /\.hero \{[^}]*margin: 12dvh auto (\d+)px;/.exec(content); | |
| 19 | expect(Number(hero?.[1])).toBeGreaterThanOrEqual(24); | |
| 20 | }); | |
| 21 | }); |
test/looks.test.ts +3 −2
| @@ -209,8 +209,9 @@ describe("the look", () => { | ||
| 209 | 209 | expect(readdirSync(join(dataDir, "looks", ".taking"))).toEqual([]); |
| 210 | 210 | const phone = calls.find((c) => c.width === 390)!; |
| 211 | 211 | expect(phone.height).toBe(844); |
| 212 | expect(calls.find((c) => c.width === 1280)?.height).toBe(800); | |
| 213 | expect(calls.find((c) => c.width === 200)?.height).toBe(125); | |
| 212 | expect(calls.find((c) => c.width === 1280 && c.scale === 1)?.height).toBe(800); | |
| 213 | expect(calls.filter((c) => c.width === 1280)).toHaveLength(2); | |
| 214 | expect(calls.find((c) => c.scale === 0.5)?.height).toBe(800); | |
| 214 | 215 | const url = new URL(phone.url); |
| 215 | 216 | expect(url.host).toBe(`hello.${DOMAIN}:${servers.port}`); |
| 216 | 217 | expect(url.pathname).toBe("/__forge/grant"); |
test/studio.test.ts +2 −2
| @@ -1448,8 +1448,8 @@ describe("the studio", () => { | ||
| 1448 | 1448 | ); |
| 1449 | 1449 | expect(tile).toBeDefined(); |
| 1450 | 1450 | expect(tile).toContain(`/looks/production/${commit}/thumb.png`); |
| 1451 | expect(tile).toContain('width="200"'); | |
| 1452 | expect(tile).toContain('height="125"'); | |
| 1451 | expect(tile).toContain('width="640"'); | |
| 1452 | expect(tile).toContain('height="400"'); | |
| 1453 | 1453 | }); |
| 1454 | 1454 | |
| 1455 | 1455 | test("the front door's tile still renders at desktop's size for a commit from before thumbs existed (#287)", async () => { |
new above
offline