import { type SetRequiredAndNotNull } from '@augment-vir/common'; import { type EmptyObject, type IsAny, type IsEmptyObject } from 'type-fest'; import { LitElement, type CSSResult } from '../lit-exports/base-lit-exports.js'; import { type MinimalDefinitionWithInputs } from '../template-transforms/minimal-element-definition.js'; import { type CustomElementTagName } from './custom-tag-name.js'; import { type DeclarativeElementInit } from './declarative-element-init.js'; import { type DeclarativeElementDefinitionOptions } from './definition-options.js'; import { type CssVars } from './properties/css-vars.js'; import { type EventDescriptorMap, type EventsInitMap } from './properties/element-events.js'; import { type PropertyInitMapBase } from './properties/element-properties.js'; import { type HostClassNamesMap } from './properties/host-classes.js'; import { type ObservableListenerMap } from './properties/property-proxy.js'; import { type BaseStringName, type StringNameMap } from './properties/string-names.js'; import { type RenderCallback, type RenderParams, type UpdateStateCallback } from './render-callback.js'; /** * The `host` type for a declarative element. This references a declarative element instance's * top-level HTML element and always contains a shadow root (wherein the element is rendered). * * @category Internal */ export type DeclarativeElementHost = any, CssVarKeys extends BaseStringName = any, SlotNames extends ReadonlyArray = any, TestIds extends ReadonlyArray = any> = SetRequiredAndNotNull, Exclude, keyof HTMLElement>>, 'shadowRoot'>; /** * The full definition for a declarative element. * * @category Internal */ export type DeclarativeElementDefinition = any, CssVarKeys extends BaseStringName = any, SlotNames extends ReadonlyArray = any, TestIds extends ReadonlyArray = any> = (new () => DeclarativeElementHost) & StaticDeclarativeElementProperties & { InstanceType: DeclarativeElementHost; }; /** * Abstract class base for all declarative elements. * * @category Internal */ export declare abstract class DeclarativeElement = any, CssVarKeys extends BaseStringName = any, SlotNames extends ReadonlyArray = any, TestIds extends ReadonlyArray = any> extends LitElement { /** * Assign inputs to an element instantiation. Use only on the opening tag. * * @example * * ```ts * import {html} from 'element-vir'; * * const myTemplate = html` * <${MyElement.assign({input1: 'a', input2: 'b'})}> * `; * ``` */ static readonly assign: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['assign']; static readonly assignedInputs: PropertyInitMapBase | undefined; static readonly tagName: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['tagName']; static readonly styles: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['styles']; static readonly render: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['render']; static readonly InputsType: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['InputsType']; static readonly StateType: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['StateType']; static readonly UpdateStateType: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['UpdateStateType']; static readonly events: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['events']; static readonly init: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['init']; static readonly elementOptions: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['elementOptions']; static readonly hostClasses: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['hostClasses']; static readonly cssVars: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['cssVars']; static readonly slotNames: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['slotNames']; static readonly testIds: StaticDeclarativeElementProperties, BaseStringName, ReadonlyArray, ReadonlyArray>['testIds']; abstract _lastRenderError: Error | undefined; abstract _internalRenderCount: number; abstract _lastRenderedProps: Readonly, 'inputs' | 'state'>>; /** * Calls all destroy methods on all state properties, if they exist. This is automatically * called whenever the element is detached. */ abstract destroy(): void; abstract render(): unknown; abstract readonly instanceState: State; abstract readonly observablePropertyListenerMap: ObservableListenerMap; abstract readonly instanceInputs: Inputs; /** * Used to assign inputs to the given element. This can be externally called as an API for * setting inputs on an element reference, though this is discouraged. Inputs should typically * be called using the `.assign()` method on an element definition inside of an HTML template. */ abstract assignInputs(inputs: EmptyObject extends Required ? never : Partial): void; /** The element definition for this element instance. */ abstract readonly definition: DeclarativeElementDefinition; } /** * The assign inputs method of a declarative element. * * @category Internal */ export type AssignMethod = IsAny extends true ? any : IsEmptyObject> extends true ? (inputsObject: never) => never : (inputsObject: IsEmptyObject> extends true ? never : Readonly) => MinimalDefinitionWithInputs; /** * All static properties on a declarative element. These all come from the element's definition. * * @category Internal */ export type StaticDeclarativeElementProperties, CssVarKeys extends BaseStringName, SlotNames extends ReadonlyArray, TestIds extends ReadonlyArray> = { /** Assign inputs to an element directly on its interpolated tag. */ readonly assign: AssignMethod; assignedInputs: Inputs | undefined; /** Pass through the render callback for direct unit testability */ readonly render: RenderCallback; readonly events: EventDescriptorMap; readonly slotNames: Readonly>; readonly testIds: Readonly>; readonly init: DeclarativeElementInit; readonly elementOptions: DeclarativeElementDefinitionOptions; readonly InputsType: Inputs; readonly StateType: Readonly; readonly UpdateStateType: UpdateStateCallback; readonly hostClasses: HostClassNamesMap; readonly cssVars: CssVars; readonly tagName: TagName; readonly styles: CSSResult; };