@leelexuan/react-qr-scanner
Version:
An enhanced React library for QR code scanning with API interaction capabilities and support for mouse-click detection on bounding boxes.
113 lines (96 loc) • 2.78 kB
TypeScript
import React, { CSSProperties, ReactNode } from 'react';
import { BarcodeFormat } from 'barcode-detector';
export { setZXingModuleOverrides } from 'barcode-detector';
interface IScannerComponents {
tracker?: TrackFunction;
onOff?: boolean;
finder?: boolean;
torch?: boolean;
zoom?: boolean;
}
interface IPoint {
x: number;
y: number;
}
interface IBoundingBox {
x: number;
y: number;
width: number;
height: number;
}
interface IUseScannerState {
lastScan: number;
lastOnScan: number;
contentBefore: string[];
lastScanHadContent: boolean;
}
interface IDetectedBarcode {
boundingBox: IBoundingBox;
cornerPoints: IPoint[];
format: string;
rawValue: string;
}
interface IStartTaskResult {
type: 'start';
data: {
videoEl: HTMLVideoElement;
stream: MediaStream;
constraints: MediaTrackConstraints;
};
}
interface IStopTaskResult {
type: 'stop';
data: {};
}
interface IStartCamera {
constraints: MediaTrackConstraints;
restart?: boolean;
}
interface IScannerStyles {
container?: CSSProperties;
video?: CSSProperties;
finderBorder?: number;
}
interface IScannerClassNames {
container?: string;
video?: string;
}
interface IAdjustedBarcode {
boundingBox: IBoundingBox;
cornerPoints: IPoint[];
format: string;
rawValue: string;
colour: string;
}
interface IBoundingBoxRawValue {
x: number;
y: number;
width: number;
height: number;
rawValue: string;
}
type TrackFunction = (detectedCodes: IAdjustedBarcode[], ctx: CanvasRenderingContext2D) => IBoundingBoxRawValue[];
interface IScannerProps {
onScan: (detectedCodes: IDetectedBarcode[]) => void;
onError?: (error: unknown) => void;
onBoundingBoxClick: (rawValue: string) => void;
onNewBarcodeDetected: (rawValue: string) => Promise<boolean>;
constraints?: MediaTrackConstraints;
formats?: BarcodeFormat[];
paused?: boolean;
children?: ReactNode;
components?: IScannerComponents;
styles?: IScannerStyles;
classNames?: IScannerClassNames;
allowMultiple?: boolean;
scanDelay?: number;
}
declare function Scanner(props: IScannerProps): React.JSX.Element;
declare function boundingBox(detectedCodes: IAdjustedBarcode[], ctx: CanvasRenderingContext2D): {
x: number;
y: number;
width: number;
height: number;
rawValue: string;
}[];
export { type IAdjustedBarcode, type IBoundingBox, type IBoundingBoxRawValue, type IDetectedBarcode, type IPoint, type IScannerClassNames, type IScannerComponents, type IScannerProps, type IScannerStyles, type IStartCamera, type IStartTaskResult, type IStopTaskResult, type IUseScannerState, Scanner, type TrackFunction, boundingBox };