UNPKG

react-prayer-widget

Version:

Embeddable prayer times widget components for React applications

84 lines (83 loc) 3.06 kB
// shared/lib/prayer/azan.ts var BUILTIN_AZAN_SOURCES = { default: "/audio/audio_azan.mp3", short: "/audio/short_azan.mp3", fajr: "/audio/audio_fajr.mp3", beep: "/audio/w-alert-1.wav" }; function getCustomAzanSource(choice, prayer) { if (choice === "custom:global") { const key = globalCustomStorageKey(); const url = typeof localStorage !== "undefined" ? localStorage.getItem(key) : null; return url || null; } const p = choice.split(":")[1]; if (p && p === prayer) { const key = customStorageKey(p); const url = typeof localStorage !== "undefined" ? localStorage.getItem(key) : null; return url || null; } return null; } function getAzanSource(choice, prayer) { if (!choice || choice === "default") { return BUILTIN_AZAN_SOURCES.default; } if (choice === "off") { return null; } if (choice in BUILTIN_AZAN_SOURCES) { return BUILTIN_AZAN_SOURCES[choice]; } if (choice.startsWith("custom:")) { return getCustomAzanSource(choice, prayer); } return BUILTIN_AZAN_SOURCES[choice] || null; } function customStorageKey(prayer) { return `tawkit:azan:custom:${prayer}`; } async function storeCustomAzanFile(prayer, file) { const dataUrl = await new Promise((resolve, reject) => { const reader = new FileReader(); reader.onerror = () => reject(new Error("Failed to read file")); reader.onload = () => resolve(String(reader.result)); reader.readAsDataURL(file); }); localStorage.setItem(customStorageKey(prayer), dataUrl); localStorage.setItem(`${customStorageKey(prayer)}:name`, file.name); return { url: dataUrl, name: file.name }; } function globalCustomStorageKey() { return "tawkit:azan:custom:GLOBAL"; } async function storeCustomAzanFileGlobal(file) { const dataUrl = await new Promise((resolve, reject) => { const reader = new FileReader(); reader.onerror = () => reject(new Error("Failed to read file")); reader.onload = () => resolve(String(reader.result)); reader.readAsDataURL(file); }); localStorage.setItem(globalCustomStorageKey(), dataUrl); localStorage.setItem(`${globalCustomStorageKey()}:name`, file.name); return { url: dataUrl, name: file.name }; } function removeCustomAzanFileGlobal() { const key = globalCustomStorageKey(); localStorage.removeItem(key); localStorage.removeItem(`${key}:name`); } function getCustomAzanGlobalName() { return localStorage.getItem(`${globalCustomStorageKey()}:name`) || void 0; } function removeCustomAzanFile(prayer) { const key = customStorageKey(prayer); localStorage.removeItem(key); localStorage.removeItem(`${key}:name`); } function getCustomAzanName(prayer) { return localStorage.getItem(`${customStorageKey(prayer)}:name`) || void 0; } export { BUILTIN_AZAN_SOURCES, customStorageKey, getAzanSource, getCustomAzanGlobalName, getCustomAzanName, globalCustomStorageKey, removeCustomAzanFile, removeCustomAzanFileGlobal, storeCustomAzanFile, storeCustomAzanFileGlobal }; //# sourceMappingURL=chunk-DVY2OY7Q.js.map //# sourceMappingURL=chunk-DVY2OY7Q.js.map