mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-30 11:47:55 +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 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 classes = []
|
||||||
const regex = /<(\w+)\s+[^>:]*color=["']([^"']+)["'][^>]*>/gs
|
const regex = /<(\w+)\s+[^>:]*color=["']([^"']+)["'][^>]*>/gs
|
||||||
const matches = [...content.matchAll(regex)]
|
const matches = [...content.matchAll(regex)]
|
||||||
@@ -125,7 +125,7 @@ export const customSafelistExtractor = (prefix, content: string) => {
|
|||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
const [, component, color] = match
|
const [, component, color] = match
|
||||||
|
|
||||||
if (colorsToExclude.includes(color)) {
|
if (!colors.includes(color)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
vue: (content) => {
|
vue: (content) => {
|
||||||
return [
|
return [
|
||||||
...defaultExtractor(content),
|
...defaultExtractor(content),
|
||||||
...customSafelistExtractor(options.prefix, content)
|
...customSafelistExtractor(options.prefix, content, nuxt.options.appConfig.ui.colors)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user