/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
///
import type { Directive } from './directive.js';
/**
* Contains types that are part of the unstable debug API.
*
* Everything in this API is not stable and may change or be removed in the future,
* even on patch releases.
*/
export declare namespace LitUnstable {
/**
* When Lit is running in dev mode and `window.emitLitDebugLogEvents` is true,
* we will emit 'lit-debug' events to window, with live details about the update and render
* lifecycle. These can be useful for writing debug tooling and visualizations.
*
* Please be aware that running with window.emitLitDebugLogEvents has performance overhead,
* making certain operations that are normally very cheap (like a no-op render) much slower,
* because we must copy data and dispatch events.
*/
namespace DebugLog {
type Entry = TemplatePrep | TemplateInstantiated | TemplateInstantiatedAndUpdated | TemplateUpdating | BeginRender | EndRender | CommitPartEntry | SetPartValue;
interface TemplatePrep {
kind: 'template prep';
template: Template;
strings: TemplateStringsArray;
clonableTemplate: HTMLTemplateElement;
parts: TemplatePart[];
}
interface BeginRender {
kind: 'begin render';
id: number;
value: unknown;
container: HTMLElement | DocumentFragment;
options: RenderOptions | undefined;
part: ChildPart | undefined;
}
interface EndRender {
kind: 'end render';
id: number;
value: unknown;
container: HTMLElement | DocumentFragment;
options: RenderOptions | undefined;
part: ChildPart;
}
interface TemplateInstantiated {
kind: 'template instantiated';
template: Template | CompiledTemplate;
instance: TemplateInstance;
options: RenderOptions | undefined;
fragment: Node;
parts: Array;
values: unknown[];
}
interface TemplateInstantiatedAndUpdated {
kind: 'template instantiated and updated';
template: Template | CompiledTemplate;
instance: TemplateInstance;
options: RenderOptions | undefined;
fragment: Node;
parts: Array;
values: unknown[];
}
interface TemplateUpdating {
kind: 'template updating';
template: Template | CompiledTemplate;
instance: TemplateInstance;
options: RenderOptions | undefined;
parts: Array;
values: unknown[];
}
interface SetPartValue {
kind: 'set part';
part: Part;
value: unknown;
valueIndex: number;
values: unknown[];
templateInstance: TemplateInstance;
}
type CommitPartEntry = CommitNothingToChildEntry | CommitText | CommitNode | CommitAttribute | CommitProperty | CommitBooleanAttribute | CommitEventListener | CommitToElementBinding;
interface CommitNothingToChildEntry {
kind: 'commit nothing to child';
start: ChildNode;
end: ChildNode | null;
parent: Disconnectable | undefined;
options: RenderOptions | undefined;
}
interface CommitText {
kind: 'commit text';
node: Text;
value: unknown;
options: RenderOptions | undefined;
}
interface CommitNode {
kind: 'commit node';
start: Node;
parent: Disconnectable | undefined;
value: Node;
options: RenderOptions | undefined;
}
interface CommitAttribute {
kind: 'commit attribute';
element: Element;
name: string;
value: unknown;
options: RenderOptions | undefined;
}
interface CommitProperty {
kind: 'commit property';
element: Element;
name: string;
value: unknown;
options: RenderOptions | undefined;
}
interface CommitBooleanAttribute {
kind: 'commit boolean attribute';
element: Element;
name: string;
value: boolean;
options: RenderOptions | undefined;
}
interface CommitEventListener {
kind: 'commit event listener';
element: Element;
name: string;
value: unknown;
oldListener: unknown;
options: RenderOptions | undefined;
removeListener: boolean;
addListener: boolean;
}
interface CommitToElementBinding {
kind: 'commit to element binding';
element: Element;
value: unknown;
options: RenderOptions | undefined;
}
}
}
/**
* Used to sanitize any value before it is written into the DOM. This can be
* used to implement a security policy of allowed and disallowed values in
* order to prevent XSS attacks.
*
* One way of using this callback would be to check attributes and properties
* against a list of high risk fields, and require that values written to such
* fields be instances of a class which is safe by construction. Closure's Safe
* HTML Types is one implementation of this technique (
* https://github.com/google/safe-html-types/blob/master/doc/safehtml-types.md).
* The TrustedTypes polyfill in API-only mode could also be used as a basis
* for this technique (https://github.com/WICG/trusted-types).
*
* @param node The HTML node (usually either a #text node or an Element) that
* is being written to. Note that this is just an exemplar node, the write
* may take place against another instance of the same class of node.
* @param name The name of an attribute or property (for example, 'href').
* @param type Indicates whether the write that's about to be performed will
* be to a property or a node.
* @return A function that will sanitize this class of writes.
*/
export type SanitizerFactory = (node: Node, name: string, type: 'property' | 'attribute') => ValueSanitizer;
/**
* A function which can sanitize values that will be written to a specific kind
* of DOM sink.
*
* See SanitizerFactory.
*
* @param value The value to sanitize. Will be the actual value passed into
* the lit-html template literal, so this could be of any type.
* @return The value to write to the DOM. Usually the same as the input value,
* unless sanitization is needed.
*/
export type ValueSanitizer = (value: unknown) => unknown;
/** TemplateResult types */
declare const HTML_RESULT = 1;
declare const SVG_RESULT = 2;
type ResultType = typeof HTML_RESULT | typeof SVG_RESULT;
declare const ATTRIBUTE_PART = 1;
declare const CHILD_PART = 2;
declare const ELEMENT_PART = 6;
declare const COMMENT_PART = 7;
/**
* The return type of the template tag functions, {@linkcode html} and
* {@linkcode svg} when it hasn't been compiled by @lit-labs/compiler.
*
* A `TemplateResult` object holds all the information about a template
* expression required to render it: the template strings, expression values,
* and type of template (html or svg).
*
* `TemplateResult` objects do not create any DOM on their own. To create or
* update DOM you need to render the `TemplateResult`. See
* [Rendering](https://lit.dev/docs/components/rendering) for more information.
*
*/
export type UncompiledTemplateResult = {
['_$litType$']: T;
strings: TemplateStringsArray;
values: unknown[];
};
/**
* This is a template result that may be either uncompiled or compiled.
*
* In the future, TemplateResult will be this type. If you want to explicitly
* note that a template result is potentially compiled, you can reference this
* type and it will continue to behave the same through the next major version
* of Lit. This can be useful for code that wants to prepare for the next
* major version of Lit.
*/
export type MaybeCompiledTemplateResult = UncompiledTemplateResult | CompiledTemplateResult;
/**
* The return type of the template tag functions, {@linkcode html} and
* {@linkcode svg}.
*
* A `TemplateResult` object holds all the information about a template
* expression required to render it: the template strings, expression values,
* and type of template (html or svg).
*
* `TemplateResult` objects do not create any DOM on their own. To create or
* update DOM you need to render the `TemplateResult`. See
* [Rendering](https://lit.dev/docs/components/rendering) for more information.
*
* In Lit 4, this type will be an alias of
* MaybeCompiledTemplateResult, so that code will get type errors if it assumes
* that Lit templates are not compiled. When deliberately working with only
* one, use either {@linkcode CompiledTemplateResult} or
* {@linkcode UncompiledTemplateResult} explicitly.
*/
export type TemplateResult = UncompiledTemplateResult;
export type HTMLTemplateResult = TemplateResult;
export type SVGTemplateResult = TemplateResult;
/**
* A TemplateResult that has been compiled by @lit-labs/compiler, skipping the
* prepare step.
*/
export interface CompiledTemplateResult {
['_$litType$']: CompiledTemplate;
values: unknown[];
}
export interface CompiledTemplate extends Omit {
el?: HTMLTemplateElement;
h: TemplateStringsArray;
}
/**
* Interprets a template literal as an HTML template that can efficiently
* render to and update a container.
*
* ```ts
* const header = (title: string) => html`
${title}
`;
* ```
*
* The `html` tag returns a description of the DOM to render as a value. It is
* lazy, meaning no work is done until the template is rendered. When rendering,
* if a template comes from the same expression as a previously rendered result,
* it's efficiently updated instead of replaced.
*/
export declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult<1>;
/**
* Interprets a template literal as an SVG fragment that can efficiently
* render to and update a container.
*
* ```ts
* const rect = svg``;
*
* const myImage = html`
* `;
* ```
*
* The `svg` *tag function* should only be used for SVG fragments, or elements
* that would be contained **inside** an `