@pawvan/autumnui
Version:
Minimal reactive UI library with no virtual DOM - Autumn
84 lines (72 loc) • 2.46 kB
TypeScript
export = autumn;
export as namespace autumn;
import { JSXInternal } from './jsx';
import { HyperscriptApi } from './h';
import * as _shared from './shared';
import * as _o from './observable';
import FunctionComponent = _shared.FunctionComponent;
import ElementChildren = _shared.ElementChildren;
// Extend JSXInternal DOMAttributes with children prop
declare module 'autumn/jsx' {
namespace JSXInternal {
interface DOMAttributes<Target extends EventTarget> {
children?: ElementChildren;
}
}
}
/**
* Autumn namespace adapted from Preact typings,
* avoiding conflicts with React typings.
*/
declare namespace autumn {
export import JSX = JSXInternal;
export import observable = _o.observable;
export import o = _o.o;
const html: (strings: TemplateStringsArray, ...values: unknown[]) => HTMLElement | DocumentFragment;
const svg: (strings: TemplateStringsArray, ...values: unknown[]) => SVGElement | DocumentFragment;
// Hyperscript h() function overloads for HTML elements
function h(
type: string,
props: JSXInternal.HTMLAttributes & Record<string, unknown> | null,
...children: ElementChildren[]
): HTMLElement;
function h(
type: FunctionComponent,
props: JSXInternal.HTMLAttributes & Record<string, unknown> | null,
...children: ElementChildren[]
): HTMLElement | DocumentFragment;
function h(
tag: ElementChildren[] | [],
...children: ElementChildren[]
): DocumentFragment;
namespace h {
export import JSX = JSXInternal;
}
// Hyperscript hs() function overloads for SVG elements
function hs(
type: string,
props: JSXInternal.SVGAttributes & Record<string, unknown> | null,
...children: ElementChildren[]
): SVGElement;
function hs(
type: FunctionComponent,
props: JSXInternal.SVGAttributes & Record<string, unknown> | null,
...children: ElementChildren[]
): SVGElement | DocumentFragment;
function hs(
tag: ElementChildren[] | [],
...children: ElementChildren[]
): DocumentFragment;
namespace hs {
export import JSX = JSXInternal;
}
/** Autumn API interface */
interface AutumnApi extends HyperscriptApi {
hs: <T extends () => unknown>(closure: T) => ReturnType<T>;
subscribe: typeof _o.subscribe;
cleanup: typeof _o.cleanup;
root: typeof _o.root;
sample: typeof _o.sample;
}
const api: AutumnApi;
}