Module Cascade.Stylesheet_intfSource

CSS stylesheet interface types

Core Types

Import Rule

Sourcetype import_rule = {
  1. url : string;
    (*

    URL or string to import

    *)
  2. layer : string option;
    (*

    Optional layer name

    *)
  3. supports : Supports.t option;
    (*

    Optional supports condition

    *)
  4. media : Media.t option;
    (*

    Optional media query

    *)
}

A CSS \@import rule

Property Rule

Sourcetype 'a property_rule = {
  1. name : string;
  2. syntax : 'a Variables.syntax;
  3. inherits : bool;
  4. initial_value : 'a option;
}

Type-safe CSS @property rule with typed syntax and initial value

Cascade Origins

Sourcetype cascade_origin =
  1. | User_agent
  2. | User
  3. | Author_presentational_hint
  4. | Author
  5. | Animation
  6. | Transition
    (*

    Cascade origins from CSS Cascading and Inheritance. Animation and Transition represent generated virtual rules.

    *)
Sourcetype cascade_layer_candidate = {
  1. layer : string option;
    (*

    Explicit layer name, or None for the implicit unlayered layer.

    *)
  2. important : bool;
    (*

    Whether this candidate comes from an important declaration.

    *)
  3. source_order : int;
    (*

    Later source-order values win after layer precedence ties.

    *)
  4. value : string;
    (*

    Test/API payload representing the cascaded value.

    *)
}

A minimal same-origin/same-specificity cascade candidate used to model the layer and source-order parts of the cascade sorting order.

Sourcetype cascade_origin_candidate = {
  1. origin : cascade_origin;
    (*

    Origin bucket that contributes this same-property candidate.

    *)
  2. important : bool;
    (*

    Whether this candidate comes from an important declaration.

    *)
  3. source_order : int;
    (*

    Later source-order values win after origin/importance ties.

    *)
  4. value : string;
    (*

    Test/API payload representing the cascaded value.

    *)
}

A minimal same-specificity cascade candidate used to model origin, importance, and source-order sorting.

Sourcetype declared_value = {
  1. property : string;
  2. value : string;
  3. important : bool;
  4. source_order : int;
}

A declared value contributed by one property declaration before cascade sorting. The value is the declaration's minified CSS value string.

Sourcetype value_source =
  1. | Cascaded
  2. | Initial_default
  3. | Inherited_default
  4. | Initial_keyword
  5. | Inherit_keyword
  6. | Unset_initial
  7. | Unset_inherited
    (*

    Why a specified value was selected during defaulting.

    *)
Sourcetype value = {
  1. value : string;
  2. value_source : value_source;
}

Result of applying the non-layout parts of specified-value defaulting.

Sourcetype value_processing_stage =
  1. | Declared_value
  2. | Cascaded_value
  3. | Specified_value
  4. | Computed_value
  5. | Used_value
  6. | Actual_value
    (*

    CSS Cascade value-processing stages.

    *)
Sourcetype url_form =
  1. | Bare
  2. | Quoted of char

@namespace prelude URI form. CSS Namespaces 3 1: <string> and url(<string>) are spec-equivalent; url_form further distinguishes whether the url() body itself quoted its argument so the pretty-printer can round-trip the source spelling. Under --minify the printer collapses every form to the bare quoted string (the shortest spelling).

Sourcetype namespace_url =
  1. | Url of string * url_form
  2. | Quoted of string
Sourcetype cascade_candidate = {
  1. origin : cascade_origin;
  2. layer : string option;
  3. important : bool;
  4. specificity : int;
  5. scope_hops : int option;
  6. source_order : int;
  7. value : string;
}

A same-property cascade candidate covering the cascade ordering criteria this library can model without a DOM: origin/importance, layer, specificity, scoping proximity, and source order.

Basic Rules

Sourcetype rule = {
  1. selector : Selector.t;
  2. declarations : Declaration.declaration list;
  3. nested : statement list;
  4. merge_key : string option;
}

A CSS rule with a selector, declarations, optional nested rules/at-rules, and an optional merge key for combining rules with identical declarations. When merge_key is Some key, rules with the same key and identical declarations can be combined into a single rule with a selector list.

Statements and Blocks

