2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: HEX_COLOR_PATTERN supports theme.js by holding or executing the hex color pattern page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
const HEX_COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: normalizeHexColor supports theme.js by holding or executing the normalize hex color page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
function normalizeHexColor(value) {
|
|
|
|
|
if (!value || typeof value !== 'string') {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
const normalized = value.trim()
|
|
|
|
|
return HEX_COLOR_PATTERN.test(normalized) ? normalized.toUpperCase() : ''
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: hexToRgb supports theme.js by holding or executing the hex to rgb page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
function hexToRgb(color) {
|
|
|
|
|
const value = color.replace('#', '')
|
|
|
|
|
return {
|
|
|
|
|
r: parseInt(value.slice(0, 2), 16),
|
|
|
|
|
g: parseInt(value.slice(2, 4), 16),
|
|
|
|
|
b: parseInt(value.slice(4, 6), 16)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: toHex supports theme.js by holding or executing the to hex page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
function toHex(value) {
|
|
|
|
|
return Math.min(255, Math.max(0, value)).toString(16).padStart(2, '0').toUpperCase()
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: rgbToHex supports theme.js by holding or executing the rgb to hex page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
function rgbToHex(rgb) {
|
|
|
|
|
return `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: mixColor supports theme.js by holding or executing the mix color page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
function mixColor(foreground, background, backgroundWeight) {
|
|
|
|
|
const fg = hexToRgb(foreground)
|
|
|
|
|
const bg = hexToRgb(background)
|
|
|
|
|
const weight = Math.min(1, Math.max(0, backgroundWeight))
|
|
|
|
|
return rgbToHex({
|
|
|
|
|
r: Math.round(fg.r * (1 - weight) + bg.r * weight),
|
|
|
|
|
g: Math.round(fg.g * (1 - weight) + bg.g * weight),
|
|
|
|
|
b: Math.round(fg.b * (1 - weight) + bg.b * weight)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: buildStyleVars supports theme.js by holding or executing the build style vars page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
function buildStyleVars(theme) {
|
|
|
|
|
const styleVars = [
|
|
|
|
|
`--theme-primary: ${theme.primaryColor};`,
|
|
|
|
|
`--theme-secondary: ${theme.secondaryColor};`,
|
|
|
|
|
`--theme-accent: ${theme.accentColor};`,
|
|
|
|
|
`--theme-page-bg: ${theme.pageBgColor};`,
|
|
|
|
|
`--theme-card-bg: ${theme.cardBgColor};`,
|
|
|
|
|
`--theme-border: ${theme.borderColor};`,
|
|
|
|
|
`--theme-primary-soft: ${theme.primarySoftColor};`,
|
|
|
|
|
`--theme-gradient: ${theme.gradient};`,
|
|
|
|
|
`--theme-gradient-soft: ${theme.softGradient};`
|
|
|
|
|
]
|
|
|
|
|
if (theme.backgroundImageUrl) {
|
|
|
|
|
styleVars.push(
|
|
|
|
|
`background-image: url("${theme.backgroundImageUrl}");`,
|
|
|
|
|
'background-size: cover;',
|
|
|
|
|
'background-position: center top;'
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return styleVars.join(' ')
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: resolveShopTheme supports theme.js by holding or executing the resolve shop theme page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
function resolveShopTheme(source) {
|
|
|
|
|
const themeSource = source || {}
|
|
|
|
|
const normalizedPrimaryColor = normalizeHexColor(themeSource.themePrimaryColor)
|
|
|
|
|
const primaryColor = normalizedPrimaryColor || DEFAULT_SHOP_THEME.primaryColor
|
|
|
|
|
const secondaryColor = normalizeHexColor(themeSource.themeSecondaryColor)
|
|
|
|
|
|| (normalizedPrimaryColor ? mixColor(primaryColor, '#FFFFFF', 0.68) : DEFAULT_SHOP_THEME.secondaryColor)
|
|
|
|
|
const accentColor = normalizeHexColor(themeSource.themeAccentColor)
|
|
|
|
|
|| (normalizedPrimaryColor ? mixColor(primaryColor, '#7A3F56', 0.38) : DEFAULT_SHOP_THEME.accentColor)
|
|
|
|
|
const pageBgColor = normalizeHexColor(themeSource.themePageBgColor) || DEFAULT_SHOP_THEME.pageBgColor
|
|
|
|
|
const cardBgColor = normalizeHexColor(themeSource.themeCardBgColor) || DEFAULT_SHOP_THEME.cardBgColor
|
|
|
|
|
const borderColor = mixColor(primaryColor, cardBgColor, 0.82)
|
|
|
|
|
const primarySoftColor = mixColor(primaryColor, cardBgColor, 0.88)
|
|
|
|
|
const gradient = `linear-gradient(135deg, ${primaryColor} 0%, ${secondaryColor} 100%)`
|
|
|
|
|
const softGradient = `linear-gradient(145deg, ${cardBgColor} 0%, ${mixColor(secondaryColor, pageBgColor, 0.55)} 58%, ${mixColor(primaryColor, pageBgColor, 0.82)} 100%)`
|
|
|
|
|
const backgroundImageFileId = themeSource.themeBackgroundImageFileId
|
|
|
|
|
? String(themeSource.themeBackgroundImageFileId).trim()
|
|
|
|
|
: ''
|
|
|
|
|
const backgroundImageUrl = themeSource.themeBackgroundImageUrl
|
|
|
|
|
? String(themeSource.themeBackgroundImageUrl).trim()
|
|
|
|
|
: ''
|
|
|
|
|
const theme = {
|
|
|
|
|
primaryColor,
|
|
|
|
|
secondaryColor,
|
|
|
|
|
accentColor,
|
|
|
|
|
pageBgColor,
|
|
|
|
|
cardBgColor,
|
|
|
|
|
borderColor,
|
|
|
|
|
primarySoftColor,
|
|
|
|
|
gradient,
|
|
|
|
|
softGradient,
|
|
|
|
|
backgroundImageFileId,
|
|
|
|
|
backgroundImageUrl
|
|
|
|
|
}
|
|
|
|
|
theme.styleVars = buildStyleVars(theme)
|
|
|
|
|
return theme
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: DEFAULT_SHOP_THEME supports theme.js by holding or executing the default shop theme page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
const DEFAULT_SHOP_THEME = {
|
|
|
|
|
primaryColor: '#C6597D',
|
|
|
|
|
secondaryColor: '#E9B7C7',
|
|
|
|
|
accentColor: '#9F4967',
|
|
|
|
|
pageBgColor: '#FFF7F9',
|
|
|
|
|
cardBgColor: '#FFFFFF',
|
|
|
|
|
borderColor: '#EFD8E0',
|
|
|
|
|
primarySoftColor: '#FBF1F4',
|
|
|
|
|
gradient: 'linear-gradient(135deg, #C6597D 0%, #E9B7C7 100%)',
|
|
|
|
|
softGradient: 'linear-gradient(145deg, #FFFFFF 0%, #FFF1F5 58%, #FFE8EF 100%)',
|
|
|
|
|
backgroundImageFileId: '',
|
|
|
|
|
backgroundImageUrl: ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEFAULT_SHOP_THEME.styleVars = buildStyleVars(DEFAULT_SHOP_THEME)
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: pageThemeData supports theme.js by holding or executing the page theme data page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
function pageThemeData(theme, backgroundImageUrl) {
|
|
|
|
|
const resolved = theme || DEFAULT_SHOP_THEME
|
|
|
|
|
const themeData = backgroundImageUrl
|
|
|
|
|
? {
|
|
|
|
|
...resolved,
|
|
|
|
|
backgroundImageUrl: String(backgroundImageUrl).trim()
|
|
|
|
|
}
|
|
|
|
|
: resolved
|
|
|
|
|
if (backgroundImageUrl) {
|
|
|
|
|
themeData.styleVars = buildStyleVars(themeData)
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
theme: themeData,
|
|
|
|
|
themeVars: themeData.styleVars,
|
|
|
|
|
navThemeColor: themeData.primaryColor,
|
|
|
|
|
navThemeBackground: themeData.pageBgColor
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
DEFAULT_SHOP_THEME,
|
|
|
|
|
resolveShopTheme,
|
|
|
|
|
pageThemeData
|
|
|
|
|
}
|