Sync live quote handling, SSE product images, store hours, file URL normalization, PWA icon cache, TV monitor, about software, SuperAdmin menu gates, price alerts, and related UX from modular while preserving boursecu branding and config constraints. Co-authored-by: Cursor <cursoragent@cursor.com>
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
/** Lottieهای لوکال (`public/lottie`) — پیشدانلود تا مودال/لیست خالی نماند */
|
|
|
|
const LOTTIE_FILES = {
|
|
logoutConfirm: 'lottie/logoutConfirm.json',
|
|
emptyList: 'lottie/emptyList.json',
|
|
goldBars: 'lottie/goldBars.json',
|
|
} as const
|
|
|
|
export type LottieAssetKey = keyof typeof LOTTIE_FILES
|
|
|
|
const cache = new Map<LottieAssetKey, string>()
|
|
|
|
export function lottieSrc(key: LottieAssetKey): string {
|
|
const base = import.meta.env.BASE_URL || '/'
|
|
const path = `${base}${LOTTIE_FILES[key]}`
|
|
return path.replace(/([^:]\/)\/+/g, '$1')
|
|
}
|
|
|
|
export function getLottieData(key: LottieAssetKey): string | undefined {
|
|
return cache.get(key)
|
|
}
|
|
|
|
export async function preloadLottieAssets(): Promise<void> {
|
|
const keys = Object.keys(LOTTIE_FILES) as LottieAssetKey[]
|
|
await Promise.all(
|
|
keys.map(async (key) => {
|
|
if (cache.has(key)) return
|
|
try {
|
|
const res = await fetch(lottieSrc(key))
|
|
if (!res.ok) return
|
|
cache.set(key, await res.text())
|
|
} catch {
|
|
/* شبکه/آفلاین — بعداً از src لوکال میخواند */
|
|
}
|
|
}),
|
|
)
|
|
}
|