mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 02:37:59 +08:00
Refactor CSS filter support check and update brightness filter parsing.
This commit is contained in:
@@ -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;
|
||||
|
10
src/Node.ts
10
src/Node.ts
@@ -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;
|
||||
|
Reference in New Issue
Block a user