fix. 코드 리팩토링

This commit is contained in:
clkim
2025-10-22 16:12:02 +09:00
parent 8e0cdc9478
commit 69e46595bc
9 changed files with 199 additions and 128 deletions

View File

@@ -15,6 +15,9 @@ import type {
* @returns 완전한 이미지 URL
*/
export const getResolvedHost = (path: string): string => {
// path가 없으면 빈 문자열 반환
if (!path || typeof path !== 'string') return ''
if (
path.startsWith('http://') ||
path.startsWith('https://') ||
@@ -33,35 +36,33 @@ export const getResolvedHost = (path: string): string => {
}
/**
* 반응형 리소스(이미지/비디오)를 처리하여 PC/모바일 버전을 반환합니다.
* 디바이스 리소스(이미지/비디오)를 처리하여 PC/모바일 버전을 반환합니다.
* @param pathArray 리소스 경로 배열
* @param options 리소스 타입 옵션
* @returns 반응형 리소스 객체 또는 null
* @returns 디바이스 리소스 객체 또는 null
*/
export const getResponsiveSrc = (
export const getDeviceSrc = (
pathArray: PageDataResourceGroupResPath,
options: {
resourcesType?: 'image' | 'bg' | 'video'
} = {}
options?: {
resourcesType?: 'image' | 'video'
}
) => {
const { resourcesType = 'image' } = options
// pathArray가 없으면 null 반환
if (!pathArray) return null
const { resourcesType = 'image' } = options ?? {}
const pcField = resourcesType === 'video' ? 'path_vid_pc' : 'path_pc'
const mobileField = resourcesType === 'video' ? 'path_vid_mo' : 'path_mo'
if (!pathArray?.[mobileField]) {
return null
}
const pcPath = pathArray[pcField] || pathArray[mobileField]
const mobilePath = pathArray[mobileField] || pathArray[pcField]
// 경로가 없으면 null 반환
if (!pcPath && !mobilePath) return null
const resolvedImages = {
pc: getResolvedHost(pathArray[pcField] || pathArray[mobileField]),
mobile: getResolvedHost(pathArray[mobileField]),
}
if (resourcesType === 'bg') {
return {
'--pc-bg': `url(${resolvedImages.pc})`,
'--mobile-bg': `url(${resolvedImages.mobile})`,
}
pc: pcPath ? getResolvedHost(pcPath) : '',
mobile: mobilePath ? getResolvedHost(mobilePath) : '',
}
return {
@@ -70,14 +71,6 @@ export const getResponsiveSrc = (
}
}
/**
* 반응형 배경 이미지를 위한 CSS 클래스를 반환합니다.
* @returns 반응형 배경 클래스 배열
*/
export const getResponsiveClass = () => {
return ['bg-[image:var(--mobile-bg)]', 'md:bg-[image:var(--pc-bg)]']
}
/**
* 색상값을 반환합니다.
* @param colorName 색상 이름