Skip to content

0.6.2 — One parse per chapter

Choose a tag to compare

@CHANG-JUI-LIN CHANG-JUI-LIN released this 06 Oct 13:33
· 79 commits to main since this release

A chapter's markup and stylesheets are now parsed and styled once, and that one evaluation serves both the capability decision and the layout that follows. Hosts that decide the engine, prepare fonts and then lay out no longer parse each chapter two or three times.

  • Adds BrowserChapterDocument(input:) (one parse) and evaluate(configuration:), which returns a BrowserChapterEvaluation carrying the verdict (capabilities, with font requests) and the style tree. bodyInlineStyle serves a host's font-scale policy from the same parse.
  • Adds HTMLLayoutDocument(evaluation:) and BrowserLayoutSession(evaluation:), which lay out from that style tree instead of running the frontend again.
  • A layout may add geometry, a font resolver captured after font preparation, or a diagnostic sink to the evaluation's configuration (rebound(to:)), but never different cascade inputs: accepts(_:) refuses and the initializers throw rather than lay out stale computed values.
  • Admission reads matched declarations from the cascade's own rule matching, plus the elements the cascade never styles, so verdicts, their order, text-indent usage and font requests are unchanged. The existing scanner, HTMLLayoutDocument(input:configuration:) and BrowserLayoutSession(input:config:) entry points remain.
  • Retains iOS 17, Swift tools 6.0 and SwiftSoup 2.13.7 requirements.

Measured on five real EPUB chapters (Release, simulator, 7-round medians): CPU spent before the box tree drops from 48–467 ms to 24–237 ms (−43…−49%); a rejected chapter pays the same as before.

Validation: an equivalence suite compares verdicts against a copy of the previous scanner on real chapters and on markup built to probe hidden subtrees, head-only rules, dark media, first-letter and important declarations, and compares display lists from a reused style tree against a fresh parse. The full package suite passes on iOS Simulator (CI: Xcode 16.4). Reader layout, line-break baseline and loading benchmarks are recorded in the Reader repository.