import { type CSSResult } from '../lit-exports/base-lit-exports.js'; import { type CustomElementTagName } from './custom-tag-name.js'; import { type DeclarativeElementDefinitionOptions } from './definition-options.js'; import { type CssVarsInitMap } from './properties/css-vars.js'; import { type EventsInitMap } from './properties/element-events.js'; import { type PropertyInitMapBase } from './properties/element-properties.js'; import { type HostClassesInitMap } from './properties/host-classes.js'; import { type BaseStringName } from './properties/string-names.js'; import { type StylesCallback } from './properties/styles.js'; import { type InitCallback, type RenderCallback, type RenderParams } from './render-callback.js'; /** * Initialization for an element-vir declarative element. This defines all the pieces required for * rendering the element. * * @category Internal */ export type DeclarativeElementInit, CssVarKeys extends BaseStringName, SlotNames extends ReadonlyArray, TestIds extends ReadonlyArray> = { /** * HTML tag name. This should not be used directly, as interpolating it with the html tagged * template from this package is preferred. */ tagName: TagName; /** Static styles. These should not and cannot change. */ styles?: CSSResult | StylesCallback | undefined; /** Events that the element can dispatch. (These can be thought of as "outputs".) */ events?: EventsInit | undefined; slotNames?: SlotNames | undefined; testIds?: TestIds | undefined; /** * HTML host classes. Values can be callbacks to determine when a host class should be defined, * based on current instance state or inputs, or just false to indicate that the host class will * only be manually set. */ hostClasses?: HostClassesInitMap | undefined; /** * CSS Vars for the component. Keys of this object should be kebab-case and start with the * element's tag name. * * Values of this object represent the default fallback value for the given CSS var. These are * then passed to the styles property, which must be a callback to take advantage of these. */ cssVars?: CssVarsInitMap; /** * Make sure to define this at the top of your element init object or TypeScript will fail to * infer the element's state type. * * Setup the element's initial state. This is only called once per element instance, before the * first render. The return type of this method becomes the element's state type. */ state?: (params: Omit, 'state' | 'updateState'>) => Extract extends never ? Extract extends never ? State : `ERROR: Cannot define an element state property that clashes with input properties: ${Extract extends string | number | bigint | boolean | null | undefined ? Extract : ''}` : `ERROR: Cannot define an element state property that clashes with native HTMLElement properties: ${Extract}`; /** Called as part of the first render call, before the first render call. */ init?: InitCallback | undefined; /** Called whenever an element updates. This creates the element's HTML. */ render: RenderCallback; /** Called whenever an element is detached from the DOM. */ cleanup?: InitCallback | undefined; /** Extra element definition options. */ options?: Partial | undefined; };