EpubScriptRunner
Runs the scripts of a book on KiteJS, for KiteDocView or any other host (#41).
val scripts = EpubScriptRunner(book)
KiteDocView(state, epubScripts = scripts)The scripts of each chapter run in a window of their own, over the library's own parse and layout: EpubScriptSession says what they see. A runner can be called from any thread. It runs every call one at a time and in order, as PdfScriptRunner does. Off the web, it runs them on a thread of its own. A KiteJS engine belongs to the thread that opened it, and each chapter's engine opens on a thread of its own, so the call goes there while it runs that chapter's scripts (#498). close stops every one of them. On the web, a long script pauses now and then so the page can draw, and the next call waits for it (#489). A listener of onNavigate or onTimersChanged runs on one of them while a script waits for it, so it hands its work on, as KiteDocView does, rather than calling the runner.
At most LIVE_CHAPTERS chapters keep their engines open: opening another closes the engine of the chapter used least recently, whose scripts start over from its markup when it opens again. On JavaScript and WebAssembly the engine loads before its first use: call prepare once and wait for it, as KiteDocView does.
Parameters
gets what scripts print with console, and what alert, confirm and prompt would have shown, on one of the runner's threads.
milliseconds on a clock that only goes forward, for the timers, the budget and Date.now(). Leave it unset for the real one; a test sets it so a timer is repeatable.
a value the app keeps for its reader, such as an install id, which makes the book's origin one of this reader's copy (#521). Without one each runner has an origin of its own.
the outline of a run of text in a host font, in glyph space as KiteCanvas.hostGlyphOutline answers it. A canvas's getImageData and toDataURL draw text with it. Without it, text reads back as blank.