import { Context } from "./context.js"; import { Expression } from "./signals.js"; import { Content } from "./types.js"; /** * Namespace URI for HTML elements. */ export const HTML = "http://www.w3.org/1999/xhtml"; /** * Namespace URI for SVG elements. */ export const SVG = "http://www.w3.org/2000/svg"; /** * Namespace URI for MathML elements. */ export const MATHML = "http://www.w3.org/1998/Math/MathML"; export type XMLNS = typeof HTML | typeof SVG | typeof MATHML; /** * Context for setting the namespace URI for new elements. */ export const XMLNS = new Context(HTML); /** * Represents any supported "class" attribute value. */ export type ClassValue = Expression> | ClassValue[]>; type HyphenCase = T extends `${infer A}${infer B}` ? `${A extends Capitalize ? "-" : ""}${Lowercase}${HyphenCase}` : T; /** * An object with css property expressions used in {@link StyleValue}. */ export type StyleMap = { [K in keyof CSSStyleDeclaration as HyphenCase]?: Expression; } & { [K in string]?: Expression; }; /** * Represents any supported "style" attribute value. */ export type StyleValue = Expression; export type EventListener = (event: E) => void; /** * Symbol for specifying a DOM node that is used as content. * * See {@link NodeTarget}. */ export const NODE = Symbol.for("rvx:node"); /** * If an object used as content has a {@link NODE} property, this node is inserted as content instead. */ export interface NodeTarget { [NODE]: T; } /** * Represents an object with jsx element attributes. */ export type Attributes<_T extends Element> = { children?: Content; class?: ClassValue; style?: StyleValue; } & { [K in keyof HTMLElementEventMap as `on:${K}`]?: EventListener | EventArgs; } & { [K in `prop:${string}`]?: Expression; } & { [K in `attr:${string}`]?: Expression; } & { [K in string]?: Expression; }; /** * Type for specifying a jsx event listener with options. */ export type EventArgs = [ listener: EventListener, options?: AddEventListenerOptions, ]; /** * Type used for mapping tag names to element types. */ export type TagNameMap = HTMLElementTagNameMap & SVGElementTagNameMap & MathMLElementTagNameMap;