hyper_render_epub 0.1.1
hyper_render_epub: ^0.1.1 copied to clipboard
EPUB container support for HyperRender. Unzips an .epub, parses its OPF manifest/spine/TOC, and resolves chapters to HyperViewer-ready content.
Changelog — hyper_render_epub #
0.1.1 #
- Added standalone
example/example.dartdemonstratingEpubBook.openandEpubReader. - Added doc comments to
EpubChapterandEpubTocEntryconstructors for 100% dartdoc coverage. - Tightened
hyper_renderandhyper_render_coredependency constraints to^1.7.0to ensure downgrade test lower bound compatibility on pub.dev.
0.1.0 #
Initial release — not publishable yet: it depends on hyper_render: ^1.7.0, which is
not on pub.dev. EpubReader needs HyperViewer.imageLoader (unreleased, on main) to
decode the inline data: URIs chapters carry, so this package ships once hyper_render
1.7.0 does. Monorepo development is unaffected.
✨ New #
-
EpubBook.open(Uint8List): unzips an.epub, locates the OPF package document throughMETA-INF/container.xml(never a hardcoded path), and parsesdc:title/dc:creator, the manifest, the spine and the cover image. ReturnsFuture<EpubBook>— a large, illustrated book is real main-thread work (zip inflate + base64 per image). -
Table of contents: EPUB3
nav.xhtml(properties="nav",epub:type="toc"), falling back to the EPUB2toc.ncxnavMap. Nesting and#fragments are preserved, and TOC titles are matched onto chapters by resolved path, soEpubChapter.titleis populated. -
Per-chapter transform:
<img src>pointing into the archive is rewritten to an inline base64data:URI;<link rel="stylesheet">and<style>elements are removed and their text concatenated intoEpubChapter.cssin document order (forHyperViewer.customCss);<body>content is extracted. Parsed with the HTML5 parser, not a strict XHTML one — real books are full of undeclared entities and unclosed tags. -
EpubChapter.linearmirrors the spine'slinear="no": such items are kept inchapters(dropping content silently is worse) but flagged so a reader can present them out of the main flow. -
epubImageLoader: aHyperImageLoaderthat decodes thosedata:URIs (falls back to the normal network loader for any other scheme). -
EpubReaderController(aChangeNotifier: position,next/previous/goTo,chapterIndexForHref,openHref) andEpubReader, which renders the current chapter throughHyperViewerand resolves link taps — in-book links move the controller, everything else goes toonExternalLinkTap. NoScaffold/app bar/TOC drawer: chrome is the app's, and it has the controller to drive it. -
EpubChapter.href(OPF-relative, matchingEpubTocEntry.href) so TOC entries and cross-chapter links can be resolved to a chapter. Links inside a chapter resolve against that chapter's directory — passrelativeTo, whichEpubReaderdoes for you. -
EpubFormatExceptionfor structural damage (not a zip, no OPF, no spine). Partial damage degrades instead of throwing: a missing chapter file is skipped, an unparsable TOC yields an empty list, an<img>with no matching entry keeps its originalsrc. -
SVG handling:
<img src="*.svg">is replaced by the SVG markup inline (adata:image/svgURI would be blocked byUrlSafety; an inline<svg>is preserved by the sanitizer and rendered throughflutter_svg— note that renderer is chained in byHyperViewer, not by core'sHyperRenderWidget).EpubBook.coverMediaTypeaccompaniescoverImageso an SVG cover can be routed toSvgPicture.memory.
📌 Deliberate limits #
- Cross-chapter
<a href>links are left as authored inEpubChapter.html;EpubReaderresolves them at tap time. - Embedded fonts (
@font-face) andbackground-imageare engine-level gaps, not worked around here. See the README.