Add an EventTarget for transforming the book

And use it to do paginator-specific CSS replacements.

And use it to catch loading errors in reader.js.

Fixes #14
Closes #18
This commit is contained in:
John Factotum
2025-03-29 15:09:23 +08:00
parent d4696cea4b
commit 052123beaf
4 changed files with 44 additions and 18 deletions
+6
View File
@@ -111,6 +111,12 @@ class Reader {
this.view.addEventListener('relocate', this.#onRelocate.bind(this))
const { book } = this.view
book.transformTarget?.addEventListener('data', ({ detail }) => {
detail.data = Promise.resolve(detail.data).catch(e => {
console.error(new Error(`Failed to load ${detail.name}`, { cause: e }))
return ''
})
})
this.view.renderer.setStyles?.(getCSS(this.style))
this.view.renderer.next()