/** * @typedef {Object} BaseElementOptions * @property {Partial} [styles] * @property {string} [id] * @property {string[]} [classes] * @property {string} [textContent] * @property {HTMLElement[]} [children] * @property {Record} [attributes] */ /** * Toast notification types * @enum {string} */ export const ToastType = { error: "error", success: "success", warning: "warning", }; /** * DOM element creation class – every creator applies its own options. * @class */ export class Dom { /** * Create a `
` * @param {BaseElementOptions} [options={}] * @returns {HTMLDivElement} */ static div(options = {}) { const { styles = {}, id = "", classes = [], textContent = "", children = [], attributes = {}, } = options; const div = document.createElement("div"); Object.assign(div.style, styles); if (id) div.id = id; for (const cls of classes) div.classList.add(cls); if (textContent) div.textContent = textContent; for (const [k, v] of Object.entries(attributes)) div.setAttribute(k, v); if (children) div.append(...children); return div; } /** * Create a `` * @param {BaseElementOptions} [options={}] * @returns {HTMLSpanElement} */ static span(options = {}) { const { styles = {}, id = "", classes = [], textContent = "", children = [], attributes = {}, } = options; const span = document.createElement("span"); Object.assign(span.style, styles); if (id) span.id = id; for (const cls of classes) span.classList.add(cls); if (textContent) span.textContent = textContent; for (const [k, v] of Object.entries(attributes)) span.setAttribute(k, v); if (children) span.append(...children); return span; } /** * Create a `