import { House } from "models"; export class DomOptions { attributes; children; classes; id; styles; /** * @param {Object} [options] * @param {Partial} [options.styles] * @param {string|null} [options.id] * @param {string[]} [options.classes] * @param {HTMLElement[]} [options.children] * @param {Record} [options.attributes] */ constructor({ id = "", styles = {}, classes = [], children = [], attributes = {} } = {}) { this.attributes = attributes; this.children = children; this.classes = classes; this.id = id; this.styles = styles; } } /** * Toast notification types * @enum {string} */ export const ToastType = { error: "error", success: "success", warning: "warning", }; export class Dom { /** * Create a `
` * @param {DomOptions} options * @returns {HTMLDivElement} */ static div(options) { const div = document.createElement("div"); Object.assign(div.style, options.styles); if (options.id) div.id = options.id; for (const cls of options.classes) div.classList.add(cls); for (const [k, v] of Object.entries(options.attributes)) div.setAttribute(k, v); if (options.children) div.append(...options.children); return div; } /** * Create a `` * @param {string} text * @param {DomOptions} options * @returns {HTMLSpanElement} */ static span(text, options = new DomOptions()) { const span = document.createElement("span"); Object.assign(span.style, options.styles); if (options.id) span.id = options.id; for (const cls of options.classes) span.classList.add(cls); span.textContent = text; for (const [k, v] of Object.entries(options.attributes)) span.setAttribute(k, v); if (options.children) span.append(...options.children); return span; } /** * Create a `