/* * Copyright (C) 2023-2025 Yomitan Authors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import type * as TaskAccumulator from './task-accumulator'; export type CreateElementMetadataCallback = (element: Element) => T | undefined; export type CompareElementMetadataCallback = (metadata1: T, metadata2: T) => boolean; export type GetValuesCallback = (args: GetValuesDetails[]) => Promise; export type SetValuesCallback = (args: SetValuesDetails[]) => Promise; export type GetValuesDetails = { element: Element; metadata: T; }; export type SetValuesDetails = { element: Element; metadata: T; value: ValueType; }; export type OnErrorCallback = (error: Error, stale: boolean, element: Element, metadata: T) => void; export type ElementObserver = { element: Element; type: NormalizedElementType; value: unknown; hasValue: boolean; eventType: EventType; onChange: null | (() => void); metadata: T; }; export type SettingChangedEventData = { value: boolean | string | number; }; export type SettingChangedEvent = CustomEvent; export type NormalizedElementType = 'textarea' | 'select' | 'text' | 'checkbox' | 'number' | 'element'; export type EventType = 'change'; export type UpdateTaskValue = {all: boolean}; export type AssignTaskValue = {value: ValueType}; export type ValueType = boolean | string | number | null; export type UpdateTask = [ key: ElementObserver | null, task: TaskAccumulator.Task, ]; export type AssignTask = [ key: ElementObserver | null, task: TaskAccumulator.Task, ]; export type ApplyTarget = [ observer: ElementObserver, task: TaskAccumulator.Task | TaskAccumulator.Task | null, ]; export type TaskResultError = { error: Error; result?: undefined; }; export type TaskResultSuccess = { error?: undefined; result: T; }; export type TaskResult = TaskResultError | TaskResultSuccess;