about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorfox <fox@fakecake.org>2026-06-16 13:14:21 +0300
committerfox <fox@fakecake.org>2026-06-16 13:14:21 +0300
commitb5c9444b9aa83e14b686d2e4192ae4d3e245905f (patch)
tree921ec30c3782f19078b4a1c62870c92b510a2edb
parent50487d21f76da26cf59618fd312f66a62f7eae62 (diff)
parente681773ceed41032b2096f710cfb6c6268bef004 (diff)
downloadthe-epube-b5c9444b9aa83e14b686d2e4192ae4d3e245905f.tar.gz
the-epube-b5c9444b9aa83e14b686d2e4192ae4d3e245905f.tar.xz
Merge branch 'dev' into 'master'
one more type hint

See merge request git/the-epube!58
-rw-r--r--lib/epub.js/types/navigation.d.ts3
-rw-r--r--lib/epub.js/types/packaging.d.ts4
-rw-r--r--lib/epub.js/types/spine.d.ts4
-rw-r--r--src/app.js55
-rw-r--r--src/reader.js32
5 files changed, 92 insertions, 6 deletions
diff --git a/lib/epub.js/types/navigation.d.ts b/lib/epub.js/types/navigation.d.ts
index 8b4f8a0..81cdcb0 100644
--- a/lib/epub.js/types/navigation.d.ts
+++ b/lib/epub.js/types/navigation.d.ts
@@ -3,7 +3,8 @@ export interface NavItem {
   href: string,
   label: string,
   subitems?: Array<NavItem>,
-  parent?: string
+  parent?: string,
+  _nest?: number,
 }
 
 export interface LandmarkItem {
diff --git a/lib/epub.js/types/packaging.d.ts b/lib/epub.js/types/packaging.d.ts
index 7151956..30aa8f3 100644
--- a/lib/epub.js/types/packaging.d.ts
+++ b/lib/epub.js/types/packaging.d.ts
@@ -30,7 +30,9 @@ export interface PackagingMetadataObject {
 export interface PackagingSpineItem {
   idref: string,
   properties: Array<string>,
-  index: number
+  index: number,
+  href: string,
+  url: string,
 }
 
 export interface PackagingManifestItem {
diff --git a/lib/epub.js/types/spine.d.ts b/lib/epub.js/types/spine.d.ts
index b7cb5c8..96a7ae9 100644
--- a/lib/epub.js/types/spine.d.ts
+++ b/lib/epub.js/types/spine.d.ts
@@ -1,4 +1,4 @@
-import Packaging from "./packaging";
+import Packaging, { PackagingSpineItem } from "./packaging";
 import Section from "./section";
 import Hook from "./utils/hook";
 
@@ -24,6 +24,8 @@ export default class Spine {
 
   spineItems: Section[];
 
+  items: PackagingSpineItem[];
+
   private append(section: Section): number;
 
   private prepend(section: Section): number;
diff --git a/src/app.js b/src/app.js
index c661725..faf51d0 100644
--- a/src/app.js
+++ b/src/app.js
@@ -3,6 +3,12 @@
 'use strict';
 
 class Cookie {
+
+    /**
+     * @param {string} name
+     * @param {string | number | boolean} value
+     * @param {number} lifetime
+     */
     static set(name, value, lifetime) {
         const d = new Date();
         d.setTime(d.getTime() + lifetime * 1000);
@@ -10,6 +16,9 @@ class Cookie {
         document.cookie = name + "=" + encodeURIComponent(value) + "; " + expires;
     }
 
+    /**
+     * @param {string} name
+     */
     static get(name) {
         name = name + "=";
         const ca = document.cookie.split(';');
@@ -28,6 +37,9 @@ class Cookie {
 }
 
 class AppCommon {
+    /**
+     * @param {string} name
+     */
     urlParam(name){
         try {
             const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
@@ -100,6 +112,7 @@ class AppCommon {
         }
     }
 
+    /** @param {boolean} is_night */
     applyNightMode(is_night) {
         console.log("night mode changed to", is_night);
 
@@ -112,20 +125,24 @@ class AppCommon {
 class AppClass extends AppCommon {
     _dl_progress_timeout;
 
+    /** @type{string} */
     index_mode = "";
 
+    /** @type{string} */
     index_query = "";
 
+    /** @type{number} */
     index_offset = 0;
 
     cached_urls = [];
 
+    /** @type{string} */
     version = BUILD_CACHE_VERSION;
 
+    /** @type{string} */
     cosmeticVersion = BUILD_VERSION;
 
-    // cacheManifest = [];
-
+    /** @type{string} */
     csrf_token = "";
 
     async init() {
@@ -232,9 +249,15 @@ class AppClass extends AppCommon {
         window.location.reload();
     }
 
+    /**
+     * @param {HTMLElement} elem
+     */
     async showSummary(elem) {
         const bookId = elem.getAttribute("data-book-id");
 
+        if (!bookId)
+            return;
+
         if (this.isOnline()) {
 
             /** @type{HttpResponse} */
@@ -280,15 +303,25 @@ class AppClass extends AppCommon {
         });
     }
 
+    /**
+     * @param {HTMLElement} elem
+     * @param {boolean} is_fav
+     */
     updateFavoritePrompt(elem, is_fav) {
         $(elem)
             .text(is_fav ? "Remove from favorites" : "Add to favorites")
             .attr('data-is-fav', is_fav ? 1 : 0);
     }
 
+    /**
+     * @param {HTMLElement} elem
+     */
     async toggleFavorite(elem) {
         const bookId = elem.getAttribute("data-book-id");
 
+        if (!bookId)
+            return;
+
         if (elem.getAttribute("data-is-fav") == "0" || confirm("Remove favorite?")) {
 
             try {
@@ -316,8 +349,15 @@ class AppClass extends AppCommon {
         });
     }
 
+    /**
+     * @param {HTMLElement} elem
+     */
     async updateOfflinePrompt(elem) {
         const bookId = elem.getAttribute("data-book-id");
+
+        if (!bookId)
+            return;
+
         const cacheId = "epube-book." + bookId;
 
         const book = await localforage.getItem(cacheId);
@@ -364,6 +404,10 @@ class AppClass extends AppCommon {
         this.populateOfflineList();
     }
 
+     /**
+     * @param {string} bookId
+     * @param {Function} callback
+     */
     async get(bookId, callback) {
         console.log("offline cache: " + bookId);
 
@@ -442,6 +486,9 @@ class AppClass extends AppCommon {
         }
     }
 
+    /**
+     * @param {HTMLElement} elem
+     */
     removeFromList(elem) {
         const bookId = elem.getAttribute("data-book-id");
 
@@ -496,6 +543,7 @@ class AppClass extends AppCommon {
             return;
         }
 
+        /** @type{BookList} */
         const data = resp.data;
         const books = $("#books_container");
         books.html("");
@@ -536,6 +584,9 @@ class AppClass extends AppCommon {
         this.updateIndexPagination(data);
     }
 
+    /**
+     * @param {BookList} data
+     */
     updateIndexPagination(data) {
         const prevLi = $(".pager .previous");
         const nextLi = $(".pager .next");
diff --git a/src/reader.js b/src/reader.js
index 1df71b5..f436810 100644
--- a/src/reader.js
+++ b/src/reader.js
@@ -751,6 +751,9 @@ class ReaderClass extends AppCommon {
 
     }
 
+    /**
+     * @param {ePub.Book} book
+     */
     initToc(book) {
         const _reader = this;
 
@@ -762,7 +765,8 @@ class ReaderClass extends AppCommon {
                     return k.indexOf(cfiBase) != -1
                 });
 
-                return Math.round(_reader.book.locations.locationFromCfi(loc) / LOCATION_DIVISOR);
+                if (loc)
+                    return Math.round(_reader.book.locations.locationFromCfi(loc) / LOCATION_DIVISOR);
 
             } catch (e) {
                 console.warn(e);
@@ -771,6 +775,11 @@ class ReaderClass extends AppCommon {
             return "";
         }
 
+        /**
+         * @param {ePub.NavItem} row
+         * @param {JQuery<HTMLElement>} list
+         * @param {number} nest
+         */
         function process_toc_sublist(row, list, nest) {
 
             if (nest == 3) return false;
@@ -853,6 +862,9 @@ class ReaderClass extends AppCommon {
     }
 
     /* embedded styles may conflict with our font sizes, etc */
+    /**
+     * @param {Document} doc
+     */
     cleanupEmbeddedStyles(doc) {
         $(doc).find("p")
                 // @ts-ignore
@@ -896,6 +908,9 @@ class ReaderClass extends AppCommon {
         }
     }
 
+    /**
+     * @param {string} base_url
+     */
     generateFontsCss(base_url) {
         return `
             /** Calibri */
@@ -1070,6 +1085,10 @@ class ReaderClass extends AppCommon {
             `;
     }
 
+    /**
+     * @param {ePub.NavItem} entry
+     * @param {number} nest
+     */
     flattenTocSubItems(entry, nest) {
         let rv = [];
 
@@ -1150,6 +1169,10 @@ class ReaderClass extends AppCommon {
         this.updateTocBarPosition(book, book.rendition.currentLocation())
     }
 
+    /**
+     * @param {ePub.Book} book
+     * @param {ePub.Location} location
+     */
     updateTocBarPosition(book, location) {
         const cur_pct = Math.round(location.start.location / book.locations.length() * 100);
 
@@ -1239,6 +1262,9 @@ class ReaderClass extends AppCommon {
             });
     }
 
+    /**
+     * @param {JQuery.KeyUpEvent<Document, undefined, Document, Document>} e
+     */
     hotkeyHandler(e) {
         try {
             //console.log('K3:' + e.which, e);
@@ -1329,10 +1355,14 @@ class ReaderClass extends AppCommon {
         }
     }
 
+    /** @param {string} [suffix] */
     cacheId(suffix) {
         return "epube-book." + this.urlParam("b") + (suffix ? "." + suffix : "");
     }
 
+    /**
+     * @param {boolean} show
+     */
     showUI(show) {
         if (show)
             $(".header,.footer").fadeIn();