Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions e2e/zoom.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,20 @@ 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);
expect((await rect(page, ".cz-close")).right).toBeLessThanOrEqual(390);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 · Class: long captions shrink the close button’s hit area. At 390px the caption in this test shrinks .cz-close to about 25px wide instead of 36px; longer alt text can reduce it below 24px, even though the right-edge assertion still passes. Keep .cz-close from shrinking in the header flex row and check its width as well as its position.

Technical details
# Let the caption shrink, not the close button

## Affected sites
- `packages/zoom/src/styles.ts:21–30` — `.cz-close` has a width of `2.25rem`, but the header’s flex layout can shrink it when the caption overflows.
- `e2e/zoom.e2e.ts:713` — the check constrains only the button’s right edge.

## Required outcome
- A long caption truncates without reducing the close button’s hit area. Adding `flex-shrink:0` to `.cz-close` kept it 36px wide and within the 390px viewport in Chromium.

});
14 changes: 14 additions & 0 deletions packages/carousel/test/carousel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ describe("comark-carousel", () => {
expect(html.match(/<script>/g)).toHaveLength(2);
});

it("zooms the slide, not the image in it, whichever plugin comes first", async () => {
for (const plugins of [
[carousel(), zoom()],
[zoom(), carousel()],
]) {
const html = await createHtmlRenderer({
plugins,
components: { ...components, ...zoomComponents },
})("::carousel\n![One](a.png)\n\nTwo\n::");
expect(html).toContain('<img src="a.png" alt="One">');
expect(html.match(/class="cc-slide"[^>]*data-zoom/g)).toHaveLength(2);
}
});

