import { type AnyFunction, type Overwrite } from '@augment-vir/common'; import { type CSSResult, type TemplateResult, type nothing } from 'lit'; import { type EmptyObject, type HasRequiredKeys, type IsNever } from 'type-fest'; import { type DeclarativeElementDefinition } from '../../declarative-element/declarative-element.js'; import { type Decrement, type Increment } from '../../util/increment.js'; import { type MinimalDefinitionWithInputs, type MinimalElementDefinition } from '../minimal-element-definition.js'; /** * Unfortunately the type for `DirectiveResult` means it's just an empty object. So in order to * block actual objects, we have to narrow `DirectiveResult` further to this empty object type. * * @category Internal */ export type DirectiveOutput = EmptyObject; /** * This is used in order to block accidental object interpolations into HTML, which get stringified * into `'[object Object]'`, which nobody ever wants that. * * @category Internal */ export type HtmlInterpolation = null | undefined | string | number | boolean | bigint | CSSResult | Readonly | Element | Readonly | TemplateResult | Readonly | MinimalElementDefinition | Readonly | MinimalDefinitionWithInputs | Readonly | DeclarativeElementDefinition | Readonly | DirectiveOutput | Readonly | AnyFunction | typeof nothing | HtmlInterpolation[] | ReadonlyArray | Iterable | Readonly>; /** * This type ensures that interpolated element definitions are not missing their inputs, when inputs * are required. * * @category Internal */ export type VerifyHtmlValues = {}> = Values extends [ infer CurrentDefinition extends DeclarativeElementDefinition, ...infer Rest extends HtmlInterpolation[] ] ? CurrentDefinition extends DeclarativeElementDefinition ? HasRequiredKeys extends true ? IsNever> extends true ? [ `ERROR: This element is missing its inputs.`, ...VerifyHtmlValues ] : [ CurrentDefinition, ...VerifyHtmlValues>>> ] : [CurrentDefinition, ...VerifyHtmlValues] : [CurrentDefinition, ...VerifyHtmlValues] : Values extends [ infer CurrentDefinition extends MinimalDefinitionWithInputs, ...infer Rest extends HtmlInterpolation[] ] ? [ CurrentDefinition, ...VerifyHtmlValues>>> ] : Values;