cursedbelt 5.92.3 → 5.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/react/components/ComboboxField.d.ts +10 -0
  2. package/dist/react/components/ComboboxField.d.ts.map +1 -1
  3. package/dist/react/components/ComboboxField.js +4 -4
  4. package/dist/react/components/ComboboxField.js.map +1 -1
  5. package/dist/react/components/CommentThread.d.ts +9 -3
  6. package/dist/react/components/CommentThread.d.ts.map +1 -1
  7. package/dist/react/components/CommentThread.js +25 -11
  8. package/dist/react/components/CommentThread.js.map +1 -1
  9. package/dist/react/components/VoiceNote.d.ts +20 -0
  10. package/dist/react/components/VoiceNote.d.ts.map +1 -0
  11. package/dist/react/components/VoiceNote.js +54 -0
  12. package/dist/react/components/VoiceNote.js.map +1 -0
  13. package/dist/react/components/VoiceRecorder.d.ts +35 -0
  14. package/dist/react/components/VoiceRecorder.d.ts.map +1 -0
  15. package/dist/react/components/VoiceRecorder.js +155 -0
  16. package/dist/react/components/VoiceRecorder.js.map +1 -0
  17. package/dist/react/index.d.ts +2 -0
  18. package/dist/react/index.d.ts.map +1 -1
  19. package/dist/react/index.js +2 -0
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/react/map-frame/MapFrame.d.ts +219 -0
  22. package/dist/react/map-frame/MapFrame.d.ts.map +1 -0
  23. package/dist/react/map-frame/MapFrame.js +726 -0
  24. package/dist/react/map-frame/MapFrame.js.map +1 -0
  25. package/dist/react/map-frame/geo.d.ts +210 -0
  26. package/dist/react/map-frame/geo.d.ts.map +1 -0
  27. package/dist/react/map-frame/geo.js +345 -0
  28. package/dist/react/map-frame/geo.js.map +1 -0
  29. package/dist/react/map-frame/index.d.ts +5 -0
  30. package/dist/react/map-frame/index.d.ts.map +1 -0
  31. package/dist/react/map-frame/index.js +3 -0
  32. package/dist/react/map-frame/index.js.map +1 -0
  33. package/dist/styles-areas/canvas-hud.css +5 -5
  34. package/dist/styles-areas/workbench.css +17 -17
  35. package/package.json +13 -1
  36. package/scripts/guardrails-baseline.json +1 -1
  37. package/scripts/styleAreas.ts +1 -1
  38. package/src/react/components/ComboboxField.spec.tsx +39 -0
  39. package/src/react/components/ComboboxField.tsx +20 -4
  40. package/src/react/components/CommentThread.spec.tsx +25 -0
  41. package/src/react/components/CommentThread.tsx +60 -10
  42. package/src/react/components/VoiceNote.tsx +92 -0
  43. package/src/react/components/VoiceRecorder.spec.tsx +116 -0
  44. package/src/react/components/VoiceRecorder.tsx +224 -0
  45. package/src/react/index.ts +9 -0
  46. package/src/react/map-frame/MapFrame.spec.ts +168 -0
  47. package/src/react/map-frame/MapFrame.tsx +954 -0
  48. package/src/react/map-frame/geo.spec.ts +393 -0
  49. package/src/react/map-frame/geo.ts +421 -0
  50. package/src/react/map-frame/index.ts +34 -0
  51. package/src/react/media/HoverScrubVideoThumb.spec.tsx +4 -0
  52. package/src/styles-areas/canvas-hud.css +5 -5
  53. package/src/styles-areas/workbench.css +17 -17
