about summary refs log tree commit diff stats
path: root/src/reader.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/reader.ts')
-rw-r--r--src/reader.ts51
1 files changed, 21 insertions, 30 deletions
diff --git a/src/reader.ts b/src/reader.ts
index 55c9844..567c920 100644
--- a/src/reader.ts
+++ b/src/reader.ts
@@ -2,10 +2,8 @@
 
 'use strict';
 
-declare var createHyphenator: any;
+/** Pattern definition as produced by the hyphen library's build process. */
 
-declare var hyphenationPatternsEnUs: any;
-declare var hyphenationPatternsRu: any;
 
 declare interface HTMLElement { checked: boolean }
 declare interface Event { deltaY: number, deltaX: number }
@@ -20,7 +18,7 @@ declare type SwipeState = {
    startX: number,
     startY: number,
     startTime: number,
-    direction: 'left'|'right'|'';
+    direction: 'left'|'right';
 }
 
 declare type SwipeConfig = {
@@ -49,7 +47,7 @@ class ReaderClass extends AppCommon {
 
     open_last_read_when_displayed = true;
 
-    hyphenate = {};
+    hyphenate = {} as HyphenateMap;
 
     _prevent_lastread_timeout: any;
 
@@ -59,10 +57,7 @@ class ReaderClass extends AppCommon {
 
     cosmeticVersion = BUILD_VERSION;
 
-    /**
-     * @type {ePub.Book}
-     */
-    book;
+    book: ePub.Book;
 
     /** @type {SwipeState} */
     _swipeState = {
@@ -73,8 +68,7 @@ class ReaderClass extends AppCommon {
         direction: '',
     };
 
-    /** @type {SwipeConfig} */
-    _swipeConfig = {
+    _swipeConfig: SwipeConfig = {
         minDistance: 50,           // px — minimum horizontal travel to count as swipe
         velocityThreshold: 0.3,    // px/ms — minimum swipe speed
         verticalDistanceThreshold: 80, // px — vertical movement before cancelling
@@ -358,9 +352,8 @@ class ReaderClass extends AppCommon {
         const enable_hyphens = await localforage.getItem("epube.enable-hyphens");
 
         if (enable_hyphens) {
-            /* global hyphenationPatternsEnUs, hyphenationPatternsRu, createHyphenator */
-            (this.hyphenate as any).en = createHyphenator(hyphenationPatternsEnUs, { html: true });
-            (this.hyphenate as any).ru = createHyphenator(hyphenationPatternsRu, { html: true });
+            this.hyphenate.en = createHyphenator(hyphenationPatternsEnUs, { html: true });
+            this.hyphenate.ru = createHyphenator(hyphenationPatternsRu, { html: true });
         }
 
         this.initRenditionHooks(this.book, rendition);
@@ -759,7 +752,7 @@ class ReaderClass extends AppCommon {
                 .on("keyup", (evt: any) => {
                     if (evt.which === 13) {
                         evt.preventDefault();
-                        this.lookupWord(null, null, '.dict_query');
+                        this.lookupWord('', null, '.dict_query');
                     }
                 });
 
@@ -889,7 +882,7 @@ class ReaderClass extends AppCommon {
      */
     cleanupEmbeddedStyles(doc: Document) {
         $(doc).find("p")
-                .filter((i: any, e: any) => (($(e).text().length >= MIN_LENGTH_TO_JUSTIFY) ? e : null))
+                .filter((i, e: any) => (($(e).text().length >= MIN_LENGTH_TO_JUSTIFY) ? e : null))
                     .css("text-align", "justify");
 
         $(doc).find("html")
@@ -919,12 +912,13 @@ class ReaderClass extends AppCommon {
             .css("background", "")
             .css("background-color", "");
 
-        if (typeof (this.hyphenate as any).en != "undefined") {
-            $(doc).find('p, div').each((i: any, elem: any) => {
-    const p = $(elem);
-    p.html((this.hyphenate as any).en(p.html()));
-    p.html((this.hyphenate as any).ru(p.html()));
-});
+        if (this.hyphenate?.en) {
+            $(doc).find('p, div').each((i, elem) => {
+                const p = $(elem);
+
+                p.html(this.hyphenate.en(p.html()) as string);
+                p.html(this.hyphenate.ru(p.html()) as string);
+            });
         }
     }
 
@@ -1399,9 +1393,10 @@ class ReaderClass extends AppCommon {
             $(".header,.footer").fadeIn();
     }
 
-    async lookupWord(word: any, callback: any, elem: any = null) {
+    /** @param [elem=null] jquery selector for the input element to use */
+    async lookupWord(word: string, callback: any, elem: string|null = null) {
         if (elem)
-            word = $(elem).val();
+            word = $(elem).val() as string;
 
         word = word.replace(/­/g, "");
 
@@ -1423,8 +1418,7 @@ class ReaderClass extends AppCommon {
                 if (callback) callback();
             }
         } catch (e) {
-            // @type {NetworkError}
-            const err = /** @type {HttpError} */(e);
+            const err = e as NetworkError;
 
             console.error(err);
 
@@ -1432,10 +1426,7 @@ class ReaderClass extends AppCommon {
         }
     }
 
-    /**
-     * @returns {Promise<void>}
-     */
-    async search() {
+    async search(): Promise<void> {
         const query = $(".search_input").val();
         const list = $(".search_results");