Sourceand statement =
  1. | Rule of rule
  2. | Declarations of Declaration.declaration list
    (*

    Bare declarations for CSS nesting (no selector)

    *)
  3. | Bang_comment of string
    (*

    Preserved /*! ... */ comment (license header convention). The body excludes the surrounding /*! / */ delimiters.

    *)
  4. | Charset of string
    (*

    @charset "UTF-8";

    *)
  5. | Import of import_rule
    (*

    @import url(...) layer(...) supports(...);

    *)
  6. | Namespace of string option * namespace_url
    (*

    @namespace prefix? url;

    *)
  7. | Property : 'a property_rule -> statement
    (*

    @property --name { ... }

    *)
  8. | Layer_decl of string list
    (*

    @layer theme, base, utilities;

    *)
  9. | Layer of string option * block
    (*

    @layer name? { ... }

    *)
  10. | Media of Media.t * block
    (*

    @media (...) { ... }

    *)
  11. | Container of string option * Container.t option * block
    (*

    @container name? (...) { ... }

    *)
  12. | Supports of Supports.t * block
    (*

    @supports (...) { ... }

    *)
  13. | Moz_document of moz_document_condition list * block
    (*

    @-moz-document url-prefix(...) { ... }

    *)
  14. | Starting_style of block
    (*

    @starting-style { ... }

    *)
  15. | When of conditional * block
    (*

    @when media(...) { ... }

    *)
  16. | Else of conditional option * block
    (*

    @else supports(...)? { ... }

    *)
  17. | Supports_condition of string * Declaration.declaration list
    (*

    @supports-condition --name { ... }

    *)
  18. | Origin of cascade_origin * block
    (*

    API-level wrapper recording the cascade origin of a stylesheet block. It has no CSS surface syntax, but lets optimizers and tests preserve origin boundaries.

    *)
  19. | Scope of Selector.t option * Selector.t option * block
    (*

    @scope (start)? to (end)? { ... }

    *)
  20. | Keyframes of string * keyframe list
    (*

    @keyframes name { ... }

    *)
  21. | Webkit_keyframes of string * keyframe list
    (*

    @-webkit-keyframes name { ... }

    *)
  22. | Moz_keyframes of string * keyframe list
    (*

    @-moz-keyframes name { ... }

    *)
  23. | Font_face of font_face_descriptor list
    (*

    @font-face { ... }

    *)
  24. | Counter_style of string * counter_style_descriptor list
    (*

    @counter-style name { ... }

    *)
  25. | Page of page_selector list * Declaration.declaration list
    (*

    @page :first { ... }; empty list is a bare @page

    *)
  26. | Page_with_margins of page_selector list * page_descriptor list * page_margin_rule list
    (*

    @page :first { margin: 1cm; @top-left { content: ... } }

    *)
  27. | Font_palette_values of string * font_palette_descriptor list
    (*

    @font-palette-values --name { ... }

    *)
  28. | Font_feature_values of Properties.font_family list * font_feature_values_block list
    (*

    @font-feature-values <family-name># { @styleset { nice: 1 } }

    *)
  29. | View_transition of view_transition_descriptor list
    (*

    @view-transition { navigation: auto }

    *)
  30. | Position_try of string * Declaration.declaration list
    (*

    @position-try --name { top: anchor(...) }

    *)
  31. | Viewport of viewport_prefix * viewport_descriptor list
    (*

    @viewport { ... } / @-ms-viewport { ... } (CSS Device Adaptation 1, deprecated but still emitted by minifiers for legacy IE).

    *)
  32. | Unknown_at_rule of {
    1. name : string;
    2. prelude : string;
    3. block : string option;
    }
    (*

    CSS Syntax 3 sec. 5.4.2 "consume an at-rule" preserves any unrecognised at-rule as raw text so authors can ship unknown vendor or future at-rules without dropping the whole stylesheet.

    *)

A CSS statement - either a rule or an at-rule

Sourceand block = statement list

A block contains a list of statements

Sourceand conditional =
  1. | Media_condition of Media.t
  2. | Supports_condition_test of Supports.t
  3. | And of conditional * conditional
  4. | Or of conditional * conditional
Sourceand moz_document_condition =
  1. | Url_prefix of string option
Sourceand viewport_prefix =
  1. | Standard
  2. | Ms_prefixed
Sourceand viewport_descriptor = {
  1. name : string;
  2. value : string;
}

Raw <name>:<value> pair inside @viewport / @-ms-viewport; viewport descriptors share names with regular CSS properties (e.g., width) but take a viewport-specific value grammar that includes device-width, device-height, so they aren't typed against the property reader.

