UNPKG

1.98 kBTypeScriptView Raw
1import { SimpleDocument, SimpleElement, SimpleNode } from '@simple-dom/interface';
2interface GenericElementTags {
3 HTML: HTMLElement;
4 SVG: SVGElement;
5 ELEMENT: HTMLElement | SVGElement;
6}
7interface GenericNodeTags {
8 NODE: Node;
9}
10declare type GenericNodeTag = keyof GenericNodeTags;
11interface BrowserElementTags extends HTMLElementTagNameMap, GenericElementTags {
12}
13declare type BrowserElementTag = keyof BrowserElementTags;
14interface BrowserTags extends BrowserElementTags, GenericNodeTags {
15}
16declare type BrowserTag = keyof BrowserTags;
17declare type NodeCheck<N extends Node> = (node: Node) => node is N;
18declare type SugaryNodeCheck<K extends BrowserTag = BrowserTag> = NodeCheck<BrowserTags[K]> | K | K[];
19declare type NodeForSugaryCheck<S extends SugaryNodeCheck<BrowserTag>> = S extends NodeCheck<infer N> ? N : S extends keyof BrowserTags ? BrowserTags[S] : S extends (keyof BrowserTags)[] ? BrowserTags[S[number]] : never;
20declare type BrowserNode = Element | Document | DocumentFragment | Text | Comment | Node;
21export declare function castToSimple(doc: Document | SimpleDocument): SimpleDocument;
22export declare function castToSimple(elem: Element | SimpleElement): SimpleElement;
23export declare function castToSimple(node: Node | SimpleNode): SimpleNode;
24export declare function castToBrowser(doc: Document | SimpleDocument): Document;
25export declare function castToBrowser<S extends SugaryNodeCheck<BrowserElementTag>>(node: BrowserNode | SimpleNode, check: S): NodeForSugaryCheck<S>;
26export declare function castToBrowser<S extends SugaryNodeCheck<GenericNodeTag>>(element: BrowserNode | SimpleNode, check: S): NodeForSugaryCheck<S>;
27export declare function castToBrowser<K extends keyof HTMLElementTagNameMap>(element: SimpleElement | Element, check: K): HTMLElementTagNameMap[K];
28export declare function checkNode<S extends SugaryNodeCheck>(node: Node | null, check: S): NodeForSugaryCheck<S>;
29export {};
30//# sourceMappingURL=simple-cast.d.ts.map
\No newline at end of file