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 {TokenString, EventNames, EventArgument as BaseEventArgument} from './core';
19import type {SearchMode} from './display';
20import type {FrameEndpointReadyDetails, FrameEndpointConnectedDetails} from './frame-client';
21import type {DatabaseUpdateType, DatabaseUpdateCause} from './backend';
22import type {
23 ApiMap as BaseApiMap,
24 ApiHandler as BaseApiHandler,
25 ApiParams as BaseApiParams,
26 ApiNames as BaseApiNames,
27 ApiReturn as BaseApiReturn,
28} from './api-map';
29
30export type ApiSurface = {
31 searchDisplayControllerGetMode: {
32 params: void;
33 return: SearchMode;
34 };
35 searchDisplayControllerSetMode: {
36 params: {
37 mode: SearchMode;
38 };
39 return: void;
40 };
41 searchDisplayControllerUpdateSearchQuery: {
42 params: {
43 text: string;
44 animate: boolean;
45 };
46 return: void;
47 };
48 applicationIsReady: {
49 params: void;
50 return: boolean;
51 };
52 applicationBackendReady: {
53 params: void;
54 return: void;
55 };
56 applicationGetUrl: {
57 params: void;
58 return: {
59 url: string;
60 };
61 };
62 applicationOptionsUpdated: {
63 params: {
64 source: string;
65 };
66 return: void;
67 };
68 applicationDatabaseUpdated: {
69 params: {
70 type: DatabaseUpdateType;
71 cause: DatabaseUpdateCause;
72 };
73 return: void;
74 };
75 applicationZoomChanged: {
76 params: {
77 oldZoomFactor: number;
78 newZoomFactor: number;
79 };
80 return: void;
81 };
82 frontendRequestReadyBroadcast: {
83 params: {
84 frameId: number | null;
85 };
86 return: void;
87 };
88 frontendSetAllVisibleOverride: {
89 params: {
90 value: boolean;
91 priority: number;
92 awaitFrame: boolean;
93 };
94 return: TokenString;
95 };
96 frontendClearAllVisibleOverride: {
97 params: {
98 token: TokenString;
99 };
100 return: boolean;
101 };
102 frontendReady: {
103 params: {
104 frameId: number | null;
105 };
106 return: void;
107 };
108 frontendScanSelectedText: {
109 params: void;
110 return: void;
111 };
112 frameEndpointReady: {
113 params: FrameEndpointReadyDetails;
114 return: void;
115 };
116 frameEndpointConnected: {
117 params: FrameEndpointConnectedDetails;
118 return: void;
119 };
120};
121
122export type ApiParams<TName extends ApiNames> = BaseApiParams<ApiSurface[TName]>;
123
124export type ApiNames = BaseApiNames<ApiSurface>;
125
126export type ApiMessageNoFrameId<TName extends ApiNames> = (
127 ApiParams<TName> extends void ?
128 {action: TName, params?: never} :
129 {action: TName, params: ApiParams<TName>}
130);
131
132export type ApiMessage<TName extends ApiNames> = ApiMessageNoFrameId<TName> & {
133 /**
134 * The origin frameId that sent this message.
135 * If sent from the backend, this value will be undefined.
136 */
137 frameId?: number;
138};
139
140export type ApiMessageNoFrameIdAny = {[name in ApiNames]: ApiMessageNoFrameId<name>}[ApiNames];
141
142export type ApiMessageAny = {[name in ApiNames]: ApiMessage<name>}[ApiNames];
143
144export type ApiMap = BaseApiMap<ApiSurface>;
145
146export type ApiHandler<TName extends ApiNames> = BaseApiHandler<ApiSurface[TName]>;
147
148export type ApiReturn<TName extends ApiNames> = BaseApiReturn<ApiSurface[TName]>;
149
150export type Events = {
151 extensionUnloaded: Record<string, never>;
152 optionsUpdated: {
153 source: string;
154 };
155 databaseUpdated: {
156 type: DatabaseUpdateType;
157 cause: DatabaseUpdateCause;
158 };
159 zoomChanged: {
160 oldZoomFactor: number;
161 newZoomFactor: number;
162 };
163 closePopups: Record<string, never>;
164 storageChanged: Record<string, never>;
165};
166
167export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;