UNPKG

dom-renderer

Version:

A light-weight DOM Renderer supports Web components standard & TypeScript language

69 lines (68 loc) 2.64 kB
import { HTMLProps, IndexKey, MathMLProps, SVGProps } from 'web-utility'; export type DataObject = Record<string, any>; export type PropsMap = Partial<Record<keyof HTMLProps<HTMLMetaElement> | keyof HTMLProps<HTMLLabelElement>, string>>; export type VNodeStyle = HTMLProps<HTMLElement>['style'] & { [K in `--${string}`]?: string; }; export declare class VNodeMeta { key?: IndexKey; ref?: (node?: Node) => any; text?: string; selector?: string; namespace?: string; tagName?: string; is?: string; props?: DataObject; style?: VNodeStyle; parent?: VNode; children?: JsxChildren; node?: Node; } export declare class VNode extends VNodeMeta { children?: VNode[]; constructor({ children, ...meta }: VNodeMeta); walkUp(): Generator<VNode, void, unknown>; namespaceOf(tagName: string): any; createDOM(document?: Document): Element | DocumentFragment | Text; toJSON(): VNodeMeta; protected generateElementXML(): Generator<string>; generateXML(this: VNode): Generator<string>; static propsMap: PropsMap; static attrsMap: Record<string, keyof HTMLProps<HTMLLabelElement>>; static isFragment({ key, node, children, ...rest }: VNode): boolean; static fromDOM(node: Node): VNode; } export type JsxChild = VNode | string | number | boolean | null | undefined; export type JsxChildren = JsxChild | Array<JsxChildren>; export type JsxProps<T extends HTMLElement> = DataObject & Pick<VNode, 'is' | 'key' | 'ref'> & Omit<HTMLProps<T>, 'children'> & { children?: JsxChildren; }; export type SvgJsxProps<T extends SVGElement> = DataObject & Pick<VNode, 'key' | 'ref'> & Omit<SVGProps<T>, 'children'> & { children?: JsxChildren; }; export type MathMlJsxProps<T extends MathMLElement> = DataObject & Pick<VNode, 'key' | 'ref'> & Omit<MathMLProps<T>, 'children'> & { children?: JsxChildren; }; declare global { /** * @see {@link https://www.typescriptlang.org/docs/handbook/jsx.html} */ namespace JSX { type Element = VNode; type JSXElements = { [tagName in keyof HTMLElementTagNameMap]: JsxProps<HTMLElementTagNameMap[tagName]>; } & { [tagName in keyof SVGElementTagNameMap]: SvgJsxProps<SVGElementTagNameMap[tagName]>; } & { [tagName in keyof MathMLElementTagNameMap]: MathMlJsxProps<MathMLElementTagNameMap[tagName]>; }; interface IntrinsicElements extends JSXElements { } interface ElementAttributesProperty { props: {}; } interface ElementChildrenAttribute { children: {}; } } }