@@ -0,0 +1,224 @@
1
+ import { Send, Trash2 } from 'lucide-react';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { cn } from '../lib/cn.js';
4
+ import { Button } from './Button.js';
5
+ import { formatVoiceTime, VoiceNote } from './VoiceNote.js';
6
+
7
+ /** Two minutes: a spoken memory, not a podcast. Opus at speech rates is ~0.5 MB, AAC ~2 MB. */
8
+ export const VOICE_MAX_MS = 120_000;
9
+
10
+ /**
11
+ * The container a recording is written in, best first: Opus in WebM where Chromium and Firefox
12
+ * take it, AAC in MP4 for WebKit (Safari records no WebM). `null` when the browser records none.
13
+ */
14
+ export const VOICE_MIME_CANDIDATES = ['audio/webm;codecs=opus', 'audio/mp4', 'audio/webm', 'audio/ogg;codecs=opus'] as const;
15
+
16
+ export function pickVoiceMime(
17
+ isSupported: (type: string) => boolean = (t) => typeof MediaRecorder !== 'undefined' && MediaRecorder.isTypeSupported(t),
18
+ ): string | null {
19
+ return VOICE_MIME_CANDIDATES.find((t) => isSupported(t)) ?? null;
20
+ }
21
+
22
+ export interface VoiceRecording {
23
+ blob: Blob;
24
+ /** The container without its codec parameter — `audio/webm`, `audio/mp4` — what a server keys on. */
25
+ mime: string;
26
+ durationMs: number;
27
+ }
28
+
29
+ export interface VoiceRecorderProps {
30
+ /** The recording, when the person sends it. */
31
+ onDone: (recording: VoiceRecording) => void;
32
+ /** Canceled, discarded, or the microphone could not be had. */
33
+ onCancel: () => void;
34
+ /** Recording stops itself here and waits to be sent or discarded. Default {@link VOICE_MAX_MS}. */
35
+ maxMs?: number;
36
+ className?: string;
37
+ }
38
+
39
+ type Phase =
40
+ | { kind: 'starting' }
41
+ | { kind: 'recording' }
42
+ | { kind: 'ready'; recording: VoiceRecording; url: string }
43
+ | { kind: 'error'; message: string };
44
+
45
+ /** The meter's five bars, lit from the left as the voice gets louder. */
46
+ const BARS = ['h-1.5', 'h-2.5', 'h-3.5', 'h-2.5', 'h-1.5'] as const;
47
+
48
+ function refusal(error: unknown): string {
49
+ const name = error instanceof DOMException ? error.name : '';
50
+ if (name === 'NotAllowedError' || name === 'SecurityError') return 'Microphone access was refused. Allow it in the browser to record.';
51
+ if (name === 'NotFoundError' || name === 'OverconstrainedError') return 'No microphone was found.';
52
+ return 'The microphone could not be started.';
53
+ }
54
+
55
+ /**
56
+ * Records one voice note from the microphone. It starts on mount — the person already tapped
57
+ * "record" to show it — and shows a running time and a level meter so they can see it hears them.
58
+ * **Send** stops and hands the recording over in one tap (WhatsApp's flow, not stop → review →
59
+ * send); **Cancel** throws it away. At `maxMs` it stops by itself and offers the take back to
60
+ * listen to, send or discard, rather than sending something nobody chose to send.
61
+ *
62
+ * The level meter reads an `AnalyserNode` when the browser has Web Audio; without one the
63
+ * meter stays dark and the recording still works.
64
+ */
65
+ export function VoiceRecorder({ onDone, onCancel, maxMs = VOICE_MAX_MS, className, ...rest }: VoiceRecorderProps) {
66
+ const [phase, setPhase] = useState<Phase>({ kind: 'starting' });
67
+ const [elapsed, setElapsed] = useState(0);
68
+ const [level, setLevel] = useState(0);
69
+ const recorder = useRef<MediaRecorder | null>(null);
70
+ /** What the next `stop` event does with the take: send it, keep it for review, or drop it. */
71
+ const then = useRef<'send' | 'review' | 'drop'>('drop');
72
+ const callbacks = useRef({ onDone, onCancel });
73
+ callbacks.current = { onDone, onCancel };
74
+
75
+ useEffect(() => {
76
+ let live = true;
77
+ let stream: MediaStream | null = null;
78
+ let audioContext: AudioContext | null = null;
79
+ let tick: ReturnType<typeof setInterval> | undefined;
80
+ let frame = 0;
81
+ const chunks: Blob[] = [];
82
+ let startedAt = 0;
83
+
84
+ const mimeType = pickVoiceMime();
85
+ if (!navigator.mediaDevices?.getUserMedia || !mimeType) {
86
+ setPhase({ kind: 'error', message: 'This browser cannot record audio.' });
87
+ return;
88
+ }
89
+
90
+ navigator.mediaDevices
91
+ .getUserMedia({ audio: true })
92
+ .then((s) => {
93
+ stream = s;
94
+ if (!live) {
95
+ for (const t of s.getTracks()) t.stop();
96
+ return;
97
+ }
98
+ const rec = new MediaRecorder(s, { mimeType });
99
+ recorder.current = rec;
100
+ rec.ondataavailable = (e) => {
101
+ if (e.data.size > 0) chunks.push(e.data);
102
+ };
103
+ rec.onstop = () => {
104
+ clearInterval(tick);
105
+ cancelAnimationFrame(frame);
106
+ for (const t of s.getTracks()) t.stop();
107
+ if (!live || then.current === 'drop') return;
108
+ const mime = (rec.mimeType || mimeType).split(';')[0] ?? 'audio/webm';
109
+ const recording: VoiceRecording = { blob: new Blob(chunks, { type: mime }), mime, durationMs: Math.min(maxMs, performance.now() - startedAt) };
110
+ if (then.current === 'send') callbacks.current.onDone(recording);
111
+ else setPhase({ kind: 'ready', recording, url: URL.createObjectURL(recording.blob) });
112
+ };
113
+ rec.start(250);
114
+ startedAt = performance.now();
115
+ setPhase({ kind: 'recording' });
116
+ tick = setInterval(() => {
117
+ const ms = performance.now() - startedAt;
118
+ setElapsed(Math.min(ms, maxMs));
119
+ if (ms >= maxMs && rec.state === 'recording') {
120
+ then.current = 'review';
121
+ rec.stop();
122
+ }
123
+ }, 200);
124
+
125
+ const Ctx = typeof AudioContext === 'undefined' ? null : AudioContext;
126
+ if (Ctx) {
127
+ audioContext = new Ctx();
128
+ const analyser = audioContext.createAnalyser();
129
+ analyser.fftSize = 512;
130
+ audioContext.createMediaStreamSource(s).connect(analyser);
131
+ const samples = new Uint8Array(analyser.fftSize);
132
+ const read = () => {
133
+ analyser.getByteTimeDomainData(samples);
134
+ let sum = 0;
135
+ for (const v of samples) sum += ((v - 128) / 128) ** 2;
136
+ // RMS of speech sits around 0.05–0.3; five steps across that range.
137
+ setLevel(Math.min(BARS.length, Math.round(Math.sqrt(sum / samples.length) * 20)));
138
+ frame = requestAnimationFrame(read);
139
+ };
140
+ frame = requestAnimationFrame(read);
141
+ }
142
+ })
143
+ .catch((error: unknown) => {
144
+ if (live) setPhase({ kind: 'error', message: refusal(error) });
145
+ });
146
+
147
+ return () => {
148
+ live = false;
149
+ clearInterval(tick);
150
+ cancelAnimationFrame(frame);
151
+ if (recorder.current?.state === 'recording') recorder.current.stop();
152
+ if (stream) for (const t of stream.getTracks()) t.stop();
153
+ void audioContext?.close();
154
+ };
155
+ }, [maxMs]);
156
+
157
+ useEffect(() => {
158
+ if (phase.kind !== 'ready') return;
159
+ return () => URL.revokeObjectURL(phase.url);
160
+ }, [phase]);
161
+
162
+ const stopAnd = (what: 'send' | 'drop') => {
163
+ then.current = what;
164
+ if (recorder.current?.state === 'recording') recorder.current.stop();
165
+ if (what === 'drop') onCancel();
166
+ };
167
+
168
+ if (phase.kind === 'error') {
169
+ return (
170
+ <div {...rest} role='alert' className={cn('flex items-center gap-2 rounded-lg bg-muted px-3 py-2 text-sm', className)}>
171
+ <span className='min-w-0 flex-1 text-muted-foreground'>{phase.message}</span>
172
+ <Button variant='ghost' size='sm' onClick={onCancel} tooltip='Close the recorder'>
173
+ Close
174
+ </Button>
175
+ </div>
176
+ );
177
+ }
178
+
179
+ if (phase.kind === 'ready') {
180
+ return (
181
+ <div {...rest} data-cb-voice-recorder='ready' className={cn('flex items-center gap-2 rounded-lg bg-muted px-2 py-1.5', className)}>
182
+ <VoiceNote src={phase.url} durationMs={phase.recording.durationMs} label='Play your recording' className='flex-1' />
183
+ <Button variant='ghost' size='sm' leftIcon={<Trash2 className='h-4 w-4' aria-hidden />} onClick={onCancel} tooltip='Discard the recording'>
184
+ Discard
185
+ </Button>
186
+ <Button variant='primary' size='sm' leftIcon={<Send className='h-4 w-4' aria-hidden />} onClick={() => onDone(phase.recording)} tooltip='Send the voice comment'>
187
+ Send
188
+ </Button>
189
+ </div>
190
+ );
191
+ }
192
+
193
+ const recording = phase.kind === 'recording';
194
+ return (
195
+ <div {...rest} data-cb-voice-recorder={phase.kind} className={cn('flex items-center gap-3 rounded-lg bg-muted px-3 py-1.5', className)}>
196
+ <span aria-hidden className={cn('size-2.5 shrink-0 rounded-full bg-destructive', recording && 'animate-pulse')} />
197
+ <span role='timer' aria-label='Recording time' className='shrink-0 text-sm font-medium tabular-nums text-foreground'>
198
+ {recording ? formatVoiceTime(elapsed) : 'Starting…'}
199
+ </span>
200
+ <span aria-hidden className='flex h-4 items-center gap-0.5'>
201
+ {BARS.map((h, i) => (
202
+ // biome-ignore lint/suspicious/noArrayIndexKey: five fixed bars, never reordered
203
+ <span key={i} className={cn('w-1 rounded-full', h, i < level ? 'bg-accent-solid' : 'bg-border-strong')} />
204
+ ))}
205
+ </span>
206
+ <span className='min-w-0 flex-1 truncate text-xs text-muted-foreground'>
207
+ {recording ? `up to ${formatVoiceTime(maxMs)}` : ''}
208
+ </span>
209
+ <Button variant='ghost' size='sm' onClick={() => stopAnd('drop')} tooltip='Cancel the recording'>
210
+ Cancel
211
+ </Button>
212
+ <Button
213
+ variant='primary'
214
+ size='sm'
215
+ disabled={!recording}
216
+ leftIcon={<Send className='h-4 w-4' aria-hidden />}
217
+ onClick={() => stopAnd('send')}
218
+ tooltip='Send the voice comment'
219
+ >
220
+ Send
221
+ </Button>
222
+ </div>
223
+ );
224
+ }
@@ -213,6 +213,15 @@ export {
213
213
  CommentThread,
214
214
  type CommentThreadProps,
215
215
  } from './components/CommentThread.js';
