chrome-devtools-frontend
Version:
Chrome DevTools UI
203 lines (198 loc) • 7.96 kB
TypeScript
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
/** TemplateResult types */
declare const HTML_RESULT = 1;
declare const SVG_RESULT = 2;
declare const MATHML_RESULT = 3;
type ResultType = typeof HTML_RESULT | typeof SVG_RESULT | typeof MATHML_RESULT;
/**
* 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.
*
*/
type UncompiledTemplateResult<T extends ResultType = ResultType> = {
['_$litType$']: T;
strings: TemplateStringsArray;
values: unknown[];
};
/**
* 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.
*/
type TemplateResult<T extends ResultType = ResultType> = UncompiledTemplateResult<T>;
/**
* Interprets a template literal as an HTML template that can efficiently
* render to and update a container.
*
* ```ts
* const header = (title: string) => html`<h1>${title}</h1>`;
* ```
*
* 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.
*/
declare const html$1: (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`<rect width="10" height="10"></rect>`;
*
* const myImage = html`
* <svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
* ${rect}
* </svg>`;
* ```
*
* The `svg` *tag function* should only be used for SVG fragments, or elements
* that would be contained **inside** an `<svg>` HTML element. A common error is
* placing an `<svg>` *element* in a template tagged with the `svg` tag
* function. The `<svg>` element is an HTML element and should be used within a
* template tagged with the {@linkcode html} tag function.
*
* In LitElement usage, it's invalid to return an SVG fragment from the
* `render()` method, as the SVG fragment will be contained within the element's
* shadow root and thus not be properly contained within an `<svg>` HTML
* element.
*/
declare const svg$1: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult<2>;
/**
* Interprets a template literal as MathML fragment that can efficiently render
* to and update a container.
*
* ```ts
* const num = mathml`<mn>1</mn>`;
*
* const eq = html`
* <math>
* ${num}
* </math>`;
* ```
*
* The `mathml` *tag function* should only be used for MathML fragments, or
* elements that would be contained **inside** a `<math>` HTML element. A common
* error is placing a `<math>` *element* in a template tagged with the `mathml`
* tag function. The `<math>` element is an HTML element and should be used
* within a template tagged with the {@linkcode html} tag function.
*
* In LitElement usage, it's invalid to return an MathML fragment from the
* `render()` method, as the MathML fragment will be contained within the
* element's shadow root and thus not be properly contained within a `<math>`
* HTML element.
*/
declare const mathml$1: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult<3>;
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
interface StaticValue {
/** The value to interpolate as-is into the template. */
_$litStatic$: string;
/**
* A value that can't be decoded from ordinary JSON, make it harder for
* an attacker-controlled data that goes through JSON.parse to produce a valid
* StaticValue.
*/
r: typeof brand;
}
/**
* Prevents JSON injection attacks.
*
* The goals of this brand:
* 1) fast to check
* 2) code is small on the wire
* 3) multiple versions of Lit in a single page will all produce mutually
* interoperable StaticValues
* 4) normal JSON.parse (without an unusual reviver) can not produce a
* StaticValue
*
* Symbols satisfy (1), (2), and (4). We use Symbol.for to satisfy (3), but
* we don't care about the key, so we break ties via (2) and use the empty
* string.
*/
declare const brand: unique symbol;
/**
* Wraps a string so that it behaves like part of the static template
* strings instead of a dynamic value.
*
* Users must take care to ensure that adding the static string to the template
* results in well-formed HTML, or else templates may break unexpectedly.
*
* Note that this function is unsafe to use on untrusted content, as it will be
* directly parsed into HTML. Do not pass user input to this function
* without sanitizing it.
*
* Static values can be changed, but they will cause a complete re-render
* since they effectively create a new template.
*/
declare const unsafeStatic: (value: string) => StaticValue;
/**
* Tags a string literal so that it behaves like part of the static template
* strings instead of a dynamic value.
*
* The only values that may be used in template expressions are other tagged
* `literal` results or `unsafeStatic` values (note that untrusted content
* should never be passed to `unsafeStatic`).
*
* Users must take care to ensure that adding the static string to the template
* results in well-formed HTML, or else templates may break unexpectedly.
*
* Static values can be changed, but they will cause a complete re-render since
* they effectively create a new template.
*/
declare const literal: (strings: TemplateStringsArray, ...values: unknown[]) => StaticValue;
/**
* Wraps a lit-html template tag (`html` or `svg`) to add static value support.
*/
declare const withStatic: (coreTag: typeof html$1 | typeof svg$1 | typeof mathml$1) => (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult;
/**
* Interprets a template literal as an HTML template that can efficiently
* render to and update a container.
*
* Includes static value support from `lit-html/static.js`.
*/
declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult;
/**
* Interprets a template literal as an SVG template that can efficiently
* render to and update a container.
*
* Includes static value support from `lit-html/static.js`.
*/
declare const svg: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult;
/**
* Interprets a template literal as MathML fragment that can efficiently render
* to and update a container.
*
* Includes static value support from `lit-html/static.js`.
*/
declare const mathml: (strings: TemplateStringsArray, ...values: unknown[]) => TemplateResult;
export { type StaticValue, html, literal, mathml, svg, unsafeStatic, withStatic };