element-vir
Version:
Heroic. Reactive. Declarative. Type safe. Web components without compromise.
26 lines (25 loc) • 1.07 kB
JavaScript
import { html as litHtml } from 'lit';
import { getTransformedTemplate } from '../transform-template.js';
import { mapHtmlValues, transformHtmlTemplate } from './html-transform.js';
/**
* Interprets a template literal as an HTML template which is lazily rendered to the DOM.
*
* Wraps lit-html's html tagged template and enables interpolations of
* `DeclarativeElementDefinition` for tag names.
*
* @category Element Definition
*/
export function html(inputTemplateStrings, ...inputValues) {
const mappedValues = mapHtmlValues(inputTemplateStrings, inputValues);
const transformedTemplate = getTransformedTemplate(inputTemplateStrings, mappedValues, () => {
return transformHtmlTemplate({
strings: inputTemplateStrings,
values: mappedValues,
});
});
/**
* The lit template is built directly from the transformed template so that a discarded lit
* template and a copy of it aren't allocated on every render.
*/
return litHtml(transformedTemplate.strings, ...transformedTemplate.values);
}