From ef79eab44bfd000792c610b968b5ceefd41e76a0 Mon Sep 17 00:00:00 2001 From: Darius Jahandarie Date: Sat, 4 Nov 2023 18:45:57 +0900 Subject: Modernize codebase - Use ES modules - Remove vendored libs and build them from npm using esbuild - Switch from JSZip to zip.js --- ext/js/accessibility/accessibility-controller.js | 5 +- ext/js/accessibility/google-docs-util.js | 9 ++- ext/js/app/content-script-main.js | 10 +-- ext/js/app/content-script-wrapper.js | 24 +++++++ ext/js/app/frontend.js | 18 +++-- ext/js/app/popup-factory.js | 14 ++-- ext/js/app/popup-proxy.js | 7 +- ext/js/app/popup-window.js | 6 +- ext/js/app/popup.js | 14 ++-- ext/js/app/theme-controller.js | 2 +- ext/js/background/backend.js | 46 ++++++------ ext/js/background/background-main.js | 5 +- ext/js/background/offscreen-main.js | 4 +- ext/js/background/offscreen.js | 8 +-- ext/js/background/profile-conditions-util.js | 6 +- ext/js/background/request-builder.js | 2 +- ext/js/background/script-manager.js | 3 +- ext/js/comm/anki-connect.js | 7 +- ext/js/comm/api.js | 4 +- ext/js/comm/clipboard-monitor.js | 4 +- ext/js/comm/clipboard-reader.js | 6 +- ext/js/comm/cross-frame-api.js | 5 +- ext/js/comm/frame-ancestry-handler.js | 5 +- ext/js/comm/frame-client.js | 4 +- ext/js/comm/frame-endpoint.js | 5 +- ext/js/comm/frame-offset-forwarder.js | 7 +- ext/js/comm/mecab.js | 4 +- ext/js/core.js | 34 ++++----- ext/js/data/anki-note-builder.js | 10 +-- ext/js/data/anki-util.js | 4 +- ext/js/data/database.js | 2 +- ext/js/data/json-schema.js | 7 +- ext/js/data/options-util.js | 9 ++- ext/js/data/permissions-util.js | 6 +- ext/js/data/sandbox/anki-note-data-creator.js | 6 +- ext/js/data/sandbox/array-buffer-util.js | 2 +- ext/js/data/sandbox/string-util.js | 2 +- ext/js/debug/timer.js | 2 +- ext/js/display/display-anki.js | 12 ++-- ext/js/display/display-audio.js | 7 +- ext/js/display/display-content-manager.js | 8 +-- ext/js/display/display-generator.js | 16 ++--- ext/js/display/display-history.js | 4 +- ext/js/display/display-notification.js | 4 +- ext/js/display/display-profile-selection.js | 8 +-- ext/js/display/display-resizer.js | 4 +- ext/js/display/display.js | 42 ++++++----- ext/js/display/element-overflow-controller.js | 4 +- ext/js/display/option-toggle-hotkey-handler.js | 5 +- ext/js/display/popup-main.js | 11 +++ ext/js/display/query-parser.js | 8 +-- ext/js/display/sandbox/pronunciation-generator.js | 2 +- .../sandbox/structured-content-generator.js | 2 +- ext/js/display/search-action-popup-controller.js | 2 +- ext/js/display/search-display-controller.js | 10 +-- ext/js/display/search-main.js | 24 +++---- .../display/search-persistent-state-controller.js | 4 +- ext/js/dom/document-focus-controller.js | 2 +- ext/js/dom/document-util.js | 11 ++- ext/js/dom/dom-data-binder.js | 10 ++- ext/js/dom/dom-text-scanner.js | 6 +- ext/js/dom/html-template-collection.js | 2 +- ext/js/dom/native-simple-dom-parser.js | 2 +- ext/js/dom/panel-element.js | 4 +- ext/js/dom/popup-menu.js | 4 +- ext/js/dom/sandbox/css-style-applier.js | 2 +- ext/js/dom/scroll-element.js | 2 +- ext/js/dom/selector-observer.js | 2 +- ext/js/dom/simple-dom-parser.js | 6 +- ext/js/dom/text-source-element.js | 9 ++- ext/js/dom/text-source-range.js | 9 ++- ext/js/extension/environment.js | 2 +- ext/js/general/cache-map.js | 3 +- ext/js/general/object-property-accessor.js | 2 +- ext/js/general/regex-util.js | 3 +- ext/js/general/task-accumulator.js | 4 +- ext/js/general/text-source-map.js | 2 +- ext/js/input/hotkey-handler.js | 8 +-- ext/js/input/hotkey-help-controller.js | 8 +-- ext/js/input/hotkey-util.js | 2 +- ext/js/language/deinflector.js | 2 +- ext/js/language/dictionary-database.js | 7 +- .../language/dictionary-importer-media-loader.js | 4 +- ext/js/language/dictionary-importer.js | 83 ++++++++++++---------- ext/js/language/dictionary-worker-handler.js | 11 ++- ext/js/language/dictionary-worker-main.js | 18 +---- ext/js/language/dictionary-worker-media-loader.js | 4 +- ext/js/language/dictionary-worker.js | 9 ++- ext/js/language/sandbox/dictionary-data-util.js | 2 +- ext/js/language/sandbox/japanese-util.js | 2 +- ext/js/language/text-scanner.js | 8 +-- ext/js/language/translator.js | 11 ++- ext/js/media/audio-downloader.js | 14 ++-- ext/js/media/audio-system.js | 7 +- ext/js/media/media-util.js | 2 +- ext/js/media/text-to-speech-audio.js | 2 +- ext/js/pages/action-popup-main.js | 9 ++- .../pages/common/extension-content-controller.js | 6 +- ext/js/pages/generic-page-main.js | 6 +- ext/js/pages/info-main.js | 10 +-- ext/js/pages/permissions-main.js | 20 +++--- ext/js/pages/settings/anki-controller.js | 16 ++--- ext/js/pages/settings/anki-templates-controller.js | 10 +-- ext/js/pages/settings/audio-controller.js | 7 +- ext/js/pages/settings/backup-controller.js | 16 ++--- .../settings/collapsible-dictionary-controller.js | 7 +- ext/js/pages/settings/dictionary-controller.js | 6 +- .../pages/settings/dictionary-import-controller.js | 10 +-- .../extension-keyboard-shortcuts-controller.js | 10 +-- .../pages/settings/generic-setting-controller.js | 9 ++- .../pages/settings/keyboard-mouse-input-field.js | 9 ++- .../settings/keyboard-shortcuts-controller.js | 12 ++-- ext/js/pages/settings/mecab-controller.js | 4 +- ext/js/pages/settings/modal-controller.js | 6 +- ext/js/pages/settings/modal.js | 6 +- ext/js/pages/settings/nested-popups-controller.js | 6 +- .../settings/permissions-origin-controller.js | 4 +- .../settings/permissions-toggle-controller.js | 6 +- .../settings/persistent-storage-controller.js | 5 +- ext/js/pages/settings/popup-preview-controller.js | 2 +- ext/js/pages/settings/popup-preview-frame-main.js | 6 ++ ext/js/pages/settings/popup-preview-frame.js | 11 ++- ext/js/pages/settings/popup-window-controller.js | 4 +- ext/js/pages/settings/profile-conditions-ui.js | 7 +- ext/js/pages/settings/profile-controller.js | 8 +-- .../settings/recommended-permissions-controller.js | 4 +- ext/js/pages/settings/scan-inputs-controller.js | 8 +-- .../settings/scan-inputs-simple-controller.js | 11 ++- .../secondary-search-dictionary-controller.js | 7 +- .../sentence-termination-characters-controller.js | 4 +- ext/js/pages/settings/settings-controller.js | 12 ++-- .../pages/settings/settings-display-controller.js | 10 ++- ext/js/pages/settings/settings-main.js | 64 ++++++++--------- .../sort-frequency-dictionary-controller.js | 4 +- ext/js/pages/settings/status-footer.js | 6 +- ext/js/pages/settings/storage-controller.js | 4 +- .../translation-text-replacements-controller.js | 4 +- ext/js/pages/welcome-main.js | 26 +++---- ext/js/script/dynamic-loader-sentinel.js | 2 + ext/js/script/dynamic-loader.js | 5 +- .../anki-template-renderer-content-manager.js | 2 +- ext/js/templates/sandbox/anki-template-renderer.js | 12 +++- .../sandbox/template-renderer-frame-api.js | 2 +- .../sandbox/template-renderer-frame-main.js | 6 +- .../sandbox/template-renderer-media-provider.js | 2 +- ext/js/templates/sandbox/template-renderer.js | 10 +-- ext/js/templates/template-patcher.js | 2 +- ext/js/templates/template-renderer-proxy.js | 4 +- ext/js/yomichan.js | 9 ++- 149 files changed, 665 insertions(+), 579 deletions(-) create mode 100644 ext/js/app/content-script-wrapper.js (limited to 'ext/js') diff --git a/ext/js/accessibility/accessibility-controller.js b/ext/js/accessibility/accessibility-controller.js index aa27cbf4..e9a24880 100644 --- a/ext/js/accessibility/accessibility-controller.js +++ b/ext/js/accessibility/accessibility-controller.js @@ -16,10 +16,13 @@ * along with this program. If not, see . */ +import {ScriptManager} from '../background/script-manager.js'; +import {log} from '../core.js'; + /** * This class controls the registration of accessibility handlers. */ -class AccessibilityController { +export class AccessibilityController { /** * Creates a new instance. * @param {ScriptManager} scriptManager An instance of the `ScriptManager` class. diff --git a/ext/js/accessibility/google-docs-util.js b/ext/js/accessibility/google-docs-util.js index 3d9818ef..e170f334 100644 --- a/ext/js/accessibility/google-docs-util.js +++ b/ext/js/accessibility/google-docs-util.js @@ -16,15 +16,14 @@ * along with this program. If not, see . */ -/* global - * DocumentUtil - * TextSourceRange - */ +import {DocumentUtil} from '../dom/document-util.js'; +import {TextSourceElement} from '../dom/text-source-element.js'; +import {TextSourceRange} from '../dom/text-source-range.js'; /** * This class is a helper for handling Google Docs content in content scripts. */ -class GoogleDocsUtil { +export class GoogleDocsUtil { /** * Scans the document for text or elements with text information at the given coordinate. * Coordinates are provided in [client space](https://developer.mozilla.org/en-US/docs/Web/CSS/CSSOM_View/Coordinate_systems). diff --git a/ext/js/app/content-script-main.js b/ext/js/app/content-script-main.js index 0006a244..d5ae0d93 100644 --- a/ext/js/app/content-script-main.js +++ b/ext/js/app/content-script-main.js @@ -16,11 +16,11 @@ * along with this program. If not, see . */ -/* global - * Frontend - * HotkeyHandler - * PopupFactory - */ +import {log} from '../core.js'; +import {HotkeyHandler} from '../input/hotkey-handler.js'; +import {yomichan} from '../yomichan.js'; +import {Frontend} from './frontend.js'; +import {PopupFactory} from './popup-factory.js'; (async () => { try { diff --git a/ext/js/app/content-script-wrapper.js b/ext/js/app/content-script-wrapper.js new file mode 100644 index 00000000..ac921c19 --- /dev/null +++ b/ext/js/app/content-script-wrapper.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * Copyright (C) 2019-2022 Yomichan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +(async () => { + const src = chrome.runtime.getURL('js/app/content-script-main.js'); + // eslint-disable-next-line no-unsanitized/method + const contentMain = await import(src); + contentMain.main(); +})(); diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index dc16701d..acc70667 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -16,17 +16,21 @@ * along with this program. If not, see . */ -/* global - * DocumentUtil - * GoogleDocsUtil - * TextScanner - * TextSourceRange - */ +import {GoogleDocsUtil} from '../accessibility/google-docs-util.js'; +import {EventListenerCollection, invokeMessageHandler, isObject, log, promiseAnimationFrame} from '../core.js'; +import {DocumentUtil} from '../dom/document-util.js'; +import {TextSourceElement} from '../dom/text-source-element.js'; +import {TextSourceRange} from '../dom/text-source-range.js'; +import {HotkeyHandler} from '../input/hotkey-handler.js'; +import {TextScanner} from '../language/text-scanner.js'; +import {yomichan} from '../yomichan.js'; +import {PopupFactory} from './popup-factory.js'; +import {Popup} from './popup.js'; /** * This is the main class responsible for scanning and handling webpage content. */ -class Frontend { +export class Frontend { /** * Creates a new instance. * @param {object} details Details about how to set up the instance. diff --git a/ext/js/app/popup-factory.js b/ext/js/app/popup-factory.js index c3c98162..7a17c106 100644 --- a/ext/js/app/popup-factory.js +++ b/ext/js/app/popup-factory.js @@ -16,17 +16,17 @@ * along with this program. If not, see . */ -/* global - * FrameOffsetForwarder - * Popup - * PopupProxy - * PopupWindow - */ +import {FrameOffsetForwarder} from '../comm/frame-offset-forwarder.js'; +import {generateId} from '../core.js'; +import {yomichan} from '../yomichan.js'; +import {PopupProxy} from './popup-proxy.js'; +import {PopupWindow} from './popup-window.js'; +import {Popup} from './popup.js'; /** * A class which is used to generate and manage popups. */ -class PopupFactory { +export class PopupFactory { /** * Creates a new instance. * @param {number} frameId The frame ID of the host frame. diff --git a/ext/js/app/popup-proxy.js b/ext/js/app/popup-proxy.js index e7e51ddf..d16a16f1 100644 --- a/ext/js/app/popup-proxy.js +++ b/ext/js/app/popup-proxy.js @@ -16,11 +16,16 @@ * along with this program. If not, see . */ +import {FrameOffsetForwarder} from '../comm/frame-offset-forwarder.js'; +import {EventDispatcher, log} from '../core.js'; +import {yomichan} from '../yomichan.js'; +import {Popup} from './popup.js'; + /** * This class is a proxy for a Popup that is hosted in a different frame. * It effectively forwards all API calls to the underlying Popup. */ -class PopupProxy extends EventDispatcher { +export class PopupProxy extends EventDispatcher { /** * Creates a new instance. * @param {object} details Details about how to set up the instance. diff --git a/ext/js/app/popup-window.js b/ext/js/app/popup-window.js index 32e8b250..b5fd9eb6 100644 --- a/ext/js/app/popup-window.js +++ b/ext/js/app/popup-window.js @@ -16,10 +16,14 @@ * along with this program. If not, see . */ +import {EventDispatcher} from '../core.js'; +import {yomichan} from '../yomichan.js'; +import {Popup} from './popup.js'; + /** * This class represents a popup that is hosted in a new native window. */ -class PopupWindow extends EventDispatcher { +export class PopupWindow extends EventDispatcher { /** * Creates a new instance. * @param {object} details Details about how to set up the instance. diff --git a/ext/js/app/popup.js b/ext/js/app/popup.js index 8d140064..6f1807a6 100644 --- a/ext/js/app/popup.js +++ b/ext/js/app/popup.js @@ -16,17 +16,17 @@ * along with this program. If not, see . */ -/* global - * DocumentUtil - * FrameClient - * ThemeController - * dynamicLoader - */ +import {FrameClient} from '../comm/frame-client.js'; +import {DynamicProperty, EventDispatcher, EventListenerCollection, deepEqual} from '../core.js'; +import {DocumentUtil} from '../dom/document-util.js'; +import {dynamicLoader} from '../script/dynamic-loader.js'; +import {yomichan} from '../yomichan.js'; +import {ThemeController} from './theme-controller.js'; /** * This class is the container which hosts the display of search results. */ -class Popup extends EventDispatcher { +export class Popup extends EventDispatcher { /** * Information about how popup content should be shown, specifically related to the outer popup frame. * @typedef {object} ContentDetails diff --git a/ext/js/app/theme-controller.js b/ext/js/app/theme-controller.js index f8d5410b..f403a534 100644 --- a/ext/js/app/theme-controller.js +++ b/ext/js/app/theme-controller.js @@ -19,7 +19,7 @@ /** * This class is used to control theme attributes on DOM elements. */ -class ThemeController { +export class ThemeController { /** * Creates a new instance of the class. * @param {?Element} element A DOM element which theme properties are applied to. diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 8e8e6945..cccfcbb3 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -16,34 +16,34 @@ * along with this program. If not, see . */ -/* global - * AccessibilityController - * AnkiConnect - * AnkiUtil - * ArrayBufferUtil - * AudioDownloader - * ClipboardMonitor - * ClipboardReader - * DictionaryDatabase - * Environment - * JapaneseUtil - * Mecab - * MediaUtil - * ObjectPropertyAccessor - * OptionsUtil - * PermissionsUtil - * ProfileConditionsUtil - * RequestBuilder - * ScriptManager - * Translator - * wanakana - */ +import * as wanakana from '../../lib/wanakana.js'; +import {AccessibilityController} from '../accessibility/accessibility-controller.js'; +import {AnkiConnect} from '../comm/anki-connect.js'; +import {ClipboardMonitor} from '../comm/clipboard-monitor.js'; +import {ClipboardReader} from '../comm/clipboard-reader.js'; +import {Mecab} from '../comm/mecab.js'; +import {clone, deferPromise, deserializeError, generateId, invokeMessageHandler, isObject, log, promiseTimeout, serializeError} from '../core.js'; +import {AnkiUtil} from '../data/anki-util.js'; +import {OptionsUtil} from '../data/options-util.js'; +import {PermissionsUtil} from '../data/permissions-util.js'; +import {ArrayBufferUtil} from '../data/sandbox/array-buffer-util.js'; +import {Environment} from '../extension/environment.js'; +import {ObjectPropertyAccessor} from '../general/object-property-accessor.js'; +import {DictionaryDatabase} from '../language/dictionary-database.js'; +import {JapaneseUtil} from '../language/sandbox/japanese-util.js'; +import {Translator} from '../language/translator.js'; +import {AudioDownloader} from '../media/audio-downloader.js'; +import {MediaUtil} from '../media/media-util.js'; +import {yomichan} from '../yomichan.js'; +import {ProfileConditionsUtil} from './profile-conditions-util.js'; +import {RequestBuilder} from './request-builder.js'; +import {ScriptManager} from './script-manager.js'; /** * This class controls the core logic of the extension, including API calls * and various forms of communication between browser tabs and external applications. */ -class Backend { +export class Backend { /** * Creates a new instance. */ diff --git a/ext/js/background/background-main.js b/ext/js/background/background-main.js index 3b1d42eb..6c30aa7a 100644 --- a/ext/js/background/background-main.js +++ b/ext/js/background/background-main.js @@ -16,9 +16,8 @@ * along with this program. If not, see . */ -/* global - * Backend - */ +import {yomichan} from '../yomichan.js'; +import {Backend} from './backend.js'; (() => { yomichan.prepare(true); diff --git a/ext/js/background/offscreen-main.js b/ext/js/background/offscreen-main.js index 808e7766..dcbf978f 100644 --- a/ext/js/background/offscreen-main.js +++ b/ext/js/background/offscreen-main.js @@ -16,9 +16,7 @@ * along with this program. If not, see . */ -/* global - * Offscreen - */ +import {Offscreen} from './offscreen.js'; (() => { new Offscreen(); diff --git a/ext/js/background/offscreen.js b/ext/js/background/offscreen.js index bc41d189..c37cdedc 100644 --- a/ext/js/background/offscreen.js +++ b/ext/js/background/offscreen.js @@ -16,15 +16,15 @@ * along with this program. If not, see . */ -/* global - * ClipboardReader - */ +import {ClipboardReader} from '../comm/clipboard-reader.js'; +import {invokeMessageHandler} from '../core.js'; +import {yomichan} from '../yomichan.js'; /** * This class controls the core logic of the extension, including API calls * and various forms of communication between browser tabs and external applications. */ -class Offscreen { +export class Offscreen { /** * Creates a new instance. */ diff --git a/ext/js/background/profile-conditions-util.js b/ext/js/background/profile-conditions-util.js index 1e2c01f8..55b287d7 100644 --- a/ext/js/background/profile-conditions-util.js +++ b/ext/js/background/profile-conditions-util.js @@ -16,14 +16,12 @@ * along with this program. If not, see . */ -/* global - * JsonSchema - */ +import {JsonSchema} from '../data/json-schema.js'; /** * Utility class to help processing profile conditions. */ -class ProfileConditionsUtil { +export class ProfileConditionsUtil { /** * A group of conditions. * @typedef {object} ProfileConditionGroup diff --git a/ext/js/background/request-builder.js b/ext/js/background/request-builder.js index 7ee89539..f4f685be 100644 --- a/ext/js/background/request-builder.js +++ b/ext/js/background/request-builder.js @@ -20,7 +20,7 @@ * This class is used to generate `fetch()` requests on the background page * with additional controls over anonymity and error handling. */ -class RequestBuilder { +export class RequestBuilder { /** * A progress callback for a fetch read. * @callback ProgressCallback diff --git a/ext/js/background/script-manager.js b/ext/js/background/script-manager.js index 694b64db..3671b854 100644 --- a/ext/js/background/script-manager.js +++ b/ext/js/background/script-manager.js @@ -16,10 +16,11 @@ * along with this program. If not, see . */ +import {isObject} from '../core.js'; /** * This class is used to manage script injection into content tabs. */ -class ScriptManager { +export class ScriptManager { /** * Creates a new instance of the class. */ diff --git a/ext/js/comm/anki-connect.js b/ext/js/comm/anki-connect.js index b5e4d16d..09838ea5 100644 --- a/ext/js/comm/anki-connect.js +++ b/ext/js/comm/anki-connect.js @@ -16,14 +16,13 @@ * along with this program. If not, see . */ -/* global - * AnkiUtil - */ +import {isObject} from '../core.js'; +import {AnkiUtil} from '../data/anki-util.js'; /** * This class controls communication with Anki via the AnkiConnect plugin. */ -class AnkiConnect { +export class AnkiConnect { /** * Creates a new instance. */ diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js index 72d2ba07..8e5cd5cc 100644 --- a/ext/js/comm/api.js +++ b/ext/js/comm/api.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class API { +import {deferPromise, deserializeError, isObject} from '../core.js'; + +export class API { constructor(yomichan) { this._yomichan = yomichan; } diff --git a/ext/js/comm/clipboard-monitor.js b/ext/js/comm/clipboard-monitor.js index fbf56432..c5046046 100644 --- a/ext/js/comm/clipboard-monitor.js +++ b/ext/js/comm/clipboard-monitor.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class ClipboardMonitor extends EventDispatcher { +import {EventDispatcher} from '../core.js'; + +export class ClipboardMonitor extends EventDispatcher { constructor({japaneseUtil, clipboardReader}) { super(); this._japaneseUtil = japaneseUtil; diff --git a/ext/js/comm/clipboard-reader.js b/ext/js/comm/clipboard-reader.js index 1ea507b8..8139cc11 100644 --- a/ext/js/comm/clipboard-reader.js +++ b/ext/js/comm/clipboard-reader.js @@ -16,14 +16,12 @@ * along with this program. If not, see . */ -/* global - * MediaUtil - */ +import {MediaUtil} from '../media/media-util.js'; /** * Class which can read text and images from the clipboard. */ -class ClipboardReader { +export class ClipboardReader { /** * Creates a new instances of a clipboard reader. * @param {object} details Details about how to set up the instance. diff --git a/ext/js/comm/cross-frame-api.js b/ext/js/comm/cross-frame-api.js index fb2a1718..c7d9ae68 100644 --- a/ext/js/comm/cross-frame-api.js +++ b/ext/js/comm/cross-frame-api.js @@ -16,6 +16,9 @@ * along with this program. If not, see . */ +import {EventDispatcher, EventListenerCollection, deserializeError, invokeMessageHandler, log, serializeError} from '../core.js'; +import {yomichan} from '../yomichan.js'; + class CrossFrameAPIPort extends EventDispatcher { constructor(otherTabId, otherFrameId, port, messageHandlers) { super(); @@ -217,7 +220,7 @@ class CrossFrameAPIPort extends EventDispatcher { } } -class CrossFrameAPI { +export class CrossFrameAPI { constructor() { this._ackTimeout = 3000; // 3 seconds this._responseTimeout = 10000; // 10 seconds diff --git a/ext/js/comm/frame-ancestry-handler.js b/ext/js/comm/frame-ancestry-handler.js index c2e79733..1934c4ac 100644 --- a/ext/js/comm/frame-ancestry-handler.js +++ b/ext/js/comm/frame-ancestry-handler.js @@ -16,13 +16,16 @@ * along with this program. If not, see . */ +import {generateId} from '../core.js'; +import {yomichan} from '../yomichan.js'; + /** * This class is used to return the ancestor frame IDs for the current frame. * This is a workaround to using the `webNavigation.getAllFrames` API, which * would require an additional permission that is otherwise unnecessary. * It is also used to track the correlation between child frame elements and their IDs. */ -class FrameAncestryHandler { +export class FrameAncestryHandler { /** * Creates a new instance. * @param {number} frameId The frame ID of the current frame the instance is instantiated in. diff --git a/ext/js/comm/frame-client.js b/ext/js/comm/frame-client.js index 46b1f502..0ca37feb 100644 --- a/ext/js/comm/frame-client.js +++ b/ext/js/comm/frame-client.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class FrameClient { +import {deferPromise, generateId, isObject} from '../core.js'; + +export class FrameClient { constructor() { this._secret = null; this._token = null; diff --git a/ext/js/comm/frame-endpoint.js b/ext/js/comm/frame-endpoint.js index dad9f40e..0e8a5c00 100644 --- a/ext/js/comm/frame-endpoint.js +++ b/ext/js/comm/frame-endpoint.js @@ -16,7 +16,10 @@ * along with this program. If not, see . */ -class FrameEndpoint { +import {EventListenerCollection, generateId, isObject} from '../core.js'; +import {yomichan} from '../yomichan.js'; + +export class FrameEndpoint { constructor() { this._secret = generateId(16); this._token = null; diff --git a/ext/js/comm/frame-offset-forwarder.js b/ext/js/comm/frame-offset-forwarder.js index 87c6a9ce..5eea2ba6 100644 --- a/ext/js/comm/frame-offset-forwarder.js +++ b/ext/js/comm/frame-offset-forwarder.js @@ -16,11 +16,10 @@ * along with this program. If not, see . */ -/* global - * FrameAncestryHandler - */ +import {yomichan} from '../yomichan.js'; +import {FrameAncestryHandler} from './frame-ancestry-handler.js'; -class FrameOffsetForwarder { +export class FrameOffsetForwarder { constructor(frameId) { this._frameId = frameId; this._frameAncestryHandler = new FrameAncestryHandler(frameId); diff --git a/ext/js/comm/mecab.js b/ext/js/comm/mecab.js index bdc8c588..50f13ddf 100644 --- a/ext/js/comm/mecab.js +++ b/ext/js/comm/mecab.js @@ -16,11 +16,13 @@ * along with this program. If not, see . */ +import {EventListenerCollection} from '../core.js'; + /** * This class is used to connect Yomichan to a native component that is * used to parse text into individual terms. */ -class Mecab { +export class Mecab { /** * The resulting data from an invocation of `parseText`. * @typedef {object} ParseResult diff --git a/ext/js/core.js b/ext/js/core.js index 1e749c7d..fb164795 100644 --- a/ext/js/core.js +++ b/ext/js/core.js @@ -21,7 +21,7 @@ * @param {*} error An error object to convert. * @returns {{name: string, message: string, stack: string, data?: *}|{value: *, hasValue: boolean}} A simple object which can be serialized by `JSON.stringify()`. */ -function serializeError(error) { +export function serializeError(error) { try { if (typeof error === 'object' && error !== null) { const result = { @@ -48,7 +48,7 @@ function serializeError(error) { * @param {{name: string, message: string, stack: string, data?: *}|{value: *, hasValue: boolean}} serializedError A simple object which was initially generated by serializeError. * @returns {Error|*} A new `Error` instance. */ -function deserializeError(serializedError) { +export function deserializeError(serializedError) { if (serializedError.hasValue) { return serializedError.value; } @@ -66,7 +66,7 @@ function deserializeError(serializedError) { * @param {*} value The value to check. * @returns {boolean} `true` if the value is an object and not an array, `false` otherwise. */ -function isObject(value) { +export function isObject(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); } @@ -76,7 +76,7 @@ function isObject(value) { * @param {string} string The string to convert to a valid regular expression. * @returns {string} The escaped string. */ -function escapeRegExp(string) { +export function escapeRegExp(string) { return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); } @@ -85,7 +85,7 @@ function escapeRegExp(string) { * @param {string} string The string to reverse. * @returns {string} The returned string, which retains proper UTF-16 surrogate pair order. */ -function stringReverse(string) { +export function stringReverse(string) { return [...string].reverse().join(''); } @@ -95,7 +95,7 @@ function stringReverse(string) { * @returns {*} A new clone of the value. * @throws An error if the value is circular and cannot be cloned. */ -const clone = (() => { +export const clone = (() => { // eslint-disable-next-line no-shadow function clone(value) { if (value === null) { return null; } @@ -168,7 +168,7 @@ const clone = (() => { * @param {*} value2 The second value to check. * @returns {boolean} `true` if the values are the same object, or deeply equal without cycles. `false` otherwise. */ -const deepEqual = (() => { +export const deepEqual = (() => { // eslint-disable-next-line no-shadow function deepEqual(value1, value2) { if (value1 === value2) { return true; } @@ -239,7 +239,7 @@ const deepEqual = (() => { * @param {number} length The number of bytes the string represents. The returned string's length will be twice as long. * @returns {string} A string of random characters. */ -function generateId(length) { +export function generateId(length) { const array = new Uint8Array(length); crypto.getRandomValues(array); let id = ''; @@ -253,7 +253,7 @@ function generateId(length) { * Creates an unresolved promise that can be resolved later, outside the promise's executor function. * @returns {{promise: Promise, resolve: Function, reject: Function}} An object `{promise, resolve, reject}`, containing the promise and the resolve/reject functions. */ -function deferPromise() { +export function deferPromise() { let resolve; let reject; const promise = new Promise((resolve2, reject2) => { @@ -269,7 +269,7 @@ function deferPromise() { * @param {*} [resolveValue] The value returned when the promise is resolved. * @returns {Promise} A promise with two additional properties: `resolve` and `reject`, which can be used to complete the promise early. */ -function promiseTimeout(delay, resolveValue) { +export function promiseTimeout(delay, resolveValue) { if (delay <= 0) { const promise = Promise.resolve(resolveValue); promise.resolve = () => {}; // NOP @@ -312,7 +312,7 @@ function promiseTimeout(delay, resolveValue) { * and `timeout` is a boolean indicating whether the cause was a timeout or not. * @throws The promise throws an error if animation is not supported in this context, such as in a service worker. */ -function promiseAnimationFrame(timeout=null) { +export function promiseAnimationFrame(timeout=null) { return new Promise((resolve, reject) => { if (typeof cancelAnimationFrame !== 'function' || typeof requestAnimationFrame !== 'function') { reject(new Error('Animation not supported in this context')); @@ -362,7 +362,7 @@ function promiseAnimationFrame(timeout=null) { * @param {...*} extraArgs Additional arguments which are passed to the `handler` function. * @returns {boolean} `true` if the function is invoked asynchronously, `false` otherwise. */ -function invokeMessageHandler({handler, async}, params, callback, ...extraArgs) { +export function invokeMessageHandler({handler, async}, params, callback, ...extraArgs) { try { let promiseOrResult = handler(params, ...extraArgs); if (async === 'dynamic') { @@ -387,7 +387,7 @@ function invokeMessageHandler({handler, async}, params, callback, ...extraArgs) /** * Base class controls basic event dispatching. */ -class EventDispatcher { +export class EventDispatcher { /** * Creates a new instance. */ @@ -462,7 +462,7 @@ class EventDispatcher { /** * Class which stores event listeners added to various objects, making it easy to remove them in bulk. */ -class EventListenerCollection { +export class EventListenerCollection { /** * Creates a new instance. */ @@ -551,7 +551,7 @@ class EventListenerCollection { * Class representing a generic value with an override stack. * Changes can be observed by listening to the 'change' event. */ -class DynamicProperty extends EventDispatcher { +export class DynamicProperty extends EventDispatcher { /** * Creates a new instance with the specified value. * @param {*} value The value to assign. @@ -657,7 +657,7 @@ class DynamicProperty extends EventDispatcher { * This class handles logging of messages to the console and triggering * an event for log calls. */ -class Logger extends EventDispatcher { +export class Logger extends EventDispatcher { /** * Creates a new instance. */ @@ -759,4 +759,4 @@ class Logger extends EventDispatcher { /** * This object is the default logger used by the runtime. */ -const log = new Logger(); +export const log = new Logger(); diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js index c1b58cc2..7fbbf03c 100644 --- a/ext/js/data/anki-note-builder.js +++ b/ext/js/data/anki-note-builder.js @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -/* global - * AnkiUtil - * TemplateRendererProxy - */ +import {deferPromise, deserializeError} from '../core.js'; +import {TemplateRendererProxy} from '../templates/template-renderer-proxy.js'; +import {yomichan} from '../yomichan.js'; +import {AnkiUtil} from './anki-util.js'; -class AnkiNoteBuilder { +export class AnkiNoteBuilder { constructor({japaneseUtil}) { this._japaneseUtil = japaneseUtil; this._markerPattern = AnkiUtil.cloneFieldMarkerPattern(true); diff --git a/ext/js/data/anki-util.js b/ext/js/data/anki-util.js index 3b433dc9..c08b562e 100644 --- a/ext/js/data/anki-util.js +++ b/ext/js/data/anki-util.js @@ -16,10 +16,12 @@ * along with this program. If not, see . */ +import {isObject} from '../core.js'; + /** * This class has some general utility functions for working with Anki data. */ -class AnkiUtil { +export class AnkiUtil { /** * Gets the root deck name of a full deck name. If the deck is a root deck, * the same name is returned. Nested decks are separated using '::'. diff --git a/ext/js/data/database.js b/ext/js/data/database.js index 205f6385..8e818d8b 100644 --- a/ext/js/data/database.js +++ b/ext/js/data/database.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -class Database { +export class Database { constructor() { this._db = null; this._isOpening = false; diff --git a/ext/js/data/json-schema.js b/ext/js/data/json-schema.js index c22a0e1a..93c8cd59 100644 --- a/ext/js/data/json-schema.js +++ b/ext/js/data/json-schema.js @@ -16,11 +16,10 @@ * along with this program. If not, see . */ -/* global - * CacheMap - */ +import {clone} from '../core.js'; +import {CacheMap} from '../general/cache-map.js'; -class JsonSchema { +export class JsonSchema { constructor(schema, rootSchema) { this._schema = null; this._startSchema = schema; diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index e0cd0362..42e31b5f 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -16,12 +16,11 @@ * along with this program. If not, see . */ -/* global - * JsonSchema - * TemplatePatcher - */ +import {escapeRegExp, isObject} from '../core.js'; +import {TemplatePatcher} from '../templates/template-patcher.js'; +import {JsonSchema} from './json-schema.js'; -class OptionsUtil { +export class OptionsUtil { constructor() { this._templatePatcher = null; this._optionsSchema = null; diff --git a/ext/js/data/permissions-util.js b/ext/js/data/permissions-util.js index afec470c..d645f21e 100644 --- a/ext/js/data/permissions-util.js +++ b/ext/js/data/permissions-util.js @@ -16,11 +16,9 @@ * along with this program. If not, see . */ -/* global - * AnkiUtil - */ +import {AnkiUtil} from './anki-util.js'; -class PermissionsUtil { +export class PermissionsUtil { constructor() { this._ankiFieldMarkersRequiringClipboardPermission = new Set([ 'clipboard-image', diff --git a/ext/js/data/sandbox/anki-note-data-creator.js b/ext/js/data/sandbox/anki-note-data-creator.js index 33b4af6f..371a62a2 100644 --- a/ext/js/data/sandbox/anki-note-data-creator.js +++ b/ext/js/data/sandbox/anki-note-data-creator.js @@ -16,15 +16,13 @@ * along with this program. If not, see . */ -/* global - * DictionaryDataUtil - */ +import {DictionaryDataUtil} from '../../language/sandbox/dictionary-data-util.js'; /** * This class is used to convert the internal dictionary entry format to the * format used by Anki, for backwards compatibility. */ -class AnkiNoteDataCreator { +export class AnkiNoteDataCreator { /** * Creates a new instance. * @param {JapaneseUtil} japaneseUtil An instance of `JapaneseUtil`. diff --git a/ext/js/data/sandbox/array-buffer-util.js b/ext/js/data/sandbox/array-buffer-util.js index f96406bc..20715bd6 100644 --- a/ext/js/data/sandbox/array-buffer-util.js +++ b/ext/js/data/sandbox/array-buffer-util.js @@ -19,7 +19,7 @@ /** * Class containing generic ArrayBuffer utility functions. */ -class ArrayBufferUtil { +export class ArrayBufferUtil { /** * Decodes the contents of an ArrayBuffer using UTF8. * @param {ArrayBuffer} arrayBuffer The input ArrayBuffer. diff --git a/ext/js/data/sandbox/string-util.js b/ext/js/data/sandbox/string-util.js index c158fd1a..096ecffe 100644 --- a/ext/js/data/sandbox/string-util.js +++ b/ext/js/data/sandbox/string-util.js @@ -19,7 +19,7 @@ /** * Class containing generic string utility functions. */ -class StringUtil { +export class StringUtil { /** * Reads code points from a string in the forward direction. * @param {string} text The text to read the code points from. diff --git a/ext/js/debug/timer.js b/ext/js/debug/timer.js index f57e9e79..acf3621b 100644 --- a/ext/js/debug/timer.js +++ b/ext/js/debug/timer.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -class Timer { +export class Timer { constructor(name) { this.samples = []; this.parent = null; diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js index 9a1aae23..a25008a2 100644 --- a/ext/js/display/display-anki.js +++ b/ext/js/display/display-anki.js @@ -16,13 +16,13 @@ * along with this program. If not, see . */ -/* global - * AnkiNoteBuilder - * AnkiUtil - * PopupMenu - */ +import {EventListenerCollection, deferPromise, isObject} from '../core.js'; +import {AnkiNoteBuilder} from '../data/anki-note-builder.js'; +import {AnkiUtil} from '../data/anki-util.js'; +import {PopupMenu} from '../dom/popup-menu.js'; +import {yomichan} from '../yomichan.js'; -class DisplayAnki { +export class DisplayAnki { constructor(display, displayAudio, japaneseUtil) { this._display = display; this._displayAudio = displayAudio; diff --git a/ext/js/display/display-audio.js b/ext/js/display/display-audio.js index c0b3859d..6ab5773f 100644 --- a/ext/js/display/display-audio.js +++ b/ext/js/display/display-audio.js @@ -16,12 +16,17 @@ * along with this program. If not, see . */ +import {EventListenerCollection} from '../core.js'; +import {PopupMenu} from '../dom/popup-menu.js'; +import {AudioSystem} from '../media/audio-system.js'; +import {yomichan} from '../yomichan.js'; + /* global * AudioSystem * PopupMenu */ -class DisplayAudio { +export class DisplayAudio { constructor(display) { this._display = display; this._audioPlaying = null; diff --git a/ext/js/display/display-content-manager.js b/ext/js/display/display-content-manager.js index 2abff98a..6cba1783 100644 --- a/ext/js/display/display-content-manager.js +++ b/ext/js/display/display-content-manager.js @@ -16,9 +16,9 @@ * along with this program. If not, see . */ -/* global - * ArrayBufferUtil - */ +import {EventListenerCollection} from '../core.js'; +import {ArrayBufferUtil} from '../data/sandbox/array-buffer-util.js'; +import {yomichan} from '../yomichan.js'; /** * A callback used when a media file has been loaded. @@ -35,7 +35,7 @@ /** * The content manager which is used when generating HTML display content. */ -class DisplayContentManager { +export class DisplayContentManager { /** * Creates a new instance of the class. * @param {Display} display The display instance that owns this object. diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index 293cb725..25df9745 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -16,14 +16,14 @@ * along with this program. If not, see . */ -/* global - * DictionaryDataUtil - * HtmlTemplateCollection - * PronunciationGenerator - * StructuredContentGenerator - */ - -class DisplayGenerator { +import {isObject} from '../core.js'; +import {HtmlTemplateCollection} from '../dom/html-template-collection.js'; +import {DictionaryDataUtil} from '../language/sandbox/dictionary-data-util.js'; +import {yomichan} from '../yomichan.js'; +import {PronunciationGenerator} from './sandbox/pronunciation-generator.js'; +import {StructuredContentGenerator} from './sandbox/structured-content-generator.js'; + +export class DisplayGenerator { constructor({japaneseUtil, contentManager, hotkeyHelpController=null}) { this._japaneseUtil = japaneseUtil; this._contentManager = contentManager; diff --git a/ext/js/display/display-history.js b/ext/js/display/display-history.js index 71882ca3..a983346c 100644 --- a/ext/js/display/display-history.js +++ b/ext/js/display/display-history.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class DisplayHistory extends EventDispatcher { +import {EventDispatcher, generateId, isObject} from '../core.js'; + +export class DisplayHistory extends EventDispatcher { constructor({clearable=true, useBrowserHistory=false}) { super(); this._clearable = clearable; diff --git a/ext/js/display/display-notification.js b/ext/js/display/display-notification.js index d5c77b04..0c26c613 100644 --- a/ext/js/display/display-notification.js +++ b/ext/js/display/display-notification.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class DisplayNotification { +import {EventListenerCollection} from '../core.js'; + +export class DisplayNotification { constructor(container, node) { this._container = container; this._node = node; diff --git a/ext/js/display/display-profile-selection.js b/ext/js/display/display-profile-selection.js index b14b4d8b..c0b642e8 100644 --- a/ext/js/display/display-profile-selection.js +++ b/ext/js/display/display-profile-selection.js @@ -16,11 +16,11 @@ * along with this program. If not, see . */ -/* global - * PanelElement - */ +import {EventListenerCollection, generateId} from '../core.js'; +import {PanelElement} from '../dom/panel-element.js'; +import {yomichan} from '../yomichan.js'; -class DisplayProfileSelection { +export class DisplayProfileSelection { constructor(display) { this._display = display; this._profielList = document.querySelector('#profile-list'); diff --git a/ext/js/display/display-resizer.js b/ext/js/display/display-resizer.js index 1356c0a7..2925561f 100644 --- a/ext/js/display/display-resizer.js +++ b/ext/js/display/display-resizer.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class DisplayResizer { +import {EventListenerCollection} from '../core.js'; + +export class DisplayResizer { constructor(display) { this._display = display; this._token = null; diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 693bd201..39e9b5f9 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -16,26 +16,26 @@ * along with this program. If not, see . */ -/* global - * DisplayContentManager - * DisplayGenerator - * DisplayHistory - * DisplayNotification - * ElementOverflowController - * FrameEndpoint - * Frontend - * HotkeyHelpController - * OptionToggleHotkeyHandler - * PopupFactory - * PopupMenu - * QueryParser - * ScrollElement - * TextScanner - * ThemeController - * dynamicLoader - */ - -class Display extends EventDispatcher { +import {Frontend} from '../app/frontend.js'; +import {PopupFactory} from '../app/popup-factory.js'; +import {ThemeController} from '../app/theme-controller.js'; +import {FrameEndpoint} from '../comm/frame-endpoint.js'; +import {DynamicProperty, EventDispatcher, EventListenerCollection, clone, deepEqual, invokeMessageHandler, isObject, log, promiseTimeout} from '../core.js'; +import {PopupMenu} from '../dom/popup-menu.js'; +import {ScrollElement} from '../dom/scroll-element.js'; +import {HotkeyHelpController} from '../input/hotkey-help-controller.js'; +import {TextScanner} from '../language/text-scanner.js'; +import {dynamicLoader} from '../script/dynamic-loader.js'; +import {yomichan} from '../yomichan.js'; +import {DisplayContentManager} from './display-content-manager.js'; +import {DisplayGenerator} from './display-generator.js'; +import {DisplayHistory} from './display-history.js'; +import {DisplayNotification} from './display-notification.js'; +import {ElementOverflowController} from './element-overflow-controller.js'; +import {OptionToggleHotkeyHandler} from './option-toggle-hotkey-handler.js'; +import {QueryParser} from './query-parser.js'; + +export class Display extends EventDispatcher { /** * Information about how popup content should be shown, specifically related to the inner popup content. * @typedef {object} ContentDetails @@ -1652,8 +1652,6 @@ class Display extends EventDispatcher { Object.assign(result, result2); } } - - console.log(result); } _triggerContentClear() { diff --git a/ext/js/display/element-overflow-controller.js b/ext/js/display/element-overflow-controller.js index 9fb3d26f..0a62906b 100644 --- a/ext/js/display/element-overflow-controller.js +++ b/ext/js/display/element-overflow-controller.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class ElementOverflowController { +import {EventListenerCollection} from '../core.js'; + +export class ElementOverflowController { constructor() { this._elements = []; this._checkTimer = null; diff --git a/ext/js/display/option-toggle-hotkey-handler.js b/ext/js/display/option-toggle-hotkey-handler.js index 251e03fa..360b0894 100644 --- a/ext/js/display/option-toggle-hotkey-handler.js +++ b/ext/js/display/option-toggle-hotkey-handler.js @@ -16,7 +16,10 @@ * along with this program. If not, see . */ -class OptionToggleHotkeyHandler { +import {deserializeError} from '../core.js'; +import {yomichan} from '../yomichan.js'; + +export class OptionToggleHotkeyHandler { constructor(display) { this._display = display; this._notification = null; diff --git a/ext/js/display/popup-main.js b/ext/js/display/popup-main.js index 4d7c8c86..0599b736 100644 --- a/ext/js/display/popup-main.js +++ b/ext/js/display/popup-main.js @@ -16,6 +16,17 @@ * along with this program. If not, see . */ +import {log} from '../core.js'; +import {DocumentFocusController} from '../dom/document-focus-controller.js'; +import {HotkeyHandler} from '../input/hotkey-handler.js'; +import {JapaneseUtil} from '../language/sandbox/japanese-util.js'; +import {yomichan} from '../yomichan.js'; +import {DisplayAnki} from './display-anki.js'; +import {DisplayAudio} from './display-audio.js'; +import {DisplayProfileSelection} from './display-profile-selection.js'; +import {DisplayResizer} from './display-resizer.js'; +import {Display} from './display.js'; + /* global * Display * DisplayAnki diff --git a/ext/js/display/query-parser.js b/ext/js/display/query-parser.js index 205be579..6eee55b2 100644 --- a/ext/js/display/query-parser.js +++ b/ext/js/display/query-parser.js @@ -16,11 +16,11 @@ * along with this program. If not, see . */ -/* global - * TextScanner - */ +import {EventDispatcher, log} from '../core.js'; +import {TextScanner} from '../language/text-scanner.js'; +import {yomichan} from '../yomichan.js'; -class QueryParser extends EventDispatcher { +export class QueryParser extends EventDispatcher { constructor({getSearchContext, japaneseUtil}) { super(); this._getSearchContext = getSearchContext; diff --git a/ext/js/display/sandbox/pronunciation-generator.js b/ext/js/display/sandbox/pronunciation-generator.js index 027771f6..76d5e2b1 100644 --- a/ext/js/display/sandbox/pronunciation-generator.js +++ b/ext/js/display/sandbox/pronunciation-generator.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -class PronunciationGenerator { +export class PronunciationGenerator { constructor(japaneseUtil) { this._japaneseUtil = japaneseUtil; } diff --git a/ext/js/display/sandbox/structured-content-generator.js b/ext/js/display/sandbox/structured-content-generator.js index 2d3a620d..227892d6 100644 --- a/ext/js/display/sandbox/structured-content-generator.js +++ b/ext/js/display/sandbox/structured-content-generator.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -class StructuredContentGenerator { +export class StructuredContentGenerator { constructor(contentManager, japaneseUtil, document) { this._contentManager = contentManager; this._japaneseUtil = japaneseUtil; diff --git a/ext/js/display/search-action-popup-controller.js b/ext/js/display/search-action-popup-controller.js index e29ac0f4..e8fb9f1b 100644 --- a/ext/js/display/search-action-popup-controller.js +++ b/ext/js/display/search-action-popup-controller.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -class SearchActionPopupController { +export class SearchActionPopupController { constructor(searchPersistentStateController) { this._searchPersistentStateController = searchPersistentStateController; } diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js index 5a271e05..9e190c85 100644 --- a/ext/js/display/search-display-controller.js +++ b/ext/js/display/search-display-controller.js @@ -16,12 +16,12 @@ * along with this program. If not, see . */ -/* global - * ClipboardMonitor - * wanakana - */ +import * as wanakana from '../../lib/wanakana.js'; +import {ClipboardMonitor} from '../comm/clipboard-monitor.js'; +import {EventListenerCollection, invokeMessageHandler} from '../core.js'; +import {yomichan} from '../yomichan.js'; -class SearchDisplayController { +export class SearchDisplayController { constructor(tabId, frameId, display, displayAudio, japaneseUtil, searchPersistentStateController) { this._tabId = tabId; this._frameId = frameId; diff --git a/ext/js/display/search-main.js b/ext/js/display/search-main.js index 77b96804..67552229 100644 --- a/ext/js/display/search-main.js +++ b/ext/js/display/search-main.js @@ -16,18 +16,18 @@ * along with this program. If not, see . */ -/* global - * Display - * DisplayAnki - * DisplayAudio - * DocumentFocusController - * HotkeyHandler - * JapaneseUtil - * SearchActionPopupController - * SearchDisplayController - * SearchPersistentStateController - * wanakana - */ +import * as wanakana from '../../lib/wanakana.js'; +import {log} from '../core.js'; +import {DocumentFocusController} from '../dom/document-focus-controller.js'; +import {HotkeyHandler} from '../input/hotkey-handler.js'; +import {JapaneseUtil} from '../language/sandbox/japanese-util.js'; +import {yomichan} from '../yomichan.js'; +import {DisplayAnki} from './display-anki.js'; +import {DisplayAudio} from './display-audio.js'; +import {Display} from './display.js'; +import {SearchActionPopupController} from './search-action-popup-controller.js'; +import {SearchDisplayController} from './search-display-controller.js'; +import {SearchPersistentStateController} from './search-persistent-state-controller.js'; (async () => { try { diff --git a/ext/js/display/search-persistent-state-controller.js b/ext/js/display/search-persistent-state-controller.js index 2b651ffa..60155143 100644 --- a/ext/js/display/search-persistent-state-controller.js +++ b/ext/js/display/search-persistent-state-controller.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class SearchPersistentStateController extends EventDispatcher { +import {EventDispatcher} from '../core.js'; + +export class SearchPersistentStateController extends EventDispatcher { constructor() { super(); this._mode = null; diff --git a/ext/js/dom/document-focus-controller.js b/ext/js/dom/document-focus-controller.js index 937a7c13..501d1fad 100644 --- a/ext/js/dom/document-focus-controller.js +++ b/ext/js/dom/document-focus-controller.js @@ -22,7 +22,7 @@ * keyboard shortcuts (e.g. arrow keys) not controlling page scroll. Instead, this class will manually * focus a dummy element inside the main content, which gives keyboard scroll focus to that element. */ -class DocumentFocusController { +export class DocumentFocusController { /** * Creates a new instance of the class. * @param {?string} autofocusElementSelector A selector string which can be used to specify an element which diff --git a/ext/js/dom/document-util.js b/ext/js/dom/document-util.js index 9bca951b..d379192c 100644 --- a/ext/js/dom/document-util.js +++ b/ext/js/dom/document-util.js @@ -16,16 +16,15 @@ * along with this program. If not, see . */ -/* global - * DOMTextScanner - * TextSourceElement - * TextSourceRange - */ +import {EventListenerCollection} from '../core.js'; +import {DOMTextScanner} from './dom-text-scanner.js'; +import {TextSourceElement} from './text-source-element.js'; +import {TextSourceRange} from './text-source-range.js'; /** * This class contains utility functions related to the HTML document. */ -class DocumentUtil { +export class DocumentUtil { /** * Options to configure how element detection is performed. * @typedef {object} GetRangeFromPointOptions diff --git a/ext/js/dom/dom-data-binder.js b/ext/js/dom/dom-data-binder.js index fca5cd9f..4da5b0c2 100644 --- a/ext/js/dom/dom-data-binder.js +++ b/ext/js/dom/dom-data-binder.js @@ -16,13 +16,11 @@ * along with this program. If not, see . */ -/* global - * DocumentUtil - * SelectorObserver - * TaskAccumulator - */ +import {TaskAccumulator} from '../general/task-accumulator.js'; +import {DocumentUtil} from './document-util.js'; +import {SelectorObserver} from './selector-observer.js'; -class DOMDataBinder { +export class DOMDataBinder { constructor({selector, createElementMetadata, compareElementMetadata, getValues, setValues, onError=null}) { this._selector = selector; this._createElementMetadata = createElementMetadata; diff --git a/ext/js/dom/dom-text-scanner.js b/ext/js/dom/dom-text-scanner.js index ec4c7bd6..ccd1c90b 100644 --- a/ext/js/dom/dom-text-scanner.js +++ b/ext/js/dom/dom-text-scanner.js @@ -16,14 +16,12 @@ * along with this program. If not, see . */ -/* global - * StringUtil - */ +import {StringUtil} from '../data/sandbox/string-util.js'; /** * A class used to scan text in a document. */ -class DOMTextScanner { +export class DOMTextScanner { /** * Creates a new instance of a DOMTextScanner. * @param {Node} node The DOM Node to start at. diff --git a/ext/js/dom/html-template-collection.js b/ext/js/dom/html-template-collection.js index 4cdcf938..100ba55c 100644 --- a/ext/js/dom/html-template-collection.js +++ b/ext/js/dom/html-template-collection.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -class HtmlTemplateCollection { +export class HtmlTemplateCollection { constructor(source) { this._templates = new Map(); diff --git a/ext/js/dom/native-simple-dom-parser.js b/ext/js/dom/native-simple-dom-parser.js index 245386bd..882469a0 100644 --- a/ext/js/dom/native-simple-dom-parser.js +++ b/ext/js/dom/native-simple-dom-parser.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -class NativeSimpleDOMParser { +export class NativeSimpleDOMParser { constructor(content) { this._document = new DOMParser().parseFromString(content, 'text/html'); } diff --git a/ext/js/dom/panel-element.js b/ext/js/dom/panel-element.js index ac283d02..9b056920 100644 --- a/ext/js/dom/panel-element.js +++ b/ext/js/dom/panel-element.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class PanelElement extends EventDispatcher { +import {EventDispatcher} from '../core.js'; + +export class PanelElement extends EventDispatcher { constructor({node, closingAnimationDuration}) { super(); this._node = node; diff --git a/ext/js/dom/popup-menu.js b/ext/js/dom/popup-menu.js index 4ab1e049..7cae1dff 100644 --- a/ext/js/dom/popup-menu.js +++ b/ext/js/dom/popup-menu.js @@ -16,7 +16,9 @@ * along with this program. If not, see . */ -class PopupMenu extends EventDispatcher { +import {EventDispatcher, EventListenerCollection} from '../core.js'; + +export class PopupMenu extends EventDispatcher { constructor(sourceElement, containerNode) { super(); this._sourceElement = sourceElement; diff --git a/ext/js/dom/sandbox/css-style-applier.js b/ext/js/dom/sandbox/css-style-applier.js index a47ef6ef..4f570bb7 100644 --- a/ext/js/dom/sandbox/css-style-applier.js +++ b/ext/js/dom/sandbox/css-style-applier.js @@ -20,7 +20,7 @@ * This class is used to apply CSS styles to elements using a consistent method * that is the same across different browsers. */ -class CssStyleApplier { +export class CssStyleApplier { /** * A CSS rule. * @typedef {object} CssRule diff --git a/ext/js/dom/scroll-element.js b/ext/js/dom/scroll-element.js index e7526db0..4b2ac70d 100644 --- a/ext/js/dom/scroll-element.js +++ b/ext/js/dom/scroll-element.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -class ScrollElement { +export class ScrollElement { constructor(node) { this._node = node; this._animationRequestId = null; diff --git a/ext/js/dom/selector-observer.js b/ext/js/dom/selector-observer.js index 56f97202..e0e3d4ff 100644 --- a/ext/js/dom/selector-observer.js +++ b/ext/js/dom/selector-observer.js @@ -19,7 +19,7 @@ /** * Class which is used to observe elements matching a selector in specific element. */ -class SelectorObserver { +export class SelectorObserver { /** * @function OnAddedCallback * @param {Element} element The element which was added. diff --git a/ext/js/dom/simple-dom-parser.js b/ext/js/dom/simple-dom-parser.js index 266a465c..3e84b783 100644 --- a/ext/js/dom/simple-dom-parser.js +++ b/ext/js/dom/simple-dom-parser.js @@ -16,11 +16,9 @@ * along with this program. If not, see . */ -/* globals - * parse5 - */ +import * as parse5 from '../../lib/parse5.js'; -class SimpleDOMParser { +export class SimpleDOMParser { constructor(content) { this._document = parse5.parse(content); this._patternHtmlWhitespace = /[\t\r\n\f ]+/g; diff --git a/ext/js/dom/text-source-element.js b/ext/js/dom/text-source-element.js index e37a3582..95534975 100644 --- a/ext/js/dom/text-source-element.js +++ b/ext/js/dom/text-source-element.js @@ -16,16 +16,15 @@ * along with this program. If not, see . */ -/* global - * DocumentUtil - * StringUtil - */ +import {StringUtil} from '../data/sandbox/string-util.js'; +import {DocumentUtil} from './document-util.js'; +import {TextSourceRange} from './text-source-range.js'; /** * This class represents a text source that is attached to a HTML element, such as an * with alt text or a