// Reusable canvas for frame capture — single canvas instance per CLAUDE.md
let captureCanvas: HTMLCanvasElement | null = null;

export function captureFrame(video: HTMLVideoElement): string | null {
  if (!captureCanvas) {
    captureCanvas = document.createElement('canvas');
  }
  captureCanvas.width = video.videoWidth;
  captureCanvas.height = video.videoHeight;
  const ctx = captureCanvas.getContext('2d');
  if (!ctx) return null;
  ctx.drawImage(video, 0, 0);
  return captureCanvas.toDataURL('image/jpeg', 0.95);
}

export function downloadDataUrl(dataUrl: string, filename: string): void {
  const a = document.createElement('a');
  a.href = dataUrl;
  a.download = filename;
  a.click();
}
