Open History to see the last commit
1/// <reference lib="dom" />
2import type { LitElement } from 'lit'
3β
4const registered = new Set<string>()
5const mountedElements = new Set<LitElement>()
6β
7export function defineOnce(name: string, ctor: CustomElementConstructor) {
8 if (!registered.has(name) && !window.customElements.get(name)) {
9 window.customElements.define(name, ctor)
10 registered.add(name)
11 }
12}
13β
14export async function mount<T extends LitElement>(tag: string): Promise<T> {
15 const el = document.createElement(tag) as T
16 document.body.appendChild(el)
17 await el.updateComplete
18 mountedElements.add(el)
19 return el
20}
21β
22export function cleanup() {
23 for (const el of mountedElements) el.remove()
24 mountedElements.clear()
25}