moved to API
This commit is contained in:
285
app/ui-tarot.js
285
app/ui-tarot.js
@@ -1,4 +1,5 @@
|
||||
(function () {
|
||||
const dataService = window.TarotDataService || {};
|
||||
const {
|
||||
resolveTarotCardImage,
|
||||
resolveTarotCardThumbnail,
|
||||
@@ -41,7 +42,8 @@
|
||||
magickDataset: null,
|
||||
referenceData: null,
|
||||
monthRefsByCardId: new Map(),
|
||||
courtCardByDecanId: new Map()
|
||||
courtCardByDecanId: new Map(),
|
||||
loadingPromise: null
|
||||
};
|
||||
|
||||
const TAROT_TRUMP_NUMBER_BY_NAME = {
|
||||
@@ -781,7 +783,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
function ensureTarotSection(referenceData, magickDataset = null) {
|
||||
async function loadCards(referenceData, magickDataset) {
|
||||
const payload = await dataService.loadTarotCards?.();
|
||||
const cards = Array.isArray(payload?.cards)
|
||||
? payload.cards
|
||||
: (Array.isArray(payload) ? payload : []);
|
||||
|
||||
return cards.map((card) => ({
|
||||
...card,
|
||||
id: String(card?.id || "").trim() || cardId(card)
|
||||
}));
|
||||
}
|
||||
|
||||
async function ensureTarotSection(referenceData, magickDataset = null) {
|
||||
state.referenceData = referenceData || state.referenceData;
|
||||
|
||||
if (magickDataset) {
|
||||
@@ -853,151 +867,156 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const databaseBuilder = window.TarotCardDatabase?.buildTarotDatabase;
|
||||
if (typeof databaseBuilder !== "function") {
|
||||
if (state.loadingPromise) {
|
||||
await state.loadingPromise;
|
||||
return;
|
||||
}
|
||||
|
||||
const cards = databaseBuilder(referenceData, magickDataset).map((card) => ({
|
||||
...card,
|
||||
id: cardId(card)
|
||||
}));
|
||||
state.loadingPromise = (async () => {
|
||||
const cards = await loadCards(referenceData, magickDataset);
|
||||
|
||||
state.cards = cards;
|
||||
state.monthRefsByCardId = buildMonthReferencesByCard(referenceData, cards);
|
||||
state.courtCardByDecanId = buildCourtCardByDecanId(cards);
|
||||
state.filteredCards = [...cards];
|
||||
renderList(elements);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
state.cards = cards;
|
||||
state.monthRefsByCardId = buildMonthReferencesByCard(referenceData, cards);
|
||||
state.courtCardByDecanId = buildCourtCardByDecanId(cards);
|
||||
state.filteredCards = [...cards];
|
||||
renderList(elements);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
|
||||
if (cards.length > 0) {
|
||||
selectCardById(cards[0].id, elements);
|
||||
}
|
||||
|
||||
elements.tarotCardListEl.addEventListener("click", (event) => {
|
||||
const target = event.target;
|
||||
if (!(target instanceof Node)) {
|
||||
return;
|
||||
if (cards.length > 0) {
|
||||
selectCardById(cards[0].id, elements);
|
||||
}
|
||||
|
||||
const button = target instanceof Element
|
||||
? target.closest(".tarot-list-item")
|
||||
: null;
|
||||
|
||||
if (!(button instanceof HTMLButtonElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedId = button.dataset.cardId;
|
||||
if (!selectedId) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectCardById(selectedId, elements);
|
||||
});
|
||||
|
||||
if (elements.tarotSearchInputEl) {
|
||||
elements.tarotSearchInputEl.addEventListener("input", () => {
|
||||
state.searchQuery = elements.tarotSearchInputEl.value || "";
|
||||
applySearchFilter(elements);
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotSearchClearEl && elements.tarotSearchInputEl) {
|
||||
elements.tarotSearchClearEl.addEventListener("click", () => {
|
||||
elements.tarotSearchInputEl.value = "";
|
||||
state.searchQuery = "";
|
||||
applySearchFilter(elements);
|
||||
elements.tarotSearchInputEl.focus();
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotHouseFocusToggleEl) {
|
||||
elements.tarotHouseFocusToggleEl.addEventListener("click", () => {
|
||||
state.houseFocusMode = !state.houseFocusMode;
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotHouseTopCardsVisibleEl) {
|
||||
elements.tarotHouseTopCardsVisibleEl.addEventListener("change", () => {
|
||||
state.houseTopCardsVisible = Boolean(elements.tarotHouseTopCardsVisibleEl.checked);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
}
|
||||
|
||||
[
|
||||
[elements.tarotHouseTopInfoHebrewEl, "hebrew"],
|
||||
[elements.tarotHouseTopInfoPlanetEl, "planet"],
|
||||
[elements.tarotHouseTopInfoZodiacEl, "zodiac"],
|
||||
[elements.tarotHouseTopInfoTrumpEl, "trump"],
|
||||
[elements.tarotHouseTopInfoPathEl, "path"]
|
||||
].forEach(([checkbox, key]) => {
|
||||
if (!checkbox) {
|
||||
return;
|
||||
}
|
||||
checkbox.addEventListener("change", () => {
|
||||
state.houseTopInfoModes[key] = Boolean(checkbox.checked);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
});
|
||||
|
||||
if (elements.tarotHouseBottomCardsVisibleEl) {
|
||||
elements.tarotHouseBottomCardsVisibleEl.addEventListener("change", () => {
|
||||
state.houseBottomCardsVisible = Boolean(elements.tarotHouseBottomCardsVisibleEl.checked);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
}
|
||||
|
||||
[
|
||||
[elements.tarotHouseBottomInfoZodiacEl, "zodiac"],
|
||||
[elements.tarotHouseBottomInfoDecanEl, "decan"],
|
||||
[elements.tarotHouseBottomInfoMonthEl, "month"],
|
||||
[elements.tarotHouseBottomInfoRulerEl, "ruler"],
|
||||
[elements.tarotHouseBottomInfoDateEl, "date"]
|
||||
].forEach(([checkbox, key]) => {
|
||||
if (!checkbox) {
|
||||
return;
|
||||
}
|
||||
checkbox.addEventListener("change", () => {
|
||||
state.houseBottomInfoModes[key] = Boolean(checkbox.checked);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
});
|
||||
|
||||
if (elements.tarotHouseExportEl) {
|
||||
elements.tarotHouseExportEl.addEventListener("click", () => {
|
||||
exportHouseOfCards(elements, "png");
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotHouseExportWebpEl) {
|
||||
elements.tarotHouseExportWebpEl.addEventListener("click", () => {
|
||||
exportHouseOfCards(elements, "webp");
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotDetailImageEl) {
|
||||
elements.tarotDetailImageEl.addEventListener("click", () => {
|
||||
if (elements.tarotDetailImageEl.style.display === "none" || !state.selectedCardId) {
|
||||
elements.tarotCardListEl.addEventListener("click", (event) => {
|
||||
const target = event.target;
|
||||
if (!(target instanceof Node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const request = buildLightboxCardRequestById(state.selectedCardId);
|
||||
if (!request?.src) {
|
||||
const button = target instanceof Element
|
||||
? target.closest(".tarot-list-item")
|
||||
: null;
|
||||
|
||||
if (!(button instanceof HTMLButtonElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.TarotUiLightbox?.open?.(request);
|
||||
});
|
||||
}
|
||||
const selectedId = button.dataset.cardId;
|
||||
if (!selectedId) {
|
||||
return;
|
||||
}
|
||||
|
||||
state.initialized = true;
|
||||
selectCardById(selectedId, elements);
|
||||
});
|
||||
|
||||
if (elements.tarotSearchInputEl) {
|
||||
elements.tarotSearchInputEl.addEventListener("input", () => {
|
||||
state.searchQuery = elements.tarotSearchInputEl.value || "";
|
||||
applySearchFilter(elements);
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotSearchClearEl && elements.tarotSearchInputEl) {
|
||||
elements.tarotSearchClearEl.addEventListener("click", () => {
|
||||
elements.tarotSearchInputEl.value = "";
|
||||
state.searchQuery = "";
|
||||
applySearchFilter(elements);
|
||||
elements.tarotSearchInputEl.focus();
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotHouseFocusToggleEl) {
|
||||
elements.tarotHouseFocusToggleEl.addEventListener("click", () => {
|
||||
state.houseFocusMode = !state.houseFocusMode;
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotHouseTopCardsVisibleEl) {
|
||||
elements.tarotHouseTopCardsVisibleEl.addEventListener("change", () => {
|
||||
state.houseTopCardsVisible = Boolean(elements.tarotHouseTopCardsVisibleEl.checked);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
}
|
||||
|
||||
[
|
||||
[elements.tarotHouseTopInfoHebrewEl, "hebrew"],
|
||||
[elements.tarotHouseTopInfoPlanetEl, "planet"],
|
||||
[elements.tarotHouseTopInfoZodiacEl, "zodiac"],
|
||||
[elements.tarotHouseTopInfoTrumpEl, "trump"],
|
||||
[elements.tarotHouseTopInfoPathEl, "path"]
|
||||
].forEach(([checkbox, key]) => {
|
||||
if (!checkbox) {
|
||||
return;
|
||||
}
|
||||
checkbox.addEventListener("change", () => {
|
||||
state.houseTopInfoModes[key] = Boolean(checkbox.checked);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
});
|
||||
|
||||
if (elements.tarotHouseBottomCardsVisibleEl) {
|
||||
elements.tarotHouseBottomCardsVisibleEl.addEventListener("change", () => {
|
||||
state.houseBottomCardsVisible = Boolean(elements.tarotHouseBottomCardsVisibleEl.checked);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
}
|
||||
|
||||
[
|
||||
[elements.tarotHouseBottomInfoZodiacEl, "zodiac"],
|
||||
[elements.tarotHouseBottomInfoDecanEl, "decan"],
|
||||
[elements.tarotHouseBottomInfoMonthEl, "month"],
|
||||
[elements.tarotHouseBottomInfoRulerEl, "ruler"],
|
||||
[elements.tarotHouseBottomInfoDateEl, "date"]
|
||||
].forEach(([checkbox, key]) => {
|
||||
if (!checkbox) {
|
||||
return;
|
||||
}
|
||||
checkbox.addEventListener("change", () => {
|
||||
state.houseBottomInfoModes[key] = Boolean(checkbox.checked);
|
||||
renderHouseOfCards(elements);
|
||||
syncHouseControls(elements);
|
||||
});
|
||||
});
|
||||
|
||||
if (elements.tarotHouseExportEl) {
|
||||
elements.tarotHouseExportEl.addEventListener("click", () => {
|
||||
exportHouseOfCards(elements, "png");
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotHouseExportWebpEl) {
|
||||
elements.tarotHouseExportWebpEl.addEventListener("click", () => {
|
||||
exportHouseOfCards(elements, "webp");
|
||||
});
|
||||
}
|
||||
|
||||
if (elements.tarotDetailImageEl) {
|
||||
elements.tarotDetailImageEl.addEventListener("click", () => {
|
||||
if (elements.tarotDetailImageEl.style.display === "none" || !state.selectedCardId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const request = buildLightboxCardRequestById(state.selectedCardId);
|
||||
if (!request?.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.TarotUiLightbox?.open?.(request);
|
||||
});
|
||||
}
|
||||
|
||||
state.initialized = true;
|
||||
})();
|
||||
|
||||
try {
|
||||
await state.loadingPromise;
|
||||
} finally {
|
||||
state.loadingPromise = null;
|
||||
}
|
||||
}
|
||||
|
||||
function selectCardByTrump(trumpNumber) {
|
||||
|
||||
Reference in New Issue
Block a user