Skip to content

Commit

Permalink
fix :image filter support theme prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
hexart committed Feb 12, 2025
1 parent e3f49ab commit c032ec2
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,30 @@ export const generateFilterStyle = (filter?: string): string => {
'opacity': (value) => `opacity(${value})`
};

const baseFilters: string[] = [];
const lightFilters: string[] = [];
const darkFilters: string[] = [];
const filters = filter.split(' ');
const cssFilters = filters
.map(f => {
const match = f.match(/^(?:light:|dark:)?(\w+)-\[(.+?)\]$/);
if (match) {
const [_, filterName, value] = match;
const transformer = filterMap[filterName];
if (transformer) {
return transformer(value);
filters.forEach(f => {
const match = f.match(/^(light:|dark:)?(\w+)-\[(.+?)\]$/);
if (match) {
const [_, themePrefix, filterName, value] = match;
const transformer = filterMap[filterName];
if (transformer) {
const cssFilter = transformer(value);
if (themePrefix === 'dark:') {
darkFilters.push(cssFilter);
} else if (themePrefix === 'light:') {
lightFilters.push(cssFilter);
} else {
baseFilters.push(cssFilter);
}
}
return '';
})
.filter(Boolean);
}
});
const isDark = document.documentElement.classList.contains('dark');

return cssFilters.join(' ');
return (baseFilters.join(' ') + ' ' + (isDark ? darkFilters.join(' ') : lightFilters.join(' '))).trim();
};

export function hslToHex(hslStr: string): string {
Expand Down

0 comments on commit c032ec2

Please sign in to comment.