Let ?w=&h= fix the editor canvas to a set size

A recording of the editor is as large as its canvas, and so far the
canvas always followed the window. With ?w=1920&h=1080 the editor is
laid out at exactly that size in CSS pixels, whatever the window.

- src/ui/pageSize.ts reads w and h (both needed, 200 to 8192 each) and
  works out how the canvas fits the window.
- A smaller window shows the canvas shrunk to fit, centred, with the
  same aspect. A larger one shows it 1:1, centred on a dark page.
- Clicks still land right, since Pixi maps them over the canvas's
  on-screen box. Switching projects keeps w and h in the URL.
- The pointer drawn into an editor recording now scales against the
  layout size, so a shrunk canvas still records a full-size pointer.

Tests:
- Unit page-size: 5 new, green.
- e2e 62d: ?w=1600&h=900 in a 960x720 window gives a 1600x900 canvas
  shown at 960x540, y 90, and a click on the menu button opens it.
  Red without the shrinking.
- Gate on melektaus-atx: 304 files, 4691 tests green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-10-12 14:44:28 +02:00
1 parent d6a325978c
commit 846a8b70b3
6 files changed
+129 -6

No files matched your search

+5 -3
View File
@@ -207,7 +207,8 @@ class CanvasSource implements FrameSource {
const at = fitPicture({ w: canvas.width, h: canvas.height }, this.size);
const x = at.x + ((pointer.x - rect.left) / rect.width) * at.w;
const y = at.y + ((pointer.y - rect.top) / rect.height) * at.h;
const scale = at.w / rect.width;
// Against the layout size: a canvas shrunk to fit (`?w=&h=`) still records a full-size pointer.
const scale = at.w / ui().app.screen.width;
let path = this.paths.get(shape);
if (!path) this.paths.set(shape, (path = new Path2D(shape.path)));
const pen = this.framePen;
@@ -263,8 +264,9 @@ class PointerTrack {
this.attached = true;
const rect = canvas.getBoundingClientRect();
const at = ui().app.renderer.events.pointer.global;
this.x = rect.left + at.x;
this.y = rect.top + at.y;
const shown = rect.width / ui().app.screen.width;
this.x = rect.left + at.x * shown;
this.y = rect.top + at.y * shown;
this.inside = at.x > 0 || at.y > 0;
window.addEventListener('pointermove', this.moved, { capture: true, passive: true });
window.addEventListener('pointerdown', this.moved, { capture: true, passive: true });