Skip to content
Merged
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
26 changes: 26 additions & 0 deletions .agents/skills/verify-screens/features/camera-focus.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A person pans with Hand, Shift-drag, the middle button or the wheel. They zoom w
## Sub-features

- `cam-pan`: Hand, Shift-drag and the wheel pan by the screen delta, with no revision.
- `minimap`: the map is off by default. Turn it on to see the canvas and navigate by click or drag. The choice survives a reload.
- `cam-zoom`: zoom out and in around the centre; Cmd+0 goes to 100%; Fit all frames everything and turns auto-fit back on.
- `focus`: the Focus action, or the agent's `focus_item`, fits one frame and hides the others. Exit focus or Escape returns.
- `focus-wheel`: in focus with Move, the wheel over the live page pans the camera, as Hand does. A scroll area inside the page keeps the wheel while it can still scroll.
Expand All @@ -22,6 +23,7 @@ A person pans with Hand, Shift-drag, the middle button or the wheel. They zoom w
## How to get to it (user POV)

- Press H or hold Shift and drag. Use the zoom buttons, Cmd+wheel, the Focus action on a selected frame, and Escape.
- Click the map icon in the zoom controls. Click the overview to jump or drag the viewport outline to pan.
- An agent calls `show_items`, `focus_item`, `get_view` and `open_screen`.

## Driving it with screens-cli
Expand Down Expand Up @@ -59,6 +61,30 @@ fit
expect view.autoFit=true
```

```screens id=minimap
expect dom.minimap=null
click ui:Minimap
expect dom.minimap.items=0
add_object title=A files=fixture:plain x=0 y=0 height=300 as=@A
zoom 100
add_object title=B files=fixture:plain x=8000 y=0 height=300 as=@B
expect dom.minimap.items=2
mark
click ui:"Canvas overview"
expect view.camera.x<-3000 view.camera.z=1 dom.minimap.x>3000 doc.rev=+0 storage.rev=doc.rev
mark
drag ui:"Canvas overview" by 20,0
expect view.camera.x<+-500 view.camera.z=1 dom.minimap.x>+500 doc.rev=+0
mark
zoom in
expect view.camera.z=1.25 dom.minimap.width<+0
view reload
wait dom.minimap.items=2
click ui:Minimap
view reload
expect dom.minimap=null
```

```screens id=focus
add_object title=A files=fixture:plain x=0 y=0 height=300 as=@A
add_object title=B files=fixture:plain x=500 y=0 height=300 as=@B
Expand Down
4 changes: 1 addition & 3 deletions .agents/skills/verify-screens/features/cli-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ get service.conns
expect service.dev=true events.revisions>0 console.errors=0
dump all as=state
theme dark
invert-scroll on
expect view.theme=dark view.invertScroll=true
expect view.theme=dark
theme light
invert-scroll off
```

## Gotchas
Expand Down
7 changes: 1 addition & 6 deletions .agents/skills/verify-screens/features/keyboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Every canvas action works from the keyboard. On a canvas, arrow keys move the se
- `kbd-camera`: with nothing selected the arrows pan. Shift+1 fits all, Shift+2 frames the selection, and Cmd+= and Cmd+- zoom.
- `kbd-focus`: Enter renames the selected item. F focuses it, Tab moves focus to the next item, and F or Escape leaves.
- `kbd-toolbar`: clicking a toolbar button leaves keyboard focus on the canvas, so the arrows still pan.
- `wheel-zoom`: Cmd plus scrolling up (deltaY < 0) zooms in and scrolling down zooms out, a pinch outward (Ctrl, deltaY < 0) zooms in, and Invert scroll flips both.
- `wheel-zoom`: Cmd plus scrolling up (deltaY < 0) zooms in and scrolling down zooms out, a pinch outward (Ctrl, deltaY < 0) zooms in.
- `lib-kbd-open`: in the library, Cmd+Down opens the focused Screen.

## How to get to it (user POV)
Expand Down Expand Up @@ -128,11 +128,6 @@ expect view.camera.z>1
zoom 100
wheel 0,100 --pinch
expect view.camera.z<1
invert-scroll on
zoom 100
wheel 0,-100 --cmd
expect view.camera.z<1
invert-scroll off
```

