From 464313258216510f71f2d2136f0f1ccc67950ea4 Mon Sep 17 00:00:00 2001 From: Alpaq92 Date: Mon, 29 Jun 2026 18:06:58 +0200 Subject: [PATCH] feat: add CHM (.chm) support via CHMate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Render Microsoft Compiled HTML Help files. CHMate (pure-JS, MIT) parses the ITSF container and LZX-decompresses topics; its hardened renderTopic sanitizes each topic, inlines resources as blob: URLs and adds a strict CSP. The new CHMRenderer shows topics in a sandboxed iframe (no allow-scripts), wires internal (data-chm-href) and external (confirm + new tab) link navigation, and builds the .hhc table of contents into the sidebar. - New src/renderers/chm-renderer.js; wired into EXT_MAP + RENDERER_LOADERS, dropzone pill + toolbar badge (#006064), file-picker accept list - chmate pinned as a git dep; `chmate/render` exposed via a Vite resolve alias (CHMate's package exports only "."), inherited by the embed-app build - README / CREDITS / EMBEDDING updated (chmate is the 3rd git-dep engine) - Also: re-fit the page when the viewer area resizes — a ResizeObserver on #viewerContainer re-applies the fit-to-width/height/page scale, so opening the sidebar (or resizing the window) no longer leaves the page clipped at its old scale. Benefits every renderer, not just CHM. - /simplify applied: merged duplicate MHTML/CHM iframe CSS, dropped a dead field + an inert TOC wrapper div, replaced a parallel Map with data-target. Co-Authored-By: Claude Opus 4.8 --- CREDITS.md | 1 + EMBEDDING.md | 2 +- README.md | 11 ++- index.html | 3 +- package-lock.json | 13 +++ package.json | 1 + src/main.js | 15 ++++ src/renderers/chm-renderer.js | 161 ++++++++++++++++++++++++++++++++++ src/style.css | 16 +++- vite.config.js | 10 +++ 10 files changed, 224 insertions(+), 9 deletions(-) create mode 100644 src/renderers/chm-renderer.js diff --git a/CREDITS.md b/CREDITS.md index e101719..140b8e5 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -26,6 +26,7 @@ dependencies** in anything that ships. | [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 | | [mhtml-to-html](https://github.com/gildas-lormeau/mhtml-to-html) | MIT | MHTML/`.mht` web archives → HTML | +| [CHMate](https://github.com/Alpaq92/CHMate) | MIT | CHM (`.chm`) reading + rendering — pure-JS ITSF container + LZX, no WASM | | [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 | diff --git a/EMBEDDING.md b/EMBEDDING.md index e91fdc3..33833f2 100644 --- a/EMBEDDING.md +++ b/EMBEDDING.md @@ -148,5 +148,5 @@ theme + inline `style` attributes). No `'unsafe-eval'` is required. - **Formats:** PDF, DjVu, ODF (ODT/ODS/ODP/ODG), RTF, DOC, DOCX, PPTX, XLSX/XLS, CSV/TSV, Markdown, source code, images (+TIFF/EXIF), comic archives (CBZ/CBR/CBT), e-books (EPUB/MOBI/AZW3/FB2), - web archives (MHTML), plain text. + web archives (MHTML), Compiled HTML Help (CHM), plain text. - See [CREDITS.md](CREDITS.md) — every bundled engine is permissively licensed. diff --git a/README.md b/README.md index 3c36079..c7f3cb1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ReaderJS — Universal Document Viewer -A browser-based document viewer that renders **PDF, ODF, RTF, DOC, DOCX, Markdown, plain text, images, comic-book archives, e-books (EPUB/MOBI), and web archives (MHTML)** natively in the browser — no server, no upload, no conversion. Everything runs client-side; your files never leave your machine. +A browser-based document viewer that renders **PDF, ODF, RTF, DOC, DOCX, Markdown, plain text, images, comic-book archives, e-books (EPUB/MOBI), web archives (MHTML), and Compiled HTML Help (CHM)** natively in the browser — no server, no upload, no conversion. Everything runs client-side; your files never leave your machine. To give it a try without installing anything, visit the [live demo](https://alpaq92.github.io/ReaderJS/). @@ -28,6 +28,7 @@ To give it a try without installing anything, visit the [live demo](https://alpa | Comic Book Archive | `.cbz` `.cbr` `.cbt` | JSZip (CBZ) + libarchive.js (CBR/CBT) | | E-book | `.epub` `.mobi` `.azw3` `.fb2` | foliate-js | | Web archive (MHTML) | `.mht` `.mhtml` | mhtml-to-html | +| Compiled HTML Help | `.chm` | CHMate | ## Features @@ -81,6 +82,7 @@ ReaderJS is built on these open-source libraries: | **[libarchive.js](https://github.com/nika-begiashvili/libarchivejs)** | Nika Begiashvili | CBR/CBT (RAR/TAR) extraction via a WASM build of libarchive — uses libarchive's own BSD-licensed RAR decoder, no UnRAR code | | **[foliate-js](https://github.com/johnfactotum/foliate-js)** | John Factotum | EPUB / MOBI / KF8 (AZW3) / FB2 parsing and paginated rendering | | **[mhtml-to-html](https://github.com/gildas-lormeau/mhtml-to-html)** | Gildas Lormeau | MHTML (`.mht` / `.mhtml`) web archives → one self-contained HTML document | +| **[CHMate](https://github.com/Alpaq92/CHMate)** | Alpaq92 | Pure-JS Microsoft Compiled HTML Help (`.chm`) reader — ITSF container + LZX decompression + sanitizing topic renderer, no WASM | | **[UTIF.js](https://github.com/photopea/UTIF.js)** | Photopea | TIFF image decoding | | **[exifr](https://github.com/MikeKovarik/exifr)** | Mike Kovarik | EXIF / GPS metadata parsing for images | | **[Vite](https://github.com/vitejs/vite)** | Evan You / Vite contributors | Build tooling and development server | @@ -88,9 +90,10 @@ ReaderJS is built on these open-source libraries: | **[Open-Color](https://github.com/yeun/open-color)** | Heeyeun Jeong | Colour palette for the compare / diff view | Every library above is a normal **npm dependency** — `npm install` is all you -need, no git submodules. The two that aren't published to npm -([foliate-js](https://github.com/johnfactotum/foliate-js) for e-books and -[DejaView](https://github.com/Alpaq92/dejaview) for DjVu) are pinned to a commit +need, no git submodules. The three that aren't published to npm +([foliate-js](https://github.com/johnfactotum/foliate-js) for e-books, +[DejaView](https://github.com/Alpaq92/dejaview) for DjVu, and +[CHMate](https://github.com/Alpaq92/CHMate) for CHM) are pinned to commits as git dependencies in `package.json`. Every engine is permissively licensed (MIT / BSD / Apache-2.0 / 0BSD). diff --git a/index.html b/index.html index 4c13662..0abc430 100644 --- a/index.html +++ b/index.html @@ -120,7 +120,7 @@