@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 37 lines 1.15 KB
Raw
1 import type { SheetViewport } from "./sheet-protocol";
2
3 export function cachedViewport(frame: SheetViewport, viewport: SheetViewport) {
4 return {
5 x: Math.max(frame.x, Math.min(viewport.x, frame.x + Math.max(0, frame.width - viewport.width))),
6 y: Math.max(
7 frame.y,
8 Math.min(viewport.y, frame.y + Math.max(0, frame.height - viewport.height)),
9 ),
10 };
11 }
12
13 export function bufferedViewport(viewport: SheetViewport): SheetViewport {
14 const marginX = Math.min(128, viewport.width / 4);
15 const marginY = Math.min(256, viewport.height / 3);
16 const x = Math.max(0, viewport.x - marginX);
17 const y = Math.max(0, viewport.y - marginY);
18 return {
19 x,
20 y,
21 width: viewport.width + viewport.x - x + marginX,
22 height: viewport.height + viewport.y - y + marginY,
23 };
24 }
25
26 export function retainCachedViewport(
27 cached: SheetViewport,
28 incoming: SheetViewport,
29 current: SheetViewport,
30 ) {
31 const covers = (frame: SheetViewport) =>
32 frame.x <= current.x &&
33 frame.y <= current.y &&
34 frame.x + frame.width >= current.x + current.width &&
35 frame.y + frame.height >= current.y + current.height;
36 return covers(cached) && !covers(incoming);
37 }