diff --git a/AGENTS.md b/AGENTS.md index 02e4369e6..70a0e0e89 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -200,7 +200,7 @@ How most packages work, so the bullets below don't repeat it: - Its output is plain elements, so it has no renderers and ships no styles. - Pandoc's `@fig-x` isn't read, since `@name` is a mention in comark-chips and comark-github. - `packages/zoom` is `comark-zoom`. - - `src/index.ts` is the parse plugin. It marks content images and adds one `zoom-runtime` node to a document with anything to zoom. Unless `size` is `false`, it gives every image without both sides its `width` and `height` from `measure()`, so the page keeps the image's room before it loads. + - `src/index.ts` is the parse plugin. It marks content images and adds one `zoom-runtime` node to a document with anything to zoom. It leaves the images inside `::zoom` alone, and inside carousel's and annotate's blocks when `state.options.plugins` registers that plugin, so an app's own `::carousel` still zooms its images. Unless `size` is `false`, it gives every image without both sides its `width` and `height` from `measure()`, so the page keeps the image's room before it loads. - `src/size.ts` is `comark-zoom/size`. `measure()` reads a picture's or a video's size from the first 64 KB of a URL (a range request) or from a data URI, cached per URL. `sizeOf()` reads it from bytes (PNG, JPEG, GIF, WebP, SVG, AVIF, MP4, MOV, WebM), turned by EXIF orientation or the track's matrix. A relative path, a format it doesn't know, or a file that doesn't answer within 5 seconds gets nothing. - comark-media and comark-annotate bundle `size` the way they bundle the theme, so every block that loads a picture or a video keeps its room. - `src/script.ts` is the browser script. `script()` is self-contained because the HTML renderer inlines its source. `src/client.ts` exports `start()`, which runs it with the bundled styles. The Vue, React, and Svelte components call it on mount and stop it on unmount. diff --git a/e2e/zoom.e2e.ts b/e2e/zoom.e2e.ts index 9edc44124..cb09aa272 100644 --- a/e2e/zoom.e2e.ts +++ b/e2e/zoom.e2e.ts @@ -162,6 +162,10 @@ test("grouped blocks stand apart, and their view fits the item between the arrow await blocks.first().click(); await expect(page.locator(".cz-nav svg")).toHaveCount(2); + const strip = await rect(page, ".cz-strip"); + const firstThumb = await rect(page, ".cz-thumb:first-child"); + const lastThumb = await rect(page, ".cz-thumb:last-child"); + expect(firstThumb.left - strip.left).toBeCloseTo(strip.right - lastThumb.right); const zoomed = await rect(page, ".cz-item"); expect(zoomed.left).toBeGreaterThan((await rect(page, ".cz-prev")).right); expect(zoomed.right).toBeLessThan((await rect(page, ".cz-next")).left); @@ -695,3 +699,50 @@ test("Up and Down move between the page's figures, scroll a tall one first, and const first = page.locator("main [data-zoom-gallery] [data-zoom]").first(); await expect(first).toBeInViewport(); }); + +test("on a phone, a long title stays on the screen and keeps the close button there", async ({ + page, +}) => { + await page.setViewportSize({ width: 390, height: 844 }); + await fixture( + page, + await render( + "![The booking page with the departure station, the arrival station, and the travel date filled in](/dashboard.png)", + ), + ); + await page.locator("main img[data-zoom]").click(); + await expect(page.locator(".cz-dialog")).toBeVisible(); + for (const part of [".cz-stage", ".cz-header"]) + expect((await rect(page, part)).right).toBeLessThanOrEqual(390); + const close = await rect(page, ".cz-close"); + expect(close.right).toBeLessThanOrEqual(390); + expect(close.width).toBeCloseTo(2.25 * 16); +}); + +test("on a phone, both ends of a wide thumbnail strip are reachable", async ({ page }) => { + await page.setViewportSize({ width: 390, height: 844 }); + await fixture( + page, + await render( + Array.from( + { length: 7 }, + (_, index) => `::zoom{group="tour" title="Item ${index + 1}"}\n${image}\n::`, + ).join("\n\n"), + ), + ); + await page.locator("[data-zoom-group='tour']").nth(3).click(); + await expect(page.locator(".cz-title")).toHaveText("Item 4"); + + const strip = page.locator(".cz-strip"); + const thumbs = strip.locator(".cz-thumb"); + await expect(thumbs).toHaveCount(7); + await strip.evaluate((node) => (node.scrollLeft = 0)); + await expect(thumbs.first()).toBeInViewport({ ratio: 1 }); + await thumbs.first().click(); + await expect(page.locator(".cz-title")).toHaveText("Item 1"); + + await strip.evaluate((node) => (node.scrollLeft = node.scrollWidth)); + await expect(thumbs.last()).toBeInViewport({ ratio: 1 }); + await thumbs.last().click(); + await expect(page.locator(".cz-title")).toHaveText("Item 7"); +}); diff --git a/packages/carousel/test/carousel.test.ts b/packages/carousel/test/carousel.test.ts index 711947d35..eb1cac366 100644 --- a/packages/carousel/test/carousel.test.ts +++ b/packages/carousel/test/carousel.test.ts @@ -33,6 +33,20 @@ describe("comark-carousel", () => { expect(html.match(/