package tw

  1. Overview
  2. Docs

Module Tw.RuleSource

CSS rule extraction — converts Tailwind utility classes into Output.t values.

This is the bridge between the high-level utility DSL (Utility.t) and the low-level CSS output type (Output.t). For every utility class, possibly wrapped in modifiers (responsive breakpoints, pseudo-classes, dark mode, …), outputs walks the modifier stack and emits the appropriate CSS rule variant.

Typical call chain:

  Utility.t list
    |> List.concat_map Rule.outputs   (* Rule *)

    |> Build.rule_sets               (* Build *)

Rule extraction

Sourceval outputs : ?theme:Scheme.t -> ?order_tbl:(string, int * int) Hashtbl.t -> Utility.t -> Output.t list

outputs ?theme u extracts the CSS rules for utility u, reading any theme values it needs from theme (default Scheme.default).

Returns a list because a single utility can produce more than one rule — for example a container utility emits one plain rule plus one @media rule per breakpoint.

?order_tbl, when given, is populated with class name -> (priority, suborder) for each base utility encountered, reusing the class strings built here so callers need not re-derive the order from the class name.

Modifier dispatch

Lower-level entry point used when constructing rules from an already-parsed modifier/selector/props triple. Prefer outputs for normal use.

Sourceval compute_variant_order : ?theme:Scheme.t -> selector:Cascade.Css.Selector.t -> string option -> int

compute_variant_order ?theme ~selector base_class computes the sort key for modifier-prefixed rules. Returns 0 for plain rules; non-zero for rules carrying a not-* or variant prefix. selector supplies the modifiers that base_class no longer carries, and theme the variants the project declared, its breakpoints among them. Used internally by Build.

Sourceval modifier_to_rule : ?inner_has_hover:bool -> Style.modifier -> string -> Cascade.Css.Selector.t -> Cascade.Css.declaration list -> Output.t

modifier_to_rule ?inner_has_hover modifier base_class selector props wraps selector/props in the CSS construct appropriate for modifier. inner_has_hover is true when an inner modifier already carries hover semantics and the outer wrapper must therefore emit @media (hover:hover) nesting.

Class name escaping

Sourceval escape_class_name : string -> string

escape_class_name name CSS-escapes all special characters in name, e.g. escape_class_name "hover:p-4" returns "hover\\:p-4".