diff --git a/.gitignore b/.gitignore index 23bde5d..517c4d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules/ dist/ +dist-embed/ .env .env.* *.local diff --git a/CREDITS.md b/CREDITS.md new file mode 100644 index 0000000..bad5307 --- /dev/null +++ b/CREDITS.md @@ -0,0 +1,37 @@ +# Credits & Licenses + +ReaderJS is MIT-licensed and **permissive-core**: every engine bundled into the +runtime (the app *and* the embeddable build) uses a permissive license +(MIT / BSD / Apache-2.0 / 0BSD / public-domain). There are **no GPL/AGPL/LGPL +dependencies** in anything that ships. + +## Runtime engines + +| Library | License | Used for | +|---------|---------|----------| +| [pdf.js](https://github.com/mozilla/pdf.js) (`pdfjs-dist`) | Apache-2.0 | PDF rendering | +| [DejaView](https://github.com/Alpaq92/dejaview) | MIT | DjVu decoding/rendering (Web Worker) | +| [mammoth.js](https://github.com/mwilliamson/mammoth.js) | BSD-2-Clause | DOCX → HTML | +| [JSDoc](https://github.com/Alpaq92/JSDoc) | 0BSD | Legacy `.doc` (binary Word) | +| [RTF.js](https://github.com/tbluemel/rtf.js) | MIT | RTF (with EMFJS/WMFJS) | +| [jQuery](https://github.com/jquery/jquery) | MIT | DOM utility required by RTF.js | +| [PptxViewJS](https://github.com/gptsci/pptxviewjs) | **MIT** | PPTX slide rendering | +| [Chart.js](https://github.com/chartjs/Chart.js) | MIT | charts inside PPTX (PptxViewJS dep) | +| [SheetJS](https://sheetjs.com/) (`xlsx`) | Apache-2.0 | XLSX/XLS spreadsheets | +| [Papa Parse](https://www.papaparse.com/) | MIT | CSV/TSV | +| [highlight.js](https://highlightjs.org/) | BSD-3-Clause | source-code highlighting | +| [marked](https://github.com/markedjs/marked) | MIT | Markdown | +| [JSZip](https://github.com/Stuk/jszip) | MIT (dual MIT/GPLv3 — MIT taken) | ODF/CBZ ZIP containers | +| [libarchive.js](https://github.com/nika-begiashvili/libarchivejs) | MIT (bundled libarchive = BSD) | CBR/CBT (RAR/TAR) via WASM | +| [foliate-js](https://github.com/johnfactotum/foliate-js) | MIT | EPUB/MOBI/AZW3/FB2 | +| [UTIF.js](https://github.com/photopea/UTIF.js) | MIT | TIFF images | +| [exifr](https://github.com/MikeKovarik/exifr) | MIT | EXIF/GPS metadata | +| [Vite](https://github.com/vitejs/vite) | MIT | build tooling | +| [Material Design Icons](https://pictogrammers.com/library/mdi/) | Apache-2.0 | UI icons | + +## Not shipped + +- **WebODF** is present as a git submodule (reference only) and is **AGPL-3.0**. + It is **never imported or bundled** — ODF files are handled by `odf-renderer.js` + using JSZip + the browser's `DOMParser`, not WebODF. It does not appear in any + build output (`dist/` or `dist-embed/`). diff --git a/EMBEDDING.md b/EMBEDDING.md new file mode 100644 index 0000000..c6b8be5 --- /dev/null +++ b/EMBEDDING.md @@ -0,0 +1,120 @@ +# Embedding ReaderJS + +ReaderJS can be embedded into another app as a **read-only**, **self-contained**, +**same-origin** document viewer. It accepts document **bytes + a filename** (the +filename's extension selects the renderer) — no file picker, no uploads, no +external network requests. The viewer runs inside an **iframe** so its full-page +CSS, JS globals, and CSP surface stay isolated from the host page. + +## Build the artifact + +```bash +npm install +npm run build:embed # → dist-embed/ +``` + +Vendor the whole `dist-embed/` folder somewhere **same-origin** on your site, +e.g. `frontend/static/readerjs/`. It is self-contained: + +``` +dist-embed/ + readerjs.js # the loader — exposes window.ReaderJS.mount() + reader.html # the viewer page (loaded inside the iframe) + assets/ # lazy per-format chunks + workers (pdf.worker, dejaview) + rtfjs/ # RTF.js vendored scripts (RTF) + libarchive/ # worker-bundle.js + libarchive.wasm (CBR/CBT) + jsdoc/ # docToText.js (legacy .doc) +``` + +All asset URLs are **relative to `reader.html`**, so the folder works from any +path you mount it at. + +## Usage + +### Option A — JS API (`mount`) + +Load the loader, then hand ReaderJS the bytes you already have (e.g. from a +same-origin, cookie-authed `/raw` endpoint): + +```html + +
+ +``` + +The container must have a height (the iframe fills `100%`). + +### Option B — iframe with `?src` (zero JS) + +Let the iframe fetch the document itself (same-origin, sends cookies): + +```html + +``` + +Pass `name` whenever the URL has no usable extension (e.g. `/raw/123`). + +## `ReaderJS.mount(container, opts) → instance` + +| `opts` field | | | +|---|---|---| +| `blob` / `arrayBuffer` | bytes mode | the document bytes | +| `src` | url mode | same-origin URL the iframe fetches itself | +| `name` | required | filename whose extension selects the renderer | +| `mime` | optional | passed through (dispatch is by extension) | + +`instance`: `{ load(blobOrBuffer, name, mime?), setLang(code), destroy(), iframe }`. + +Bytes are sent to the iframe as a **structured-clone copy** (your `ArrayBuffer` +is not neutered). The host↔iframe handshake is origin-checked and same-origin only. + +## Content-Security-Policy + +Everything is same-origin under the vendored folder. The viewer loads: + +- `assets/*.js` — lazy per-format engine chunks, incl. `pdf.worker.min.mjs` and the dejaview worker +- `rtfjs/*.js` — RTF.js (RTF documents) +- `libarchive/worker-bundle.js` + `libarchive/libarchive.wasm` — CBR/CBT +- `jsdoc/docToText.js` — legacy `.doc` + +Recommended directives for the page hosting the iframe (tighten origins to your host): + +``` +frame-src 'self'; +script-src 'self' 'wasm-unsafe-eval'; # WASM = libarchive (CBR/CBT); no eval otherwise +worker-src 'self' blob:; +connect-src 'self'; # asset fetches + ?src document fetch +img-src 'self' blob: data:; # renderers use object/data URLs +style-src 'self' 'unsafe-inline'; # highlight.js injects its theme as