216
+ export { formatVoiceTime, VoiceNote, type VoiceNoteProps } from './components/VoiceNote.js';
217
+ export {
218
+ pickVoiceMime,
219
+ VOICE_MAX_MS,
220
+ VOICE_MIME_CANDIDATES,
221
+ type VoiceRecording,
222
+ VoiceRecorder,
223
+ type VoiceRecorderProps,
224
+ } from './components/VoiceRecorder.js';
216
225
  export { ConfirmDialog, type ConfirmDialogProps } from './components/ConfirmDialog.js';
217
226
  export {
218
227
  ConnectionHealer,
@@ -0,0 +1,168 @@
1
+ /**
2
+ * The map's pan arithmetic.
3
+ *
4
+ * ── Why these three functions are pure, and tested here ─────────────────────
5
+ * The owner reported the atlas's drag as *"the nodes and paths move while the map
6
+ * stays still and catches up after dropping"*. The cause was not arithmetic — both
7
+ * halves projected correctly — it was that the overlay re-projected per pointer
8
+ * move while the imagery had to be FETCHED per pointer move. No unit test could
9
+ * have caught that, and the rewrite's comments carry the story.
10
+ *
11
+ * What a test CAN pin is the three pieces of math the rewrite introduced, each of
12
+ * which is silently wrong in a way a screenshot would not show:
13
+ *
14
+ * · `pannedCenter` — a drag must cover the same GROUND at every zoom, and the
15
+ * center must move opposite the finger. Getting the sign right by accident is
16
+ * easy; getting the zoom scaling right by accident is not.
17
+ * · `imagePlacement` — where the imagery already on screen belongs inside the
18
+ * viewport being drawn now. This is the whole reason a released drag does not
19
+ * flash: an off-by-half-a-frame here shows as the map jumping at the exact
20
+ * moment the reader lets go, which reads as the original bug.
21
+ * · `mapImageSource` — the URL, which is a BILLABLE render. A round trip through
22
+ * it proves a committed pan asks for the viewport it landed on rather than a
23
+ * neighboring one, and the four-decimal rounding is what keeps the server's
24
+ * cache key space finite.
25
+ */
26
+ import { describe, expect, test } from "bun:test";
27
+ import { imagePlacement, mapImageSource, pannedCenter, VIEW_HEIGHT, VIEW_WIDTH, visibleArea } from "./MapFrame.js";
28
+ import { project, type Viewport } from "./geo.js";
29
+
30
+ const LONDON = { lat: 51.5074, lng: -0.1278 };
31
+ const view = (center = LONDON, zoom = 6): Viewport => ({
32
+ center,
33
+ zoom,
34
+ width: VIEW_WIDTH,
35
+ height: VIEW_HEIGHT,
36
+ });
37
+
38
+ describe("pannedCenter — where a released drag lands", () => {
39
+ test("no movement is no movement", () => {
40
+ const next = pannedCenter(LONDON, 6, { dx: 0, dy: 0 });
41
+ expect(next.lat).toBeCloseTo(LONDON.lat, 9);
42
+ expect(next.lng).toBeCloseTo(LONDON.lng, 9);
43
+ });
44
+
45
+ test("dragging right moves the center WEST — the map follows the finger", () => {
46
+ // The sign that makes a map feel like a map. Backwards, and every drag
47
+ // scrolls away from where the reader is reaching.
48
+ const next = pannedCenter(LONDON, 6, { dx: 100, dy: 0 });
49
+ expect(next.lng).toBeLessThan(LONDON.lng);
50
+ expect(next.lat).toBeCloseTo(LONDON.lat, 6);
51
+ });
52
+
53
+ test("dragging down moves the center NORTH", () => {
54
+ const next = pannedCenter(LONDON, 6, { dx: 0, dy: 80 });
55
+ expect(next.lat).toBeGreaterThan(LONDON.lat);
56
+ });
57
+
58
+ test("the same drag covers HALF the ground one zoom level in", () => {
59
+ // The property that makes panning feel identical at every scale. Computed in
60
+ // pixels, so it is exact rather than approximate.
61
+ const out = pannedCenter(LONDON, 6, { dx: 128, dy: 0 });
62
+ const inOne = pannedCenter(LONDON, 7, { dx: 128, dy: 0 });
63
+ const outDelta = LONDON.lng - out.lng;
64
+ const inDelta = LONDON.lng - inOne.lng;
65
+ expect(inDelta).toBeCloseTo(outDelta / 2, 9);
66
+ });
67
+
68
+ test("a drag then its exact reverse returns to where it started", () => {
69
+ const there = pannedCenter(LONDON, 8, { dx: 73, dy: -41 });
70
+ const back = pannedCenter(there, 8, { dx: -73, dy: 41 });
71
+ expect(back.lat).toBeCloseTo(LONDON.lat, 6);
72
+ expect(back.lng).toBeCloseTo(LONDON.lng, 6);
73
+ });
74
+
75
+ test("the point under the finger stays under the finger", () => {
76
+ // The one claim a reader actually makes about a drag: whatever they grabbed
77
+ // is what they are holding when they let go. Expressed as: a landmark's
78
+ // projected position moves by exactly the drag delta.
79
+ const landmark = { lat: 48.8566, lng: 2.3522 };
80
+ const pan = { dx: 55, dy: -30 };
81
+ const before = project(landmark, view());
82
+ const after = project(landmark, view(pannedCenter(LONDON, 6, pan), 6));
83
+ expect(after.x - before.x).toBeCloseTo(pan.dx, 6);
84
+ expect(after.y - before.y).toBeCloseTo(pan.dy, 6);
85
+ });
86
+ });
87
+
88
+ describe("imagePlacement — the render already on screen, in the viewport being drawn", () => {
89
+ test("the settled viewport IS the current one: full frame, no offset", () => {
90
+ const at = imagePlacement({ center: LONDON, zoom: 6 }, view());
91
+ expect(at.x).toBeCloseTo(0, 9);
92
+ expect(at.y).toBeCloseTo(0, 9);
93
+ expect(at.width).toBe(VIEW_WIDTH);
94
+ expect(at.height).toBe(VIEW_HEIGHT);
95
+ });
96
+
97
+ test("after a committed drag the old imagery sits exactly where the drag left it", () => {
98
+ // 🔴 The no-flash property. The reader dragged by `pan`; the frame committed
99
+ // a new center; the picture they were looking at has to be drawn `pan` away
100
+ // from the middle, or it snaps back the instant they release — which is
101
+ // indistinguishable from the bug this replaced.
102
+ const pan = { dx: 90, dy: -45 };
103
+ const committed = pannedCenter(LONDON, 6, pan);
104
+ const at = imagePlacement({ center: LONDON, zoom: 6 }, view(committed, 6));
105
+ expect(at.x).toBeCloseTo(pan.dx, 6);
106
+ expect(at.y).toBeCloseTo(pan.dy, 6);
107
+ });
108
+
109
+ test("a zoom IN leaves the old render covering the middle at double size", () => {
110
+ const at = imagePlacement({ center: LONDON, zoom: 6 }, view(LONDON, 7));
111
+ expect(at.width).toBe(VIEW_WIDTH * 2);
112
+ expect(at.height).toBe(VIEW_HEIGHT * 2);
113
+ // Centered: it overhangs the frame equally on every side.
114
+ expect(at.x).toBeCloseTo(-VIEW_WIDTH / 2, 6);
115
+ expect(at.y).toBeCloseTo(-VIEW_HEIGHT / 2, 6);
116
+ });
117
+
118
+ test("a zoom OUT leaves it half-size in the middle, not stretched to fill", () => {
119
+ // Stretching would be the lie: it would claim detail the render does not
120
+ // have. Half-size with the graticule around it is the honest shape.
121
+ const at = imagePlacement({ center: LONDON, zoom: 6 }, view(LONDON, 5));
122
+ expect(at.width).toBe(VIEW_WIDTH / 2);
123
+ expect(at.x).toBeCloseTo(VIEW_WIDTH / 4, 6);
124
+ });
125
+ });
126
+
127
+ describe("mapImageSource — the billable render's URL", () => {
128
+ test("carries the viewport, the size and the theme", () => {
129
+ const url = mapImageSource(LONDON, 6, "dark");
130
+ expect(url).toContain("lat=51.5074");
131
+ expect(url).toContain("lng=-0.1278");
132
+ expect(url).toContain("z=6");
133
+ expect(url).toContain(`w=${VIEW_WIDTH}`);
134
+ expect(url).toContain(`h=${VIEW_HEIGHT}`);
135
+ expect(url).toContain("theme=dark");
136
+ });
137
+
138
+ test("rounds to four decimals, so a cache key space stays finite", () => {
139
+ // ~11 meters. Two viewports that differ by less are the same picture, and
140
+ // the server caches per URL — an unrounded center would make every drag a
141
+ // cache miss and a fresh charge.
142
+ expect(mapImageSource({ lat: 51.50740001, lng: -0.12780002 }, 6, "light")).toBe(
143
+ mapImageSource(LONDON, 6, "light"),
144
+ );
145
+ });
146
+
147
+ test("a committed pan asks for a DIFFERENT picture than it started from", () => {
148
+ // The other direction: rounding must not be so coarse that a real drag
149
+ // re-requests the render it already has and the map never moves.
150
+ const moved = pannedCenter(LONDON, 6, { dx: 120, dy: 60 });
151
+ expect(mapImageSource(moved, 6, "light")).not.toBe(mapImageSource(LONDON, 6, "light"));
152
+ });
153
+ });
154
+
155
+ describe("visibleArea — what a box of that size shows of the sliced viewport", () => {
156
+ test("a 16:10 box shows all of it, and so does an unmeasured one", () => {
157
+ expect(visibleArea({ width: 1280, height: 800 })).toEqual({ x: 0, y: 0, width: VIEW_WIDTH, height: VIEW_HEIGHT });
158
+ expect(visibleArea({ width: 0, height: 0 })).toEqual({ x: 0, y: 0, width: VIEW_WIDTH, height: VIEW_HEIGHT });
159
+ });
160
+
161
+ test("a phone's 4:5 box crops the sides, centered — the middle 320 of 640", () => {
162
+ expect(visibleArea({ width: 358, height: 447.5 })).toEqual({ x: 160, y: 0, width: 320, height: VIEW_HEIGHT });
163
+ });
164
+
165
+ test("a letterbox crops top and bottom", () => {
166
+ expect(visibleArea({ width: 1280, height: 400 })).toEqual({ x: 0, y: 100, width: VIEW_WIDTH, height: 200 });
167
+ });
168
+ });