mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
fix(module): only safelist known colors
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user