/** `defineElement` turns a component factory into a custom element. */ import { DEFAULT_PREFIX } from "./styles.js"; /** The part of a component the element relies on. */ export interface ElementComponent { element: HTMLElement; destroy: () => void; } export type AttributeType = "string" | "boolean" | "number"; export type AttributeValue = string | boolean | number | null; export type Config = Record; export interface AttributeSpec { type: AttributeType; /** Config key the attribute feeds at creation. */ config?: string; /** Applies a change after creation. */ update?: (component: C, value: AttributeValue, host: HTMLElement) => void; } export interface PropertySpec { get: (component: C) => unknown; set: (component: C, value: unknown) => void; /** Config key a value set before creation feeds. */ config?: string; } export interface EventSpec { /** Maps the factory payload to the event's `detail`. */ detail?: (payload: unknown) => unknown; /** The event reports a change of state beside the model (`open`, `expanded`), not of the model: dispatching it leaves the element clean. */ state?: boolean; listen?: (host: HTMLElement) => void; } export interface SlotSpec { /** Attribute whose text is the slot's fallback content. */ attribute: string; /** The config key that takes the text or a node (`text`, `label`): the element passes its `` there and the factory places it. */ config: string; } export interface FormSpec { /** The value submitted with the form under the host's `name`; FormData submits its own entries instead (several values); null submits nothing. */ value: (component: C, host: HTMLElement) => string | FormData | null; /** The inner control whose validity the element reports. */ control?: (component: C) => HTMLInputElement | HTMLTextAreaElement | null; /** Events after which the form value is read again. */ events?: readonly string[]; /** Called when a `