import { Signal } from "@dathra/reactivity"; import { AtomStore } from "@dathra/store"; import { GenericHydrationPlan } from "@dathra/runtime/hydration"; import { IslandStrategyName } from "@dathra/shared"; //#region src/defineComponent/implementation.d.ts /** Supported prop type constructors or custom coercion functions. */ type PropType = StringConstructor | NumberConstructor | BooleanConstructor | ((value: string | null) => unknown); /** Definition for a single prop (type, default, attribute mapping). */ interface PropDefinition { /** Constructor or coercion function for attribute→value conversion. */ type: PropType; /** Default value when attribute is absent. Falls back to type default. */ default?: unknown; /** Attribute name override, or `false` to disable attribute observation. */ attribute?: string | false; } /** Schema mapping prop names to their definitions. */ type PropsSchema = Record; type EmptyPropsSchema = Record; /** Infer the runtime type from a PropDefinition's type field. */ type InferPropType = D extends { type: StringConstructor; } ? string : D extends { type: NumberConstructor; } ? number : D extends { type: BooleanConstructor; } ? boolean : D extends { type: (v: string | null) => infer R; } ? R : unknown; /** Map a PropsSchema to an object of reactive signals. */ type InferProps = { readonly [K in keyof S]: Signal> }; /** * Function component that receives reactive props as signals. * Props can be accessed via .value and will reactively update when attributes change. */ type FunctionComponent = (ctx: ComponentContext) => Node | DocumentFragment | string; /** Internal setup function with host and context. @internal */ type SetupFunction = (host: HTMLElement, ctx: ComponentContext) => Node | DocumentFragment | string; /** Context passed to setup and hydrate functions. */ interface ComponentContext { readonly host: HTMLElement; readonly props: Readonly>; readonly client: ComponentClientContext; readonly store: AtomStore; readonly children: unknown; } interface ComponentClientContext { readonly strategy: IslandStrategyName | null; readonly value: string | null; readonly hydrated: boolean; } interface JSXReactiveValue { readonly value: T; } type JSXPropValue = T | JSXReactiveValue; interface IslandsDirectiveJSXProps { readonly "client:load"?: true | ""; readonly "client:visible"?: true | ""; readonly "client:idle"?: true | ""; readonly "client:interaction"?: true | string; readonly "client:media"?: string; } /** Props accepted by the JSX helper component returned from defineComponent. */ type JSXComponentProps = { readonly [K in keyof S]?: JSXPropValue> } & { readonly children?: unknown; } & IslandsDirectiveJSXProps; /** Options for defineComponent. */ interface ComponentOptions { /** CSS styles to apply via adoptedStyleSheets. */ styles?: readonly (CSSStyleSheet | string)[]; /** Props schema defining observed attributes with type coercion. */ props?: S; /** Hydration setup function for Declarative Shadow DOM. */ hydrate?: HydrateSetupFunction; } /** Component class with tag name and schema metadata. */ interface ComponentMetadata { readonly __tagName__: string; readonly __propsSchema__?: S; readonly __hydrationMetadata__?: ComponentHydrationMetadata; } type HydrationPlanFactory = (host: HTMLElement, ctx: ComponentContext) => GenericHydrationPlan; interface ComponentHydrationMetadata { readonly kind: "generic-plan"; readonly planFactory?: HydrationPlanFactory | null; readonly unsupportedReason?: string; } /** Component class with tag name and schema metadata. */ interface ComponentClass extends Function, ComponentMetadata {} /** Constructor type returned by defineComponent. */ type ComponentConstructor = { new (): HTMLElement & { [K in keyof S]: InferPropType }; readonly prototype: HTMLElement; } & ComponentClass; /** JSX helper component returned by defineComponent. */ type JSXComponent = (props: JSXComponentProps | null) => Node; /** Public object returned by defineComponent. */ interface DefinedComponent extends ComponentMetadata { (props: JSXComponentProps | null): Node; readonly webComponent: ComponentConstructor; readonly jsx: JSXComponent; } /** TSX helper: derive element attribute types from a ComponentClass. */ type ComponentElement = C extends ComponentMetadata ? JSXComponentProps : Record; /** Function that hydrates existing DSD content without creating new DOM. */ type HydrateSetupFunction = (ctx: ComponentContext) => void; /** * Define a custom element with automatic Shadow DOM, reactive props with * type coercion, adoptedStyleSheets, and lifecycle management. * Accepts a FunctionComponent that receives reactive prop signals. * @param tagName - Custom element tag name (must contain a hyphen). * @param component - Function component that creates the component's DOM content. * @param options - Optional configuration for styles, props, and hydration. * @returns A component definition object containing the custom element class and JSX helper. */ declare function defineComponent(tagName: string, component: FunctionComponent, options?: ComponentOptions): DefinedComponent; //#endregion export { PropType as _, ComponentMetadata as a, defineComponent as b, FunctionComponent as c, InferProps as d, JSXComponent as f, PropDefinition as g, JSXReactiveValue as h, ComponentElement as i, HydrateSetupFunction as l, JSXPropValue as m, ComponentConstructor as n, ComponentOptions as o, JSXComponentProps as p, ComponentContext as r, DefinedComponent as s, ComponentClass as t, InferPropType as u, PropsSchema as v, SetupFunction as y }; //# sourceMappingURL=implementation-E2NIKX9i.d.mts.map