Refactor CSS filter support check and update brightness filter parsing.

This commit is contained in:
Anton Lavrevov
2025-08-23 04:00:12 -05:00
parent 62d67e964c
commit 37213f2cc9
2 changed files with 7 additions and 11 deletions

View File

@@ -108,13 +108,7 @@ export function isCSSFiltersSupported(): boolean {
_cssFiltersSupported = false;
return false;
}
// Test if setting the filter property works
const originalFilter = ctx.filter;
ctx.filter = 'blur(1px)';
_cssFiltersSupported = ctx.filter === 'blur(1px)';
ctx.filter = originalFilter;
return _cssFiltersSupported;
return !!ctx && 'filter' in ctx;
} catch (e) {
_cssFiltersSupported = false;
return false;

View File

@@ -44,7 +44,9 @@ function parseCSSFilters(cssFilter: string): FilterFunction {
}
case 'brightness': {
const brightness = parseFloat(filterValue);
const brightness = filterValue.includes('%')
? parseFloat(filterValue) / 100
: parseFloat(filterValue);
return function (imageData) {
(this as any).brightness(brightness); // CSS uses multiplier
const KonvaFilters = (Konva as any).Filters;
@@ -694,9 +696,9 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
const fallbackRequired =
typeof filters[i] === 'string' && !isCSSFiltersSupported();
if (fallbackRequired) {
Util.warn(
`CSS filter "${filters[i]}" is not supported in native mode.`
);
// Util.warn(
// `CSS filter "${filters[i]}" is not supported in native mode.`
// );
}
if (typeof filters[i] !== 'string' || !isCSSFiltersSupported()) {
useNativeOnly = false;