ESLint autofix

This commit is contained in:
Marc Rousavy
2021-02-20 17:07:10 +01:00
parent 50509200aa
commit dc2be934f6
22 changed files with 439 additions and 690 deletions

View File

@@ -12,15 +12,15 @@
* * `"hevc-alpha"`: The HEVC (`muxa`) video codec that supports an alpha channel. This constant is used to select the appropriate encoder, but is NOT used on the encoded content, which is backwards compatible and hence uses `"hvc1"` as its codec type. _(iOS 13.0+)_
*/
export type CameraVideoCodec =
| "h264"
| "hevc"
| "hevc-alpha"
| "jpeg"
| "pro-res-4444"
| "pro-res-422"
| "pro-res-422-hq"
| "pro-res-422-lt"
| "pro-res-422-proxy";
| 'h264'
| 'hevc'
| 'hevc-alpha'
| 'jpeg'
| 'pro-res-4444'
| 'pro-res-422'
| 'pro-res-422-hq'
| 'pro-res-422-lt'
| 'pro-res-422-proxy';
// TODO: Support RAW photo codec
/**
@@ -30,4 +30,4 @@ export type CameraVideoCodec =
* * `"jpeg"`: The JPEG (`jpeg`) video codec. _(iOS 11.0+)_
* * `"hevc-alpha"`: The HEVC (`muxa`) video codec that supports an alpha channel. This constant is used to select the appropriate encoder, but is NOT used on the encoded content, which is backwards compatible and hence uses `"hvc1"` as its codec type. _(iOS 13.0+)_
*/
export type CameraPhotoCodec = "hevc" | "jpeg" | "hevc-alpha";
export type CameraPhotoCodec = 'hevc' | 'jpeg' | 'hevc-alpha';

View File

