fix(module): only safelist known colors

This commit is contained in:
Benjamin Canac
2023-06-13 14:52:56 +02:00
parent ccd9ca5106
commit cdce519742
2 changed files with 3 additions and 3 deletions

View File

@@ -117,7 +117,7 @@ export const excludeColors = (colors: object) => Object.keys(omit(colors, colors
export const generateSafelist = (colors: string[]) => ['avatar', 'badge', 'button', 'input', 'notification'].flatMap(component => safelistByComponent[component](colorsAsRegex(colors)))
export const customSafelistExtractor = (prefix, content: string) => {
export const customSafelistExtractor = (prefix, content: string, colors: string[]) => {
const classes = []
const regex = /<(\w+)\s+[^>:]*color=["']([^"']+)["'][^>]*>/gs
const matches = [...content.matchAll(regex)]
@@ -125,7 +125,7 @@ export const customSafelistExtractor = (prefix, content: string) => {
for (const match of matches) {
const [, component, color] = match
if (colorsToExclude.includes(color)) {
if (!colors.includes(color)) {
continue
}

View File

@@ -152,7 +152,7 @@ export default defineNuxtModule<ModuleOptions>({
vue: (content) => {
return [
...defaultExtractor(content),
...customSafelistExtractor(options.prefix, content)
...customSafelistExtractor(options.prefix, content, nuxt.options.appConfig.ui.colors)
]
}
}