kiru 0.44.4
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/LICENSE +7 -0
- package/README.md +5 -0
- package/package.json +81 -0
- package/src/appContext.ts +186 -0
- package/src/cloneVNode.ts +14 -0
- package/src/constants.ts +146 -0
- package/src/context.ts +56 -0
- package/src/dom.ts +712 -0
- package/src/element.ts +54 -0
- package/src/env.ts +6 -0
- package/src/error.ts +85 -0
- package/src/flags.ts +15 -0
- package/src/form/index.ts +662 -0
- package/src/form/types.ts +261 -0
- package/src/form/utils.ts +19 -0
- package/src/generateId.ts +19 -0
- package/src/globalContext.ts +161 -0
- package/src/globals.ts +21 -0
- package/src/hmr.ts +178 -0
- package/src/hooks/index.ts +14 -0
- package/src/hooks/useAsync.ts +136 -0
- package/src/hooks/useCallback.ts +31 -0
- package/src/hooks/useContext.ts +79 -0
- package/src/hooks/useEffect.ts +44 -0
- package/src/hooks/useEffectEvent.ts +24 -0
- package/src/hooks/useId.ts +42 -0
- package/src/hooks/useLayoutEffect.ts +47 -0
- package/src/hooks/useMemo.ts +33 -0
- package/src/hooks/useReducer.ts +50 -0
- package/src/hooks/useRef.ts +40 -0
- package/src/hooks/useState.ts +62 -0
- package/src/hooks/useSyncExternalStore.ts +59 -0
- package/src/hooks/useViewTransition.ts +26 -0
- package/src/hooks/utils.ts +259 -0
- package/src/hydration.ts +67 -0
- package/src/index.ts +61 -0
- package/src/jsx.ts +11 -0
- package/src/lazy.ts +238 -0
- package/src/memo.ts +48 -0
- package/src/portal.ts +43 -0
- package/src/profiling.ts +105 -0
- package/src/props.ts +36 -0
- package/src/reconciler.ts +531 -0
- package/src/renderToString.ts +91 -0
- package/src/router/index.ts +2 -0
- package/src/router/route.ts +51 -0
- package/src/router/router.ts +275 -0
- package/src/router/routerUtils.ts +49 -0
- package/src/scheduler.ts +522 -0
- package/src/signals/base.ts +237 -0
- package/src/signals/computed.ts +139 -0
- package/src/signals/effect.ts +60 -0
- package/src/signals/globals.ts +11 -0
- package/src/signals/index.ts +12 -0
- package/src/signals/jsx.ts +45 -0
- package/src/signals/types.ts +10 -0
- package/src/signals/utils.ts +12 -0
- package/src/signals/watch.ts +151 -0
- package/src/ssr/client.ts +29 -0
- package/src/ssr/hydrationBoundary.ts +63 -0
- package/src/ssr/index.ts +1 -0
- package/src/ssr/server.ts +124 -0
- package/src/store.ts +241 -0
- package/src/swr.ts +360 -0
- package/src/transition.ts +80 -0
- package/src/types.dom.ts +1250 -0
- package/src/types.ts +209 -0
- package/src/types.utils.ts +39 -0
- package/src/utils.ts +581 -0
- package/src/warning.ts +9 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { ReadonlySignal, Signal as SignalClass } from "./signals"
|
|
2
|
+
import type {
|
|
3
|
+
$CONTEXT,
|
|
4
|
+
$CONTEXT_PROVIDER,
|
|
5
|
+
$FRAGMENT,
|
|
6
|
+
$HYDRATION_BOUNDARY,
|
|
7
|
+
} from "./constants"
|
|
8
|
+
import type { KaiokenGlobalContext } from "./globalContext"
|
|
9
|
+
import type {
|
|
10
|
+
GlobalAttributes,
|
|
11
|
+
HtmlElementAttributes,
|
|
12
|
+
SvgElementAttributes,
|
|
13
|
+
SvgGlobalAttributes,
|
|
14
|
+
StyleObject,
|
|
15
|
+
HtmlElementBindableProps,
|
|
16
|
+
HTMLTagToElement,
|
|
17
|
+
SVGTagToElement,
|
|
18
|
+
} from "./types.dom"
|
|
19
|
+
import { Signalable, SomeDom } from "./types.utils"
|
|
20
|
+
|
|
21
|
+
export type { ElementProps, StyleObject }
|
|
22
|
+
|
|
23
|
+
type ElementProps<T extends keyof JSX.IntrinsicElements> =
|
|
24
|
+
JSX.IntrinsicElements[T]
|
|
25
|
+
|
|
26
|
+
type SignalableHtmlElementAttributes<Tag extends keyof HtmlElementAttributes> =
|
|
27
|
+
{
|
|
28
|
+
[K in keyof HtmlElementAttributes[Tag]]: Signalable<
|
|
29
|
+
HtmlElementAttributes[Tag][K]
|
|
30
|
+
>
|
|
31
|
+
} & (Tag extends keyof HtmlElementBindableProps
|
|
32
|
+
? HtmlElementBindableProps[Tag]
|
|
33
|
+
: {})
|
|
34
|
+
type SignalableSvgElementAttributes<Tag extends keyof SvgElementAttributes> = {
|
|
35
|
+
[K in keyof SvgElementAttributes[Tag]]: Signalable<
|
|
36
|
+
SvgElementAttributes[Tag][K]
|
|
37
|
+
>
|
|
38
|
+
}
|
|
39
|
+
type SignalableAriaProps = {
|
|
40
|
+
[K in keyof ARIAMixin]?: Signalable<ARIAMixin[K]>
|
|
41
|
+
}
|
|
42
|
+
type SignalableGlobalAttributes = {
|
|
43
|
+
[K in keyof GlobalAttributes]: Signalable<GlobalAttributes[K]>
|
|
44
|
+
}
|
|
45
|
+
type SignalableSvgGlobalAttributes = {
|
|
46
|
+
[K in keyof SvgGlobalAttributes]: Signalable<SvgGlobalAttributes[K]>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type ElementMap = {
|
|
50
|
+
[Tag in keyof HtmlElementAttributes]: SignalableHtmlElementAttributes<Tag> &
|
|
51
|
+
SignalableGlobalAttributes &
|
|
52
|
+
SignalableAriaProps &
|
|
53
|
+
Kaioken.EventAttributes<HTMLTagToElement<Tag>> &
|
|
54
|
+
JSX.ElementAttributes & {
|
|
55
|
+
ref?:
|
|
56
|
+
| Kaioken.Ref<HTMLTagToElement<Tag>>
|
|
57
|
+
| SignalClass<HTMLTagToElement<Tag> | null>
|
|
58
|
+
}
|
|
59
|
+
} & {
|
|
60
|
+
[Tag in keyof SvgElementAttributes]: SignalableSvgElementAttributes<Tag> &
|
|
61
|
+
SignalableSvgGlobalAttributes &
|
|
62
|
+
SignalableGlobalAttributes &
|
|
63
|
+
SignalableAriaProps &
|
|
64
|
+
Kaioken.EventAttributes<SVGTagToElement<Tag>> &
|
|
65
|
+
JSX.ElementAttributes & {
|
|
66
|
+
ref?:
|
|
67
|
+
| Kaioken.Ref<SVGTagToElement<Tag>>
|
|
68
|
+
| SignalClass<SVGTagToElement<Tag> | null>
|
|
69
|
+
}
|
|
70
|
+
} & {
|
|
71
|
+
[Tag in `${string}-${string}`]: Record<string, any>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare global {
|
|
75
|
+
interface Window {
|
|
76
|
+
__kaioken: KaiokenGlobalContext | undefined
|
|
77
|
+
}
|
|
78
|
+
namespace JSX {
|
|
79
|
+
interface IntrinsicElements extends ElementMap {}
|
|
80
|
+
|
|
81
|
+
interface IntrinsicAttributes {
|
|
82
|
+
key?: ElementKey
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface ElementAttributesProperty {
|
|
86
|
+
props: {}
|
|
87
|
+
}
|
|
88
|
+
interface ElementChildrenAttribute {
|
|
89
|
+
children: {}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type Children = JSX.Element | JSX.Element[]
|
|
93
|
+
|
|
94
|
+
type PrimitiveChild = string | number | bigint | boolean | undefined | null
|
|
95
|
+
|
|
96
|
+
type ElementKey = string | number
|
|
97
|
+
|
|
98
|
+
type Element =
|
|
99
|
+
| Element[]
|
|
100
|
+
| Kaioken.VNode
|
|
101
|
+
| PrimitiveChild
|
|
102
|
+
| Kaioken.Signal<PrimitiveChild>
|
|
103
|
+
|
|
104
|
+
type ElementAttributes = {
|
|
105
|
+
key?: JSX.ElementKey
|
|
106
|
+
children?: JSX.Children
|
|
107
|
+
innerHTML?:
|
|
108
|
+
| string
|
|
109
|
+
| number
|
|
110
|
+
| Kaioken.Signal<string | number | null | undefined>
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
namespace Kaioken {
|
|
114
|
+
type ProviderProps<T> = {
|
|
115
|
+
value: T
|
|
116
|
+
children?: JSX.Children | ((value: T) => JSX.Element)
|
|
117
|
+
}
|
|
118
|
+
type Context<T> = {
|
|
119
|
+
[$CONTEXT]: true
|
|
120
|
+
Provider: (({ value, children }: ProviderProps<T>) => JSX.Element) & {
|
|
121
|
+
displayName?: string
|
|
122
|
+
}
|
|
123
|
+
default: () => T
|
|
124
|
+
/** Used to display the name of the context in devtools */
|
|
125
|
+
displayName?: string
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type FC<T = {}> = ((props: FCProps<T>) => JSX.Element) & {
|
|
129
|
+
/** Used to display the name of the component in devtools */
|
|
130
|
+
displayName?: string
|
|
131
|
+
}
|
|
132
|
+
type FCProps<T = {}> = T & { children?: JSX.Children }
|
|
133
|
+
type InferProps<T> = T extends Kaioken.FC<infer P> ? P : never
|
|
134
|
+
|
|
135
|
+
type HookDevtoolsProvisions<T extends Record<string, any>> = {
|
|
136
|
+
get: () => T
|
|
137
|
+
set?: (value: T) => void
|
|
138
|
+
}
|
|
139
|
+
type Hook<T> = T & {
|
|
140
|
+
cleanup?: () => void
|
|
141
|
+
name?: string
|
|
142
|
+
dev?: {
|
|
143
|
+
/** Used to perform invalidation during HMR when the hook's arguments have changed */
|
|
144
|
+
initialArgs?: any
|
|
145
|
+
devtools?: HookDevtoolsProvisions<any>
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
type RefObject<T> = {
|
|
149
|
+
readonly current: T | null
|
|
150
|
+
}
|
|
151
|
+
type MutableRefObject<T> = {
|
|
152
|
+
current: T
|
|
153
|
+
}
|
|
154
|
+
type RefCallback<T> = {
|
|
155
|
+
bivarianceHack(instance: T | null): void
|
|
156
|
+
}["bivarianceHack"]
|
|
157
|
+
|
|
158
|
+
type Ref<T> = RefCallback<T> | RefObject<T> | null | undefined
|
|
159
|
+
|
|
160
|
+
type RenderMode = "dom" | "hydrate" | "string" | "stream"
|
|
161
|
+
|
|
162
|
+
type StateSetter<T> = T | ((prev: T) => T)
|
|
163
|
+
|
|
164
|
+
type Signal<T> = SignalClass<T> | ReadonlySignal<T>
|
|
165
|
+
|
|
166
|
+
type ExoticSymbol =
|
|
167
|
+
| typeof $FRAGMENT
|
|
168
|
+
| typeof $CONTEXT_PROVIDER
|
|
169
|
+
| typeof $HYDRATION_BOUNDARY
|
|
170
|
+
|
|
171
|
+
type VNode = {
|
|
172
|
+
dom?: SomeDom
|
|
173
|
+
lastChildDom?: SomeDom
|
|
174
|
+
type: Function | ExoticSymbol | "#text" | (string & {})
|
|
175
|
+
props: {
|
|
176
|
+
[key: string]: any
|
|
177
|
+
children?: unknown
|
|
178
|
+
key?: JSX.ElementKey
|
|
179
|
+
ref?: Kaioken.Ref<unknown>
|
|
180
|
+
}
|
|
181
|
+
index: number
|
|
182
|
+
depth: number
|
|
183
|
+
parent: VNode | null
|
|
184
|
+
child: VNode | null
|
|
185
|
+
sibling: VNode | null
|
|
186
|
+
prev: VNode | null
|
|
187
|
+
deletions: VNode[] | null
|
|
188
|
+
flags: number
|
|
189
|
+
hooks?: Hook<unknown>[]
|
|
190
|
+
subs?: Set<string>
|
|
191
|
+
cleanups?: Record<string, Function>
|
|
192
|
+
effects?: Array<Function>
|
|
193
|
+
immediateEffects?: Array<Function>
|
|
194
|
+
memoizedProps?: Record<string, any>
|
|
195
|
+
isMemoized?: boolean
|
|
196
|
+
arePropsEqual?: (
|
|
197
|
+
prev: Record<string, any>,
|
|
198
|
+
next: Record<string, any>
|
|
199
|
+
) => boolean
|
|
200
|
+
// dev-mode only
|
|
201
|
+
hookSig?: string[]
|
|
202
|
+
hmrUpdated?: boolean
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
interface Element {
|
|
207
|
+
__kaiokenNode?: Kaioken.VNode
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { $CONTEXT_PROVIDER, $HYDRATION_BOUNDARY } from "./constants"
|
|
2
|
+
import type { HydrationBoundaryMode } from "./ssr/hydrationBoundary"
|
|
3
|
+
import type { Signal } from "./signals"
|
|
4
|
+
|
|
5
|
+
export type SomeElement = HTMLElement | SVGElement
|
|
6
|
+
export type SomeDom = HTMLElement | SVGElement | Text
|
|
7
|
+
export type MaybeDom = SomeDom | undefined
|
|
8
|
+
|
|
9
|
+
type VNode = Kaioken.VNode
|
|
10
|
+
|
|
11
|
+
export type FunctionVNode = Omit<VNode, "type"> & {
|
|
12
|
+
type: (...args: any) => any
|
|
13
|
+
}
|
|
14
|
+
export type ExoticVNode = Omit<VNode, "type"> & {
|
|
15
|
+
type: Kaioken.ExoticSymbol
|
|
16
|
+
}
|
|
17
|
+
export type ElementVNode = Omit<VNode, "dom" | "type"> & {
|
|
18
|
+
dom: SomeElement
|
|
19
|
+
type: string
|
|
20
|
+
}
|
|
21
|
+
export type DomVNode = Omit<VNode, "dom" | "type"> & {
|
|
22
|
+
dom: SomeDom
|
|
23
|
+
type: "#text" | (string & {})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ContextProviderNode<T> = Kaioken.VNode & {
|
|
27
|
+
type: typeof $CONTEXT_PROVIDER
|
|
28
|
+
props: { value: T; ctx: Kaioken.Context<T>; dependents: Set<Kaioken.VNode> }
|
|
29
|
+
}
|
|
30
|
+
export type HydrationBoundaryNode = Kaioken.VNode & {
|
|
31
|
+
type: typeof $HYDRATION_BOUNDARY
|
|
32
|
+
props: { mode: HydrationBoundaryMode }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type Prettify<T> = {
|
|
36
|
+
[K in keyof T]: T[K]
|
|
37
|
+
} & {}
|
|
38
|
+
|
|
39
|
+
export type Signalable<T> = T | Signal<T>
|