Create + append an element to body; optionally set attrs and inline styles.
(
tag: string,
attrs: Record<string, string> = {},
styles: Record<string, string> = {},
)
| 25 | |
| 26 | /** Create + append an element to body; optionally set attrs and inline styles. */ |
| 27 | function make( |
| 28 | tag: string, |
| 29 | attrs: Record<string, string> = {}, |
| 30 | styles: Record<string, string> = {}, |
| 31 | ): HTMLElement { |
| 32 | const elem = document.createElement(tag); |
| 33 | for (const [k, v] of Object.entries(attrs)) elem.setAttribute(k, v); |
| 34 | for (const [k, v] of Object.entries(styles)) elem.style.setProperty(k, v); |
| 35 | document.body.appendChild(elem); |
| 36 | return elem; |
| 37 | } |
| 38 | |
| 39 | function adapterWith(resolvePoint: (x: number, y: number) => Element | null) { |
| 40 | return createPreviewAdapter(document, { resolvePoint }); |
no test coverage detected