it("inlines styles a site can theme with --cc-* variables, with today's look as the fallback", async () => {
const style = /<style data-comark-carousel>(.*?)<\/style>/s.exec(
await render("::carousel\nOne\n\nTwo\n::"),
Expand Down
2 changes: 1 addition & 1 deletion packages/zoom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import zoom, { components } from "comark-zoom/html";
const render = createHtmlRenderer({ plugins: [zoom()], components });
```

Content images zoom on their own, except images inside links. Wrap any other block in `::zoom` to make it zoomable, and give blocks the same `group` to page through them in one zoomed view with a strip at the bottom:
Content images zoom on their own, except images inside links and inside a block that zooms as a whole: `::zoom`, and comark-carousel's and comark-annotate's blocks when those plugins are registered. Wrap any other block in `::zoom` to make it zoomable, and give blocks the same `group` to page through them in one zoomed view with a strip at the bottom:

```md
![Dashboard](dashboard.png)
Expand Down
2 changes: 1 addition & 1 deletion packages/zoom/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Use the `data-zoom-src` attribute to load a larger file when the view opens. Unt

### Turn zoom off

Use `zoom=false` to keep one image from zooming. Images inside links never zoom.
Use `zoom=false` to keep one image from zooming. Images inside links never zoom, and images inside a `::zoom`, a carousel slide, or a screenshot zoom with it. A `::carousel` or `::screenshot` counts only when comark-carousel or comark-annotate is registered, so a block of your own with that name keeps its images zoomable.

```md
![Company logo](/logo.png){zoom=false}
Expand Down
19 changes: 14 additions & 5 deletions packages/zoom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ export interface ZoomOptions {
/** The node that starts the zoom script. The plugin adds one at the end of a document that has anything to zoom. */
export const RUNTIME_TAG = "zoom-runtime";

// Blocks that zoom as a whole, so the images inside them don't zoom on their own.
const WHOLE = new Set(["zoom", "carousel", "slide", "screenshot", "compare"]);
// Blocks that zoom as a whole, by the plugin that draws them; without it, a block of that name is the app's own.
const WHOLE = {
carousel: "comark-carousel",
slide: "comark-carousel",
screenshot: "comark-annotate",
compare: "comark-annotate",
};

const off = (value: unknown) => value === false || value === "false";

// Marks images with the same attributes a `::zoom` block gets, so every renderer outputs zoomable images unchanged.
// An element marked by hand gets the same; `{zoom=false}` on an image, or `data-zoom=false` anywhere, opts out.
function mark(nodes: Node[], images: boolean, skip = false): boolean {
function mark(nodes: Node[], images: boolean, whole: Set<string>, skip = false): boolean {
let found = false;
for (const node of nodes) {
if (!isElement(node)) continue;
Expand All @@ -44,7 +49,8 @@ function mark(nodes: Node[], images: boolean, skip = false): boolean {
found = true;
}
// SAFETY: an element node is [tag, attributes, ...children], so everything after index 1 is a child node.
if (mark(node.slice(2) as Node[], images, skip || tag === "a" || WHOLE.has(tag))) found = true;
if (mark(node.slice(2) as Node[], images, whole, skip || tag === "a" || whole.has(tag)))
found = true;
}
return found;
}
Expand Down Expand Up @@ -86,7 +92,10 @@ export default /* @__PURE__ */ defineComarkPlugin<ZoomOptions>((options) => ({
name: "comark-zoom",
async post(state) {
const { nodes } = state.tree;
if (mark(nodes, options?.images ?? true)) nodes.push([RUNTIME_TAG, {}]);
const plugins = new Set(state.options.plugins?.map((plugin) => plugin.name));
const drawn = Object.entries(WHOLE).filter(([, plugin]) => plugins.has(plugin));
const whole = new Set(["zoom", ...drawn.map(([tag]) => tag)]);
if (mark(nodes, options?.images ?? true, whole)) nodes.push([RUNTIME_TAG, {}]);
if (options?.size !== false)
await Promise.all(images(nodes).map((node) => size(node, options?.size === true)));
},
Expand Down
2 changes: 1 addition & 1 deletion packages/zoom/src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const css = `@layer comark{${[
"[data-zoom]:focus-visible{outline:2px solid var(--_comark-ring);outline-offset:3px}",
// The dialog fills the window in place of the browser's centered box. Its styles keep it shown after a close, so the
// closing animation runs to its end whatever closed it.
".cz-dialog{position:fixed;inset:0;z-index:2147483000;display:grid;grid-template-rows:auto minmax(0,1fr) auto;width:auto;height:auto;max-width:none;max-height:none;margin:0;padding:0;overflow:visible;border:0;background:none;color:var(--_comark-foreground);font:13px/1.4 var(--_comark-font);outline:none}",
".cz-dialog{position:fixed;inset:0;z-index:2147483000;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;width:auto;height:auto;max-width:none;max-height:none;margin:0;padding:0;overflow:visible;border:0;background:none;color:var(--_comark-foreground);font:13px/1.4 var(--_comark-font);outline:none}",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 · Class: centered overflow clips the start of a scrollable strip. On a 390px touch viewport, open item 4 of seven grouped ::zoom blocks: the first thumbnail is entirely offscreen even at the strip’s leftmost scroll position, so tapping it is impossible. Make the strip center only when its thumbnails fit; justify-content:safe center restored direct selection in Chromium.

Technical details
# Keep the first thumbnail reachable

## Affected sites
- `packages/zoom/src/styles.ts:17` — the explicit grid column now bounds the footer to the viewport.
- `packages/zoom/src/styles.ts:60` — `.cz-strip` still centers overflowing flex items. At `scrollLeft === 0`, the first thumbnail spans x=-165px to -69px at a 390px viewport.

## Required outcome
- A reader can scroll to and tap the first and last thumbnails in a group wider than the dialog, while short strips remain centered.

// .cz-backdrop is the backdrop, so it fades with the rest of the view.
".cz-dialog::backdrop{background:none}",
".cz-backdrop{position:absolute;inset:0;background:var(--cz-backdrop,color-mix(in srgb,var(--_comark-background) var(--cz-backdrop-opacity,96%),transparent))}",
Expand Down
6 changes: 6 additions & 0 deletions packages/zoom/test/zoom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ describe("comark-zoom", () => {
expect(html).not.toContain("<script>");
});

it("zooms the images in a block named carousel when comark-carousel doesn't draw it", async () => {
const html = await render("::carousel\n1. A step\n\n ![One](a.png)\n::");
expect(html).toContain('<img src="a.png" alt="One" data-zoom="" tabindex="0">');
expect(html.match(/<script>/g)).toHaveLength(1);
});

it("can leave every image alone", async () => {
const html = await render("![One](a.png)", { images: false });
expect(html).not.toContain("data-zoom");
Expand Down
2 changes: 1 addition & 1 deletion skills/comark-ui/references/zoom.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ comark-zoom lets the reader click an image or a `::zoom` block to see it large,

- `::zoom` zooms everything inside it as one item. `title` heads the zoomed view. Items with the same `group` page through one zoomed view, with a strip of them below. `#id` and `.class` go on the block.
- Every content image zooms on its own, with its alt text as the zoomed view's heading. It grows no larger than its file, so give a small image a larger file to open with `{data-zoom-src="dashboard@2x.png"}`.
- An image inside a link keeps its link and doesn't zoom. Images inside `::zoom`, `::carousel`, `::screenshot`, or `::compare` zoom with their block.
- An image inside a link keeps its link and doesn't zoom. Images inside `::zoom` zoom with their block, and so do images inside `::carousel`, `::screenshot`, or `::compare` when comark-carousel or comark-annotate draws it. A block of your own with one of those names leaves its images to zoom on their own.
- `{zoom=false}` keeps an image from zooming, and `{data-zoom}` makes any element zoom on its own.

comark-zoom reports no problems, so a misspelled prop such as `titel` is dropped silently and passes the linter. Spell `title` and `group` as written here.
Expand Down
Loading