Pop-up dictionary browser extension for language learning. Successor to Yomichan. (PERSONAL FORK)
at lambda-fork/main 92 lines 2.8 kB view raw
1/* 2 * Copyright (C) 2023-2025 Yomitan Authors 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18import type * as TaskAccumulator from './task-accumulator'; 19 20export type CreateElementMetadataCallback<T = unknown> = (element: Element) => T | undefined; 21 22export type CompareElementMetadataCallback<T = unknown> = (metadata1: T, metadata2: T) => boolean; 23 24export type GetValuesCallback<T = unknown> = (args: GetValuesDetails<T>[]) => Promise<TaskResult[]>; 25 26export type SetValuesCallback<T = unknown> = (args: SetValuesDetails<T>[]) => Promise<TaskResult[]>; 27 28export type GetValuesDetails<T = unknown> = { 29 element: Element; 30 metadata: T; 31}; 32 33export type SetValuesDetails<T = unknown> = { 34 element: Element; 35 metadata: T; 36 value: ValueType; 37}; 38 39export type OnErrorCallback<T = unknown> = (error: Error, stale: boolean, element: Element, metadata: T) => void; 40 41export type ElementObserver<T = unknown> = { 42 element: Element; 43 type: NormalizedElementType; 44 value: unknown; 45 hasValue: boolean; 46 eventType: EventType; 47 onChange: null | (() => void); 48 metadata: T; 49}; 50 51export type SettingChangedEventData = { 52 value: boolean | string | number; 53}; 54 55export type SettingChangedEvent = CustomEvent<SettingChangedEventData>; 56 57export type NormalizedElementType = 'textarea' | 'select' | 'text' | 'checkbox' | 'number' | 'element'; 58 59export type EventType = 'change'; 60 61export type UpdateTaskValue = {all: boolean}; 62 63export type AssignTaskValue = {value: ValueType}; 64 65export type ValueType = boolean | string | number | null; 66 67export type UpdateTask<T = unknown> = [ 68 key: ElementObserver<T> | null, 69 task: TaskAccumulator.Task<UpdateTaskValue>, 70]; 71 72export type AssignTask<T = unknown> = [ 73 key: ElementObserver<T> | null, 74 task: TaskAccumulator.Task<AssignTaskValue>, 75]; 76 77export type ApplyTarget<T = unknown> = [ 78 observer: ElementObserver<T>, 79 task: TaskAccumulator.Task<UpdateTaskValue> | TaskAccumulator.Task<AssignTaskValue> | null, 80]; 81 82export type TaskResultError = { 83 error: Error; 84 result?: undefined; 85}; 86 87export type TaskResultSuccess<T = unknown> = { 88 error?: undefined; 89 result: T; 90}; 91 92export type TaskResult<T = unknown> = TaskResultError | TaskResultSuccess<T>;