Commit Graph
11 Commits
Author SHA1 Message Date
John O'Keefe b7597d6159 fix(paginator): guard getVisibleRange against not-yet-loaded documents
Second member of the 50f56ee guard family: the scroll-anchor tick
(#afterScroll) can run before the iframe document is parsed, throwing
'createTreeWalker' on null body. getVisibleRange now returns null for
that tick and #afterScroll preserves the previous visibility state.
Observed live in the Android app on PalmDOC open.
2026-10-03 22:35:28 -04:00
John O'Keefe 111898ee0e fix(paginator): bail from expand() when the iframe document is torn down
A queued resize tick can run against a not-yet-parsed or unloaded
iframe; documentElement is null then and expand() threw inside the
ResizeObserver callback. Observed live in the Android app (twice in
row during boot and page turns). Follows the 50f56ee guard family.
2026-10-03 22:30:03 -04:00
John O'Keefe ac699e71ee feat(rtff-pdb): RTF and PalmDOC plain-text support (v0.5.0)
rtf.js: a minimal single-pass RTF tokenizer extracting document text
with paragraph structure — groups, control words with signed params,
\\'hh Windows-1252 escapes, \\uN unicode with \\ucN fallback skipping,
known text destinations skipped whole (fonttbl/colortbl/stylesheet/
info/headers/pict/field/...), spec-required ignoring of unknown words.
Format runs are intentionally not converted; RTF is read as styled
text like .txt.

pdb.js: the TEXt/REAd PalmDOC container (PalmDOC, TealDoc) — the PDB
record reader and LZ77 decompressor are shared from mobi.js (both
exported; upstream already carried the TODO for this path). Records
decode as Windows-1252 and feed the plain-text pipeline (paragraph
split, line join, ~150KB sectioning, Part N TOC).

makeBook dispatch: content-based (TEXtREAd magic at offset 60;
'{\\rtf' magic), after MOBI and before the text branch.

Tests: node harness covering store + compressed PalmDOC, RTF paragraphs
/escapes/unicode/hex/destination-skipping, makeBook routing; txt/docx
regression suites pass.
2026-10-03 14:49:22 -04:00
John O'Keefe 50f56ee67f fix(paginator): tolerate not-yet-loaded section documents in early resize renders
The ResizeObserver can fire while the iframe document is still unset:
setImageSize dereferenced doc.body unconditionally and
setStylesImportant destructure-crashed on null, killing the render
loop — the view then never snapped or relocated again (observed in an
embedded Android WebView where the first observation lands pre-load).
Guard both paths.
2026-10-02 15:17:00 -04:00
John O'Keefe 8e1d5fc8d6 feat(docx): Word (.docx) support via mammoth (lazy npm dependency)
makeDocxBook: the docx blob goes straight to mammoth.convertToHtml
(mammoth unzips internally; the browser entry takes {arrayBuffer}, the
node entry {buffer}). Converted HTML is sectioned at block-element
boundaries into ~150KB chunks (string-level — no DOMParser), giving a
Part N TOC; images inline as data URIs by default.

makeBook: zip files whose entries contain word/document.xml route to
the docx branch before the EPUB fallback (previously they died inside
new EPUB(...) on the missing container.xml).

mammoth is the fork's first runtime dependency: updates and security
fixes flow via semver; the browser-field mappings swap its node unzip
for the browser one; the dynamic import keeps it out of every other
format's path.
2026-10-01 14:17:38 -04:00
John O'Keefe cd2fbf278e feat(text): plain-text (.txt) renderer
makeTextBook: UTF-8 decode (BOM stripped), blank-line paragraph split,
hard-wrapped lines joined (natural reflow under font-size changes), HTML
escaped, sections capped at ~150KB at paragraph boundaries (small Part N
TOC, avoids one giant DOM). Sections expose load/createDocument/size per
the reflowable interface; positions for txt books are percentage-based
(sections get fake CFIs from index, same as other non-EPUB books).

makeBook: dispatches text/plain or .txt in the final non-zip/non-pdf
branch. EPUB/PDF/CBZ/MOBI/FB2 routing untouched.

Tests: offline node harness (isText, paragraph join/split, escaping,
section capping, TOC shape, dispatch incl. zip-still-routes-to-EPUB).
2026-09-30 15:12:05 -04:00
John O'Keefe 734ce41a50 chore: bump version to 0.1.0
npm's cache reuse keyed on name@version (stuck at 0.0.0) silently served
stale tarballs to Docker builds; bumping on every deploy-worthy change
forces fresh resolution.
2026-09-17 10:10:24 -04:00
John Factotum 1217096245 Update PDF.js to 5.5.207
Fixes https://github.com/johnfactotum/foliate-js/issues/85
2026-03-05 15:52:38 +08:00
John Factotum ae61c5e85f Make zip.js, fflate, and PDF.js dev dependencies
Previously, zip.js and fflate were built from the main Foliate repo.
And PDF.js files were copied manually. Now they all build here.

Unfortunately, two CSS files still need to be copied manually.
2024-10-12 07:44:33 +08:00
John Factotum 7372c658cf Fix package.json 2024-04-27 16:51:04 +08:00
John Factotum 5600b6c0dc Migrate to ESLint 9 and fix linting issues 2024-04-23 12:59:31 +08:00