import "./events"; import "./lifecycle"; declare const anyParentNodeModifierTag: unique symbol; type NativeElementAttributes = { [K in keyof HTMLElementTagNameMap[TTagName] as K extends `on${string}` ? never : K]?: K extends "style" ? ValueOrFactory : ValueOrFactory; }; type LowercaseEventAttributes = { [K in Extract]?: never; }; /** * `onMount` / `onDestroy` attributes — not real DOM events (no native * `on${string}` IDL property exists for them), so they're typed here rather * than derived from HTMLElementEventAttributeNameMap. See src/element/lifecycle.ts. */ type LifecycleElementAttributes = { onMount?: MountCallback; onDestroy?: DestroyCallback; }; declare global { export type Primitive = string | number | bigint | boolean | symbol | null | undefined; export type ElementTagName = keyof HTMLElementTagNameMap; export type SVGTagName = keyof SVGElementTagNameMap; export type ValueFactory = () => TValue; export type ValueOrFactory = TValue | ValueFactory; // `never[]` (not `unknown[]`) so factories with typed parameters still match: // `(...args: unknown[])` rejects e.g. `(x: number) => string` under strict // contravariance and would resolve to never. export type InferFactoryResult = TFactory extends (...args: never[]) => infer TResult ? TResult : never; // CSS style object: only the string-valued (settable) CSSStyleDeclaration // properties, as string | number. Filters out methods (setProperty, item…), // readonly non-string members (length, parentRule) and the numeric index. export type CSSStyleObject = { [K in keyof CSSStyleDeclaration as K extends string ? CSSStyleDeclaration[K] extends string ? K : never : never]?: string | number; }; // Core element attribute types export type ExpandedElementAttributes< TTagName extends ElementTagName = ElementTagName, > = NativeElementAttributes & CamelCaseEventAttributes & LowercaseEventAttributes & LifecycleElementAttributes & { // Allow custom attributes (data-*, aria-*, etc.) [key: string]: ValueOrFactory; }; export type DetachedExpandedElementFactory< TTagName extends ElementTagName = ElementTagName, > = NodeModFn & (( parent?: ExpandedElement, index?: number, ) => ExpandedElement) & { readonly [anyParentNodeModifierTag]: true; }; /** Type-only marker for modifiers whose runtime accepts any parent tag. */ export type AnyParentNodeModifier = { readonly [anyParentNodeModifierTag]: true; }; // Core element type export type ExpandedElement< TTagName extends ElementTagName = ElementTagName, > = Partial> & Pick; /** A block or portal modifier returns its comment anchor. */ export type MarkerModifier = (parent: ExpandedElement, index: number) => Comment; // Core modifier types export type NodeRenderable = | Primitive | ExpandedElementAttributes | ExpandedElement | Node; export type NodeMod = | NodeRenderable | ValueFactory | ((parent: ExpandedElement, index: number) => Node); // Allow Node builders export type NodeModFn = ( parent: ExpandedElement, index: number, ) => NodeMod | void; export type NodeModLike = | NodeMod | NodeModFn | AnyParentNodeModifier; export type InferExpandedElement = TValue extends ExpandedElement ? ExpandedElement : TValue extends DetachedExpandedElementFactory ? ExpandedElement : TValue extends ExpandedElementBuilder ? ExpandedElement : TValue extends NodeModFn ? ExpandedElement : Extract; // Core builder types export type ExpandedElementBuilder< TTagName extends ElementTagName = ElementTagName, > = ( ...rawMods: readonly NodeModLike[] ) => DetachedExpandedElementFactory; } export { };