mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-30 03:38:54 +01:00
@@ -1,3 +1,5 @@
|
|||||||
|
import { omit, kebabCase, camelCase, upperFirst } from 'lodash-es'
|
||||||
|
|
||||||
const colorsToExclude = [
|
const colorsToExclude = [
|
||||||
'inherit',
|
'inherit',
|
||||||
'transparent',
|
'transparent',
|
||||||
@@ -12,19 +14,6 @@ const colorsToExclude = [
|
|||||||
'cool'
|
'cool'
|
||||||
]
|
]
|
||||||
|
|
||||||
const omit = (obj: object, keys: string[]) => {
|
|
||||||
return Object.fromEntries(
|
|
||||||
Object.entries(obj).filter(([key]) => !keys.includes(key))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const kebabCase = (str: string) => {
|
|
||||||
return str
|
|
||||||
?.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
|
||||||
?.map(x => x.toLowerCase())
|
|
||||||
?.join('-')
|
|
||||||
}
|
|
||||||
|
|
||||||
const safelistByComponent = {
|
const safelistByComponent = {
|
||||||
alert: (colorsAsRegex) => [{
|
alert: (colorsAsRegex) => [{
|
||||||
pattern: new RegExp(`bg-(${colorsAsRegex})-50`)
|
pattern: new RegExp(`bg-(${colorsAsRegex})-50`)
|
||||||
@@ -225,7 +214,7 @@ export const generateSafelist = (colors: string[], globalColors) => {
|
|||||||
|
|
||||||
export const customSafelistExtractor = (prefix, content: string, colors: string[], safelistColors: string[]) => {
|
export const customSafelistExtractor = (prefix, content: string, colors: string[], safelistColors: string[]) => {
|
||||||
const classes = []
|
const classes = []
|
||||||
const regex = /<(\w+)\s+(?![^>]*:color\b)[^>]*\bcolor=["']([^"']+)["'][^>]*>/gs
|
const regex = /<([A-Za-z][A-Za-z0-9]*(?:-[A-Za-z][A-Za-z0-9]*)*)\s+(?![^>]*:color\b)[^>]*\bcolor=["']([^"']+)["'][^>]*>/gs
|
||||||
|
|
||||||
const matches = content.matchAll(regex)
|
const matches = content.matchAll(regex)
|
||||||
|
|
||||||
@@ -234,11 +223,13 @@ export const customSafelistExtractor = (prefix, content: string, colors: string[
|
|||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
const [, component, color] = match
|
const [, component, color] = match
|
||||||
|
|
||||||
|
const camelComponent = upperFirst(camelCase(component))
|
||||||
|
|
||||||
if (!colors.includes(color) || safelistColors.includes(color)) {
|
if (!colors.includes(color) || safelistColors.includes(color)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = safelistComponentAliasesMap[component] ? safelistComponentAliasesMap[component] : component
|
let name = safelistComponentAliasesMap[camelComponent] ? safelistComponentAliasesMap[camelComponent] : camelComponent
|
||||||
|
|
||||||
if (!components.includes(name)) {
|
if (!components.includes(name)) {
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user