Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(chrome-extension): add popup UI and recording controls

Richie McIlroyd4e2586c615b
diff --git a/apps/chrome-extension/src/popup/components/camera-selector.tsx b/apps/chrome-extension/src/popup/components/camera-selector.tsx
new file mode 100644
index 000000000..1f1083732
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/camera-selector.tsx
@@ -0,0 +1,189 @@
+import {
+ NO_CAMERA,
+ NO_CAMERA_VALUE,
+} from "@cap/recorder-core/recorder-constants";
+import clsx from "clsx";
+import { CameraIcon, CameraOffIcon } from "lucide-react";
+import type { KeyboardEvent, MouseEvent } from "react";
+import type { CameraDevice } from "../../shared/types";
+import { DEFAULT_CAMERA_DEVICE_ID } from "../../shared/types";
+import {
+ SelectContent,
+ SelectItem,
+ SelectRoot,
+ SelectTrigger,
+ SelectValue,
+} from "../ui/select";
+import { useMediaPermission } from "./use-media-permission";
+
+interface CameraSelectorProps {
+ selectedCameraId: string | null;
+ availableCameras: CameraDevice[];
+ permissionGranted: boolean;
+ disabled?: boolean;
+ open?: boolean;
+ onOpenChange?: (open: boolean) => void;
+ onCameraChange: (cameraId: string | null) => void;
+ onRefreshDevices: () => Promise<void> | void;
+ onPermissionBlocked: () => void;
+}
+
+export const CameraSelector = ({
+ selectedCameraId,
+ availableCameras,
+ permissionGranted,
+ disabled = false,
+ open,
+ onOpenChange,
+ onCameraChange,
+ onRefreshDevices,
+ onPermissionBlocked,
+}: CameraSelectorProps) => {
+ const cameraEnabled = selectedCameraId !== null;
+ const { state: permissionState, requestPermission } =
+ useMediaPermission("camera");
+
+ const permissionSupported = permissionState !== "unsupported";
+ const hasDeviceAccess = availableCameras.length > 0;
+ const hasAccess = permissionGranted || hasDeviceAccess || cameraEnabled;
+ const shouldRequestPermission =
+ permissionSupported && permissionState !== "granted" && !hasAccess;
+
+ const statusPillDisabled = !shouldRequestPermission && !cameraEnabled;
+
+ const statusPillClassName = clsx(
+ "px-[0.375rem] h-[1.25rem] min-w-[2.5rem] rounded-full text-[0.75rem] leading-[1.25rem] flex items-center justify-center font-normal transition-colors duration-200 disabled:opacity-100 disabled:pointer-events-none focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:ring-[var(--blue-8)]",
+ statusPillDisabled ? "cursor-default" : "cursor-pointer",
+ shouldRequestPermission
+ ? "bg-[var(--red-3)] text-[var(--red-11)]"
+ : cameraEnabled
+ ? "bg-[var(--blue-3)] text-[var(--blue-11)] hover:bg-[var(--blue-4)]"
+ : "bg-[var(--red-3)] text-[var(--red-11)]",
+ );
+
+ const handleStatusPillClick = async (
+ event: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>,
+ ) => {
+ if (shouldRequestPermission) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ try {
+ const granted = await requestPermission();
+ if (granted) {
+ await Promise.resolve(onRefreshDevices());
+ }
+ } catch (error) {
+ console.error("Camera permission request failed", error);
+ onPermissionBlocked();
+ }
+
+ return;
+ }
+
+ if (!cameraEnabled) {
+ return;
+ }
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ onCameraChange(null);
+ };
+
+ const handleStatusPillKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
+ if (event.key === "Enter" || event.key === " ") {
+ void handleStatusPillClick(event);
+ }
+ };
+
+ return (
+ <div className="flex flex-col gap-[0.25rem] items-stretch text-[--text-primary]">
+ <SelectRoot
+ value={selectedCameraId ?? NO_CAMERA_VALUE}
+ onValueChange={(value) => {
+ onCameraChange(value === NO_CAMERA_VALUE ? null : value);
+ }}
+ disabled={disabled}
+ open={open}
+ onOpenChange={onOpenChange}
+ >
+ <div className="relative w-full">
+ <SelectTrigger
+ className={clsx(
+ "relative flex flex-row items-center h-[2rem] pl-[0.375rem] pr-[3.5rem] gap-[0.375rem] border border-gray-3 rounded-lg w-full transition-colors overflow-hidden z-10 font-normal text-[0.875rem] bg-transparent hover:bg-transparent focus:bg-transparent focus:border-gray-3 hover:border-gray-3 text-[--text-primary] disabled:text-gray-11 [&>svg]:hidden",
+ disabled || shouldRequestPermission
+ ? "cursor-default"
+ : undefined,
+ )}
+ onPointerDown={(event) => {
+ if (shouldRequestPermission) {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ }}
+ onKeyDown={(event: KeyboardEvent<HTMLButtonElement>) => {
+ if (shouldRequestPermission) {
+ const keys = ["Enter", " ", "ArrowDown", "ArrowUp"];
+ if (keys.includes(event.key)) {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ }
+ }}
+ aria-disabled={disabled || shouldRequestPermission}
+ >
+ <SelectValue
+ placeholder={NO_CAMERA}
+ className="flex-1 flex items-center gap-[0.375rem] truncate"
+ />
+ </SelectTrigger>
+ <button
+ type="button"
+ className={clsx(
+ statusPillClassName,
+ "absolute right-[0.375rem] top-1/2 -translate-y-1/2 z-20",
+ )}
+ disabled={statusPillDisabled}
+ aria-disabled={statusPillDisabled}
+ onClick={(event) => void handleStatusPillClick(event)}
+ onKeyDown={handleStatusPillKeyDown}
+ >
+ {shouldRequestPermission
+ ? "Request permission"
+ : cameraEnabled
+ ? "On"
+ : "Off"}
+ </button>
+ </div>
+ <SelectContent className="z-[502]">
+ <SelectItem value={NO_CAMERA_VALUE}>
+ <span className="flex items-center gap-2 truncate">
+ <CameraOffIcon className="size-4 text-gray-11" />
+ {NO_CAMERA}
+ </span>
+ </SelectItem>
+ {selectedCameraId === DEFAULT_CAMERA_DEVICE_ID &&
+ !availableCameras.some(
+ (camera) => camera.deviceId === DEFAULT_CAMERA_DEVICE_ID,
+ ) && (
+ <SelectItem value={DEFAULT_CAMERA_DEVICE_ID}>
+ <span className="flex items-center gap-2 truncate">
+ <CameraIcon className="size-4 text-gray-11" />
+ System default camera
+ </span>
+ </SelectItem>
+ )}
+ {availableCameras.map((camera, index) => (
+ <SelectItem key={camera.deviceId} value={camera.deviceId}>
+ <span className="flex items-center gap-2 truncate">
+ <CameraIcon className="size-4 text-gray-11" />
+ {camera.label?.trim() || `Camera ${index + 1}`}
+ </span>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </SelectRoot>
+ </div>
+ );
+};
diff --git a/apps/chrome-extension/src/popup/components/cog-icon.tsx b/apps/chrome-extension/src/popup/components/cog-icon.tsx
new file mode 100644
index 000000000..4ca078689
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/cog-icon.tsx
@@ -0,0 +1,43 @@
+import clsx from "clsx";
+import type { SVGProps } from "react";
+
+interface CogIconProps extends SVGProps<SVGSVGElement> {
+ size?: number;
+}
+
+const CogIcon = ({ className, size = 28, ...props }: CogIconProps) => (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width={size}
+ height={size}
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className={clsx(
+ "transition-transform duration-700 [transition-timing-function:cubic-bezier(0.34,1.2,0.64,1)] group-hover:rotate-180",
+ className,
+ )}
+ {...props}
+ >
+ <title>Settings</title>
+ <path d="M12 20a8 8 0 1 0 0-16 8 8 0 0 0 0 16Z" />
+ <path d="M12 14a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z" />
+ <path d="M12 2v2" />
+ <path d="M12 22v-2" />
+ <path d="m17 20.66-1-1.73" />
+ <path d="M11 10.27 7 3.34" />
+ <path d="m20.66 17-1.73-1" />
+ <path d="m3.34 7 1.73 1" />
+ <path d="M14 12h8" />
+ <path d="M2 12h2" />
+ <path d="m20.66 7-1.73 1" />
+ <path d="m3.34 17 1.73-1" />
+ <path d="m17 3.34-1 1.73" />
+ <path d="m11 13.73-4 6.93" />
+ </svg>
+);
+
+export default CogIcon;
diff --git a/apps/chrome-extension/src/popup/components/how-it-works-button.tsx b/apps/chrome-extension/src/popup/components/how-it-works-button.tsx
new file mode 100644
index 000000000..be4355f12
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/how-it-works-button.tsx
@@ -0,0 +1,18 @@
+import { CircleHelpIcon } from "lucide-react";
+
+interface HowItWorksButtonProps {
+ onClick: () => void;
+}
+
+export const HowItWorksButton = ({ onClick }: HowItWorksButtonProps) => {
+ return (
+ <button
+ type="button"
+ onClick={onClick}
+ className="flex items-center justify-center gap-1 text-xs font-medium transition-colors hover:text-blue-12"
+ >
+ <CircleHelpIcon className="size-3.5" aria-hidden />
+ How it works (tips)
+ </button>
+ );
+};
diff --git a/apps/chrome-extension/src/popup/components/microphone-selector.tsx b/apps/chrome-extension/src/popup/components/microphone-selector.tsx
new file mode 100644
index 000000000..a1e766aee
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/microphone-selector.tsx
@@ -0,0 +1,202 @@
+import {
+ NO_MICROPHONE,
+ NO_MICROPHONE_VALUE,
+} from "@cap/recorder-core/recorder-constants";
+import clsx from "clsx";
+import { MicIcon, MicOffIcon } from "lucide-react";
+import type { KeyboardEvent, MouseEvent } from "react";
+import type { MicrophoneDevice } from "../../shared/types";
+import { DEFAULT_MICROPHONE_DEVICE_ID } from "../../shared/types";
+import {
+ SelectContent,
+ SelectItem,
+ SelectRoot,
+ SelectTrigger,
+ SelectValue,
+} from "../ui/select";
+import { useMediaPermission } from "./use-media-permission";
+
+interface MicrophoneSelectorProps {
+ selectedMicId: string | null;
+ availableMics: MicrophoneDevice[];
+ permissionGranted: boolean;
+ disabled?: boolean;
+ open?: boolean;
+ onOpenChange?: (open: boolean) => void;
+ onMicChange: (micId: string | null) => void;
+ onRefreshDevices: () => Promise<void> | void;
+ onPermissionBlocked: () => void;
+}
+
+export const MicrophoneSelector = ({
+ selectedMicId,
+ availableMics,
+ permissionGranted,
+ disabled = false,
+ open,
+ onOpenChange,
+ onMicChange,
+ onRefreshDevices,
+ onPermissionBlocked,
+}: MicrophoneSelectorProps) => {
+ const micEnabled = selectedMicId !== null;
+ const { state: permissionState, requestPermission } =
+ useMediaPermission("microphone");
+
+ const permissionSupported = permissionState !== "unsupported";
+ const hasDeviceAccess = availableMics.length > 0;
+ const hasAccess = permissionGranted || hasDeviceAccess || micEnabled;
+ const shouldRequestPermission =
+ permissionSupported && permissionState !== "granted" && !hasAccess;
+
+ const statusPillDisabled =
+ disabled || (!shouldRequestPermission && !micEnabled);
+
+ const statusPillClassName = clsx(
+ "px-[0.375rem] h-[1.25rem] min-w-[2.5rem] rounded-full text-[0.75rem] leading-[1.25rem] flex items-center justify-center font-normal transition-colors duration-200 disabled:opacity-100 disabled:pointer-events-none focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:ring-[var(--blue-8)]",
+ statusPillDisabled ? "cursor-default" : "cursor-pointer",
+ shouldRequestPermission
+ ? "bg-[var(--red-3)] text-[var(--red-11)]"
+ : micEnabled
+ ? "bg-[var(--blue-3)] text-[var(--blue-11)] hover:bg-[var(--blue-4)]"
+ : "bg-[var(--red-3)] text-[var(--red-11)]",
+ );
+
+ const handleStatusPillClick = async (
+ event: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>,
+ ) => {
+ if (disabled) {
+ event.preventDefault();
+ event.stopPropagation();
+ return;
+ }
+
+ if (shouldRequestPermission) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ try {
+ const granted = await requestPermission();
+ if (granted) {
+ await Promise.resolve(onRefreshDevices());
+ }
+ } catch (error) {
+ console.error("Microphone permission request failed", error);
+ onPermissionBlocked();
+ }
+
+ return;
+ }
+
+ if (!micEnabled) {
+ return;
+ }
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ onMicChange(null);
+ };
+
+ const handleStatusPillKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
+ if (disabled) {
+ if (event.key === "Enter" || event.key === " ") {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ return;
+ }
+
+ if (event.key === "Enter" || event.key === " ") {
+ void handleStatusPillClick(event);
+ }
+ };
+
+ return (
+ <div className="flex flex-col gap-[0.25rem] items-stretch text-[--text-primary]">
+ <SelectRoot
+ value={selectedMicId ?? NO_MICROPHONE_VALUE}
+ onValueChange={(value) => {
+ onMicChange(value === NO_MICROPHONE_VALUE ? null : value);
+ }}
+ disabled={disabled}
+ open={open}
+ onOpenChange={onOpenChange}
+ >
+ <div className="relative w-full">
+ <SelectTrigger
+ className={clsx(
+ "relative flex flex-row items-center h-[2rem] pl-[0.375rem] pr-[3.5rem] gap-[0.375rem] border border-gray-3 rounded-lg w-full transition-colors overflow-hidden z-10 font-normal text-[0.875rem] bg-transparent hover:bg-transparent focus:bg-transparent focus:border-gray-3 hover:border-gray-3 text-[--text-primary] disabled:text-gray-11 [&>svg]:hidden",
+ disabled || shouldRequestPermission
+ ? "cursor-default"
+ : undefined,
+ )}
+ onPointerDown={(event) => {
+ if (shouldRequestPermission) {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ }}
+ onKeyDown={(event: KeyboardEvent<HTMLButtonElement>) => {
+ if (shouldRequestPermission) {
+ const keys = ["Enter", " ", "ArrowDown", "ArrowUp"];
+ if (keys.includes(event.key)) {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ }
+ }}
+ aria-disabled={disabled || shouldRequestPermission}
+ >
+ <SelectValue
+ placeholder={NO_MICROPHONE}
+ className="flex-1 flex items-center gap-[0.375rem] truncate"
+ />
+ </SelectTrigger>
+ <button
+ type="button"
+ className={clsx(
+ statusPillClassName,
+ "absolute right-[0.375rem] top-1/2 -translate-y-1/2 z-20",
+ )}
+ disabled={statusPillDisabled}
+ aria-disabled={statusPillDisabled}
+ onClick={(event) => void handleStatusPillClick(event)}
+ onKeyDown={handleStatusPillKeyDown}
+ >
+ {shouldRequestPermission
+ ? "Request permission"
+ : micEnabled
+ ? "On"
+ : "Off"}
+ </button>
+ </div>
+ <SelectContent className="z-[502]">
+ <SelectItem value={NO_MICROPHONE_VALUE}>
+ <span className="flex items-center gap-2 truncate">
+ <MicOffIcon className="size-4 text-gray-11" />
+ {NO_MICROPHONE}
+ </span>
+ </SelectItem>
+ {(availableMics.length === 0 ||
+ selectedMicId === DEFAULT_MICROPHONE_DEVICE_ID) && (
+ <SelectItem value={DEFAULT_MICROPHONE_DEVICE_ID}>
+ <span className="flex items-center gap-2 truncate">
+ <MicIcon className="size-4 text-gray-11" />
+ Default microphone
+ </span>
+ </SelectItem>
+ )}
+ {availableMics.map((mic, index) => (
+ <SelectItem key={mic.deviceId} value={mic.deviceId}>
+ <span className="flex items-center gap-2 truncate">
+ <MicIcon className="size-4 text-gray-11" />
+ {mic.label?.trim() || `Microphone ${index + 1}`}
+ </span>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </SelectRoot>
+ </div>
+ );
+};
diff --git a/apps/chrome-extension/src/popup/components/recorder-header.tsx b/apps/chrome-extension/src/popup/components/recorder-header.tsx
new file mode 100644
index 000000000..3b6d92e13
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/recorder-header.tsx
@@ -0,0 +1,118 @@
+import clsx from "clsx";
+import { X } from "lucide-react";
+
+interface RecorderHeaderProps {
+ isBusy: boolean;
+ isPro: boolean;
+ showPlan: boolean;
+ /** Hide the logo row; the sign-in screen renders its own centered brand. */
+ minimal?: boolean;
+ onClose: () => void;
+ onUpgradeClick: () => void;
+}
+
+export const RecorderHeader = ({
+ isBusy,
+ isPro,
+ showPlan,
+ minimal = false,
+ onClose,
+ onUpgradeClick,
+}: RecorderHeaderProps) => {
+ const planLabel = isPro ? "Pro" : "Free";
+ const planClassName = clsx(
+ "ml-2 inline-flex items-center rounded-full px-2 text-[0.7rem] font-medium transition-colors",
+ isPro
+ ? "bg-blue-9 text-gray-1"
+ : "cursor-pointer bg-gray-3 text-gray-12 hover:bg-gray-4",
+ );
+
+ return (
+ <>
+ <div className="absolute left-3.5 top-4 flex gap-2 items-center">
+ <button
+ type="button"
+ onClick={onClose}
+ disabled={isBusy}
+ title="Close Cap"
+ className={clsx(
+ "flex size-4 items-center justify-center rounded-full bg-[#FF5F57] border border-[#E0443E]/60 p-0",
+ isBusy
+ ? "opacity-50 cursor-not-allowed"
+ : "cursor-pointer transition-transform hover:scale-110",
+ )}
+ aria-label="Close Cap and hide all recorder UI"
+ >
+ <X
+ size={10}
+ strokeWidth={3.5}
+ className="text-[#741b15]"
+ aria-hidden
+ />
+ </button>
+ <div className="size-3 rounded-full bg-gray-8 opacity-50"></div>
+ <div className="size-3 rounded-full bg-gray-8 opacity-50"></div>
+ </div>
+ {minimal ? null : (
+ <div className="flex items-center justify-between pb-[0.25rem]">
+ <div className="flex items-center space-x-1">
+ <svg
+ className="w-[92px] h-auto block"
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 103 40"
+ aria-label="Cap Logo"
+ >
+ <title>Cap Logo</title>
+ <rect
+ width="39.5"
+ height="39.5"
+ x="0.25"
+ y="0.25"
+ fill="#fff"
+ rx="7.75"
+ ></rect>
+ <rect
+ width="39.5"
+ height="39.5"
+ x="0.25"
+ y="0.25"
+ stroke="#E7EAF0"
+ strokeWidth="0.5"
+ rx="7.75"
+ ></rect>
+ <path
+ fill="#4785FF"
+ d="M20 36c8.837 0 16-7.163 16-16S28.837 4 20 4 4 11.164 4 20s7.164 16 16 16"
+ ></path>
+ <path
+ fill="#ADC9FF"
+ d="M20 33c7.18 0 13-5.82 13-13S27.18 7 20 7 7 12.82 7 20s5.82 13 13 13"
+ ></path>
+ <path
+ fill="#fff"
+ d="M20 30c5.523 0 10-4.477 10-10s-4.477-10-10-10-10 4.477-10 10 4.477 10 10 10"
+ ></path>
+ <path
+ fill="#12161F"
+ d="M58.416 30.448c-5.404 0-9.212-3.864-9.212-10.36 0-6.384 3.668-10.416 9.268-10.416 5.068 0 7.784 2.66 8.624 7.168l-3.808.196c-.476-2.604-2.072-4.2-4.816-4.2-3.388 0-5.488 2.828-5.488 7.252 0 4.48 2.156 7.196 5.46 7.196 2.94 0 4.508-1.708 4.956-4.564l3.808.196c-.784 4.676-3.752 7.532-8.792 7.532m16.23-.112c-3.137 0-5.209-1.484-5.209-4.088 0-2.576 1.596-3.948 4.872-4.592l4.956-.98c0-2.1-.98-3.192-2.856-3.192-1.764 0-2.716.812-3.052 2.324l-3.668-.168c.588-3.136 2.996-4.928 6.72-4.928 4.256 0 6.44 2.24 6.44 6.216v5.432c0 .812.28 1.036.84 1.036h.476V30c-.224.056-.812.112-1.288.112-1.624 0-2.828-.588-3.136-2.436-.728 1.596-2.632 2.66-5.096 2.66m.727-2.604c2.38 0 3.892-1.512 3.892-3.78v-.84l-3.864.784c-1.596.308-2.24.98-2.24 2.016 0 1.176.784 1.82 2.212 1.82M86.874 34.2V15.048h3.444l.056 2.212c.868-1.652 2.52-2.548 4.48-2.548 4.256 0 6.356 3.5 6.356 7.812s-2.128 7.812-6.384 7.812c-1.904 0-3.556-.924-4.368-2.38V34.2zm7.112-6.776c2.184 0 3.5-1.82 3.5-4.9s-1.316-4.9-3.5-4.9-3.528 1.652-3.528 4.9 1.316 4.9 3.528 4.9"
+ ></path>
+ </svg>
+ {showPlan &&
+ (isPro ? (
+ <span className={planClassName}>{planLabel}</span>
+ ) : (
+ <button
+ type="button"
+ onClick={onUpgradeClick}
+ className={planClassName}
+ >
+ {planLabel}
+ </button>
+ ))}
+ </div>
+ </div>
+ )}
+ </>
+ );
+};
diff --git a/apps/chrome-extension/src/popup/components/recording-bar.tsx b/apps/chrome-extension/src/popup/components/recording-bar.tsx
new file mode 100644
index 000000000..9cb9208a5
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/recording-bar.tsx
@@ -0,0 +1,176 @@
+import clsx from "clsx";
+import {
+ Mic,
+ MicOff,
+ MoreVertical,
+ PauseCircle,
+ PlayCircle,
+ RotateCcw,
+ StopCircle,
+} from "lucide-react";
+import type { ComponentProps } from "react";
+import { formatDuration } from "../../shared/format-duration";
+import type { RecordingStatus, UploadSummary } from "../../shared/types";
+
+const ActionButton = ({ className, ...props }: ComponentProps<"button">) => (
+ <button
+ {...props}
+ type="button"
+ className={clsx(
+ "p-[0.25rem] rounded-lg transition-all",
+ "text-gray-11",
+ "h-8 w-8 flex items-center justify-center",
+ "hover:bg-gray-3 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-9",
+ "disabled:opacity-50 disabled:cursor-not-allowed",
+ className,
+ )}
+ />
+);
+
+const InlineChunkProgress = ({ upload }: { upload?: UploadSummary }) => {
+ if (!upload || upload.totalChunks === 0) {
+ return null;
+ }
+
+ const completedCount = upload.completedChunks;
+ const failed = upload.failedChunks > 0;
+ const progressRatio = Math.max(
+ 0,
+ Math.min(
+ 1,
+ upload.totalBytes > 0
+ ? upload.uploadedBytes / upload.totalBytes
+ : completedCount / upload.totalChunks,
+ ),
+ );
+ const radius = 15.9155;
+ const circumference = 2 * Math.PI * radius;
+ const strokeDashoffset = circumference * (1 - progressRatio);
+ const colorClass = failed
+ ? "text-[var(--red-11)]"
+ : completedCount === upload.totalChunks
+ ? "text-[var(--green-11)]"
+ : "text-blue-9";
+
+ return (
+ <div className="inline-flex items-center gap-2 rounded-lg px-1.5 py-1 text-[12px] text-gray-12">
+ <div className="relative h-5 w-5" role="img" aria-label="Upload progress">
+ <svg className="h-5 w-5 -rotate-90" viewBox="0 0 36 36">
+ <title>Upload progress</title>
+ <circle
+ className="fill-none stroke-gray-4"
+ strokeWidth={4}
+ cx="18"
+ cy="18"
+ r={radius}
+ />
+ <circle
+ className={clsx(
+ "fill-none stroke-current transition-[stroke-dashoffset] duration-300 ease-out",
+ colorClass,
+ )}
+ strokeWidth={4}
+ strokeLinecap="round"
+ strokeDasharray={circumference}
+ strokeDashoffset={strokeDashoffset}
+ cx="18"
+ cy="18"
+ r={radius}
+ />
+ </svg>
+ </div>
+ <span
+ className={clsx(
+ "font-semibold tabular-nums leading-none",
+ failed ? "text-[var(--red-11)]" : "text-gray-12",
+ )}
+ >
+ {completedCount}/{upload.totalChunks}
+ </span>
+ </div>
+ );
+};
+
+type ActiveRecordingStatus = Extract<
+ RecordingStatus,
+ { phase: "recording" | "paused" | "uploading" }
+>;
+
+interface RecordingBarProps {
+ status: ActiveRecordingStatus;
+ hasAudioTrack: boolean;
+ disabled: boolean;
+ onStop: () => void;
+ onPauseResume: () => void;
+}
+
+export const RecordingBar = ({
+ status,
+ hasAudioTrack,
+ disabled,
+ onStop,
+ onPauseResume,
+}: RecordingBarProps) => {
+ const isPaused = status.phase === "paused";
+ const canStop = !disabled;
+ const showTimer = status.phase === "recording" || isPaused;
+ const statusText = showTimer
+ ? formatDuration(status.durationMs)
+ : "Uploading";
+ const canTogglePause = !disabled && status.phase !== "uploading";
+
+ return (
+ <div className="flex flex-row items-stretch rounded-[0.9rem] border border-gray-5 bg-gray-1 text-gray-12 shadow-[0_16px_60px_rgba(0,0,0,0.35)] w-full">
+ <div className="flex flex-row justify-between flex-1 gap-3 p-[0.25rem]">
+ <button
+ type="button"
+ onClick={onStop}
+ disabled={!canStop}
+ className="py-[0.25rem] px-[0.5rem] text-red-300 gap-[0.35rem] flex flex-row items-center rounded-lg transition-opacity disabled:opacity-60"
+ >
+ <StopCircle className="size-5" />
+ <span className="font-[500] text-[0.875rem] tabular-nums">
+ {statusText}
+ </span>
+ </button>
+
+ <div className="flex gap-3 items-center">
+ <InlineChunkProgress upload={status.upload} />
+ <div className="flex relative justify-center items-center w-8 h-8">
+ {hasAudioTrack ? (
+ <>
+ <Mic className="size-5 text-gray-12" />
+ <div className="absolute bottom-1 left-1 right-1 h-0.5 bg-gray-10 overflow-hidden rounded-full">
+ <div className="absolute inset-0 bg-blue-9" />
+ </div>
+ </>
+ ) : (
+ <MicOff className="text-gray-7 size-5" />
+ )}
+ </div>
+
+ <ActionButton
+ onClick={onPauseResume}
+ disabled={!canTogglePause}
+ aria-label={isPaused ? "Resume recording" : "Pause recording"}
+ >
+ {isPaused ? (
+ <PlayCircle className="size-5" />
+ ) : (
+ <PauseCircle className="size-5" />
+ )}
+ </ActionButton>
+ <ActionButton disabled aria-label="Restart recording">
+ <RotateCcw className="size-5" />
+ </ActionButton>
+ </div>
+ </div>
+ <div
+ className="flex items-center justify-center p-[0.25rem] border-l border-gray-5 text-gray-9"
+ aria-hidden
+ >
+ <MoreVertical className="size-5" />
+ </div>
+ </div>
+ );
+};
diff --git a/apps/chrome-extension/src/popup/components/recording-button.tsx b/apps/chrome-extension/src/popup/components/recording-button.tsx
new file mode 100644
index 000000000..8190b0b32
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/recording-button.tsx
@@ -0,0 +1,58 @@
+import type { SVGProps } from "react";
+import { Button } from "../ui/button";
+
+interface RecordingButtonProps {
+ isRecording: boolean;
+ disabled?: boolean;
+ onStart: () => void;
+ onStop: () => void;
+}
+
+export const InstantIcon = ({
+ className,
+ ...props
+}: SVGProps<SVGSVGElement>) => (
+ <svg
+ width="152"
+ height="223"
+ viewBox="0 0 152 223"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ className={className}
+ {...props}
+ >
+ <title>Instant recording</title>
+ <path
+ d="M150.167 109.163L53.4283 220.65C52.4032 221.826 51.05 222.613 49.573 222.89C48.0959 223.167 46.5752 222.919 45.2403 222.185C43.9054 221.451 42.8287 220.27 42.1727 218.82C41.5167 217.369 41.317 215.729 41.6038 214.146L54.2661 146.019L4.48901 125.914C3.41998 125.484 2.46665 124.776 1.7142 123.853C0.961745 122.93 0.433602 121.82 0.176954 120.624C-0.0796948 119.428 -0.0568536 118.182 0.243435 116.997C0.543723 115.813 1.1121 114.727 1.8978 113.837L98.6363 2.35043C99.6614 1.17365 101.015 0.387451 102.492 0.110461C103.969 -0.166529 105.489 0.080724 106.824 0.814909C108.159 1.54909 109.236 2.73037 109.892 4.18049C110.548 5.63061 110.748 7.27088 110.461 8.85379L97.7639 77.0554L147.541 97.1322C148.602 97.5652 149.548 98.2727 150.294 99.1922C151.041 100.112 151.566 101.215 151.822 102.404C152.078 103.593 152.058 104.832 151.763 106.011C151.468 107.19 150.908 108.273 150.132 109.163H150.167Z"
+ fill="currentColor"
+ />
+ </svg>
+);
+
+export const RecordingButton = ({
+ isRecording,
+ disabled = false,
+ onStart,
+ onStop,
+}: RecordingButtonProps) => {
+ return (
+ <div className="flex items-center space-x-1 w-full">
+ <Button
+ variant="blue"
+ size="md"
+ disabled={disabled}
+ onClick={isRecording ? onStop : onStart}
+ className="flex flex-grow justify-center items-center"
+ >
+ {isRecording ? (
+ "Stop Recording"
+ ) : (
+ <>
+ <InstantIcon className="size-[0.8rem] mr-1.5" />
+ Start recording
+ </>
+ )}
+ </Button>
+ </div>
+ );
+};
diff --git a/apps/chrome-extension/src/popup/components/recording-mode-selector.tsx b/apps/chrome-extension/src/popup/components/recording-mode-selector.tsx
new file mode 100644
index 000000000..7ef1d188a
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/recording-mode-selector.tsx
@@ -0,0 +1,102 @@
+import {
+ CameraIcon,
+ Globe,
+ type LucideIcon,
+ MonitorIcon,
+ RectangleHorizontal,
+} from "lucide-react";
+import type { RecordingMode } from "../../shared/types";
+import {
+ SelectContent,
+ SelectItem,
+ SelectRoot,
+ SelectTrigger,
+ SelectValue,
+} from "../ui/select";
+
+interface RecordingModeSelectorProps {
+ mode: RecordingMode;
+ disabled?: boolean;
+ onModeChange: (mode: RecordingMode) => void;
+}
+
+export const RecordingModeSelector = ({
+ mode,
+ disabled = false,
+ onModeChange,
+}: RecordingModeSelectorProps) => {
+ const recordingModeOptions: Record<
+ RecordingMode,
+ {
+ label: string;
+ displayLabel: string;
+ icon: LucideIcon;
+ }
+ > = {
+ fullscreen: {
+ label: "Full Screen (Recommended)",
+ displayLabel: "Full Screen",
+ icon: MonitorIcon,
+ },
+ window: {
+ label: "Window",
+ displayLabel: "Window",
+ icon: RectangleHorizontal,
+ },
+ tab: {
+ label: "Current tab",
+ displayLabel: "Current tab",
+ icon: Globe,
+ },
+ camera: {
+ label: "Camera only",
+ displayLabel: "Camera only",
+ icon: CameraIcon,
+ },
+ };
+
+ const selectedOption = mode ? recordingModeOptions[mode] : null;
+ const SelectedIcon = selectedOption?.icon;
+
+ return (
+ <div className="flex flex-col gap-[0.25rem] items-stretch text-[--text-primary] max-w-full">
+ <SelectRoot
+ value={mode}
+ onValueChange={(value) => {
+ onModeChange(value as RecordingMode);
+ }}
+ disabled={disabled}
+ >
+ <SelectTrigger className="relative flex flex-row items-center h-[2rem] px-[0.375rem] border border-gray-3 rounded-lg w-full max-w-[280px] disabled:text-gray-11 transition-colors overflow-hidden z-10 font-normal text-[0.875rem] bg-transparent hover:bg-transparent focus:bg-transparent focus:border-gray-3 hover:border-gray-3 text-[--text-primary] [&>svg]:hidden">
+ <SelectValue
+ placeholder="Select recording mode"
+ className="flex w-full items-center gap-[0.375rem] text-left truncate"
+ >
+ {selectedOption && SelectedIcon && (
+ <span className="flex items-center gap-[0.375rem]">
+ <SelectedIcon className="size-4 text-gray-11 shrink-0" />
+ {selectedOption.displayLabel}
+ </span>
+ )}
+ </SelectValue>
+ </SelectTrigger>
+ <SelectContent className="z-[502] max-w-[280px]">
+ {Object.entries(recordingModeOptions).map(([value, option]) => {
+ const OptionIcon = option.icon;
+
+ return (
+ <SelectItem key={value} value={value}>
+ <span className="flex flex-col gap-0.5">
+ <span className="flex items-center gap-2">
+ <OptionIcon className="size-4 text-gray-11" />
+ {option.label}
+ </span>
+ </span>
+ </SelectItem>
+ );
+ })}
+ </SelectContent>
+ </SelectRoot>
+ </div>
+ );
+};
diff --git a/apps/chrome-extension/src/popup/components/settings-button.tsx b/apps/chrome-extension/src/popup/components/settings-button.tsx
new file mode 100644
index 000000000..81a1c8698
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/settings-button.tsx
@@ -0,0 +1,19 @@
+import { Button } from "../ui/button";
+import CogIcon from "./cog-icon";
+
+interface SettingsButtonProps {
+ onClick: () => void;
+}
+
+export const SettingsButton = ({ onClick }: SettingsButtonProps) => (
+ <Button
+ type="button"
+ variant="outline"
+ size="icon"
+ aria-label="Open recorder settings"
+ className="group absolute right-3 top-3 z-10 !p-0"
+ onClick={onClick}
+ >
+ <CogIcon size={20} aria-hidden className="text-gray-12" />
+ </Button>
+);
diff --git a/apps/chrome-extension/src/popup/components/sign-in-view.tsx b/apps/chrome-extension/src/popup/components/sign-in-view.tsx
new file mode 100644
index 000000000..7b53dd664
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/sign-in-view.tsx
@@ -0,0 +1,94 @@
+import { type CSSProperties, useId } from "react";
+import { CapBrand, DoodleBoilFilter } from "../../shared/cap-brand";
+
+interface SignInViewProps {
+ authPending: boolean;
+ busy: boolean;
+ onSignIn: () => void;
+}
+
+export const SignInView = ({
+ authPending,
+ busy,
+ onSignIn,
+}: SignInViewProps) => {
+ const boilId = useId();
+ return (
+ <div className="cap-signin">
+ <CapBrand className="cap-signin-brand cap-fade-up" />
+ <svg
+ className="cap-signin-doodle cap-fade-up cap-fade-up-1"
+ viewBox="0 0 120 104"
+ aria-hidden="true"
+ >
+ <defs>
+ <DoodleBoilFilter id={boilId} />
+ </defs>
+ <g
+ className="cap-signin-boil"
+ style={{ "--cap-signin-boil": `url(#${boilId})` } as CSSProperties}
+ >
+ <circle
+ className="cap-signin-stroke cap-signin-ring"
+ pathLength={1}
+ cx="60"
+ cy="52"
+ r="30"
+ />
+ <circle className="cap-signin-dot" cx="60" cy="52" r="11" />
+ <path
+ className="cap-signin-spark is-1"
+ d="M 18 22 L 18 28 M 18 36 L 18 42 M 8 32 L 14 32 M 22 32 L 28 32"
+ />
+ <path
+ className="cap-signin-spark is-2"
+ d="M 100 10 L 100 16 M 100 24 L 100 30 M 90 20 L 96 20 M 104 20 L 110 20"
+ />
+ <path
+ className="cap-signin-spark is-3"
+ d="M 102 64 L 102 69 M 102 75 L 102 80 M 94 72 L 99 72 M 105 72 L 110 72"
+ />
+ </g>
+ </svg>
+ <h1 className="cap-fade-up cap-fade-up-2">
+ {authPending ? "Finish signing in" : "Sign in to record"}
+ </h1>
+ <p className="cap-signin-lede cap-fade-up cap-fade-up-3">
+ {authPending
+ ? "Complete sign-in in the Cap window. This panel updates automatically."
+ : "Record your tab, screen or camera. Your video uploads while you record."}
+ </p>
+ {authPending ? (
+ <p className="cap-signin-wait cap-fade-up cap-fade-up-4">
+ <svg viewBox="0 0 24 24" aria-hidden="true">
+ <circle pathLength={1} cx="12" cy="12" r="9" />
+ </svg>
+ Waiting for the Cap sign-in window…
+ </p>
+ ) : null}
+ <button
+ type="button"
+ className={
+ authPending
+ ? "cap-paper-cta is-ghost cap-fade-up cap-fade-up-5"
+ : "cap-paper-cta cap-fade-up cap-fade-up-4"
+ }
+ disabled={busy}
+ onClick={onSignIn}
+ >
+ {authPending ? "Open the sign-in window again" : "Sign in to Cap"}
+ </button>
+ <p
+ className={
+ authPending
+ ? "cap-signin-footnote cap-fade-up cap-fade-up-6"
+ : "cap-signin-footnote cap-fade-up cap-fade-up-5"
+ }
+ >
+ {authPending
+ ? "The window closes by itself once it connects."
+ : "Your share link is ready the moment you stop."}
+ </p>
+ </div>
+ );
+};
diff --git a/apps/chrome-extension/src/popup/components/system-audio-toggle.tsx b/apps/chrome-extension/src/popup/components/system-audio-toggle.tsx
new file mode 100644
index 000000000..dd9ccf794
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/system-audio-toggle.tsx
@@ -0,0 +1,57 @@
+import clsx from "clsx";
+import { Volume2Icon, VolumeOffIcon } from "lucide-react";
+import type { RecordingMode } from "../../shared/types";
+
+interface SystemAudioToggleProps {
+ enabled: boolean;
+ disabled?: boolean;
+ recordingMode: RecordingMode;
+ onToggle: (enabled: boolean) => void;
+}
+
+const SYSTEM_AUDIO_HINTS: Partial<Record<RecordingMode, string>> = {
+ fullscreen: 'Make sure to check "Share system audio" in the browser picker.',
+ window: "System audio may not be available when sharing a window.",
+};
+
+export const SystemAudioToggle = ({
+ enabled,
+ disabled = false,
+ recordingMode,
+ onToggle,
+}: SystemAudioToggleProps) => {
+ const Icon = enabled ? Volume2Icon : VolumeOffIcon;
+ const hint = enabled ? SYSTEM_AUDIO_HINTS[recordingMode] : undefined;
+
+ return (
+ <div className="flex flex-col gap-[0.25rem] items-stretch text-[--text-primary]">
+ <button
+ type="button"
+ disabled={disabled}
+ onClick={() => onToggle(!enabled)}
+ className={clsx(
+ "relative flex flex-row items-center h-[2rem] px-[0.375rem] gap-[0.375rem] border border-gray-3 rounded-lg w-full transition-colors overflow-hidden font-normal text-[0.875rem] text-[--text-primary] disabled:text-gray-11",
+ disabled ? "cursor-default" : "cursor-pointer hover:bg-gray-3/50",
+ )}
+ >
+ <Icon className="size-4 text-gray-11 shrink-0" />
+ <span className="flex-1 text-left truncate">System Audio</span>
+ <span
+ className={clsx(
+ "px-[0.375rem] h-[1.25rem] min-w-[2.5rem] rounded-full text-[0.75rem] leading-[1.25rem] flex items-center justify-center font-normal transition-colors duration-200",
+ enabled
+ ? "bg-[var(--blue-3)] text-[var(--blue-11)]"
+ : "bg-[var(--red-3)] text-[var(--red-11)]",
+ )}
+ >
+ {enabled ? "On" : "Off"}
+ </span>
+ </button>
+ {hint && (
+ <p className="text-[0.6875rem] leading-snug text-gray-10 px-[0.375rem]">
+ {hint}
+ </p>
+ )}
+ </div>
+ );
+};
diff --git a/apps/chrome-extension/src/popup/components/use-media-permission.ts b/apps/chrome-extension/src/popup/components/use-media-permission.ts
new file mode 100644
index 000000000..b4f7d322a
--- /dev/null
+++ b/apps/chrome-extension/src/popup/components/use-media-permission.ts
@@ -0,0 +1,103 @@
+import { useCallback, useEffect, useRef, useState } from "react";
+
+type MediaPermissionKind = "camera" | "microphone";
+
+type MediaPermissionState = PermissionState | "unsupported" | "unknown";
+
+const permissionNameMap: Record<MediaPermissionKind, PermissionName> = {
+ camera: "camera",
+ microphone: "microphone",
+};
+
+const mediaConstraintsMap: Record<MediaPermissionKind, MediaStreamConstraints> =
+ {
+ camera: {
+ video: { width: { ideal: 1280 }, height: { ideal: 720 } },
+ audio: false,
+ },
+ microphone: { audio: true, video: false },
+ };
+
+export const useMediaPermission = (kind: MediaPermissionKind) => {
+ const [state, setState] = useState<MediaPermissionState>("unknown");
+ const permissionStatusRef = useRef<PermissionStatus | null>(null);
+
+ const updateState = useCallback((next: MediaPermissionState) => {
+ setState((prev) => {
+ if (prev === next) return prev;
+ return next;
+ });
+ }, []);
+
+ const refreshPermission = useCallback(async () => {
+ if (!navigator.permissions?.query) {
+ updateState("unsupported");
+ return;
+ }
+
+ try {
+ const descriptor = {
+ name: permissionNameMap[kind],
+ } as PermissionDescriptor;
+
+ const permissionStatus = await navigator.permissions.query(descriptor);
+ if (permissionStatusRef.current) {
+ permissionStatusRef.current.onchange = null;
+ }
+ permissionStatusRef.current = permissionStatus;
+
+ updateState(permissionStatus.state);
+
+ permissionStatus.onchange = () => {
+ updateState(permissionStatus.state);
+ };
+ } catch (_error) {
+ updateState("unsupported");
+ }
+ }, [kind, updateState]);
+
+ useEffect(() => {
+ void refreshPermission();
+
+ return () => {
+ if (permissionStatusRef.current) {
+ permissionStatusRef.current.onchange = null;
+ }
+ permissionStatusRef.current = null;
+ };
+ }, [refreshPermission]);
+
+ const requestPermission = useCallback(async () => {
+ if (!navigator.mediaDevices?.getUserMedia) {
+ updateState("unsupported");
+ return false;
+ }
+
+ try {
+ const stream = await navigator.mediaDevices.getUserMedia(
+ mediaConstraintsMap[kind],
+ );
+ for (const track of stream.getTracks()) {
+ track.stop();
+ }
+ updateState("granted");
+ await refreshPermission();
+ return true;
+ } catch (error) {
+ if (error instanceof DOMException) {
+ if (
+ error.name === "NotAllowedError" ||
+ error.name === "SecurityError"
+ ) {
+ updateState("denied");
+ }
+ }
+ throw error;
+ }
+ }, [kind, refreshPermission, updateState]);
+
+ return {
+ state,
+ requestPermission,
+ };
+};
diff --git a/apps/chrome-extension/src/popup/main.tsx b/apps/chrome-extension/src/popup/main.tsx
new file mode 100644
index 000000000..d6aea816c
--- /dev/null
+++ b/apps/chrome-extension/src/popup/main.tsx
@@ -0,0 +1,701 @@
+import clsx from "clsx";
+import { useCallback, useEffect, useRef, useState } from "react";
+import { createRoot } from "react-dom/client";
+import {
+ reconcileRememberedDevices,
+ rememberCameraSelection,
+ rememberMicrophoneSelection,
+ rememberRecordingMode,
+} from "../shared/preferences";
+import { sendServiceWorkerMessage } from "../shared/runtime";
+import {
+ defaultSettings,
+ FAILED_RECORDINGS_KEY,
+ loadAuth,
+ loadCachedBootstrap,
+ loadFailedRecordings,
+ loadMediaAccessState,
+ loadSettings,
+ MEDIA_ACCESS_KEY,
+ type MediaAccessState,
+ saveSettings,
+ updateMediaAccessState,
+} from "../shared/storage";
+import type {
+ BootstrapData,
+ CameraDevice,
+ ExtensionAuth,
+ ExtensionSettings,
+ MicrophoneDevice,
+ RecordingMode,
+ RecordingStatus,
+} from "../shared/types";
+import { DEFAULT_MICROPHONE_DEVICE_ID } from "../shared/types";
+import { CameraSelector } from "./components/camera-selector";
+import { HowItWorksButton } from "./components/how-it-works-button";
+import { MicrophoneSelector } from "./components/microphone-selector";
+import { RecorderHeader } from "./components/recorder-header";
+import { RecordingBar } from "./components/recording-bar";
+import { RecordingButton } from "./components/recording-button";
+import { RecordingModeSelector } from "./components/recording-mode-selector";
+import { SettingsButton } from "./components/settings-button";
+import { SignInView } from "./components/sign-in-view";
+import { SystemAudioToggle } from "./components/system-audio-toggle";
+import "./styles.css";
+
+type ActiveRecordingStatus = Extract<
+ RecordingStatus,
+ { phase: "recording" | "paused" | "uploading" }
+>;
+
+const PANEL_TOKEN = decodeURIComponent(window.location.hash.slice(1));
+const IS_EMBEDDED = PANEL_TOKEN.length > 0 && window.parent !== window;
+const DEFAULT_MEDIA_ACCESS: MediaAccessState = {
+ camera: false,
+ microphone: false,
+ updatedAt: 0,
+};
+
+const postPanelMessage = (
+ message: { type: "size"; height: number } | { type: "dismiss" },
+) => {
+ if (!IS_EMBEDDED) return;
+ window.parent.postMessage(
+ {
+ source: "cap-extension-panel",
+ token: PANEL_TOKEN,
+ ...message,
+ },
+ "*",
+ );
+};
+
+const isRecordingStatus = (
+ status: RecordingStatus,
+): status is ActiveRecordingStatus =>
+ status.phase === "recording" ||
+ status.phase === "paused" ||
+ status.phase === "uploading";
+
+const toCameraDevices = (devices: MediaDeviceInfo[]): CameraDevice[] =>
+ devices
+ .filter(
+ (device) =>
+ device.kind === "videoinput" && device.deviceId.trim().length > 0,
+ )
+ .map((device, index) => ({
+ deviceId: device.deviceId,
+ groupId: device.groupId,
+ label: device.label?.trim() || `Camera ${index + 1}`,
+ }));
+
+const toMicrophoneDevices = (devices: MediaDeviceInfo[]): MicrophoneDevice[] =>
+ devices
+ .filter(
+ (device) =>
+ device.kind === "audioinput" && device.deviceId.trim().length > 0,
+ )
+ .map((device, index) => ({
+ deviceId: device.deviceId,
+ groupId: device.groupId,
+ label: device.label?.trim() || `Microphone ${index + 1}`,
+ }));
+
+function App() {
+ // This page is web accessible, so any site can put it in an iframe and
+ // overlay it for clickjacking. When embedded, render nothing until the
+ // service worker confirms the URL-hash token was registered by one of our
+ // content scripts — only the extension overlay can do that.
+ const [embedAuthorized, setEmbedAuthorized] = useState(!IS_EMBEDDED);
+ const [auth, setAuth] = useState<ExtensionAuth | null>(null);
+ const [bootstrap, setBootstrap] = useState<BootstrapData | null>(null);
+ const [settings, setSettings] = useState<ExtensionSettings>(defaultSettings);
+ const [status, setStatus] = useState<RecordingStatus>({ phase: "idle" });
+ const [mode, setMode] = useState<RecordingMode>("fullscreen");
+ const [authPending, setAuthPending] = useState(false);
+ const [bootstrapped, setBootstrapped] = useState(false);
+ const [busy, setBusy] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ const [cameraDevices, setCameraDevices] = useState<CameraDevice[]>([]);
+ const [micDevices, setMicDevices] = useState<MicrophoneDevice[]>([]);
+ const [mediaAccess, setMediaAccess] =
+ useState<MediaAccessState>(DEFAULT_MEDIA_ACCESS);
+ const [cameraSelectOpen, setCameraSelectOpen] = useState(false);
+ const [micSelectOpen, setMicSelectOpen] = useState(false);
+ const [failedRecordingsCount, setFailedRecordingsCount] = useState(0);
+ const settingsRef = useRef(defaultSettings);
+
+ const recordingActive = isRecordingStatus(status);
+ const isPro = Boolean(bootstrap?.plan.isPro);
+ const cameraRequired = mode === "camera" && !settings.webcam.deviceId;
+
+ const selectedCameraId =
+ settings.webcam.enabled && settings.webcam.deviceId
+ ? settings.webcam.deviceId
+ : null;
+ const selectedMicId = settings.microphone.enabled
+ ? (settings.microphone.deviceId ?? DEFAULT_MICROPHONE_DEVICE_ID)
+ : null;
+
+ const updateSettings = useCallback(async (next: ExtensionSettings) => {
+ settingsRef.current = next;
+ setSettings(next);
+ setMode(next.capture.recordingMode);
+ await saveSettings(next);
+ await sendServiceWorkerMessage({
+ target: "service-worker",
+ type: "settings-updated",
+ settings: next,
+ }).catch(() => undefined);
+ }, []);
+
+ const applySettings = useCallback((next: ExtensionSettings) => {
+ settingsRef.current = next;
+ setSettings(next);
+ setMode(next.capture.recordingMode);
+ }, []);
+
+ const loadDevices = useCallback(async () => {
+ if (!navigator.mediaDevices?.enumerateDevices) {
+ return;
+ }
+
+ try {
+ const devices = await navigator.mediaDevices.enumerateDevices();
+ const cameras = toCameraDevices(devices);
+ const microphones = toMicrophoneDevices(devices);
+ setCameraDevices(cameras);
+ setMicDevices(microphones);
+ if (cameras.length > 0 || microphones.length > 0) {
+ const nextAccess = await updateMediaAccessState({
+ ...(cameras.length > 0 ? { camera: true } : {}),
+ ...(microphones.length > 0 ? { microphone: true } : {}),
+ });
+ setMediaAccess(nextAccess);
+ }
+ const reconciled = reconcileRememberedDevices(
+ settingsRef.current,
+ cameras,
+ microphones,
+ );
+ if (reconciled !== settingsRef.current) {
+ await updateSettings(reconciled);
+ }
+ } catch (err) {
+ setError(err instanceof Error ? err.message : String(err));
+ }
+ }, [updateSettings]);
+
+ const openPermissionPage = () => {
+ chrome.tabs.create({
+ url: chrome.runtime.getURL("camera-permission.html"),
+ active: true,
+ });
+ };
+
+ useEffect(() => {
+ if (!IS_EMBEDDED) return;
+ let disposed = false;
+ sendServiceWorkerMessage({
+ target: "service-worker",
+ type: "validate-overlay-token",
+ token: PANEL_TOKEN,
+ })
+ .then((response) => {
+ if (!disposed) {
+ setEmbedAuthorized(response.ok && response.valid === true);
+ }
+ })
+ .catch(() => {
+ if (!disposed) setEmbedAuthorized(false);
+ });
+ return () => {
+ disposed = true;
+ };
+ }, []);
+
+ useEffect(() => {
+ if (!IS_EMBEDDED) return;
+ const postSize = () => {
+ postPanelMessage({
+ type: "size",
+ height: Math.ceil(document.body.getBoundingClientRect().height),
+ });
+ };
+ const observer = new ResizeObserver(postSize);
+ observer.observe(document.body);
+ postSize();
+ return () => observer.disconnect();
+ }, []);
+
+ useEffect(() => {
+ if (!IS_EMBEDDED) return;
+ const handleKeyDown = (event: KeyboardEvent) => {
+ if (event.key === "Escape") postPanelMessage({ type: "dismiss" });
+ };
+ window.addEventListener("keydown", handleKeyDown);
+ return () => window.removeEventListener("keydown", handleKeyDown);
+ }, []);
+
+ useEffect(() => {
+ let disposed = false;
+
+ Promise.all([
+ loadSettings(),
+ loadAuth(),
+ loadCachedBootstrap(),
+ loadMediaAccessState(),
+ ])
+ .then(
+ ([cachedSettings, cachedAuth, cachedBootstrap, cachedMediaAccess]) => {
+ if (disposed || !cachedAuth) return;
+ applySettings(cachedSettings);
+ setAuth(cachedAuth);
+ setBootstrap(cachedBootstrap);
+ setMediaAccess(cachedMediaAccess);
+ setBootstrapped(true);
+ },
+ )
+ .catch(() => undefined);
+
+ sendServiceWorkerMessage({ target: "service-worker", type: "bootstrap" })
+ .then((response) => {
+ if (disposed) return;
+ setBootstrapped(true);
+ if (!response.ok) {
+ setError(response.error);
+ return;
+ }
+ setAuth(response.auth ?? null);
+ setAuthPending(Boolean(response.authPending && !response.auth));
+ setBootstrap(response.bootstrap ?? null);
+ if (response.authError) setError(response.authError);
+ if (response.cameraDevices) setCameraDevices(response.cameraDevices);
+ if (response.settings) applySettings(response.settings);
+ if (response.status) setStatus(response.status);
+ })
+ .catch((err: unknown) => {
+ if (!disposed) {
+ setBootstrapped(true);
+ setError(err instanceof Error ? err.message : String(err));
+ }
+ });
+ return () => {
+ disposed = true;
+ };
+ }, [applySettings]);
+
+ useEffect(() => {
+ const handleMessage = (message: unknown) => {
+ if (!message || typeof message !== "object") return false;
+ const candidate = message as {
+ type?: unknown;
+ devices?: unknown;
+ };
+ if (
+ candidate.type === "camera-devices-changed" &&
+ Array.isArray(candidate.devices)
+ ) {
+ setCameraDevices(candidate.devices as CameraDevice[]);
+ }
+ return false;
+ };
+
+ chrome.runtime.onMessage.addListener(handleMessage);
+ return () => chrome.runtime.onMessage.removeListener(handleMessage);
+ }, []);
+
+ useEffect(() => {
+ const handleStorageChange = (
+ changes: Record<string, chrome.storage.StorageChange>,
+ areaName: string,
+ ) => {
+ if (areaName !== "local" || !changes[MEDIA_ACCESS_KEY]) return;
+ void loadMediaAccessState()
+ .then(setMediaAccess)
+ .catch(() => undefined);
+ };
+
+ chrome.storage.onChanged.addListener(handleStorageChange);
+ return () => chrome.storage.onChanged.removeListener(handleStorageChange);
+ }, []);
+
+ // Recordings whose upload failed (or that a crash stranded) wait in local
+ // storage; surface a small recovery link so they are discoverable from
+ // here instead of only from the options page.
+ useEffect(() => {
+ let disposed = false;
+ const refreshFailedRecordings = () => {
+ loadFailedRecordings()
+ .then((entries) => {
+ if (!disposed) setFailedRecordingsCount(entries.length);
+ })
+ .catch(() => undefined);
+ };
+
+ const handleStorageChange = (
+ changes: Record<string, chrome.storage.StorageChange>,
+ areaName: string,
+ ) => {
+ if (areaName !== "local" || !changes[FAILED_RECORDINGS_KEY]) return;
+ refreshFailedRecordings();
+ };
+
+ refreshFailedRecordings();
+ chrome.storage.onChanged.addListener(handleStorageChange);
+ return () => {
+ disposed = true;
+ chrome.storage.onChanged.removeListener(handleStorageChange);
+ };
+ }, []);
+
+ useEffect(() => {
+ if (!auth) return;
+
+ void loadDevices();
+
+ const handleDeviceChange = () => {
+ void loadDevices();
+ };
+
+ navigator.mediaDevices?.addEventListener(
+ "devicechange",
+ handleDeviceChange,
+ );
+ return () => {
+ navigator.mediaDevices?.removeEventListener(
+ "devicechange",
+ handleDeviceChange,
+ );
+ };
+ }, [auth, loadDevices]);
+
+ useEffect(() => {
+ if (!authPending || auth) return;
+ const interval = window.setInterval(() => {
+ sendServiceWorkerMessage({ target: "service-worker", type: "bootstrap" })
+ .then((response) => {
+ if (!response.ok) return;
+ setAuth(response.auth ?? null);
+ setAuthPending(Boolean(response.authPending && !response.auth));
+ setBootstrap(response.bootstrap ?? null);
+ // A failed sign-in clears authPending (stopping this poll), so
+ // the stored failure is surfaced here or never.
+ if (response.authError) setError(response.authError);
+ if (response.cameraDevices) setCameraDevices(response.cameraDevices);
+ if (response.settings) applySettings(response.settings);
+ if (response.status) setStatus(response.status);
+ })
+ .catch(() => undefined);
+ }, 1000);
+ return () => window.clearInterval(interval);
+ }, [authPending, auth, applySettings]);
+
+ useEffect(() => {
+ if (!recordingActive) return;
+ const interval = window.setInterval(() => {
+ sendServiceWorkerMessage({
+ target: "service-worker",
+ type: "get-recording-status",
+ })
+ .then((response) => {
+ if (response.ok && response.status) setStatus(response.status);
+ })
+ .catch(() => undefined);
+ }, 1000);
+ return () => window.clearInterval(interval);
+ }, [recordingActive]);
+
+ const run = async (task: () => Promise<void>) => {
+ setBusy(true);
+ setError(null);
+ try {
+ await task();
+ } catch (err) {
+ setError(err instanceof Error ? err.message : String(err));
+ } finally {
+ setBusy(false);
+ }
+ };
+
+ const signIn = () =>
+ run(async () => {
+ const response = await sendServiceWorkerMessage({
+ target: "service-worker",
+ type: "auth-start",
+ });
+ if (!response.ok) throw new Error(response.error);
+ setAuth(response.auth ?? null);
+ setAuthPending(Boolean(response.authPending && !response.auth));
+ setBootstrap(response.bootstrap ?? null);
+ if (response.settings) applySettings(response.settings);
+ });
+
+ const start = () =>
+ run(async () => {
+ if (cameraRequired) {
+ throw new Error("Select a camera before recording.");
+ }
+ const response = await sendServiceWorkerMessage({
+ target: "service-worker",
+ type: "start-recording",
+ mode,
+ });
+ if (!response.ok) {
+ // Dismissing the capture picker is a deliberate action, not a
+ // failure worth surfacing.
+ if (response.canceled) return;
+ throw new Error(response.error);
+ }
+ if (response.status) setStatus(response.status);
+ postPanelMessage({ type: "dismiss" });
+ });
+
+ const stop = () =>
+ run(async () => {
+ const response = await sendServiceWorkerMessage({
+ target: "service-worker",
+ type: "stop-recording",
+ });
+ if (!response.ok) throw new Error(response.error);
+ if (response.status) setStatus(response.status);
+ });
+
+ const pauseOrResume = () =>
+ run(async () => {
+ const response = await sendServiceWorkerMessage({
+ target: "service-worker",
+ type:
+ status.phase === "paused" ? "resume-recording" : "pause-recording",
+ });
+ if (!response.ok) throw new Error(response.error);
+ if (response.status) setStatus(response.status);
+ });
+
+ const openOptions = () =>
+ sendServiceWorkerMessage({
+ target: "service-worker",
+ type: "open-options",
+ }).catch(() => undefined);
+
+ const openHowItWorks = () =>
+ sendServiceWorkerMessage({
+ target: "service-worker",
+ type: "open-how-it-works",
+ }).catch(() => undefined);
+
+ const handleModeChange = (recordingMode: RecordingMode) => {
+ setMode(recordingMode);
+ void updateSettings(
+ rememberRecordingMode(settingsRef.current, recordingMode),
+ );
+ };
+
+ const handleCameraChange = (cameraId: string | null) => {
+ void updateSettings(
+ rememberCameraSelection(settingsRef.current, cameraId, cameraDevices),
+ );
+ };
+
+ const handleMicChange = (micId: string | null) => {
+ void updateSettings(
+ rememberMicrophoneSelection(settingsRef.current, micId, micDevices),
+ );
+ };
+
+ const handleUpgradeClick = () => {
+ chrome.tabs.create({
+ url: `${settings.apiBaseUrl}/pricing`,
+ active: true,
+ });
+ };
+
+ const closePanel = () => {
+ if (busy) return;
+ // Closing the recorder tears down every piece of Cap UI: the panel,
+ // the camera preview and the recording bar in every tab.
+ postPanelMessage({ type: "dismiss" });
+ void sendServiceWorkerMessage({
+ target: "service-worker",
+ type: "close-extension-ui",
+ }).catch(() => undefined);
+ if (!IS_EMBEDDED) window.close();
+ };
+
+ const maxRecordingMs =
+ bootstrap && bootstrap.plan.maxRecordingSeconds !== null
+ ? bootstrap.plan.maxRecordingSeconds * 1000
+ : null;
+ const recordingTimerDisplayMs =
+ recordingActive && status.phase !== "uploading"
+ ? isPro || maxRecordingMs === null
+ ? status.durationMs
+ : Math.max(0, maxRecordingMs - status.durationMs)
+ : 0;
+
+ const recordingBarStatus = recordingActive
+ ? status.phase === "uploading"
+ ? status
+ : { ...status, durationMs: recordingTimerDisplayMs }
+ : null;
+
+ const signedOut = bootstrapped && !auth;
+
+ if (!embedAuthorized) return null;
+
+ return (
+ <main className="flex w-[300px] justify-center">
+ <div
+ className={clsx(
+ "relative flex justify-center flex-col w-[300px] p-[1rem] pt-[3.25rem] gap-[0.75rem] text-[0.875rem] font-[400] text-[--text-primary] min-h-[440px]",
+ signedOut ? "bg-[--paper]" : "bg-gray-2",
+ )}
+ >
+ {auth && <SettingsButton onClick={() => void openOptions()} />}
+ <RecorderHeader
+ isBusy={busy || recordingActive}
+ isPro={isPro}
+ showPlan={Boolean(auth)}
+ minimal={signedOut}
+ onClose={closePanel}
+ onUpgradeClick={handleUpgradeClick}
+ />
+
+ {!bootstrapped ? (
+ <div className="flex flex-1 items-center justify-center">
+ <output
+ className="block size-6 animate-spin rounded-full border-2 border-gray-5 border-t-gray-10"
+ aria-label="Loading"
+ />
+ </div>
+ ) : auth ? (
+ <>
+ <div className="cap-fade-up cap-fade-up-1">
+ <RecordingModeSelector
+ mode={mode}
+ disabled={recordingActive || busy}
+ onModeChange={handleModeChange}
+ />
+ </div>
+ <div className="cap-fade-up cap-fade-up-2">
+ <CameraSelector
+ selectedCameraId={selectedCameraId}
+ availableCameras={cameraDevices}
+ permissionGranted={
+ mediaAccess.camera || Boolean(settings.webcam.deviceId)
+ }
+ disabled={recordingActive || busy}
+ open={cameraSelectOpen}
+ onOpenChange={(isOpen) => {
+ setCameraSelectOpen(isOpen);
+ if (isOpen) {
+ setMicSelectOpen(false);
+ }
+ }}
+ onCameraChange={handleCameraChange}
+ onRefreshDevices={loadDevices}
+ onPermissionBlocked={openPermissionPage}
+ />
+ </div>
+ <div className="cap-fade-up cap-fade-up-3">
+ <MicrophoneSelector
+ selectedMicId={selectedMicId}
+ availableMics={micDevices}
+ permissionGranted={
+ mediaAccess.microphone || Boolean(selectedMicId)
+ }
+ disabled={recordingActive || busy}
+ open={micSelectOpen}
+ onOpenChange={(isOpen) => {
+ setMicSelectOpen(isOpen);
+ if (isOpen) {
+ setCameraSelectOpen(false);
+ }
+ }}
+ onMicChange={handleMicChange}
+ onRefreshDevices={loadDevices}
+ onPermissionBlocked={openPermissionPage}
+ />
+ </div>
+ {mode !== "camera" && (
+ <div className="cap-fade-up cap-fade-up-4">
+ <SystemAudioToggle
+ enabled={settings.systemAudio.enabled}
+ disabled={recordingActive || busy}
+ recordingMode={mode}
+ onToggle={(enabled) =>
+ void updateSettings({
+ ...settings,
+ systemAudio: { ...settings.systemAudio, enabled },
+ })
+ }
+ />
+ </div>
+ )}
+ <div className="cap-fade-up cap-fade-up-5">
+ <RecordingButton
+ isRecording={recordingActive}
+ disabled={busy || (!recordingActive && cameraRequired)}
+ onStart={() => void start()}
+ onStop={() => void stop()}
+ />
+ </div>
+ {recordingBarStatus && (
+ <div className="cap-fade-up">
+ <RecordingBar
+ status={recordingBarStatus}
+ hasAudioTrack={settings.microphone.enabled}
+ disabled={busy}
+ onStop={() => void stop()}
+ onPauseResume={() => void pauseOrResume()}
+ />
+ </div>
+ )}
+ {status.phase === "error" && (
+ <div className="cap-fade-up rounded-md border border-red-6 bg-red-3/70 px-3 py-2 text-xs leading-snug text-red-12">
+ <span className="font-medium">Recording failed.</span>{" "}
+ {status.message}
+ </div>
+ )}
+ <div className="cap-fade-up cap-fade-up-6">
+ <HowItWorksButton onClick={() => void openHowItWorks()} />
+ </div>
+ {failedRecordingsCount > 0 && (
+ <div className="cap-fade-up cap-fade-up-6">
+ <button
+ type="button"
+ onClick={() => void openOptions()}
+ className="flex w-full items-center justify-center gap-1 text-xs font-medium text-[var(--red-11)] transition-colors hover:text-[var(--red-12)]"
+ >
+ Recover {failedRecordingsCount}{" "}
+ {failedRecordingsCount === 1 ? "recording" : "recordings"}
+ </button>
+ </div>
+ )}
+ </>
+ ) : (
+ <SignInView
+ authPending={authPending}
+ busy={busy}
+ onSignIn={() => void signIn()}
+ />
+ )}
+
+ {error && (
+ <div
+ className={clsx(
+ "cap-fade-up",
+ signedOut
+ ? "cap-paper-error"
+ : "rounded-md border border-red-6 bg-red-3/70 px-3 py-2 text-xs leading-snug text-red-12",
+ )}
+ >
+ {error}
+ </div>
+ )}
+ </div>
+ </main>
+ );
+}
+
+createRoot(document.getElementById("root") as HTMLElement).render(<App />);
diff --git a/apps/chrome-extension/src/popup/styles.css b/apps/chrome-extension/src/popup/styles.css
new file mode 100644
index 000000000..f4373b5f7
--- /dev/null
+++ b/apps/chrome-extension/src/popup/styles.css
@@ -0,0 +1,509 @@
+@import "@radix-ui/colors/red.css";
+@import "@radix-ui/colors/red-dark.css";
+@import "@radix-ui/colors/gray.css";
+@import "@radix-ui/colors/gray-alpha.css";
+@import "@radix-ui/colors/gray-dark.css";
+@import "@radix-ui/colors/blue.css";
+@import "@radix-ui/colors/green.css";
+@import "@radix-ui/colors/purple.css";
+
+@tailwind base;
+@tailwind components;
+@tailwind utilities;
+
+@font-face {
+ font-family: "Neue Montreal";
+ src: url("/fonts/NeueMontreal-Regular.otf") format("opentype");
+ font-weight: 400;
+ font-style: normal;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "Neue Montreal";
+ src: url("/fonts/NeueMontreal-Italic.otf") format("opentype");
+ font-weight: 400;
+ font-style: italic;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "Neue Montreal";
+ src: url("/fonts/NeueMontreal-Medium.otf") format("opentype");
+ font-weight: 500;
+ font-style: normal;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "Neue Montreal";
+ src: url("/fonts/NeueMontreal-MediumItalic.otf") format("opentype");
+ font-weight: 500;
+ font-style: italic;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "Neue Montreal";
+ src: url("/fonts/NeueMontreal-Bold.otf") format("opentype");
+ font-weight: 700;
+ font-style: normal;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "Neue Montreal";
+ src: url("/fonts/NeueMontreal-BoldItalic.otf") format("opentype");
+ font-weight: 700;
+ font-style: italic;
+ font-display: swap;
+}
+
+:root {
+ --primary: #005cb1;
+ --primary-2: #004c93;
+ --primary-3: #003b73;
+ --secondary: #2eb4ff;
+ --secondary-2: #1696e0;
+ --secondary-3: #117ebd;
+ --tertiary: #c5eaff;
+ --tertiary-2: #d3e5ff;
+ --tertiary-3: #e0edff;
+ --filler: #efefef;
+ --filler-2: #e4e4e4;
+ --filler-3: #e2e2e2;
+ --filler-txt: #b3b3b3;
+ --text-primary: #0d1b2a;
+ --text-secondary: #ffffff;
+ color-scheme: light;
+ font-family:
+ "Neue Montreal", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
+ "Segoe UI", sans-serif;
+}
+
+@layer base {
+ :root {
+ --background: 0 0% 100%;
+ --foreground: 224 71.4% 4.1%;
+ --card: 0 0% 100%;
+ --card-foreground: 224 71.4% 4.1%;
+ --popover: 0 0% 100%;
+ --popover-foreground: 224 71.4% 4.1%;
+ --primary-foreground: 210 20% 98%;
+ --secondary-foreground: 220.9 39.3% 11%;
+ --muted: 220 14.3% 95.9%;
+ --muted-foreground: 220 8.9% 46.1%;
+ --accent: 220 14.3% 95.9%;
+ --accent-foreground: 220.9 39.3% 11%;
+ --destructive: 0 84.2% 60.2%;
+ --destructive-foreground: 210 20% 98%;
+ --border: 220 13% 91%;
+ --input: 220 13% 91%;
+ --ring: 224 71.4% 4.1%;
+ --radius: 0.5rem;
+ }
+
+ * {
+ @apply border-border;
+ }
+}
+
+*,
+*:before,
+*:after {
+ box-sizing: border-box;
+}
+
+* {
+ min-width: 0;
+ min-height: 0;
+}
+
+::selection {
+ background: #000000;
+ color: #ffffff;
+}
+
+::-webkit-scrollbar {
+ width: 4px;
+ height: 4px;
+}
+
+::-webkit-scrollbar-track {
+ border-radius: 10px;
+}
+
+::-webkit-scrollbar-thumb {
+ background: var(--gray-7);
+ border-radius: 10px;
+}
+
+h1,
+h2,
+h3,
+h4,
+h5 {
+ @apply m-0 font-normal tracking-normal;
+}
+
+a,
+p,
+span,
+input,
+label,
+button {
+ @apply tracking-normal leading-[1.5rem];
+}
+
+p {
+ @apply m-0;
+}
+
+a {
+ @apply transition-all;
+}
+
+label {
+ @apply block text-sm font-semibold text-left;
+}
+
+.dark-button-shadow {
+ box-shadow: 0 1.5px 0 0 rgba(255, 255, 255, 0.2) inset;
+}
+
+.gray-button-border {
+ @apply border-gray-8;
+}
+
+.dark-button-border {
+ @apply border-gray-12;
+}
+
+.gray-button-shadow {
+ box-shadow: 0 1.5px 0 0 rgba(255, 255, 255, 0.4) inset;
+}
+
+body {
+ margin: 0;
+ width: 300px;
+ color: var(--text-primary);
+ background: var(--gray-2);
+}
+
+.settings-slider {
+ -webkit-appearance: none;
+ appearance: none;
+ width: 100%;
+ height: 4px;
+ border-radius: 999px;
+ background: linear-gradient(
+ to right,
+ var(--blue-9) 0%,
+ var(--blue-9) var(--slider-progress, 50%),
+ var(--gray-4) var(--slider-progress, 50%),
+ var(--gray-4) 100%
+ );
+ outline: none;
+ cursor: pointer;
+}
+
+.settings-slider::-webkit-slider-thumb {
+ -webkit-appearance: none;
+ appearance: none;
+ width: 16px;
+ height: 16px;
+ border-radius: 50%;
+ background: #ffffff;
+ border: 1px solid var(--gray-6);
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
+}
+
+/* Paper aesthetic shared with the welcome / how-it-works pages. */
+:root {
+ --paper: #fbfaf7;
+ --ink: #20242c;
+ --ink-soft: #8b8f98;
+ --paper-accent: #4785ff;
+ --track: #dcdcd4;
+}
+
+.cap-fade-up {
+ animation: cap-fade-up 0.45s ease both;
+}
+
+.cap-fade-up-1 {
+ animation-delay: 0.06s;
+}
+
+.cap-fade-up-2 {
+ animation-delay: 0.12s;
+}
+
+.cap-fade-up-3 {
+ animation-delay: 0.18s;
+}
+
+.cap-fade-up-4 {
+ animation-delay: 0.24s;
+}
+
+.cap-fade-up-5 {
+ animation-delay: 0.3s;
+}
+
+.cap-fade-up-6 {
+ animation-delay: 0.36s;
+}
+
+.cap-signin {
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ padding: 4px 4px 10px;
+ text-align: center;
+}
+
+.cap-signin-brand {
+ height: 24px;
+ width: auto;
+ color: var(--ink);
+}
+
+.cap-signin-doodle {
+ width: 102px;
+ height: auto;
+ margin-top: 26px;
+ overflow: visible;
+}
+
+.cap-signin-boil {
+ filter: var(--cap-signin-boil, none);
+}
+
+.cap-signin-stroke {
+ fill: none;
+ stroke: var(--ink);
+ stroke-width: 4.5;
+ stroke-linecap: round;
+ stroke-linejoin: round;
+}
+
+.cap-signin-ring {
+ stroke-dasharray: 1;
+ stroke-dashoffset: 1;
+ animation: cap-draw 0.8s ease 0.35s forwards;
+}
+
+.cap-signin-dot {
+ fill: var(--paper-accent);
+ opacity: 0;
+ transform-box: fill-box;
+ transform-origin: center;
+ animation:
+ cap-pop 0.45s ease 1.05s both,
+ cap-soft-pulse 1.9s ease-in-out 2.2s infinite;
+}
+
+.cap-signin-spark {
+ fill: none;
+ stroke: var(--paper-accent);
+ stroke-width: 3.5;
+ stroke-linecap: round;
+ opacity: 0;
+ transform-box: fill-box;
+ transform-origin: center;
+ animation: cap-pop 0.5s ease forwards;
+}
+
+.cap-signin-spark.is-1 {
+ animation-delay: 1.2s;
+}
+
+.cap-signin-spark.is-2 {
+ animation-delay: 1.35s;
+}
+
+.cap-signin-spark.is-3 {
+ animation-delay: 1.5s;
+}
+
+.cap-signin h1 {
+ margin-top: 22px;
+ font-size: 19px;
+ font-weight: 500;
+ letter-spacing: -0.01em;
+ line-height: 1.25;
+ color: var(--ink);
+}
+
+.cap-signin-lede {
+ margin-top: 8px;
+ max-width: 236px;
+ font-size: 13px;
+ line-height: 1.5;
+ color: var(--ink-soft);
+}
+
+.cap-signin-wait {
+ display: inline-flex;
+ align-items: center;
+ gap: 8px;
+ margin-top: 16px;
+ font-size: 12.5px;
+ font-weight: 500;
+ line-height: 1.4;
+ color: var(--ink-soft);
+}
+
+.cap-signin-wait svg {
+ width: 15px;
+ height: 15px;
+ flex: 0 0 auto;
+ overflow: visible;
+}
+
+.cap-signin-wait circle {
+ fill: none;
+ stroke: var(--paper-accent);
+ stroke-width: 3;
+ stroke-linecap: round;
+ stroke-dasharray: 0.125 0.125;
+ animation: cap-march 1.1s linear infinite;
+}
+
+.cap-paper-cta {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
+ width: 100%;
+ min-height: 42px;
+ margin-top: 22px;
+ padding: 0 24px;
+ border: 1.5px solid var(--ink);
+ border-radius: 999px;
+ background: transparent;
+ color: var(--ink);
+ font-family: inherit;
+ font-size: 14px;
+ font-weight: 500;
+ line-height: 1.4;
+ cursor: pointer;
+ transition:
+ background 0.2s ease,
+ color 0.2s ease,
+ border-color 0.2s ease,
+ opacity 0.2s ease;
+}
+
+.cap-paper-cta:hover:not(:disabled) {
+ background: var(--ink);
+ color: var(--paper);
+}
+
+.cap-paper-cta:focus-visible {
+ outline: 2px solid var(--paper-accent);
+ outline-offset: 2px;
+}
+
+.cap-paper-cta:disabled {
+ cursor: not-allowed;
+ opacity: 0.45;
+}
+
+.cap-paper-cta.is-ghost {
+ border-color: var(--track);
+ color: var(--ink-soft);
+}
+
+.cap-paper-cta.is-ghost:hover:not(:disabled) {
+ background: transparent;
+ border-color: var(--ink-soft);
+ color: var(--ink);
+}
+
+.cap-signin-footnote {
+ margin-top: 14px;
+ font-size: 12px;
+ line-height: 1.5;
+ color: var(--ink-soft);
+}
+
+.cap-paper-error {
+ padding: 10px 14px;
+ border: 1.5px solid #e5484d;
+ border-radius: 14px;
+ color: #e5484d;
+ font-size: 12px;
+ line-height: 1.5;
+ text-align: left;
+}
+
+@keyframes cap-fade-up {
+ from {
+ opacity: 0;
+ transform: translateY(10px);
+ }
+ to {
+ opacity: 1;
+ transform: none;
+ }
+}
+
+@keyframes cap-draw {
+ to {
+ stroke-dashoffset: 0;
+ }
+}
+
+@keyframes cap-pop {
+ from {
+ opacity: 0;
+ transform: scale(0.2);
+ }
+ 60% {
+ opacity: 1;
+ transform: scale(1.15);
+ }
+ to {
+ opacity: 1;
+ transform: scale(1);
+ }
+}
+
+@keyframes cap-soft-pulse {
+ 0%,
+ 100% {
+ opacity: 1;
+ }
+ 50% {
+ opacity: 0.4;
+ }
+}
+
+@keyframes cap-march {
+ to {
+ stroke-dashoffset: -0.25;
+ }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .cap-signin-boil {
+ filter: none;
+ }
+
+ .cap-fade-up,
+ .cap-signin-ring,
+ .cap-signin-dot,
+ .cap-signin-spark {
+ animation-duration: 0.01ms;
+ animation-delay: 0s;
+ animation-iteration-count: 1;
+ }
+
+ .cap-signin-wait circle {
+ animation: none;
+ }
+}
diff --git a/apps/chrome-extension/src/popup/ui/button.tsx b/apps/chrome-extension/src/popup/ui/button.tsx
new file mode 100644
index 000000000..69c4a8c68
--- /dev/null
+++ b/apps/chrome-extension/src/popup/ui/button.tsx
@@ -0,0 +1,68 @@
+import { cva, type VariantProps } from "class-variance-authority";
+import * as React from "react";
+import { classNames } from "./class-names";
+
+const buttonVariants = cva(
+ "flex items-center justify-center transition-colors duration-200 rounded-full disabled:cursor-not-allowed cursor-pointer font-medium px-5 ring-offset-transparent relative gap-1",
+ {
+ defaultVariants: {
+ variant: "primary",
+ size: "md",
+ },
+ variants: {
+ variant: {
+ primary:
+ "bg-gray-12 dark-button-shadow text-gray-1 disabled:bg-gray-6 disabled:text-gray-9",
+ blue: "bg-blue-600 text-white disabled:border-gray-8 border border-blue-800 shadow-[0_1.50px_0_0_rgba(255,255,255,0.20)_inset] hover:bg-blue-700 disabled:bg-gray-7 disabled:text-gray-10",
+ destructive:
+ "bg-red-500 text-white border-transparent hover:bg-red-600 disabled:bg-gray-7 disabled:border-gray-8 border disabled:text-gray-10",
+ outline:
+ "border border-gray-4 hover:border-gray-5 hover:bg-gray-3 text-gray-12 disabled:bg-gray-8",
+ white:
+ "bg-gray-3 border border-gray-5 hover:border-gray-6 text-gray-12 hover:bg-gray-6 disabled:bg-gray-8",
+ gray: "bg-gray-5 hover:bg-gray-7 border gray-button-border gray-button-shadow text-gray-12 disabled:border-gray-7 disabled:bg-gray-8 disabled:text-gray-11",
+ dark: "bg-gray-12 dark-button-shadow hover:bg-gray-11 border dark-button-border text-gray-1 disabled:cursor-not-allowed disabled:text-gray-10 disabled:bg-gray-7 disabled:border-gray-8",
+ },
+ size: {
+ xs: "text-xs h-[32px]",
+ sm: "text-sm h-[40px]",
+ md: "text-sm h-[44px]",
+ lg: "text-md h-[48px]",
+ icon: "h-9 w-9",
+ },
+ },
+ },
+);
+
+export interface ButtonProps
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
+ VariantProps<typeof buttonVariants> {
+ href?: string;
+ target?: string;
+}
+
+const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
+ ({ className, variant, size, href, target, ...props }, ref) => {
+ if (href) {
+ return (
+ <a
+ className={classNames(buttonVariants({ variant, size, className }))}
+ href={href}
+ target={target}
+ >
+ {props.children}
+ </a>
+ );
+ }
+ return (
+ <button
+ className={classNames(buttonVariants({ variant, size, className }))}
+ ref={ref}
+ {...props}
+ />
+ );
+ },
+);
+Button.displayName = "Button";
+
+export { Button, buttonVariants };
diff --git a/apps/chrome-extension/src/popup/ui/class-names.ts b/apps/chrome-extension/src/popup/ui/class-names.ts
new file mode 100644
index 000000000..293ec62f1
--- /dev/null
+++ b/apps/chrome-extension/src/popup/ui/class-names.ts
@@ -0,0 +1,6 @@
+import { type ClassValue, clsx } from "clsx";
+import { twMerge } from "tailwind-merge";
+
+export function classNames(...inputs: ClassValue[]) {
+ return twMerge(clsx(inputs));
+}
diff --git a/apps/chrome-extension/src/popup/ui/select.tsx b/apps/chrome-extension/src/popup/ui/select.tsx
new file mode 100644
index 000000000..4e1178740
--- /dev/null
+++ b/apps/chrome-extension/src/popup/ui/select.tsx
@@ -0,0 +1,266 @@
+import * as SelectPrimitive from "@radix-ui/react-select";
+import { cva, cx } from "class-variance-authority";
+import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react";
+import * as React from "react";
+
+type SelectVariant = "default" | "light" | "dark" | "gray" | "transparent";
+type Size = "default" | "fit" | "sm" | "md" | "lg";
+
+const SelectVariantContext = React.createContext<SelectVariant>("default");
+
+const selectTriggerVariants = cva(
+ cx(
+ "font-medium flex transition-all duration-200 text-[13px] outline-0",
+ "border items-center justify-between gap-2 whitespace-nowrap",
+ "disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-gray-3 disabled:text-gray-9",
+ "ring-0 ring-gray-6 ring-offset-gray-6 data-[state=open]:border-gray-7 data-[state=open]:ring-gray-7 data-[state=open]:ring-1 data-[state=open]:ring-offset-0",
+ "data-placeholder:text-gray-12",
+ "data-[slot=select-value]:*:line-clamp-1 data-[slot=select-value]:*:flex data-[slot=select-value]:*:items-center data-[slot=select-value]:*:gap-2",
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg]:transition-transform [&_svg]:duration-200",
+ "[&[data-state=open]_svg.caret-icon]:rotate-180",
+ ),
+ {
+ defaultVariants: {
+ variant: "default",
+ size: "default",
+ },
+ variants: {
+ variant: {
+ default:
+ "bg-gray-2 border-gray-5 text-gray-12 hover:bg-gray-3 hover:border-gray-6",
+ dark: "bg-gray-12 transition-all duration-200 data-[state=open]:ring-offset-2 data-[state=open]:ring-gray-10 ring-transparent ring-offset-gray-3 text-gray-1 border-gray-5 hover:bg-gray-11 hover:border-gray-6",
+ light:
+ "bg-gray-1 transition-all duration-200 data-[state=open]:ring-offset-2 data-[state=open]:ring-gray-10 ring-transparent ring-offset-gray-3 text-gray-12 border-gray-5 hover:bg-gray-3 hover:border-gray-6",
+ gray: "bg-gray-5 text-gray-12 border-gray-5 hover:bg-gray-7 hover:border-gray-6",
+ transparent:
+ "bg-transparent text-gray-12 border-transparent hover:bg-gray-3 hover:border-gray-6",
+ },
+ size: {
+ default: "w-full h-[44px] px-4 rounded-xl",
+ fit: "w-fit h-[32px] px-3 rounded-[10px]",
+ sm: "w-fit h-[32px] px-3 rounded-[10px]",
+ md: "w-fit h-[40px] px-3 rounded-xl",
+ lg: "w-fit h-[48px] px-4 rounded-xl",
+ },
+ },
+ },
+);
+
+const selectContentVariants = cva(
+ cx(
+ "z-[1000] rounded-xl border overflow-hidden",
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
+ "data-[state=open]:animate-in data-[state=closed]:animate-out",
+ "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
+ "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
+ "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2",
+ "data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
+ ),
+ {
+ defaultVariants: {
+ variant: "default",
+ },
+ variants: {
+ variant: {
+ default: "bg-gray-2 border-gray-5 text-gray-12",
+ dark: "hover:bg-gray-11-50 bg-gray-12 dark-button-border dark-button-shadow text-gray-1 border-gray-5",
+ light:
+ "bg-gray-1 transition-all duration-200 data-[state=open]:ring-offset-2 data-[state=open]:ring-gray-10 ring-transparent ring-offset-gray-3 text-gray-12 border-gray-5",
+ gray: "bg-gray-5 text-gray-12 border-gray-5",
+ transparent:
+ "bg-transparent hover:bg-gray-3 text-gray-12 border-transparent",
+ },
+ },
+ },
+);
+
+const selectItemVariants = cva(
+ cx(
+ "relative flex w-full cursor-default items-center gap-2 py-2 pr-8 pl-3 text-[13px]",
+ "rounded-lg outline-hidden select-none transition-colors duration-200",
+ "data-disabled:pointer-events-none data-disabled:opacity-50 data-disabled:text-gray-9",
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
+ ),
+ {
+ defaultVariants: {
+ variant: "default",
+ },
+ variants: {
+ variant: {
+ default: "text-gray-12 hover:bg-gray-3 focus:bg-gray-3",
+ dark: "text-gray-1 hover:text-gray-12 focus:text-gray-12 hover:bg-gray-1 focus:bg-gray-1",
+ light:
+ "text-gray-12 hover:text-gray-12 hover:bg-gray-3 focus:bg-gray-3",
+ gray: "text-gray-12 hover:text-gray-12 hover:bg-gray-6 focus:bg-gray-6",
+ transparent:
+ "text-gray-12 hover:text-gray-12 hover:bg-gray-3 focus:bg-gray-3",
+ },
+ },
+ },
+);
+
+function SelectRoot({
+ ...props
+}: React.ComponentProps<typeof SelectPrimitive.Root>) {
+ return <SelectPrimitive.Root data-slot="select" {...props} />;
+}
+
+function SelectValue({
+ ...props
+}: React.ComponentProps<typeof SelectPrimitive.Value>) {
+ return <SelectPrimitive.Value data-slot="select-value" {...props} />;
+}
+
+function SelectTrigger({
+ className,
+ icon,
+ size = "default",
+ variant = "default",
+ children,
+ ...props
+}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
+ size?: Size;
+ variant?: SelectVariant;
+ icon?: React.ReactNode;
+}) {
+ const iconSizeVariant = {
+ default: "size-2.5",
+ fit: "size-2",
+ sm: "size-2",
+ md: "size-3",
+ lg: "size-3",
+ };
+ return (
+ <SelectPrimitive.Trigger
+ data-slot="select-trigger"
+ data-size={size}
+ className={cx(selectTriggerVariants({ size, variant }), className)}
+ {...props}
+ >
+ {icon &&
+ React.cloneElement(icon as React.ReactElement<{ className: string }>, {
+ className: cx(iconSizeVariant[size], "text-gray-9"),
+ })}
+ {children}
+ <SelectPrimitive.Icon asChild>
+ <ChevronDownIcon className="opacity-50 size-4 caret-icon" />
+ </SelectPrimitive.Icon>
+ </SelectPrimitive.Trigger>
+ );
+}
+
+function SelectContent({
+ className,
+ children,
+ position = "popper",
+ variant = "default",
+ sideOffset = 4,
+ ...props
+}: React.ComponentProps<typeof SelectPrimitive.Content> & {
+ variant?: SelectVariant;
+}) {
+ return (
+ <SelectPrimitive.Portal>
+ <SelectPrimitive.Content
+ data-slot="select-content"
+ className={cx(selectContentVariants({ variant }), className)}
+ position={position}
+ sideOffset={sideOffset}
+ {...props}
+ >
+ <SelectScrollUpButton />
+ <SelectPrimitive.Viewport
+ className={cx(
+ "p-1",
+ position === "popper" &&
+ "h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width) scroll-my-1",
+ )}
+ >
+ <SelectVariantContext.Provider value={variant}>
+ {children}
+ </SelectVariantContext.Provider>
+ </SelectPrimitive.Viewport>
+ <SelectScrollDownButton />
+ </SelectPrimitive.Content>
+ </SelectPrimitive.Portal>
+ );
+}
+
+function SelectItem({
+ className,
+ children,
+ icon,
+ ...props
+}: React.ComponentProps<typeof SelectPrimitive.Item> & {
+ icon?: React.ReactNode;
+}) {
+ const variant = React.useContext(SelectVariantContext);
+
+ return (
+ <SelectPrimitive.Item
+ data-slot="select-item"
+ className={cx(selectItemVariants({ variant }), className)}
+ {...props}
+ >
+ <span className="absolute right-2 flex size-3.5 items-center justify-center">
+ <SelectPrimitive.ItemIndicator>
+ <CheckIcon className="size-4" />
+ </SelectPrimitive.ItemIndicator>
+ </span>
+ <div className="flex justify-between items-center w-full">
+ <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
+ {icon &&
+ React.cloneElement(
+ icon as React.ReactElement<{ className: string }>,
+ { className: cx("size-3", "text-gray-9") },
+ )}
+ </div>
+ </SelectPrimitive.Item>
+ );
+}
+
+function SelectScrollUpButton({
+ className,
+ ...props
+}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
+ return (
+ <SelectPrimitive.ScrollUpButton
+ data-slot="select-scroll-up-button"
+ className={cx(
+ "flex justify-center items-center py-1 cursor-default",
+ className,
+ )}
+ {...props}
+ >
+ <ChevronUpIcon className="size-4" />
+ </SelectPrimitive.ScrollUpButton>
+ );
+}
+
+function SelectScrollDownButton({
+ className,
+ ...props
+}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
+ return (
+ <SelectPrimitive.ScrollDownButton
+ data-slot="select-scroll-down-button"
+ className={cx(
+ "flex justify-center items-center py-1 cursor-default",
+ className,
+ )}
+ {...props}
+ >
+ <ChevronDownIcon className="size-4" />
+ </SelectPrimitive.ScrollDownButton>
+ );
+}
+
+export {
+ SelectRoot,
+ SelectContent,
+ SelectItem,
+ SelectScrollDownButton,
+ SelectScrollUpButton,
+ SelectTrigger,
+ SelectValue,
+};
diff --git a/apps/chrome-extension/src/popup/ui/switch.tsx b/apps/chrome-extension/src/popup/ui/switch.tsx
new file mode 100644
index 000000000..ab69d514c
--- /dev/null
+++ b/apps/chrome-extension/src/popup/ui/switch.tsx
@@ -0,0 +1,32 @@
+import * as SwitchPrimitives from "@radix-ui/react-switch";
+import * as React from "react";
+import { classNames } from "./class-names";
+
+const Switch = React.forwardRef<
+ React.ElementRef<typeof SwitchPrimitives.Root>,
+ React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
+>(({ className, ...props }, ref) => (
+ <SwitchPrimitives.Root
+ className={classNames(
+ "peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-transparent transition-colors",
+ "w-11 h-6 p-0.5",
+ "bg-gray-5 data-[state=checked]:bg-blue-500",
+ "focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",
+ "disabled:cursor-not-allowed disabled:opacity-40 disabled:bg-gray-4",
+ className,
+ )}
+ {...props}
+ ref={ref}
+ >
+ <SwitchPrimitives.Thumb
+ className={classNames(
+ "pointer-events-none block rounded-full bg-white shadow-md",
+ "size-5 transition-transform",
+ "data-[state=checked]:translate-x-[calc(100%)] data-[state=unchecked]:translate-x-0",
+ )}
+ />
+ </SwitchPrimitives.Root>
+));
+Switch.displayName = SwitchPrimitives.Root.displayName;
+
+export { Switch };