Automatically build API documentation (#11)
* Automatically build API documentation using Typedoc and Docusaurus * Move MD and move to MDX for Docusaurus Guides
This commit is contained in:
@@ -9,8 +9,11 @@ import type { CameraDevice, CameraDeviceFormat, FrameRateRange } from 'react-nat
|
||||
* > Note that this makes the `sort()` function descending, so the first element (`[0]`) is the "best" device.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* const devices = camera.devices.sort(sortDevices)
|
||||
* const bestDevice = devices[0]
|
||||
* ```
|
||||
* @method
|
||||
*/
|
||||
export const sortDevices = (left: CameraDevice, right: CameraDevice): number => {
|
||||
let leftPoints = 0;
|
||||
@@ -27,7 +30,19 @@ export const sortDevices = (left: CameraDevice, right: CameraDevice): number =>
|
||||
return rightPoints - leftPoints;
|
||||
};
|
||||
|
||||
export type Size = { width: number; height: number };
|
||||
/**
|
||||
* Represents a Size in any unit.
|
||||
*/
|
||||
export type Size = {
|
||||
/**
|
||||
* Points in width.
|
||||
*/
|
||||
width: number;
|
||||
/**
|
||||
* Points in height.
|
||||
*/
|
||||
height: number;
|
||||
};
|
||||
const SCREEN_SIZE: Size = {
|
||||
width: Dimensions.get('window').width,
|
||||
height: Dimensions.get('window').height,
|
||||
@@ -64,10 +79,15 @@ const getFormatAspectRatioOverflow = (format: CameraDeviceFormat, size: Size): n
|
||||
/**
|
||||
* Filters Camera Device Formats by the best matching aspect ratio for the given `viewSize`.
|
||||
*
|
||||
* @param {CameraDeviceFormat[]} formats A list of formats the current device has (see {@link CameraDevice.formats})
|
||||
* @param {Size} viewSize The size of the camera view which will be used to find the best aspect ratio. Defaults to the screen size.
|
||||
* @returns A list of Camera Device Formats that match the given `viewSize`' aspect ratio _as close as possible_.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* const formats = useMemo(() => filterFormatsByAspectRatio(device.formats, CAMERA_VIEW_SIZE), [device.formats])
|
||||
* ```
|
||||
* @method
|
||||
*/
|
||||
export const filterFormatsByAspectRatio = (formats: CameraDeviceFormat[], viewSize = SCREEN_SIZE): CameraDeviceFormat[] => {
|
||||
const minOverflow = formats.reduce((prev, curr) => {
|
||||
@@ -80,11 +100,14 @@ export const filterFormatsByAspectRatio = (formats: CameraDeviceFormat[], viewSi
|
||||
};
|
||||
|
||||
/**
|
||||
* Sorts Camera Device Formats by highest photo-capture resolution, descending.
|
||||
* Sorts Camera Device Formats by highest photo-capture resolution, descending. Use this in a `.sort` function.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* const formats = useMemo(() => device.formats.sort(sortFormatsByResolution), [device.formats])
|
||||
* const bestFormat = formats[0]
|
||||
* ```
|
||||
* @method
|
||||
*/
|
||||
export const sortFormatsByResolution = (left: CameraDeviceFormat, right: CameraDeviceFormat): number => {
|
||||
let leftPoints = left.photoHeight * left.photoWidth;
|
||||
@@ -102,8 +125,13 @@ export const sortFormatsByResolution = (left: CameraDeviceFormat, right: CameraD
|
||||
/**
|
||||
* Returns `true` if the given Frame Rate Range (`range`) contains the given frame rate (`fps`)
|
||||
*
|
||||
* @param {FrameRateRange} range The range to check if the given `fps` are included in
|
||||
* @param {number} fps The FPS to check if the given `range` supports.
|
||||
* @example
|
||||
* ```js
|
||||
* // get all formats that support 60 FPS
|
||||
* const formatsWithHighFps = useMemo(() => device.formats.filter((f) => f.frameRateRanges.some((r) => frameRateIncluded(r, 60))), [device.formats])
|
||||
* ```
|
||||
* @method
|
||||
*/
|
||||
export const frameRateIncluded = (range: FrameRateRange, fps: number): boolean => fps >= range.minFrameRate && fps <= range.maxFrameRate;
|
||||
|
Reference in New Issue
Block a user