Skip to content

Implement comprehensive CSS filter and backdrop-filter parser with parameter support#238

Merged
yorkie merged 9 commits intomainfrom
copilot/fix-55f7f009-0df2-4c65-9409-8f53a0f80507
Aug 27, 2025
Merged

Implement comprehensive CSS filter and backdrop-filter parser with parameter support#238
yorkie merged 9 commits intomainfrom
copilot/fix-55f7f009-0df2-4c65-9409-8f53a0f80507

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 26, 2025

This PR implements a complete CSS filter parsing infrastructure for the JSAR Runtime CSSOM, addressing all TODOs and feedback from the initial implementation.

Key Improvements

🏗️ New CSS Filter Parser

Created css_filter_parser.hpp/.cpp following the existing css_transform_parser pattern:

  • Uses css_value_tokenizer for proper tokenization
  • Supports all standard CSS filter functions with parameter validation
  • Handles complex parsing scenarios like drop-shadow(16px 16px 20px blue)
  • Proper error handling and validation for length, angle, and percentage units

🎯 Enhanced Type System

Redesigned the filter class hierarchy to support parameter storage:

  • Added FilterFunctionValue struct for storing values with units
  • Enhanced GenericFilterFunction to store and serialize parameters
  • Updated filter functions to accept specific parameter types (lengths, percentages, angles)
  • Proper CSS serialization with parameters: blur(5px), brightness(150%), hue-rotate(90deg)

📋 Complete Filter Function Support

  • blur(length) - Blur effect with length parameter
  • brightness(number|percentage) - Brightness adjustment
  • contrast(number|percentage) - Contrast adjustment
  • drop-shadow(...) - Drop shadow with complex parameter parsing
  • grayscale(number|percentage) - Grayscale conversion
  • hue-rotate(angle) - Hue rotation by angle
  • invert(number|percentage) - Color inversion
  • opacity(number|percentage) - Opacity adjustment
  • saturate(number|percentage) - Saturation adjustment
  • sepia(number|percentage) - Sepia tone effect

🔄 Multi-Function Support

Now supports filter lists like blur(5px) brightness(1.2) contrast(110%) with proper parsing and CSS serialization.

Comprehensive Testing

Added extensive test coverage for:

  • Individual filter function parameter parsing
  • Multi-function filter lists
  • CSS serialization with parameters
  • Error handling for invalid inputs
  • Edge cases and default values

Usage Example

// Parse complex filter combinations
specified::Filter filter;
filter.parse("blur(5px) brightness(150%) hue-rotate(90deg)");

// Access parsed functions
const auto& functions = filter.getFunctions();
// functions[0].isBlur() == true, parameters[0] = {5.0, "px"}
// functions[1].isBrightness() == true, parameters[0] = {1.5, "%"}
// functions[2].isHueRotate() == true, parameters[0] = {90.0, "deg"}

// Generate CSS output
filter.toCss(); // Returns: "blur(5px) brightness(150%) hue-rotate(90deg)"

This implementation provides a solid foundation for CSS filter support in the JSAR Runtime, maintaining compatibility with the existing CSSOM architecture while adding comprehensive parsing and parameter handling capabilities.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits August 26, 2025 18:20
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title [WIP] Support parsing CSS properties (filter and backdrop-filter), and adding these computed values to the ComputedStyle Add CSS filter and backdrop-filter property parsing support Aug 26, 2025
Copilot AI requested a review from yorkie August 26, 2025 18:32
Copy link
Copy Markdown
Collaborator

@yorkie yorkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Please finish the TODOs that you added.

{
}

bool parse(const std::string &input) override
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Implement the parser at cssom/parsers/ and you can also use the css_value_tokenizer to get the filter function identifier and its parameters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented a comprehensive CSS filter parser at src/client/cssom/parsers/css_filter_parser.hpp and .cpp. The parser uses the css_value_tokenizer to parse filter function identifiers and their parameters, supporting all standard CSS filter functions with proper parameter validation and error handling. Commit f97c4bd.

kInvert,
kOpacity,
kSaturate,
kSepia,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot You need different class for these types with their parameters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhanced the filter class hierarchy to support different classes for each filter type with proper parameter storage. Added FilterFunctionValue struct to store parameter values with units, and updated all filter functions to support their specific parameters (lengths for blur, percentages/numbers for brightness/contrast, angles for hue-rotate, etc.). Commit f97c4bd.

if (is_none_)
return "none";

// TODO: Implement proper CSS serialization for filter functions
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement this please.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented proper CSS serialization in the toCss() method. It now correctly outputs filter functions with their parameters, such as blur(5px), brightness(1.2), hue-rotate(90deg), and supports multiple filter functions separated by spaces. The implementation handles all filter types including complex ones like drop-shadow. Commit f97c4bd.

Copilot AI and others added 2 commits August 26, 2025 19:13
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 26, 2025

@copilot Please finish the TODOs that you added.

Completed all TODOs that were added in the CSS filter implementation:

  1. ✅ Created proper CSS filter parser using css_value_tokenizer
  2. ✅ Enhanced filter classes with parameter storage for each filter type
  3. ✅ Implemented proper CSS serialization with parameters
  4. ✅ Updated specified filter classes to use the new parser
  5. ✅ Added comprehensive tests for parser functionality
  6. ✅ Fixed all formatting issues and validated with linters

The implementation now supports all standard CSS filter functions with proper parameter parsing, validation, and CSS output generation. Commit f97c4bd.

Copilot AI changed the title Add CSS filter and backdrop-filter property parsing support Implement comprehensive CSS filter and backdrop-filter parser with parameter support Aug 26, 2025
Copilot AI requested a review from yorkie August 26, 2025 19:20
@yorkie yorkie marked this pull request as ready for review August 26, 2025 23:53
@yorkie yorkie requested a review from Copilot August 27, 2025 04:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a comprehensive CSS filter and backdrop-filter parsing infrastructure for the JSAR Runtime CSSOM, addressing the need for visual effects support in the CSS parser. The implementation provides a complete type system, parser, and integration with the computed style system.

  • Introduces a new CSS filter parser with parameter support for all standard filter functions
  • Creates a type hierarchy supporting both simple and complex filter functions with proper CSS serialization
  • Integrates filter support into the computed style system with proper getter methods

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/client/css_filter_tests.cpp Comprehensive test coverage for filter parsing, conversion, and CSS output
tests/client/css_filter_parser_tests.cpp Unit tests for the low-level CSS filter parser functionality
src/client/cssom/values/specified/filter.hpp Specified filter value implementation with parsing and computed conversion
src/client/cssom/values/generics/filter.hpp Generic filter type hierarchy with parameter support and CSS serialization
src/client/cssom/values/computed/filter.hpp Computed filter value types
src/client/cssom/parsers/css_filter_parser.hpp CSS filter parser interface with tokenizer integration
src/client/cssom/parsers/css_filter_parser.cpp Complete CSS filter parser implementation
src/client/cssom/computed_style.hpp ComputedStyle integration with filter getter methods
src/client/cssom/computed_style.cpp CSS property parsing integration for filter properties

Comment thread src/client/cssom/values/specified/filter.hpp
Comment thread src/client/cssom/values/generics/filter.hpp
Comment thread src/client/cssom/computed_style.cpp Outdated
Comment thread src/client/cssom/parsers/css_filter_parser.cpp
@yorkie yorkie merged commit 04b171b into main Aug 27, 2025
2 checks passed
@yorkie yorkie deleted the copilot/fix-55f7f009-0df2-4c65-9409-8f53a0f80507 branch August 27, 2025 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants