# Braille Interliner

Shows the English word above every braille word, lined up cell by cell, so a sighted
teacher, EA or parent can follow along with a braille reader. Free and open source (MIT).

## What it does
- **English → braille**: type or paste English; it is translated with [liblouis](https://liblouis.io/) to
  UEB grade 1, UEB grade 2, or **only the contractions the student knows** (tick them from all 180 UEB
  contractions, grouped as in the UEB rulebook), and laid out on braille pages (cells per line, lines per page).
- **Braille file → English**: open a `.brf` (Braille Ready Format) file, e.g. saved from Duxbury DBT.
  The original lines and page breaks are kept; the English is back-translated automatically and
  any word can be corrected by hand.
- **On-screen view** for following along on a laptop or tablet (click or arrow keys to mark the place).
- **Printed ink copy** that mirrors the braille page (same lines and cell positions, dots drawn in ink,
  English above, line numbers), scaled to Letter or A4.
- Export the braille alone as a `.brf` file (with the chosen contractions) for an embosser, braille display or transcriber.

Everything runs in the browser. Nothing is uploaded or stored.

## How the alignment works
liblouis reports, for every input character, which output braille cell it became. Each English
word is attached to the braille word its first letter maps to, and drawn starting at that word's
first cell. If a label is wider than the room before the next braille word, it moves up a row
(with a thin leader line), so every word still starts exactly over its braille.

## How "known contractions" works
The text is translated with full UEB grade 2. liblouis's position map shows which input letters became each
braille sign, so every contraction used can be identified. For any the student hasn't learned, the
letters are marked `no_contract` and translated again, trying the smallest change first so other known
contractions in the same word are kept ("reached" without *ea* → r-e-a-ch-ed). Stock liblouis applies
`no_contract` from a letter to the end of the word; `patches/per-char-nocontract.diff` makes it apply
only to rules that touch the marked letters.

## Files
- `index.html` – page, styles and markup
- `app.js` – layout, rendering, keyboard support, import/export
- `contractions.js` – UEB contraction list and the known-contractions translator
- `louis.js` – loads liblouis WebAssembly with a tiny in-memory WASI file system
- `vendor/louis-wasm.js` – liblouis 3.39.0 compiled with wasi-sdk 25 (base64)
- `vendor/louis-tables.js` – UEB tables (`en-ueb-g1.ctb`, `en-ueb-g2.ctb` and includes, `unicode.dis`)
- `vendor/*.woff2` – Atkinson Hyperlegible font

## Rebuilding liblouis
Apply `patches/per-char-nocontract.diff`, then compile `liblouis/*.c` from the v3.39.0 tag with wasi-sdk, a `config.h` containing
`PACKAGE_VERSION "3.39.0"` and `TABLESDIR "/tables"`, `liblouis.h` generated from `liblouis.h.in`
with `widechar` = `unsigned short int`, and:
`clang --target=wasm32-wasip1 -O2 -mexec-model=reactor -Wl,-z,stack-size=4194304 -Wl,--initial-memory=33554432 -Wl,--export=lou_translate,--export=lou_backTranslate,--export=lou_version,--export=lou_free,--export=malloc,--export=free,--export=lou_setLogLevel`

## Accessibility
Built to WCAG 2.2 AA: keyboard-only use (roving focus over words, arrow keys, Enter to edit),
screen-reader names for every word (English plus Unicode braille), labelled controls, visible focus,
44 px targets, light/dark and forced-colours support, no motion. Checked with axe-core (no violations).

## Limits
Back-translation of contracted braille can be ambiguous; check the English. Not a substitute for a
certified braille transcriber.
