// Pure ordering logic (kept DOM-free so it is unit-testable). The card MODULES // themselves are imported by sacred_valley.js, which passes their defs here. export function orderCards(defs, layout = { card_order: [], hidden: [] }) { const byId = new Map(defs.map(d => [d.id, d])); const hidden = new Set(layout.hidden || []); const out = []; for (const id of layout.card_order || []) { if (byId.has(id) && !hidden.has(id)) { out.push(byId.get(id)); byId.delete(id); } } for (const d of defs) { if (byId.has(d.id) && !hidden.has(d.id)) out.push(d); } return out; }