forked from Zerthox/betterdiscord-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom.d.ts
60 lines (49 loc) · 1.9 KB
/
dom.d.ts
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
import { Cancel, Bound } from ".";
export interface DOM {
/** Current width of the user's screen. */
get screenHeight(): number;
/** Current height of the user's screen. */
get screenWidth(): number;
/** Adds a `<style>` to the document with the given ID. */
addStyle(id: string, css: string): void;
/** Removes a `<style>` from the document corresponding to the given ID. */
removeStyle(id: string): void;
/** Adds a listener for when the node is removed from the document body. */
onRemoved(node: HTMLElement, callback: () => void): Cancel;
/** Utility to help smoothly animate using JavaScript. */
animate(
update: (progress: number) => void,
duration: number,
options?: AnimateOptions,
): void;
/**
* Utility function to make creating DOM elements easier.
* Acts similarly to `React.createElement`.
*/
createElement(
tag: string,
options?: CreateElementOptions,
child?: HTMLElement,
): HTMLElement;
/**
* Parses a string of HTML and returns the results.
* If the second parameter is `true`, the parsed HTML will be returned as a document fragment.
* This is extremely useful if you have a list of elements at the top level, they can then be appended all at once to another node.
*
* If the second parameter is `false`, then the return value will be the list of parsed nodes
* and there were multiple top level nodes, otherwise the single node is returned.
*/
parseHTML<F extends boolean = false>(
html: string,
fragment?: F,
): F extends true ? DocumentFragment : NodeList | HTMLElement;
}
export type BoundDOM = Bound<DOM, "addStyle" | "removeStyle">;
export interface AnimateOptions {
timing?: (timeFraction: number) => number;
}
export interface CreateElementOptions {
id?: string;
className?: string;
target?: HTMLElement;
}