-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
64 lines (61 loc) · 2.29 KB
/
types.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
61
62
63
64
import type { CssProperty } from './css-properties.js';
import type { PickPropertyValues } from './css-property-values.js';
import type { CTag } from './tag.js';
import type { ValidTagName } from './tag-names.js';
export type StyleMap = { [key in CssProperty]?: PickPropertyValues<key> };
export type NoOp = () => void;
// eslint-disable-next-line @typescript-eslint/array-type, @typescript-eslint/ban-types
export type KeysOf<T extends Record<string, unknown>> = keyof T;
export type Suffix<K extends string, T extends string> = `${T}${K}`;
export type Suffixer<K, T extends string> = {
[P in keyof K as Suffix<T, string & P>]: K[P];
};
export type Primitive = number | string | boolean | symbol | bigint;
export type NestedStyleMap = {
[key in CssProperty]?: PickPropertyValues<key> | StyleMap;
};
export type StyleSet = Record<string, NestedStyleMap>;
export type TagChildren = TagChild[];
export type EventCallback<T extends EventName> = (
tag: CTag,
evt: HTMLElementEventMap[T],
) => void;
export type EventName = keyof HTMLElementEventMap;
export type EventMap = {
[k in EventName]?: EventCallback<k>;
};
export type TagBuilder = (children: TagChildren, silent: boolean) => CTag;
export interface IConsumable<T = any> {
changed: (callback: (newValue: T) => void) => IConsumable<T>;
remove: (callback: (newValue: T) => void) => IConsumable<T>;
dispatch: (newValue: T) => IConsumable<T>;
destroy: () => void;
intersect: <K>(intersector: (val: T) => K) => IConsumable<K>;
value: T;
prev?: T;
}
export type IConsumableOr<T = any> = IConsumable<T> | T;
export interface WithLength {
length: number;
}
export type TextObj<T extends IConsumable<Primitive> = any> = Record<string, T>;
export type TagChild = string | CTag | HTMLElement | Node | IConsumable<any>;
export interface TagConfig {
style?: StyleMap;
attr?: Record<string, string | undefined>;
classList?: string[];
text?: string;
children?: TagChildren;
on?: EventMap;
value?: string;
className?: string;
}
export type PickArgType<T> = T extends 'style' ? StyleSet[] : TagChildren;
export type AllTags = {
[key in ValidTagName]: ((...children: PickArgType<key>) => CTag) & {
/**
* This will attach (append) this tag to the currently attached tag if there is one.
*/
attach: (...children: PickArgType<key>) => CTag;
};
};