```screens id=lib-kbd-open
Expand Down
21 changes: 12 additions & 9 deletions packages/canvas/src/engine/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export interface ViewState {
readonly comment: CommentSession & { readonly showResolved: boolean; readonly restore: CommentSession | null };
/** The command's deadline uses the animation clock, independently of its wire timestamp. */
readonly deferredCommand: (ViewCommand & { readonly expiresAt: number }) | null;
readonly invertScroll: boolean;
readonly capabilities: { readonly comments: boolean };
/** The participant whose work the camera follows (roster Follow). Any press, wheel, zoom or Escape releases it. */
readonly following: string | null;
Expand Down Expand Up @@ -137,8 +136,8 @@ export type CanvasInput =

export type WheelZoom = "none" | "cmd" | "pinch";
/** Wheel delta to zoom exponent. Scrolling up (deltaY < 0) with Cmd or Ctrl zooms in, and so does a trackpad pinch
* outward, which browsers report as a Ctrl wheel with deltaY < 0. Invert scroll flips it. */
export const wheelZoom = (dy: number, invert: boolean): number => -dy * WHEEL_ZOOM_K * (invert ? -1 : 1);
* outward, which browsers report as a Ctrl wheel with deltaY < 0. */
const wheelZoom = (dy: number): number => -dy * WHEEL_ZOOM_K;

/** A file the shell has already read. No Blob reaches the engine: the runtime keeps the bytes under the hash. */
export interface DroppedImage { readonly hash: string; readonly mediaType: string; readonly width: number; readonly height: number; readonly title: string }
Expand All @@ -162,7 +161,7 @@ export type Command =
| { readonly kind: "focus"; readonly itemId: ItemId } | { readonly kind: "exit-focus" }
| { readonly kind: "select-tool"; readonly tool: ToolId } | { readonly kind: "delete" } | { readonly kind: "undo" } | { readonly kind: "redo" }
| { readonly kind: "pencil-color"; readonly color: string } | { readonly kind: "pencil-size"; readonly size: PencilSize }
| { readonly kind: "invert-scroll"; readonly on: boolean } | { readonly kind: "edit"; readonly editing: Editing }
| { readonly kind: "center-camera"; readonly at: Point } | { readonly kind: "edit"; readonly editing: Editing }
/** Panel row or card Close (null). */
| { readonly kind: "open-thread"; readonly threadId: ThreadId | null }
| { readonly kind: "resolve-thread"; readonly threadId: ThreadId; readonly resolved: boolean }
Expand Down Expand Up @@ -206,12 +205,12 @@ export interface Step { readonly state: ViewState; readonly effects: readonly Ef

export const ESCAPE_CHAIN = ["cancel-gesture", "clear-stroke-selection", "clear-comment", "clear-interacting", "exit-focus", "clear-selection", "tool-move"] as const;

export function initialViewState(o: { viewport: Size; pointer: "fine" | "coarse"; dpr: number; theme: "light" | "dark"; invertScroll?: boolean }): ViewState {
export function initialViewState(o: { viewport: Size; pointer: "fine" | "coarse"; dpr: number; theme: "light" | "dark" }): ViewState {
return {
viewport: o.viewport, pointer: o.pointer, dpr: o.dpr, theme: o.theme, camera: { x: 0, y: 0, z: 1 }, autoFit: true, moving: false, animation: null,
focus: { mode: "none" }, tool: "move", shiftPanning: false, pencil: { color: defaultInk(o.theme), size: 6 },
selection: { kind: "items", ids: [] }, interacting: null, gesture: null, wheel: { dx: 0, dy: 0, zoom: 0, anchor: { x: 0, y: 0 }, scheduled: false },
editing: null, comment: { draft: null, activeThreadId: null, parkedDraft: null, showResolved: false, expanded: false, panelOpen: false, editingCommentId: null, composing: false, restore: null }, deferredCommand: null, invertScroll: o.invertScroll ?? false, capabilities: { comments: true }, following: null,
editing: null, comment: { draft: null, activeThreadId: null, parkedDraft: null, showResolved: false, expanded: false, panelOpen: false, editingCommentId: null, composing: false, restore: null }, deferredCommand: null, capabilities: { comments: true }, following: null,
pages: SCROLL,
};
}
Expand Down Expand Up @@ -277,7 +276,7 @@ function stepInner(s: ViewState, input: CanvasInput, doc: BaseDoc, env: Env, fx:
const w = s.wheel;
if (input.zoom === "none" && policy(s, doc).wheel === "vertical") input = { ...input, dx: 0 };
const next = input.zoom !== "none"
? { ...w, zoom: w.zoom + wheelZoom(input.dy, s.invertScroll), anchor: input.client }
? { ...w, zoom: w.zoom + wheelZoom(input.dy), anchor: input.client }
: { ...w, dx: w.dx + input.dx, dy: w.dy + input.dy };
if (!w.scheduled) fx.push({ type: "request-frame" });
return { ...s, wheel: { ...next, scheduled: true } };
Expand Down Expand Up @@ -307,7 +306,7 @@ function stepInner(s: ViewState, input: CanvasInput, doc: BaseDoc, env: Env, fx:
// A wheel the page cannot scroll itself pans the canvas, as it would outside a live page.
if (m.kind === "pan") return stepInner(s, { type: "wheel", dx: m.dx, dy: m.dy, zoom: "none", client: { x: s.viewport.width / 2, y: s.viewport.height / 2 } }, doc, env, fx);
const anchor = { x: s.camera.x + (it.x + m.x) * s.camera.z, y: s.camera.y + (it.y + m.y) * s.camera.z };
return userCamera(s, zoomAround(s.camera, Math.exp(wheelZoom(m.dy, s.invertScroll)), anchor), doc, fx);
return userCamera(s, zoomAround(s.camera, Math.exp(wheelZoom(m.dy)), anchor), doc, fx);
}
case "command": return command(s, input.command, doc, env, fx);
case "title-commit": {
Expand Down Expand Up @@ -895,6 +894,11 @@ function command(s: ViewState, c: Command, doc: BaseDoc, env: Env, fx: Effect[])
case "zoom-in": return userCamera(s, zoomAround(s.camera, ZOOM_STEP_IN, center), doc, fx);
case "zoom-out": return userCamera(s, zoomAround(s.camera, ZOOM_STEP_OUT, center), doc, fx);
case "zoom-100": return userCamera(s, zoomAround(s.camera, 1 / s.camera.z, center), doc, fx);
case "center-camera": {
if (s.focus.mode === "focused" || presenting(s, doc)) return s;
const { z } = s.camera;
return userCamera({ ...s, animation: null }, { x: center.x - c.at.x * z, y: center.y - c.at.y * z, z }, doc, fx);
}
case "fit-all": {
if (s.focus.mode !== "none") return s;
const cam = fitFor(s, doc, boundsOf(doc.items.map((i) => i.rect)));
Expand Down Expand Up @@ -986,7 +990,6 @@ function command(s: ViewState, c: Command, doc: BaseDoc, env: Env, fx: Effect[])
case "redo": fx.push({ type: "redo" }); return s;
case "pencil-color": return { ...s, pencil: { ...s.pencil, color: c.color } };
case "pencil-size": return { ...s, pencil: { ...s.pencil, size: c.size } };
case "invert-scroll": return { ...s, invertScroll: c.on };
case "edit": return { ...s, editing: c.editing };
case "pages-view": return pagesView(s, c.view, doc, env, fx);
}
Expand Down
82 changes: 82 additions & 0 deletions packages/canvas/src/shell/Minimap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { useLayoutEffect, useRef, type PointerEvent } from "react";
import type { Point, Rect } from "@screens/core";
import { boundsOf, containsPoint, strokeBounds, strokePath, viewportWorldRect, type BaseDoc } from "../engine/index.ts";
import type { CanvasRuntime } from "./runtime.ts";

const WIDTH = 200, HEIGHT = 132, INSET = 10;

function mapBounds(content: Rect | null, viewport: Rect): Rect {
const b = content ? boundsOf([content, viewport])! : viewport;
const unitsPerPixel = Math.max(b.w / (WIDTH - 2 * INSET), b.h / (HEIGHT - 2 * INSET));
const w = WIDTH * unitsPerPixel, h = HEIGHT * unitsPerPixel;
return { x: b.x + (b.w - w) / 2, y: b.y + (b.h - h) / 2, w, h };
}

export function Minimap({ rt, doc }: { rt: CanvasRuntime; doc: BaseDoc }) {
const svg = useRef<SVGSVGElement>(null);
const outline = useRef<SVGRectElement>(null);
const projection = useRef<Rect | null>(null);
const drag = useRef<{ id: number; bounds: Rect; offset: Point } | null>(null);
const items = doc.items.filter((it) => !it.removing);
const ink = doc.strokes.filter((s) => !s.removing && s.anchor.kind === "world" && s.points.length > 0);
const content = boundsOf([...items.map((it) => it.rect), ...ink.map((s) => strokeBounds(s.points, s.size))]);

const paint = () => {
const map = svg.current, rect = outline.current;
if (!map || !rect) return;
const viewport = viewportWorldRect(rt.view.camera, rt.view.viewport);
if (viewport.w <= 0 || viewport.h <= 0) return;
// Keep the map still under a captured pointer while the camera moves.
const bounds = drag.current?.bounds ?? mapBounds(content, viewport);
projection.current = bounds;
map.setAttribute("viewBox", `${bounds.x} ${bounds.y} ${bounds.w} ${bounds.h}`);
rect.setAttribute("x", String(viewport.x));
rect.setAttribute("y", String(viewport.y));
rect.setAttribute("width", String(viewport.w));
rect.setAttribute("height", String(viewport.h));
};
useLayoutEffect(() => {
paint();
return rt.onPaint(paint);
});

const worldPoint = (e: PointerEvent<SVGSVGElement>, b: Rect): Point => {
const r = e.currentTarget.getBoundingClientRect();
const fraction = (n: number) => Math.max(0, Math.min(1, n));
return { x: b.x + fraction((e.clientX - r.left) / r.width) * b.w, y: b.y + fraction((e.clientY - r.top) / r.height) * b.h };
};
const navigate = (p: Point, offset: Point) => rt.dispatch({
type: "command", command: { kind: "center-camera", at: { x: p.x + offset.x, y: p.y + offset.y } },
});
const start = (e: PointerEvent<SVGSVGElement>) => {
const bounds = projection.current;
if (e.button !== 0 || !bounds || drag.current || rt.view.gesture) return;
const p = worldPoint(e, bounds);
const v = viewportWorldRect(rt.view.camera, rt.view.viewport);
const inside = containsPoint(v, p);
const offset = inside ? { x: v.x + v.w / 2 - p.x, y: v.y + v.h / 2 - p.y } : { x: 0, y: 0 };
e.currentTarget.setPointerCapture(e.pointerId);
drag.current = { id: e.pointerId, bounds, offset };
if (!inside) navigate(p, offset);
};
const move = (e: PointerEvent<SVGSVGElement>) => {
const active = drag.current;
if (active?.id === e.pointerId) navigate(worldPoint(e, active.bounds), active.offset);
};
const end = (e: PointerEvent<SVGSVGElement>) => {
if (drag.current?.id !== e.pointerId) return;
drag.current = null;
paint();
};

return (
<div className="chrome screens-minimap">
<svg ref={svg} width={WIDTH} height={HEIGHT} preserveAspectRatio="none" role="img" aria-label="Canvas overview"
onPointerDown={start} onPointerMove={move} onPointerUp={end} onPointerCancel={end} onLostPointerCapture={end}>
{items.map(({ id, rect: r }) => <rect key={id} className="screens-minimap-item" x={r.x} y={r.y} width={r.w} height={r.h} />)}
{ink.map((s) => <path key={s.id} d={strokePath(s.points, s.size)} fill={s.color} />)}
<rect ref={outline} className="screens-minimap-viewport" vectorEffect="non-scaling-stroke" />
</svg>
</div>
);
}
11 changes: 9 additions & 2 deletions packages/canvas/src/shell/ScreenCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {
HANDLES, PENCIL_COLORS, PRESENT_KEYS, PRESENT_PRELOAD, boundsOf, copyableItem, nextItem, PENCIL_SIZES, TOOLS, policyOf, presentFrame, presentIndex, presentThread, renderDocOf, slotBar, strokeBounds, strokePath,
type DisplayItem, type DisplayStroke, type FramePresentation, type PagesView, type ViewState,
} from "../engine/index.ts";
import { CanvasRuntime, hitTargetOf, isControl, isEditable } from "./runtime.ts";
import { CanvasRuntime, hitTargetOf, isControl, isEditable, safeStore } from "./runtime.ts";
import { Icon } from "./icons.tsx";
import { dockAt, Grip, SPOTS, useDock, type DockSpot } from "./Dock.tsx";
import { CommentLayer, CommentOverlay, CommentsPanel } from "./Comments.tsx";
import { PieceEditor } from "./Layers.tsx";
import { Minimap } from "./Minimap.tsx";
import { Filmstrip } from "./Filmstrip.tsx";
import { PresenceLayer, PresenceOverlay, PresenceRoster } from "./Presence.tsx";

Expand Down Expand Up @@ -112,6 +113,11 @@ export function ScreenCanvas({ client, viewId, onRuntime, leading, trailing }: {
const [compactLayersOpen, setCompactLayersOpen] = useState(false);
// On a wide canvas the person's choice to hide Layers holds across focus; on a compact one it starts closed each time.
const [wideLayersOpen, setWideLayersOpen] = useState(() => { try { return localStorage.getItem("screens.layersOpen") !== "0"; } catch { return true; } });
const [minimapOpen, setMinimapOpen] = useState(() => safeStore.get("screens.minimapOpen") === "1");
const toggleMinimap = () => {
safeStore.set("screens.minimapOpen", minimapOpen ? "0" : "1");
setMinimapOpen(!minimapOpen);
};
const compactCanvas = v.viewport.width <= 700;
const focusId = v.focus.mode === "focused" ? v.focus.itemId : null;
useEffect(() => { setCompactLayersOpen(false); }, [focusId]);
Expand Down Expand Up @@ -266,10 +272,11 @@ export function ScreenCanvas({ client, viewId, onRuntime, leading, trailing }: {
)}
</div>

{minimapOpen && !presenting && !focusId && <Minimap rt={rt} doc={doc} />}
<div className="chrome screens-zoom" data-dock={zoomAt}>
<div className="shell">
<Grip label="Move zoom controls" spot={zoomAt} open={SPOTS.filter((s) => s !== toolsAt && !pagesHold.includes(s))} onDock={setZoomSpot} />
<button className="tool" aria-label="Invert scroll" title="Invert scroll" aria-pressed={v.invertScroll} onClick={() => rt.setInvertScroll(!v.invertScroll)}><Icon name="scroll" /></button>
<button className="tool" aria-label="Minimap" title="Minimap" aria-pressed={minimapOpen} disabled={focusId !== null} onClick={toggleMinimap}><Icon name="map" /></button>
<button className="tool" aria-label="Theme" title="Theme" onClick={() => rt.setTheme(v.theme === "dark" ? "light" : "dark")}><Icon name={v.theme === "dark" ? "sun" : "moon"} /></button>
<span className="shell-divider" />
<button className="tool" aria-label="Zoom out" title="Zoom out" onClick={() => rt.dispatch({ type: "command", command: { kind: "zoom-out" } })}><Icon name="minus" /></button>
Expand Down
Loading
Loading