import type { ElementAttributes, HTMLAttributes, IntrinsicElementAttributes } from "./Attributes.js"; import type { HTMLTagNameMap, SVGTagNameMap } from "./Elements.js"; import type { Effect } from "./Hooks.js"; import type { HTML } from "./HTML.js"; import type { Context } from "./render.js"; /** * Identify virtual dom objects. */ declare const V_SYM: unique symbol; type EmptyObject = {}; /** * Check if a property is a method. */ type IfMethod< T, K extends keyof T, A, B > = T[K] extends (...args: any[]) => any ? A : B; /** * Check if a property is any. */ type IfAny< T, K extends keyof T, A, B > = 0 extends 1 & T[K] ? A : B; /** * Get the values of a type. */ type Values = T[keyof T] extends never ? EmptyObject : T[keyof T]; /** * Exclude component mixin properties. */ type ReservedKeys = "extends" | "realm" | "collectingUpdates" | "updateScheduled" | "is" | "slotChildNodes" | "initialize" | "childNodesBySlot" | "connectedCallback" | "disconnectedCallback" | "attributeChangedCallback" | "stateChangedCallback" | "updatedCallback" | "childListChangedCallback" | "requestUpdate" | "shouldUpdate" | "propertyChangedCallback" | "getInnerPropertyValue" | "setInnerPropertyValue" | "observe" | "unobserve" | "dispatchEvent" | "dispatchAsyncEvent" | "delegateEventListener" | "undelegateEventListener" | "render" | "forceUpdate" | "collectUpdatesStart" | "collectUpdatesEnd" | "assign" | Exclude | keyof ElementCSSInlineStyle; /** * Extract known keys of an Element class. */ type KnownKeys = keyof { [K in keyof T as K extends string ? IfAny : never] : unknown }; /** * Get the base class of an element. */ type BaseClass = T["extends"] extends keyof HTMLTagNameMap ? HTMLTagNameMap[T["extends"]] : HTMLElement; /** * Get element attributes. */ export type Attrs = T extends HTMLElement ? ElementAttributes : T extends keyof IntrinsicElementAttributes ? IntrinsicElementAttributes[T] : HTMLAttributes; /** * Pick defined properties of a component. */ export type Members< T extends HTMLElement, InvalidKeys = ReservedKeys | KnownKeys> > = T extends HTML.Element ? { [K in keyof T as K extends InvalidKeys ? never : IfMethod]? : T[K] } : EmptyObject; /** * Pick methods of a class. */ export type Methods = { [K in keyof T as K extends ReservedKeys ? never : IfMethod] : T[K] }; /** * Get the properties of a component. */ export type Props< T extends HTMLElement, InvalidKeys = ReservedKeys | KnownKeys> > = T extends HTML.Element ? Attrs & Members : EmptyObject; /** * A constructor alias used for JSX fragments . * @param props The properties of the fragment. * @returns The fragment children. */ export declare const Fragment: FunctionComponent<{ [key: PropertyKey]: never; }>; /** * Get render properties for keyed nodes. */ export type KeyedProperties = { key?: unknown; }; /** * Get render properties for tree nodes. */ export type TreeProperties = { children?: Template | Template[]; }; /** * Get render properties for event listeners. */ export type EventProperties = { [listener: `on:${string}`]: EventListener | null | undefined; }; /** * Get render properties for dom nodes. */ export type ElementProperties = { is?: string; slot?: string; class?: string | Record; style?: string | Record; xmlns?: string; ref?: Element; }; /** * Get base properties for an element. */ type RenderAttributes = Omit, "style" | "class">; /** * A function that returns a template. * * @param props A set of properties with children. * @param hooks Hooks methods. * @returns A template. */ export type FunctionComponent

