Files
ReaderJS/vite.config.js
adminandClaude Opus 4.8 4643132582 feat: add CHM (.chm) support via CHMate
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 <noreply@anthropic.com>
2026-06-29 18:06:58 +02:00

41 lines
1.6 KiB
JavaScript

import { defineConfig } from 'vite'
import { fileURLToPath } from 'node:url'
// foliate-js's pdf.js bundles pdf.mjs via a `new URL(`vendor/pdfjs/…`)` pattern
// that Vite's production build can't resolve. ReaderJS never opens PDFs through
// foliate (PDFRenderer handles them), so intercept foliate's conditional
// `import('./pdf.js')` at resolve time and redirect it to a harmless stub.
const stubFoliatePdf = {
name: 'stub-foliate-pdf',
enforce: 'pre',
resolveId(source, importer) {
if (source === './pdf.js' && importer?.replace(/\\/g, '/').includes('/foliate-js/')) {
return fileURLToPath(new URL('./src/foliate-pdf-stub.js', import.meta.url))
}
},
}
export default defineConfig({
plugins: [stubFoliatePdf],
resolve: {
alias: {
// CHMate only declares its reader (".") in package.json exports, which
// blocks a bare `chmate/render` import. Alias the browser renderer
// (renderTopic/BlobCache) straight to its file so the CHM renderer can
// reuse CHMate's hardened sanitizer instead of reimplementing it.
// TODO: drop this alias once CHMate adds "./render" to its package exports.
'chmate/render': fileURLToPath(new URL('./node_modules/chmate/src/render.js', import.meta.url)),
},
},
optimizeDeps: {
include: ['pdfjs-dist', 'mammoth'],
// Don't esbuild-prebundle foliate-js: it's source-style ESM and its
// (stubbed, unused) pdf.js uses top-level await, which fails the es2020
// optimizer target. Served as source, it goes through stubFoliatePdf.
exclude: ['foliate-js'],
},
build: {
target: 'es2020'
}
})