aboutsummaryrefslogtreecommitdiff
path: root/types
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 17:43:53 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 17:43:53 -0500
commit29317da4ea237557e1805a834913dad73c51ed8a (patch)
treee19ff6014774b42a95c22dbc7874b51d7bc3bf66 /types
parenta96be7d413c8f1714f0d1b44b3987f2eb87b22d8 (diff)
Update offscreen
Diffstat (limited to 'types')
-rw-r--r--types/ext/dictionary-database.d.ts2
-rw-r--r--types/ext/offscreen.d.ts115
-rw-r--r--types/ext/translator.d.ts12
3 files changed, 128 insertions, 1 deletions
diff --git a/types/ext/dictionary-database.d.ts b/types/ext/dictionary-database.d.ts
index 2e0f854b..06a246e8 100644
--- a/types/ext/dictionary-database.d.ts
+++ b/types/ext/dictionary-database.d.ts
@@ -35,7 +35,7 @@ export interface MediaDataBase<TContentType = unknown> {
export interface MediaDataArrayBufferContent extends MediaDataBase<ArrayBuffer> {}
export interface MediaDataStringContent extends MediaDataBase<string> {}
-export type Media = {index: number} & MediaDataBase<ArrayBuffer>;
+export type Media<T extends (ArrayBuffer | string) = ArrayBuffer> = {index: number} & MediaDataBase<T>;
export type DatabaseTermEntry = {
expression: string;
diff --git a/types/ext/offscreen.d.ts b/types/ext/offscreen.d.ts
new file mode 100644
index 00000000..7dd64d1e
--- /dev/null
+++ b/types/ext/offscreen.d.ts
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2023 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 Core from './core';
+import type * as Deinflector from './deinflector';
+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 Translation from './translation';
+import type * as Translator from './translator';
+
+export type MessageAny2 = Message<keyof MessageDetailsMap>;
+
+export type Message<T extends MessageType> = (
+ MessageDetailsMap[T] extends undefined ?
+ {action: T} :
+ {action: T, params: MessageDetailsMap[T]}
+);
+
+export type MessageReturn<T extends MessageType> = MessageReturnMap[T];
+
+type MessageDetailsMap = {
+ databasePrepareOffscreen: undefined;
+ getDictionaryInfoOffscreen: undefined;
+ databasePurgeOffscreen: undefined;
+ databaseGetMediaOffscreen: {
+ targets: DictionaryDatabase.MediaRequest[];
+ };
+ translatorPrepareOffscreen: {
+ deinflectionReasons: Deinflector.ReasonsRaw;
+ };
+ findKanjiOffscreen: {
+ text: string;
+ options: FindKanjiOptionsOffscreen;
+ };
+ findTermsOffscreen: {
+ mode: Translator.FindTermsMode;
+ text: string;
+ options: FindTermsOptionsOffscreen;
+ };
+ getTermFrequenciesOffscreen: {
+ termReadingList: Translator.TermReadingList;
+ dictionaries: string[];
+ };
+ clearDatabaseCachesOffscreen: undefined;
+ clipboardSetBrowserOffscreen: {
+ value: Environment.Browser | null;
+ };
+ clipboardGetTextOffscreen: {
+ useRichText: boolean;
+ };
+ clipboardGetImageOffscreen: undefined;
+};
+
+type MessageReturnMap = {
+ databasePrepareOffscreen: void;
+ getDictionaryInfoOffscreen: DictionaryImporter.Summary[];
+ databasePurgeOffscreen: boolean;
+ databaseGetMediaOffscreen: DictionaryDatabase.Media<string>[];
+ translatorPrepareOffscreen: void;
+ findKanjiOffscreen: Dictionary.KanjiDictionaryEntry[];
+ findTermsOffscreen: Translator.FindTermsResult;
+ getTermFrequenciesOffscreen: Translator.TermFrequencySimple[];
+ clearDatabaseCachesOffscreen: void;
+ clipboardSetBrowserOffscreen: void;
+ clipboardGetTextOffscreen: string;
+ clipboardGetImageOffscreen: string | null;
+};
+
+export type MessageType = keyof MessageDetailsMap;
+
+export type FindKanjiOptionsOffscreen = Omit<Translation.FindKanjiOptions, 'enabledDictionaryMap'> & {
+ enabledDictionaryMap: [
+ key: string,
+ options: Translation.FindKanjiDictionary,
+ ][];
+};
+
+
+export type FindTermsOptionsOffscreen = Omit<Translation.FindTermsOptions, 'enabledDictionaryMap' | 'excludeDictionaryDefinitions' | 'textReplacements'> & {
+ enabledDictionaryMap: [
+ key: string,
+ options: Translation.FindTermDictionary,
+ ][];
+ excludeDictionaryDefinitions: string[] | null;
+ textReplacements: (FindTermsTextReplacementOffscreen[] | null)[];
+};
+
+export type FindTermsTextReplacementOffscreen = Omit<Translation.FindTermsTextReplacement, 'pattern'> & {
+ pattern: string;
+};
+
+export type MessageHandler<
+ TMessage extends MessageType,
+ TIsAsync extends boolean,
+> = (
+ details: MessageDetailsMap[TMessage],
+) => (TIsAsync extends true ? Promise<MessageReturn<TMessage>> : MessageReturn<TMessage>);
+
+export type MessageHandlerMap = Map<MessageType, Core.MessageHandlerDetails>;
diff --git a/types/ext/translator.d.ts b/types/ext/translator.d.ts
index f17b3bf6..e7d45295 100644
--- a/types/ext/translator.d.ts
+++ b/types/ext/translator.d.ts
@@ -81,3 +81,15 @@ export type SequenceQuery = {
};
export type FindTermsMode = 'simple' | 'group' | 'merge' | 'split';
+
+export type TermReadingItem = {
+ term: string;
+ reading: string | null;
+};
+
+export type TermReadingList = TermReadingItem[];
+
+export type FindTermsResult = {
+ dictionaryEntries: Dictionary.TermDictionaryEntry[];
+ originalTextLength: number;
+};