Skip to content

Commit d4f8b1a

Browse files
feat: add safelist support
1 parent 21a2705 commit d4f8b1a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/index.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface Options {
1717
completions?: boolean,
1818
},
1919
//
20-
safeList?: string[];
20+
safeList?: string;
2121
// bundle?: string;
2222
// debug?: boolean;
2323
// compile?: boolean;
@@ -219,6 +219,17 @@ export function windi(options: typeof OPTIONS = {}): PreprocessorGroup {
219219
if (OPTIONS.configPath) {
220220
const loadedConfig = await useConfig.load(OPTIONS.configPath)
221221
windiConfig = loadedConfig
222+
if (windiConfig.safelist) {
223+
if (typeof windiConfig.safelist == 'string') {
224+
OPTIONS.safeList = windiConfig.safelist
225+
} else {
226+
const tmpSafelist = windiConfig.safelist as (string | string[])[]
227+
// @ts-expect-error flatten on already flattened Array is fine
228+
OPTIONS.safeList = [...new Set(tmpSafelist.flat(Infinity))].join(' ')
229+
230+
}
231+
// console.log('SAFELIST', OPTIONS.safeList)
232+
}
222233
// OPTIONS.safeList = windiConfig.safelist
223234
//TODO:
224235
// if (error) useDebug.error()
@@ -276,7 +287,7 @@ export function windi(options: typeof OPTIONS = {}): PreprocessorGroup {
276287
// TODO: MARK: SAFELIST
277288
if (attributes['windi:safelist'] || attributes['windi:safelist:global']) {
278289
if (OPTIONS.safeList) {
279-
const SAFELIST = PROCESSOR.interpret(OPTIONS.safeList.join(' ')).styleSheet
290+
const SAFELIST = PROCESSOR.interpret(OPTIONS.safeList).styleSheet
280291
if (attributes['windi:safelist:global']) {
281292
SAFELIST_STYLE = globalStyleSheet(SAFELIST).build()
282293
} else {

0 commit comments

Comments
 (0)