= (props: P & KeyedProperties & TreeProperties, hooks: { useState: (initialValue: T) => [T, (value: T) => void]; useMemo: (factory: () => T, deps?: unknown[]) => T; useEffect: (effect: Effect, deps?: unknown[]) => void; useId: (suffix?: string) => string; useRenderContext: () => Context; }) => Template; /** * Get render properties for a functional component. */ type VFunctionRenderProperties = Parameters[0] & KeyedProperties & TreeProperties; /** * The interface of a functional component. */ export type VFunction = { type: T; key: unknown; namespace: string; properties: VFunctionRenderProperties; children: Template[]; [V_SYM]: true; }; /** * Get render properties for an element instance. */ type VElementRenderProperties = Members & RenderAttributes & KeyedProperties & TreeProperties & EventProperties & ElementProperties; /** * The interface of an HTML node used as JSX tag. */ export type VElement = { type: T; key: unknown; namespace: string; properties: VElementRenderProperties; children: Template[]; [V_SYM]: true; }; /** * Get render properties for a slot tag. */ type VSlotRenderProperties = RenderAttributes<"slot"> & KeyedProperties & TreeProperties & EventProperties; /** * The interface of slot element. */ export type VSlot = { type: "slot"; key: unknown; properties: VSlotRenderProperties; children: Template[]; [V_SYM]: true; }; /** * Get base render properties for a tag. */ type VTagBaseRenderProperties = RenderAttributes & KeyedProperties & TreeProperties & EventProperties & ElementProperties; /** * Get full render properties for a tag. */ type VTagRenderProperties = (T extends keyof JSXInternal.CustomElements ? Members : EmptyObject) & VTagBaseRenderProperties; /** * The interface of a generic JSX tag. */ export type VTag = { type: T; key: unknown; namespace: string; properties: VTagRenderProperties; children: Template[]; [V_SYM]: true; }; /** * A literal value. */ export type VLiteral = { type: string; }; /** * A virtual DOM object properties. */ type VObjectProperties = T extends typeof Fragment ? null : T extends FunctionComponent ? VFunctionRenderProperties : T extends HTMLElement ? VElementRenderProperties : T extends "slot" ? VSlotRenderProperties : T extends string ? VTagRenderProperties : never; /** * A distinct virtual object type. */ type DistinctVObject = T extends FunctionComponent ? VFunction : T extends HTMLElement ? VElement : T extends "slot" ? VSlot : T extends string ? VTag : never; /** * Generic virtual dom object. */ export type VObject = VFunction | VElement | VSlot | VTag; /** * A generic template. Can be a single atomic item or a list of items. */ export type Template = any; /** * Check if the current virtual node is a fragment. * @param target The node to check. * @returns True if the target is a virtual DOM object. */ export declare const isVObject: (target: Template) => target is VObject; /** * Check if the current virtual node is a functional component. * @param target The node to check. * @returns True if the target is a functional component. */ export declare const isVFunction: (target: VObject) => target is VFunction; /** * Check if the current virtual node is an HTML node instance. * @param target The node to check. * @returns True if the target is an HTML node instance. */ export declare const isVNode: (target: VObject) => target is VElement; /** * Check if the current virtual node is a slot element. * @param target The node to check. * @returns True if the target is a slot element. */ export declare const isVSlot: (target: VObject) => target is VSlot; /** * Check if the current virtual node is a generic tag to render. * @param target The node to check. * @returns True if the target is a generic tag to render. */ export declare const isVTag: (target: VObject) => target is VTag; /** * Function factory to use as JSX pragma. * * @param type The tag name, the constructor or the instance of the node. * @param properties The set of properties of the Node. * @param children The children of the Node. * @returns The virtual DOM object. */ declare function h(type: T, properties?: VObjectProperties | null, ...children: Template[]): DistinctVObject; /** * Function factory to use as JSX pragma. * * @param type The tag name, the constructor or the instance of the node. * @param properties The set of properties of the Node. * @param key The Node key reference. * @returns The virtual DOM object. */ declare function jsx(type: T, properties?: VObjectProperties | null, key?: unknown): DistinctVObject; declare const jsxs: typeof jsx; declare const jsxDEV: typeof jsx; export { h, jsx, jsxs, jsxDEV }; /** * Compile a template string into virtual DOM template. * @param string The string to compile. * @param values Values to interpolate. * @returns The virtual DOM template. */ export declare const html: (strings: TemplateStringsArray, ...values: Template[]) => ReturnType | ReturnType[]; /** * Compile a string into virtual DOM template. * @param string The string to compile. * @returns The virtual DOM template. */ export declare const compile: (string: string) => Template; /** * The internal JSX namespace. */ export declare namespace JSXInternal { interface CustomElements {} type Element = Template; interface ElementClass extends HTMLElement {} type IntrinsicAttributes = KeyedProperties & EventProperties & TreeProperties & ElementProperties; type AutonomousElements = { [K in keyof CustomElements as CustomElements[K] extends { extends: string; } ? never : K] : Members }; type CustomizedElements = { [K in keyof HTMLTagNameMap] : Values<{ [P in keyof CustomElements as CustomElements[P] extends { extends: K; } ? P : never] : Members & { is: P; } }> }; type BuiltinElements = { [K in keyof HTMLTagNameMap] : Partial, never>> & { is?: string | null | undefined; } }; type IntrinsicElements = { [key: string]: VElementRenderProperties & { [key: PropertyKey]: unknown; }; } & { [K in keyof AutonomousElements] : AutonomousElements[K] & VTagBaseRenderProperties } & { [K in keyof CustomizedElements] : (BuiltinElements[K] | CustomizedElements[K]) & VTagBaseRenderProperties } & { [K in keyof SVGTagNameMap] : VTagRenderProperties }; }