Pop-up dictionary browser extension for language learning. Successor to Yomichan. (PERSONAL FORK)
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 {Response} from 'core';
19import type {RenderMode, NoteData} from 'anki-templates';
20import type {CompositeRenderData, PartialOrCompositeRenderData, RenderMultiItem, RenderResult} from 'template-renderer';
21import type {
22 ApiMap as BaseApiMap,
23 ApiMapInit as BaseApiMapInit,
24 ApiHandler as BaseApiHandler,
25 ApiParams as BaseApiParams,
26 ApiNames as BaseApiNames,
27 ApiReturn as BaseApiReturn,
28 ApiReturnAny as BaseApiReturnAny,
29} from './api-map';
30
31// Frontend API
32
33type FrontendApiSurface = {
34 render: {
35 params: {
36 template: string;
37 data: PartialOrCompositeRenderData;
38 type: RenderMode;
39 };
40 return: RenderResult;
41 };
42 renderMulti: {
43 params: {
44 items: RenderMultiItem[];
45 };
46 return: Response<RenderResult>[];
47 };
48 getModifiedData: {
49 params: {
50 data: CompositeRenderData;
51 type: RenderMode;
52 };
53 return: NoteData;
54 };
55};
56
57type FrontendApiParams<TName extends FrontendApiNames> = BaseApiParams<FrontendApiSurface[TName]>;
58
59type FrontendApiNames = BaseApiNames<FrontendApiSurface>;
60
61type FrontendApiReturnAny = BaseApiReturnAny<FrontendApiSurface>;
62
63export type FrontendMessage<TName extends FrontendApiNames> = {
64 action: TName;
65 params: FrontendApiParams<TName>;
66 id: string;
67};
68
69export type FrontendMessageAny = FrontendMessage<FrontendApiNames>;
70
71export type FrontendApiReturn<TName extends FrontendApiNames> = BaseApiReturn<FrontendApiSurface[TName]>;
72
73export type FrontendApiMap = BaseApiMap<FrontendApiSurface>;
74
75export type FrontendApiMapInit = BaseApiMapInit<FrontendApiSurface>;
76
77export type FrontendApiHandler<TName extends FrontendApiNames> = BaseApiHandler<FrontendApiSurface[TName]>;
78
79// Backend API
80
81export type BackendApiSurface = {
82 ready: {
83 params: void;
84 return: void;
85 };
86 response: {
87 params: Response<FrontendApiReturnAny>;
88 return: void;
89 };
90};
91
92type BackendApiNames = BaseApiNames<BackendApiSurface>;
93
94type BackendApiParams<TName extends BackendApiNames> = BaseApiParams<BackendApiSurface[TName]>;
95
96export type BackendMessage<TName extends BackendApiNames> = {
97 action: TName;
98 params: BackendApiParams<TName>;
99 id: string | null;
100};
101
102export type BackendMessageAny = BackendMessage<BackendApiNames>;