diff --git a/e2e/annotate.e2e.ts b/e2e/annotate.e2e.ts
index fa9d61d83..1bc598d5f 100644
--- a/e2e/annotate.e2e.ts
+++ b/e2e/annotate.e2e.ts
@@ -398,7 +398,7 @@ The pigeons ate week 15.
expect(Math.abs(note - (await middle(".ca-arrow-left")))).toBeLessThan(2);
});
-test("a slider moves its divider by drag and by key, and a click without a drag zooms it", async ({
+test("a slider moves its divider by drag and by key, and no click on it zooms", async ({
page,
}) => {
await open(
@@ -430,7 +430,6 @@ test("a slider moves its divider by drag and by key, and a click without a drag
await page.mouse.up();
await expect(handle).toHaveAttribute("aria-valuenow", "25");
await expect(handle).toHaveAttribute("aria-valuetext", "Before 25%, After 75%");
- // The click that ends a drag doesn't zoom.
await expect(page.locator(".cz-dialog")).toHaveCount(0);
await handle.focus();
@@ -444,12 +443,9 @@ test("a slider moves its divider by drag and by key, and a click without a drag
// Focusing and clicking the handle can scroll the page, so measure the pair again.
const now = (await swipe.boundingBox())!;
await page.mouse.click(now.x + now.width * 0.3, now.y + now.height * 0.6);
- await expect(page.locator(".cz-item .ca-swipe")).toBeVisible();
- const zoomed = page.locator(".cz-item .ca-handle");
- await expect(zoomed).toHaveAttribute("aria-valuenow", "95");
- await zoomed.focus();
- await page.keyboard.press("Home");
- await expect(zoomed).toHaveAttribute("aria-valuenow", "0");
+ await expect(page.locator(".cz-dialog")).toHaveCount(0);
+ await expect(swipe).not.toHaveAttribute("data-zoom");
+ await expect(page.locator("main .ca-slider")).not.toHaveAttribute("data-wide");
});
test("Copy puts a screenshot on the clipboard with its marks, and a right-click on the image finds the same copy", async ({
diff --git a/e2e/wide.e2e.ts b/e2e/wide.e2e.ts
index b0aa6ed99..2f84f9ece 100644
--- a/e2e/wide.e2e.ts
+++ b/e2e/wide.e2e.ts
@@ -20,14 +20,15 @@ flowchart LR
const small = "```mermaid\nflowchart TD\n A --> B\n```";
const compare =
"## Checkout\n\n::compare\n\n\n::";
+const slider = compare.replace("::compare", '::compare{mode="slider"}');
// A 46rem column in a 1440px window, the way a docs page or a review doc lays out its text.
-async function column(page: Page, room?: { start: string; end: string }) {
+async function column(page: Page, room?: { start: string; end: string }, comparison = compare) {
await page.setViewportSize({ width: 1440, height: 900 });
const style = room ? `--comark-wide-start:${room.start};--comark-wide-end:${room.end};` : "";
await page.setContent(
`${await render(
- [flowchart, small, compare].join("\n\n"),
+ [flowchart, small, comparison].join("\n\n"),
)}`,
);
}
@@ -83,6 +84,20 @@ test("a wide diagram grows to its own width, centered on the column, and a compa
expect(wide.short).toBe(wide.main);
});
+test("a slider and its heading stay aligned in the column even with room to widen", async ({
+ page,
+}) => {
+ const side = "calc((100vw - 100%) / 2 - 1.5rem)";
+ await column(page, { start: side, end: side }, slider);
+ const layout = await widths(page);
+ const columnLeft = layout.center - layout.main / 2;
+ expect(layout.compare).toBe(layout.main);
+ expect(layout.compareLeft).toBe(columnLeft);
+ expect(layout.heading.width).toBe(layout.main);
+ expect(layout.heading.left).toBe(columnLeft);
+ expect(layout.title).toBe(columnLeft);
+});
+
test("with room on one side only, a wide diagram keeps its size and moves toward it", async ({
page,
}) => {
diff --git a/e2e/zoom.e2e.ts b/e2e/zoom.e2e.ts
index 6927fdf20..3f20663c1 100644
--- a/e2e/zoom.e2e.ts
+++ b/e2e/zoom.e2e.ts
@@ -747,7 +747,7 @@ test("figure navigation counts interleaved named groups at their first item", as
await expect(page.locator("main [data-zoom]").first()).toBeFocused();
});
-test("Up and Down move between the page's figures, scroll a tall one first, and leave a slider its keys", async ({
+test("Up and Down move between the page's figures, scroll a tall one first, and don't wrap", async ({
page,
}) => {
await page.emulateMedia({ reducedMotion: "reduce" });
@@ -767,25 +767,15 @@ test("Up and Down move between the page's figures, scroll a tall one first, and
const filler = "Pigeons home from far away. ".repeat(200);
await fixture(
page,
- await render(
- [
- image,
- filler,
- pair(),
- filler,
- pair('mode="slider"'),
- filler,
- "",
- ].join("\n\n"),
- ),
+ await render([image, filler, pair(), filler, ""].join("\n\n")),
);
const dialog = page.locator(".cz-dialog");
const place = page.locator(".cz-place");
await page.locator("main img[data-zoom]").first().click();
- await expect(place).toHaveText("Figure 1 of 4");
+ await expect(place).toHaveText("Figure 1 of 3");
await page.keyboard.press("ArrowDown");
- await expect(place).toHaveText("Figure 2 of 4");
+ await expect(place).toHaveText("Figure 2 of 3");
await expect(page.locator(".cz-count")).toHaveText("1 / 2");
await expect(page.locator(".cz-title")).toHaveText("Before");
await expect(page.locator(".cz-thumb")).toHaveCount(2);
@@ -793,33 +783,21 @@ test("Up and Down move between the page's figures, scroll a tall one first, and
await page.keyboard.press("ArrowRight");
await expect(page.locator(".cz-title")).toHaveText("After");
- // A comparison keeps Up and Down for its divider.
- await page.keyboard.press("ArrowDown");
- await expect(place).toHaveText("Figure 3 of 4");
- const handle = page.locator(".cz-item .ca-handle");
- await handle.focus();
- await page.keyboard.press("ArrowUp");
- await expect(handle).toHaveAttribute("aria-valuenow", "55");
- await expect(place).toHaveText("Figure 3 of 4");
- await dialog.focus();
-
// A tall figure scrolls to its end before Down moves on, and the last figure doesn't wrap.
await page.keyboard.press("ArrowDown");
- await expect(place).toHaveText("Figure 4 of 4");
+ await expect(place).toHaveText("Figure 3 of 3");
await expect(page.locator(".cz-nav")).toHaveCount(0);
const stage = page.locator(".cz-stage");
await page.keyboard.press("ArrowDown");
await expect.poll(() => stage.evaluate((node) => node.scrollTop)).toBeGreaterThan(0);
await stage.evaluate((node) => (node.scrollTop = node.scrollHeight));
await page.keyboard.press("ArrowDown");
- await expect(place).toHaveText("Figure 4 of 4");
+ await expect(place).toHaveText("Figure 3 of 3");
await stage.evaluate((node) => (node.scrollTop = 0));
- // Back up to the first comparison, then close: the page has scrolled to it and focus lands on it.
- await page.keyboard.press("ArrowUp");
- await expect(place).toHaveText("Figure 3 of 4");
+ // Back up to the comparison, then close: the page has scrolled to it and focus lands on it.
await page.keyboard.press("ArrowUp");
- await expect(place).toHaveText("Figure 2 of 4");
+ await expect(place).toHaveText("Figure 2 of 3");
await page.keyboard.press("Escape");
await expect(dialog).toHaveCount(0);
const first = page.locator("main [data-zoom-gallery] [data-zoom]").first();
diff --git a/packages/annotate/docs/components/compare.md b/packages/annotate/docs/components/compare.md
index 06dc3f0fb..bc170d53f 100644
--- a/packages/annotate/docs/components/compare.md
+++ b/packages/annotate/docs/components/compare.md
@@ -29,7 +29,7 @@ Fixed.
- The two screenshots sit side by side, and on a narrow screen they show one at a time.
- They zoom as one gallery.
- Notes are numbered on from the first screenshot to the second.
-- A slider lays the pair in one frame, with a divider to drag.
+- A slider lays the pair in one frame, with a divider to drag. It stays in the text column and doesn't zoom.
- Without the script, a slider's screenshots stack.
## Usage
@@ -51,7 +51,7 @@ Put exactly two [`screenshot`](/annotate/components/screenshot) blocks inside, t
### Title
-Use the `title` prop to say what the comparison shows. Side by side, it's the name screen readers read, and defaults to "Comparison". In a slider, it titles the zoomed view, and defaults to the screenshots' titles, such as "Before / After".
+Use the `title` prop to say what the comparison shows. Side by side, it's the name screen readers read, and defaults to "Comparison". In a slider, it names the pair for screen readers, and defaults to the screenshots' titles, such as "Before / After".
```md
::compare{title="Toolbar alignment"}
@@ -65,7 +65,7 @@ Use the `title` prop to say what the comparison shows. Side by side, it's the na
### Slider
-Use the `mode` prop set to `slider` to lay the two screenshots in one frame, Before left of a divider and After right of it. Use it for a small change in one spot, so the reader sees it at full width.
+Use the `mode` prop set to `slider` to lay the two screenshots in one frame, Before left of a divider and After right of it. Use it for a small change in one spot. The slider fills the text column and doesn't open the zoomed view.
::example
```md
@@ -86,7 +86,6 @@ Use the `mode` prop set to `slider` to lay the two screenshots in one frame, Bef
::
- Drag anywhere on the pair to move the divider, or focus its handle and use the arrow keys.
-- A click that doesn't drag zooms the pair.
- Side notes join the numbered list.
### Ink
@@ -139,13 +138,13 @@ Side by side, a note with `side="left"` or `side="right"` joins the numbered lis
Side by side, the pair is a carousel region named by its `title`. Each screenshot is a slide, such as "1 of 2", and a tab stop that opens the [zoomed view](/zoom).
-In a slider, the pair is one tab stop that zooms. Its divider is a slider named "Divider between Before and After", with a value such as "Before 50%, After 50%". It takes the arrow keys on the page and in the zoomed view.
+In a slider, the pair is a group named by its `title`, and its divider is the only tab stop. The divider is a slider named "Divider between Before and After", with a value such as "Before 50%, After 50%". It takes the arrow keys.
### Keyboard interactions
| Key | Description |
| --- | --- |
-| `Enter`, `Space` | Opens the focused screenshot, or the slider's pair, in the zoomed view. |
+| `Enter`, `Space` | Opens the focused screenshot in the zoomed view. |
| `ArrowLeft`, `ArrowRight` | Side by side, moves to the other screenshot when they show one at a time, and in the zoomed view. |
| `ArrowLeft`, `ArrowDown` | On the slider's divider, moves it 5% left. |
| `ArrowRight`, `ArrowUp` | On the slider's divider, moves it 5% right. |
@@ -158,7 +157,7 @@ In a slider, the pair is one tab stop that zooms. Its divider is a slider named
| Prop | Default | Description |
| --- | --- | --- |
-| `title` | "Comparison" | What the comparison shows. Screen readers read it side by side. In a slider, it titles the zoomed view, and defaults to the screenshots' titles joined by " / ". |
+| `title` | "Comparison" | What the comparison shows. Screen readers read it side by side. In a slider, it names the pair, and defaults to the screenshots' titles joined by " / ". |
| `mode` | `columns` | `columns` puts the screenshots side by side. `slider` lays one over the other with a divider to drag. |
| `ink` | — | The color of every mark and note in both screenshots that doesn't set its own. A screenshot's own `ink` wins. |
| `id` | — | An id for the comparison, such as `#fig-toolbar`, that links and [comark-xref](/xref) references point at. |
diff --git a/packages/annotate/src/html.ts b/packages/annotate/src/html.ts
index 77442c715..4ec2c7ee3 100644
--- a/packages/annotate/src/html.ts
+++ b/packages/annotate/src/html.ts
@@ -357,7 +357,8 @@ async function figure(
const GRIP = ``;
// Without the script the two screenshots stack, each under its title. The script lays them over each other and lets
-// the reader drag the divider; the notes stay under the pair, and beside it when zoomed.
+// the reader drag the divider; the notes stay under the pair. It sits in the text column and doesn't zoom, since
+// zoom would show the pair no larger than the column and put the notes beside it.
async function slider({ id: own, title, shots }: Compare, state: State, id: string) {
const names = shots.map((shot) => shot.title || shot.alt);
let sides = "";
@@ -373,8 +374,8 @@ async function slider({ id: own, title, shots }: Compare, state: State, id: stri
`
` +
`${GRIP}
`;
return (
- `
${sides}${shots.length === 2 ? handle : ""}
` +
- `${notes && `
${notes}
`}
${zoomRuntime(state)}${runtime(state)}`
+ `
${sides}${shots.length === 2 ? handle : ""}
` +
+ `${notes && `
${notes}
`}
${runtime(state)}`
);
}
diff --git a/packages/annotate/src/script.ts b/packages/annotate/src/script.ts
index b7b52ec46..43414a9bd 100644
--- a/packages/annotate/src/script.ts
+++ b/packages/annotate/src/script.ts
@@ -10,9 +10,9 @@ declare global {
}
/**
- * Starts every `.ca-swipe` slider on the page: a drag anywhere on the pair moves the divider, the handle takes arrow
- * keys, and a click that doesn't drag still zooms. The handle is a focusable `role="separator"`, a window splitter, so
- * the motion layer, where the page runs it, bends its line past either edge and springs it back. Also lets a reader copy a screenshot with its
+ * Starts every `.ca-swipe` slider on the page: a drag anywhere on the pair moves the divider, and the handle takes
+ * arrow keys. The handle is a focusable `role="separator"`, a window splitter, so the motion layer, where the page
+ * runs it, bends its line past either edge and springs it back. Also lets a reader copy a screenshot with its
* marks, by its Copy button, Control or Command+C, or the browser's menu on the image. Returns a function that stops it. The
* function is self-contained: the HTML renderer inlines its source as a script, so it must not use anything from
* outside its body.
@@ -99,14 +99,11 @@ export function start(): () => void {
() => document.querySelectorAll(comparisons).forEach(scheduleFit),
{ signal },
);
- // A press that moves less than this is a click, which zooms.
+ // A press that moves less than this isn't a drag.
const SLOP = 4;
type Drag = { swipe: HTMLElement; id: number; x: number; moved: boolean };
let drag: Drag | null = null;
- // Whether the last press on each slider dragged. A browser may send that press's click late, even after the next
- // press starts, so it's dropped when the click comes rather than on a timer.
- const dragged = new WeakMap();
const splits = new WeakMap();
const swipeOf = (target: EventTarget | null) =>
@@ -165,26 +162,11 @@ export function start(): () => void {
if (!drag || event.pointerId !== drag.id) return;
const { swipe, moved } = drag;
drag = null;
- dragged.set(swipe, moved && event.type === "pointerup");
if (moved) swipe.removeAttribute("data-dragging");
};
document.addEventListener("pointerup", release, { signal });
document.addEventListener("pointercancel", release, { signal });
- // Zoom skips a click that's already handled: the one ending a drag, and any on the handle, which is there to drag.
- addEventListener(
- "click",
- (event) => {
- const swipe = swipeOf(event.target);
- if (!swipe) return;
- const handle = event.target instanceof Element && event.target.closest(".ca-handle");
- if (!handle && !dragged.get(swipe)) return;
- dragged.delete(swipe);
- event.preventDefault();
- },
- { capture: true, signal },
- );
-
// Firefox drags the image out of the page otherwise.
document.addEventListener(
"dragstart",
@@ -217,14 +199,6 @@ export function start(): () => void {
{ signal },
);
- // Zoom copies the slider without its tab stops; the handle needs its own back to move by key.
- const focusable = () => {
- for (const handle of document.querySelectorAll(".cz-dialog .ca-handle"))
- handle.setAttribute("tabindex", "0");
- };
- document.addEventListener("comark-zoom:open", focusable, { signal });
- document.addEventListener("comark-zoom:change", focusable, { signal });
-
// Copying. The marks are HTML and SVG over a plain image, so the browser's own Copy Image leaves them out. The copy
// paints the screenshot's figure as it rests on the page (image, marks, stamps, arrows, and notes) onto a canvas.
const copying = "clipboard" in navigator && "ClipboardItem" in window;
@@ -245,14 +219,7 @@ export function start(): () => void {
if (!(target instanceof Element)) return null;
if (target.closest(".ca-zoom-tools")) return zoomed;
if (target.closest(".cz-dialog"))
- return zoomed &&
- target.closest(
- zoomed.matches(".ca-side") || zoomed.matches(".ca-swipe")
- ? ".ca-swipe"
- : ".ca-screenshot",
- )
- ? zoomed
- : null;
+ return zoomed && target.closest(".ca-screenshot") ? zoomed : null;
return target.closest(".ca-screenshot");
};
const keyOf = (figure: HTMLElement) => {
@@ -757,7 +724,7 @@ export function start(): () => void {
const figure = own
? figureOf(target)
: target?.matches(".cz-dialog")
- ? figureOf(target.querySelector(".ca-screenshot, .ca-swipe"))
+ ? figureOf(target.querySelector(".ca-screenshot"))
: null;
if (!target || !figure) return;
event.preventDefault();
@@ -776,15 +743,8 @@ export function start(): () => void {
const focused = active?.closest(".ca-hide") ? ".ca-hide input" : active ? ".ca-copy" : null;
zoomCopy?.remove();
zoomCopy = null;
- // A screenshot zooms its stage, inside the source that copy paints. Sliders zoom their pair, so use the first
- // side as the screenshot source for the keyboard copy path.
- zoomed =
- item instanceof HTMLElement
- ? (item.closest(".ca-screenshot") ??
- (item.matches(".ca-swipe")
- ? item.querySelector(".ca-side-before .ca-stage")
- : null))
- : null;
+ // A screenshot zooms its stage, inside the source that copy paints.
+ zoomed = item instanceof HTMLElement ? item.closest(".ca-screenshot") : null;
// Zoom copies the figure as it was, a moment's "Copied" included; a thumbnail is a button and gets no button inside.
for (const part of document.querySelectorAll(
".cz-thumb :is(.ca-copy,.ca-copy-status,.ca-hide)",
diff --git a/packages/annotate/test/annotate.test.ts b/packages/annotate/test/annotate.test.ts
index ede94e1ac..7a7345d65 100644
--- a/packages/annotate/test/annotate.test.ts
+++ b/packages/annotate/test/annotate.test.ts
@@ -89,7 +89,7 @@ describe("comark-annotate", () => {
);
expect(issues).toEqual([]);
expect(html).toContain(
- '