1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
/*
* Copyright (C) 2023-2024 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 <https://www.gnu.org/licenses/>.
*/
import type * as Anki from './anki';
import type * as AnkiNoteBuilder from './anki-note-builder';
import type * as Audio from './audio';
import type * as AudioDownloader from './audio-downloader';
import type * as Backend from './backend';
import type * as Core from './core';
import type * as Dictionary from './dictionary';
import type * as DictionaryDatabase from './dictionary-database';
import type * as DictionaryImporter from './dictionary-importer';
import type * as Environment from './environment';
import type * as Extension from './extension';
import type * as Language from './language';
import type * as Log from './log';
import type * as Settings from './settings';
import type * as SettingsModifications from './settings-modifications';
import type * as Translation from './translation';
import type * as Translator from './translator';
import type {ApiMessageNoFrameIdAny as ApplicationApiMessageNoFrameIdAny} from './application';
import type {
ApiMap as BaseApiMap,
ApiMapInit as BaseApiMapInit,
ApiHandler as BaseApiHandler,
ApiParams as BaseApiParams,
ApiReturn as BaseApiReturn,
ApiNames as BaseApiNames,
ApiParam as BaseApiParam,
ApiParamNames as BaseApiParamNames,
ApiParamsAny as BaseApiParamsAny,
} from './api-map';
export type FindTermsDetails = {
matchType?: Translation.FindTermsMatchType;
deinflect?: boolean;
};
export type ParseTextResultItem = {
id: string;
source: 'scanning-parser' | 'mecab';
dictionary: null | string;
content: ParseTextLine[];
};
export type ParseTextSegment = {
text: string;
reading: string;
};
export type ParseTextLine = ParseTextSegment[];
export type InjectAnkiNoteMediaTermDefinitionDetails = {
type: 'term';
term: string;
reading: string;
};
export type InjectAnkiNoteMediaKanjiDefinitionDetails = {
type: 'kanji';
character: string;
};
export type InjectAnkiNoteMediaDefinitionDetails = InjectAnkiNoteMediaTermDefinitionDetails | InjectAnkiNoteMediaKanjiDefinitionDetails;
export type InjectAnkiNoteMediaAudioDetails = AnkiNoteBuilder.AudioMediaOptions;
export type InjectAnkiNoteMediaScreenshotDetails = {
tabId: number;
frameId: number;
format: Settings.AnkiScreenshotFormat;
quality: number;
};
export type InjectAnkiNoteMediaClipboardDetails = {
image: boolean;
text: boolean;
};
export type InjectAnkiNoteMediaDictionaryMediaDetails = {
dictionary: string;
path: string;
};
export type InjectAnkiNoteDictionaryMediaResult = {
dictionary: string;
path: string;
fileName: string | null;
};
export type GetMediaDetailsTarget = {
path: string;
dictionary: string;
};
export type GetTermFrequenciesDetailsTermReadingListItem = {
term: string;
reading: string | null;
};
type ApiSurface = {
applicationReady: {
params: void;
return: void;
};
optionsGet: {
params: {
optionsContext: Settings.OptionsContext;
};
return: Settings.ProfileOptions;
};
optionsGetFull: {
params: void;
return: Settings.Options;
};
termsFind: {
params: {
text: string;
details: FindTermsDetails;
optionsContext: Settings.OptionsContext;
};
return: {
dictionaryEntries: Dictionary.TermDictionaryEntry[];
originalTextLength: number;
};
};
parseText: {
params: {
text: string;
optionsContext: Settings.OptionsContext;
scanLength: number;
useInternalParser: boolean;
useMecabParser: boolean;
};
return: ParseTextResultItem[];
};
kanjiFind: {
params: {
text: string;
optionsContext: Settings.OptionsContext;
};
return: Dictionary.KanjiDictionaryEntry[];
};
isAnkiConnected: {
params: void;
return: boolean;
};
getAnkiConnectVersion: {
params: void;
return: number | null;
};
addAnkiNote: {
params: {
note: Anki.Note;
};
return: Anki.NoteId | null;
};
updateAnkiNote: {
params: {
noteWithId: Anki.NoteWithId;
};
return: null;
};
getAnkiNoteInfo: {
params: {
notes: Anki.Note[];
fetchAdditionalInfo: boolean;
};
return: Anki.NoteInfoWrapper[];
};
injectAnkiNoteMedia: {
params: {
timestamp: number;
definitionDetails: InjectAnkiNoteMediaDefinitionDetails;
audioDetails: InjectAnkiNoteMediaAudioDetails | null;
screenshotDetails: InjectAnkiNoteMediaScreenshotDetails | null;
clipboardDetails: InjectAnkiNoteMediaClipboardDetails | null;
dictionaryMediaDetails: InjectAnkiNoteMediaDictionaryMediaDetails[];
};
return: {
screenshotFileName: string | null;
clipboardImageFileName: string | null;
clipboardText: string | null;
audioFileName: string | null;
dictionaryMedia: InjectAnkiNoteDictionaryMediaResult[];
errors: Core.SerializedError[];
};
};
viewNotes: {
params: {
noteIds: Anki.NoteId[];
mode: Settings.AnkiNoteGuiMode;
allowFallback: boolean;
};
return: Settings.AnkiNoteGuiMode;
};
suspendAnkiCardsForNote: {
params: {
noteId: Anki.NoteId;
};
return: number;
};
getTermAudioInfoList: {
params: {
source: Audio.AudioSourceInfo;
term: string;
reading: string;
languageSummary: Language.LanguageSummary;
};
return: AudioDownloader.Info[];
};
commandExec: {
params: {
command: string;
params?: Core.SerializableObject;
};
return: boolean;
};
sendMessageToFrame: {
params: {
frameId: number;
message: ApplicationApiMessageNoFrameIdAny;
};
return: boolean;
};
broadcastTab: {
params: {
message: ApplicationApiMessageNoFrameIdAny;
};
return: boolean;
};
frameInformationGet: {
params: void;
return: Extension.ContentOrigin;
};
injectStylesheet: {
params: {
type: 'file' | 'code';
value: string;
};
return: void;
};
getStylesheetContent: {
params: {
url: string;
};
return: string;
};
getEnvironmentInfo: {
params: void;
return: Environment.Info;
};
clipboardGet: {
params: void;
return: string;
};
getZoom: {
params: void;
return: {
zoomFactor: number;
};
};
getDefaultAnkiFieldTemplates: {
params: void;
return: string;
};
getDictionaryInfo: {
params: void;
return: DictionaryImporter.Summary[];
};
purgeDatabase: {
params: void;
return: void;
};
getMedia: {
params: {
targets: GetMediaDetailsTarget[];
};
return: DictionaryDatabase.MediaDataStringContent[];
};
logGenericErrorBackend: {
params: {
error: Core.SerializedError;
level: Log.LogLevel;
context: Log.LogContext | undefined;
};
return: void;
};
logIndicatorClear: {
params: void;
return: void;
};
modifySettings: {
params: {
targets: SettingsModifications.ScopedModification[];
source: string;
};
return: Core.Response<SettingsModifications.ModificationResult>[];
};
getSettings: {
params: {
targets: SettingsModifications.ScopedRead[];
};
return: Core.Response<SettingsModifications.ModificationResult>[];
};
setAllSettings: {
params: {
value: Settings.Options;
source: string;
};
return: void;
};
getOrCreateSearchPopup: {
params: {
focus?: boolean | 'ifCreated';
text?: string;
};
return: {
tabId: number | null;
windowId: number;
};
};
isTabSearchPopup: {
params: {
tabId: number;
};
return: boolean;
};
triggerDatabaseUpdated: {
params: {
type: Backend.DatabaseUpdateType;
cause: Backend.DatabaseUpdateCause;
};
return: void;
};
testMecab: {
params: void;
return: true;
};
isTextLookupWorthy: {
params: {
text: string;
language: string;
};
return: boolean;
};
getTermFrequencies: {
params: {
termReadingList: GetTermFrequenciesDetailsTermReadingListItem[];
dictionaries: string[];
};
return: Translator.TermFrequencySimple[];
};
findAnkiNotes: {
params: {
query: string;
};
return: Anki.NoteId[];
};
openCrossFramePort: {
params: {
targetTabId: number;
targetFrameId: number;
};
return: {
targetTabId: number;
targetFrameId: number;
};
};
requestBackendReadySignal: {
params: void;
return: boolean;
};
getLanguageSummaries: {
params: void;
return: Language.LanguageSummary[];
};
};
type ApiExtraArgs = [sender: chrome.runtime.MessageSender];
export type ApiNames = BaseApiNames<ApiSurface>;
export type ApiMap = BaseApiMap<ApiSurface, ApiExtraArgs>;
export type ApiMapInit = BaseApiMapInit<ApiSurface, ApiExtraArgs>;
export type ApiHandler<TName extends ApiNames> = BaseApiHandler<ApiSurface[TName], ApiExtraArgs>;
export type ApiHandlerNoExtraArgs<TName extends ApiNames> = BaseApiHandler<ApiSurface[TName], []>;
export type ApiParams<TName extends ApiNames> = BaseApiParams<ApiSurface[TName]>;
export type ApiParam<TName extends ApiNames, TParamName extends BaseApiParamNames<ApiSurface[TName]>> = BaseApiParam<ApiSurface[TName], TParamName>;
export type ApiReturn<TName extends ApiNames> = BaseApiReturn<ApiSurface[TName]>;
export type ApiParamsAny = BaseApiParamsAny<ApiSurface>;
export type ApiMessageAny = {[name in ApiNames]: ApiMessage<name>}[ApiNames];
type ApiMessage<TName extends ApiNames> = {
action: TName;
params: ApiParams<TName>;
};
|