/** * LombokQRCode — QR Code constant tables * * All values below are numeric parameters defined by the public * ISO/IEC 18004 QR Code standard (capacities, alignment-pattern * positions, error-correction block layout, generator polynomial * degrees). These are specification data, not another project's * source code — this file is an independent, clean-room encoding * of the standard. */ type ErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H'; interface QREncodeOptions { errorCorrectionLevel?: ErrorCorrectionLevel; minVersion?: number; maxVersion?: number; } interface QRCodeResult { version: number; errorCorrectionLevel: ErrorCorrectionLevel; size: number; modules: boolean[][]; } /** * Encodes `text` into a QR Code symbol. Automatically picks the smallest * version that fits at the requested error-correction level (default 'M'), * and the mask pattern with the lowest ISO/IEC 18004 penalty score. */ declare function encodeQR(text: string, options?: QREncodeOptions): QRCodeResult; type Mode = 'numeric' | 'alphanumeric' | 'byte'; interface Segment { mode: Mode; text: string; } /** * Splits the input string into segments of consecutive characters sharing * the same best mode, then merges adjacent segments when doing so is cheaper * (avoids mode-switch overhead for short runs). This is a greedy approach * that works well in practice — the switching overhead (4-bit mode indicator + * char-count field) means very short segments are better merged into * the neighboring, less-compact mode. * * Thresholds are derived from the bit math: * - Numeric run < 4 chars inside alphanumeric: merge (saves ~13 header bits, * costs at most 12 data bits via alphanumeric encoding) * - Numeric run < 6 chars inside byte: merge * - Alphanumeric run < 11 chars inside byte for versions 1-9: merge * (header savings outweigh data cost at these short lengths) */ declare function splitSegments(text: string, version: number): Segment[]; interface Code128Result { /** Symbol values in order, including start/stop and checksum. */ symbols: number[]; /** Bar/space widths (in modules) for the full barcode, alternating bar/space starting with a bar. */ widths: number[]; } /** * Encodes `text` (Latin-1 range, code points 0-127 for subsets A/B) as Code 128, * automatically switching between subset C (paired digits, most compact for * numeric runs) and subset B (general ASCII) as needed. */ declare function encodeCode128(text: string): Code128Result; type DotStyle = 'square' | 'rounded' | 'dots' | 'classy'; type CornerStyle = 'square' | 'rounded' | 'dot'; interface LogoOptions { /** Data URL or external href for the logo image. */ href: string; /** Fraction of the QR's width the logo should occupy (0-0.35 recommended). */ sizeRatio?: number; /** Adds a solid background behind the logo so surrounding modules stay legible. */ backgroundInset?: boolean; } interface QRTemplate { dotStyle?: DotStyle; cornerStyle?: CornerStyle; /** Solid color, or a CSS gradient spec handled via `gradient`. */ foreground?: string; background?: string; /** Linear/radial gradient for the dark modules. */ gradient?: { type: 'linear' | 'radial'; colors: [string, string]; angle?: number; }; logo?: LogoOptions; /** Quiet-zone width in modules (spec recommends >= 4). */ margin?: number; /** Pixels per module in the output viewBox. */ moduleSize?: number; } declare function listTemplates(): string[]; interface RenderOptions extends QREncodeOptions { template?: QRTemplate | string; } /** Renders `text` as a fully self-contained SVG string. */ declare function renderQRToSVG(text: string, options?: RenderOptions): string; declare function matrixToSVG(result: QRCodeResult, template?: QRTemplate | string): string; interface BarcodeRenderOptions { moduleWidth?: number; height?: number; quietModules?: number; foreground?: string; background?: string; /** Print the human-readable text under the bars. */ showText?: boolean; fontFamily?: string; } declare function renderCode128ToSVG(text: string, options?: BarcodeRenderOptions): string; /** * LombokQRCode — Canvas/PNG renderer * * Pure-JS PNG encoder. No native canvas, no external dependencies. * Works in Node.js and browsers alike. * * Produces a Uint8Array containing a valid PNG file from a QRCodeResult, * using the same template system as the SVG renderer. */ interface CanvasRenderOptions extends QREncodeOptions { /** Pixels per module. Default: 10. */ scale?: number; /** Quiet-zone width in modules. Default: 4. */ margin?: number; /** Foreground color as [R, G, B] or [R, G, B, A]. Default: [0, 0, 0]. */ foreground?: number[]; /** Background color as [R, G, B] or [R, G, B, A]. Default: [255, 255, 255]. */ background?: number[]; } declare function parseHexColor(hex: string): [number, number, number, number]; /** * Renders `text` as a QR code and returns raw RGBA pixel data. * * @returns `{ pixels, width, height }` where `pixels` is a Uint8Array of * length width × height × 4 (RGBA). */ declare function renderQRToPixels(text: string, options?: CanvasRenderOptions): { pixels: Uint8Array; width: number; height: number; }; /** * Converts an already-encoded QRCodeResult to raw RGBA pixel data. */ declare function matrixToPixels(result: QRCodeResult, options?: CanvasRenderOptions): { pixels: Uint8Array; width: number; height: number; }; /** * Renders `text` as a QR code and returns a PNG file as a Uint8Array. * The returned buffer can be written directly to a .png file or served * as `image/png`. */ declare function renderQRToPNG(text: string, options?: CanvasRenderOptions): Uint8Array; /** * Converts an already-encoded QRCodeResult to a PNG file as a Uint8Array. */ declare function matrixToPNG(result: QRCodeResult, options?: CanvasRenderOptions): Uint8Array; type LocaleCode = 'en' | 'id' | 'es' | 'fr' | 'de' | 'pt' | 'ja' | 'zh' | 'ar' | 'ru' | 'hi'; interface MessageCatalog { errorTooLong: string; errorUnsupportedChar: string; errorEmptyInput: string; scanPromptCamera: string; scanPromptNoCamera: string; scanPromptDenied: string; labelCopy: string; labelDownload: string; labelScanQR: string; labelScanBarcode: string; } declare function getMessages(locale?: LocaleCode): MessageCatalog; declare function availableLocales(): LocaleCode[]; /** * Browser-only camera capture and scanning helper. * * Scope note: this module wires up camera access and, where the browser * exposes the native `BarcodeDetector` API (Chrome/Edge/Android WebView, * and Safari 17+ for some symbologies), uses it to decode QR/barcodes * from live video. A fully from-scratch camera decoder (finder-pattern * detection, perspective correction, bit sampling) is tracked as a * roadmap item — see docs/ARCHITECTURE.md — rather than shipped * half-verified. Where `BarcodeDetector` is unavailable, `scan()` * rejects with a clear, catchable error so callers can show a message * or offer manual entry instead of failing silently. */ interface ScanResult { rawValue: string; format: string; cornerPoints?: Array<{ x: number; y: number; }>; } interface ScannerOptions { formats?: string[]; facingMode?: 'environment' | 'user'; } declare class LombokScanner { private stream; private video; private detector; private rafHandle; static isSupported(): boolean; start(videoEl: HTMLVideoElement, options?: ScannerOptions): Promise; /** Scans the current video frame once. Call repeatedly (e.g. via requestAnimationFrame) for continuous scanning. */ scanOnce(): Promise; /** Continuously scans until a result is found or stop() is called. */ watch(onResult: (results: ScanResult[]) => void, onError?: (err: unknown) => void): void; stop(): void; } export { type BarcodeRenderOptions, type CanvasRenderOptions, type Code128Result, type CornerStyle, type DotStyle, type ErrorCorrectionLevel, type LocaleCode, type LogoOptions, LombokScanner, type MessageCatalog, type QRCodeResult, type QREncodeOptions, type QRTemplate, type RenderOptions, type ScanResult, type ScannerOptions, type Segment, availableLocales, encodeCode128, encodeQR, getMessages, listTemplates, matrixToPNG, matrixToPixels, matrixToSVG, parseHexColor, renderCode128ToSVG, renderQRToPNG, renderQRToPixels, renderQRToSVG, splitSegments };