aboutsummaryrefslogtreecommitdiff
path: root/types/ext/display.d.ts
blob: 3aba304e8bcb72aa863e19e1295a6f2a379ea1dc (plain)
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
/*
 * 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 Dictionary from './dictionary';
import type * as Extension from './extension';
import type * as Settings from './settings';
import type * as TextScannerTypes from './text-scanner';
import type {EventNames, EventArgument as BaseEventArgument} from './core';
import type {Message as FrameClientMessage} from './frame-client';
import type {
    ApiMap as BaseApiMap,
    ApiParams as BaseApiParams,
    ApiNames as BaseApiNames,
    ApiMapInit as BaseApiMapInit,
    ApiParamsAny as BaseApiParamsAny,
    ApiHandler as BaseApiHandler,
    ApiReturn as BaseApiReturn,
} from './api-map';

export type HistoryMode = 'clear' | 'overwrite' | 'new';

export type DisplayPageType = 'search' | 'popup';

export type PageType = 'terms' | 'kanji' | 'unloaded' | 'clear';

/**
 * Information about how popup content should be shown, specifically related to the inner popup content.
 */
export type ContentDetails = {
    /** Whether or not the frame should be `focus()`'d. */
    focus: boolean;
    /** An object containing key-value pairs representing the URL search params. */
    params: HistoryParams;
    /** The semi-persistent state assigned to the navigation entry. */
    state: HistoryState | null;
    /** The non-persistent content assigned to the navigation entry. */
    content: HistoryContent | null;
    /** How the navigation history should be modified. */
    historyMode: HistoryMode;
};

/**
 * An object containing key-value pairs representing the URL search params.
 */
export type HistoryParams = {
    /** The type of content that is being shown. */
    type?: PageType;
    /** The search query. */
    query?: string;
    /** Whether or not wildcards can be used for the search query. */
    wildcards?: 'on' | 'off';
    /** The start position of the `query` string as an index into the `full` query string. */
    offset?: string;
    /** The full search text. If absent, `query` is the full search text. */
    full?: string;
    /** Whether or not the full search query should be forced to be visible. */
    ['full-visible']?: 'true' | 'false';
    /** Whether or not the query should be looked up. If it is not looked up, the content should be provided. */
    lookup?: 'true' | 'false';
    /** Other values; only used for assignment. */
    [otherKey: string]: unknown;
};

/**
 * The semi-persistent state assigned to the navigation entry.
 */
export type HistoryState = {
    /** What was the cause of the navigation. */
    cause?: 'queryParser';
    /** The sentence context. */
    sentence?: HistoryStateSentence;
    /** The index of the dictionary entry to focus. */
    focusEntry?: number;
    /** The horizontal scroll position. */
    scrollX?: number;
    /** The vertical scroll position. */
    scrollY?: number;
    /** The options context which should be used for lookups. */
    optionsContext?: Settings.OptionsContext;
    /** The originating URL of the content. */
    url?: string;
    /** The originating document title of the content. */
    documentTitle?: string;
    /** Computed theme of the page */
    pageTheme?: 'dark' | 'light';
};

/**
 * The sentence context.
 */
export type HistoryStateSentence = {
    /** The full string. */
    text: string;
    /** The offset from the start of `text` to the full search query. */
    offset: number;
};

/**
 * The non-persistent content assigned to the navigation entry.
 */
export type HistoryContent = {
    /** Whether or not any CSS animations should occur. */
    animate?: boolean;
    /** An array of dictionary entries to display as content. */
    dictionaryEntries?: Dictionary.DictionaryEntry[];
    /** The identifying information for the frame the content originated from. */
    contentOrigin?: Extension.ContentOrigin;
};

export type SearchMode = null | 'popup' | 'action-popup';

export type GetSearchContextCallback = TextScannerTypes.GetSearchContextCallbackSync;

export type QueryParserOptions = {
    selectedParser: string | null;
    termSpacing: boolean;
    readingMode: Settings.ParsingReadingMode;
    useInternalParser: boolean;
    useMecabParser: boolean;
    language: string;
    scanning: TextScannerTypes.Options;
};

export type Events = {
    optionsUpdated: {
        options: Settings.ProfileOptions;
    };
    frameVisibilityChange: {
        value: boolean;
    };
    logDictionaryEntryData: {
        dictionaryEntry: Dictionary.DictionaryEntry;
        promises: Promise<unknown>[];
    };
    contentClear: Record<string, never>;
    contentUpdateStart: {
        type: PageType;
        query: string;
    };
    contentUpdateEntry: {
        dictionaryEntry: Dictionary.DictionaryEntry;
        element: Element;
        index: number;
    };
    contentUpdateComplete: {
        type: PageType;
    };
};

export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;

// Direct API

export type DirectApiSurface = {
    displayAudioClearAutoPlayTimer: {
        params: void;
        return: void;
    };
    displaySetOptionsContext: {
        params: {
            optionsContext: Settings.OptionsContext;
        };
        return: void;
    };
    displaySetContent: {
        params: {
            details: ContentDetails;
        };
        return: void;
    };
    displaySetCustomCss: {
        params: {
            css: string;
        };
        return: void;
    };
    displaySetContentScale: {
        params: {
            scale: number;
        };
        return: void;
    };
    displayConfigure: {
        params: {
            depth: number;
            parentPopupId: string;
            parentFrameId: number;
            childrenSupported: boolean;
            scale: number;
            optionsContext: Settings.OptionsContext;
        };
        return: void;
    };
    displayVisibilityChanged: {
        params: {
            value: boolean;
        };
        return: void;
    };
};

export type DirectApiNames = BaseApiNames<DirectApiSurface>;

export type DirectApiMapInit = BaseApiMapInit<DirectApiSurface>;

export type DirectApiMap = BaseApiMap<DirectApiSurface, []>;

export type DirectApiHandler<TName extends DirectApiNames> = BaseApiHandler<DirectApiSurface[TName]>;

export type DirectApiParams<TName extends DirectApiNames> = BaseApiParams<DirectApiSurface[TName]>;

export type DirectApiReturn<TName extends DirectApiNames> = BaseApiReturn<DirectApiSurface[TName]>;

export type DirectApiMessageAny = {[name in DirectApiNames]: DirectApiMessage<name>}[DirectApiNames];

export type DirectApiReturnAny = BaseApiParamsAny<DirectApiSurface>;

type DirectApiMessage<TName extends DirectApiNames> = {
    action: TName;
    params: DirectApiParams<TName>;
};

export type DirectApiFrameClientMessageAny = {[name in DirectApiNames]: FrameClientMessage<DirectApiMessage<name>>}[DirectApiNames];

// Window API

export type WindowApiSurface = {
    displayExtensionUnloaded: {
        params: void;
        return: void;
    };
};

type WindowApiNames = BaseApiNames<WindowApiSurface>;

export type WindowApiMapInit = BaseApiMapInit<WindowApiSurface>;

export type WindowApiMap = BaseApiMap<WindowApiSurface, []>;

export type WindowApiHandler<TName extends WindowApiNames> = BaseApiHandler<WindowApiSurface[TName]>;

type WindowApiParams<TName extends WindowApiNames> = BaseApiParams<WindowApiSurface[TName]>;

export type WindowApiMessageAny = {[name in WindowApiNames]: WindowApiMessage<name>}[WindowApiNames];

type WindowApiMessage<TName extends WindowApiNames> = {
    action: TName;
    params: WindowApiParams<TName>;
};

export type WindowApiFrameClientMessageAny = {[name in WindowApiNames]: FrameClientMessage<WindowApiMessage<name>>}[WindowApiNames];