peertube-plugin-livechat/shared/lib/autocolors.ts
John Livingston c178213e19
Use ESBuild for frontend build.
Replacing webpack by ESBuild for client code compilation (as in the
official quickstart plugin).

So we can remove deprecated webpack dependencies.

Note: webpack is still used for ConverseJS build.
This may be removed soon.

Related to issue #122.
2022-12-12 19:31:29 +01:00

53 lines
1.2 KiB
TypeScript

const validateColor = require('validate-color').default
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
*/
function isAutoColorsAvailable (theme: string): boolean {
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]
if (!validateColor(color)) {
errors.push(color)
}
}
if (errors.length) {
return errors
}
return true
}
export type {
AutoColors
}
export {
isAutoColorsAvailable,
areAutoColorsValid
}