aboutsummaryrefslogtreecommitdiff
path: root/types/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-12-29 00:02:14 -0500
committerGitHub <noreply@github.com>2023-12-29 05:02:14 +0000
commit8b68504b3b95d0647b4305a43d7b326b801e1936 (patch)
tree106cfa2eb67bb5630c40dc63a4b8d9b2e1d8fa6d /types/ext
parent6a072dfdacf26d309bf8cd570c05f4d4b57c9af2 (diff)
Display API safety (#479)
* Remove unused * Add TODOs * Rename * Initial setup * More updates * Simplify naming * Set up window API * Remove type * Move type * Update type
Diffstat (limited to 'types/ext')
-rw-r--r--types/ext/display.d.ts118
1 files changed, 103 insertions, 15 deletions
diff --git a/types/ext/display.d.ts b/types/ext/display.d.ts
index bafb1fa1..f7c45b02 100644
--- a/types/ext/display.d.ts
+++ b/types/ext/display.d.ts
@@ -18,12 +18,19 @@
import type {DisplayContentManager} from '../../ext/js/display/display-content-manager';
import type {HotkeyHelpController} from '../../ext/js/input/hotkey-help-controller';
import type {JapaneseUtil} from '../../ext/js/language/sandbox/japanese-util';
-import type * as Core from './core';
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 {
+ ApiMap as BaseApiMap,
+ ApiParams as BaseApiParams,
+ ApiNames as BaseApiNames,
+ ApiMapInit as BaseApiMapInit,
+ ApiParamsAny as BaseApiParamsAny,
+ ApiHandler as BaseApiHandler,
+} from './api-map';
export type HistoryMode = 'clear' | 'overwrite' | 'new';
@@ -159,22 +166,103 @@ export type Events = {
export type EventArgument<TName extends EventNames<Events>> = BaseEventArgument<Events, TName>;
-export type ConfigureMessageDetails = {
- depth: number;
- parentPopupId: string;
- parentFrameId: number;
- childrenSupported: boolean;
- scale: number;
- optionsContext: Settings.OptionsContext;
-};
-
-export type MessageDetails = {
- action: string;
- params: Core.SerializableObject;
-};
-
export type DisplayGeneratorConstructorDetails = {
japaneseUtil: JapaneseUtil;
contentManager: DisplayContentManager;
hotkeyHelpController?: HotkeyHelpController | null;
};
+
+// 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;
+ };
+};
+
+type DirectApiNames = BaseApiNames<DirectApiSurface>;
+
+export type DirectApiMapInit = BaseApiMapInit<DirectApiSurface>;
+
+export type DirectApiMap = BaseApiMap<DirectApiSurface, []>;
+
+export type DirectApiHandler<TName extends DirectApiNames> = BaseApiHandler<DirectApiSurface[TName]>;
+
+type DirectApiParams<TName extends DirectApiNames> = BaseApiParams<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>;
+};
+
+// 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>;
+};