import React from "react"; /** 미디어 입력 장치 목록과 label 사용 가능 여부. */ type UseMediaDevicesResult = { /** 마지막으로 조회한 장치 목록. 조회 전이면 빈 배열이다. 조회에 실패하면 이전 목록을 유지한다. */ readonly devices: readonly MediaDeviceInfo[]; /** 장치가 있고 모든 장치에 label이 있으면 true다. 카메라·마이크 권한을 허용하기 전에는 false다. */ readonly labelsAvailable: boolean; /** 마지막 조회 오류. 조회에 성공하면 undefined다. */ readonly error: Error | undefined; /** 장치 목록을 다시 조회한다. 권한을 허용한 뒤 label을 얻을 때 호출한다. 오류는 던지지 않고 `error`로 전달한다. */ refresh: () => Promise; }; /** * 미디어 입력 장치 목록을 조회하고 `devicechange`마다 자동으로 갱신한다. * * - `kind`를 생략하면 브라우저가 알려 주는 모든 장치를 반환한다. * - 권한 허용 전에는 `label`이 빈 문자열이다. `labelsAvailable`이 false이면 대체 이름을 쓴다. * - 서버 렌더링 중에는 조회하지 않는다. 마운트 뒤에 조회한다. */ export declare function useMediaDevices(kind?: "videoinput" | "audioinput"): UseMediaDevicesResult; /** * Webcam lifecycle phases published by the component. */ type WebcamPhase = "idle" | "requesting" | "live" | "playback-error" | "denied" | "unavailable" | "unsupported" | "insecure" | "error"; /** * Normalized webcam error codes derived from browser errors. */ type WebcamErrorCode = "permission-denied" | "policy-blocked" | "security-error" | "device-not-found" | "device-in-use" | "constraints-unsatisfied" | "unsupported-browser" | "insecure-context" | "aborted" | "track-ended" | "unknown"; /** * Actual video size observed after metadata is available. * The value is optional on every variant so it can survive phase transitions. */ type WithVideoSize = { videoSize?: { width: number; height: number; }; }; /** * Set to `true` once the audio track ended unexpectedly (for example, the microphone was unplugged). * The video stream is kept alive, so the phase does not change. */ type WithAudioEnded = { audioEnded?: boolean; }; /** * Shared fields for error phases. */ type WebcamDetailError = WithVideoSize & { phase: "denied" | "unavailable" | "unsupported" | "insecure" | "error"; /** Normalized library error code. */ errorCode: WebcamErrorCode; /** Original browser error. */ error: Error; /** Constraints active when the error occurred. */ constraints: MediaStreamConstraints; }; /** * Discriminated union describing the current webcam state. * Narrow with `phase` to safely access phase-specific fields. * * @example * ```ts * function handleDetail(detail: WebcamDetail) { * if (detail.phase === 'live') { * console.log(detail.mediaStream); // MediaStream — 항상 존재 * } else if (detail.phase === 'denied') { * console.warn(detail.errorCode); // WebcamErrorCode — 항상 존재 * } * } * ``` */ type WebcamDetail = /** Initial state before requesting a stream. */ (WithVideoSize & { phase: "idle"; }) | /** `getUserMedia` request in progress. */ (WithVideoSize & { phase: "requesting"; constraints: MediaStreamConstraints; }) | /** Stream acquired. This alone does not guarantee playback or a decoded frame. */ (WithVideoSize & WithAudioEnded & { phase: "live"; /** Acquired `MediaStream`, always present in the `live` phase. */ mediaStream: MediaStream; constraints: MediaStreamConstraints; }) | /** * Stream acquisition succeeded, but `video.play()` failed. * This commonly happens when autoplay is blocked. * `AbortError` caused by `srcObject` replacement does not enter this phase. */ (WithVideoSize & WithAudioEnded & { phase: "playback-error"; /** The stream is still valid even though playback failed. */ mediaStream: MediaStream; constraints: MediaStreamConstraints; /** Original `play()` failure. */ error: Error; }) | /** Error phases such as denied, unavailable, unsupported, insecure, or generic failure. */ WebcamDetailError; /** * `WebcamDetail` variants that describe a failed camera request. * This is the detail type passed to the `errorFallback` render function. */ type WebcamErrorDetail = Extract; /** How the video is fitted into its box when no `aspectRatio` is set. */ type WebcamFitMode = "unset" | "fill" | "cover" | "contain"; /** Camera options translated into `getUserMedia()` constraints. */ type WebcamOptions = { /** Enables audio capture. */ audioEnabled?: boolean; /** * Preferred video size, or `"element-size"` to mirror the rendered element. * With `"element-size"`, size changes under 10% of the last requested size * (both width and height) do not request the stream again. */ size?: { width?: number; height?: number; } | "element-size"; /** Preferred aspect ratio. */ aspectRatio?: number; /** Preferred device ID. */ deviceId?: string; /** * Preferred facing mode. When omitted, the browser chooses automatically. * Ignored when `deviceId` is provided. */ facingMode?: "user" | "environment"; /** * Device selection strategy. * - `'ideal'`: use `deviceId` as an ideal constraint * - `'exact'`: use `deviceId` as an exact constraint * Defaults to `'ideal'`. */ deviceSelectionStrategy?: "ideal" | "exact"; /** Preferred frame rate. */ frameRate?: number; /** Upper bound for the frame rate. */ maxFrameRate?: number; }; /** 호출자가 소유한 video와 카메라 요청 조건. */ type UseWebcamOptions = { /** 요소가 없으면 요청하지 않는다. muted와 playsInline은 호출자가 설정한다. */ videoElement: HTMLVideoElement | null | undefined; webcamOptions?: WebcamOptions; disabled?: boolean; /** true이면 `track-ended` 오류 뒤 탭이 다시 보일 때 스트림을 한 번 다시 요청한다. 기본값은 false다. */ autoRecover?: boolean; }; /** 표시 UI에 의존하지 않는 카메라 상태와 제어 함수. */ type UseWebcamResult = { readonly detail: WebcamDetail; /** * live 상태에서 현재 스트림의 readyState가 2 이상이고 영상 크기가 양수일 때 true다. * 비디오 트랙이 `muted`인 동안은 false다. */ readonly isFrameReady: boolean; /** 현재 스트림을 정리하고 같은 옵션으로 다시 요청한다. disabled 중에는 요청하지 않는다. */ retry: () => void; /** 영상 재생만 멈춘다. 카메라 트랙은 유지한다. */ pausePlayback: () => void; /** 사용자 조작 후 호출한다. 재생 실패는 detail의 playback-error로 전달한다. */ resumePlayback: () => void; }; /** 외부 video에 스트림을 연결하고 요청·재생 에러와 프레임 준비 상태를 관리한다. */ export declare function useWebcam(options: UseWebcamOptions): UseWebcamResult; /** Returns every media input device visible to the current browser context. */ export declare function listMediaDevices(): Promise; /** Returns the available video input devices. */ export declare function listVideoInputDevices(): Promise; /** Returns the available audio input devices. */ export declare function listAudioInputDevices(): Promise; /** Options for capturing the current video frame to a canvas. */ type SnapshotOptions = { /** Enables image smoothing on the destination canvas. */ imageSmoothEnabled?: boolean; /** Existing canvas to draw into instead of creating a new one. */ canvas?: HTMLCanvasElement; /** Maximum size constraint applied to the captured image. */ sizeConstraints?: { maxWidth: number; } | { maxHeight: number; }; /** * 결과 이미지의 좌우 반전 여부다. * 생략하면 현재 `flipped` 상태(미리보기와 같은 방향)를 따른다. * 거울 미리보기에서 정방향 이미지를 저장하려면 `false`를 넘긴다. */ flipped?: boolean; /** * 원본 프레임 가운데를 이 비율(너비/높이)로 잘라 낸다. * 미리보기 컨테이너 비율이 이 값과 같고 `fitMode: "cover"`이며 `object-position`이 기본값일 때는 미리보기와 같은 영역이다. * 0 이하, `NaN`, `Infinity`는 무시한다. * `sizeConstraints`는 잘라 낸 크기에 적용한다. 처리 순서는 크롭, 축소, 반전이다. */ aspectRatio?: number; }; /** * Optional label overrides for the built-in webcam UI controls. * Any field left undefined falls back to the default Korean label set. */ type WebcamLabels = { /** Snapshot button `title` / `aria-label`. */ snapshot?: string; /** Mirror toggle button `title` / `aria-label`. */ flip?: string; /** Camera direction button `title` / `aria-label`. */ cameraDirection?: string; /** Rear camera name shown in the camera direction button `title` / `aria-label`. */ facingModeBack?: string; /** Front camera name shown in the camera direction button `title` / `aria-label`. */ facingModeFront?: string; /** @deprecated The camera direction button no longer has a browser-default option. This label is not used. */ facingModeDefault?: string; /** Aspect ratio button `title` / `aria-label`. */ aspectRatio?: string; /** Aspect ratio menu label for the automatic option. */ aspectRatioAuto?: string; }; /** Built-in English label table. Pass it as `labels` to switch the built-in UI to English. */ export declare const WEBCAM_LABELS_EN: Required; /** `Webcam`이 내장하는 컨트롤 버튼의 표시 여부다. */ type WebcamControls = { /** 좌우 반전 토글 버튼 표시 여부다. */ flip?: boolean; /** 카메라 방향 버튼 표시 여부다. */ cameraDirection?: boolean; /** 화면 비율 버튼 표시 여부다. */ aspectRatio?: boolean; /** 스냅샷 버튼 표시 여부다. */ snapshot?: boolean; }; /** * `Webcam`이 내장하는 컨트롤 버튼의 아이콘 교체값이다. * 빠진 항목은 기본 아이콘을 쓴다. 아이콘은 버튼 안에 그대로 렌더링한다. * 색은 `currentColor`를 따르면 버튼 색과 맞는다. 기본 크기는 `flip`, `cameraDirection`, * `aspectRatio`가 `1.2rem`, `snapshot`이 `2rem`이다. */ type WebcamIcons = { /** 좌우 반전 버튼 아이콘이다. */ flip?: React.ReactNode; /** 카메라 방향 버튼 아이콘이다. */ cameraDirection?: React.ReactNode; /** 화면 비율 버튼 아이콘이다. */ aspectRatio?: React.ReactNode; /** 스냅샷 버튼 아이콘이다. */ snapshot?: React.ReactNode; }; /** `Webcam`이 내장하는 디버그 오버레이의 표시 여부다. */ type WebcamDebug = { /** 비디오 크기 디버그 UI 표시 여부다. */ videoSize?: boolean; /** 미디어 제약 조건 디버그 UI 표시 여부다. */ constraints?: boolean; }; /** * `ref`로 노출하는 `Webcam` 제어 핸들이다. * * @example * ```tsx * const ref = useRef(null); * * const canvas = ref.current?.snapshotToCanvas(); * ``` */ type WebcamHandle = { /** * 현재 프레임을 캔버스로 캡처한다. 아직 준비 전이면 `null`을 반환한다. * `options.flipped`를 생략하면 현재 반전 상태를 따르고, 지정하면 그 값으로 덮어쓴다. * `options.aspectRatio`를 지정하면 가운데를 그 비율로 잘라 낸다. */ snapshotToCanvas: (options?: SnapshotOptions) => HTMLCanvasElement | null; /** * 지금 프레임을 캡처할 수 있는지 반환한다. `onFrameReadyChange`가 다루는 현재 값이다. * * - `true`: phase가 `live`이고 `readyState >= 2`이며 영상 크기가 양수이고 비디오 트랙이 `muted`가 아니다. * - `pausePlayback()`은 이 값을 바꾸지 않는다. 일시 정지한 프레임도 캡처할 수 있다. * - `true`여도 `snapshotToCanvas`가 `null`을 돌려줄 수 있다(예: 2D context 생성 실패). * - 언마운트 뒤에는 캐시한 핸들도 `false`를 반환한다. * - 호출 시점의 값이며 구독하지 않는다. 변경을 따라가려면 `onFrameReadyChange`를 쓴다. */ isFrameReady: () => boolean; /** * 현재 webcam detail을 반환한다. * * - `onStateChange`로 받는 값과 같다. * - 이벤트 핸들러 안에서 "지금 live인가"를 확인할 때 쓴다. * - 호출 시점의 값이며 구독하지 않는다. 변경을 따라가려면 `onStateChange`를 쓴다. */ getDetail: () => WebcamDetail; /** * `Webcam`이 렌더링한 `