UNPKG

scandit-web-datacapture-core

Version:

Scandit Data Capture SDK for the Web

1,322 lines (1,310 loc) 71.1 kB
/// <reference types="emscripten" /> import { Serializable } from './private/Serializable.js'; import { WatermarkStack } from './private/FrameReaders/WatermarkStack.js'; import { Optional, MethodSignature } from './tsHelper.js'; import { Size, Orientation, MarginsWithUnitJSON, PointWithUnitJSON, Anchor, MarginsWithUnit, PointWithUnit, Point, Quadrilateral, JSONType, RectJSON, PointJSON } from './Common.js'; import { DataCaptureContextSettings, DataCaptureContextSettingsJSON } from './DataCaptureContextSettings.js'; import { LogoStyle, FocusGestureJSON, ZoomGestureJSON, FocusGesture, ZoomGesture } from './DataCaptureViewPlusRelated.js'; import { Control } from './ViewControls.js'; import { DidTapCustomLocationsViewListener, StateToRender } from './private/CustomLocationsView.js'; import { AnchorPositions } from './private/AnchorPositions.js'; import { HTMLElementStateJSON } from './private/HtmlElementState.js'; import { Logger } from './logger.js'; import { ProgressInfo } from './LoadingStatus.js'; declare enum CameraPosition$1 { WorldFacing = "worldFacing", UserFacing = "userFacing" } declare enum CameraResolutionConstraint$1 { ULTRA_HD = 0, FULL_HD = 1, HD = 2, SD = 3, NONE = 4 } declare enum AspectRatio { AUTO = "auto", FOUR_TO_THREE = "fourToThree", SIXTEEN_TO_NINE = "sixteenToNine" } interface DeviceCamera$1 { position: CameraPosition$1; label: string; deviceId: string; currentResolution?: VideoFrameResolution; } /** * A helper object to interact with cameras. */ declare namespace CameraAccess$1 { /** * Overrides for main camera for a given camera position on a desktop/laptop device, set when accessing an initial camera. */ const mainCameraForPositionOverridesOnDesktop: Map<CameraPosition$1, DeviceCamera$1>; /** * * To be accessed directly only for tests. * * The mapping from deviceIds to camera objects. */ const deviceIdToCameraObjects: Map<string, DeviceCamera$1>; /** * * To be accessed directly only for tests. * * The list of inaccessible deviceIds. */ const inaccessibleDeviceIds: Set<string>; function setMainCameraForPositionOverridesOnDesktop(cameraPosition: CameraPosition$1, deviceCamera: DeviceCamera$1): void; /** * used mainly for testing */ function clearMainCameraForPositionOverridesOnDesktop(): void; /** * * @param label The camera label. * @returns Whether the label identifies the camera being the iOS front (main) camera one. */ function isIOSFrontCameraLabel(label: string): boolean; /** * * @param label The camera label. * @returns Whether the label identifies the camera being the iOS back (main) camera one. */ function isIOSBackCameraLabel(label: string): boolean; /** * * @param label The camera label. * @returns Whether the label identifies the camera being the iOS Back Dual camera one. */ function isIOSBackDualWideCameraLabel(label: string): boolean; /** * * @param label The camera label. * @returns Whether the label identifies the camera being the iOS UltraWide back camera one. */ function isIOSUltraWideBackCameraLabel(label: string): boolean; /** * * Get the main camera for the given camera position. * * @param cameras The array of available [[DeviceCamera]] objects. * @param cameraPosition The wanted camera position. * @returns The main camera matching the wanted camera position. */ function getMainCameraForPosition(cameras: DeviceCamera$1[], cameraPosition: CameraPosition$1): DeviceCamera$1 | undefined; /** * * Sort the given cameras in order of priority of access based on the given camera position. * * @param cameras The array of available [[DeviceCamera]] objects. * @param cameraPosition The preferred camera position. * @returns The sorted cameras. */ function sortCamerasForCameraPosition<DeviceCameraLike extends DeviceCamera$1 = DeviceCamera$1>(cameras: DeviceCameraLike[], cameraPosition: CameraPosition$1): DeviceCameraLike[]; /** * * Adjusts the camera's information based on the given currently active video stream. * * @param mediaStream The currently active `MediaStream` object. * @param camera The currently active [[Camera]] object associated with the video stream. */ function adjustCameraFromMediaStream(mediaStream: MediaStream, camera: DeviceCamera$1): void; /** * Get a list of cameras (if any) available on the device, a camera access permission is requested to the user * the first time this method is called if needed. * * If the user denies the necessary camera access permission, a list of cameras with the correct amount of devices is * returned in any case, but the cameras will have no available (empty) label and deviceId and can thus not be * accessed. * * If the browser is incompatible the returned promise is rejected with a `UnsupportedBrowserError` error. * * When refreshing available devices, if updated deviceId information is detected, cameras' deviceId are updated * accordingly. This could happen after a camera access and stop in some situations. * * @param refreshDevices Force a call to refresh available video devices even when information is already available. * @param cameraAlreadyAccessed Hint that a camera has already been accessed before, avoiding a possible initial * camera access permission request on the first call, in cases this cannot be already reliably detected. * @returns A promise resolving to the array of available [[Camera]] objects (could be empty). */ function getCameras(refreshDevices?: boolean, cameraAlreadyAccessed?: boolean): Promise<DeviceCamera$1[]>; /** * * Get the *getUserMedia* *video* parameters to be used given a resolution fallback level and the browser used. * * @param cameraResolutionConstraint The resolution constraint. * @returns The resulting *getUserMedia* *video* parameters. */ function getUserMediaVideoParameters(cameraResolutionConstraint: CameraResolutionConstraint$1, preferredAspectRatio?: AspectRatio): MediaTrackConstraints; /** * * Mark a camera to be inaccessible and thus excluded from the camera list returned by [[getCameras]]. * * @param camera The camera to mark to be inaccessible. */ function markCameraAsInaccessible(camera: DeviceCamera$1): void; /** * * Try to access a given camera for video input at the given resolution level. * * If a camera is inaccessible because of errors, then it's added to the inaccessible device list. If the specific * error is of type `OverconstrainedError` or `NotReadableError` however, this procedure is done later on via a * separate external logic; also, in case of an error of type `NotAllowedError` (permission denied) this procedure is * not executed, in order to possibly recover if and when the user allows the camera to be accessed again. * This is done to allow checking if the camera can still be accessed via an updated deviceId when deviceId * information changes, or if it should then be confirmed to be considered inaccessible. * * Depending on parameters, device features and user permissions for camera access, any of the following errors * could be the rejected result of the returned promise: * - `AbortError` * - `NotAllowedError` * - `NotFoundError` * - `NotReadableError` * - `SecurityError` * - `OverconstrainedError` * * @param cameraResolutionConstraint The resolution constraint. * @param camera The camera to try to access for video input. * @returns A promise resolving to the `MediaStream` object coming from the accessed camera. */ function accessCameraStream(camera: DeviceCamera$1, cameraResolutionConstraint: CameraResolutionConstraint$1, preferredAspectRatio?: AspectRatio): Promise<MediaStream>; } /** * these are the public exports from CameraAccess */ declare namespace CameraAccess { function getCameras(refreshDevices?: boolean, cameraAlreadyAccessed?: boolean): Promise<DeviceCamera[]>; } interface DeviceCamera { position: CameraPosition$1; label: string; deviceId: string; } declare enum FrameSourceState { On = "on", Off = "off", Standby = "standby", Starting = "starting", Stopping = "stopping", BootingUp = "bootingUp", WakingUp = "wakingUp", GoingToSleep = "goingToSleep", ShuttingDown = "shuttingDown" } declare enum TorchState { On = "on", Off = "off" } declare enum CameraPosition { WorldFacing = "worldFacing", UserFacing = "userFacing" } declare enum VideoResolution { Auto = "auto", HD = "hd", FullHD = "fullHd", UHD4K = "uhd4k" } declare enum FocusGestureStrategy { None = "none", Manual = "manual", ManualUntilCapture = "manualUntilCapture", AutoOnLocation = "autoOnLocation" } interface FrameSourceListener { didChangeState?: (frameSource: FrameSource, newState: FrameSourceState) => void; } interface FrameSourceJSON { type: string; } interface FrameSource extends Serializable<FrameSourceJSON> { readonly desiredState: FrameSourceState; getCurrentState: () => FrameSourceState; switchToDesiredState: (desiredState: FrameSourceState) => Promise<void>; addListener: (listener: FrameSourceListener) => void; removeListener: (listener: FrameSourceListener) => void; } interface CameraSettingsJSONBase { preferredResolution: string; zoomFactor: number; zoomGestureZoomFactor: number; api?: number; } interface CameraSettingsFromJSON extends CameraSettingsJSONBase { focusGestureStrategy: string; } interface CameraSettingsJSON extends CameraSettingsJSONBase { focus: { focusGestureStrategy: string; [key: string]: any; }; [key: string]: any; } declare function isCameraFrameSource(frameSource?: FrameSource | null): frameSource is Camera; declare class CameraSettings implements Serializable<CameraSettingsJSON> { preferredResolution: VideoResolution; zoomFactor: number; zoomGestureZoomFactor: number; private focus; get focusGestureStrategy(): FocusGestureStrategy; set focusGestureStrategy(newStrategy: FocusGestureStrategy); private static fromJSON; constructor(); constructor(settings: CameraSettings); setProperty(name: string, value: any): void; getProperty(name: string): any; /** * The resulting JSON must also contain properties set on the object itself ("hidden" properties) */ toJSONObject(): CameraSettingsJSON & Record<string, any>; } interface PoolCapacityOptions { minPoolCapacity: number; maxPoolCapacity: number; } declare abstract class FrameReaderAbstract { colorType: ColorType; protected readonly _contextWebGL: WebGLRenderingContext; protected readonly _maxPoolCapacity: number; protected readonly _minPoolCapacity: number; /** * In mobile applications, particularly on Android, capturing frames at a slow rate can be a common issue, * especially in scenarios involving barcode tracking. Using a stack becomes valuable in such situations * because it allows us to capture next frame with pixel data while the engine is still processing the previous one, * eliminating the need to wait for the engine to finish before capturing the next frame. */ protected _framePool: Optional<WatermarkStack<Uint8ClampedArray>>; constructor(contextWebGL: WebGLRenderingContext, options?: PoolCapacityOptions | undefined); abstract readFromSource(source: TexImageSource): FrameCapture; abstract setup(): void; recycle(pixelsData: Uint8ClampedArray): void; abstract dispose(): void; } declare enum ColorType { RGBA = "RGBA", GRAYSCALE = "GRAYSCALE" } declare class FrameReader extends FrameReaderAbstract { colorType: ColorType; private _framebuffer; private _texture; private _frameSize; private get _initialized(); readFromSource(source: TexImageSource): FrameCapture; setup(): void; dispose(): void; private updateFrameSizeIfNeeded; } interface DataCaptureContextListener { didChangeStatus?: (context: DataCaptureContext$1, contextStatus: ContextStatus) => void; didStartObservingContext?: (context: DataCaptureContext$1) => void; didChangeFrameSource?: (context: DataCaptureContext$1, frameSource: FrameSource | null) => void; } interface ContextStatusJSON { code: number; isValid: boolean; message: string; } declare class ContextStatus { private _message; private _code; private _isValid; private static fromJSON; get message(): string; get code(): number; get isValid(): boolean; } declare enum PrivateMirrorAxis { None = "None", X = "X", Y = "Y" } interface DataCaptureOverlay extends Serializable { toJSONObject: () => any; } interface DataCaptureViewListener { didChangeSize?: (view: DataCaptureView$1, size: Size, orientation: Orientation) => void; } interface DataCaptureViewJSON { scanAreaMargins: MarginsWithUnitJSON; pointOfInterest: PointWithUnitJSON; logoAnchor: Anchor; logoOffset: PointWithUnitJSON; logoHidden: boolean; logoStyle: LogoStyle; overlays: any[]; controls: any[]; focusGesture: FocusGestureJSON | null; zoomGesture: ZoomGestureJSON | null; } declare class DataCaptureView$1 implements Serializable<DataCaptureViewJSON> { focusGesture: FocusGesture | null; zoomGesture: ZoomGesture | null; private _scanAreaMargins; private _pointOfInterest; private _logoStyle; private _logoAnchor; private _logoOffset; private _cameraRecoveryText; private _context; private readonly overlays; private readonly controls; private gestureRecognizer; private readonly controlWidgets; private containerElement; private cameraPaintboardElement?; private singleImageUploaderPaintboardElement?; private videoElement?; private visibilityListener; private videoPauseListener; private cameraRecoveryListener; private controlsElement; private cameraRecoveryElement; private errorElement; private hintContainerElement; private hintElement; private canvasElement; private frozenFrame; private frozenFrameCanvas; private _canvasDrawer; private readonly listeners; private htmlElement?; private htmlElementState?; private lastHtmlElementState; private isVideoElementDetached; private loadingOverlay; private customLocationsView; private lastFrameSourceState; private singleImageUploaderView; private orientation; private hiddenProperties; private orientationObserver; private onOrientationChangeListener; private hintPresenter; private onHintPresenterUpdateHandler; private onBeforeShowToastsHandler; private onWorkerMessageHandler; constructor(); get scanAreaMargins(): MarginsWithUnit; set scanAreaMargins(margins: MarginsWithUnit); get pointOfInterest(): PointWithUnit; set pointOfInterest(pointOfInterest: PointWithUnit); get logoStyle(): LogoStyle; set logoStyle(logoStyle: LogoStyle); get logoAnchor(): Anchor; set logoAnchor(logoAnchor: Anchor); get logoOffset(): PointWithUnit; set logoOffset(logoOffset: PointWithUnit); get cameraRecoveryText(): string; /** * @deprecated 6.21.0 */ set cameraRecoveryText(cameraRecoveryText: string); private get width(); private get height(); private get canvasDrawer(); /** * The current context as a PrivateDataCaptureContext */ private get privateContext(); static forContext(context: DataCaptureContext$1 | null): Promise<DataCaptureView$1>; showProgressBar(): void; hideProgressBar(): void; setProgressBarPercentage(percentage: number | null): void; setProgressBarMessage(message: string): void; getContext(): DataCaptureContext$1 | null; setContext(context: DataCaptureContext$1 | null): Promise<void>; connectToElement(element: HTMLElement): void; detachFromElement(): void; addOverlay(overlay: DataCaptureOverlay): Promise<void>; removeOverlay(overlay: DataCaptureOverlay): Promise<void>; addListener(listener: DataCaptureViewListener): void; removeListener(listener: DataCaptureViewListener): void; /** * Converts a point in the coordinate system of the last visible frame and maps it to a coordinate in the view. * It does *not* take into account if the frameSource is mirrored. */ viewPointForFramePoint(point: Point): Point; viewQuadrilateralForFrameQuadrilateral(quadrilateral: Quadrilateral): Quadrilateral; addControl(control: Control): void; removeControl(control: Control): void; toJSONObject(): DataCaptureViewJSON; isCameraRecoveryVisible(): boolean; setCameraRecoveryVisible(visible: boolean): void; allowPictureInPicture(allow: boolean): Promise<void>; protected viewAnchorPositionsForFrameAnchorPositions(anchorPositions: AnchorPositions): AnchorPositions; protected setDidTapCustomLocationsViewListener(didTapViewListener: DidTapCustomLocationsViewListener): void; protected renderCustomLocationsView(state: StateToRender): void; private removeStyles; private onHintPresenterUpdate; private clearHtmlElementContent; private setupHtmlElement; private setupHtmlElementSingleImageUploader; private setupHtmlElementVisibility; private createStyles; private onOrientationChange; private htmlElementDidChange; private htmlElementDisconnected; private handleVideoDisplay; private isCanvasDrawerWithMetrics; private onWorkerMessage; private onBeforeShowToasts; private drawEngineCommands; private displayError; private clearError; private displayHint; private hideHint; private updateHint; private updateAnchor; private controlsUpdated; private redrawControls; /** * Allows capture modes to register their own widgets so that they can be added to the view. */ private registerControlWidget; private getControlWidget; private onFrameSourceChange; private onCameraStateChanged; private setVideoElementOpacity; private onSingleImageUploaderSettingsChange; private handleVideoPause; private setHiddenProperty; private onVisibilityChange; private cameraRecovery; private freezeFrame; private unfreezeFrame; } type CommandAndPayload<A, C> = A extends { command: C; } ? A : never; type WorkerCommandPayload<C> = Omit<CommandAndPayload<AnyDataCaptureActionMessage, C>, "command" | "id">; type WorkerListener = (event: DataCaptureCallbackMessage) => any; declare enum OverrideState { Auto = "auto", Off = "off", On = "on" } interface DataCaptureLoaderOptions { libraryLocation: string; verifyResponseHash: boolean; loadProgressNotifier?: (info: ProgressInfo) => void; logLevel?: Logger.Level; overrideSimdSupport: OverrideState; overrideThreadsSupport: OverrideState; highEndBlurryRecognition?: boolean; } /** * The DataCaptureLoader class is used by the main thread, it instantiates the worker * and sends commands to it. It represents thus the main communication channel * between the main thread and the engine running in the worker. */ declare class DataCaptureLoader { highEndBlurryRecognition?: boolean; protected overrideThreadsSupport: OverrideState; protected overrideSimdSupport: OverrideState; protected verifyResponseHash: boolean; protected _dataCaptureWorker?: DataCaptureWorker; protected readonly libraryLocation: string; protected workerCommandId: number; protected readonly workerTasks: Map<number, { resolve: (...arguments_: any[]) => any; reject: (...arguments_: any[]) => any; command: string; }>; protected readonly workerListeners: WorkerListener[]; protected workerMessageListener: (event_: MessageEvent<DataCaptureCallbackMessage>) => void; protected constructor(options: DataCaptureLoaderOptions); get dataCaptureWorker(): DataCaptureWorker; protected get name(): string; protected get fixedWasmMemory(): number | null; static create(options: DataCaptureLoaderOptions): Promise<DataCaptureLoader>; load(): Promise<WorkerResponse<"loadLibrary">>; /** * Send a task (i.e. a command) to the worker. Every task sent has a corresponding Promise object which * gets resolved when the worker has processed the request. The tasks are identified by an id which is * sent along with the data by both sides. */ workerCommand<C extends DataCaptureActionMessageKey>(command: C, payload: WorkerCommandPayload<C>, transferables?: Transferable[]): Promise<WorkerResponse<C>>; terminateDataCaptureWorker(disposeContext?: boolean): Promise<void>; addWorkerListener(listener: WorkerListener): void; removeWorkerListener(listener: WorkerListener): void; getOptions(): Pick<DataCaptureLoaderOptions, "libraryLocation" | "overrideSimdSupport" | "overrideThreadsSupport" | "verifyResponseHash">; protected onWorkerMessage(event_: MessageEvent<DataCaptureCallbackMessage>): void; } type Change = { type: "modeEnabled"; newValue: boolean; } | { type: "addControl"; newValue: any; } | { type: "addOverlay"; newValue: any; } | { type: "cameraSettings"; newValue: any; } | { type: "frameSourceState"; newValue: any; } | { type: "removeControl"; newValue: any; } | { type: "removeOverlay"; newValue: any; } | { type: "singleImageModeUploaderSettings"; newValue: any; } | { type: "torchState"; newValue: any; } | { type: "viewChange"; newValue: { orientation: Orientation; } & Partial<HTMLElementStateJSON>; } | { type: "viewSet"; newValue: DataCaptureView$1 | null; }; type PrivateChangeSet = Change[]; interface PrivateDataCaptureMode { type: "barcodeCapture" | "idCapture"; skipSerialization: boolean; _context: Optional<DataCaptureContext$1>; attachedToContext: (context: DataCaptureContext$1) => Promise<void>; detachedFromContext: () => Promise<void>; _synchronousFrameFlow?: boolean; } interface DataCaptureMode extends Serializable { isEnabled(): boolean; setEnabled(enabled: boolean): Promise<void>; context: Optional<DataCaptureContext$1>; } interface DataCaptureModeJSON<S = JSONType> { type: "barcodeCapture" | "barcodeTracking" | "idCapture" | "parser" | "sparkScan" | "barcodeFind"; enabled: boolean; settings: S; } interface PrivateDataCaptureComponent { _context: DataCaptureContext$1; } type DataCaptureComponentJSON = JSONType; interface DataCaptureComponent extends Serializable<DataCaptureComponentJSON> { readonly id: string; } interface PrivateDataCaptureContextOptions { deviceName?: string | null; dataCaptureInstance?: DataCaptureLoader; delayedRegistration?: boolean; } interface PrivateDataCaptureContext<W extends (...parameters: any[]) => unknown = DataCaptureLoader["workerCommand"]> { _frameSource?: FrameSource | null; modes: Set<DataCaptureMode>; components: DataCaptureComponent[]; initialize: () => Promise<void>; update: (changeSet?: PrivateChangeSet) => Promise<void>; addComponent: (component: DataCaptureComponent) => Promise<void>; dataCaptureInstance: DataCaptureLoader; sendFrameToProcessor: (capture: FrameCapture) => Promise<WorkerResponse<"processFrame">>; subscribeToWorkerMessages: (listener: (message: DataCaptureCallbackMessage) => void) => void; unsubscribeToWorkerMessages: (listener: (message: DataCaptureCallbackMessage) => void) => void; hasEnabledMode: () => boolean; workerCommand: MethodSignature<W>; performanceMark: MethodSignature<DataCaptureContext$1["performanceMark"]>; isFeatureSupported: (feature: LicensedFeature) => Promise<boolean>; new (licenseKey: string, options: PrivateDataCaptureContextOptions): DataCaptureContext$1; updateListeners: Set<(change: Change) => void>; } interface DataCaptureContextCreationOptions { deviceName?: string; licenseKey?: string; settings?: DataCaptureContextSettings; } interface RuntimeEnvironment { deviceOS: string; browser: string; browserVersion: string; deviceModelName: string; } interface DataCaptureContextJSON extends RuntimeEnvironment { framework: string; settings: DataCaptureContextSettingsJSON; licenseKey: string; deviceName: string; frameSource: FrameSourceJSON | null; modes: DataCaptureModeJSON[]; components: DataCaptureComponentJSON[]; view: DataCaptureViewJSON | null; } type PrivateFrameHandlerResponse = "continue" | "skip"; type PrivateFrameHandler = (frame: FrameCapture) => Promise<PrivateFrameHandlerResponse>; declare class DataCaptureContext$1 implements Serializable<DataCaptureContextJSON> { static deviceID: string; private readonly framework; private readonly runtimeEnvironment; private settings; private readonly licenseKey; private readonly deviceName; private _frameSource; private _view; private readonly modes; private readonly components; private readonly listeners; private readonly updateListeners; private readonly cameraPropertiesReportListener; private readonly cameraAccessErrorListener; private readonly onWorkerMessageListener; private readonly onVisibilityChangeListener; private readonly dataCaptureInstance; private readonly delayedRegistration; private readonly highEndBlurryRecognition; private readonly _frameHandlers; private constructor(); get frameSource(): FrameSource | null; private get workerCommand(); static create(): Promise<DataCaptureContext$1>; static createWithOptions(options: DataCaptureContextCreationOptions): Promise<DataCaptureContext$1>; /** * Disconnect the current frame source from the context and connect the new one. This process can happen multiple * times for the same frame source because of its initialisation (The mirroring info of a camera is only available * when it has started for example). * Trigger the "didChangeFrameSource" listeners only if the new frame source is different than the old one. */ setFrameSource(frameSource: FrameSource | null): Promise<void>; addListener(listener: DataCaptureContextListener): void; flushAnalytics(): Promise<void>; removeListener(listener: DataCaptureContextListener): void; addMode(mode: DataCaptureMode): Promise<void>; removeMode(mode: DataCaptureMode): Promise<void>; removeAllModes(): Promise<void>; dispose(): Promise<void>; applySettings(settings: DataCaptureContextSettings): Promise<void>; toJSONObject(): DataCaptureContextJSON; private getView; private setView; private getAppName; private urlToHostname; private getParentDomain; private initialize; private subscribeToVisibilityChange; private unsubscribeToVisibilityChange; private requestFrameData; private performanceMark; private sendFrameToProcessor; private sendFrameToHandlers; private sendFrameToSDC; private registerFrameHandler; private unregisterFrameHandler; private onVisibilityChange; private onWorkerMessage; private subscribeToCameraManagerEvents; private reportCameraProperties; private onCameraAccessError; private update; private updateContext; private getViewInfo; private getMirrorAxisForFrameSource; private addComponent; private subscribeToWorkerMessages; private unsubscribeToWorkerMessages; private hasEnabledMode; /** * Some capture modes process frames synchronously, like IdCapture. Other can process multiple frames * in parallel, like MatrixScan. We inform the CameraManager how to process frames. */ private updateCameraFrameFlow; private isFeatureSupported; } /** * MESSAGES (ACTIONS) SENT TO THE WORKER */ type DataCaptureActionMessageKey = "createContext" | "deleteFrameData" | "dispose" | "documentVisibility" | "extractCentaurusLicense" | "flushAnalytics" | "isFeatureSupported" | "loadLibrary" | "onTap" | "processFrame" | "reportCameraProperties" | "requestFrameData" | "setFrameSource" | "setLogLevel" | "updateContext" | "hintPresenterV2update" | "getViewfinderInfo"; interface ExtractCentaurusLicenseResponse { centaurus: { licenseKey: string; }; } interface RequestFrameDataResponse { data: Uint8ClampedArray | null; } interface IsFeatureSupportedResponse { supported: boolean; } interface GetViewfinderInfo { isDisplayingViewfinder: boolean; rect: RectJSON; } type WorkerResponse<C> = C extends "processFrame" ? ProcessFrameParameters : C extends "extractCentaurusLicense" ? ExtractCentaurusLicenseResponse : C extends "requestFrameData" ? RequestFrameDataResponse : C extends "isFeatureSupported" ? IsFeatureSupportedResponse : C extends "getViewfinderInfo" ? GetViewfinderInfo : undefined; interface DataCaptureActionMessage { command: DataCaptureActionMessageKey; id: number; } type LoadLibraryDataCaptureAction = DataCaptureActionMessage & LoadLibraryParameters & { command: "loadLibrary"; }; type CreateContextDataCaptureAction = CreateContextParameters & DataCaptureActionMessage & { command: "createContext"; }; type SetFrameSourceDataCaptureAction = DataCaptureActionMessage & SetFrameSourceParameters & { command: "setFrameSource"; }; type ProcessFrameDataCaptureAction = DataCaptureActionMessage & ProcessFrameParameters & { command: "processFrame"; }; type RequestFrameDataDataCaptureAction = DataCaptureActionMessage & { command: "requestFrameData"; frameId: number; }; type DeleteFrameDataDataCaptureAction = DataCaptureActionMessage & { command: "deleteFrameData"; frameId: number; }; type VisibilityChangeAction = DataCaptureActionMessage & { command: "documentVisibility"; state: DocumentVisibilityState; }; type IsFeatureSupportedAction = DataCaptureActionMessage & { command: "isFeatureSupported"; feature: LicensedFeature; }; type UpdateContextDataCaptureAction = DataCaptureActionMessage & { command: "updateContext"; context: DataCaptureContextJSON; view: UpdateContextParameters["view"]; }; type DisposeDataCaptureAction = DataCaptureActionMessage & { command: "dispose"; }; type FlushAnalyticsDataCaptureAction = DataCaptureActionMessage & { command: "flushAnalytics"; }; type ReportCameraPropertiesDataCaptureAction = DataCaptureActionMessage & ReportCameraPropertiesParameters & { command: "reportCameraProperties"; }; type SetLogLevelDataCaptureAction = DataCaptureActionMessage & { command: "setLogLevel"; level: Logger.Level; }; type ExtractCentaurusLicenseDataCaptureAction = DataCaptureActionMessage & { command: "extractCentaurusLicense"; licenseKey: string; }; type OnTapAction = DataCaptureActionMessage & { command: "onTap"; point: PointJSON; }; type HintPresenterV2updateAction = DataCaptureActionMessage & { command: "hintPresenterV2update"; }; type GetViewfinderInfoAction = DataCaptureActionMessage & { command: "getViewfinderInfo"; }; type AnyDataCaptureActionMessage = CreateContextDataCaptureAction | DeleteFrameDataDataCaptureAction | DisposeDataCaptureAction | ExtractCentaurusLicenseDataCaptureAction | FlushAnalyticsDataCaptureAction | IsFeatureSupportedAction | LoadLibraryDataCaptureAction | OnTapAction | ProcessFrameDataCaptureAction | ReportCameraPropertiesDataCaptureAction | RequestFrameDataDataCaptureAction | SetFrameSourceDataCaptureAction | SetLogLevelDataCaptureAction | UpdateContextDataCaptureAction | VisibilityChangeAction | HintPresenterV2updateAction | GetViewfinderInfoAction; /** * MESSAGES EMITTED BY THE WORKER */ type DataCaptureCallbackMessageKeys = "contextDidChangeStatus" | "didStartObservingContext" | "draw" | "hideHint" | "isFeatureSupported" | "loadLibraryProgress" | "performanceMetricsReport" | "showHint" | "successFeedback" | "updateHint" | "workerTaskId" | "onFrameProcessingStarted" | "onFrameProcessingFinished" | "onFrameSkipped" | "showToast" | "hideToast" | "showGuidance" | "hideGuidance" | "startUpdateTimer" | "stopUpdateTimer" | "setViewfinderRect"; interface BaseDataCaptureCallbackMessage { type: DataCaptureCallbackMessageKeys; } interface LoadLibraryProgressMessage { type: "loadLibraryProgress"; payload: ProgressInfo; } interface ConsoleWorkerMessage { type: "console"; payload: string; } interface WorkerTaskIdWorkerMessage extends BaseDataCaptureCallbackMessage { type: "workerTaskId"; command: string; id: number; error?: unknown; payload?: unknown; } type DrawWorkerMessage = BaseDataCaptureCallbackMessage & { type: "draw"; payload: Uint8Array; }; type DidChangeStatusWorkerMessage = BaseDataCaptureCallbackMessage & { type: "contextDidChangeStatus"; payload: ContextStatusJSON; }; type StartObservingContextWorkerMessage = BaseDataCaptureCallbackMessage & { type: "didStartObservingContext"; }; type SuccessFeedbackWorkerMessage = BaseDataCaptureCallbackMessage & { type: "successFeedback"; }; type ShowHintWorkerMessage = BaseDataCaptureCallbackMessage & { type: "showHint"; payload: { text: string; style: HintStyle; }; }; type UpdateHintWorkerMessage = BaseDataCaptureCallbackMessage & { type: "updateHint"; payload: { style: HintStyle; }; }; type IsFeatureSupportedMessage = BaseDataCaptureCallbackMessage & { type: "isFeatureSupported"; payload: { [key in LicensedFeature]: boolean; }; }; type HideHintWorkerMessage = BaseDataCaptureCallbackMessage & { type: "hideHint"; payload: Record<string, never>; }; type PerformanceMetricsReportMessage = BaseDataCaptureCallbackMessage & { type: "performanceMetricsReport"; payload: PerformanceMetrics; }; type DidTapTrackedBarcode = BaseDataCaptureCallbackMessage & { type: "didTapTrackedBarcode"; payload: any; }; type OnFrameProcessingStartedMessage = BaseDataCaptureCallbackMessage & { type: "onFrameProcessingStarted"; }; type OnFrameProcessingFinishedMessage = BaseDataCaptureCallbackMessage & { type: "onFrameProcessingFinished"; }; type OnFrameSkippedMessage = BaseDataCaptureCallbackMessage & { type: "onFrameSkipped"; }; type ShowToastMessage = BaseDataCaptureCallbackMessage & { type: "showToast"; payload: GenericHint; }; type HideToastMessage = BaseDataCaptureCallbackMessage & { type: "hideToast"; payload: GenericHint; }; type ShowGuidanceMessage = BaseDataCaptureCallbackMessage & { type: "showGuidance"; payload: GenericHint; }; type HideGuidanceMessage = BaseDataCaptureCallbackMessage & { type: "hideGuidance"; payload: GenericHint; }; type StartUpdateTimerMessage = BaseDataCaptureCallbackMessage & { type: "startUpdateTimer"; payload: { duration: { unit: "ms"; value: number; }; }; }; type StopUpdateTimerMessage = BaseDataCaptureCallbackMessage & { type: "stopUpdateTimer"; }; type DataCaptureCallbackMessage = ConsoleWorkerMessage | DidChangeStatusWorkerMessage | DrawWorkerMessage | HideHintWorkerMessage | IsFeatureSupportedMessage | LoadLibraryProgressMessage | PerformanceMetricsReportMessage | ShowHintWorkerMessage | StartObservingContextWorkerMessage | SuccessFeedbackWorkerMessage | UpdateHintWorkerMessage | WorkerTaskIdWorkerMessage | OnFrameProcessingStartedMessage | OnFrameProcessingFinishedMessage | OnFrameSkippedMessage | ShowToastMessage | HideToastMessage | ShowGuidanceMessage | HideGuidanceMessage | StartUpdateTimerMessage | StopUpdateTimerMessage; /** * OTHERS */ type PayloadForCommand<A, C> = A extends { command: C; } ? A : never; interface DataCaptureWorker extends Omit<Worker, "postMessage"> { onmessage: ((this: Worker, event_: MessageEvent & { data: unknown; }) => void) | null; postMessage: <C extends AnyDataCaptureActionMessage["command"]>(message: PayloadForCommand<AnyDataCaptureActionMessage, C>, transfer?: Transferable[]) => void; } interface EmscriptenClassHandle<Self = EmscriptenClassHandle<unknown>> { clone: () => Self; delete: () => void; isDeleted: () => boolean; deleteLater: () => void; isAliasOf: () => Self; } interface DataCaptureContext extends EmscriptenClassHandle { setCameraProperties: (deviceId: string, isFrontFacing: boolean, hasAutofocus: boolean) => void; addListener: (function_: unknown) => void; addFrameListener: (listener: unknown) => void; dispose: () => void; setFrameSource: (source: EmscriptenClassHandle) => void; flushAnalytics: () => void; isFeatureSupported: (feature: LicensedFeature) => boolean; } interface DataCaptureImageBufferFrameSource extends EmscriptenClassHandle { outputFrame: (address: number, width: number, height: number, format: unknown) => void; } interface GestureListener extends EmscriptenClassHandle<GestureListener> { onTap(point: string): void; } interface GestureRecognizer extends EmscriptenClassHandle { setGestureListener(gestureListener: GestureListener, flags: number): void; } interface DataCaptureView extends EmscriptenClassHandle { setViewSize: (w: number, h: number, orientation: Orientation) => void; setNeedsRedrawDelegate: (delegate: unknown) => void; draw: () => void; getDrawCommands: () => Uint8Array; isViewRefreshHandlerSet: boolean; hintPresenterInitialized: () => boolean; setHintPresenter: (hintPresenter: unknown) => void; setHintPresenterV2: (hintPresenterV2: HintPresenterV2) => void; setGestureRecognizer: (recognizer: GestureRecognizer) => void; isDisplayingViewfinder: () => boolean; getViewfinderRect: () => string; addOverlay: (overlay: EmscriptenClassHandle) => void; removeOverlay: (overlay: EmscriptenClassHandle) => void; } interface JSONParseable { toJson: () => string; } interface DataCaptureContextDeserializerResult extends EmscriptenClassHandle { getContext: () => DataCaptureContext; getView: () => DataCaptureView | undefined; } interface DataCaptureContextDeserializer extends EmscriptenClassHandle { contextFromJson: (json: string) => DataCaptureContextDeserializerResult | null; updateContextFromJson: (context: DataCaptureContext, view: DataCaptureView | undefined, json: string) => DataCaptureContextDeserializerResult | null; } interface CaptureModeDeserializerInstance extends EmscriptenClassHandle { setListener: (listener: unknown) => void; } interface ModuleMirrorAxis { None: unknown; X: unknown; Y: unknown; } interface Vector<T = unknown> { push_back: (element: unknown) => void; get: (index: number) => T; size: () => number; } interface WasmFrameData { getFrameData: () => Uint8ClampedArray; getWidth: () => number; getHeight: () => number; getMirrorAxis: () => unknown; getOrientation: () => unknown; } declare enum HintFont { Body = "body", Footnote = "footnote" } declare enum HintTextAlignment { Start = "start", Center = "center", End = "end" } declare enum HintWidth { Normal = "normal", Wider = "wider", FitText = "fitText" } declare enum HintHeight { Normal = "normal", Taller = "taller" } declare enum HintCornerStyle { Square = "square", Rounded = "rounded" } declare enum HintIcon { None = "none", Check = "check", ExclamationMark = "exclamationMark" } declare enum HintAnchor { Top = "top", AboveViewFinder = "aboveViewFinder", BelowViewFinder = "belowViewFinder" } interface HintStyle { textColor: string; textAlignment: HintTextAlignment; backgroundColor: string; hintIcon: HintIcon; isAnimatedToView: boolean; hintAnchor: HintAnchor; hintAnchorOffset: number; horizontalMargin: number; maxWidthFraction: number; textSize: number; textWeight: number; lineHeight: number; iconColor: string; maxLines: number; cornerRadius: number; fitToText: boolean; /** * Will be removed after Id Capture migrates to HintPresenter v2 * @deprecated */ anchor: Anchor; /** * @deprecated */ verticalOffsetRatio: number; /** * @deprecated */ font: HintFont; /** * @deprecated */ hintWidth: HintWidth; /** * @deprecated */ hintHeight: HintHeight; /** * @deprecated */ hintCornerStyle: HintCornerStyle; } declare enum GuidanceHintAnchor { AboveViewFinder = "aboveViewFinder", BelowViewFinder = "belowViewFinder" } declare enum GuidanceHintStyle { BlackOnWhite = "blackOnWhite", WhiteOnBlack = "whiteOnBlack", Transparent = "transparent" } interface GuidanceHint { text: string; guidanceHintStyle: GuidanceHintStyle; guidanceHintAnchor: GuidanceHintAnchor; hintStyle?: HintStyle; moveCloserAnimation?: boolean; } declare enum ToastHintStyle { Success = "success", Error = "error", Warning = "warning", Info = "info", Notification = "notification" } interface ToastHint { text: string; tag: string; toastHintStyle: ToastHintStyle; hintStyle?: HintStyle; } interface GenericHint { text: string; tag?: string; hintStyle: Omit<HintStyle, "anchor" | "verticalOffsetRatio" | "font" | "hintWidth" | "hintHeight" | "hintCornerStyle">; } interface PerformanceMetrics { processedFramesCount: number; redrawRequestsCount: number; actualRedrawsCount: number; frameDataPoolSize: number; } declare enum LicensedFeature { Ocr = 0, HideLogo = 1, ShowTestLicenseMessage = 2, AugmentedReality = 5, ActivityPingStatsAddon = 8, ActivityPing = 9, Registration = 10, Parser = 11, BarcodeCapture = 14, Analytics = 17, AnalyticsBatchMode = 18, AnalyticsScanContent = 19, AnalyticsOnlineVerification = 20, SparkScan = 21, AamvaIdBarcodeVerification = 22, MappingForTracking = 23, BarcodeFind = 24, MandatoryRegistration = 25, FeatureTracking = 26, IdCaptureViz = 27, IdCaptureMrz = 28, IdCaptureBarcode = 29, BarcodeSelectionAimToScan = 30, BarcodeSelectionTapToScan = 31, BarcodeCount = 32, BarcodePick = 33, IdVerificationDataComparison = 34, SmartLabelBarcode = 35, SmartLabelText = 36, VoidedIdDetection = 37, BarcodeArFull = 38 } interface HintPresenterV2 extends EmscriptenClassHandle { showToast: (toastHint: string) => void; hideToast: (tag: string) => void; hideAllToasts: () => void; showGuidance: (guidanceHint: string) => void; hideCurrentGuidance: () => void; update: () => void; } interface PlatformHintPresenter extends EmscriptenClassHandle { setHintPresenter(presenter: HintPresenterV2): void; showToast(toast: string): void; hideToast(toast: string): void; showGuidance(guidanceHint: string): void; hideGuidance(guidanceHint: string): void; startUpdateTimer(intervalMs: number): void; stopUpdateTimer(): void; } interface Module extends EmscriptenModule { callMain: () => void; canvas: OffscreenCanvas | undefined; PThread?: Record<number | string | symbol, unknown>; mainScriptUrlOrBlob: string; DataCaptureContextDeserializer: new (fsFolderPath: string, deviceId: string, deviceModel: string, domain: string, parentDomain: string, modeDeserializer: Vector, delayedRegistration: boolean, highEndBlurryRecognition: boolean, resourcePath: string) => DataCaptureContextDeserializer; DataCaptureContextListener: { extend: (target: "DataCaptureContextListener", parameters: { didChangeStatus: (context: DataCaptureContext, contextStatus: { toJson: () => string; }) => void; didStartObservingContext: (context: DataCaptureContext) => void; }) => new () => EmscriptenClassHandle; }; DataCaptureContextFrameListener: { extend: (target: "DataCaptureContextFrameListener", parameters: { onObservationStarted: (context: DataCaptureContext) => void; onObservationStopped: (context: DataCaptureContext) => void; onFrameProcessingStarted: (context: DataCaptureContext, frameData: WasmFrameData) => void; onFrameProcessingFinished: (context: DataCaptureContext, frameData: WasmFrameData) => void; onFrameSkipped: (context: DataCaptureContext, frameData: WasmFrameData) => void; }) => new () => EmscriptenClassHandle; }; HintPresenter: { extend: (target: "HintPresenter", parameters: { showHint: (hint: string, style: string) => void; updateHint: (style: string) => void; hideHint: () => void; }) => new () => EmscriptenClassHandle; }; PlatformHintPresenter: { extend: (target: "PlatformHintPresenter", parameters: { setHintPresenter(presenter: HintPresenterV2): void; showToast(toastHint: string): void; hideToast(toastHint: string): void; showGuidance(guidanceHint: string): void; hideGuidance(guidanceHint: string): void; startUpdateTimer(intervalMs: number): void; stopUpdateTimer(): void; }) => new () => PlatformHintPresenter; }; HintPresenterV2: new (platformHintPresenter: PlatformHintPresenter) => HintPresenterV2; ImageBufferFrameSource: new (mirroredAxis: unknown, isCameraFrameSource: boolean, orientation?: number) => DataCaptureImageBufferFrameSource; ImageBufferFormat: { Grayscale8: unknown; Rgb888: unknown; Rgba8888: unknown; }; Axis: ModuleMirrorAxis; NeedsRedrawDelegate: { extend: (target: "NeedsRedrawDelegate", parameters: { setNeedsRedrawIn: (inMs: number) => void; }) => new () => EmscriptenClassHandle; }; GestureRecognizer: { extend: (target: "GestureRecognizer", parameters: { setGestureListener(gestureListener: GestureListener, flags: number): void; }) => new () => GestureRecognizer; }; VectorDataCaptureModeDeserializer: new () => Vector; allocateUint8Array: (length: number) => number; deleteUint8Array: (adress: number) => void; DataDecoding: { extend: (target: "DataDecoding", options: { decode: (rawData: ArrayBuffer, encodingRanges: string) => string; }) => new () => EmscriptenClassHandle; }; setDataDecoding: (decoder: unknown) => void; LicenseUtils: { getBlinkIdLicenseKey: (scanditLicense: string) => string; }; Feedback: { extend: (target: "Feedback", parameters: { emit: () => void; }) => new () => EmscriptenClassHandle; }; dispose: () => void; LicenseFeature: LicensedFeature; addBarcodeFindToContext: (context: DataCaptureContext, mode: EmscriptenClassHandle) => void; removeBarcodeFindFromContext: (context: DataCaptureContext, mode: EmscriptenClassHandle) => void; addBarcodeFindBasicOverlayToView: (view: DataCaptureView, overlay: EmscriptenClassHandle) => void; removeBarcodeFindBasicOverlayFromView: (view: DataCaptureView, overlay: EmscriptenClassHandle) => void; } type AugmentedWorker<M extends EmscriptenModule> = Worker & { Module: M; OffscreenCanvas: new (w: number, h: number) => OffscreenCanvas; }; type EngineWorkerResponse<C extends DataCaptureActionMessageKey> = WorkerResponse<C> extends Promise<void> | void ? Promise<void> | void : { payload: WorkerResponse<C>; transferables?: Transferable[]; }; interface ModuleHandler<M extends Module> { get: () => M; set: (v: M) => void; } interface FrameData { readonly width: number; readonly height: number; readonly isFrameSourceMirrored: boolean; toBlob(type?: string, quality?: number): Promise<Blob | null>; getData(): Promise<Uint8ClampedArray | null>; } type PrivateLoadableFrameData = Omit<FrameData, "getData" | "toBlob"> & { frameId: number; }; /** * Adds some function to the passed frame data object to let the user load the frame data. */ declare function convertToPublicFrameData(loadableFrameData: PrivateLoadableFrameData, context: DataCaptureContext$1): FrameData; interface LoadLibraryParameters { libraryLocation: string; locationPath: string; writableDataPathOverride?: string; overrideSimdSupport: OverrideState; overrideThreadsSupport: OverrideState; verifyResponseHash: boolean; onProgress?: (info: ProgressInfo) => void; referredOrigin?: string; fixedWasmMemory: number | null; } interface CreateContextParameters { context: DataCaptureContextJSON; deviceId: string; delayedRegistration: boolean; highEndBlurryRecognition: boolean; appName: string | null; parentDomain: string; } interface UpdateContextParameters { context: DataCaptureContextJSON; view: { width: number; height: number; visible: boolean; orientation: Orientation; } | null; } interface SetFrameSourceParameters { mirrorAxis: PrivateMirrorAxis; isCameraFrameSource: boolean; } type ProcessFrameParameters = FrameCapture; interface ReportCameraPropertiesParameters { deviceId: string; hasAutofocus: boolean; isFrontFacing: boolean; } interface WorkerFunctions { getOffscreenCanvas: () => OffscreenCanvas | undefined; postMessage: (message: DataCaptureCallbackMessage, transfer?: Transferable[]) => void; } /** * Dat