add iching tarot links

This commit is contained in:
2026-03-07 16:13:58 -08:00
parent ed9b3bb257
commit 84b340d7d1
7 changed files with 199 additions and 9 deletions

View File

@@ -102,6 +102,8 @@
return String(value || "")
.trim()
.toLowerCase()
.replace(/^key\s+\d+\s*:\s*/g, "")
.replace(/\b(pentacles?|coins?)\b/g, "disks")
.replace(/\s+/g, " ");
}
@@ -114,6 +116,14 @@
}
function resolveTarotTrumpNumber(cardName) {
const rawKey = String(cardName || "")
.trim()
.toLowerCase();
const keyMatch = rawKey.match(/\bkey\s*(\d{1,2})\b/);
if (keyMatch) {
return Number(keyMatch[1]);
}
const key = normalizeTarotName(cardName);
if (!key) {
return null;
@@ -724,11 +734,86 @@
];
}
function buildIChingRelationsForCard(card, referenceData) {
const iChing = referenceData?.iChing;
const hexagrams = Array.isArray(iChing?.hexagrams) ? iChing.hexagrams : [];
const trigrams = Array.isArray(iChing?.trigrams) ? iChing.trigrams : [];
const correspondences = Array.isArray(iChing?.correspondences?.tarotToTrigram)
? iChing.correspondences.tarotToTrigram
: [];
if (!card || !hexagrams.length || !correspondences.length) {
return [];
}
const trigramByKey = new Map(
trigrams
.map((trigram) => [normalizeRelationId(trigram?.name), trigram])
.filter(([key]) => Boolean(key))
);
const matchedTrigramKeys = [...new Set(
correspondences
.filter((row) => cardMatchesTarotAssociation(card, row?.tarot))
.map((row) => normalizeRelationId(row?.trigram))
.filter(Boolean)
)];
if (!matchedTrigramKeys.length) {
return [];
}
const relations = [];
hexagrams.forEach((hexagram) => {
const positionsByTrigram = new Map();
const upperKey = normalizeRelationId(hexagram?.upperTrigram);
const lowerKey = normalizeRelationId(hexagram?.lowerTrigram);
if (matchedTrigramKeys.includes(upperKey)) {
positionsByTrigram.set(upperKey, ["upper"]);
}
if (matchedTrigramKeys.includes(lowerKey)) {
const existing = positionsByTrigram.get(lowerKey) || [];
positionsByTrigram.set(lowerKey, [...existing, "lower"]);
}
positionsByTrigram.forEach((positions, trigramKey) => {
const trigram = trigramByKey.get(trigramKey) || null;
const sideLabel = positions.length === 2
? "Upper + Lower"
: positions[0] === "upper"
? "Upper"
: "Lower";
const trigramLabel = trigram?.element || trigram?.name || hexagram?.upperTrigram || hexagram?.lowerTrigram || "Trigram";
relations.push({
type: "ichingHexagram",
id: String(hexagram?.number || ""),
label: `Hexagram ${hexagram.number}: ${hexagram.name || "--"} · ${sideLabel} ${trigramLabel}`,
data: {
hexagramNumber: Number(hexagram?.number),
name: hexagram?.name || "",
upperTrigram: hexagram?.upperTrigram || "",
lowerTrigram: hexagram?.lowerTrigram || "",
trigramName: trigram?.name || "",
trigramElement: trigram?.element || "",
positions: positions.join(",")
},
__key: `ichingHexagram|${hexagram?.number}|${trigramKey}|${positions.join(",")}`
});
});
});
return relations.sort((left, right) => Number(left?.data?.hexagramNumber || 999) - Number(right?.data?.hexagramNumber || 999));
}
window.TarotRelationsUi = {
buildCourtCardByDecanId,
buildSmallCardCourtLinkRelations,
buildMonthReferencesByCard,
buildCubeRelationsForCard,
buildIChingRelationsForCard,
parseMonthDayToken
};
})();