Skip to content

Add the @property at-rule#212

Merged
TylerBrinks merged 1 commit into
TylerBrinks:masterfrom
jhaygood86:feature/at-property-rule
Jul 23, 2026
Merged

Add the @property at-rule#212
TylerBrinks merged 1 commit into
TylerBrinks:masterfrom
jhaygood86:feature/at-property-rule

Conversation

@jhaygood86

@jhaygood86 jhaygood86 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Feature

The @property at-rule (CSS Properties and Values API 1 §3) registers a typed custom property:

@property --my-color {
  syntax: '<color>';
  initial-value: red;
  inherits: false;
}

Implementation

  • PropertyRule — a DeclarationRule like FontFaceRule, with its Name captured from the prelude like KeyframesRule, and Syntax / InitialValue / Inherits accessors. Exposed as IPropertyRule.
  • RuleNames.Property, RuleType.Property, and the three descriptor property names.
  • PropertyFactory.CreatePropertyDescriptor — the descriptors have no fixed grammar (initial-value depends on syntax; syntax is an arbitrary string), so each is stored raw via UnknownProperty.
  • StylesheetComposer.CreateProperty and its dispatch in CreateAtRule.

The rule round-trips: @property --gap { syntax: "<length>"; initial-value: 0px; inherits: true }.

Scope: object model only, no registration/substitution

This adds the object model for the @property rule — parsing the prelude and the three descriptors into an inspectable, round-trippable IPropertyRule. It does not register the custom property or apply its syntax/initial-value/inherits semantics: nothing validates a var() substitution against the declared syntax, supplies the initial-value when a reference is invalid, or drives inheritance from inherits. Doing that is a computed-value/registered-property layer that would have to be built on top — the same substitution layer described in #211.

To be useful at all, this needs #211 (custom properties and var()): @property registers a custom property, so without custom-property/var() support there is nothing for it to describe. #211 is the foundation; this is the @property rule on top of it, and a substitution/registration layer would sit above both. (This branch already carries the one -- lexer change from #211 so it builds standalone — see Dependency below.)

If a registration/computed-value layer would be useful upstream, I'm happy to contribute one as a follow-up: this was extracted from a downstream renderer that already applies the @property descriptors (syntax-checked substitution, initial-value fallback, inheritance) on top of exactly these types, so a version that builds on this framework already exists and could be adapted.

Dependency

The --name prelude requires -- to lex as a single ident, which is the lexer fix from "Add custom properties and var()" (#211). This branch includes that one lexer change so it's self-contained; if #211 merges first, it rebases cleanly.

Tests

5 tests in AtPropertyTests.cs: name/descriptor capture, round-trip, the universal * syntax, IPropertyRule exposure, and an @property among style rules.

The full suite (1263 existing tests) stays green, and all seven target frameworks build with no new warnings.

@Property (CSS Properties and Values API 1 3) registers a typed custom
property with syntax, initial-value and inherits descriptors. Add
PropertyRule (a DeclarationRule like FontFaceRule, with a Name captured
from the prelude), IPropertyRule, RuleNames.Property, RuleType.Property,
the three descriptor names, PropertyFactory.CreatePropertyDescriptor
(storing each raw via UnknownProperty, since their values have no fixed
grammar), and StylesheetComposer.CreateProperty with its dispatch.

Includes the "--foo" lexer fix from the custom-properties change (also
submitted standalone), needed here to lex the "--name" prelude; if that
merges first, this rebases cleanly.
@jhaygood86
jhaygood86 marked this pull request as ready for review July 22, 2026 23:17
@TylerBrinks
TylerBrinks merged commit 6c22282 into TylerBrinks:master Jul 23, 2026
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.

2 participants