(el: HTMLDivElement)
| 329 | private _el?: HTMLDivElement |
| 330 | onRender?: () => void |
| 331 | async render(el: HTMLDivElement) { |
| 332 | if (el === this._el) return |
| 333 | this._el = ref(el) |
| 334 | |
| 335 | const file = await db?.files.get(this.book.id) |
| 336 | if (!file) return |
| 337 | |
| 338 | this.epub = ref(await fileToEpub(file.file)) |
| 339 | |
| 340 | this.epub.loaded.navigation.then((nav) => { |
| 341 | this.nav = nav |
| 342 | }) |
| 343 | console.log(this.epub) |
| 344 | this.epub.loaded.spine.then((spine: any) => { |
| 345 | const sections = spine.spineItems as ISection[] |
| 346 | // https://github.com/futurepress/epub.js/issues/887#issuecomment-700736486 |
| 347 | const promises = sections.map((s) => |
| 348 | s.load(this.epub?.load.bind(this.epub)), |
| 349 | ) |
| 350 | |
| 351 | Promise.all(promises).then(() => { |
| 352 | sections.forEach((s) => { |
| 353 | s.length = s.document.body.textContent?.length ?? 0 |
| 354 | s.images = [...s.document.querySelectorAll('img')].map((el) => el.src) |
| 355 | this.epub!.loaded.navigation.then(() => { |
| 356 | s.navitem = this.mapSectionToNavItem(s.href) |
| 357 | }) |
| 358 | }) |
| 359 | this.sections = ref(sections) |
| 360 | }) |
| 361 | }) |
| 362 | this.rendition = ref( |
| 363 | this.epub.renderTo(el, { |
| 364 | width: '100%', |
| 365 | height: '100%', |
| 366 | allowScriptedContent: true, |
| 367 | }), |
| 368 | ) |
| 369 | console.log(this.rendition) |
| 370 | this.rendition.display( |
| 371 | this.location?.start.cfi ?? this.book.cfi ?? undefined, |
| 372 | ) |
| 373 | this.rendition.themes.default(defaultStyle) |
| 374 | this.rendition.hooks.render.register((view: any) => { |
| 375 | console.log('hooks.render', view) |
| 376 | this.onRender?.() |
| 377 | }) |
| 378 | |
| 379 | this.rendition.on('relocated', (loc: Location) => { |
| 380 | console.log('relocated', loc) |
| 381 | this.rendered = true |
| 382 | this.timeline.unshift({ |
| 383 | location: loc, |
| 384 | timestamp: Date.now(), |
| 385 | }) |
| 386 | |
| 387 | // calculate percentage |
| 388 | if (this.sections) { |
nothing calls this directly
no test coverage detected