package cascade

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Cascade.MediaSource

Structured media conditions for type-safe media query construction.

Sourcetype cmp =
  1. | Lt
  2. | Le
  3. | Eq
  4. | Gt
  5. | Ge
Sourcetype name =
  1. | Width
  2. | Height
  3. | Inline_size
  4. | Block_size
  5. | Aspect_ratio
  6. | Resolution
  7. | Color
  8. | Color_index
  9. | Monochrome
  10. | Grid
  11. | Horizontal_viewport_segments
  12. | Vertical_viewport_segments
  13. | Orientation
  14. | Hover
  15. | Any_hover
  16. | Pointer
  17. | Any_pointer
  18. | Update
  19. | Overflow_block
  20. | Overflow_inline
  21. | Scan
  22. | Color_gamut
  23. | Video_color_gamut
  24. | Dynamic_range
  25. | Video_dynamic_range
  26. | Display_mode
  27. | Environment_blending
  28. | Prefers_color_scheme
  29. | Prefers_reduced_motion
  30. | Prefers_reduced_transparency
  31. | Prefers_reduced_data
  32. | Prefers_contrast
  33. | Forced_colors
  34. | Inverted_colors
  35. | Nav_controls
  36. | Scripting
  37. | Min of name
  38. | Max of name
  39. | Other of string
Sourcetype ident =
  1. | Infinite
  2. | Portrait
  3. | Landscape
  4. | None
  5. | Hover
  6. | Coarse
  7. | Fine
  8. | Slow
  9. | Fast
  10. | Interlace
  11. | Progressive
  12. | Srgb
  13. | P3
  14. | Rec2020
  15. | Standard
  16. | High
  17. | Optional_paged
  18. | Paged
  19. | Scroll
  20. | Fullscreen
  21. | Standalone
  22. | Minimal_ui
  23. | Browser
  24. | Picture_in_picture
  25. | Opaque
  26. | Additive
  27. | Subtractive
  28. | Light
  29. | Dark
  30. | No_preference
  31. | Reduce
  32. | Less
  33. | More
  34. | Custom
  35. | Active
  36. | Inverted
  37. | Back
  38. | Initial_only
  39. | Enabled
  40. | Other of string
Sourcetype value =
  1. | Length of Values.length
  2. | Integer of int
  3. | Number of float
  4. | Ratio of int * int
  5. | Resolution_value of float * string
  6. | Ident of ident
  7. | Function of string * string
    (*

    env(--name) / var(...) / calc(...) etc. captured as a function name plus its raw argument body.

    *)
Sourcetype feature =
  1. | Plain of name * value
  2. | Boolean of name
  3. | Range of name * cmp * value
  4. | Range_rev of value * cmp * name
  5. | Interval of value * cmp * name * cmp * value
Sourcetype condition =
  1. | Feature of feature
  2. | Not of condition
  3. | And of condition * condition
  4. | Or of condition * condition
Sourcetype medium =
  1. | All
  2. | Screen
  3. | Print
  4. | Other of string
Sourcetype prefix =
  1. | Not
  2. | Only
Sourcetype t =
  1. | Cond of condition
  2. | Type of {
    1. prefix : prefix option;
    2. type_ : medium;
    3. trailing : condition option;
    }
  3. | List of t list
    (*

    Comma-separated media query list.

    *)
Sourceval of_string : string -> t

of_string s parses s as a media query.

Sourceval of_string_strict : string -> t

of_string_strict s parses s as a media query without branch recovery.

Sourceval of_function_body : string -> t

of_function_body s parses the body of a conditional media(...) function. Unlike a standalone media query, a single feature appears without its outer parentheses in this grammar.

Sourceval value_of_string : string -> value

value_of_string s parses s as a media-feature value.

Sourceval name_of_string : string -> name

name_of_string s parses a media feature name.

Sourceval string_of_name : name -> string

string_of_name name serializes a media feature name.

Sourceval ident_of_string : string -> ident

ident_of_string s parses a media identifier value.

Sourceval string_of_ident : ident -> string

string_of_ident ident serializes a media identifier value.

Sourceval feature : string -> value -> t

feature name v is the plain feature (name: v).

Sourceval boolean : string -> t

boolean name is the boolean feature (name).

Sourceval to_string : ?minify:bool -> t -> string

to_string ?minify t serialises t as CSS source text. The default ~minify:false keeps the pretty form ((min-width: 30em)); pass ~minify:true for the compact form ((min-width:30em)).

Sourceval pp : t Pp.t

Pretty-printer for media queries.

Sourceval lower_for_minify : t -> t

lower_for_minify t applies the target-fact grammar upgrades used under minify: min-X/max-X plain features become the range form X>=V/X<=V, and a lower bound paired with an upper bound on the same feature across an and collapses into the two-sided interval V<=name<=V.

Sourceval pp_condition : condition Pp.t

Pretty-printer for media query conditions.

Sourceval pp_feature : feature Pp.t

Pretty-printer for media features.

Sourceval compare : t -> t -> int

Total order on media queries.

Sourceval equal : t -> t -> bool

Structural equality on media queries.

Sourcetype key

A precomputed sort key for compare. Deriving the order serializes the query and re-extracts its kind, both of which allocate; a sort that compares raw queries pays that on every comparison. Precompute a key once per query with sort_key and compare with compare_keys.

Sourceval sort_key : t -> key

sort_key t precomputes the components compare derives from t.

Sourceval compare_keys : key -> key -> int

compare_keys k1 k2 orders two queries by their precomputed keys, with no allocation. compare_keys (sort_key a) (sort_key b) = compare a b.

Sourceval sort_by : ('a -> t) -> 'a list -> 'a list

sort_by project items orders items by the media query project returns for each, serializing each query exactly once. Sorting this way, rather than with List.sort (fun a b -> compare (project a) (project b)), is the point of sort_key: the comparator form re-derives and re-serializes a query on every comparison, which a sort does O(n log n) times. The sort is stable.

Sourcetype kind =
  1. | Hover
  2. | Responsive of int * float
  3. | Responsive_max of int * float
  4. | Preference_accessibility
  5. | Preference_appearance
  6. | Other
Sourceval kind : t -> kind

kind t classifies t for grouping and ordering.

Sourceval group_order : kind -> int * float

group_order k is the sort key used to group queries by kind.

Sourceval preference_order : t -> int

preference_order t orders preference queries within their group.