@@ -1,4 +1,4 @@
import type { CameraPosition } from "./CameraPosition";
import type { CameraPosition } from './CameraPosition';
/**
* Indentifiers for a physical camera (one that actually exists on the back/front of the device)
@@ -7,10 +7,7 @@ import type { CameraPosition } from "./CameraPosition";
* * `"wide-angle-camera"`: A built-in wide-angle camera. (focal length between 24mm and 35mm)
* * `"telephoto-camera"`: A built-in camera device with a longer focal length than a wide-angle camera. (focal length between above 85mm)
*/
export type PhysicalCameraDeviceType =
| "ultra-wide-angle-camera"
| "wide-angle-camera"
| "telephoto-camera";
export type PhysicalCameraDeviceType = 'ultra-wide-angle-camera' | 'wide-angle-camera' | 'telephoto-camera';
/**
* Indentifiers for a logical camera (Combinations of multiple physical cameras to create a single logical camera).
@@ -20,38 +17,24 @@ export type PhysicalCameraDeviceType =
* * `"triple-camera"`: A device that consists of three cameras of fixed focal length, one ultrawide angle, one wide angle, and one telephoto.
* * `"true-depth-camera"`: A combination of cameras and other sensors that creates a capture device capable of photo, video, and depth capture.
*/
export type LogicalCameraDeviceType =
| "dual-camera"
| "dual-wide-camera"
| "triple-camera"
| "true-depth-camera";
export type LogicalCameraDeviceType = 'dual-camera' | 'dual-wide-camera' | 'triple-camera' | 'true-depth-camera';
/**
* Parses an array of physical device types into a single `PhysicalCameraDeviceType` or `LogicalCameraDeviceType`, depending what matches.
*/
export const parsePhysicalDeviceTypes = (
physicalDeviceTypes: PhysicalCameraDeviceType[]
): PhysicalCameraDeviceType | LogicalCameraDeviceType => {
if (physicalDeviceTypes.length === 1) {
return physicalDeviceTypes[0];
}
const hasWide = physicalDeviceTypes.includes("wide-angle-camera");
const hasUltra = physicalDeviceTypes.includes("ultra-wide-angle-camera");
const hasTele = physicalDeviceTypes.includes("telephoto-camera");
if (hasTele && hasWide && hasUltra) {
return "triple-camera";
}
if (hasWide && hasUltra) {
return "dual-wide-camera";
}
if (hasWide && hasTele) {
return "dual-camera";
}
throw new Error(
`Invalid physical device type combination! ${physicalDeviceTypes.join(
" + "
)}`
);
export const parsePhysicalDeviceTypes = (physicalDeviceTypes: PhysicalCameraDeviceType[]): PhysicalCameraDeviceType | LogicalCameraDeviceType => {
if (physicalDeviceTypes.length === 1) return physicalDeviceTypes[0];
const hasWide = physicalDeviceTypes.includes('wide-angle-camera');
const hasUltra = physicalDeviceTypes.includes('ultra-wide-angle-camera');
const hasTele = physicalDeviceTypes.includes('telephoto-camera');
if (hasTele && hasWide && hasUltra) return 'triple-camera';
if (hasWide && hasUltra) return 'dual-wide-camera';
if (hasWide && hasTele) return 'dual-camera';
throw new Error(`Invalid physical device type combination! ${physicalDeviceTypes.join(' + ')}`);
};
/**
@@ -65,7 +48,7 @@ export const parsePhysicalDeviceTypes = (
* #### The following colorspaces are available on Android:
* * `"yuv"`: The YCbCr color space.
*/
export type ColorSpace = "hlg-bt2020" | "p3-d65" | "srgb" | "yuv";
export type ColorSpace = 'hlg-bt2020' | 'p3-d65' | 'srgb' | 'yuv';
/**
* Indicates a format's autofocus system.
@@ -74,7 +57,7 @@ export type ColorSpace = "hlg-bt2020" | "p3-d65" | "srgb" | "yuv";
* * `"contrast-detection"`: Indicates that autofocus is achieved by contrast detection. Contrast detection performs a focus scan to find the optimal position
* * `"phase-detection"`: Indicates that autofocus is achieved by phase detection. Phase detection has the ability to achieve focus in many cases without a focus scan. Phase detection autofocus is typically less visually intrusive than contrast detection autofocus
*/
export type AutoFocusSystem = "contrast-detection" | "phase-detection" | "none";
export type AutoFocusSystem = 'contrast-detection' | 'phase-detection' | 'none';
/**
* Indicates a format's supported video stabilization mode
@@ -85,12 +68,7 @@ export type AutoFocusSystem = "contrast-detection" | "phase-detection" | "none";
* * `"cinematic-extended"`: Indicates that the video should be stabilized using the extended cinematic stabilization algorithm. Enabling extended cinematic stabilization introduces longer latency into the video capture pipeline compared to the AVCaptureVideoStabilizationModeCinematic and consumes more memory, but yields improved stability. It is recommended to use identical or similar min and max frame durations in conjunction with this mode (iOS 13.0+)
* * `"auto"`: Indicates that the most appropriate video stabilization mode for the device and format should be chosen automatically
*/
export type VideoStabilizationMode =
| "off"
| "standard"
| "cinematic"
| "cinematic-extended"
| "auto";
export type VideoStabilizationMode = 'off' | 'standard' | 'cinematic' | 'cinematic-extended' | 'auto';
export type FrameRateRange = Readonly<{
minFrameRate: number;

View File

@@ -1,42 +1,40 @@
export type PermissionError =
| "permission/microphone-permission-denied"
| "permission/camera-permission-denied";
export type PermissionError = 'permission/microphone-permission-denied' | 'permission/camera-permission-denied';
export type ParameterError =
| "parameter/invalid-parameter"
| "parameter/unsupported-os"
| "parameter/unsupported-output"
| "parameter/unsupported-input"
| "parameter/invalid-combination";
| 'parameter/invalid-parameter'
| 'parameter/unsupported-os'
| 'parameter/unsupported-output'
| 'parameter/unsupported-input'
| 'parameter/invalid-combination';
export type DeviceError =
| "device/configuration-error"
| "device/no-device"
| "device/invalid-device"
| "device/torch-unavailable"
| "device/microphone-unavailable"
| "device/low-light-boost-not-supported"
| "device/focus-not-supported"
| "device/camera-not-available-on-simulator";
| 'device/configuration-error'
| 'device/no-device'
| 'device/invalid-device'
| 'device/torch-unavailable'
| 'device/microphone-unavailable'
| 'device/low-light-boost-not-supported'
| 'device/focus-not-supported'
| 'device/camera-not-available-on-simulator';
export type FormatError =
| "format/invalid-fps"
| "format/invalid-hdr"
| "format/invalid-low-light-boost"
| "format/invalid-format"
| "format/invalid-preset";
export type SessionError = "session/camera-not-ready";
| 'format/invalid-fps'
| 'format/invalid-hdr'
| 'format/invalid-low-light-boost'
| 'format/invalid-format'
| 'format/invalid-preset';
export type SessionError = 'session/camera-not-ready';
export type CaptureError =
| "capture/invalid-photo-format"
| "capture/encoder-error"
| "capture/muxer-error"
| "capture/recording-in-progress"
| "capture/no-recording-in-progress"
| "capture/file-io-error"
| "capture/create-temp-file-error"
| "capture/invalid-photo-codec"
| "capture/not-bound-error"
| "capture/capture-type-not-supported"
| "capture/unknown";
export type SystemError = "system/no-camera-manager";
export type UnknownError = "unknown/unknown";
| 'capture/invalid-photo-format'
| 'capture/encoder-error'
| 'capture/muxer-error'
| 'capture/recording-in-progress'
| 'capture/no-recording-in-progress'
| 'capture/file-io-error'
| 'capture/create-temp-file-error'
| 'capture/invalid-photo-codec'
| 'capture/not-bound-error'
| 'capture/capture-type-not-supported'
| 'capture/unknown';
export type SystemError = 'system/no-camera-manager';
export type UnknownError = 'unknown/unknown';
export interface ErrorWithCause {
/**
@@ -69,15 +67,7 @@ export interface ErrorWithCause {
cause?: ErrorWithCause;
}
type CameraErrorCode =
| PermissionError
| ParameterError
| DeviceError
| FormatError
| SessionError
| CaptureError
| SystemError
| UnknownError;
type CameraErrorCode = PermissionError | ParameterError | DeviceError | FormatError | SessionError | CaptureError | SystemError | UnknownError;
/**
* Represents any kind of error that occured in the Camera View Module.
@@ -98,7 +88,7 @@ class CameraError<TCode extends CameraErrorCode> extends Error {
}
constructor(code: TCode, message: string, cause?: ErrorWithCause) {
super(`[${code}]: ${message}${cause ? ` (Cause: ${cause.message})` : ""}`);
super(`[${code}]: ${message}${cause ? ` (Cause: ${cause.message})` : ''}`);
this._code = code;
this._message = message;
this._cause = cause;
@@ -114,58 +104,44 @@ export class CameraCaptureError extends CameraError<CaptureError> {}
* Represents any kind of error that occured in the Camera View Module.
*/
export class CameraRuntimeError extends CameraError<
| PermissionError
| ParameterError
| DeviceError
| FormatError
| SessionError
| SystemError
| UnknownError
PermissionError | ParameterError | DeviceError | FormatError | SessionError | SystemError | UnknownError
> {}
export const isErrorWithCause = (error: unknown): error is ErrorWithCause =>
typeof error === "object" &&
typeof error === 'object' &&
error != null &&
// @ts-expect-error error is still unknown
typeof error.message === "string" &&
typeof error.message === 'string' &&
// @ts-expect-error error is still unknown
(typeof error.stacktrace === "string" || error.stacktrace == null) &&
(typeof error.stacktrace === 'string' || error.stacktrace == null) &&
// @ts-expect-error error is still unknown
(isErrorWithCause(error.cause) || error.cause == null);
const isCameraErrorJson = (
error: unknown
): error is { code: string; message: string; cause?: ErrorWithCause } =>
typeof error === "object" &&
const isCameraErrorJson = (error: unknown): error is { code: string; message: string; cause?: ErrorWithCause } =>
typeof error === 'object' &&
error != null &&
// @ts-expect-error error is still unknown
typeof error.code === "string" &&
typeof error.code === 'string' &&
// @ts-expect-error error is still unknown
typeof error.message === "string" &&
typeof error.message === 'string' &&
// @ts-expect-error error is still unknown
(typeof error.cause === "object" || error.cause == null);
(typeof error.cause === 'object' || error.cause == null);
/**
* Tries to parse an error coming from native to a typed JS camera error.
* @param nativeError The native error instance. This is a JSON in the legacy native module architecture.
* @returns A `CameraRuntimeError` or `CameraCaptureError`, or the nativeError if it's not parsable
*/
export const tryParseNativeCameraError = <T>(
nativeError: T
): (CameraRuntimeError | CameraCaptureError) | T => {
export const tryParseNativeCameraError = <T>(nativeError: T): (CameraRuntimeError | CameraCaptureError) | T => {
if (isCameraErrorJson(nativeError)) {
if (nativeError.code.startsWith("capture")) {
return new CameraCaptureError(
nativeError.code as CaptureError,
nativeError.message,
nativeError.cause
);
if (nativeError.code.startsWith('capture')) {
return new CameraCaptureError(nativeError.code as CaptureError, nativeError.message, nativeError.cause);
} else {
return new CameraRuntimeError(
// @ts-expect-error the code is string, we narrow it down to TS union.
nativeError.code,
nativeError.message,
nativeError.cause
nativeError.cause,
);
}
} else {

View File

@@ -10,4 +10,4 @@
* #### Android only
* * `"external"`: The camera device is an external camera, and has no fixed facing relative to the device's screen. (Android only)
*/
export type CameraPosition = "front" | "back" | "unspecified" | "external";
export type CameraPosition = 'front' | 'back' | 'unspecified' | 'external';

View File

@@ -15,15 +15,15 @@
* * `"vga-640x480"`: Specifies capture settings suitable for VGA quality (640 x 480 pixel) video output.
*/
export type CameraPreset =
| "cif-352x288"
| "hd-1280x720"
| "hd-1920x1080"
| "hd-3840x2160"
| "high"
| "iframe-1280x720"
| "iframe-960x540"
| "input-priority"
| "low"
| "medium"
| "photo"
| "vga-640x480";
| 'cif-352x288'
| 'hd-1280x720'
| 'hd-1920x1080'
| 'hd-3840x2160'
| 'high'
| 'iframe-1280x720'
| 'iframe-960x540'
| 'input-priority'
| 'low'
| 'medium'
| 'photo'
| 'vga-640x480';

View File

@@ -2,24 +2,24 @@
* Available code types
*/
export type CodeType =
| "cat-body"
| "dog-body"
| "human-body"
| "salient-object"
| "aztec"
| "code-128"
| "code-39"
| "code-39-mod-43"
| "code-93"
| "data-matrix"
| "ean-13"
| "ean-8"
| "face"
| "interleaved-2-of-5"
| "itf-14"
| "pdf-417"
| "qr"
| "upce";
| 'cat-body'
| 'dog-body'
| 'human-body'
| 'salient-object'
| 'aztec'
| 'code-128'
| 'code-39'
| 'code-39-mod-43'
| 'code-93'
| 'data-matrix'
| 'ean-13'
| 'ean-8'
| 'face'
| 'interleaved-2-of-5'
| 'itf-14'
| 'pdf-417'
| 'qr'
| 'upce';
/**
* Represents a File in the local filesystem.

View File

@@ -1,5 +1,5 @@
import type { CameraPhotoCodec } from "./CameraCodec";
import type { TemporaryFile } from "./TemporaryFile";
import type { CameraPhotoCodec } from './CameraCodec';
import type { TemporaryFile } from './TemporaryFile';
export interface TakePhotoOptions {
/**
@@ -18,13 +18,13 @@ export interface TakePhotoOptions {
* @platform iOS 13.0+
* @default "balanced"
*/
qualityPrioritization?: "quality" | "balanced" | "speed";
qualityPrioritization?: 'quality' | 'balanced' | 'speed';
/**
* Whether the Flash should be enabled or disabled
*
* @default "auto"
*/
flash?: "on" | "off" | "auto";
flash?: 'on' | 'off' | 'auto';
/**
* Specifies whether red-eye reduction should be applied automatically on flash captures.
*
@@ -86,8 +86,8 @@ export type PhotoFile = Readonly<
*
* @platform iOS
*/
"{MakerApple}"?: Record<string, unknown>;
"{TIFF}": {
'{MakerApple}'?: Record<string, unknown>;
'{TIFF}': {
ResolutionUnit: number;
Software: string;
Make: string;
@@ -100,7 +100,7 @@ export type PhotoFile = Readonly<
Model: string;
YResolution: number;
};
"{Exif}": {
'{Exif}': {
DateTimeOriginal: string;
ExposureTime: number;
FNumber: number;

View File

@@ -26,14 +26,14 @@
// maxKeyFrameIntervalDuration?: TCodec extends "h264" ? number : never;
// }
import type { CameraCaptureError } from "./CameraError";
import type { TemporaryFile } from "./TemporaryFile";
import type { CameraCaptureError } from './CameraError';
import type { TemporaryFile } from './TemporaryFile';
export interface RecordVideoOptions {
/**
* Set the video flash mode. Natively, this just enables the torch while recording.
*/
flash?: "on" | "off" | "auto";
flash?: 'on' | 'off' | 'auto';
/**
* Called when there was an unexpected runtime error while recording the video.
*/