MIT · clean-room · Rust → WASM · WebGPU

@webreflection/barcode

A barcode and QR scanner that reads 17 symbologies from a camera or a still image, and a renderer that produces a fresh, standards-compliant SVG for every one of them. One import, one session, one worker. Everything runs on the device.

Live demos

Each card is a real page using the shipped public API — no mock-ups.

One import, three entries

importcontextdefault
@webreflection/barcodeautopage → barcode(); worker → bootstrap promise
@webreflection/barcode/mainpagebarcode(options)
@webreflection/barcode/workerworkerbootstrap promise
@webreflection/barcode/csspageoptional default scan UI
import barcode from '@webreflection/barcode';
import '@webreflection/barcode/css';

const { scan, render } = barcode();     // one session, one worker

const code = await scan();              // default UI: camera + torch + ✕
if (code) {
  console.log(code.symbology, code.text);
  document.body.append(await render(code));
}

What it reads

2D

qrcode (v1–40, all EC levels and masks, ECI, rotation/perspective), microqr, datamatrix (square and rectangular), aztec, pdf417.

1D

ean13 / upca, ean8, upce, code39, code93, code128 / GS1-128, itf, codabar, GS1 DataBar (Omni, Limited, Stacked, Stacked Omni).

Inverted (white-on-black) codes work on both paths. A code filling a dark scene and a white-on-black code on a light page are handled by the same polarity pass.

The API in one screen

scan(options)

One complete scan. Resolves once with the best Code (most centered first) or undefined for a graceful stop. Modes: { into }, { video, signal } or { image }.

await scan();                    // built-in UI
await scan({ into: '#modal' });  // mount it yourself
await scan({ video, signal });   // your <video>
await scan({ image });           // still: canvas | bitmap |
                                 // image | SVG | Blob/File

render(result, opts)

Re-encodes the payload as a fresh SVG (class barcode-svg). Options: module, height, QR ec/mask/version, PDF417 level/columns, Data Matrix rows/cols.

await render(code);
await render(code, { ec: 'H', version: 7 });
await render(code, { rows: 12, cols: 36 });

Private by construction

The camera stream, still images and decoded payloads never leave the device. There is no analytics, no upload endpoint and no network call after the static files are fetched.

Run it locally

npm install
npm run build          # → packages/web/dist
npm run build:demo     # → packages/web/demo-dist
npm run serve:demo     # http://<lan-ip>:8124

# phone over USB, no HTTPS needed
adb reverse tcp:5173 tcp:5173
npm run dev            # http://localhost:5173/scan.html

A real iPhone needs a secure origin: npm run serve:iphone serves the built demo over LAN HTTPS with mkcert and prints the one-time CA trust steps.