Barcode API
Full surface of oge-barcode and oge-barcode-scanner: their inputs, methods and outputs, the encoders and the config provider.
Properties Methods Events Types
OgeBarcode & OgeBarcodeScanner
oge-barcode, oge-barcode-scannerProperties 15
oge-barcode
| Name | Type | Default | Description |
|---|---|---|---|
value | string (required) | — | What the symbol encodes. |
type | 'qr' | 'code128' | 'ean13' | 'qr' | 'qr' (numeric, alphanumeric or UTF-8 byte mode, versions 1–40, the smallest that fits, the lowest-penalty mask), 'code128' (printable ASCII; set C packs runs of digits two to a symbol) or 'ean13' (12 digits — the check digit is added — or 13, verified). A value the symbology cannot hold shows the invalid message instead of a symbol. |
errorCorrection | 'L' | 'M' | 'Q' | 'H' | undefined | config ?? 'M' | QR only: recovers about 7, 15, 25 or 30 % of a damaged symbol; higher levels need a larger symbol. |
scale | number | 4 | Pixels per module. The SVG also shrinks to fit its container. |
barHeight | number | 50 | Bar height of a linear symbol, in modules. |
quietZone | boolean | true | The light margin scanners need: 4 modules round a QR code, 10 beside bars. |
showText | boolean | true | The human-readable line under a linear symbol. |
color / background | string | '#000000' / '#ffffff' | Bar and background colours. Keep them dark on light: scanners need the contrast. |
ariaLabel | string | undefined | qrLabel / barcodeLabel message | Accessible name of the symbol (an img). |
messages | Partial<OgeBarcodeMessages> | — | Per-instance overrides of the config catalog. |
oge-barcode-scanner
| Name | Type | Default | Description |
|---|---|---|---|
active | boolean (model) | false | Two-way: the camera is open and reading. A camera that cannot open sets it back to false. |
decoder | OgeBarcodeDecoder | undefined | the browser’s BarcodeDetector | Reading uses the browser’s own BarcodeDetector (the Shape Detection API: Chrome and Edge on Android, macOS and ChromeOS, Safari 17+). Elsewhere — Firefox, desktop Chrome on Windows and Linux — pass a decoder (a ZXing build, a server call); without one the scanner says it cannot read. A value read again within 1.5 s counts once. |
types | readonly OgeBarcodeType[] | ['qr', 'code128', 'ean13'] | Symbologies the browser’s reader looks for. |
interval | number | 250 | Milliseconds between camera frames read. |
facingMode | 'environment' | 'user' | 'environment' | The back camera, or the one facing the user. |
Methods 4
| Name | Type | Description |
|---|---|---|
toSvg() | () => string | null | oge-barcode: the symbol as a standalone SVG document (for an <img>, a print, an e-mail). |
download(fileName?) | (fileName?: string) => void | oge-barcode: saves the symbol as an SVG file (default 'barcode.svg'). |
start() / stop() | () => void | oge-barcode-scanner: opens or closes the camera. |
scanImage(image) | (image: Blob) => Promise<readonly OgeBarcodeResult[]> | oge-barcode-scanner: reads a picked or pasted image; every barcode found is also emitted. |
Events 3
| Name | Type | Description |
|---|---|---|
activeChange | boolean | The banana half of [(active)]. |
detected | OgeBarcodeResult | { value, format } — format as the Shape Detection API names it (qr_code, code_128, ean_13, …). |
statusChange | OgeBarcodeScannerStatus | 'idle', 'starting', 'scanning', 'unsupported', 'permission' (access refused), 'no-camera' or 'failed'; a polite status line says the same. |
Types 13
Vocabulary
| Name | Type | Description |
|---|---|---|
OgeBarcodeType | 'qr' | 'code128' | 'ean13' | The symbologies drawn. |
OgeQrErrorCorrection | 'L' | 'M' | 'Q' | 'H' | QR error-correction level. |
OgeBarcodeResult | { value: string; format: string } | One barcode read. |
OgeBarcodeDecoder | (source: ImageBitmapSource) => Promise<readonly OgeBarcodeResult[]> | What the scanner reads frames and images with. |
OgeBarcodeScannerStatus | 'idle' | 'starting' | 'scanning' | 'unsupported' | 'permission' | 'no-camera' | 'failed' | Where the scanner stands. |
Functions (@oge-ui/behavior, re-exported)
| Name | Type | Description |
|---|---|---|
ogeEncodeBarcode | (value, type, { errorCorrection? }) => OgeBarcodeSymbol | Encodes without drawing: a module matrix or a row of bars. Throws RangeError for a value that does not fit. |
ogeBarcodeSvg | (drawing, { scale?, color?, background?, label? }) => string | A standalone SVG of a drawing (ogeBarcodeDrawing lays a symbol out) — for servers and workers. |
ogeNativeBarcodeDecoder | (formats?) => OgeBarcodeDecoder | null | The browser’s BarcodeDetector as a decoder, or null where there is none. |
Behavior building blocks (@oge-ui/behavior)
| Name | Type | Description |
|---|---|---|
ogeEncodeQr / OgeQrCode / OgeQrOptions | (text, { errorCorrection?, minVersion?, mask? }) => OgeQrCode | The QR encoder: { version, size, errorCorrection, mask, mode, modules }; minVersion keeps a series of codes one size. |
ogeEncodeCode128 / ogeEncodeEan13 / ogeEan13CheckDigit / OgeLinearBarcode | (text) => { modules, text } | The linear encoders and the EAN-13 check digit. |
ogeBarcodeDrawing / OgeBarcodeDrawing / OgeBarcodeDrawingOptions / OGE_BARCODE_TEXT_HEIGHT | (symbol, { quietZone?, barHeight?, showText? }) => OgeBarcodeDrawing | A symbol laid out in module units: one path of merged dark runs, and the text line. |
OgeBarcodeScannerCore / OgeBarcodeScannerCoreOptions / OGE_BARCODE_FORMATS | class | The scanner’s framework-free half: camera stream, frame loop, decoder and repeat filter; the Shape Detection API names of the three symbologies. |
OgeBarcodeSymbol / OgeBarcodeEncodeOptions | types | What ogeEncodeBarcode takes and returns. |
Configuration
Properties 2
provideOgeBarcodeConfig()
| Name | Type | Description |
|---|---|---|
messages | OgeBarcodeMessages | Every user-facing string: qrLabel / barcodeLabel ({value}, the symbol’s accessible name), invalid ({type}), scannerLabel, start, stop, scanImage, scanning, unsupported, permission, noCamera, failed, detected ({value}) and nothingFound. Translated in every @oge-ui/locales pack (layout.barcode). |
errorCorrection | 'L' | 'M' | 'Q' | 'H' | undefined | Default QR error correction. Pass a function for a live config. |
Types 8
| Name | Type | Description |
|---|---|---|
provideOgeBarcodeConfig | (config: OgeBarcodeConfigInput | (() => OgeBarcodeConfigInput)) => Provider | Application- or component-scoped defaults; a function makes the config live. |
OGE_BARCODE_CONFIG | InjectionToken<OgeBarcodeConfig> | The resolved config the barcode and the scanner inject. |
OGE_DEFAULT_BARCODE_CONFIG | OgeBarcodeConfig | The defaults (from @oge-ui/behavior). |
OGE_DEFAULT_BARCODE_MESSAGES | OgeBarcodeMessages | The English catalog. |
resolveOgeBarcodeConfig | (input?, base?) => OgeBarcodeConfig | Merges a partial config over a base (the defaults). |
OgeBarcodeConfig | { messages: OgeBarcodeMessages; errorCorrection? } | Resolved config shape. |
OgeBarcodeConfigInput | Partial<OgeBarcodeConfig> with partial messages | What the provider accepts. |
OgeBarcodeMessages | { qrLabel; barcodeLabel; invalid; scannerLabel; start; stop; scanImage; scanning; unsupported; permission; noCamera; failed; detected; nothingFound } | The barcode catalog. |