Skip to content

Implement CSS @property at-rule (CSS Properties and Values API) #274

Closed

Description

@FlorianRappl

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 @property at-rule.
  • Parse and represent the following descriptors:
    • syntax
    • inherits
    • initial-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 (CSSPropertyRule or 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 @property rules 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

  • @property is 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions