// ── Glass UI Shared Utilities ──────────────────────────────────────────
// Single source of truth for common functions used across Glass UI modules.

/**
 * Escape HTML special characters to prevent XSS attacks.
 * Handles null/undefined safely via nullish coalescing.
 * @param {*} t - Value to escape (converted to string)
 * @returns {string} HTML-safe string
 */
function escHtml(t) {
  return String(t ?? "")
    .replace(/&/g, "&amp;")
    .replace(/</g, "&lt;")
    .replace(/>/g, "&gt;")
    .replace(/"/g, "&quot;")
    .replace(/'/g, "&#39;");
}

/**
 * Escape a value for use in HTML attributes.
 * Alias for escHtml since both require the same escaping.
 */
function escAttr(t) {
  return escHtml(t);
}

// Expose globally for use by other Glass UI scripts
window.escHtml = escHtml;
window.escAttr = escAttr;
