-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
657 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
npm-debug.log | ||
.DS_Store | ||
Thumbs.db | ||
yarn-error.log | ||
yarn-error.log | ||
/umd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/umd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "../../tsconfig", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
}, | ||
"include": [ | ||
"./**/*.ts" | ||
], | ||
"exclude": [ | ||
"src/**/*.spec.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { type Fiber } from '../fiber'; | ||
declare function batch(callback: () => void): void; | ||
declare function runBatch(fiber: Fiber, callback: () => void): void; | ||
export { batch, runBatch }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './batch'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { DarkElementKey, DarkElementInstance } from '../shared'; | ||
import type { Ref } from '../ref'; | ||
import type { CreateElement, ComponentOptions, StandardComponentProps, SlotProps } from './types'; | ||
declare class ComponentFactory<P extends StandardComponentProps = any, R = any> { | ||
type: CreateElement<P>; | ||
token: Symbol; | ||
props: P; | ||
ref: Ref<R>; | ||
displayName: string; | ||
children: Array<DarkElementInstance>; | ||
shouldUpdate?: (props: P, nextProps: P) => boolean; | ||
constructor(options: ComponentFactory<P>); | ||
} | ||
declare function createComponent<P, R = any>( | ||
createElement: CreateElement<P & SlotProps, R>, | ||
options?: ComponentOptions<P>, | ||
): ( | ||
props?: P & | ||
import('./types').KeyProps & | ||
Readonly<{ | ||
slot?: import('../shared').DarkElement; | ||
}> & | ||
import('./types').RefProps<unknown>, | ||
ref?: Ref<R>, | ||
) => ComponentFactory< | ||
P & | ||
import('./types').KeyProps & | ||
Readonly<{ | ||
slot?: import('../shared').DarkElement; | ||
}> & | ||
import('./types').RefProps<unknown>, | ||
any | ||
>; | ||
declare const detectIsComponentFactory: (factory: unknown) => factory is ComponentFactory<any, any>; | ||
declare const getComponentFactoryKey: (factory: ComponentFactory) => DarkElementKey; | ||
export { ComponentFactory, createComponent, detectIsComponentFactory, getComponentFactoryKey }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './component'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { ComponentFactory } from './component'; | ||
import type { DarkElementKey, DarkElement } from '../shared'; | ||
import type { Ref } from '../ref'; | ||
export declare type ComponentOptions<P extends StandardComponentProps> = Readonly<{ | ||
displayName?: string; | ||
defaultProps?: Partial<P>; | ||
token?: Symbol; | ||
shouldUpdate?: (props: P, nextProps: P) => boolean; | ||
}>; | ||
export declare type StandardComponentProps = KeyProps & SlotProps & RefProps; | ||
export declare type KeyProps = { | ||
key?: DarkElementKey; | ||
}; | ||
export declare type SlotProps<T = DarkElement> = Readonly<{ | ||
slot?: T; | ||
}>; | ||
export declare type RefProps<T = unknown> = { | ||
ref?: Ref<T>; | ||
}; | ||
export declare type Component<T extends Pick<StandardComponentProps, 'slot'> = any, R = any> = ( | ||
props: T, | ||
ref?: Ref<R>, | ||
) => ComponentFactory; | ||
export declare type ComponentFactoryReturnType = DarkElement; | ||
export declare type CreateElement<P extends StandardComponentProps, R = any> = ( | ||
props: P & Pick<StandardComponentProps, 'slot'>, | ||
ref?: Ref<R>, | ||
) => ComponentFactoryReturnType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export declare const ROOT = 'root'; | ||
export declare const EMPTY_NODE = 'dark:matter'; | ||
export declare const ATTR_KEY = 'key'; | ||
export declare const ATTR_REF = 'ref'; | ||
export declare const PARTIAL_UPDATE = 'partial-update'; | ||
export declare enum TaskPriority { | ||
HIGH = 2, | ||
NORMAL = 1, | ||
LOW = 0, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { Context } from './types'; | ||
declare function createContext<T>(defaultValue: T): Context<T>; | ||
export { createContext }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './context'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Component, SlotProps } from '../component'; | ||
import type { DarkElement } from '../shared'; | ||
export declare type ContexProviderProps<T> = { | ||
value: T; | ||
} & SlotProps; | ||
export declare type Context<T = unknown> = { | ||
Provider: Component<ContexProviderProps<T>>; | ||
Consumer: Component<SlotProps<(value: T) => DarkElement>>; | ||
displayName?: string; | ||
defaultValue: T; | ||
}; | ||
export declare type ContextProviderValue<T = unknown> = { | ||
value: T; | ||
subscribers: Array<(value: T) => void>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { type TagVirtualNodeFactory } from '../view'; | ||
declare function createElement( | ||
tag: string | Function, | ||
props: any, | ||
...children: Array<any> | ||
): TagVirtualNodeFactory | Function | null; | ||
export { createElement }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './element'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { type ComponentFactory } from '../component'; | ||
import { type TagVirtualNode } from '../view'; | ||
import type { Context, ContextProviderValue } from '../context'; | ||
import type { DarkElementInstance } from '../shared'; | ||
import { type NativeElement, type Hook, EffectTag } from './types'; | ||
declare class Fiber<N = NativeElement> { | ||
nativeElement: N; | ||
parent: Fiber<N>; | ||
child: Fiber<N>; | ||
nextSibling: Fiber<N>; | ||
alternate: Fiber<N>; | ||
effectTag: EffectTag; | ||
instance: DarkElementInstance; | ||
hook: Hook; | ||
shadow: Fiber<N>; | ||
provider: Map<Context, ContextProviderValue>; | ||
transposition: boolean; | ||
mountedToHost: boolean; | ||
portalHost: boolean; | ||
effectHost: boolean; | ||
layoutEffectHost: boolean; | ||
childrenCount: number; | ||
marker: string; | ||
isUsed: boolean; | ||
idx: number; | ||
batched: Array<() => void>; | ||
catchException: (error: Error) => void; | ||
constructor(options: Partial<Fiber<N>>); | ||
markPortalHost(): void; | ||
markEffectHost(): void; | ||
markLayoutEffectHost(): void; | ||
markMountedToHost(): void; | ||
setError(error: Error): void; | ||
} | ||
declare function workLoop(): boolean; | ||
declare function hasChildrenProp(element: DarkElementInstance): element is TagVirtualNode | ComponentFactory; | ||
declare function createHook(): Hook; | ||
declare type CreateUpdateCallbackOptions = { | ||
rootId: number; | ||
fiber: Fiber; | ||
forceStart?: boolean; | ||
onStart: () => void; | ||
}; | ||
declare function createUpdateCallback(options: CreateUpdateCallbackOptions): () => void; | ||
export { Fiber, workLoop, createHook, hasChildrenProp, createUpdateCallback }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './fiber'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export declare enum EffectTag { | ||
CREATE = 'CREATE', | ||
UPDATE = 'UPDATE', | ||
DELETE = 'DELETE', | ||
SKIP = 'SKIP', | ||
} | ||
export declare type NativeElement = unknown; | ||
export declare type HookValue<T = any> = { | ||
token?: Symbol; | ||
deps: Array<any>; | ||
value: T; | ||
}; | ||
export declare type Hook<T = any> = { | ||
idx: number; | ||
values: Array<T>; | ||
}; | ||
export declare const cloneTagMap: { | ||
CREATE: boolean; | ||
SKIP: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { type KeyProps } from '../component'; | ||
declare const Fragment: ( | ||
props?: KeyProps & | ||
Readonly<{ | ||
slot?: import('..').DarkElement; | ||
}> & | ||
import('../component').RefProps<unknown>, | ||
ref?: import('..').Ref<any>, | ||
) => import('../component/component').ComponentFactory< | ||
KeyProps & | ||
Readonly<{ | ||
slot?: import('..').DarkElement; | ||
}> & | ||
import('../component').RefProps<unknown>, | ||
any | ||
>; | ||
declare const detectIsFragment: (factory: unknown) => boolean; | ||
export { Fragment, detectIsFragment }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './fragment'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { NestedArray } from '../shared'; | ||
declare const detectIsFunction: (o: any) => o is Function; | ||
declare const detectIsUndefined: (o: any) => o is undefined; | ||
declare const detectIsNumber: (o: any) => o is number; | ||
declare const detectIsString: (o: any) => o is string; | ||
declare const detectIsObject: (o: any) => o is object; | ||
declare const detectIsBoolean: (o: any) => o is boolean; | ||
declare const detectIsArray: (o: any) => o is any[]; | ||
declare const detectIsNull: (o: any) => o is null; | ||
declare const detectIsEmpty: (o: any) => boolean; | ||
declare function error(str: string): void; | ||
declare function flatten<T = any>(source: Array<NestedArray<T>>): Array<T>; | ||
declare function getTime(): number; | ||
declare function keyBy<T = any>( | ||
list: Array<T>, | ||
fn: (o: T) => string | number, | ||
value?: boolean, | ||
): Record<string | number, T | boolean>; | ||
declare function fromEnd<T>(source: Array<T>, count: number): T[]; | ||
declare const dummyFn: () => void; | ||
declare function detectIsDepsDifferent(deps: Array<unknown>, prevDeps: Array<unknown>): boolean; | ||
export { | ||
detectIsFunction, | ||
detectIsUndefined, | ||
detectIsNumber, | ||
detectIsString, | ||
detectIsObject, | ||
detectIsBoolean, | ||
detectIsArray, | ||
detectIsNull, | ||
detectIsEmpty, | ||
error, | ||
flatten, | ||
getTime, | ||
keyBy, | ||
fromEnd, | ||
dummyFn, | ||
detectIsDepsDifferent, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export * from './component'; | ||
export * from './context'; | ||
export { createElement as h } from './element'; | ||
export * from './fiber'; | ||
export * from './fragment'; | ||
export * from './platform'; | ||
export * from './helpers'; | ||
export * from './lazy'; | ||
export * from './memo'; | ||
export * from './ref'; | ||
export * from './scope'; | ||
export * from './shared'; | ||
export * from './suspense'; | ||
export * from './use-callback'; | ||
export * from './use-context'; | ||
export * from './use-deferred-value'; | ||
export { useEffect } from './use-effect'; | ||
export * from './use-error'; | ||
export * from './use-event'; | ||
export * from './use-imperative-handle'; | ||
export { useLayoutEffect } from './use-layout-effect'; | ||
export * from './use-memo'; | ||
export * from './use-reducer'; | ||
export * from './use-ref'; | ||
export * from './use-state'; | ||
export * from './use-update'; | ||
export * from './view'; | ||
export * from './constants'; | ||
export { walkFiber } from './walk'; | ||
export { unmountRoot } from './unmount'; | ||
export { batch } from './batch'; | ||
export declare const version: string; | ||
declare global { | ||
namespace JSX { | ||
interface ElementChildrenAttribute { | ||
slot: {}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lazy'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { type Component } from '../component'; | ||
declare function lazy<P, R = unknown>( | ||
dynamic: () => Promise<{ | ||
default: Component<P>; | ||
}>, | ||
): ({ | ||
ref, | ||
...rest | ||
}: P & | ||
import('../component').KeyProps & | ||
Readonly<{ | ||
slot?: import('..').DarkElement; | ||
}> & | ||
import('../component').RefProps<unknown> & | ||
import('../component').RefProps<R>) => import('../component/component').ComponentFactory< | ||
P & | ||
import('../component').KeyProps & | ||
Readonly<{ | ||
slot?: import('..').DarkElement; | ||
}> & | ||
import('../component').RefProps<unknown>, | ||
R | ||
>; | ||
declare const detectIsLazy: (factory: unknown) => boolean; | ||
export { lazy, detectIsLazy }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './memo'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { type Component, type ComponentFactory, type StandardComponentProps, type SlotProps } from '../component'; | ||
import { type Ref } from '../ref'; | ||
declare type ShouldUpdate<T> = (props: T, nextProps: T) => boolean; | ||
declare const $$memo: unique symbol; | ||
declare const detectIsMemo: (factory: unknown) => boolean; | ||
declare function memo<T>( | ||
component: (props: T, ref?: Ref) => ComponentFactory<T>, | ||
shouldUpdate?: ShouldUpdate<T & SlotProps>, | ||
): Component<T & StandardComponentProps>; | ||
export { $$memo, memo, detectIsMemo }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './platform'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import type { Platform } from './types'; | ||
export declare const platform: Platform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { type Fiber } from '../fiber'; | ||
import { type TaskPriority } from '../constants'; | ||
import { type ComponentFactory } from '../component'; | ||
import { type VirtualNode } from '../view'; | ||
export declare type Platform = { | ||
createNativeElement: <N>(vNode: VirtualNode) => N; | ||
requestAnimationFrame: typeof requestAnimationFrame; | ||
scheduleCallback: (callback: () => void, options?: ScheduleCallbackOptions) => void; | ||
shouldYeildToHost: () => boolean; | ||
applyCommit: (fiber: Fiber) => void; | ||
finishCommitWork: () => void; | ||
detectIsPortal: (factory: ComponentFactory) => boolean; | ||
unmountPortal: (fiber: Fiber) => void; | ||
}; | ||
export declare type ScheduleCallbackOptions = { | ||
priority?: TaskPriority; | ||
timeoutMs?: number; | ||
forceSync?: boolean; | ||
}; |
Oops, something went wrong.