Debian Codegraph @

a11y-plugin/src/util.ts

raw
1 export function createElement(html: string): HTMLElement {
2 const template = document.createElement('template');
3 template.innerHTML = html;
4 return template.content.children[0] as HTMLElement;
5 }
6
7 export function parseTemplate(str: string, replacements: Record<string, string>): string {
8 return Object.keys(replacements).reduce((str, key) => {
9 return str.replace(`{${key}}`, replacements[key] || '');
10 }, str || '');
11 }
12
13 export function prefersReducedMotion(): boolean {
14 return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
15 }