import type { Merge } from "type-fest"; import { type ReaderOptions, type ReadResult, type ScanXReaderOptions, type ScanXReadResult, type ScanXVector, type ScanXWriteResult, type ScanXWriterOptions, type WriterOptions } from "./bindings/index.js"; export type ScanXModuleType = "reader" | "writer" | "full"; /** * @internal */ export interface ScanXReaderModule extends EmscriptenModule { readBarcodesFromImage(bufferPtr: number, bufferLength: number, ScanXReaderOptions: ScanXReaderOptions): ScanXVector; readBarcodesFromPixmap(bufferPtr: number, imgWidth: number, imgHeight: number, ScanXReaderOptions: ScanXReaderOptions): ScanXVector; readSingleBarcodeFromPixmap(bufferPtr: number, imgWidth: number, imgHeight: number, ScanXReaderOptions: ScanXReaderOptions): ScanXReadResult; } /** * @internal */ export interface ScanXWriterModule extends EmscriptenModule { writeBarcodeFromText(text: string, ScanXWriterOptions: ScanXWriterOptions): ScanXWriteResult; writeBarcodeFromBytes(bufferPtr: number, bufferLength: number, ScanXWriterOptions: ScanXWriterOptions): ScanXWriteResult; } /** * @internal */ export interface ScanXFullModule extends ScanXReaderModule, ScanXWriterModule { } export type ScanXReaderModuleFactory = EmscriptenModuleFactory; export type ScanXWriterModuleFactory = EmscriptenModuleFactory; export type ScanXFullModuleFactory = EmscriptenModuleFactory; interface TypeModuleMap { reader: [ScanXReaderModule, ScanXReaderModuleFactory]; writer: [ScanXWriterModule, ScanXWriterModuleFactory]; full: [ScanXFullModule, ScanXFullModuleFactory]; } export type ScanXModule = TypeModuleMap[T][0]; export type ScanXModuleFactory = TypeModuleMap[T][1]; export type ScanXModuleOverrides = Partial; export declare const SCANX_WASM_VERSION: string; export declare const SCANX_CPP_COMMIT: string; export type CDNHost = string | undefined | null; export interface PrepareScanXModuleOptions { /** * The Emscripten module overrides to be passed to the factory function. * The `locateFile` function is overridden by default to load the WASM file from the jsDelivr CDN. */ overrides?: ScanXModuleOverrides; /** * Custom CDN host URL to load WASM files from. * If provided, this will override the default jsDelivr CDN URL. * @example "https://my-custom-cdn.com/scanx-wasm" */ cdnHost?: CDNHost; /** * A function to compare the cached overrides with the input overrides. * So that the module promise can be reused if the overrides are the same. * Defaults to a shallow equality function. */ equalityFn?: (cachedOverrides: ScanXModuleOverrides, overrides: ScanXModuleOverrides) => boolean; /** * Whether to instantiate the module immediately. * If `true`, the module is eagerly instantiated and a promise of the module is returned. * If `false`, only the overrides are updated and module instantiation is deferred * to the first read/write operation. * * @default false */ fireImmediately?: boolean; } /** * Performs a shallow equality comparison between two objects. * * @param a - First object to compare * @param b - Second object to compare * @returns `true` if objects are shallowly equal, `false` otherwise * * @remarks * Objects are considered shallowly equal if: * - They are the same reference (using Object.is) * - They have the same number of keys * - All keys in `a` exist in `b` with strictly equal values (===) * * Note: This comparison only checks the first level of properties. * Nested objects or arrays are compared by reference, not by value. * * @example * ```ts * shallow({ a: 1, b: 2 }, { a: 1, b: 2 }) // returns true * shallow({ a: 1 }, { a: 1, b: 2 }) // returns false * shallow({ a: {x: 1} }, { a: {x: 1} }) // returns false (different object references) * ``` */ export declare function shallow>(a: T, b: T): boolean; export declare function prepareScanXModuleWithFactory(ScanXModuleFactory: ScanXModuleFactory, options?: Merge): void; export declare function prepareScanXModuleWithFactory(ScanXModuleFactory: ScanXModuleFactory, options: Merge): Promise>; export declare function prepareScanXModuleWithFactory(ScanXModuleFactory: ScanXModuleFactory, options?: PrepareScanXModuleOptions): void | Promise>; /** * Removes a ScanX module instance from the internal cache. * * @param ScanXModuleFactory - The factory function used to create the ScanX module instance * * @remarks * This function is used to clean up cached ScanX module instances when they are no longer needed. */ export declare function purgeScanXModuleWithFactory(ScanXModuleFactory: ScanXModuleFactory): void; /** * Reads barcodes from an image using a ScanX module factory. * * @param ScanXModuleFactory - Factory function to create a ScanX module instance * @param input - Source image data as a Blob, ArrayBuffer, Uint8Array, or ImageData * @param readerOptions - Optional configuration options for barcode reading (defaults to defaultReaderOptions) * @returns An array of ReadResult objects containing decoded barcode information * * @remarks * The function manages memory allocation and deallocation for the ScanX module * and properly cleans up resources after processing. */ export declare function readBarcodesWithFactory(ScanXModuleFactory: ScanXModuleFactory, input: Blob | ArrayBuffer | Uint8Array | ImageData, readerOptions?: ReaderOptions, cdnHost?: CDNHost): Promise; /** * Reads a single barcode from an image using a ScanX module factory. * * @param ScanXModuleFactory - Factory function to create a ScanX module instance * @param input - Source image data as a Blob, ArrayBuffer, Uint8Array, or ImageData * @param readerOptions - Optional configuration options for barcode reading (defaults to defaultReaderOptions) * @returns A single ReadResult object containing decoded barcode information or null if no barcode is found * * @remarks * This function is optimized to detect a single barcode and return immediately upon detection. * It's more efficient than readBarcodesWithFactory when only one barcode is expected. */ export declare function readSingleBarcodeWithFactory(ScanXModuleFactory: ScanXModuleFactory, input: Blob | ArrayBuffer | Uint8Array | ImageData, readerOptions?: Omit, cdnHost?: CDNHost): Promise; /** * Generates a barcode image using a ScanX module factory with support for text and binary input. * * @param ScanXModuleFactory - The factory function that creates a ScanX module instance * @param input - The data to encode in the barcode, either as a string or Uint8Array * @param writerOptions - Optional configuration options for barcode generation * @returns A promise that resolves to the barcode write result * * @remarks * The function handles memory management automatically when processing binary input, * ensuring proper allocation and deallocation of memory in the ScanX module. */ export declare function writeBarcodeWithFactory(ScanXModuleFactory: ScanXModuleFactory, input: string | Uint8Array, writerOptions?: WriterOptions, cdnHost?: CDNHost): Promise<{ image: Blob | null; svg: string; utf8: string; error: string; symbol: import("./bindings/barcodeSymbol.js").BarcodeSymbol; }>; export {};