| 77 | type AsRef = { $$valtioRef: true } |
| 78 | |
| 79 | export class BookTab extends BaseTab { |
| 80 | epub?: Book |
| 81 | iframe?: Window & AsRef |
| 82 | rendition?: Rendition & { manager?: any } |
| 83 | nav?: Navigation |
| 84 | locationToReturn?: Location |
| 85 | section?: ISection |
| 86 | sections?: ISection[] |
| 87 | results?: IMatch[] |
| 88 | activeResultID?: string |
| 89 | rendered = false |
| 90 | |
| 91 | get container() { |
| 92 | return this?.rendition?.manager?.container as HTMLDivElement | undefined |
| 93 | } |
| 94 | |
| 95 | timeline: TimelineItem[] = [] |
| 96 | get location() { |
| 97 | return this.timeline[0]?.location |
| 98 | } |
| 99 | |
| 100 | display(target?: string, returnable = true) { |
| 101 | this.rendition?.display(target) |
| 102 | if (returnable) this.showPrevLocation() |
| 103 | } |
| 104 | displayFromSelector(selector: string, section: ISection, returnable = true) { |
| 105 | try { |
| 106 | const el = section.document.querySelector(selector) |
| 107 | if (el) this.display(section.cfiFromElement(el), returnable) |
| 108 | } catch (err) { |
| 109 | this.display(section.href, returnable) |
| 110 | } |
| 111 | } |
| 112 | prev() { |
| 113 | this.rendition?.prev() |
| 114 | // avoid content flash |
| 115 | if (this.container?.scrollLeft === 0 && !this.location?.atStart) { |
| 116 | this.rendered = false |
| 117 | } |
| 118 | } |
| 119 | next() { |
| 120 | this.rendition?.next() |
| 121 | } |
| 122 | |
| 123 | updateBook(changes: Partial<BookRecord>) { |
| 124 | changes = { |
| 125 | ...changes, |
| 126 | updatedAt: Date.now(), |
| 127 | } |
| 128 | // don't wait promise resolve to make valtio batch updates |
| 129 | this.book = { ...this.book, ...changes } |
| 130 | db?.books.update(this.book.id, changes) |
| 131 | } |
| 132 | |
| 133 | annotationRange?: Range |
| 134 | setAnnotationRange(cfi: string) { |
| 135 | const range = this.view?.contents.range(cfi) |
| 136 | if (range) this.annotationRange = ref(range) |
nothing calls this directly
no outgoing calls
no test coverage detected