Skip to content

Commit

Permalink
type updates (#500)
Browse files Browse the repository at this point in the history
* type updates

* remove comments

* fix comment

* remove types
  • Loading branch information
Casheeew authored Jan 13, 2024
1 parent 60276d4 commit 36c40ff
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 57 deletions.
1 change: 0 additions & 1 deletion ext/js/app/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
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; }

Expand Down
2 changes: 1 addition & 1 deletion ext/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
2 changes: 1 addition & 1 deletion ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 4 additions & 11 deletions ext/js/dom/dom-text-scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 17 additions & 13 deletions ext/js/templates/sandbox/anki-template-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,16 @@ export class AnkiTemplateRenderer {
return this._stringToMultiLineHtml(this._computeValueString(options, context));
}

/** @type {import('template-renderer').HelperFunction<string>} */
/**
* 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<string>}
*/
_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) {
Expand All @@ -262,13 +264,15 @@ export class AnkiTemplateRenderer {
return value;
}

/** @type {import('template-renderer').HelperFunction<string>} */
/**
* 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<string>}
*/
_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) {
Expand Down
21 changes: 7 additions & 14 deletions types/ext/dictionary-importer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 22 additions & 0 deletions types/ext/dom-text-scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
9 changes: 3 additions & 6 deletions types/ext/log.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 4 additions & 8 deletions types/ext/text-scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 36c40ff

Please sign in to comment.