2021-11-22 12:45:19 +00:00
|
|
|
const validateColor = require('validate-color').default
|
2021-11-19 15:45:10 +00:00
|
|
|
|
|
|
|
type AutoColorValue = string
|
|
|
|
|
|
|
|
interface AutoColors {
|
|
|
|
mainForeground: AutoColorValue
|
|
|
|
mainBackground: AutoColorValue
|
|
|
|
greyForeground: AutoColorValue
|
|
|
|
greyBackground: AutoColorValue
|
|
|
|
menuForeground: AutoColorValue
|
|
|
|
menuBackground: AutoColorValue
|
|
|
|
inputForeground: AutoColorValue
|
|
|
|
inputBackground: AutoColorValue
|
|
|
|
buttonForeground: AutoColorValue
|
|
|
|
buttonBackground: AutoColorValue
|
|
|
|
link: AutoColorValue
|
|
|
|
linkHover: AutoColorValue
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param theme value of the settings 'converse-theme'
|
|
|
|
* @returns true if the theme can use autocolors
|
|
|
|
*/
|
2022-10-10 16:08:20 +00:00
|
|
|
function isAutoColorsAvailable (theme: string): boolean {
|
2021-11-19 15:45:10 +00:00
|
|
|
return theme === 'peertube' // currently the only theme that can handle autocolors.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param autocolors
|
|
|
|
* @returns true if ok. Else a string array with invalid values.
|
|
|
|
*/
|
|
|
|
function areAutoColorsValid (autocolors: AutoColors): true | string[] {
|
|
|
|
const errors: string[] = []
|
|
|
|
for (const k in autocolors) {
|
|
|
|
const color = autocolors[k as keyof AutoColors]
|
2021-11-22 12:45:19 +00:00
|
|
|
if (!validateColor(color)) {
|
2021-11-19 15:45:10 +00:00
|
|
|
errors.push(color)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (errors.length) {
|
|
|
|
return errors
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-12-07 17:36:16 +00:00
|
|
|
export type {
|
|
|
|
AutoColors
|
|
|
|
}
|
2021-11-19 15:45:10 +00:00
|
|
|
export {
|
|
|
|
isAutoColorsAvailable,
|
|
|
|
areAutoColorsValid
|
|
|
|
}
|