| import { backgroundWallpaper } from "../config";
|
|
|
|
|
| export const getBackgroundImages = () => {
|
| const bgSrc = backgroundWallpaper.src;
|
|
|
| if (
|
| typeof bgSrc === "object" &&
|
| bgSrc !== null &&
|
| !Array.isArray(bgSrc) &&
|
| ("desktop" in bgSrc || "mobile" in bgSrc)
|
| ) {
|
| const srcObj = bgSrc as {
|
| desktop?: string | string[];
|
| mobile?: string | string[];
|
| };
|
| return {
|
| desktop: srcObj.desktop || srcObj.mobile || "",
|
| mobile: srcObj.mobile || srcObj.desktop || "",
|
| };
|
| }
|
|
|
| return {
|
| desktop: bgSrc,
|
| mobile: bgSrc,
|
| };
|
| };
|
|
|
|
|
| export const isBannerSrcObject = (
|
| src:
|
| | string
|
| | string[]
|
| | { desktop?: string | string[]; mobile?: string | string[] },
|
| ): src is { desktop?: string | string[]; mobile?: string | string[] } => {
|
| return (
|
| typeof src === "object" &&
|
| src !== null &&
|
| !Array.isArray(src) &&
|
| ("desktop" in src || "mobile" in src)
|
| );
|
| };
|
|
|
|
|
| export const getDefaultBackground = (): string => {
|
| const src = backgroundWallpaper.src;
|
| if (typeof src === "string") {
|
| return src;
|
| }
|
| if (src && typeof src === "object" && !Array.isArray(src)) {
|
|
|
| const desktopSrc = src.desktop;
|
| const mobileSrc = src.mobile;
|
| if (typeof desktopSrc === "string") {
|
| return desktopSrc;
|
| }
|
| if (typeof mobileSrc === "string") {
|
| return mobileSrc;
|
| }
|
| }
|
| return "";
|
| };
|
|
|
|
|
| export const isHomePage = (pathname: string): boolean => {
|
|
|
| const baseUrl = import.meta.env.BASE_URL || "/";
|
| const baseUrlNoSlash = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
|
| if (pathname === baseUrl) return true;
|
| if (pathname === baseUrlNoSlash) return true;
|
| if (pathname === "/") return true;
|
|
|
| return false;
|
| };
|
|
|
|
|
| export const getBannerOffset = (position = "center") => {
|
| const bannerOffsetByPosition = {
|
| top: "100vh",
|
| center: "50vh",
|
| bottom: "0",
|
| };
|
| return (
|
| bannerOffsetByPosition[position as keyof typeof bannerOffsetByPosition] ||
|
| "50vh"
|
| );
|
| };
|
|
|