tridactyl/src/tridactyl.d.ts

126 lines
3.5 KiB
TypeScript
Raw Normal View History

// Interfaces common to the tridactyl project.
// For some obscure reason, tsc doesn't like .d.ts files to share a name with
// .ts files. So don't do that.
// Ill-advised monkeypatching
interface Number {
mod(n: number): number
clamp(lo: number, hi: number): number
}
2017-09-28 22:39:26 +01:00
// Firefox-specific dom properties
interface Window {
scrollByLines(n: number): void
scrollByPages(n: number): void
eval(str: string): any
}
// Record that we've added a property with convenience objects to the
// window object:
interface Window {
tri: any
}
2018-06-24 13:36:06 +02:00
// This isn't an actual firefox type but it's nice to have one for this kind of object
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/find/find
interface findResult {
count: number
2020-06-18 21:57:16 +01:00
rangeData: Array<{
2018-06-24 13:36:06 +02:00
framePos: number
startTextNodePos: number
endTextNodePos: number
startOffset: number
endOffset: number
text: string
2020-06-18 21:57:16 +01:00
}>
2018-06-24 13:36:06 +02:00
rectData: {
2020-06-18 21:57:16 +01:00
rectsAndTexts: Array<{
2018-06-24 13:36:06 +02:00
top: number
left: number
bottom: number
right: number
2020-06-18 21:57:16 +01:00
}>
2018-06-24 13:36:06 +02:00
textList: string[]
}
}
interface HTMLElement {
// Let's be future proof:
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus
2020-06-19 13:11:03 +01:00
focus(options?: any): void
}
2020-06-18 21:55:04 +01:00
/* eslint-disable @typescript-eslint/ban-types */
// these functions really can be anything, ditto for the objects
declare function exportFunction(
func: Function,
targetScope: object,
options?: { defineAs?: string; allowCrossOriginArguments?: boolean },
): Function
2020-06-18 21:55:04 +01:00
/* eslint-enable @typescript-eslint/ban-types */
// Web extension types not in web-ext-types yet
declare namespace browser.find {
function find(query, object): any
}
2017-11-15 12:40:26 +00:00
declare namespace browser.tabs {
function setZoom(zoomFactor: number): Promise<void>
2020-06-19 13:11:03 +01:00
// setZoom has an optional first argument of tabId: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/setZoom#Parameters
// eslint-disable-next-line @typescript-eslint/unified-signatures
function setZoom(tabId: number, zoomFactor: number): Promise<void>
function toggleReaderMode(tabId?: number): Promise<void>
2017-11-15 12:40:26 +00:00
}
// web-ext-browser barely declares a third of the management
// interface, and we can't switch to @types/firefox-webext-browser yet
// because their enums are all messed up (see
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/28369)
// Instead, we'll copy-paste as much as we need from the fixed branch:
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d1180e5218a7bf69e6f0da5ac2e2584bd57a1cdf/types/firefox-webext-browser/index.d.ts
interface WebExtEventBase<
TAddListener extends (...args: any[]) => any,
TCallback
> {
addListener: TAddListener
removeListener(cb: TCallback): void
hasListener(cb: TCallback): boolean
}
// html-tagged-template.js
declare function html(
strings: TemplateStringsArray,
...values: any[]
): HTMLElement
declare namespace browser.search {
function search(searchProperties: {
query: string
engine?: string
tabId?: number
}): void
function get(): Promise<
Array<{
name: string
isDefault: boolean
alias?: string
faviconURL?: string
}>
>
}
2018-05-21 01:22:04 +01:00
// Stop typedoc complaining about toBeAll.
declare namespace jest {
interface Matchers<R> {
toBeAll: any
}
}
2020-07-05 21:56:44 +01:00
// jest-webextension-mock doesn't know about this Firefox specific API
declare namespace browser.commands {
function update(details)
}