Pop-up dictionary browser extension for language learning. Successor to Yomichan. (PERSONAL FORK)
1/*
2 * Copyright (C) 2023-2025 Yomitan Authors
3 * Copyright (C) 2022 Yomichan Authors
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19import type * as Dictionary from './dictionary';
20import type {SearchResolution} from 'settings';
21
22// Kanji
23
24/**
25 * An options object for use with `Translator.findKanji`.
26 */
27export type FindKanjiOptions = {
28 /**
29 * The mapping of dictionaries to search for kanji in.
30 * The key is the dictionary name.
31 */
32 enabledDictionaryMap: KanjiEnabledDictionaryMap;
33 /**
34 * Whether or not non-Japanese characters should be searched.
35 */
36 removeNonJapaneseCharacters: boolean;
37};
38
39/**
40 * Details about a dictionary.
41 */
42export type FindKanjiDictionary = {
43 /**
44 * The index of the dictionary
45 */
46 index: number;
47 /**
48 * The alias of the dictionary
49 */
50 alias: string;
51};
52
53// Terms
54
55/**
56 * An options object for use with `Translator.findTerms`.
57 */
58export type FindTermsOptions = {
59 /**
60 * The matching type for looking up terms.
61 */
62 matchType: FindTermsMatchType;
63 /**
64 * Whether or not deinflection should be performed.
65 */
66 deinflect: boolean;
67 /**
68 * The reading which will be sorted to the top of the results, if provided as a query parameter.
69 */
70 primaryReading: string;
71 /**
72 * The name of the primary dictionary to search.
73 */
74 mainDictionary: string;
75 /**
76 * The name of the frequency dictionary used for sorting
77 */
78 sortFrequencyDictionary: string | null;
79 /**
80 * The order used when using a sorting dictionary.
81 */
82 sortFrequencyDictionaryOrder: FindTermsSortOrder;
83 /**
84 * Whether or not non-Japanese characters should be searched.
85 */
86 removeNonJapaneseCharacters: boolean;
87 /**
88 * An iterable sequence of text replacements to be applied during the term lookup process.
89 */
90 textReplacements: FindTermsTextReplacements;
91 /**
92 * The mapping of dictionaries to search for terms in.
93 * The key is the dictionary name.
94 */
95 enabledDictionaryMap: TermEnabledDictionaryMap;
96 /**
97 * A set of dictionary names which should have definitions removed.
98 */
99 excludeDictionaryDefinitions: Set<string> | null;
100 /**
101 * Whether every substring should be searched for, or only whole words.
102 */
103 searchResolution: SearchResolution;
104 /**
105 * ISO-639 code of the language.
106 */
107 language: string;
108};
109
110/**
111 * The matching type for looking up terms.
112 */
113export type FindTermsMatchType = Dictionary.TermSourceMatchType;
114
115/**
116 * A sorting order to use when finding terms.
117 */
118export type FindTermsSortOrder = 'ascending' | 'descending';
119
120/**
121 * Information about how text should be replaced when looking up terms.
122 */
123export type FindTermsTextReplacement = {
124 /**
125 * The pattern to replace.
126 */
127 pattern: RegExp;
128 /**
129 * The replacement string. This can contain special sequences, such as `$&`.
130 */
131 replacement: string;
132};
133
134/**
135 * Multiple text replacements.
136 */
137export type FindTermsTextReplacements = (FindTermsTextReplacement[] | null)[];
138
139/**
140 * Details about a dictionary.
141 */
142export type FindTermDictionary = {
143 /**
144 * The index of the dictionary
145 */
146 index: number;
147 /**
148 * The alias of the dictionary
149 */
150 alias: string;
151 /**
152 * Whether or not secondary term searches are allowed for this dictionary.
153 */
154 allowSecondarySearches: boolean;
155 /**
156 * Whether this dictionary's part of speech rules should be used to filter results.
157 */
158 partsOfSpeechFilter: boolean;
159 /**
160 * Whether to use the deinflections from this dictionary.
161 */
162 useDeinflections: boolean;
163};
164
165export type TermEnabledDictionaryMap = Map<string, FindTermDictionary>;
166
167export type KanjiEnabledDictionaryMap = Map<string, FindKanjiDictionary>;