Vixen
dd8b0a81
csharp
public sealed class MediaConditions

The conditional groups a stylesheet declared, as a tree of conjunctions.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

⚠ What replaced deciding @media at load, and the reason two windows of one document can now answer max-width differently. The loader used to evaluate a condition and either emit the block's rules or drop them, which put the answer in the rule set — and a rule set is shared by every surface of a document, because that is what keeps one theme across a torn-off window. So the question could only be asked once, and it was asked of the primary surface.

Now the block's rules are always emitted, each tagged with the group it came from, and the verdict is a MediaVerdicts a surface carries. The cost is one integer test per candidate rule that is in a group — Unconditional is checked first and is what every rule in every stylesheet this repository ships is — and the saving is the whole of StyleEngine.Reload on a resize: crossing a breakpoint was measured at 42 ms of ExCSS re-parsing for the editor's twelve sheets, per surface, and it also restarted every fade in the window.

⚠ A group is a conjunction and it is stored as a link to its parent rather than as a flattened condition. CSS Conditional 5 § 3 lets a conditional group rule contain another and the conditions conjoin, so @media (min-width: 640px) { @media (min-width: 900px) { … } } is two questions, not one — and 700 px answers them differently. Flattening to the outermost or to the innermost passes two of the three widths and fails the middle one. The parent link keeps both questions and evaluates them in order, which is also what makes an inner condition inside a false outer one cost one boolean test rather than an evaluation.

⚠ A condition that cannot be read never becomes a group. TryEvaluate fails only on the text — every one of its refusals names a feature, a value or a length it could not parse, and none of them consults the context it was handed — so unreadability is decided once, at load, where the diagnostic already has somewhere to go. Deferring it would mean a refusal per surface per evaluation, arriving in a list nothing drains.

Fields and properties (3)

  • public const int Unconditional

    The group a rule outside every @media belongs to, which always holds.

  • public int Count

    How many groups there are, the unconditional one included.

  • public int Revision

    Bumped whenever a group is added, so a cached evaluation can tell it is stale.

Methods (5)

  • public int Register(int within, string? condition)

    Registers a conditional group, or finds the one already registered.

  • public void Reset()

    Forgets every group, as a reload does.

  • public string ConditionOf(int group)

    The condition text a group was registered with.

  • public int EnclosingOf(int group)

    The group a group is nested in, or -1 for Unconditional.

  • public MediaVerdicts Evaluate(MediaContext context)

    Asks every group whether it holds on a surface.

Used by (5)

  • MediaScopesVixen.Ui.Styling
  • MediaVerdictsVixen.Ui.Styling
  • StyleEngineVixen.Ui.Styling
  • StyleRuleSetVixen.Ui.Styling
  • StyleSheetLoaderVixen.Ui.Styling