ajo 0.1.30 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types.ts CHANGED
@@ -1,90 +1,135 @@
1
- declare module 'ajo' {
2
-
3
- type Tag = keyof (HTMLElementTagNameMap & SVGElementTagNameMap)
4
-
5
- type Type<TArguments extends Args = {}, TTag extends Tag = 'div'> = Tag | Stateless<TArguments> | Stateful<TArguments, TTag>
6
-
7
- type Component<TArguments extends Args = {}> = Stateless<TArguments> | Stateful<TArguments>
8
-
9
- type Args = Record<string, unknown>
10
-
11
- type VNode<TTag extends Type, TArgs extends Args> = TArgs & {
12
- nodeName: TTag,
13
- children?: Children,
14
- }
15
-
16
- type Children = unknown
17
-
18
- type ElementType<TTag> = TTag extends keyof HTMLElementTagNameMap
19
- ? HTMLElementTagNameMap[TTag]
20
- : TTag extends keyof SVGElementTagNameMap
21
- ? SVGElementTagNameMap[TTag]
22
- : never
23
-
24
- type SpecialAttrs<TElement> = {
25
- key: unknown,
26
- skip: boolean,
27
- memo: unknown,
28
- ref: (el: TElement | null) => void,
29
- } & ElementChildrenAttribute
30
-
31
- type PropSetter<TTag> = {
32
- [K in keyof ElementType<TTag> as `set:${Exclude<K, symbol>}`]: ElementType<TTag>[K]
33
- }
34
-
35
- type AttrSetter = {
36
- [key: `attr:${string}`]: unknown
37
- }
38
-
39
- type Stateless<TArguments extends Args = {}> = (args: TArguments) => Children
40
-
41
- type Stateful<TArguments extends Args = {}, TTag extends Tag = 'div'> = {
42
- (this: StatefulElement<TArguments, TTag>, args: StatefulArgs<TArguments, TTag>): Iterator<Children>
43
- } & (TTag extends 'div' ? { is?: TTag } : { is: TTag }) & {
44
- attrs?: Partial<PropSetter<TTag>> & Args,
45
- args?: Partial<TArguments>,
46
- src?: string,
47
- fallback?: Children,
48
- }
49
-
50
- type StatefulArgs<TArguments, TTag> =
51
- Partial<SpecialAttrs<StatefulElement<TArguments, TTag>> & PropSetter<TTag>> &
52
- AttrSetter &
53
- TArguments
54
-
55
- type StatefulElement<TArguments, TTag> = ElementType<TTag> & {
56
- next: (fn?: (this: StatefulElement<TArguments, TTag>, args: StatefulArgs<TArguments, TTag>) => void) => void,
57
- throw: (value?: unknown) => void,
58
- return: () => void,
59
- }
60
-
61
- type IntrinsicElements = {
62
- [TTag in Tag]: Partial<PropSetter<TTag> & SpecialAttrs<ElementType<TTag>>> & Args
63
- }
64
-
65
- type ElementChildrenAttribute = { children: Children }
66
-
67
- type WithChildren<T extends Args = {}> = T & Partial<ElementChildrenAttribute>
68
-
69
- function Fragment({ children }: ElementChildrenAttribute): typeof children
70
- function h(tag: Type, attrs?: Args | null, ...children: Children[]): VNode<Type, Args>
71
- function render(h: Children, el: ParentNode, child?: ChildNode, ref?: ChildNode): void
72
- }
73
-
74
- declare module 'ajo/context' {
75
- function context<T>(fallback?: T): {
76
- (): T
77
- <V extends T>(value: V): V
78
- }
79
- function current(): import('ajo').StatefulElement<any, any> | null
80
- }
81
-
82
- declare module 'ajo/html' {
83
- function render(h: import('ajo').Children): string
84
- function html(h: import('ajo').Children): IterableIterator<string>
85
- }
86
-
87
- declare namespace JSX {
88
- type ElementChildrenAttribute = import('ajo').ElementChildrenAttribute
89
- type IntrinsicElements = import('ajo').IntrinsicElements
90
- }
1
+ declare module 'ajo' {
2
+
3
+ type Tag = keyof (HTMLElementTagNameMap & SVGElementTagNameMap)
4
+
5
+ type Type = Tag | (string & {}) | Stateless | Stateful
6
+
7
+ type Children = unknown
8
+
9
+ type Args = Record<string, unknown>
10
+
11
+ type VNode = {
12
+ nodeName: Type,
13
+ children?: Children,
14
+ [key: string]: unknown,
15
+ }
16
+
17
+ type ElementType<TTag> = TTag extends keyof HTMLElementTagNameMap
18
+ ? HTMLElementTagNameMap[TTag]
19
+ : TTag extends keyof SVGElementTagNameMap
20
+ ? SVGElementTagNameMap[TTag]
21
+ : object
22
+
23
+ type SpecialAttrs<TElement> = {
24
+ key: string | number,
25
+ skip: boolean,
26
+ memo: unknown,
27
+ ref: (el: TElement | null) => void,
28
+ } & ElementChildrenAttribute
29
+
30
+ type PropSetter<TTag> = {
31
+ [K in keyof ElementType<TTag> as `set:${Exclude<K, symbol>}`]: ElementType<TTag>[K]
32
+ }
33
+
34
+ type AttrSetter = {
35
+ [key: `attr:${string}`]: unknown
36
+ }
37
+
38
+ interface Defaults { }
39
+
40
+ type DefaultTag = Defaults extends { tag: infer T extends string } ? T : 'div'
41
+
42
+ const defaults: { tag: string }
43
+
44
+ type Stateless<TArgs extends Args = {}> = (args: TArgs) => Children
45
+
46
+ type Stateful<TArgs extends Args = {}, TTag extends string = DefaultTag> = {
47
+ (this: StatefulElement<TArgs, TTag>, args: TArgs): Iterator<Children>
48
+ } & (TTag extends DefaultTag ? { is?: TTag } : { is: TTag }) & {
49
+ attrs?: Partial<PropSetter<TTag>> & Args,
50
+ args?: Partial<TArgs>,
51
+ }
52
+
53
+ type Component<TArgs extends Args = {}> = Stateless<TArgs> | Stateful<TArgs>
54
+
55
+ type StatefulArgs<TArgs, TTag> =
56
+ Partial<SpecialAttrs<StatefulElement<TArgs, TTag>> & PropSetter<TTag>> &
57
+ AttrSetter &
58
+ TArgs
59
+
60
+ type StatefulElement<TArgs, TTag> = ElementType<TTag> & {
61
+ [Symbol.iterator](): Iterator<TArgs>,
62
+ signal: AbortSignal,
63
+ next: <R>(fn?: (this: StatefulElement<TArgs, TTag>, args: TArgs) => R) => R,
64
+ throw: (value?: unknown) => void,
65
+ return: (deep?: boolean) => void,
66
+ }
67
+
68
+ type HTMLIntrinsicElements = {
69
+ [TTag in Tag]: Partial<PropSetter<TTag> & SpecialAttrs<ElementType<TTag>>> & Args
70
+ }
71
+
72
+ interface IntrinsicElements extends HTMLIntrinsicElements { }
73
+
74
+ type ElementChildrenAttribute = { children: Children }
75
+
76
+ type WithChildren<T extends Args = {}> = T & Partial<ElementChildrenAttribute>
77
+
78
+ type ManagedAttributes<C, P> =
79
+ C extends (...args: any) => Iterator<any>
80
+ ? C extends { is?: infer TTag }
81
+ ? StatefulArgs<P, TTag & string>
82
+ : P
83
+ : P
84
+
85
+ function render(h: Children, el: ParentNode, child?: ChildNode, ref?: ChildNode): void
86
+
87
+ function stateful<TArgs extends Args, TTag extends string = DefaultTag>(
88
+ fn: (this: StatefulElement<TArgs, TTag>, args: TArgs) => Iterator<Children>,
89
+ is?: TTag
90
+ ): Stateful<TArgs, TTag>
91
+ }
92
+
93
+ declare module 'ajo/context' {
94
+ function context<T>(fallback?: T): {
95
+ (): T
96
+ <V extends T>(value: V): V
97
+ }
98
+ function current(): import('ajo').StatefulElement<any, any> | null
99
+ }
100
+
101
+ declare module 'ajo/html' {
102
+ const defaults: { tag: string }
103
+ function render(h: import('ajo').Children): string
104
+ function html(h: import('ajo').Children, emit: (chunk: string) => void): void
105
+ }
106
+
107
+ declare module 'ajo/jsx-runtime' {
108
+ import { Type, Args, VNode, Children, ElementChildrenAttribute, IntrinsicElements as _IE } from 'ajo'
109
+ export function Fragment({ children }: ElementChildrenAttribute): typeof children
110
+ export function h(tag: Type, attrs?: Args | null, ...children: Children[]): VNode
111
+ export function jsx(type: Type, props: Args | null, key?: string | number): VNode
112
+ export function jsxs(type: Type, props: Args | null, key?: string | number): VNode
113
+ export function jsxDEV(type: Type, props: Args | null, key?: string | number): VNode
114
+ export namespace JSX {
115
+ type ElementChildrenAttribute = import('ajo').ElementChildrenAttribute
116
+ type LibraryManagedAttributes<C, P> = import('ajo').ManagedAttributes<C, P>
117
+ interface IntrinsicElements extends _IE { }
118
+ }
119
+ }
120
+
121
+ declare module 'ajo/jsx-dev-runtime' {
122
+ import { IntrinsicElements as _IE } from 'ajo'
123
+ export { Fragment, h, jsx, jsxs, jsxDEV } from 'ajo/jsx-runtime'
124
+ export namespace JSX {
125
+ type ElementChildrenAttribute = import('ajo').ElementChildrenAttribute
126
+ type LibraryManagedAttributes<C, P> = import('ajo').ManagedAttributes<C, P>
127
+ interface IntrinsicElements extends _IE { }
128
+ }
129
+ }
130
+
131
+ declare namespace JSX {
132
+ type ElementChildrenAttribute = import('ajo').ElementChildrenAttribute
133
+ type LibraryManagedAttributes<C, P> = import('ajo').ManagedAttributes<C, P>
134
+ type IntrinsicElements = import('ajo').IntrinsicElements
135
+ }