diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 282b8c76..23061702 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -5,7 +5,7 @@ "plugins": [ { "name": "visualci", - "version": "0.1.27", + "version": "0.1.28", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 12db3312..1dcbda3c 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.27", + "version": "0.1.28", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index dd1ada1c..603f596c 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "visualci", "displayName": "VisualCI", - "version": "0.1.27", + "version": "0.1.28", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring" diff --git a/gemini-extension.json b/gemini-extension.json index aac4b8dd..003f6b5f 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.27", + "version": "0.1.28", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "mcpServers": { "visualci": { diff --git a/scripts/screenshots/capture.mjs b/scripts/screenshots/capture.mjs index 57457959..30498185 100644 --- a/scripts/screenshots/capture.mjs +++ b/scripts/screenshots/capture.mjs @@ -91,14 +91,14 @@ async function main() { ], }) const contexts = new Map() - async function context(variant, signedIn) { - const key = `${variant}/${signedIn}` + async function context(variant, signedIn, scale = 1) { + const key = `${variant}/${signedIn}/${scale}` if (contexts.has(key)) return contexts.get(key) const [width, theme] = variant.split('-') const ctx = await browser.newContext({ baseURL: opts.baseUrl, viewport: { width: Number(width), height: 900 }, - deviceScaleFactor: 1, + deviceScaleFactor: scale, colorScheme: theme, reducedMotion: 'reduce', locale: 'en-US', @@ -141,8 +141,11 @@ async function main() { let count = 0 for (const [name, target, signedIn, variants] of pages()) { if (opts.only && !name.includes(opts.only)) continue - for (const variant of variants) { - const ctx = await context(variant, signedIn) + // Each screenshot at 1x (the baseline VisualCI compares). The app's, which the public gallery publishes, again at 2x + // (`-2x`) for high-density screens: visualci.com's own pages use it in their srcset. + const scales = name.startsWith('app/') ? [1, 2] : [1] + for (const [variant, scale] of variants.flatMap((v) => scales.map((x) => [v, x]))) { + const ctx = await context(variant, signedIn, scale) const page = await ctx.newPage() const api = async (path) => { const res = await ctx.request.get(path) @@ -154,7 +157,7 @@ async function main() { if (!response || response.status() >= 400) throw new Error(`${name}: ${path} gave HTTP ${response?.status()}`) await settle(page) await unstick(page) - const file = join(opts.out, `${name}/${variant}.png`) + const file = join(opts.out, `${name}/${variant}${scale === 2 ? '-2x' : ''}.png`) await mkdir(dirname(file), { recursive: true }) await page.screenshot({ path: file, fullPage: true, animations: 'disabled', caret: 'hide' }) await page.close() diff --git a/server/frontend/content/docs/agents.md b/server/frontend/content/docs/agents.md index eda4473a..1d794191 100644 --- a/server/frontend/content/docs/agents.md +++ b/server/frontend/content/docs/agents.md @@ -39,7 +39,7 @@ claude mcp add --transport http visualci https://mcp.visualci.com/mcp \ 1. CI sends a build and finishes. When something changed, the CI job still passes, and the pull request's VisualCI check stays pending. 2. The agent calls `list_builds` or `get_build` to see what needs attention: changed, added, removed and failed snapshots. -3. For each change, it calls `get_snapshot`. For PDFs and images that returns the base, head and diff images of the changed pages, the changed regions, the page's text diff, and lines that moved to another page. For text, JSON and HTML snapshots it returns the changes by JSON path (`items[3].price: 10 → 12`) and a unified diff. +3. For each change, it calls `get_snapshot`. For PDFs and images that returns the base, head and diff images of the changed pages, the changed regions, the page's text diff, and lines that moved to another page. For text, JSON and HTML snapshots it returns the changes by JSON path (`items[3].price: 10 → 12`) and a unified diff. A contact sheet is for finding the changes, not for judging them: its thumbnails are too small to show a button covering a tab or a missing style. Open every sizeable UI change with `get_snapshot` and `crop: "changed"`, which shows the changed regions at full size. 4. The agent checks each change against the code and the task: - **Intended:** it calls `review` with `approve`. The approved snapshots become the baseline, and the check turns green. No new commit or CI run is needed. - **A bug:** it fixes the code and pushes again. The next build is compared with the same baseline. diff --git a/server/frontend/scripts/prerender.mjs b/server/frontend/scripts/prerender.mjs index 3eb0c547..a9065f93 100644 --- a/server/frontend/scripts/prerender.mjs +++ b/server/frontend/scripts/prerender.mjs @@ -176,67 +176,114 @@ async function galleryManifest() { const escapeHtml = (s) => s.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"') -/** A group's screenshots by screen: `screenshots/app/billing/free/1440-dark` is the screen `billing/free` at - * `1440-dark`. Light before dark, wide before narrow. */ -function screens(items) { - const byScreen = new Map() - for (const item of items) { - const parts = item.name.split('/') - const variant = parts.pop() - const screen = parts.filter((p, i) => !(i === 0 && p === 'screenshots')).join('/') || item.name - if (!byScreen.has(screen)) byScreen.set(screen, []) - byScreen.get(screen).push({ ...item, variant }) - } - const order = (v) => [-(parseInt(v, 10) || 0), v.includes('dark') ? 1 : 0] - for (const list of byScreen.values()) { - list.sort((a, b) => { - const [aw, ad] = order(a.variant) - const [bw, bd] = order(b.variant) - return aw - bw || ad - bd - }) +/** `screenshots/app/billing/free/1440-dark-2x` → the screen `app/billing/free`, desktop, dark, 2x. A name that isn't + * `-` is its own screen, shown as it is. */ +function parseShot(name) { + const parts = name.split('/') + const last = parts.pop() + const m = /^(\d+)-(light|dark)(-2x)?$/.exec(last) + const screen = parts.filter((p, i) => !(i === 0 && p === 'screenshots')).join('/') + if (!m) return { screen: parts.length ? `${screen}/${last}` : last, device: 'desktop', theme: 'light', x2: false } + return { screen, device: Number(m[1]) >= 768 ? 'desktop' : 'phone', theme: m[2], x2: !!m[3] } +} + +/** The page's sections, each a list of screens with their versions ({device, theme, url, url2x, width, height}). + * Screens under `app/` are the web app (on desktop and phone, whichever groups they came from); the rest are the + * site. */ +function gallerySections(manifest) { + const sections = new Map() + for (const group of manifest.groups) { + for (const item of group.items) { + const shot = parseShot(item.name) + const key = shot.screen.startsWith('app/') ? 'app' : 'site' + if (!sections.has(key)) { + const title = key === 'app' ? 'The web app' : 'visualci.com and its docs' + sections.set(key, { key, title, screens: new Map() }) + } + const screens = sections.get(key).screens + if (!screens.has(shot.screen)) screens.set(shot.screen, new Map()) + const versions = screens.get(shot.screen) + const vkey = `${shot.device}-${shot.theme}` + const v = versions.get(vkey) ?? { device: shot.device, theme: shot.theme } + if (shot.x2) v.url2x = item.url + else Object.assign(v, { url: item.url, width: item.width, height: item.height }) + versions.set(vkey, v) + } } - return [...byScreen].map(([screen, variants]) => ({ screen, variants })) + const order = ['app', 'site'] + return [...sections.values()] + .sort((a, b) => order.indexOf(a.key) - order.indexOf(b.key)) + .map((s) => ({ + ...s, + screens: [...s.screens] + .map(([screen, versions]) => ({ screen, versions: [...versions.values()].filter((v) => v.url) })) + .filter((s) => s.versions.length) + .sort((a, b) => screenOrder(a.screen) - screenOrder(b.screen) || a.screen.localeCompare(b.screen)), + })) } -const variantLabel = (v) => v.replace(/^(\d+)-/, '$1 px, ') +/** The homepage first, then the docs home, then the rest by name. */ +const screenOrder = (screen) => (screen === 'landing' ? 0 : screen === 'docs/index' ? 1 : 2) + +/** `app/billing/free` → "Billing, free"; `docs/ci/github-actions` → "Docs: CI, GitHub Actions"; `landing` → + * "Homepage". */ +function screenTitle(screen) { + const words = { ci: 'CI', api: 'API', cli: 'CLI', pdf: 'PDF', json: 'JSON', html: 'HTML', github: 'GitHub', gitlab: 'GitLab', circleci: 'CircleCI', rspec: 'RSpec', vitest: 'Vitest', jest: 'Jest', insta: 'insta', syrupy: 'syrupy', buildkite: 'Buildkite' } + const word = (w) => w.split('-').map((p) => words[p] ?? p).join(' ') + const cap = (t) => t.charAt(0).toUpperCase() + t.slice(1) + if (screen === 'landing') return 'Homepage' + if (screen === 'docs/index') return 'Docs home' + const parts = screen.split('/') + if (parts[0] === 'docs') return `Docs: ${parts.slice(1).map((p) => cap(word(p))).join(', ')}` + if (parts[0] === 'app') parts.shift() + return cap(parts.map(word).join(', ')) +} + +/** The version a card shows for a theme and device: exactly that, else the same device, else the same theme, else any. */ +function pickVersion(versions, device, theme) { + return ( + versions.find((v) => v.device === device && v.theme === theme) ?? + versions.find((v) => v.device === device) ?? + versions.find((v) => v.theme === theme) ?? + versions[0] + ) +} function galleryHtml(manifest) { - const intro = `

Screenshots VisualCI's own tests take of its web app and this site, as approved on main. They come from VisualCI's public gallery, so they change when a change to them is approved. As JSON: visualci.json.

` + const intro = `

Every screen of VisualCI's web app, light and dark, on a desktop and on a phone. VisualCI's own tests take them, and they come from its public gallery, so each one changes when it is approved. As JSON: visualci.json.

` if (!manifest?.groups?.length) { - return `${intro}` + return `${intro}` } - const groups = manifest.groups.map((g, gi) => { - const id = `shots-${g.name.toLowerCase().replace(/[^a-z0-9]+/g, '-')}` - const cards = screens(g.items).map(({ screen, variants }) => { - const first = variants.find((v) => !v.variant.includes('dark')) ?? variants[0] - const dark = variants.find((v) => v.variant.includes('dark') && parseInt(v.variant, 10) === parseInt(first.variant, 10)) - const data = escapeHtml(JSON.stringify(variants.map((v) => ({ url: v.url, label: variantLabel(v.variant), width: v.width, height: v.height })))) - const alt = escapeHtml(`${g.title || g.name}: ${screen}`) - return `
  • ${dark ? `` : ''}${alt}${escapeHtml(screen)}${variants.map((v) => escapeHtml(variantLabel(v.variant))).join(' · ')}
  • ` + const sections = gallerySections(manifest).map((section) => { + const cards = section.screens.map(({ screen, versions }) => { + const shown = pickVersion(versions, 'desktop', 'light') + const title = screenTitle(screen) + const data = escapeHtml(JSON.stringify(versions)) + return `${escapeHtml(title)}${escapeHtml(title)}` }) - return `

    ${escapeHtml(g.title || g.name)}

      ${cards.join('')}
    ` + return `

    ${escapeHtml(section.title)}

    ${section.screens.length} screens
    ${cards.join('')}
    ` }) - return `${intro}` + return `${intro}` } function galleryMarkdown(manifest) { - const head = `VisualCI's own screenshots of its web app and this site, as approved on main, from its public gallery (${SITE}/docs/gallery.md). The manifest: ${GALLERY_MANIFEST}` + const head = `VisualCI's own screenshots of its web app, light and dark, on a desktop and on a phone, as approved on main, from its public gallery (${SITE}/docs/gallery.md). Each has a 2x copy for high-density screens (the same URL ending in -2x.png). The manifest: ${GALLERY_MANIFEST}` if (!manifest?.groups?.length) return `${head}\n\nThe screenshots couldn't be loaded when this page was built.` - const groups = manifest.groups.map( - (g) => - `## ${g.title || g.name}\n\n` + - screens(g.items) - .map(({ screen, variants }) => `- ${screen}: ${variants.map((v) => `[${variantLabel(v.variant)}](${v.url})`).join(', ')}`) + const sections = gallerySections(manifest).map( + (s) => + `## ${s.title}\n\n` + + s.screens + .map(({ screen, versions }) => `- ${screenTitle(screen)}: ${versions.map((v) => `[${v.device}, ${v.theme}](${v.url})`).join(', ')}`) .join('\n'), ) - return [head, ...groups].join('\n\n') + return [head, ...sections].join('\n\n') } const manifest = await galleryManifest() await writeStandalone({ slug: 'screenshots', title: 'Screenshots', - description: "VisualCI's web app and site, from its own public gallery: the screenshots its tests take, as approved on main.", + description: "Every screen of VisualCI's web app, light and dark, on a desktop and on a phone, from its own public gallery.", html: galleryHtml(manifest), copy: galleryMarkdown(manifest), }) diff --git a/server/frontend/src/components/AgentPrompt.tsx b/server/frontend/src/components/AgentPrompt.tsx index 12dc6222..7dad5c2a 100644 --- a/server/frontend/src/components/AgentPrompt.tsx +++ b/server/frontend/src/components/AgentPrompt.tsx @@ -1,8 +1,7 @@ import { CopyButton } from './ui' -import { siteUrl } from '../lib/hosts' - -/** The one-line setup for coding agents, to copy: the agent fetches install.md and follows it. */ -export const AGENT_PROMPT = `Fetch ${siteUrl('/install.md')} and follow it` +/** The one-line setup for coding agents, to copy: the agent fetches install.md and follows it. Always visualci.com's, + * the only one worth giving an agent (a dev server or CI capture would otherwise show its own address). */ +export const AGENT_PROMPT = 'Fetch https://visualci.com/install.md and follow it' export function AgentPrompt({ label = 'Or ask your coding agent:' }: { label?: string }) { return ( diff --git a/server/frontend/src/components/GalleryImage.tsx b/server/frontend/src/components/GalleryImage.tsx index 28de0b95..3b33a14c 100644 --- a/server/frontend/src/components/GalleryImage.tsx +++ b/server/frontend/src/components/GalleryImage.tsx @@ -6,29 +6,37 @@ export const GALLERY = 'https://app.visualci.com/g/docspring/visualci' export const galleryUrl = (name: string) => `${GALLERY}/${name}.png` -/** One gallery screenshot, sized up front so nothing moves while it loads. If it can't load (the app is down, the - * screenshot was renamed), its description takes its place. */ +/** The 2x copy of a gallery screenshot (`…/1440-light-2x`), captured at device scale 2 for high-density screens. */ +export const galleryUrl2x = (name: string) => `${GALLERY}/${name}-2x.png` + +/** One gallery screenshot, sized up front so nothing moves while it loads. High-density screens get its 2x copy + * (`srcset` by width, so a phone picks the 1x one). If the 2x copy can't load (not approved yet), the 1x one is used; if + * neither can (the app is down, the screenshot was renamed), its description takes its place. */ export function GalleryImage({ name, width, height, alt, + sizes, className, }: { name: string + /** The 1x image's size in CSS pixels. */ width: number height: number alt: string + /** How wide the image shows, for picking 1x or 2x (`sizes`). */ + sizes: string className?: string }) { const ref = useRef(null) - const [failed, setFailed] = useState(false) + const [stage, setStage] = useState<'srcset' | 'plain' | 'failed'>('srcset') // An image that failed before the page hydrated fired its error event before React was listening. useEffect(() => { const img = ref.current - if (img && img.complete && img.naturalWidth === 0) setFailed(true) - }, []) - if (failed) { + if (img && img.complete && img.naturalWidth === 0) setStage((s) => (s === 'srcset' ? 'plain' : 'failed')) + }, [stage]) + if (stage === 'failed') { return ( {alt} @@ -40,12 +48,14 @@ export function GalleryImage({ ref={ref} className={className} src={galleryUrl(name)} + srcSet={stage === 'srcset' ? `${galleryUrl(name)} ${width}w, ${galleryUrl2x(name)} ${width * 2}w` : undefined} + sizes={stage === 'srcset' ? sizes : undefined} width={width} height={height} alt={alt} loading="lazy" decoding="async" - onError={() => setFailed(true)} + onError={() => setStage((s) => (s === 'srcset' ? 'plain' : 'failed'))} /> ) } diff --git a/server/frontend/src/pages/DocsPage.tsx b/server/frontend/src/pages/DocsPage.tsx index 2e93cee2..ef04e24e 100644 --- a/server/frontend/src/pages/DocsPage.tsx +++ b/server/frontend/src/pages/DocsPage.tsx @@ -85,7 +85,14 @@ export function DocsPage({ page }: { page: DocsPageData }) { -
    +
    {!standalone && (
    diff --git a/server/frontend/src/pages/ProjectPage.tsx b/server/frontend/src/pages/ProjectPage.tsx index 6eb22183..fde153a7 100644 --- a/server/frontend/src/pages/ProjectPage.tsx +++ b/server/frontend/src/pages/ProjectPage.tsx @@ -89,7 +89,8 @@ function PublicList({ gallery }: { gallery: PublicGallery }) { if (!gallery.manifest_url) return (

    - Nothing is public. Add gallery groups to visualci.yml to publish screenshots.{' '} + The gallery is on, with nothing in it yet. Add gallery groups to visualci.yml to + publish screenshots.{' '} How

    ) diff --git a/server/frontend/src/styles.css b/server/frontend/src/styles.css index ae08a736..408746ae 100644 --- a/server/frontend/src/styles.css +++ b/server/frontend/src/styles.css @@ -98,6 +98,8 @@ --color-page: oklch(100% 0 0); --shadow-sm: 0 1px 2px oklch(30% 0.02 262 / 0.06); --shadow-pop: 0 8px 28px oklch(30% 0.03 262 / 0.14), 0 1px 3px oklch(30% 0.03 262 / 0.08); + /* Behind a dialog: dims the page in its own theme. */ + --color-scrim: oklch(22% 0.02 262 / 0.55); color-scheme: light; } @@ -144,6 +146,7 @@ --color-page: oklch(97% 0.002 262); --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.3); --shadow-pop: 0 10px 30px oklch(0% 0 0 / 0.45), 0 1px 3px oklch(0% 0 0 / 0.3); + --color-scrim: oklch(8% 0.01 262 / 0.85); color-scheme: dark; } } @@ -187,6 +190,7 @@ --color-page: oklch(97% 0.002 262); --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.3); --shadow-pop: 0 10px 30px oklch(0% 0 0 / 0.45), 0 1px 3px oklch(0% 0 0 / 0.3); + --color-scrim: oklch(8% 0.01 262 / 0.85); color-scheme: dark; } @@ -4818,75 +4822,156 @@ html.vci-signed-in .site-auth-out { font-size: 13px; } -/* ---------- /screenshots/: VisualCI's own gallery ---------- */ -.shots { +/* ---------- /screenshots/: VisualCI's own gallery ---------- + Hallmark · component: gallery grid + lightbox · genre: modern-minimal · theme: VisualCI's own tokens + states: default · hover · focus · active · loading (lazy) · error (the description in its place) */ +.docs-layout.docs-layout-wide { + grid-template-columns: minmax(0, 1240px); +} + +.docs-layout-wide .docs-main { + max-width: none; +} + +.gx-lede { + max-width: 68ch; + color: var(--color-ink-2); +} + +.gx { display: grid; - gap: var(--space-6); + gap: var(--space-12); margin-top: var(--space-6); } -.shots-tabs { +/* Light or dark, desktop or phone, for every card at once; it stays in view while the page scrolls. */ +.gx-bar { + position: sticky; + top: var(--space-3); + z-index: 5; justify-self: start; - max-width: 100%; - overflow-x: auto; + display: flex; + flex-wrap: wrap; + gap: var(--space-2); + padding: var(--space-2); + border: 1px solid var(--color-rule); + border-radius: var(--radius-lg); + background: var(--color-surface); + box-shadow: var(--shadow-pop); } -.shots-group h2 { - margin-top: 0; +.gx-section { + display: grid; + gap: var(--space-5); } -.shots-grid { - list-style: none; +.gx-section-head { + display: flex; + align-items: baseline; + gap: var(--space-3); +} + +.gx-section-head h2 { margin: 0; - padding: 0; +} + +.gx-count { + color: var(--color-muted); + font-size: var(--text-sm); +} + +.gx-grid { display: grid; - grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); - gap: var(--space-4); + gap: var(--space-8) var(--space-6); + grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr)); } -.shots-card a { +/* Phones are tall and narrow: more of them to a row. */ +.gx-grid[data-device='phone'] { + grid-template-columns: repeat(auto-fill, minmax(min(100%, 10.5rem), 1fr)); + gap: var(--space-8) var(--space-5); +} + +.gx-card { display: grid; - gap: var(--space-2); + gap: var(--space-3); + align-content: start; + min-width: 0; color: inherit; text-decoration: none; } -.shots-card img, -.shots-card .gallery-missing { +/* Every card in a grid has one shape; a tall full-page screenshot shows its top, never squashed. */ +.gx-thumb { display: block; - width: 100%; - height: auto; + cursor: zoom-in; aspect-ratio: 16 / 10; - object-fit: cover; - object-position: top; + overflow: hidden; border: 1px solid var(--color-rule); border-radius: var(--radius-lg); background: var(--color-sunken); - transition: border-color var(--dur-fast) var(--ease-out); + transition: + border-color var(--dur-fast) var(--ease-out), + box-shadow var(--dur-fast) var(--ease-out), + transform var(--dur-fast) var(--ease-out); } -.shots-card a:hover img, -.shots-card a:focus-visible img { - border-color: var(--color-accent); +.gx-grid[data-device='phone'] .gx-thumb { + aspect-ratio: 9 / 19.5; +} + +.gx-thumb img, +.gx-thumb .gallery-missing { + display: block; + width: 100%; + height: 100%; + object-fit: cover; + object-position: top; +} + +.gx-card:hover .gx-thumb { + border-color: var(--color-rule-strong); + box-shadow: var(--shadow-pop); + transform: translateY(-2px); +} + +.gx-card:focus-visible { + outline: none; } -.shots-card a:focus-visible { +.gx-card:focus-visible .gx-thumb { outline: 2px solid var(--color-focus); outline-offset: 2px; - border-radius: var(--radius-lg); } -.shots-caption { - display: grid; - gap: 2px; - font-size: var(--text-sm); - min-width: 0; +.gx-card:active .gx-thumb { + transform: translateY(0); +} + +/* The card is one link: no underline on it or its image, only on the title when the title itself is pointed at or + the card has keyboard focus. */ +.gx-card:hover { + text-decoration: none; +} + +.gx-name { + justify-self: start; + cursor: pointer; + font-weight: 500; overflow-wrap: anywhere; + text-underline-offset: 3px; +} + +.gx-name:hover, +.gx-card:focus-visible .gx-name { + text-decoration: underline; } -.shots-lightbox { - width: min(100% - var(--space-8), 90rem); - max-height: calc(100% - var(--space-8)); +.gx-lightbox { + width: min(100% - var(--space-6), 1320px); + height: calc(100% - var(--space-6)); + max-width: none; + max-height: none; padding: 0; border: 1px solid var(--color-rule); border-radius: var(--radius-lg); @@ -4896,39 +4981,80 @@ html.vci-signed-in .site-auth-out { overflow: hidden; } -.shots-lightbox[open] { +.gx-lightbox[open] { + cursor: auto; display: grid; grid-template-rows: auto minmax(0, 1fr); } -.shots-lightbox::backdrop { - background: color-mix(in oklch, var(--color-ink) 55%, transparent); +.gx-lightbox::backdrop { + background: var(--color-scrim); + cursor: zoom-out; } -.shots-lightbox-head { +.gx-lb-bar { display: flex; - gap: var(--space-3); + flex-wrap: wrap; align-items: center; - justify-content: space-between; + gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-rule); +} + +.gx-lb-title { + margin-right: auto; min-width: 0; overflow-wrap: anywhere; } -.shots-lightbox-list { +.gx-lb-segs, +.gx-lb-nav { + display: flex; + flex-wrap: wrap; + gap: var(--space-2); +} + +/* The whole image at its own ratio, as wide as fits (a phone's at its own width), scrolling down a tall page. */ +.gx-lb-view { overflow: auto; - padding: var(--space-4); + padding: var(--space-5); + background: var(--color-sunken); display: grid; - grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); - gap: var(--space-4); - align-items: start; + justify-items: center; + align-content: start; } -.shots-lightbox-list figure { - margin: 0; - display: grid; - gap: var(--space-2); +.gx-lb-view img { + display: block; + width: 100%; + max-width: 1240px; + height: auto; + border: 1px solid var(--color-rule); + border-radius: var(--radius); + background: var(--color-surface); +} + +.gx-lb-view[data-device='phone'] img { + max-width: 390px; +} + +@media (max-width: 640px) { + .gx-lightbox { + width: 100%; + height: 100%; + border-radius: 0; + } + + .gx-lb-view { + padding: var(--space-3); + } +} + +/* With reduced motion the image still sits 2px higher on hover, without moving there. */ +@media (prefers-reduced-motion: reduce) { + .gx-thumb { + transition: none; + } } /* ---------- Compare two PDFs (visualci.com/tools/compare-pdfs/) ---------- */ @@ -5011,17 +5137,6 @@ html.vci-signed-in .site-auth-out { gap: var(--space-2); } -.shots-lightbox-list figcaption { - font-size: var(--text-sm); -} - -.shots-lightbox-list img { - width: 100%; - height: auto; - border: 1px solid var(--color-rule); - border-radius: var(--radius); -} - @media (max-width: 640px) { .pdf-drops { grid-template-columns: minmax(0, 1fr); diff --git a/server/frontend/src/tools/screenshots.ts b/server/frontend/src/tools/screenshots.ts index dde1bc11..9eb25998 100644 --- a/server/frontend/src/tools/screenshots.ts +++ b/server/frontend/src/tools/screenshots.ts @@ -1,110 +1,159 @@ -/** /screenshots/ in the browser: the prerendered groups become tabs, a screenshot opens in a lightbox with all its - * versions (light and dark, wide and narrow), and one that can't load shows its name instead. Without JavaScript the - * page is the same list, each card a link to the image. */ +/** /screenshots/ in the browser. The prerendered page is a grid of screens, each showing its desktop light version + * and linking to it, which works without JavaScript. This adds the bar that switches every card between light and + * dark and desktop and phone, and a lightbox with the same switches, previous and next. A screenshot that can't load + * shows its name instead. */ -type Variant = { url: string; label: string; width: number; height: number } +type Theme = 'light' | 'dark' +type Device = 'desktop' | 'phone' +type Version = { device: Device; theme: Theme; url: string; url2x?: string; width: number; height: number } -export function enhanceScreenshots(root: HTMLElement) { - const groups = [...root.querySelectorAll('.shots-group')] - for (const img of root.querySelectorAll('.shots-card img')) { - const broken = () => { - const span = document.createElement('span') - span.className = 'gallery-missing' - span.textContent = img.alt - img.closest('picture')?.replaceWith(span) - } - if (img.complete && img.naturalWidth === 0) broken() - else img.addEventListener('error', broken, { once: true }) +const versionsOf = (card: HTMLElement) => JSON.parse(card.dataset.versions ?? '[]') as Version[] + +/** The version for a theme and device: exactly that, else the same device, else the same theme, else any. */ +function pick(versions: Version[], device: Device, theme: Theme): Version { + return ( + versions.find((v) => v.device === device && v.theme === theme) ?? + versions.find((v) => v.device === device) ?? + versions.find((v) => v.theme === theme) ?? + versions[0] + ) +} + +function siteTheme(): Theme { + const set = document.documentElement.dataset.theme + if (set === 'light' || set === 'dark') return set + return matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' +} + +/** A segmented control: a radio group of buttons. */ +function seg(label: string, options: [T, string][], value: () => T, set: (v: T) => void) { + const el = document.createElement('div') + el.className = 'seg seg-sm' + el.setAttribute('role', 'radiogroup') + el.setAttribute('aria-label', label) + for (const [v, text] of options) { + const b = document.createElement('button') + b.type = 'button' + b.className = 'seg-btn' + b.setAttribute('role', 'radio') + b.dataset.value = v + b.textContent = text + b.addEventListener('click', () => set(v)) + el.append(b) } + const sync = () => el.querySelectorAll('button').forEach((b) => b.setAttribute('aria-checked', String(b.dataset.value === value()))) + return { el, sync } +} - // Tabs: one group at a time, kept in the URL's hash. - if (groups.length > 1) { - const tabs = document.createElement('div') - tabs.className = 'seg shots-tabs' - tabs.setAttribute('role', 'tablist') - tabs.setAttribute('aria-label', 'Screenshot groups') - const select = (id: string, push: boolean) => { - const target = groups.find((g) => g.id === id) ?? groups[0] - for (const g of groups) g.hidden = g !== target - for (const b of tabs.querySelectorAll('button')) b.setAttribute('aria-selected', String(b.dataset.id === target.id)) - if (push) history.replaceState(null, '', `#${target.id}`) - } - for (const g of groups) { - const b = document.createElement('button') - b.type = 'button' - b.className = 'seg-btn' - b.setAttribute('role', 'tab') - b.dataset.id = g.id - b.textContent = `${g.dataset.name ?? g.id} (${g.querySelectorAll('.shots-card').length})` - b.addEventListener('click', () => select(g.id, true)) - tabs.append(b) - g.querySelector('h2')?.classList.add('sr-only') +function missing(img: HTMLImageElement) { + const span = document.createElement('span') + span.className = 'gallery-missing' + span.textContent = img.alt + img.replaceWith(span) +} + +function watch(img: HTMLImageElement) { + if (img.complete && img.naturalWidth === 0 && img.getAttribute('src')) missing(img) + else img.addEventListener('error', () => missing(img), { once: true }) +} + +export function enhanceScreenshots(root: HTMLElement) { + const state: { theme: Theme; device: Device } = { theme: siteTheme(), device: 'desktop' } + const cards = [...root.querySelectorAll('.gx-card')] + const bar = document.createElement('div') + bar.className = 'gx-bar' + const themes = seg('Theme', [['light', 'Light'], ['dark', 'Dark']], () => state.theme, (t) => { state.theme = t; apply() }) + const devices = seg('Device', [['desktop', 'Desktop'], ['phone', 'Phone']], () => state.device, (d) => { state.device = d; apply() }) + bar.append(themes.el, devices.el) + root.prepend(bar) + + function apply() { + themes.sync() + devices.sync() + for (const grid of root.querySelectorAll('.gx-grid')) grid.dataset.device = state.device + for (const card of cards) { + const v = pick(versionsOf(card), state.device, state.theme) + const thumb = card.querySelector('.gx-thumb')! + thumb.dataset.device = v.device + let img = thumb.querySelector('img') + if (!img) { + thumb.replaceChildren((img = document.createElement('img'))) + img.alt = card.dataset.title ?? '' + img.loading = 'lazy' + img.decoding = 'async' + } + if (img.getAttribute('src') !== v.url) { + img.width = v.width + img.height = v.height + img.src = v.url + watch(img) + } + card.href = v.url } - root.prepend(tabs) - select(location.hash.slice(1), false) + if (dialog.open) show(current) } - // The lightbox: every version of one screenshot; arrow keys move through the group. + // The lightbox: one screen at a time, its whole image at its own ratio, the same switches, previous and next. const dialog = document.createElement('dialog') - dialog.className = 'shots-lightbox' - dialog.setAttribute('aria-label', 'Screenshot') + dialog.className = 'gx-lightbox' + dialog.innerHTML = + '
    ' + + '' + + '' + + '
    ' + + '
    ' + const lbThemes = seg('Theme', [['light', 'Light'], ['dark', 'Dark']], () => state.theme, (t) => { state.theme = t; apply() }) + const lbDevices = seg('Device', [['desktop', 'Desktop'], ['phone', 'Phone']], () => state.device, (d) => { state.device = d; apply() }) + dialog.querySelector('.gx-lb-segs')!.append(lbThemes.el, lbDevices.el) document.body.append(dialog) - const open = (card: HTMLAnchorElement) => { - const variants = JSON.parse(card.dataset.variants ?? '[]') as Variant[] - const title = card.querySelector('.shots-caption .mono')?.textContent ?? '' - dialog.replaceChildren() - const head = document.createElement('div') - head.className = 'shots-lightbox-head' - const h = document.createElement('strong') - h.className = 'mono' - h.textContent = title - const close = document.createElement('button') - close.type = 'button' - close.className = 'btn btn-secondary btn-sm' - close.textContent = 'Close' - close.addEventListener('click', () => dialog.close()) - head.append(h, close) - const list = document.createElement('div') - list.className = 'shots-lightbox-list' - for (const v of variants) { - const fig = document.createElement('figure') - const img = document.createElement('img') - img.src = v.url - img.width = v.width - img.height = v.height - img.alt = `${title}, ${v.label}` + let current = 0 + + function show(i: number) { + current = (i + cards.length) % cards.length + const card = cards[current] + const v = pick(versionsOf(card), state.device, state.theme) + lbThemes.sync() + lbDevices.sync() + dialog.querySelector('.gx-lb-title')!.textContent = card.dataset.title ?? '' + const view = dialog.querySelector('.gx-lb-view')! + view.dataset.device = v.device + let img = view.querySelector('img') + if (!img) { + view.replaceChildren((img = document.createElement('img'))) img.decoding = 'async' - const cap = document.createElement('figcaption') - const link = document.createElement('a') - link.href = v.url - link.textContent = v.label - cap.append(link) - fig.append(cap, img) - list.append(fig) } - dialog.append(head, list) - dialog.dataset.index = card.dataset.index + img.alt = `${card.dataset.title ?? ''}, ${v.device}, ${v.theme}` + img.width = v.width + img.height = v.height + // The 2x copy on high-density screens, chosen by width so a phone takes the 1x one. + if (v.url2x) { + img.srcset = `${v.url} ${v.width}w, ${v.url2x} ${v.width * 2}w` + img.sizes = v.device === 'phone' ? `min(${v.width}px, 100vw)` : 'min(1280px, 100vw)' + } else { + img.removeAttribute('srcset') + } + img.src = v.url + img.addEventListener('error', () => { if (img!.srcset) img!.removeAttribute('srcset') }, { once: true }) + view.scrollTop = 0 if (!dialog.open) dialog.showModal() - list.scrollTop = 0 } - const cards = () => [...root.querySelectorAll('.shots-group:not([hidden]) .shots-card a')] + root.addEventListener('click', (e) => { - const card = (e.target as Element).closest('.shots-card a') - if (!card || e.metaKey || e.ctrlKey || e.shiftKey) return + const card = (e.target as Element).closest('.gx-card') + if (!card || e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return e.preventDefault() - cards().forEach((c, i) => (c.dataset.index = String(i))) - open(card) + show(cards.indexOf(card)) }) dialog.addEventListener('click', (e) => { - if (e.target === dialog) dialog.close() + const t = e.target as HTMLElement + if (t === dialog || t.closest('[data-close]')) dialog.close() + const go = t.closest('[data-go]') + if (go) show(current + Number(go.dataset.go)) }) dialog.addEventListener('keydown', (e) => { - if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') return - const list = cards() - const i = Number(dialog.dataset.index ?? 0) + (e.key === 'ArrowRight' ? 1 : -1) - if (list[i]) { - list.forEach((c, n) => (c.dataset.index = String(n))) - open(list[i]) - } + if (e.key === 'ArrowRight') show(current + 1) + else if (e.key === 'ArrowLeft') show(current - 1) }) + for (const img of root.querySelectorAll('.gx-thumb img')) watch(img) + apply() } diff --git a/skills/visualci-review/SKILL.md b/skills/visualci-review/SKILL.md index 0d00b8da..8084aec9 100644 --- a/skills/visualci-review/SKILL.md +++ b/skills/visualci-review/SKILL.md @@ -44,7 +44,7 @@ claude mcp add --transport http visualci https://mcp.visualci.com/mcp \ 1. CI sends a build and finishes. When something changed, the CI job still passes, and the pull request's VisualCI check stays pending. 2. The agent calls `list_builds` or `get_build` to see what needs attention: changed, added, removed and failed snapshots. -3. For each change, it calls `get_snapshot`. For PDFs and images that returns the base, head and diff images of the changed pages, the changed regions, the page's text diff, and lines that moved to another page. For text, JSON and HTML snapshots it returns the changes by JSON path (`items[3].price: 10 → 12`) and a unified diff. +3. For each change, it calls `get_snapshot`. For PDFs and images that returns the base, head and diff images of the changed pages, the changed regions, the page's text diff, and lines that moved to another page. For text, JSON and HTML snapshots it returns the changes by JSON path (`items[3].price: 10 → 12`) and a unified diff. A contact sheet is for finding the changes, not for judging them: its thumbnails are too small to show a button covering a tab or a missing style. Open every sizeable UI change with `get_snapshot` and `crop: "changed"`, which shows the changed regions at full size. 4. The agent checks each change against the code and the task: - **Intended:** it calls `review` with `approve`. The approved snapshots become the baseline, and the check turns green. No new commit or CI run is needed. - **A bug:** it fixes the code and pushes again. The next build is compared with the same baseline. diff --git a/visualci.yml b/visualci.yml index 6de4e4dd..a0877d2f 100644 --- a/visualci.yml +++ b/visualci.yml @@ -1,12 +1,13 @@ # yaml-language-server: $schema=https://visualci.com/visualci.schema.json # VisualCI's own screenshots, published as its public gallery (https://visualci.com/docs/gallery/): each URL serves the # approved version on main. The manifest is https://app.visualci.com/g/docspring/visualci.json. Only the app is -# published: the landing page and the docs home are taken to catch regressions, not to show. +# published: the landing page and the docs home are taken to catch regressions, not to show. Each app screenshot has +# a 2x copy (`…-2x`, scripts/screenshots/capture.mjs) for high-density screens. gallery: groups: - name: App title: The web app - include: ["screenshots/app/**/1440-light", "screenshots/app/**/1440-dark"] + include: ["screenshots/app/**/1440-light", "screenshots/app/**/1440-dark", "screenshots/app/**/1440-*-2x"] - name: Phone title: The web app on a phone - include: ["screenshots/app/**/390-light", "screenshots/app/**/390-dark"] + include: ["screenshots/app/**/390-light", "screenshots/app/**/390-dark", "screenshots/app/**/390-*-2x"]