end to end app store screenshot creation using AI
TypeScript agentic-aiappleappstoreautomateclaudecursordesigngenerateiosios-appmarketingscreenshotskillsskills-shswiftswiftuiui
fix: tell the two iPhone Duo displays apart and measure bezels faster
Parth Jadhavc9be362f7178
diff --git a/skills/app-store-screenshots/template/docs/testing/e2e.md b/skills/app-store-screenshots/template/docs/testing/e2e.mdindex b520389..e2d4c60 100644--- a/skills/app-store-screenshots/template/docs/testing/e2e.md+++ b/skills/app-store-screenshots/template/docs/testing/e2e.md@@ -15,7 +15,7 @@ bun run test:e2eSCREENSHOTS_E2E_PRODUCTION=1 bun run test:e2e```-`bun run test:e2e` runs 56 tests: 53 tests that directly drive/inspect the product with Tester Army (30 in `tests/editor.e2e.ts`, 11 for Style Lab, Scene Playground and the magnifier in `tests/scene-style-lab.e2e.ts`, 12 for iPhone Duo, App Store creatives and the issue 41 export regression in `tests/targets.e2e.ts`), plus three tests that run 56 existing regression groups (35 browser/export, 12 UI, nine API). Nested loops cover every advertised device size, layout, orientation, theme and built-in font. Counts refer to test/group definitions, not every loop iteration.+`bun run test:e2e` runs 58 tests: 55 tests that directly drive/inspect the product with Tester Army (30 in `tests/editor.e2e.ts`, 11 for Style Lab, Scene Playground and the magnifier in `tests/scene-style-lab.e2e.ts`, 14 for iPhone Duo, App Store creatives and the issue 41 export regression in `tests/targets.e2e.ts`), plus three tests that run 56 existing regression groups (35 browser/export, 12 UI, nine API). Nested loops cover every advertised device size, layout, orientation, theme and built-in font. Counts refer to test/group definitions, not every loop iteration.For one direct regression:@@ -170,3 +170,16 @@ Two fixes came out of this:- **Bezel cutouts are now measured per corner** (`radii` in `/api/frames`) and the capture is clipped to that shape. The Duo's outer display is square on its hinge side and rounded on the other, so a single radius let the capture poke past the bezel's body.- **Turned poses are captured with the phone turned left.** That orientation matches Apple's landscape bezel, which has the camera top left.++### Duo capture checks and bezel measurement (9 October 2026)++Fixes from the review of PR #44.++- **Duo captures are matched within 0.5 %.** The two displays differ by 2.35 %, and the earlier 3 % tolerance let an outer capture pass as inner, so it was cropped without a warning. Other devices use 1 %, since every current iPhone capture size is within 0.4 %.+- **Inline (data URI) captures are decoded on load,** so their size is known after a reload.+- **Bezels are measured with a scanline flood fill over the alpha channel only.** All nine bundled bezels now measure in 250 ms instead of 2,065 ms (Node 24), with peak memory at 258 MB instead of 561 MB. The results are identical.++| Check | Result |+| --- | --- |+| New tests: an outer-display capture on the inner deck is flagged, served and inline | Both fail on the old code. The inline test still fails with only the tolerance fixed. Both pass with the fixes. |+| Dev Tester Army suite | 58/58 passed; all 56 harness groups passed |diff --git a/skills/app-store-screenshots/template/src/components/editor/device-frames.tsx b/skills/app-store-screenshots/template/src/components/editor/device-frames.tsxindex e1f3599..63fd750 100644--- a/skills/app-store-screenshots/template/src/components/editor/device-frames.tsx+++ b/skills/app-store-screenshots/template/src/components/editor/device-frames.tsx@@ -1,7 +1,7 @@"use client";import * as React from "react";import { MAC_RATIO, MAC_TITLE_BAR, PHONE_SCREEN } from "@/lib/constants";-import { bezelGeometry, type DuoDevice } from "@/lib/frame-assets";+import { bezelGeometry, isDuoDevice, type DuoDevice } from "@/lib/frame-assets";import type { Device } from "@/lib/types";import { img, imgSize } from "@/lib/image-cache";@@ -354,11 +354,16 @@ export function IPad({ src, alt = "", style, hideEmpty }: FrameProps) {// A capture whose aspect is off by more than this is letterboxed rather than// cropped: cropping would cut real UI, which is worse than a visible bar.-const FIT_TOLERANCE = 0.03;+// iPhone captures of every current size are within 0.4 % of the bezel's screen.+const FIT_TOLERANCE = 0.01;+// The two iPhone Duo displays differ by only 2.35 % (1398 × 2034 against+// 2007 × 2853), so Duo captures must match far more closely to tell an outer+// capture from an inner one. Scaled-down captures of the right display pass.+export const DUO_FIT_TOLERANCE = 0.005;-export function captureFits(src: string, screenAspect: number) {+export function captureFits(src: string, screenAspect: number, tolerance = FIT_TOLERANCE) {const size = imgSize(src);- return !size || Math.abs(size.w / size.h / screenAspect - 1) <= FIT_TOLERANCE;+ return !size || Math.abs(size.w / size.h / screenAspect - 1) <= tolerance;}// A device drawn under Apple's bezel (or, for iPhone Duo without one, a drawn@@ -415,7 +420,7 @@ function BezelFrame({ device, src, alt = "", style, hideEmpty }: FrameProps & {display: "block",width: "100%",height: "100%",- objectFit: device === "mac" || captureFits(src, g.screenAspect) ? "cover" : "contain",+ objectFit: device === "mac" || captureFits(src, g.screenAspect, isDuoDevice(device) ? DUO_FIT_TOLERANCE : undefined) ? "cover" : "contain",objectPosition: device === "mac" ? "top" : "center",}}draggable={false}diff --git a/skills/app-store-screenshots/template/src/components/editor/inspector.tsx b/skills/app-store-screenshots/template/src/components/editor/inspector.tsxindex e4c03e7..f5083b7 100644--- a/skills/app-store-screenshots/template/src/components/editor/inspector.tsx+++ b/skills/app-store-screenshots/template/src/components/editor/inspector.tsx@@ -77,7 +77,7 @@ import type {import { BackgroundControls } from "./background-controls";import { ScreenshotPicker } from "./screenshot-picker";import { CalloutControls } from "./callout-controls";-import { captureFits } from "./device-frames";+import { DUO_FIT_TOLERANCE, captureFits } from "./device-frames";import { calloutAvailable, getCanvas, getElementTransform } from "./slide-canvas";type Props = {@@ -296,7 +296,7 @@ export function Inspector({function CaptureNote({ device, src }: { device: Device; src: string }) {if (!isDuoDevice(device)) return null;const { w, h } = CANVAS[device];- const fits = !src || captureFits(src, duoGeometry(device).screenAspect);+ const fits = !src || captureFits(src, duoGeometry(device).screenAspect, DUO_FIT_TOLERANCE);return (<p className={cn("text-[11px] leading-relaxed", fits ? "text-muted-foreground" : "text-amber-600")}>{fitsdiff --git a/skills/app-store-screenshots/template/src/components/editor/screenshot-editor.tsx b/skills/app-store-screenshots/template/src/components/editor/screenshot-editor.tsxindex cd43ac4..f1f981f 100644--- a/skills/app-store-screenshots/template/src/components/editor/screenshot-editor.tsx+++ b/skills/app-store-screenshots/template/src/components/editor/screenshot-editor.tsx@@ -36,7 +36,7 @@ import type {import { Inspector } from "./inspector";import { PreviewStage } from "./preview-stage";import { Sidebar } from "./sidebar";-import { captureFits } from "./device-frames";+import { DUO_FIT_TOLERANCE, captureFits } from "./device-frames";import { DeckCanvas, getCanvas } from "./slide-canvas";import { StyleLab } from "./style-lab";import { Toolbar } from "./toolbar";@@ -110,7 +110,10 @@ export function ScreenshotEditor() {const allSlides: Slide[] = Object.values(state.slidesByDevice).flat();for (const s of allSlides) {for (const raw of [s.screenshot, s.screenshotSecondary]) {- if (!raw || raw.startsWith("data:")) continue;+ if (!raw) continue;+ // Inline (data URI) captures are decoded too, so their size is known+ // after a reload and a mismatched Duo capture is still flagged.+ if (raw.startsWith("data:")) { paths.add(raw); continue; }if (raw.includes("{locale}")) {for (const loc of state.locales) paths.add(resolveScreenshot(raw, loc));} else {@@ -123,7 +126,8 @@ export function ScreenshotEditor() {}return Array.from(paths).sort();}, [state.slidesByDevice, state.appIcon, state.locales, state.device, framesLoaded]);- const assetSig = assetPaths.join("|");+ // Inline captures can be megabytes long; a length and tail stand in for them.+ const assetSig = assetPaths.map((p) => (p.startsWith("data:") ? `data:${p.length}:${p.slice(-48)}` : p)).join("|");React.useEffect(() => {// Wait for the bezel measurements, so the first paint already has the@@ -490,7 +494,7 @@ export function ScreenshotEditor() {// cropped or stretched, so name it rather than let it pass unnoticed.const fitsDisplay = (raw: string | undefined, display: Device) =>!raw || !isDuoDevice(display) ||- locales.every((loc) => captureFits(resolveScreenshot(raw, loc), duoGeometry(display).screenAspect));+ locales.every((loc) => captureFits(resolveScreenshot(raw, loc), duoGeometry(display).screenAspect, DUO_FIT_TOLERANCE));const mismatched = isDuoDevice(device)? currentSlides.filter((slide) =>slideNeedsScreenshot(device, slide) &&diff --git a/skills/app-store-screenshots/template/src/lib/image-cache.ts b/skills/app-store-screenshots/template/src/lib/image-cache.tsindex b5993d4..edea24c 100644--- a/skills/app-store-screenshots/template/src/lib/image-cache.ts+++ b/skills/app-store-screenshots/template/src/lib/image-cache.ts@@ -10,6 +10,14 @@ const pending = new Map<string, Promise<void>>();async function fetchAsDataUrl(path: string): Promise<{ data: string; w: number; h: number } | null> {try {+ // A capture saved inline in the project is already a data URI: just decode+ // it, so its size is known (frames and warnings check a capture's aspect).+ if (path.startsWith("data:")) {+ const image = new Image();+ image.src = path;+ await image.decode();+ return { data: path, w: image.naturalWidth, h: image.naturalHeight };+ }const resp = await fetch(path, { signal: AbortSignal.timeout(10000) });if (!resp.ok) return null;const blob = await resp.blob();diff --git a/skills/app-store-screenshots/template/src/lib/measure-frame.ts b/skills/app-store-screenshots/template/src/lib/measure-frame.tsindex 73e4f0a..d1530e1 100644--- a/skills/app-store-screenshots/template/src/lib/measure-frame.ts+++ b/skills/app-store-screenshots/template/src/lib/measure-frame.ts@@ -11,33 +11,58 @@ const CLEAR_ALPHA = 24;* cut-ins are opaque islands inside that region, so they don't move the box.*/export async function measureFrame(bytes: Buffer, src: string): Promise<MeasuredFrame> {- const { data, info } = await sharp(bytes).ensureAlpha().raw().toBuffer({ resolveWithObject: true });- const { width, height, channels } = info;- const clear = (x: number, y: number) => data[(y * width + x) * channels + 3] <= CLEAR_ALPHA;+ // Only the alpha channel matters: one byte per pixel instead of four.+ const { data: alpha, info } = await sharp(bytes).ensureAlpha().extractChannel(3).raw().toBuffer({ resolveWithObject: true });+ const { width, height } = info;const cx = Math.floor(width / 2);const cy = Math.floor(height / 2);- if (!clear(cx, cy)) {+ if (alpha[cy * width + cx] > CLEAR_ALPHA) {throw new Error("the centre of the image is not transparent; export the bezel with an empty screen");}+ // Scanline flood fill from the centre: each popped seed fills its whole row+ // span, then seeds one pixel per unseen clear run in the rows above and below.+ // A 4K TV cutout is millions of pixels, so nothing is allocated per pixel.const seen = new Uint8Array(width * height);- const stack = [cy * width + cx];- seen[stack[0]] = 1;+ const open = (i: number) => !seen[i] && alpha[i] <= CLEAR_ALPHA;+ let stack = new Int32Array(1024);+ let top = 0;+ const push = (i: number) => {+ if (top === stack.length) {+ const grown = new Int32Array(stack.length * 2);+ grown.set(stack);+ stack = grown;+ }+ stack[top++] = i;+ };+ push(cy * width + cx);let minX = cx, maxX = cx, minY = cy, maxY = cy;- while (stack.length) {- const index = stack.pop()!;- const x = index % width;- const y = (index - x) / width;- if (x < minX) minX = x;- if (x > maxX) maxX = x;+ while (top) {+ const seed = stack[--top];+ if (!open(seed)) continue;+ const y = (seed / width) | 0;+ const row = y * width;+ let left = seed - row;+ let right = left;+ while (left > 0 && open(row + left - 1)) left--;+ while (right < width - 1 && open(row + right + 1)) right++;+ seen.fill(1, row + left, row + right + 1);+ if (left < minX) minX = left;+ if (right > maxX) maxX = right;if (y < minY) minY = y;if (y > maxY) maxY = y;- for (const [nx, ny] of [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]) {- if (nx < 0 || ny < 0 || nx >= width || ny >= height) continue;- const next = ny * width + nx;- if (seen[next] || !clear(nx, ny)) continue;- seen[next] = 1;- stack.push(next);+ for (const ny of [y - 1, y + 1]) {+ if (ny < 0 || ny >= height) continue;+ const nrow = ny * width;+ let inRun = false;+ for (let x = left; x <= right; x++) {+ if (open(nrow + x)) {+ if (!inRun) push(nrow + x);+ inRun = true;+ } else {+ inRun = false;+ }+ }}}if (minX === 0 || minY === 0 || maxX === width - 1 || maxY === height - 1) {diff --git a/skills/app-store-screenshots/template/tests/targets.e2e.ts b/skills/app-store-screenshots/template/tests/targets.e2e.tsindex cccd597..60755c8 100644--- a/skills/app-store-screenshots/template/tests/targets.e2e.ts+++ b/skills/app-store-screenshots/template/tests/targets.e2e.ts@@ -193,3 +193,25 @@ test('duo folded + open pairs the other display and never reuses the front captuawait expect(screen.getByText('Export includes placeholder screenshots', { exact: true })).toBeVisible();await expect(browser.locator('[data-sonner-toast]').first()).toContainText('1 screen will export with an empty device.');});++// The two Duo displays differ in shape by only 2.35 %, so an outer capture on the+// inner deck must still be flagged (and letterboxed), whether it is served from a+// URL or saved inline in the project, where its size is only known after decoding.+const outerCapture = '<svg xmlns="http://www.w3.org/2000/svg" width="1398" height="2034"><rect width="1398" height="2034" fill="#0ea5e9"/></svg>';+for (const [how, screenshot] of [+ ['served', '/screenshots/duo/outer.svg'],+ ['inline', `data:image/svg+xml;base64,${Buffer.from(outerCapture).toString('base64')}`],+] as const) {+ test(`an outer-display capture on the inner deck is flagged (${how})`, async ({ app, browser, screen }) => {+ await browser.route('**/screenshots/duo/outer.svg', route => route.fulfill({ body: outerCapture, headers: { 'content-type': 'image/svg+xml' } }));+ await mock(browser, project('duo-inner', { 'duo-inner': [slide('Wrong display', 'hero', { screenshot })] }));+ await app.open('/');+ await expect(screen.getByRole('textbox', 'Headline')).toHaveValue('Wrong display');+ await expect(screen.getByText(/isn't 2007 × 2853/)).toBeVisible();+ // Letterboxed, never cropped.+ await eventually(async () => {+ const fits = await browser.evaluate(() => [...document.querySelectorAll('main img')].map(i => getComputedStyle(i).objectFit));+ await expect(fits).toContain('contain');+ });+ });+}