From 4da4827bcbcdd1ef163f635d9b29416ff272b0bb Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 27 Nov 2023 12:48:14 -0500 Subject: Add JSDoc type annotations to project (rebased) --- ext/js/display/sandbox/pronunciation-generator.js | 56 +++++++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) (limited to 'ext/js/display/sandbox/pronunciation-generator.js') diff --git a/ext/js/display/sandbox/pronunciation-generator.js b/ext/js/display/sandbox/pronunciation-generator.js index 76d5e2b1..eeedc574 100644 --- a/ext/js/display/sandbox/pronunciation-generator.js +++ b/ext/js/display/sandbox/pronunciation-generator.js @@ -17,10 +17,21 @@ */ export class PronunciationGenerator { + /** + * @param {JapaneseUtil} japaneseUtil + */ constructor(japaneseUtil) { + /** @type {JapaneseUtil} */ this._japaneseUtil = japaneseUtil; } + /** + * @param {string[]} morae + * @param {number} downstepPosition + * @param {number[]} nasalPositions + * @param {number[]} devoicePositions + * @returns {HTMLSpanElement} + */ createPronunciationText(morae, downstepPosition, nasalPositions, devoicePositions) { const jp = this._japaneseUtil; const nasalPositionsSet = nasalPositions.length > 0 ? new Set(nasalPositions) : null; @@ -63,7 +74,7 @@ export class PronunciationGenerator { group.className = 'pronunciation-character-group'; const n2 = characterNodes[0]; - const character = n2.textContent; + const character = /** @type {string} */ (n2.textContent); const characterInfo = jp.getKanaDiacriticInfo(character); if (characterInfo !== null) { @@ -81,7 +92,7 @@ export class PronunciationGenerator { n3.className = 'pronunciation-nasal-indicator'; group.appendChild(n3); - n2.parentNode.replaceChild(group, n2); + /** @type {ParentNode} */ (n2.parentNode).replaceChild(group, n2); group.insertBefore(n2, group.firstChild); } @@ -94,6 +105,11 @@ export class PronunciationGenerator { return container; } + /** + * @param {string[]} morae + * @param {number} downstepPosition + * @returns {SVGSVGElement} + */ createPronunciationGraph(morae, downstepPosition) { const jp = this._japaneseUtil; const ii = morae.length; @@ -145,12 +161,16 @@ export class PronunciationGenerator { return svg; } + /** + * @param {number} downstepPosition + * @returns {HTMLSpanElement} + */ createPronunciationDownstepPosition(downstepPosition) { - downstepPosition = `${downstepPosition}`; + const downstepPositionString = `${downstepPosition}`; const n1 = document.createElement('span'); n1.className = 'pronunciation-downstep-notation'; - n1.dataset.downstepPosition = downstepPosition; + n1.dataset.downstepPosition = downstepPositionString; let n2 = document.createElement('span'); n2.className = 'pronunciation-downstep-notation-prefix'; @@ -159,7 +179,7 @@ export class PronunciationGenerator { n2 = document.createElement('span'); n2.className = 'pronunciation-downstep-notation-number'; - n2.textContent = downstepPosition; + n2.textContent = downstepPositionString; n1.appendChild(n2); n2 = document.createElement('span'); @@ -172,15 +192,33 @@ export class PronunciationGenerator { // Private + /** + * @param {Element} container + * @param {string} svgns + * @param {number} x + * @param {number} y + */ _addGraphDot(container, svgns, x, y) { container.appendChild(this._createGraphCircle(svgns, 'pronunciation-graph-dot', x, y, '15')); } + /** + * @param {Element} container + * @param {string} svgns + * @param {number} x + * @param {number} y + */ _addGraphDotDownstep(container, svgns, x, y) { container.appendChild(this._createGraphCircle(svgns, 'pronunciation-graph-dot-downstep1', x, y, '15')); container.appendChild(this._createGraphCircle(svgns, 'pronunciation-graph-dot-downstep2', x, y, '5')); } + /** + * @param {Element} container + * @param {string} svgns + * @param {number} x + * @param {number} y + */ _addGraphTriangle(container, svgns, x, y) { const node = document.createElementNS(svgns, 'path'); node.setAttribute('class', 'pronunciation-graph-triangle'); @@ -189,6 +227,14 @@ export class PronunciationGenerator { container.appendChild(node); } + /** + * @param {string} svgns + * @param {string} className + * @param {number} x + * @param {number} y + * @param {string} radius + * @returns {Element} + */ _createGraphCircle(svgns, className, x, y, radius) { const node = document.createElementNS(svgns, 'circle'); node.setAttribute('class', className); -- cgit v1.2.3 From ac562ca36417f2d9fdb860d1f8a879fdccde438d Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 27 Nov 2023 15:16:07 -0500 Subject: Update types --- .vscode/settings.json | 2 +- ext/js/data/anki-note-builder.js | 4 ++-- ext/js/data/options-util.js | 7 +++++++ ext/js/data/sandbox/anki-note-data-creator.js | 4 ++-- ext/js/display/display-anki.js | 14 +++++++------- ext/js/display/display-audio.js | 4 ++-- ext/js/display/display-content-manager.js | 4 ++-- ext/js/display/display-generator.js | 6 +++--- ext/js/display/display-profile-selection.js | 4 ++-- ext/js/display/display-resizer.js | 4 ++-- ext/js/display/display.js | 18 +++++++++--------- ext/js/display/option-toggle-hotkey-handler.js | 7 ++++--- ext/js/display/query-parser.js | 2 +- ext/js/display/sandbox/pronunciation-generator.js | 4 ++-- ext/js/display/sandbox/structured-content-generator.js | 8 ++++---- ext/js/display/search-display-controller.js | 14 +++++++------- 16 files changed, 57 insertions(+), 49 deletions(-) (limited to 'ext/js/display/sandbox/pronunciation-generator.js') diff --git a/.vscode/settings.json b/.vscode/settings.json index 81cd7b9c..734f6360 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,7 @@ "markdown.extension.toc.levels": "1..3", "editor.codeActionsOnSave": { "source.addMissingImports": false, - "source.organizeImports": true, + "source.organizeImports": false, "source.fixAll.eslint": false }, "eslint.format.enable": true, diff --git a/ext/js/data/anki-note-builder.js b/ext/js/data/anki-note-builder.js index 28809e1f..4920db39 100644 --- a/ext/js/data/anki-note-builder.js +++ b/ext/js/data/anki-note-builder.js @@ -24,10 +24,10 @@ import {AnkiUtil} from './anki-util.js'; export class AnkiNoteBuilder { /** - * @param {{japaneseUtil: JapaneseUtil}} details + * @param {{japaneseUtil: import('../language/sandbox/japanese-util.js').JapaneseUtil}} details */ constructor({japaneseUtil}) { - /** @type {JapaneseUtil} */ + /** @type {import('../language/sandbox/japanese-util.js').JapaneseUtil} */ this._japaneseUtil = japaneseUtil; /** @type {RegExp} */ this._markerPattern = AnkiUtil.cloneFieldMarkerPattern(true); diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index e8723f1f..70c1622f 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -1144,6 +1144,9 @@ export class OptionsUtil { return options; } + /** + * @type {import('options-util').ModernUpdateFunctionAsync} + */ async _updateVersion21(options) { await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v21.handlebars'); @@ -1163,6 +1166,10 @@ export class OptionsUtil { return options; } + /** + * @param {string} url + * @returns {Promise} + */ _createTab(url) { return new Promise((resolve, reject) => { chrome.tabs.create({url}, (tab) => { diff --git a/ext/js/data/sandbox/anki-note-data-creator.js b/ext/js/data/sandbox/anki-note-data-creator.js index 821d4024..dce71938 100644 --- a/ext/js/data/sandbox/anki-note-data-creator.js +++ b/ext/js/data/sandbox/anki-note-data-creator.js @@ -25,10 +25,10 @@ import {DictionaryDataUtil} from '../../language/sandbox/dictionary-data-util.js export class AnkiNoteDataCreator { /** * Creates a new instance. - * @param {JapaneseUtil} japaneseUtil An instance of `JapaneseUtil`. + * @param {import('../../language/sandbox/japanese-util.js').JapaneseUtil} japaneseUtil An instance of `JapaneseUtil`. */ constructor(japaneseUtil) { - /** @type {JapaneseUtil} */ + /** @type {import('../../language/sandbox/japanese-util.js').JapaneseUtil} */ this._japaneseUtil = japaneseUtil; } diff --git a/ext/js/display/display-anki.js b/ext/js/display/display-anki.js index c0173697..d0da568c 100644 --- a/ext/js/display/display-anki.js +++ b/ext/js/display/display-anki.js @@ -24,14 +24,14 @@ import {yomitan} from '../yomitan.js'; export class DisplayAnki { /** - * @param {Display} display - * @param {DisplayAudio} displayAudio - * @param {JapaneseUtil} japaneseUtil + * @param {import('./display.js').Display} display + * @param {import('./display-audio.js').DisplayAudio} displayAudio + * @param {import('../language/sandbox/japanese-util.js').JapaneseUtil} japaneseUtil */ constructor(display, displayAudio, japaneseUtil) { - /** @type {Display} */ + /** @type {import('./display.js').Display} */ this._display = display; - /** @type {DisplayAudio} */ + /** @type {import('./display-audio.js').DisplayAudio} */ this._displayAudio = displayAudio; /** @type {?string} */ this._ankiFieldTemplates = null; @@ -39,11 +39,11 @@ export class DisplayAnki { this._ankiFieldTemplatesDefault = null; /** @type {AnkiNoteBuilder} */ this._ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil}); - /** @type {?DisplayNotification} */ + /** @type {?import('./display-notification.js').DisplayNotification} */ this._errorNotification = null; /** @type {?EventListenerCollection} */ this._errorNotificationEventListeners = null; - /** @type {?DisplayNotification} */ + /** @type {?import('./display-notification.js').DisplayNotification} */ this._tagsNotification = null; /** @type {?Promise} */ this._updateAdderButtonsPromise = null; diff --git a/ext/js/display/display-audio.js b/ext/js/display/display-audio.js index 8d917e81..3fbfc3c8 100644 --- a/ext/js/display/display-audio.js +++ b/ext/js/display/display-audio.js @@ -23,10 +23,10 @@ import {yomitan} from '../yomitan.js'; export class DisplayAudio { /** - * @param {Display} display + * @param {import('./display.js').Display} display */ constructor(display) { - /** @type {Display} */ + /** @type {import('./display.js').Display} */ this._display = display; /** @type {?import('display-audio').GenericAudio} */ this._audioPlaying = null; diff --git a/ext/js/display/display-content-manager.js b/ext/js/display/display-content-manager.js index fa8ad0fa..c78ef7e8 100644 --- a/ext/js/display/display-content-manager.js +++ b/ext/js/display/display-content-manager.js @@ -26,10 +26,10 @@ import {yomitan} from '../yomitan.js'; export class DisplayContentManager { /** * Creates a new instance of the class. - * @param {Display} display The display instance that owns this object. + * @param {import('./display.js').Display} display The display instance that owns this object. */ constructor(display) { - /** @type {Display} */ + /** @type {import('./display.js').Display} */ this._display = display; /** @type {import('core').TokenObject} */ this._token = {}; diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index e8be79d9..eb464001 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -29,11 +29,11 @@ export class DisplayGenerator { * @param {import('display').DisplayGeneratorConstructorDetails} details */ constructor({japaneseUtil, contentManager, hotkeyHelpController=null}) { - /** @type {JapaneseUtil} */ + /** @type {import('../language/sandbox/japanese-util.js').JapaneseUtil} */ this._japaneseUtil = japaneseUtil; - /** @type {DisplayContentManager} */ + /** @type {import('./display-content-manager.js').DisplayContentManager} */ this._contentManager = contentManager; - /** @type {?HotkeyHelpController} */ + /** @type {?import('../input/hotkey-help-controller.js').HotkeyHelpController} */ this._hotkeyHelpController = hotkeyHelpController; /** @type {HtmlTemplateCollection} */ this._templates = new HtmlTemplateCollection(); diff --git a/ext/js/display/display-profile-selection.js b/ext/js/display/display-profile-selection.js index 619d07aa..c5cb7d06 100644 --- a/ext/js/display/display-profile-selection.js +++ b/ext/js/display/display-profile-selection.js @@ -22,10 +22,10 @@ import {yomitan} from '../yomitan.js'; export class DisplayProfileSelection { /** - * @param {Display} display + * @param {import('./display.js').Display} display */ constructor(display) { - /** @type {Display} */ + /** @type {import('./display.js').Display} */ this._display = display; /** @type {HTMLElement} */ this._profielList = /** @type {HTMLElement} */ (document.querySelector('#profile-list')); diff --git a/ext/js/display/display-resizer.js b/ext/js/display/display-resizer.js index 6280286d..8ce7e91a 100644 --- a/ext/js/display/display-resizer.js +++ b/ext/js/display/display-resizer.js @@ -20,10 +20,10 @@ import {EventListenerCollection} from '../core.js'; export class DisplayResizer { /** - * @param {Display} display + * @param {import('./display.js').Display} display */ constructor(display) { - /** @type {Display} */ + /** @type {import('./display.js').Display} */ this._display = display; /** @type {?import('core').TokenObject} */ this._token = null; diff --git a/ext/js/display/display.js b/ext/js/display/display.js index f9c36a67..f14291d1 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -43,9 +43,9 @@ export class Display extends EventDispatcher { * @param {number|undefined} tabId * @param {number|undefined} frameId * @param {import('display').DisplayPageType} pageType - * @param {JapaneseUtil} japaneseUtil - * @param {DocumentFocusController} documentFocusController - * @param {HotkeyHandler} hotkeyHandler + * @param {import('../language/sandbox/japanese-util.js').JapaneseUtil} japaneseUtil + * @param {import('../dom/document-focus-controller.js').DocumentFocusController} documentFocusController + * @param {import('../input/hotkey-handler.js').HotkeyHandler} hotkeyHandler */ constructor(tabId, frameId, pageType, japaneseUtil, documentFocusController, hotkeyHandler) { super(); @@ -55,11 +55,11 @@ export class Display extends EventDispatcher { this._frameId = frameId; /** @type {import('display').DisplayPageType} */ this._pageType = pageType; - /** @type {JapaneseUtil} */ + /** @type {import('../language/sandbox/japanese-util.js').JapaneseUtil} */ this._japaneseUtil = japaneseUtil; - /** @type {DocumentFocusController} */ + /** @type {import('../dom/document-focus-controller.js').DocumentFocusController} */ this._documentFocusController = documentFocusController; - /** @type {HotkeyHandler} */ + /** @type {import('../input/hotkey-handler.js').HotkeyHandler} */ this._hotkeyHandler = hotkeyHandler; /** @type {HTMLElement} */ this._container = /** @type {HTMLElement} */ (document.querySelector('#dictionary-entries')); @@ -168,7 +168,7 @@ export class Display extends EventDispatcher { this._copyTextarea = null; /** @type {?TextScanner} */ this._contentTextScanner = null; - /** @type {?DisplayNotification} */ + /** @type {?import('./display-notification.js').DisplayNotification} */ this._tagNotification = null; /** @type {HTMLElement} */ this._footerNotificationContainer = /** @type {HTMLElement} */ (document.querySelector('#content-footer')); @@ -235,7 +235,7 @@ export class Display extends EventDispatcher { this._updateQueryParser(); } - /** @type {JapaneseUtil} */ + /** @type {import('../language/sandbox/japanese-util.js').JapaneseUtil} */ get japaneseUtil() { return this._japaneseUtil; } @@ -245,7 +245,7 @@ export class Display extends EventDispatcher { return this._depth; } - /** @type {HotkeyHandler} */ + /** @type {import('../input/hotkey-handler.js').HotkeyHandler} */ get hotkeyHandler() { return this._hotkeyHandler; } diff --git a/ext/js/display/option-toggle-hotkey-handler.js b/ext/js/display/option-toggle-hotkey-handler.js index 9677e86b..531e208d 100644 --- a/ext/js/display/option-toggle-hotkey-handler.js +++ b/ext/js/display/option-toggle-hotkey-handler.js @@ -16,17 +16,18 @@ * along with this program. If not, see . */ +import {generateId} from '../core.js'; import {ExtensionError} from '../core/extension-error.js'; import {yomitan} from '../yomitan.js'; export class OptionToggleHotkeyHandler { /** - * @param {Display} display + * @param {import('./display.js').Display} display */ constructor(display) { - /** @type {Display} */ + /** @type {import('./display.js').Display} */ this._display = display; - /** @type {?DisplayNotification} */ + /** @type {?import('./display-notification.js').DisplayNotification} */ this._notification = null; /** @type {?number} */ this._notificationHideTimer = null; diff --git a/ext/js/display/query-parser.js b/ext/js/display/query-parser.js index fd173bde..03b54fd5 100644 --- a/ext/js/display/query-parser.js +++ b/ext/js/display/query-parser.js @@ -31,7 +31,7 @@ export class QueryParser extends EventDispatcher { super(); /** @type {import('display').GetSearchContextCallback} */ this._getSearchContext = getSearchContext; - /** @type {JapaneseUtil} */ + /** @type {import('../language/sandbox/japanese-util.js').JapaneseUtil} */ this._japaneseUtil = japaneseUtil; /** @type {string} */ this._text = ''; diff --git a/ext/js/display/sandbox/pronunciation-generator.js b/ext/js/display/sandbox/pronunciation-generator.js index eeedc574..d113485f 100644 --- a/ext/js/display/sandbox/pronunciation-generator.js +++ b/ext/js/display/sandbox/pronunciation-generator.js @@ -18,10 +18,10 @@ export class PronunciationGenerator { /** - * @param {JapaneseUtil} japaneseUtil + * @param {import('../../language/sandbox/japanese-util.js').JapaneseUtil} japaneseUtil */ constructor(japaneseUtil) { - /** @type {JapaneseUtil} */ + /** @type {import('../../language/sandbox/japanese-util.js').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 af49b643..5a91b01c 100644 --- a/ext/js/display/sandbox/structured-content-generator.js +++ b/ext/js/display/sandbox/structured-content-generator.js @@ -18,14 +18,14 @@ export class StructuredContentGenerator { /** - * @param {DisplayContentManager|AnkiTemplateRendererContentManager} contentManager - * @param {JapaneseUtil} japaneseUtil + * @param {import('../../display/display-content-manager.js').DisplayContentManager|import('../../templates/sandbox/anki-template-renderer-content-manager.js').AnkiTemplateRendererContentManager} contentManager + * @param {import('../../language/sandbox/japanese-util.js').JapaneseUtil} japaneseUtil * @param {Document} document */ constructor(contentManager, japaneseUtil, document) { - /** @type {DisplayContentManager|AnkiTemplateRendererContentManager} */ + /** @type {import('../../display/display-content-manager.js').DisplayContentManager|import('../../templates/sandbox/anki-template-renderer-content-manager.js').AnkiTemplateRendererContentManager} */ this._contentManager = contentManager; - /** @type {JapaneseUtil} */ + /** @type {import('../../language/sandbox/japanese-util.js').JapaneseUtil} */ this._japaneseUtil = japaneseUtil; /** @type {Document} */ this._document = document; diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js index 76e7bebe..a9bf2217 100644 --- a/ext/js/display/search-display-controller.js +++ b/ext/js/display/search-display-controller.js @@ -25,21 +25,21 @@ export class SearchDisplayController { /** * @param {number|undefined} tabId * @param {number|undefined} frameId - * @param {Display} display - * @param {DisplayAudio} displayAudio - * @param {JapaneseUtil} japaneseUtil - * @param {SearchPersistentStateController} searchPersistentStateController + * @param {import('./display.js').Display} display + * @param {import('./display-audio.js').DisplayAudio} displayAudio + * @param {import('../language/sandbox/japanese-util.js').JapaneseUtil} japaneseUtil + * @param {import('./search-persistent-state-controller.js').SearchPersistentStateController} searchPersistentStateController */ constructor(tabId, frameId, display, displayAudio, japaneseUtil, searchPersistentStateController) { /** @type {number|undefined} */ this._tabId = tabId; /** @type {number|undefined} */ this._frameId = frameId; - /** @type {Display} */ + /** @type {import('./display.js').Display} */ this._display = display; - /** @type {DisplayAudio} */ + /** @type {import('./display-audio.js').DisplayAudio} */ this._displayAudio = displayAudio; - /** @type {SearchPersistentStateController} */ + /** @type {import('./search-persistent-state-controller.js').SearchPersistentStateController} */ this._searchPersistentStateController = searchPersistentStateController; /** @type {HTMLButtonElement} */ this._searchButton = /** @type {HTMLButtonElement} */ (document.querySelector('#search-button')); -- cgit v1.2.3