Sourceand keyframe = {
  1. selector : Keyframe.selector;
    (*

    e.g., From, To, Percent 50.

    *)
  2. declarations : Declaration.declaration list;
}

A single keyframe within \@keyframes

Sourceand page_pseudo =
  1. | First
  2. | Left
  3. | Right
  4. | Blank
Sourceand page_selector = {
  1. name : string option;
  2. pseudos : page_pseudo list;
}

@page selector: an optional page name and zero or more pseudo-pages, e.g. invoice:blank:first

Sourceand page_descriptor = Declaration.declaration
Sourceand font_palette_base =
  1. | Light
  2. | Dark
  3. | Index of int
  4. | Palette_ident of string
Sourceand font_palette_descriptor =
  1. | Palette_font_family of Properties.font_family list
  2. | Base_palette of font_palette_base
  3. | Override_colors of (int * Values.color) list
Sourceand font_feature_values_block = string * (string * int list) list
Sourceand counter_style_system =
  1. | Cyclic
  2. | Numeric
  3. | Alphabetic
  4. | Symbolic
  5. | Fixed of int option
  6. | Additive
  7. | Extends of string
Sourceand counter_style_descriptor =
  1. | System of counter_style_system
  2. | Symbols of string list
  3. | Suffix of string
  4. | Prefix of string
  5. | Fallback of string
  6. | Range of string
  7. | Pad of string
  8. | Negative of string
  9. | Additive_symbols of string
  10. | Speak_as of string
Sourceand view_transition_descriptor =
  1. | Navigation of [ `Auto | `None ]
  2. | Types of string list option
Sourceand font_variant_descriptor =
  1. | Normal
  2. | None
  3. | Values of font_variant_descriptor_value list
Sourceand font_variant_descriptor_value =
  1. | Ligature of Properties.font_variant_ligature
  2. | Caps of Properties.font_variant_caps
  3. | Numeric of Properties.font_variant_numeric_token
  4. | East_asian of Properties.east_asian_feature
Sourceand page_margin_rule = {
  1. name : string;
  2. descriptors : Declaration.declaration list;
}

CSS page margin at-rule inside @page.

Sourceand font_face_descriptor =
  1. | Font_family of Properties.font_family list
    (*

    Font family name

    *)
  2. | Src of Font_face.src
    (*

    Font source (url(), local(), etc.)

    *)
  3. | Font_style of Properties.font_style
    (*

    normal, italic, oblique

    *)
  4. | Font_style_range of Properties.font_style * Properties.font_style
    (*

    variable font style range, e.g. normal italic

    *)
  5. | Font_weight of Properties.font_weight
    (*

    normal, bold, 100-900

    *)
  6. | Font_weight_range of Properties.font_weight * Properties.font_weight
    (*

    variable font weight range, e.g. 100 900

    *)
  7. | Font_stretch of Properties.font_stretch
    (*

    normal, condensed, expanded, etc.

    *)
  8. | Font_stretch_range of string
    (*

    variable font stretch range

    *)
  9. | Font_display of Properties.font_display
    (*

    auto, block, swap, fallback, optional

    *)
  10. | Unicode_range of Properties.unicode_range list
    (*

    CSS Fonts 4 sec. 4.5 comma-separated unicode-range list.

    *)
  11. | Font_variant of font_variant_descriptor
    (*

    font-variant descriptor

    *)
  12. | Font_feature_settings of Properties.font_feature_settings
    (*

    OpenType feature settings

    *)
  13. | Font_variation_settings of Properties.font_variation_settings
    (*

    Variable font settings

    *)
  14. | Font_tech of string
    (*

    font-tech descriptor

    *)
  15. | Size_adjust of Font_face.size_adjust
    (*

    Size adjustment percentage

    *)
  16. | Ascent_override of Font_face.metric_override
    (*

    Ascent metric override

    *)
  17. | Descent_override of Font_face.metric_override
    (*

    Descent metric override

    *)
  18. | Line_gap_override of Font_face.metric_override
    (*

    Line gap metric override

    *)

Font-face descriptors per CSS Fonts spec

Stylesheet Structure

Sourcetype stylesheet = statement list

A CSS stylesheet is a list of statements

Alias for backwards compatibility

Rendering

Sourcetype mode =
  1. | Variables
  2. | Inline
    (*

    Rendering mode for CSS output

    *)
Sourceval equal_cascade_origin : cascade_origin -> cascade_origin -> bool
Sourceval equal : stylesheet -> stylesheet -> bool