어나운스 바 설정 확장 v1.5.38
This commit is contained in:
@@ -11,14 +11,54 @@ export const ANNOUNCEMENT_BACKGROUND_PRESETS = [
|
||||
/** @type {string} 기본 어나운스 바 배경색 */
|
||||
export const DEFAULT_ANNOUNCEMENT_BACKGROUND_COLOR = '#15171a'
|
||||
|
||||
/** @type {string} 기본 어나운스 바 정렬 */
|
||||
export const DEFAULT_ANNOUNCEMENT_ALIGNMENT = 'center'
|
||||
|
||||
/**
|
||||
* 어나운스 바 배경색이 허용 프리셋인지 확인한다.
|
||||
* @param {string} value - hex 색상
|
||||
* @returns {boolean} 허용 여부
|
||||
* 어나운스 바 정렬 옵션
|
||||
* @type {ReadonlyArray<{ value: string, label: string }>}
|
||||
*/
|
||||
export const isValidAnnouncementBackgroundColor = (value) => {
|
||||
const normalized = (value || '').trim().toLowerCase()
|
||||
return ANNOUNCEMENT_BACKGROUND_PRESETS.some((preset) => preset.value.toLowerCase() === normalized)
|
||||
export const ANNOUNCEMENT_ALIGNMENT_OPTIONS = [
|
||||
{ value: 'center', label: '중앙' },
|
||||
{ value: 'left', label: '왼쪽' }
|
||||
]
|
||||
|
||||
/**
|
||||
* 어나운스 바 배경색 형식이 올바른지 확인한다.
|
||||
* @param {unknown} value - hex 색상
|
||||
* @returns {boolean} 유효 여부
|
||||
*/
|
||||
export const isValidAnnouncementBackgroundColor = (value) => /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(String(value || '').trim())
|
||||
|
||||
/**
|
||||
* 어나운스 바 배경색을 6자리 hex 값으로 정규화한다.
|
||||
* @param {unknown} value - 입력 색상
|
||||
* @returns {string} 정규화된 색상
|
||||
*/
|
||||
export const normalizeAnnouncementBackgroundColor = (value) => {
|
||||
const color = String(value || '').trim().toLowerCase()
|
||||
|
||||
if (!isValidAnnouncementBackgroundColor(color)) {
|
||||
return DEFAULT_ANNOUNCEMENT_BACKGROUND_COLOR
|
||||
}
|
||||
|
||||
if (color.length === 4) {
|
||||
return `#${color[1]}${color[1]}${color[2]}${color[2]}${color[3]}${color[3]}`
|
||||
}
|
||||
|
||||
return color
|
||||
}
|
||||
|
||||
/**
|
||||
* 어나운스 바 정렬 값을 정리한다.
|
||||
* @param {unknown} value - 입력 정렬
|
||||
* @returns {string} 정리된 정렬
|
||||
*/
|
||||
export const normalizeAnnouncementAlignment = (value) => {
|
||||
const alignment = String(value || '').trim().toLowerCase()
|
||||
return ANNOUNCEMENT_ALIGNMENT_OPTIONS.some((option) => option.value === alignment)
|
||||
? alignment
|
||||
: DEFAULT_ANNOUNCEMENT_ALIGNMENT
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,13 +67,19 @@ export const isValidAnnouncementBackgroundColor = (value) => {
|
||||
* @returns {string} 전경 hex 색상
|
||||
*/
|
||||
export const getAnnouncementBarTextColor = (backgroundColor) => {
|
||||
const normalized = (backgroundColor || '').trim().toLowerCase()
|
||||
const normalized = normalizeAnnouncementBackgroundColor(backgroundColor)
|
||||
const preset = ANNOUNCEMENT_BACKGROUND_PRESETS.find((item) => item.value.toLowerCase() === normalized)
|
||||
if (preset) {
|
||||
return preset.textColor
|
||||
}
|
||||
|
||||
return '#ffffff'
|
||||
const hex = normalized.slice(1)
|
||||
const red = parseInt(hex.slice(0, 2), 16)
|
||||
const green = parseInt(hex.slice(2, 4), 16)
|
||||
const blue = parseInt(hex.slice(4, 6), 16)
|
||||
const luminance = (red * 299 + green * 587 + blue * 114) / 1000
|
||||
|
||||
return luminance > 150 ? '#15171a' : '#ffffff'
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user