-
Notifications
You must be signed in to change notification settings - Fork 5
/
dreamland.d.ts
107 lines (88 loc) · 2.74 KB
/
dreamland.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
declare namespace JSX {
export type IntrinsicElements = {
[index: string]: any
}
type ElementType = Fragment | string | Component<any, any, any>
type Element = DLElement<any>
interface ElementAttributesProperty {
props: {}
}
interface ElementChildrenAttribute {
children: {}
}
}
declare function h(
type: string | Component<any, any, any>,
props?: { [index: string]: any } | null,
...children: (HTMLElement | string)[]
): Node
declare function $if(
condition: DLPointer<any> | any,
then?: Element,
otherwise?: Element
): HTMLElement
type DLPointer<T> = {
readonly __symbol: unique symbol
readonly __signature: T
readonly value: T
}
declare function use<T>(sink: T, mapping?: (arg: T) => any): DLPointer<T>
declare function use(
template: TemplateStringsArray,
...params: any[]
): DLPointer<string>
type Stateful<T> = T & { readonly symbol: unique symbol }
declare function $state<T>(target: T): Stateful<T>
declare function $store<T>(
target: T,
options: {
ident: string
backing:
| 'localstorage'
| { read: () => string; write: (value: string) => void }
autosave: 'auto' | 'manual' | 'beforeunload'
}
): Stateful<T>
declare function useChange<T>(
references: DLPointer<T>[] | DLPointer<T> | T | T[],
callback: (changedvalue: T) => void
): void
declare function isDLPtr(ptr: any): boolean
declare function isStateful(object: any): boolean
declare function css(strings: TemplateStringsArray, ...values: any): string
type DLCSS = string
declare var $el: HTMLElement
type Fragment = { readonly fragment: unique symbol }
declare var Fragment: Fragment
interface Element {
$: OuterComponentTypes & { [index: string | symbol]: any }
}
interface DLElement<T> extends HTMLElement {
$: T & OuterComponentTypes
}
type ComponentElement<T extends (...args: any) => any> = ReturnType<T>
type ComponentType<T extends (...args: any) => any> = ReturnType<T>['$']
type OuterComponentTypes = {
root: Element
children: Element[]
}
type InnerComponentTypes = {
css: DLCSS
mount?: () => void
}
type ComponentTypes = OuterComponentTypes & InnerComponentTypes
type ArrayOrSingular<T extends []> = T | T[keyof T]
type Component<Props = {}, Private = {}, Public = {}> = (
this: Props & Private & Public & ComponentTypes,
props: Props & {
children?: ArrayOrSingular<
Private extends { children: any }
? Private['children']
: Public extends { children: any }
? Public['children']
: never
>
} & {
[K in keyof Props as `bind:${Extract<K, string>}`]?: DLPointer<Props[K]>
}
) => DLElement<Props & Public>