From fd107e703b4fa2958b82b335d7da84b60f821f3f Mon Sep 17 00:00:00 2001 From: Khai Truong Date: Wed, 18 Sep 2024 00:08:49 +0700 Subject: [PATCH] move pointer event type to input.d.ts --- ext/js/language/text-scanner.js | 24 +++++++++++----------- types/ext/input.d.ts | 29 +++++++++++++++++++++++++++ types/ext/settings.d.ts | 7 +++---- types/ext/text-scanner.d.ts | 35 +++------------------------------ 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js index 69cb044716..535acc0d94 100644 --- a/ext/js/language/text-scanner.js +++ b/ext/js/language/text-scanner.js @@ -155,7 +155,7 @@ export class TextScanner extends EventDispatcher { this._preventNextClick = false; /** @type {boolean} */ this._preventScroll = false; - /** @type {import('text-scanner').PenPointerState} */ + /** @type {import('input').PenPointerState} */ this._penPointerState = 0; /** @type {Map} */ this._pointerIdTypeMap = new Map(); @@ -339,7 +339,7 @@ export class TextScanner extends EventDispatcher { * @param {import('text-source').TextSource} textSource * @param {number} length * @param {boolean} layoutAwareScan - * @param {import('text-scanner').PointerType | undefined} pointerType + * @param {import('input').PointerType | undefined} pointerType * @returns {string} */ getTextSourceContent(textSource, length, layoutAwareScan, pointerType) { @@ -1443,7 +1443,7 @@ export class TextScanner extends EventDispatcher { /** * @param {PointerEvent} e - * @param {import('text-scanner').PointerEventType} eventType + * @param {import('input').PointerEventType} eventType * @param {boolean} prevent */ async _searchAtFromPen(e, eventType, prevent) { @@ -1471,7 +1471,7 @@ export class TextScanner extends EventDispatcher { } /** - * @param {import('text-scanner').PointerEventType} eventType + * @param {import('input').PointerEventType} eventType * @param {import('text-scanner').InputConfig} input * @returns {boolean} */ @@ -1495,8 +1495,8 @@ export class TextScanner extends EventDispatcher { } /** - * @param {import('text-scanner').PointerType} pointerType - * @param {import('text-scanner').PointerEventType} eventType + * @param {import('input').PointerType} pointerType + * @param {import('input').PointerEventType} eventType * @param {MouseEvent|TouchEvent} event * @returns {?import('text-scanner').InputInfo} */ @@ -1507,8 +1507,8 @@ export class TextScanner extends EventDispatcher { } /** - * @param {import('text-scanner').PointerType} pointerType - * @param {import('text-scanner').PointerEventType} eventType + * @param {import('input').PointerType} pointerType + * @param {import('input').PointerEventType} eventType * @param {import('input').Modifier[]} modifiers * @param {import('input').ModifierKey[]} modifierKeys * @returns {?import('text-scanner').InputInfo} @@ -1538,8 +1538,8 @@ export class TextScanner extends EventDispatcher { /** * @param {?import('text-scanner').InputConfig} input - * @param {import('text-scanner').PointerType} pointerType - * @param {import('text-scanner').PointerEventType} eventType + * @param {import('input').PointerType} pointerType + * @param {import('input').PointerEventType} eventType * @param {boolean} passive * @param {import('input').Modifier[]} modifiers * @param {import('input').ModifierKey[]} modifierKeys @@ -1637,7 +1637,7 @@ export class TextScanner extends EventDispatcher { * @param {?string} includeSelector * @param {?string} excludeSelector * @param {boolean} layoutAwareScan - * @param {import('text-scanner').PointerType | undefined} pointerType + * @param {import('input').PointerType | undefined} pointerType */ _constrainTextSource(textSource, includeSelector, excludeSelector, layoutAwareScan, pointerType) { let length = textSource.text().length; @@ -1659,7 +1659,7 @@ export class TextScanner extends EventDispatcher { /** * @param {?string} excludeSelector - * @param {import('text-scanner').PointerType | undefined} pointerType + * @param {import('input').PointerType | undefined} pointerType * @returns {?string} */ _getExcludeSelectorForPointerType(excludeSelector, pointerType) { diff --git a/types/ext/input.d.ts b/types/ext/input.d.ts index e71a0110bb..03dd6dccc7 100644 --- a/types/ext/input.d.ts +++ b/types/ext/input.d.ts @@ -22,3 +22,32 @@ export type ModifierMouseButton = 'mouse0' | 'mouse1' | 'mouse2' | 'mouse3' | 'm export type Modifier = ModifierKey | ModifierMouseButton; export type ModifierType = 'key' | 'mouse'; + +export type PointerType = ( + 'pen' | + 'mouse' | + 'touch' | + 'script' +); + +export type PointerEventType = ( + 'mouseMove' | + 'pointerOver' | + 'pointerDown' | + 'pointerMove' | + 'pointerUp' | + 'touchStart' | + 'touchEnd' | + 'touchMove' | + 'click' | + 'script' +); + +/** + * An enum representing the pen pointer state. + * - `0` - Not active. + * - `1` - Hovering. + * - `2` - Touching. + * - `3` - Hovering after touching. + */ +export type PenPointerState = 0 | 1 | 2 | 3; \ No newline at end of file diff --git a/types/ext/settings.d.ts b/types/ext/settings.d.ts index 16a1c091cc..87695b64cc 100644 --- a/types/ext/settings.d.ts +++ b/types/ext/settings.d.ts @@ -15,7 +15,6 @@ * along with this program. If not, see . */ -import type {PointerType} from './text-scanner'; import type * as Input from './input'; export type OptionsContextFlag = 'clipboard'; @@ -28,7 +27,7 @@ export type OptionsContext1 = { flags?: OptionsContextFlag[]; modifiers?: Input.Modifier[]; modifierKeys?: Input.ModifierKey[]; - pointerType?: PointerType; + pointerType?: Input.PointerType; }; export type OptionsContext2 = { @@ -39,7 +38,7 @@ export type OptionsContext2 = { flags?: OptionsContextFlag[]; modifiers?: Input.Modifier[]; modifierKeys?: Input.ModifierKey[]; - pointerType?: PointerType; + pointerType?: Input.PointerType; }; export type OptionsContext3 = { @@ -50,7 +49,7 @@ export type OptionsContext3 = { flags?: OptionsContextFlag[]; modifiers?: Input.Modifier[]; modifierKeys?: Input.ModifierKey[]; - pointerType?: PointerType; + pointerType?: Input.PointerType; }; export type OptionsContext = OptionsContext1 | OptionsContext2 | OptionsContext3; diff --git a/types/ext/text-scanner.d.ts b/types/ext/text-scanner.d.ts index bc660d6e31..73a9a6cc6e 100644 --- a/types/ext/text-scanner.d.ts +++ b/types/ext/text-scanner.d.ts @@ -82,7 +82,7 @@ export type SentenceParsingOptions = { export type InputConfig = { include: string[]; exclude: string[]; - types: Set; + types: Set; searchTerms: boolean; searchKanji: boolean; scanOnTouchMove: boolean; @@ -100,8 +100,8 @@ export type InputConfig = { export type InputInfo = { input: InputConfig | null; - pointerType: PointerType; - eventType: PointerEventType; + pointerType: Input.PointerType; + eventType: Input.PointerEventType; passive: boolean; modifiers: Input.Modifier[]; modifierKeys: Input.ModifierKey[]; @@ -188,35 +188,6 @@ export type Sentence = { offset: number; }; -export type PointerType = ( - 'pen' | - 'mouse' | - 'touch' | - 'script' -); - -export type PointerEventType = ( - 'mouseMove' | - 'pointerOver' | - 'pointerDown' | - 'pointerMove' | - 'pointerUp' | - 'touchStart' | - 'touchEnd' | - 'touchMove' | - 'click' | - 'script' -); - -/** - * An enum representing the pen pointer state. - * - `0` - Not active. - * - `1` - Hovering. - * - `2` - Touching. - * - `3` - Hovering after touching. - */ -export type PenPointerState = 0 | 1 | 2 | 3; - export type SentenceTerminatorMap = Map; export type SentenceForwardQuoteMap = Map;