Vixen
dd8b0a81
csharp
public sealed class UtilityGenerator

Turns the utilities a project uses into a stylesheet.

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

Remarks

Emitted into @layer utilities, and that one line is what makes the whole system behave. A generated .p-4 is one class and a hand-written .card .body is two, so on specificity alone the utility loses every time and the only remedy is !important on everything the generator produces. With a layer the question is settled once, declaratively, and specificity never enters into it.

⚠ And an @layer base, components, utilities; statement above it, which is what makes the layer worth anything. A layer only wins if something loses to it, and until the engine's own sheets moved into components nothing did: an unlayered rule beats every layer, so a control default beat every utility silently and always. The statement is also the ladder's *order*, and order is decided by whoever declares a name first — so a sheet naming only its own layer is a sheet whose position depends on load order. Every theme sheet in the tree opens with the same line for the same reason.

Only the utilities that are used are emitted. The alternative — every combination of every family and every token — is a stylesheet in the tens of megabytes, and the scanner exists so that nobody has to think about that.

Fields and properties (3)

  • public IReadOnlyList<string> Unrecognised

    The candidates that looked like utilities and were not ones.

  • public IReadOnlyList<UtilityRefusal> Unresolved

    The candidates that named a registered family and still produced no rule.

  • public int RuleCount

    How many rules the last generation emitted.

Methods (3)

  • public UtilityGenerator(ThemeTokens tokens)

    Creates a generator.

  • public string Generate(IEnumerable<string> candidates)

    Generates a stylesheet for a set of candidate class names.

  • public static string Escape(string name)

    Escapes a class name so it can be a CSS selector.

Used by (12)

  • ApplyAtInstallTestsVixen.Ui.Styling.Utilities.Tests
  • ArbitraryPropertyTestsVixen.Ui.Styling.Utilities.Tests
  • CompositionTestsVixen.Ui.Styling.Utilities.Tests
  • ShadowedFamilyTestsVixen.Ui.Styling.Utilities.Tests
  • ThemeAndScannerTestsVixen.Ui.Styling.Utilities.Tests
  • TransitionUtilityTestsVixen.Ui.Styling.Utilities.Tests
  • UtilityConsumptionProbeVixen.Ui.Styling.Utilities.Tests
  • UtilityFixtureVixen.Ui.Styling.Utilities.Tests
  • UtilityGenerationTestsVixen.Ui.Styling.Utilities.Tests
  • StyleGenRunnerVixen.StyleGen
  • StylesheetTestsVixen.Editor.Ui.Tests
  • UtilityFamilySupportTestsVixen.Editor.Ui.Tests