/* ui-zodiac.js β Zodiac sign browser section */ (function () { "use strict"; const ELEMENT_STYLE = { fire: { emoji: "π₯", badge: "zod-badge--fire", label: "Fire" }, earth: { emoji: "π", badge: "zod-badge--earth", label: "Earth" }, air: { emoji: "π¨", badge: "zod-badge--air", label: "Air" }, water: { emoji: "π§", badge: "zod-badge--water", label: "Water" } }; const PLANET_SYMBOLS = { saturn: "βοΈ", jupiter: "βοΈ", mars: "βοΈ", sol: "βοΈ", venus: "βοΈ", mercury: "βΏοΈ", luna: "βΎοΈ" }; const MONTH_NAMES = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; const state = { initialized: false, entries: [], filteredEntries: [], selectedId: null, searchQuery: "", kabPaths: [], decansBySign: {}, monthRefsBySignId: new Map(), cubePlacementBySignId: new Map() }; // ββ Elements ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function getElements() { return { listEl: document.getElementById("zodiac-sign-list"), countEl: document.getElementById("zodiac-sign-count"), searchEl: document.getElementById("zodiac-search-input"), searchClearEl: document.getElementById("zodiac-search-clear"), detailNameEl: document.getElementById("zodiac-detail-name"), detailSubEl: document.getElementById("zodiac-detail-sub"), detailBodyEl: document.getElementById("zodiac-detail-body") }; } // ββ Normalise βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function norm(s) { return String(s || "").toLowerCase().replace(/[^a-z0-9 ]/g, "").trim(); } function cap(s) { return String(s || "").charAt(0).toUpperCase() + String(s || "").slice(1); } function buildSearchText(sign) { return norm([ sign.name?.en, sign.meaning?.en, sign.elementId, sign.quadruplicity, sign.planetId, sign.id ].join(" ")); } function formatDateRange(rulesFrom) { if (!Array.isArray(rulesFrom) || rulesFrom.length < 2) return "β"; const [from, to] = rulesFrom; const fMonth = MONTH_NAMES[(from[0] || 1) - 1]; const tMonth = MONTH_NAMES[(to[0] || 1) - 1]; return `${fMonth} ${from[1]} β ${tMonth} ${to[1]}`; } function buildMonthReferencesBySign(referenceData) { const map = new Map(); const months = Array.isArray(referenceData?.calendarMonths) ? referenceData.calendarMonths : []; const holidays = Array.isArray(referenceData?.celestialHolidays) ? referenceData.celestialHolidays : []; const signs = Array.isArray(referenceData?.signs) ? referenceData.signs : []; const monthById = new Map(months.map((month) => [month.id, month])); const monthByOrder = new Map( months .filter((month) => Number.isFinite(Number(month?.order))) .map((month) => [Number(month.order), month]) ); function parseMonthDay(value) { const [month, day] = String(value || "").split("-").map((part) => Number(part)); if (!Number.isFinite(month) || !Number.isFinite(day)) { return null; } return { month, day }; } function monthOrdersInRange(startMonth, endMonth) { const orders = []; let cursor = startMonth; let guard = 0; while (guard < 13) { orders.push(cursor); if (cursor === endMonth) { break; } cursor = cursor === 12 ? 1 : cursor + 1; guard += 1; } return orders; } function pushRef(signId, month) { const key = String(signId || "").trim().toLowerCase(); if (!key || !month?.id) { return; } if (!map.has(key)) { map.set(key, []); } const rows = map.get(key); if (rows.some((entry) => entry.id === month.id)) { return; } rows.push({ id: month.id, name: month.name || month.id, order: Number.isFinite(Number(month.order)) ? Number(month.order) : 999 }); } months.forEach((month) => { pushRef(month?.associations?.zodiacSignId, month); const events = Array.isArray(month?.events) ? month.events : []; events.forEach((event) => { pushRef(event?.associations?.zodiacSignId, month); }); }); holidays.forEach((holiday) => { const month = monthById.get(holiday?.monthId); if (!month) { return; } pushRef(holiday?.associations?.zodiacSignId, month); }); // Structural month coverage from sign date ranges (e.g., Scorpio spans Oct+Nov). signs.forEach((sign) => { const start = parseMonthDay(sign?.start); const end = parseMonthDay(sign?.end); if (!start || !end || !sign?.id) { return; } monthOrdersInRange(start.month, end.month).forEach((monthOrder) => { const month = monthByOrder.get(monthOrder); if (month) { pushRef(sign.id, month); } }); }); map.forEach((rows, key) => { rows.sort((left, right) => left.order - right.order || left.name.localeCompare(right.name)); map.set(key, rows); }); return map; } function buildCubeSignPlacements(magickDataset) { const placements = new Map(); const cube = magickDataset?.grouped?.kabbalah?.cube || {}; const walls = Array.isArray(cube?.walls) ? cube.walls : []; const edges = Array.isArray(cube?.edges) ? cube.edges : []; const paths = Array.isArray(magickDataset?.grouped?.kabbalah?.["kabbalah-tree"]?.paths) ? magickDataset.grouped.kabbalah["kabbalah-tree"].paths : []; function normalizeLetterId(value) { const key = String(value || "").toLowerCase().replace(/[^a-z]/g, "").trim(); const aliases = { aleph: "alef", beth: "bet", zain: "zayin", cheth: "het", chet: "het", daleth: "dalet", teth: "tet", peh: "pe", tzaddi: "tsadi", tzadi: "tsadi", tzade: "tsadi", tsaddi: "tsadi", qoph: "qof", taw: "tav", tau: "tav" }; return aliases[key] || key; } function edgeWalls(edge) { const explicitWalls = Array.isArray(edge?.walls) ? edge.walls.map((wallId) => String(wallId || "").trim().toLowerCase()).filter(Boolean) : []; if (explicitWalls.length >= 2) { return explicitWalls.slice(0, 2); } return String(edge?.id || "") .trim() .toLowerCase() .split("-") .map((wallId) => wallId.trim()) .filter(Boolean) .slice(0, 2); } function edgeLabel(edge) { const explicitName = String(edge?.name || "").trim(); if (explicitName) { return explicitName; } return edgeWalls(edge) .map((part) => cap(part)) .join(" "); } function resolveCubeDirectionLabel(wallId, edge) { const normalizedWallId = String(wallId || "").trim().toLowerCase(); const edgeId = String(edge?.id || "").trim().toLowerCase(); if (!normalizedWallId || !edgeId) { return ""; } const cubeUi = window.CubeSectionUi; if (cubeUi && typeof cubeUi.getEdgeDirectionLabelForWall === "function") { const directionLabel = String(cubeUi.getEdgeDirectionLabelForWall(normalizedWallId, edgeId) || "").trim(); if (directionLabel) { return directionLabel; } } return edgeLabel(edge); } const wallById = new Map( walls.map((wall) => [String(wall?.id || "").trim().toLowerCase(), wall]) ); const pathByLetterId = new Map( paths .map((path) => [normalizeLetterId(path?.hebrewLetter?.transliteration), path]) .filter(([letterId]) => Boolean(letterId)) ); edges.forEach((edge) => { const letterId = normalizeLetterId(edge?.hebrewLetterId || edge?.associations?.hebrewLetterId); const path = pathByLetterId.get(letterId) || null; const signId = path?.astrology?.type === "zodiac" ? String(path?.astrology?.name || "").trim().toLowerCase() : ""; if (!signId || placements.has(signId)) { return; } const wallsForEdge = edgeWalls(edge); const primaryWallId = wallsForEdge[0] || ""; const primaryWall = wallById.get(primaryWallId); placements.set(signId, { wallId: primaryWallId, edgeId: String(edge?.id || "").trim().toLowerCase(), wallName: primaryWall?.name || cap(primaryWallId || "wall"), edgeName: resolveCubeDirectionLabel(primaryWallId, edge) }); }); return placements; } function cubePlacementLabel(placement) { const wallName = placement?.wallName || "Wall"; const edgeName = placement?.edgeName || "Direction"; return `Cube: ${wallName} Wall - ${edgeName}`; } // ββ List ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function applyFilter() { const q = norm(state.searchQuery); state.filteredEntries = q ? state.entries.filter((s) => buildSearchText(s).includes(q)) : [...state.entries]; } function renderList(els) { if (!els.listEl) return; els.listEl.innerHTML = ""; state.filteredEntries.forEach((sign) => { const active = sign.id === state.selectedId; const el = document.createElement("div"); el.className = "planet-list-item" + (active ? " is-selected" : ""); el.setAttribute("role", "option"); el.setAttribute("aria-selected", active ? "true" : "false"); el.dataset.id = sign.id; const elemStyle = ELEMENT_STYLE[sign.elementId] || {}; el.innerHTML = `