Skip to content
OGE logoOGE

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-scanner

Properties 15

oge-barcode

Name Type DefaultDescription
valuestring (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' | undefinedconfig ?? 'M'QR only: recovers about 7, 15, 25 or 30 % of a damaged symbol; higher levels need a larger symbol.
scalenumber4Pixels per module. The SVG also shrinks to fit its container.
barHeightnumber50Bar height of a linear symbol, in modules.
quietZonebooleantrueThe light margin scanners need: 4 modules round a QR code, 10 beside bars.
showTextbooleantrueThe human-readable line under a linear symbol.
color / backgroundstring'#000000' / '#ffffff'Bar and background colours. Keep them dark on light: scanners need the contrast.
ariaLabelstring | undefinedqrLabel / barcodeLabel messageAccessible name of the symbol (an img).
messagesPartial<OgeBarcodeMessages>—Per-instance overrides of the config catalog.

oge-barcode-scanner

Name Type DefaultDescription
activeboolean (model)falseTwo-way: the camera is open and reading. A camera that cannot open sets it back to false.
decoderOgeBarcodeDecoder | undefinedthe browser’s BarcodeDetectorReading 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.
typesreadonly OgeBarcodeType[]['qr', 'code128', 'ean13']Symbologies the browser’s reader looks for.
intervalnumber250Milliseconds between camera frames read.
facingMode'environment' | 'user''environment'The back camera, or the one facing the user.

Methods 4

Name Type Description
toSvg()() => string | nulloge-barcode: the symbol as a standalone SVG document (for an <img>, a print, an e-mail).
download(fileName?)(fileName?: string) => voidoge-barcode: saves the symbol as an SVG file (default 'barcode.svg').
start() / stop()() => voidoge-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
activeChangebooleanThe banana half of [(active)].
detectedOgeBarcodeResult{ value, format } — format as the Shape Detection API names it (qr_code, code_128, ean_13, …).
statusChangeOgeBarcodeScannerStatus'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? }) => OgeBarcodeSymbolEncodes 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? }) => stringA standalone SVG of a drawing (ogeBarcodeDrawing lays a symbol out) — for servers and workers.
ogeNativeBarcodeDecoder(formats?) => OgeBarcodeDecoder | nullThe 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? }) => OgeQrCodeThe 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? }) => OgeBarcodeDrawingA symbol laid out in module units: one path of merged dark runs, and the text line.
OgeBarcodeScannerCore / OgeBarcodeScannerCoreOptions / OGE_BARCODE_FORMATSclassThe scanner’s framework-free half: camera stream, frame loop, decoder and repeat filter; the Shape Detection API names of the three symbologies.
OgeBarcodeSymbol / OgeBarcodeEncodeOptionstypesWhat ogeEncodeBarcode takes and returns.

Configuration

Properties 2

provideOgeBarcodeConfig()

Name Type Description
messagesOgeBarcodeMessagesEvery 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' | undefinedDefault QR error correction. Pass a function for a live config.

Types 8

Name Type Description
provideOgeBarcodeConfig(config: OgeBarcodeConfigInput | (() => OgeBarcodeConfigInput)) => ProviderApplication- or component-scoped defaults; a function makes the config live.
OGE_BARCODE_CONFIGInjectionToken<OgeBarcodeConfig>The resolved config the barcode and the scanner inject.
OGE_DEFAULT_BARCODE_CONFIGOgeBarcodeConfigThe defaults (from @oge-ui/behavior).
OGE_DEFAULT_BARCODE_MESSAGESOgeBarcodeMessagesThe English catalog.
resolveOgeBarcodeConfig(input?, base?) => OgeBarcodeConfigMerges a partial config over a base (the defaults).
OgeBarcodeConfig{ messages: OgeBarcodeMessages; errorCorrection? }Resolved config shape.
OgeBarcodeConfigInputPartial<OgeBarcodeConfig> with partial messagesWhat the provider accepts.
OgeBarcodeMessages{ qrLabel; barcodeLabel; invalid; scannerLabel; start; stop; scanImage; scanning; unsupported; permission; noCamera; failed; detected; nothingFound }The barcode catalog.