From 36c40ff671ae1f8a05aac77c8694e9bccdda85fb Mon Sep 17 00:00:00 2001 From: Cashew <52880648+Scrub1492@users.noreply.github.com> Date: Sat, 13 Jan 2024 11:58:48 +0700 Subject: [PATCH] type updates (#500) * type updates * remove comments * fix comment * remove types --- ext/js/app/frontend.js | 1 - ext/js/background/backend.js | 4 +-- ext/js/core.js | 2 +- ext/js/display/display.js | 2 +- ext/js/dom/dom-text-scanner.js | 15 +++------- .../sandbox/anki-template-renderer.js | 30 +++++++++++-------- types/ext/dictionary-importer.d.ts | 21 +++++-------- types/ext/dom-text-scanner.d.ts | 22 ++++++++++++++ types/ext/log.d.ts | 9 ++---- types/ext/text-scanner.d.ts | 12 +++----- 10 files changed, 61 insertions(+), 57 deletions(-) diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index 9dafde7a19..eb88beef20 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -864,7 +864,6 @@ export class Frontend { case 'web': return preventMiddleMouseOptions.onWebPages; case 'popup': return preventMiddleMouseOptions.onPopupPages; case 'search': return preventMiddleMouseOptions.onSearchPages; - default: return false; } } diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 481567b55f..3f3c606301 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -2629,14 +2629,14 @@ export class Backend { } /** + * Only request this permission for Firefox versions >= 77. + * https://bugzilla.mozilla.org/show_bug.cgi?id=1630413 * @returns {Promise} */ async _requestPersistentStorage() { try { if (await navigator.storage.persisted()) { return; } - // Only request this permission for Firefox versions >= 77. - // https://bugzilla.mozilla.org/show_bug.cgi?id=1630413 const {vendor, version} = await browser.runtime.getBrowserInfo(); if (vendor !== 'Mozilla') { return; } diff --git a/ext/js/core.js b/ext/js/core.js index 726b037c43..854099e839 100644 --- a/ext/js/core.js +++ b/ext/js/core.js @@ -686,11 +686,11 @@ export class Logger extends EventDispatcher { /* eslint-disable no-console */ switch (level) { + case 'log': console.log(message); break; case 'info': console.info(message); break; case 'debug': console.debug(message); break; case 'warn': console.warn(message); break; case 'error': console.error(message); break; - default: console.log(message); break; } /* eslint-enable no-console */ diff --git a/ext/js/display/display.js b/ext/js/display/display.js index cae394f84f..ff77d2033f 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -480,7 +480,7 @@ export class Display extends EventDispatcher { case 'overwrite': this._history.replaceState(state, content, url); break; - default: // 'new' + case 'new': this._updateHistoryState(); this._history.pushState(state, content, url); break; diff --git a/ext/js/dom/dom-text-scanner.js b/ext/js/dom/dom-text-scanner.js index 21770a7005..e910574186 100644 --- a/ext/js/dom/dom-text-scanner.js +++ b/ext/js/dom/dom-text-scanner.js @@ -212,10 +212,8 @@ export class DOMTextScanner { /** * Gets information about how whitespace characters are treated. - * @param {Text} textNode The text node to check. - * @returns {{preserveNewlines: boolean, preserveWhitespace: boolean}} Information about the whitespace. - * The value of `preserveNewlines` indicates whether or not newline characters are treated as line breaks. - * The value of `preserveWhitespace` indicates whether or not sequences of whitespace characters are collapsed. + * @param {Text} textNode + * @returns {import('dom-text-scanner').WhitespaceSettings} */ _getWhitespaceSettings(textNode) { if (this._forcePreserveWhitespace) { @@ -412,13 +410,8 @@ export class DOMTextScanner { } /** - * Gets seek information about an element. - * @param {Element} element The element to check. - * @returns {{enterable: boolean, newlines: number}} The seek information. - * The `enterable` value indicates whether the content of this node should be entered. - * The `newlines` value corresponds to the number of newline characters that should be added. - * - 1 newline corresponds to a simple new line in the layout. - * - 2 newlines corresponds to a significant visual distinction since the previous content. + * @param {Element} element + * @returns {import('dom-text-scanner').ElementSeekInfo} */ static getElementSeekInfo(element) { let enterable = true; diff --git a/ext/js/templates/sandbox/anki-template-renderer.js b/ext/js/templates/sandbox/anki-template-renderer.js index 158102393c..3311097f2e 100644 --- a/ext/js/templates/sandbox/anki-template-renderer.js +++ b/ext/js/templates/sandbox/anki-template-renderer.js @@ -235,14 +235,16 @@ export class AnkiTemplateRenderer { return this._stringToMultiLineHtml(this._computeValueString(options, context)); } - /** @type {import('template-renderer').HelperFunction} */ + /** + * Usage: + * ```{{#regexReplace regex string [flags] [content]...}}content{{/regexReplace}}``` + * - regex: regular expression string + * - string: string to replace + * - flags: optional flags for regular expression. + * e.g. "i" for case-insensitive, "g" for replace all + * @type {import('template-renderer').HelperFunction} + */ _regexReplace(args, context, options) { - // Usage: - // {{#regexReplace regex string [flags] [content]...}}content{{/regexReplace}} - // regex: regular expression string - // string: string to replace - // flags: optional flags for regular expression - // e.g. "i" for case-insensitive, "g" for replace all const argCount = args.length; let value = this._computeValueString(options, context); if (argCount > 3) { @@ -262,13 +264,15 @@ export class AnkiTemplateRenderer { return value; } - /** @type {import('template-renderer').HelperFunction} */ + /** + * Usage: + * {{#regexMatch regex [flags] [content]...}}content{{/regexMatch}} + * - regex: regular expression string + * - flags: optional flags for regular expression + * e.g. "i" for case-insensitive, "g" for match all + * @type {import('template-renderer').HelperFunction} + */ _regexMatch(args, context, options) { - // Usage: - // {{#regexMatch regex [flags] [content]...}}content{{/regexMatch}} - // regex: regular expression string - // flags: optional flags for regular expression - // e.g. "i" for case-insensitive, "g" for match all const argCount = args.length; let value = this._computeValueString(options, context); if (argCount > 2) { diff --git a/types/ext/dictionary-importer.d.ts b/types/ext/dictionary-importer.d.ts index cda1bd19b4..2d16dc5e62 100644 --- a/types/ext/dictionary-importer.d.ts +++ b/types/ext/dictionary-importer.d.ts @@ -25,20 +25,13 @@ export type OnProgressCallback = (data: ProgressData) => void; /** * An enum representing the import step. - * - * `-2` `-1` Dictionary import is uninitialized. - * - * `0` Load dictionary archive and validate index step. - * - * `1` Load schemas and get archive files step. - * - * `2` Load and validate dictionary data step. - * - * `3` Format dictionary data and extended data support step. - * - * `4` Resolve async requirements and import media step. - * - * `5` Add dictionary descriptor and import data step. + * - `-2` `-1` - Dictionary import is uninitialized. + * - `0` - Load dictionary archive and validate index step. + * - `1` - Load schemas and get archive files step. + * - `2` - Load and validate dictionary data step. + * - `3` - Format dictionary data and extended data support step. + * - `4` - Resolve async requirements and import media step. + * - `5` - Add dictionary descriptor and import data step. */ export type ImportStep = -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5; diff --git a/types/ext/dom-text-scanner.d.ts b/types/ext/dom-text-scanner.d.ts index 33c01aa8a1..c3e26493c7 100644 --- a/types/ext/dom-text-scanner.d.ts +++ b/types/ext/dom-text-scanner.d.ts @@ -24,3 +24,25 @@ * - `3` - Character should be added to the content and is a newline. */ export type CharacterAttributes = 0 | 1 | 2 | 3; + +/** + * Seek information about an element. + * The `enterable` value indicates whether the content of this node should be entered. + * The `newlines` value corresponds to the number of newline characters that should be added. + * - 1 newline corresponds to a simple new line in the layout. + * - 2 newlines corresponds to a significant visual distinction since the previous content. + */ +export type ElementSeekInfo = { + enterable: boolean; + newlines: number; +}; + +/** + * Information about the whitespace. + * `preserveNewlines` indicates whether or not newline characters are treated as line breaks. + * `preserveWhitespace` indicates whether or not sequences of whitespace characters are collapsed. + */ +export type WhitespaceSettings = { + preserveNewlines: boolean; + preserveWhitespace: boolean; +}; diff --git a/types/ext/log.d.ts b/types/ext/log.d.ts index e8ca4c4390..18616d584e 100644 --- a/types/ext/log.d.ts +++ b/types/ext/log.d.ts @@ -25,12 +25,9 @@ export type LogContext = { /** * An enum representing the log error level. - * - * `0` _log_, _info_, _debug_ level. - * - * `1` _warn_ level. - * - * `2` _error_ level. + * - `0` - _log_, _info_, _debug_ level. + * - `1` - _warn_ level. + * - `2` - _error_ level. */ export type LogErrorLevelValue = 0 | 1 | 2; diff --git a/types/ext/text-scanner.d.ts b/types/ext/text-scanner.d.ts index e2779e4d69..d4214a1d04 100644 --- a/types/ext/text-scanner.d.ts +++ b/types/ext/text-scanner.d.ts @@ -197,14 +197,10 @@ export type PointerEventType = ( /** * An enum representing the pen pointer state. - * - * `0` Not active. - * - * `1` Hovering. - * - * `2` Touching. - * - * `3` Hovering after touching. + * - `0` - Not active. + * - `1` - Hovering. + * - `2` - Touching. + * - `3` - Hovering after touching. */ export type PenPointerState = 0 | 1 | 2 | 3;