mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
15 lines
592 B
TypeScript
15 lines
592 B
TypeScript
/** Create an `HTMLTemplateElement` from an HTML string, or `null` when `document` is unavailable (SSR). */
|
|
export function createTemplate(html: string): HTMLTemplateElement | null {
|
|
const doc = globalThis.document;
|
|
if (!doc) return null;
|
|
|
|
const template = doc.createElement('template');
|
|
template.innerHTML = html;
|
|
return template;
|
|
}
|
|
|
|
/** Deep-clone a template's content into a container. */
|
|
export function renderTemplate(container: Element | ShadowRoot, template: HTMLTemplateElement): void {
|
|
container.appendChild(container.ownerDocument.importNode(template.content, true));
|
|
}
|