Repository navigation
Closed
Description
Implement support for the CSS @property at-rule as defined by the [CSS Properties and Values API Level 1](https://www.w3.org/TR/css-properties-values-api-1/).
The @property at-rule allows authors to register CSS custom properties with additional metadata, including their expected syntax, inheritance behavior, and initial value. This enables custom properties to behave more like regular CSS properties instead of being treated as untyped token sequences.
For example:
@property --my-color {
syntax: "<color>";
inherits: false;
initial-value: #c0ffee;
}
.example {
--my-color: red;
color: var(--my-color);
}AngleSharp.Css already supports custom properties and has a parser architecture based on composable sub-parsers. This should make implementing the new at-rule relatively straightforward.
Scope
- Add parsing support for the
@propertyat-rule. - Parse and represent the following descriptors:
syntaxinheritsinitial-value
- Support the syntax definition grammar, including universal syntax (
*), alternatives (|), and multipliers (+and#). - Validate descriptor values according to the specification.
- Implement the corresponding CSSOM representation (
CSSPropertyRuleor an appropriate AngleSharp equivalent). - Integrate registered custom properties with the existing custom property handling.
- Ensure that the initial value, inheritance behavior, and syntax constraints are taken into account when processing registered custom properties.
Expected behavior
- Valid
@propertyrules are parsed and exposed through the CSSOM. - Invalid or incomplete registrations are handled according to the specification.
- Registered properties retain their declared syntax and inheritance metadata.
- Values assigned to registered custom properties are validated against their registered syntax.
- Existing unregistered custom properties continue to behave as before.
- Existing custom property parsing and serialization must not regress.
Acceptance criteria
-
@propertyis recognized as an at-rule. - All three descriptors are parsed and represented.
- Syntax definitions are parsed and validated.
- Invalid registrations are handled correctly.
- Registered custom properties participate in CSS value processing.
- Tests cover valid and invalid registrations, initial values, inheritance, and ordinary custom properties.
- Existing CSS custom property tests continue to pass.
References
- [CSS Properties and Values API Level 1](https://www.w3.org/TR/css-properties-values-api-1/)
- [MDN: @property](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@property)
- [MDN: CSS Properties and Values API](https://developer.mozilla.org/en-US/docs/Web/API/CSS_Properties_and_Values_API)
Activity
Added support for @Property #274