Skip to content

ui: full-screen diagram preview that zooms around what is on screen, inert diagrams - #32591

Merged
allozaur merged 3 commits into
ggml-org:masterfrom
allozaur:allozaur/fix/ui-inert-diagrams
Nov 20, 2026
Merged

allozaur merged 3 commits into
ggml-org:masterfrom
allozaur:allozaur/fix/ui-inert-diagrams

Conversation

@allozaur

@allozaur allozaur commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Overview

The diagram preview opens full screen, and zooming follows what you're looking at: the pointer for the wheel or a pinch, the middle of the screen for the buttons, wherever the diagram has been panned to. Diagrams also stay inert again: a click directive no longer turns a node into a live link. Follows up #32555 (review).

Demo

Demo

Recorded at faddbad; click the preview for the full video.

Additional information

Cause
  • Zoom: the diagram scaled around its own middle, while panning moved it with a separate offset. After panning, zooming pulled the view back towards the diagram's middle instead of the part on screen. The wheel stepped the scale by a fixed 0.15, so each step was a large jump when zoomed out and a small one when zoomed in.
  • Links: ui: cut Llama Chat's first-load JavaScript by 63%, load diagrams, math and PDFs on demand #32555 replaced Mermaid with Pele. Mermaid ran with securityLevel: 'strict', which left diagrams without links. Pele wraps a node with click A href "…" in <a href="…"> (with target="_blank" when given). It already drops javascript: URLs, ignores click … call and emits no event handlers, so the link is the only interactive part.
What changed
  • DialogMermaidPreview fills the window on every device; on phones it keeps clear of the status bar and the home indicator as other dialogs do.
  • MermaidPreview places the diagram from its top left corner, so a zoom can keep any screen point fixed. The math is in diagram-viewport.ts:
    • the wheel and a trackpad pinch zoom around the pointer, by a factor that follows the scroll distance;
    • the zoom buttons and the +/- keys zoom around the middle of the screen, by 1.25×;
    • drag to pan, two-finger pinch on touch (zooming around the fingers and moving with them), double-click to zoom in 2×, arrow keys to pan;
    • the diagram opens fitted to the screen (above the controls; a small diagram grows up to 2×) and keeps fitting as the window resizes or a streamed svg grows, until you pan or zoom. Reset view (0) fits it again.
  • renderMermaidDiagrams() unwraps every <a> in Pele's output, keeping its children. The inline block, the live preview of the markdown editor, the preview dialog and the downloaded SVG all take the diagram from there, so none of them has a link.
  • Storybook: new MermaidPreview stories (flowchart, wide, small and sequence diagrams) and a DialogMermaidPreview story. The flowchart in the MarkdownContent Diagrams story gets click … href and click … call directives.
Testing

In ui/apps/chat, after npm ci: npm run check, npm run lint, the unit, client and Storybook tests and npm run build pass.

  • diagram-viewport.test.ts: zooming keeps the point under the pointer or the middle of the screen in place, also after a pan and at the scale limits; fitting shrinks a large diagram and grows a small one up to the cap; wheel and pinch factors.
  • The MermaidPreview Flowchart story's play test zooms with the wheel and checks the point under the pointer stays put, pans, zooms out with the button and checks the middle of the screen stays put, and checks that Reset view fits the diagram again. The Wide diagram story checks that fitting shrinks it.
  • The DialogMermaidPreview story checks that the dialog fills the window. The MarkdownContent Diagrams story checks that no <a> or href is left in the rendered diagrams (this fails without the unwrapping) and that its preview button opens the full-screen preview.
  • By hand in Storybook, desktop and a 375 px phone in dark and light mode: the preview opens full screen, fitted; wheel zoom, drag, pinch (synthetic touch pointers) and the buttons behave as above.

Not checked on a real phone or with a real trackpad pinch.

Demo script
test.use({ traces: ['diagrams'] });

test('Full-screen diagram preview', async ({ demo, page }) => {
	// the reload after the import races a hash start path, so open the conversation here
	await page.evaluate(() => (location.hash = '/chat/a1e09849-e0c0-4f2f-a11c-b37cf8084540'));

	const block = page.locator('pre.mermaid').first();

	await block.waitFor();
	// diagrams stay inert: no link in the rendered diagram
	await expect(block.locator('a')).toHaveCount(0);
	await demo.caption('Diagrams stay inert: the click directive makes no link');
	await demo.hover(block);
	await demo.click(page.locator('.preview-code-btn').first());

	const preview = page.locator('.mermaid-preview');

	await preview.waitFor();
	await demo.caption('The preview fills the screen, fitted');

	const box = (await preview.boundingBox())!;
	const at = (fx: number, fy: number) => ({
		x: box.x + box.width * fx,
		y: box.y + box.height * fy
	});

	await demo.caption('The wheel zooms around the pointer');
	await page.mouse.move(at(0.7, 0.4).x, at(0.7, 0.4).y);
	for (let i = 0; i < 6; i++) (await page.mouse.wheel(0, -120), await page.waitForTimeout(90));
	await demo.pause(900);

	await demo.caption('Drag to move around');
	await page.mouse.move(at(0.5, 0.5).x, at(0.5, 0.5).y);
	await page.mouse.down();
	await page.mouse.move(at(0.2, 0.6).x, at(0.2, 0.6).y, { steps: 25 });
	await page.mouse.up();
	await demo.pause(600);

	await demo.caption('The buttons zoom around the middle of the screen, not the old center');
	const out = page.getByRole('button', { name: 'Zoom out' });

	for (let i = 0; i < 3; i++) await demo.click(out, 500);
	await demo.pause(800);
	await demo.click(page.getByRole('button', { name: 'Reset view' }));
	await demo.pause(800);
	await demo.press('Escape');
});

Requirements

Pele turns a node with `click ... href` into a live link, where Mermaid's
strict security level left diagrams without links. Unwrap every link in
Pele's output, keeping its children, so the inline block, the live-preview
editor, the preview dialog and the downloaded svg stay inert. The Diagrams
story's flowchart now carries click directives and its play test checks
that no link or href is left.

Assisted-by: Claude (Opus 5.5 Medium)
@allozaur allozaur changed the title ui: keep Mermaid diagrams inert, without links from click directives ui: full-screen diagram preview that zooms around what is on screen, inert diagrams Nov 19, 2026
The diagram preview dialog fills the window on every device. The preview
places the diagram from its top left corner, so a zoom keeps a screen point
fixed: the wheel and a trackpad pinch zoom around the pointer, the buttons
and +/- keys around the middle of the screen, wherever the diagram has been
panned to. Two-finger pinch, double-click and arrow keys work too. The
diagram opens fitted and keeps fitting until panned or zoomed; Reset view
fits it again.

Adds MermaidPreview and DialogMermaidPreview stories with play tests and a
unit test for the zoom math.

Assisted-by: Claude (Opus 5.5 Medium)
Assisted-by: Claude (Opus 5.5 Medium)
@allozaur
allozaur marked this pull request as ready for review November 19, 2026 16:44
@allozaur
allozaur requested a review from a team as a code owner November 19, 2026 16:44
@github-actions github-actions Bot added the video demo PR features a video demo recorded with the UI demo pipeline label Nov 19, 2026
@allozaur
allozaur merged commit 55b8d8d into ggml-org:master Nov 20, 2026
10 checks passed
Kidplayer666 pushed a commit to Kidplayer666/llama.cpp that referenced this pull request Nov 20, 2026
…inert diagrams (ggml-org#32591)

* ui: keep Pele diagrams inert

Pele turns a node with `click ... href` into a live link, where Mermaid's
strict security level left diagrams without links. Unwrap every link in
Pele's output, keeping its children, so the inline block, the live-preview
editor, the preview dialog and the downloaded svg stay inert. The Diagrams
story's flowchart now carries click directives and its play test checks
that no link or href is left.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: open diagrams full screen, zoom around what is on screen

The diagram preview dialog fills the window on every device. The preview
places the diagram from its top left corner, so a zoom keeps a screen point
fixed: the wheel and a trackpad pinch zoom around the pointer, the buttons
and +/- keys around the middle of the screen, wherever the diagram has been
panned to. Two-finger pinch, double-click and arrow keys work too. The
diagram opens fitted and keeps fitting until panned or zoomed; Reset view
fits it again.

Adds MermaidPreview and DialogMermaidPreview stories with play tests and a
unit test for the zoom math.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add a diagrams trace to the demo fixtures

Assisted-by: Claude (Opus 5.5 Medium)
Annieren pushed a commit to Annieren/llama.cpp-upstream that referenced this pull request Nov 23, 2026
…inert diagrams (ggml-org#32591)

* ui: keep Pele diagrams inert

Pele turns a node with `click ... href` into a live link, where Mermaid's
strict security level left diagrams without links. Unwrap every link in
Pele's output, keeping its children, so the inline block, the live-preview
editor, the preview dialog and the downloaded svg stay inert. The Diagrams
story's flowchart now carries click directives and its play test checks
that no link or href is left.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: open diagrams full screen, zoom around what is on screen

The diagram preview dialog fills the window on every device. The preview
places the diagram from its top left corner, so a zoom keeps a screen point
fixed: the wheel and a trackpad pinch zoom around the pointer, the buttons
and +/- keys around the middle of the screen, wherever the diagram has been
panned to. Two-finger pinch, double-click and arrow keys work too. The
diagram opens fitted and keeps fitting until panned or zoomed; Reset view
fits it again.

Adds MermaidPreview and DialogMermaidPreview stories with play tests and a
unit test for the zoom math.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add a diagrams trace to the demo fixtures

Assisted-by: Claude (Opus 5.5 Medium)
Nindaleth pushed a commit to Nindaleth/llama.cpp that referenced this pull request Nov 26, 2026
…inert diagrams (ggml-org#32591)

* ui: keep Pele diagrams inert

Pele turns a node with `click ... href` into a live link, where Mermaid's
strict security level left diagrams without links. Unwrap every link in
Pele's output, keeping its children, so the inline block, the live-preview
editor, the preview dialog and the downloaded svg stay inert. The Diagrams
story's flowchart now carries click directives and its play test checks
that no link or href is left.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: open diagrams full screen, zoom around what is on screen

The diagram preview dialog fills the window on every device. The preview
places the diagram from its top left corner, so a zoom keeps a screen point
fixed: the wheel and a trackpad pinch zoom around the pointer, the buttons
and +/- keys around the middle of the screen, wherever the diagram has been
panned to. Two-finger pinch, double-click and arrow keys work too. The
diagram opens fitted and keeps fitting until panned or zoomed; Reset view
fits it again.

Adds MermaidPreview and DialogMermaidPreview stories with play tests and a
unit test for the zoom math.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add a diagrams trace to the demo fixtures

Assisted-by: Claude (Opus 5.5 Medium)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server/ui video demo PR features a video demo recorded with the UI demo pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants