Expose ReaderJS as a read-only, self-contained, same-origin embed:
ReaderJS.mount(container, { blob|arrayBuffer, name, mime }) -> { load, destroy }
The host hands in document bytes (not a File); the filename's extension picks
the renderer. Isolated in a same-origin iframe so the viewer's full-page CSS,
JS globals and CSP surface stay out of the host page. Also supports a zero-JS
iframe variant: reader.html?src=<url>&name=<file> (self-fetches same-origin).
- main.js: lazy per-format renderer registry (pdf.js/jszip/foliate split into
on-demand chunks) + loadBytes(bytes, name, mime); openFile delegates; export
DocumentViewer; null-tolerant UI wiring; auto-init gated on #dropzone.
- reader.html (trimmed index.html, no upload UI) + src/reader.js bootstrap
(?src self-fetch or origin-checked postMessage handshake).
- src/readerjs.js: IIFE loader exposing window.ReaderJS.mount (sandboxed iframe,
structured-clone copy so the host buffer is not neutered).
- vite.config.app.js + vite.config.embed.js -> dist-embed/ (base:'./', workers/
wasm/public assets bundle-relative); npm run build:embed.
- i18n.js: localStorage guarded for sandboxed contexts.
- CREDITS.md (all engines permissive; pptxviewjs MIT; WebODF reference-only, not
bundled) + EMBEDDING.md (API, iframe variant, CSP asset list).
Verified against the built artifact: bytes-mode renders DjVu (dejaview module
worker under base:'./'), ?src mode renders CSV, per-format lazy chunks, zero
external-origin requests, destroy() cleanup. Demo app build unaffected.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
21 lines
652 B
JavaScript
21 lines
652 B
JavaScript
import { defineConfig } from 'vite'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
// Embed build #2 — the tiny loader IIFE (readerjs.js) exposing window.ReaderJS.
|
|
// Runs AFTER the app build, into the SAME folder, WITHOUT emptying it.
|
|
export default defineConfig({
|
|
base: './',
|
|
build: {
|
|
outDir: 'dist-embed',
|
|
emptyOutDir: false, // keep the app build's reader.html + chunks
|
|
target: 'es2020',
|
|
lib: {
|
|
entry: fileURLToPath(new URL('./src/readerjs.js', import.meta.url)),
|
|
name: 'ReaderJS',
|
|
formats: ['iife'],
|
|
fileName: () => 'readerjs.js',
|
|
},
|
|
rollupOptions: { output: { extend: true } },
|
|
},
|
|
})
|