/* ========================================================================== js/render.js — dueño B: pinta el chat de WhatsApp (iOS) dentro del iPhone. API (SPEC §2): WAM.render / renderHeader / renderMensaje / anadirMensajeDOM / setTema / setEscribiendo / scrollAbajo / abrirSheet / abrirOpciones / cerrarSheet / tick. Campos por tipo: SPEC §1. Aspecto: docs/referencias/README.md. Cero listeners de flujo (los clics los resuelven main.js + interactivity.js con los data-* estampados aquí). Listeners propios, solo de presentación: cierre de la hoja (#sheet-fondo / X / enlaces), "Ver todas las opciones" y el reenvío del clic de una fila de esa hoja al botón (oculto) equivalente de la burbuja. No toca DOM al cargar. ========================================================================== */ (function () { "use strict"; window.WAM = window.WAM || {}; /* ------------------------------ helpers ------------------------------ */ function byId(id) { return document.getElementById(id); } function esc(s) { return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]; }); } function vacio(s) { return s == null || String(s) === ""; } function estado() { return WAM.estado || { cuenta: {}, mensajes: [] }; } var ESCRIBIENDO = false; var HOJA_ID = ""; /* id del mensaje cuya hoja está abierta ("" = ninguna) */ var ORIGEN_HOJA = null; /* elemento que tenía el foco al abrir la hoja */ var FOCO_EN_HOJA = false; /* la hoja movió el foco a su interior al abrirse */ /* Solo esquemas seguros en href (defensa en profundidad para JSON importados). */ function urlSegura(u) { var s = String(u == null ? "" : u).trim(); if (/^(https?:|mailto:|tel:)/i.test(s)) return s; /* Sin esquema ("www.cafe.com", "cafe.com/menu"): WhatsApp lo abre como https */ if (/^www\.[^\s]+$/i.test(s) || /^[\w-]+(\.[\w-]+)+(:\d+)?([\/?#][^\s]*)?$/.test(s)) return "https://" + s; return ""; } /* src de /