function createElement(tag, attrs = {}, ...children) {
const elem = document.createElement(tag);
for (let [k, v] of Object.entries(attrs)) {
if (k.startsWith('on')) {
elem.addEventListener(k.slice(2), v);
} else {
elem.setAttribute(k, v);
}
}
for (let child of children) {
elem.appendChild((child instanceof HTMLElement) ? child : document.createTextNode(child));
}
return elem;
}