/* /assets/js/bridge/helpers.js — Namespace + Utilities (kein ES-Module) */ (function(w){ var B = w.BridgeParts = w.BridgeParts || {}; B.post = function(m){ try { parent.postMessage(m,'*'); } catch{} }; B.send = function(type, payload){ B.post(Object.assign({ source:'email-editor', type:type }, payload||{})); }; B.log = function(msg){ B.post({ source:'bridge', type:'log', detail:String(msg||'') }); }; B.ready = function(cb){ (function t(){ if (w.grapesjs) return cb(); setTimeout(t,40); })(); }; B.BADGE = function(){ return document.getElementById('badge'); }; B.badgeSay = function(txt, tone){ var b = B.BADGE(); if(!b) return; b.textContent = txt; var cfg = { ok: ['#ecfeff','#155e75','#a5f3fc'], warn: ['#fef3c7','#92400e','#fde68a'], err: ['#fee2e2','#7f1d1d','#fecaca'], base: ['#eef2ff','#1e3a8a','#c7d2fe'] }[tone||'base']; b.style.background = cfg[0]; b.style.color = cfg[1]; b.style.borderColor = cfg[2]; }; B.waitForBlocks = function(ed, opt){ opt = opt || {}; var timeoutMs = opt.timeoutMs || 4000, interval = opt.interval || 80; var bm = ed.BlockManager, t0 = Date.now(); return new Promise(function(resolve){ (function tick(){ var n = (bm && bm.getAll && bm.getAll().length) || 0; if (n > 0 || Date.now() - t0 > timeoutMs) return resolve(n); setTimeout(tick, interval); })(); }); }; B.renderBlocks = function(ed){ try { ed.BlockManager.render(); } catch{} }; })(window);