(file)
| 106 | menu.groups.layout.select("paginated"); |
| 107 | } |
| 108 | async open(file) { |
| 109 | this.view = document.createElement("foliate-view"); |
| 110 | document.body.append(this.view); |
| 111 | await this.view.open(file); |
| 112 | this.view.addEventListener("load", this.#onLoad.bind(this)); |
| 113 | this.view.addEventListener("relocate", this.#onRelocate.bind(this)); |
| 114 | |
| 115 | const { book } = this.view; |
| 116 | book.transformTarget?.addEventListener("data", ({ detail }) => { |
| 117 | detail.data = Promise.resolve(detail.data).catch((e) => { |
| 118 | console.error(new Error(`Failed to load ${detail.name}`, { cause: e })); |
| 119 | return ""; |
| 120 | }); |
| 121 | }); |
| 122 | this.view.renderer.setStyles?.(getCSS(this.style)); |
| 123 | this.view.renderer.next(); |
| 124 | |
| 125 | $("#header-bar").style.visibility = "visible"; |
| 126 | $("#nav-bar").style.visibility = "visible"; |
| 127 | $("#left-button").addEventListener("click", () => this.view.goLeft()); |
| 128 | $("#right-button").addEventListener("click", () => this.view.goRight()); |
| 129 | |
| 130 | const slider = $("#progress-slider"); |
| 131 | slider.dir = book.dir; |
| 132 | slider.addEventListener("input", (e) => |
| 133 | this.view.goToFraction(Number.parseFloat(e.target.value)), |
| 134 | ); |
| 135 | for (const fraction of this.view.getSectionFractions()) { |
| 136 | const option = document.createElement("option"); |
| 137 | option.value = fraction; |
| 138 | $("#tick-marks").append(option); |
| 139 | } |
| 140 | |
| 141 | document.addEventListener("keydown", this.#handleKeydown.bind(this)); |
| 142 | |
| 143 | const title = formatLanguageMap(book.metadata?.title) || "Untitled Book"; |
| 144 | document.title = title; |
| 145 | $("#side-bar-title").innerText = title; |
| 146 | $("#side-bar-author").innerText = formatContributor(book.metadata?.author); |
| 147 | Promise.resolve(book.getCover?.())?.then((blob) => |
| 148 | blob ? ($("#side-bar-cover").src = URL.createObjectURL(blob)) : null, |
| 149 | ); |
| 150 | |
| 151 | const toc = book.toc; |
| 152 | if (toc) { |
| 153 | this.#tocView = createTOCView(toc, (href) => { |
| 154 | this.view.goTo(href).catch((e) => console.error(e)); |
| 155 | this.closeSideBar(); |
| 156 | }); |
| 157 | $("#toc-view").append(this.#tocView.element); |
| 158 | } |
| 159 | |
| 160 | // load and show highlights embedded in the file by Calibre |
| 161 | const bookmarks = await book.getCalibreBookmarks?.(); |
| 162 | if (bookmarks) { |
| 163 | const { fromCalibreHighlight } = await import("./epubcfi.js"); |
| 164 | for (const obj of bookmarks) { |
| 165 | if (obj.type === "highlight") { |
no test coverage detected