Parsers
1 CSS
1.1 Overview
1.2 Quick Start
1.3 Cookbook
1.3.1 Rename A Class
1.3.2 Scope A Stylesheet
1.3.3 Rename A Custom Property
1.3.4 Rewrite URLs
1.3.5 Wrap Matching Rules In @media
1.3.6 Split Grouped Selectors
1.3.7 Remove Duplicate Declarations
1.3.8 Inspect Selector Pseudos
1.4 Core Model
1.5 Parsing
1.6 Serialization
1.7 Query Helpers
1.7.1 Choosing Helpers
1.7.2 Reduced Computed Style
1.8 Rewrite Helpers
1.9 Derived Structures
1.10 Limitations
1.11 Reference
1.11.1 Parsing and Serialization
current-css-standard
make-css-parser
parse-css
parse-stylesheet
serialize-stylesheet
serialize-stylesheet/  normalized
serialize-css
1.11.2 Rewrite Reference
css-map-declarations
css-map-rules
css-map-at-rules
css-map-selectors
css-map-declarations-in-selectors
css-update-declaration-values
css-update-declaration-values/  preserve-source
css-remove-declarations
css-remove-declarations/  preserve-source
css-append-declaration
css-append-declaration/  preserve-source
css-append-declaration-by-pseudo
css-append-declaration-by-pseudo/  preserve-source
css-append-declaration-by-class
css-append-declaration-by-class/  preserve-source
css-append-declaration-by-attribute
css-append-declaration-by-attribute/  preserve-source
css-rename-class
css-prefix-selectors
css-rewrite-media-queries
css-rewrite-supports-conditions
css-rewrite-custom-properties
css-split-grouped-selectors
css-clone-rule
css-insert-rule-before
css-insert-rule-after
css-remove-rules
css-remove-at-rules
css-wrap-rules-in-media
css-wrap-rules-in-supports
css-merge-adjacent-rules
css-dedupe-declarations
css-sort-declarations
css-rename-custom-property
css-rewrite-var-functions
css-rename-keyframes
css-rewrite-imports
css-rewrite-font-face
css-rewrite-url-values
css-filter-comments
css-hoist-nested-rules
css-lower-nesting
css-rewrite-attribute-selectors
css-rewrite-pseudos
css-rewrite-selector-structure
css-update-declaration-values-in-media-feature
css-update-declaration-values-in-media-feature/  preserve-source
css-remove-declarations-in-media-feature
css-remove-declarations-in-media-feature/  preserve-source
css-update-declaration-values-in-supports-feature
css-update-declaration-values-in-supports-feature/  preserve-source
css-remove-declarations-in-supports-feature
css-remove-declarations-in-supports-feature/  preserve-source
1.11.3 Core AST And Derived Reference
css-stylesheet?
css-stylesheet-rules
css-stylesheet-source
css-stylesheet-span
css-source-span?
css-source-span-start
css-source-span-end
css-comment?
css-comment-text
css-comment-span
css-recovery?
css-recovery-kind
css-recovery-reason
css-recovery-text
css-recovery-span
css-recovery-detail
css-style-rule?
css-style-rule-selector-groups
css-style-rule-selectors
css-selector?
css-selector-text
css-selector-span
css-selector-parts
css-selector-compounds
css-selector-compound?
css-selector-compound-items
css-selector-compound-span
css-selector-combinator?
css-selector-combinator-text
css-selector-combinator-span
css-selector-type?
css-selector-type-name
css-selector-type-span
css-selector-namespaced-type?
css-selector-namespaced-type-namespace
css-selector-namespaced-type-name
css-selector-namespaced-type-span
css-selector-class?
css-selector-class-name
css-selector-class-span
css-selector-id?
css-selector-id-name
css-selector-id-span
css-selector-attribute?
css-selector-attribute-name
css-selector-attribute-matcher
css-selector-attribute-value
css-selector-attribute-modifier
css-selector-attribute-text
css-selector-attribute-span
css-selector-attribute-derived-details
css-selector-attribute-details?
css-selector-attribute-details-namespace
css-selector-attribute-details-name
css-selector-attribute-details-matcher
css-selector-attribute-details-value
css-selector-attribute-details-modifier
css-selector-attribute-details-text
css-selector-attribute-details-span
css-selector-attribute-identifier-value?
css-selector-attribute-identifier-value-text
css-selector-attribute-identifier-value-value
css-selector-attribute-identifier-value-span
css-selector-attribute-string-value?
css-selector-attribute-string-value-text
css-selector-attribute-string-value-value
css-selector-attribute-string-value-span
css-selector-pseudo?
css-selector-pseudo-name
css-selector-pseudo-element?
css-selector-pseudo-text
css-selector-pseudo-span
css-selector-pseudo-arguments
css-selector-pseudo-argument-structure
css-selector-pseudo-selector-list?
css-selector-pseudo-value-list?
css-selector-pseudo-nth-arguments?
css-selector-pseudo-selector-list-selectors
css-selector-pseudo-selector-list-text
css-selector-pseudo-selector-list-span
css-selector-pseudo-value-list-values
css-selector-pseudo-value-list-text
css-selector-pseudo-value-list-span
css-selector-pseudo-nth-arguments-formula
css-selector-pseudo-nth-arguments-selectors
css-selector-pseudo-nth-arguments-text
css-selector-pseudo-nth-arguments-span
css-selector-pseudo-identifier-list?
css-selector-pseudo-identifier-list-values
css-selector-pseudo-identifier-list-text
css-selector-pseudo-identifier-list-span
css-selector-pseudo-identifier?
css-selector-pseudo-identifier-text
css-selector-pseudo-identifier-value
css-selector-pseudo-identifier-span
css-selector-universal?
css-selector-universal-text
css-selector-universal-span
css-selector-namespaced-universal?
css-selector-namespaced-universal-namespace
css-selector-namespaced-universal-text
css-selector-namespaced-universal-span
css-style-rule-block
css-style-rule-raw-selector
css-style-rule-span
css-at-rule?
css-at-rule-name
css-at-rule-prelude
css-at-rule-prelude-values
css-at-rule-prelude-derived-details
css-media-prelude-details?
css-media-prelude-details-queries
css-media-prelude-details-text
css-media-prelude-details-span
css-media-query?
css-media-query-modifier
css-media-query-media-type
css-media-query-features
css-media-query-text
css-media-query-span
css-media-feature?
css-media-feature-text
css-media-feature-span
css-media-feature-expression?
css-media-feature-expression-name
css-media-feature-expression-operator
css-media-feature-expression-value
css-media-feature-expression-text
css-media-feature-expression-span
css-media-feature-range?
css-media-feature-range-name
css-media-feature-range-lower
css-media-feature-range-lower-operator
css-media-feature-range-upper-operator
css-media-feature-range-upper
css-media-feature-range-text
css-media-feature-range-span
css-supports-prelude-details?
css-supports-prelude-details-conditions
css-supports-prelude-details-text
css-supports-prelude-details-span
css-supports-condition?
css-supports-condition-kind
css-supports-condition-text
css-supports-condition-arguments
css-supports-condition-span
css-supports-feature?
css-supports-feature-name
css-supports-feature-value
css-supports-feature-text
css-supports-feature-span
css-at-rule-block
css-at-rule-span
css-declaration?
css-declaration-name
css-declaration-value
css-declaration-component-values
css-declaration-important?
css-declaration-span
css-qualified-rule?
css-qualified-rule-prelude
css-qualified-rule-block
css-component-token?
css-component-token-text
css-component-token-span
css-component-an-plus-b?
css-component-an-plus-b-text
css-component-an-plus-b-a
css-component-an-plus-b-b
css-component-an-plus-b-span
css-component-number?
css-component-number-text
css-component-number-value
css-component-number-span
css-component-percentage?
css-component-percentage-text
css-component-percentage-value
css-component-percentage-span
css-component-dimension?
css-component-dimension-text
css-component-dimension-value
css-component-dimension-unit
css-component-dimension-span
css-component-string?
css-component-string-text
css-component-string-value
css-component-string-span
css-component-hash?
css-component-hash-text
css-component-hash-value
css-component-hash-span
css-component-url?
css-component-url-text
css-component-url-value
css-component-url-span
css-component-function?
css-component-function-name
css-component-function-arguments
css-component-function-text
css-component-function-span
css-component-block?
css-component-block-delimiter
css-component-block-values
css-component-block-text
css-component-block-span
1.11.4 Query And Recovery Reference
css-flatten-rules
css-find-rules-by-selector-group
css-find-rules-by-raw-selector
css-find-declarations-in-selector-group
css-find-declarations-in-selector-groups
css-collect-custom-properties-in-selector-group
css-collect-custom-properties-in-selector-groups
css-compute-style-for-selector-group
css-compute-custom-properties-for-selector-group
css-compute-style-trace?
css-compute-style-trace-selector-group
css-compute-style-trace-matched-rules
css-compute-style-trace-property-results
css-compute-style-trace-custom-property-results
css-compute-style-trace-var-resolutions
css-compute-matched-rule?
css-compute-matched-rule-selector-group
css-compute-matched-rule-specificity
css-compute-matched-rule-source-order
css-compute-matched-rule-rule
css-compute-property-result?
css-compute-property-result-name
css-compute-property-result-candidates
css-compute-property-result-winner
css-compute-candidate?
css-compute-candidate-name
css-compute-candidate-value
css-compute-candidate-important?
css-compute-candidate-specificity
css-compute-candidate-source-order
css-compute-candidate-declaration
css-compute-candidate-matched-rule
css-compute-candidate-source-name
css-compute-var-resolution?
css-compute-var-resolution-name
css-compute-var-resolution-raw-value
css-compute-var-resolution-resolved-value
css-compute-var-resolution-references
css-compute-var-resolution-cycle?
css-find-declarations
css-query-selector
css-find-rules-by-pseudo
css-find-media-queries
css-find-supports-features
css-recovery-nodes
css-has-recovery?
css-recovery-summary
1.11.5 Error Reference
exn:  fail:  css?
exn:  fail:  css-source
exn:  fail:  css-detail
1.11.6 Parser Procedure Reference
css-parser?
9.2

Parsers🔗ℹ

Jens Axel Søgaard <jensaxel@soegaard.net>

Note: The parsers library and documentation were written with the help of Codex.

The parsers package is a collection of reusable parsers. This first release provides a CSS parser and a few CSS tools for inspection and rewriting.

The manual is organized by language. Future parsers will get their own chapters; the CSS chapter below documents the current public API.

    1 CSS

      1.1 Overview

      1.2 Quick Start

      1.3 Cookbook

        1.3.1 Rename A Class

        1.3.2 Scope A Stylesheet

        1.3.3 Rename A Custom Property

        1.3.4 Rewrite URLs

        1.3.5 Wrap Matching Rules In @media

        1.3.6 Split Grouped Selectors

        1.3.7 Remove Duplicate Declarations

        1.3.8 Inspect Selector Pseudos

      1.4 Core Model

      1.5 Parsing

      1.6 Serialization

      1.7 Query Helpers

        1.7.1 Choosing Helpers

        1.7.2 Reduced Computed Style

      1.8 Rewrite Helpers

      1.9 Derived Structures

      1.10 Limitations

      1.11 Reference

        1.11.1 Parsing and Serialization

        1.11.2 Rewrite Reference

        1.11.3 Core AST And Derived Reference

        1.11.4 Query And Recovery Reference

        1.11.5 Error Reference

        1.11.6 Parser Procedure Reference

1 CSS🔗ℹ

 (require parsers/css) package: parsers-lib

CSS is the stylesheet language used to describe the presentation of HTML and other structured documents, including layout, colors, typography, and responsive styling.

This CSS parser and rewrite library is intended for tooling-oriented use cases such as selector inspection, declaration lookup, cascade-oriented analysis, source-preserving edits, and later higher-level transforms.

1.1 Overview🔗ℹ

The public CSS entry point is parsers/css. It is intended to track the modern CSS standard over time. If fixed compatibility targets become useful later, they can be added as separate module paths.

The CSS library is built around five layers:

  • Parsing: raw CSS source becomes a stylesheet AST.

  • Derived views: selectors, values, and some at-rule preludes can be inspected through richer helper APIs without changing the underlying AST.

  • Queries: common lookups such as “find declarations”, “find rules by pseudo”, or “find supports features”.

  • Reduced computed style: exact-target winner selection and limited shorthand expansion for tooling that needs final values without a browser engine.

  • Rewrites: normalized AST rewrites plus a smaller source-preserving rewrite layer for targeted declaration/block edits.

The parser is intentionally not a browser engine, layout engine, or full CSS semantic validator. It parses structure faithfully enough for tooling and rewriting, and keeps semantic interpretation layered on top.

1.2 Quick Start🔗ℹ

Install the package with raco pkg install parsers, then require the CSS module:

(require parsers/css)

For most users, the workflow is:

  • parse a stylesheet with parse-css

  • inspect rules, declarations, and derived selector/value structure

  • optionally apply rewrites

  • serialize back to CSS with serialize-stylesheet

Examples:
> (define stylesheet
    (parse-css ".card, .panel { color: red; }"))
> (css-stylesheet? stylesheet)

#t

> (map css-style-rule-selector-groups (css-stylesheet-rules stylesheet))

'((".card" ".panel"))

> (map css-declaration-value
       (css-find-declarations-in-selector-group stylesheet ".card" "color"))

'("red")

> (serialize-stylesheet
   (css-rename-class stylesheet "card" "tile"))

".tile, .panel { color: red; }"

To parse a file, pass an input port:

(define stylesheet
  (call-with-input-file "site.css" parse-css))

Malformed input is recorded with recovery nodes when the parser can continue:

Examples:
> (define recovered
    (parse-css ".ok { color: red; }\n.bad { color }\n.next { color: blue; }"))
> (css-has-recovery? recovered)

#t

> (length (css-recovery-nodes recovered))

1

1.3 Cookbook🔗ℹ

This section is intended to give a taste of what can be done with the parsed stylesheet. See the full reference later for details.

1.3.1 Rename A Class🔗ℹ

This example renames .card to .tile.

Examples:
> (define rename-class-input
    ".card:hover, .card .title { color: red; }")
> (define rename-class-output
    (serialize-stylesheet
     (css-rename-class
      (parse-css rename-class-input)
      "card"
      "tile")))
> rename-class-input

".card:hover, .card .title { color: red; }"

> rename-class-output

".tile:hover, .tile .title { color: red; }"

1.3.2 Scope A Stylesheet🔗ℹ

This example prefixes every selector with .scope.

Examples:
> (define scope-input
    "body { color: red; }")
> (define scope-output
    (serialize-stylesheet
     (css-prefix-selectors
      (parse-css scope-input)
      ".scope")))
> scope-input

"body { color: red; }"

> scope-output

".scope body { color: red; }"

1.3.3 Rename A Custom Property🔗ℹ

This example renames brand to accent in both declaration names and var(...) references.

Examples:
> (define custom-property-input
    ":root { --brand: red; color: var(--brand); }")
> (define custom-property-output
    (serialize-stylesheet
     (css-rename-custom-property
      (parse-css custom-property-input)
      "--brand"
      "--accent")))
> custom-property-input

":root { --brand: red; color: var(--brand); }"

> custom-property-output

":root { --accent: red; color: var(--accent); }"

1.3.4 Rewrite URLs🔗ℹ

This example rewrites both declaration and @import URLs.

Examples:
> (define rewrite-url-input
    "body { background: url(\"a.png\"); }\n@import url(\"b.css\") screen;")
> (define rewrite-url-output
    (serialize-stylesheet
     (css-rewrite-url-values
      (parse-css rewrite-url-input)
      (lambda (inner)
        (cond
          [(equal? inner "\"a.png\"") "\"c.png\""]
          [(equal? inner "\"b.css\"") "\"d.css\""]
          [else inner])))))
> rewrite-url-input

"body { background: url(\"a.png\"); }\n@import url(\"b.css\") screen;"

> rewrite-url-output

"body { background: url(\"c.png\"); }\n@import url(\"d.css\") screen;"

1.3.5 Wrap Matching Rules In @media🔗ℹ

This example wraps the body rule in a new @media block.

Examples:
> (define wrap-media-input
    "body { color: red; }")
> (define wrap-media-output
    (serialize-stylesheet
     (css-wrap-rules-in-media
      (parse-css wrap-media-input)
      "body"
      "screen")))
> wrap-media-input

"body { color: red; }"

> wrap-media-output

"@media screen { body { color: red; } }"

1.3.6 Split Grouped Selectors🔗ℹ

This example splits one grouped rule into two separate rules.

Examples:
> (define split-selectors-input
    ".a, .b { background: rgb(1 2 3); }")
> (define split-selectors-output
    (serialize-stylesheet
     (css-split-grouped-selectors
      (parse-css split-selectors-input))))
> split-selectors-input

".a, .b { background: rgb(1 2 3); }"

> split-selectors-output

".a { background: rgb(1 2 3); }\n.b { background: rgb(1 2 3); }"

1.3.7 Remove Duplicate Declarations🔗ℹ

This example keeps the last duplicate declaration in the rule.

Examples:
> (define dedupe-input
    "body { color: red; color: blue; margin: 0; }")
> (define dedupe-output
    (serialize-stylesheet
     (css-dedupe-declarations
      (parse-css dedupe-input))))
> dedupe-input

"body { color: red; color: blue; margin: 0; }"

> dedupe-output

"body { color: blue; margin: 0; }"

1.3.8 Inspect Selector Pseudos🔗ℹ

This example finds rules that use the pseudo selector :not.

Examples:
> (define pseudo-input
    "a:not(.x, #y) > span:nth-child(2n+1) { color: red; }")
> (define pseudo-stylesheet
    (parse-css pseudo-input))
> (define pseudo-rules
    (css-find-rules-by-pseudo pseudo-stylesheet "not"))
> pseudo-input

"a:not(.x, #y) > span:nth-child(2n+1) { color: red; }"

> (length pseudo-rules)

1

> (map css-style-rule-selector-groups pseudo-rules)

'(("a:not(.x, #y) > span:nth-child(2n+1)"))

1.4 Core Model🔗ℹ

The parser returns a small explicit AST:

The AST is intentionally simpler than a browser’s internal model. Raw selector text, declaration values, source order, comments, and recovery information are preserved first; richer interpretation is exposed through helper APIs rather than forced into the base tree.

The public module exports predicates and accessors for AST values returned by the parser. It does not export the core AST constructors as the primary editing interface. For edits, prefer the rewrite helpers; when a helper asks for a replacement rule node, a common pattern is to parse a small CSS snippet and extract the rule from the resulting stylesheet.

Examples:
> (define replacement-rule
    (car (css-stylesheet-rules
          (parse-css ".notice { color: blue; }"))))
> (css-style-rule? replacement-rule)

#t

1.5 Parsing🔗ℹ

The parser currently handles a substantial structural subset of modern CSS, including style rules, grouped selectors, declarations, comments, and common at-rules such as @media, @supports, @import, @font-face, and @keyframes.

Internally it uses:

  • lexers/css as the tokenizer source

  • a handwritten structural reader for rules, at-rules, blocks, and declarations

  • derived selector/value/media/supports helpers layered on top of the raw AST

Malformed input is handled with recovery nodes where possible, so tooling can keep working on imperfect stylesheets instead of failing hard on the first error.

As a release target, the parser aims to preserve useful structure rather than prove that every value is semantically valid CSS:

  • Generally supported: stylesheets, style rules, grouped selectors, declarations, comments, common rule-bearing at-rules, @import, @font-face, and @keyframes.

  • Derived support: selector parts, component values, selected @media preludes, and selected @supports conditions.

  • Recovered: malformed statements and declarations when the parser can skip the fragment and continue.

  • Out of scope: browser validation, DOM matching, layout, inheritance, media-environment simulation, and framework-specific behavior.

1.6 Serialization🔗ℹ

There are two main serialization modes:

  • normalized: serialize the AST with consistent spacing

  • source-preserving: when the stylesheet still carries original source text and the operation did not invalidate it, return that original text instead

Most normalized AST rewrites clear the preserved source string intentionally. The smaller source-preserving rewrite family edits source slices directly and then reparses the result.

1.7 Query Helpers🔗ℹ

Query helpers sit above the raw AST and derived structures. They are intended for common tooling tasks such as:

  • iterating rules in source order

  • finding declarations by property

  • matching exact selector groups or exact raw selector text

  • querying selectors or pseudos

  • computing reduced exact-target style and custom-property environments

  • collecting derived @media and @supports information

  • inspecting parser recovery output

1.7.1 Choosing Helpers🔗ℹ

The helper families intentionally sit at different levels:

1.7.2 Reduced Computed Style🔗ℹ

The library also includes a small computed-style layer for tooling use cases. It is deliberately narrow:

  • exact selector-group matching only

  • cascade winner selection by !important, specificity, and source order

  • limited shorthand expansion for border, border-top, border-right, border-bottom, border-left, padding, and margin

  • optional var(...) resolution against computed custom properties and caller-supplied defaults

  • optional trace output so downstream tools can inspect why a value won

This is useful for stylesheet inspection tools, but it is not a browser engine. In particular, it does not do general selector matching, inheritance, DOM simulation, media-environment evaluation, or layout.

Exact matching means that .btn and .btn:hover are different selector-group targets. Nested rule-bearing at-rules such as @media are included by structural flattening, but their conditions are not evaluated.

Examples:
> (define exact-style
    (parse-css
     (string-append
      ".btn:hover { color: red; }\n"
      ".btn { color: blue; }\n"
      "@media screen { .btn { color: green; } }")))
> (length (css-find-rules-by-selector-group exact-style ".btn"))

2

> (length (css-find-rules-by-selector-group exact-style ".btn:hover"))

1

> (hash-ref (css-compute-style-for-selector-group exact-style ".btn")
            "color"
            #f)

"green"

Custom properties can be returned as their own exact-target environment, and standard properties can optionally resolve var(...) references through that environment and caller-supplied defaults.

Examples:
> (define computed-style
    (parse-css
     (string-append
      ".btn { --accent: steelblue; color: var(--accent); padding: 1px 2px; }\n"
      ".fallback { color: var(--missing); }")))
> (hash-ref (css-compute-custom-properties-for-selector-group
             computed-style
             ".btn"
             #:resolve-vars? #t)
            "--accent"
            #f)

"steelblue"

> (hash-ref (css-compute-style-for-selector-group
             computed-style
             ".btn"
             #:resolve-vars? #t)
            "color"
            #f)

"steelblue"

> (hash-ref (css-compute-style-for-selector-group
             computed-style
             ".btn")
            "padding-left"
            #f)

"2px"

> (hash-ref (css-compute-style-for-selector-group
             computed-style
             ".fallback"
             #:resolve-vars? #t
             #:defaults (hash "--missing" "royalblue"))
            "color"
            #f)

"royalblue"

When #:trace? is true, the computed-style helpers return two values: the computed hash and an inspectable css-compute-style-trace? payload.

Examples:
> (define-values (style trace)
    (css-compute-style-for-selector-group
     computed-style
     ".btn"
     #:resolve-vars? #t
     #:trace? #t))
> (css-compute-style-trace? trace)

#t

> (length (css-compute-style-trace-matched-rules trace))

1

> (hash-ref style "color" #f)

"steelblue"

1.8 Rewrite Helpers🔗ℹ

The rewrite layer is broad enough now to support many PostCSS-style workflows.

PostCSS is a JavaScript-based CSS transformation ecosystem built around plugins that parse CSS, transform an AST, and serialize the result again. The rewrite helpers here aim to support many of the same kinds of transformations, but in Racket and with this library’s AST model.

It currently includes:

  • declaration rewrites and removals

  • selector rewrites, including class renaming and selector prefixing

  • at-rule prelude rewrites for @media, @supports, and @import

  • rule insertion, removal, cloning, wrapping, splitting, and merging

  • custom-property, URL, keyframes, comment, and nesting-oriented helpers

  • source-preserving declaration/block edits for targeted cases

The important design distinction is that some helpers are fully AST-based, while others still operate on preserved raw selector or prelude text. The reference section calls that out where it matters.

1.9 Derived Structures🔗ℹ

The raw AST keeps selectors and many values as preserved text. Richer structure is available through helper APIs:

  • selector parts, compounds, pseudos, attributes, and namespace-aware forms

  • component values such as numbers, percentages, dimensions, strings, hashes, URLs, functions, and blocks

  • derived @media query structures

  • derived @supports condition structures

This layered approach keeps the parser reusable: consumers can stay close to the raw source when they need fidelity, or opt into richer interpretation when they need convenience.

1.10 Limitations🔗ℹ

Current limitations worth knowing up front:

  • This is not a CSS engine or full semantic validator.

  • Some rewrite helpers still work at the raw-text level for selectors or preludes, because there is not yet a full selector serializer.

  • Source-preserving rewrites exist for targeted declaration/block edits, not for every normalized transform.

  • Nesting helpers operate on nested AST structure; they do not magically infer arbitrary future syntax beyond what the parser has represented.

  • The computed-style helpers use an exact selector-group model; they do not match selectors against a DOM tree.

1.11 Reference🔗ℹ

The remainder of this chapter is the API reference.

1.11.1 Parsing and Serialization🔗ℹ

The standard tag used by parsers/css. The current public parser target is 'current.

procedure

(make-css-parser [#:standard standard])

  (input-port? . -> . css-stylesheet?)
  standard : symbol? = current-css-standard
Constructs a port-based CSS parser.

The result is a procedure of one argument, an input port. The intended use is to create the parser and apply it to a port containing a complete stylesheet.

The parser handles stylesheets with style rules, grouped selectors, declarations, comments, recovery nodes, and common at-rules.

Example:

procedure

(parse-css source)  css-stylesheet?

  source : (or/c string? input-port?)
Parses CSS from a string or input port.

This is the convenience entry point for most consumers. It accepts either a complete stylesheet string or an input port and uses the current CSS standard target.

The parser supports style rules, grouped selectors, declarations, comments, recovery nodes for malformed fragments, and the outer structure of common at-rules such as @media, @supports, @import, @font-face, and @keyframes.

Examples:
> (define stylesheet
    (parse-css "body { color: red; }"))
> (css-stylesheet? stylesheet)

#t

procedure

(parse-stylesheet source)  css-stylesheet?

  source : (or/c string? input-port?)
Alias for parse-css.

procedure

(serialize-stylesheet stylesheet 
  [#:preserve-source? preserve-source?]) 
  string?
  stylesheet : css-stylesheet?
  preserve-source? : boolean? = #f
Serializes a stylesheet AST back to CSS text.

When preserve-source? is true and the stylesheet still carries its original source string, the serializer returns that original source. Otherwise it produces normalized output from the AST.

Example:
> (serialize-stylesheet (parse-css "body { color: red; }") #:preserve-source? #t)

"body { color: red; }"

procedure

(serialize-stylesheet/normalized stylesheet)  string?

  stylesheet : css-stylesheet?
Serializes a stylesheet AST using normalized spacing regardless of any preserved source text.

Comments, declarations, style rules, and the currently supported at-rules are preserved structurally.

Example:
> (serialize-stylesheet/normalized (parse-css "body { color: red; }"))

"body { color: red; }"

procedure

(serialize-css stylesheet)  string?

  stylesheet : css-stylesheet?

1.11.2 Rewrite Reference🔗ℹ

procedure

(css-map-declarations stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : 
(-> css-declaration?
    (or/c css-declaration? #f))
Rewrites declarations throughout a stylesheet.

The procedure receives each css-declaration? node and should return either a replacement declaration or #f to remove it. The returned stylesheet clears its preserved source string, since the original source is no longer an exact representation of the modified AST.

procedure

(css-map-rules stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : 
(-> css-style-rule?
    (or/c css-style-rule?
          (listof css-style-rule?)
          #f))
Rewrites each css-style-rule? in the stylesheet. The procedure may return one replacement rule, a list of replacement rules, or #f to remove the rule.

procedure

(css-map-at-rules stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : 
(-> css-at-rule?
    (or/c css-at-rule?
          (listof css-at-rule?)
          #f))
Rewrites each css-at-rule? in the stylesheet. The procedure may return one replacement at-rule, a list of replacement at-rules, or #f to remove the rule.

procedure

(css-map-selectors stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : (-> string? string?)
Rewrites each selector-group string in every style rule. The procedure receives one selector-group string and must return a replacement string.

procedure

(css-map-declarations-in-selectors stylesheet 
  selector-group 
  proc) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  selector-group : string?
  proc : 
(-> css-declaration?
    (or/c css-declaration? #f))
Rewrites declarations only inside style rules whose selector groups include selector-group exactly.

procedure

(css-update-declaration-values stylesheet    
  name    
  updater)  css-stylesheet?
  stylesheet : css-stylesheet?
  name : string?
  updater : (-> string? string?)
Updates declaration values for property names that match name case-insensitively. The updater is called with the raw declaration value string and should return a replacement string.

procedure

(css-update-declaration-values/preserve-source stylesheet 
  name 
  updater) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  name : string?
  updater : (-> string? string?)
Updates declaration values like css-update-declaration-values, but preserves untouched source text when the stylesheet still has original source and the targeted declarations have source spans.

The touched declaration text is rewritten in place and the result is reparsed, so unchanged formatting and comments elsewhere remain intact.

procedure

(css-remove-declarations stylesheet name)  css-stylesheet?

  stylesheet : css-stylesheet?
  name : string?
Removes declarations whose property name matches name case-insensitively.

procedure

(css-remove-declarations/preserve-source stylesheet 
  name) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  name : string?
Removes declarations like css-remove-declarations, but preserves untouched source text when possible by editing the original source string in place and reparsing it.

procedure

(css-append-declaration stylesheet 
  selector-group 
  name 
  value 
  [#:important? important?]) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  selector-group : string?
  name : string?
  value : string?
  important? : boolean? = #f
Appends a declaration to each style rule whose selector groups include selector-group exactly.

procedure

(css-append-declaration/preserve-source 
  stylesheet 
  selector-group 
  name 
  value 
  [#:important? important?]) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  selector-group : string?
  name : string?
  value : string?
  important? : boolean? = #f
Appends a declaration like css-append-declaration, but preserves untouched source text when the stylesheet still has original source and the matched style rules have source spans.

The new declaration text is inserted directly into each matched rule block and the result is reparsed, so unchanged formatting and comments elsewhere remain intact.

procedure

(css-append-declaration-by-pseudo stylesheet 
  pseudo-name 
  name 
  value 
  [#:important? important?]) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  pseudo-name : string?
  name : string?
  value : string?
  important? : boolean? = #f
Appends a declaration to each style rule whose derived selector structure uses the pseudo selector named by pseudo-name.

procedure

(css-append-declaration-by-pseudo/preserve-source 
  stylesheet 
  pseudo-name 
  name 
  value 
  [#:important? important?]) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  pseudo-name : string?
  name : string?
  value : string?
  important? : boolean? = #f
Appends a declaration like css-append-declaration-by-pseudo, but preserves untouched source text when possible by inserting the new declaration directly into each matched rule block and reparsing the edited source.

procedure

(css-append-declaration-by-class stylesheet 
  class-name 
  name 
  value 
  [#:important? important?]) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  class-name : string?
  name : string?
  value : string?
  important? : boolean? = #f
Appends a declaration to each style rule whose derived selector structure uses the class selector named by class-name.

procedure

(css-append-declaration-by-class/preserve-source 
  stylesheet 
  class-name 
  name 
  value 
  [#:important? important?]) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  class-name : string?
  name : string?
  value : string?
  important? : boolean? = #f
Appends a declaration like css-append-declaration-by-class, but preserves untouched source text when possible by inserting the new declaration directly into each matched rule block and reparsing the edited source.

procedure

(css-append-declaration-by-attribute stylesheet 
  attribute-name 
  name 
  value 
  [#:important? important?]) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  attribute-name : string?
  name : string?
  value : string?
  important? : boolean? = #f
Appends a declaration to each style rule whose derived selector structure uses an attribute selector named by attribute-name.

procedure

(css-append-declaration-by-attribute/preserve-source 
  stylesheet 
  attribute-name 
  name 
  value 
  [#:important? important?]) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  attribute-name : string?
  name : string?
  value : string?
  important? : boolean? = #f
Appends a declaration like css-append-declaration-by-attribute, but preserves untouched source text when possible by inserting the new declaration directly into each matched rule block and reparsing the edited source.

procedure

(css-rename-class stylesheet    
  old-name    
  new-name)  css-stylesheet?
  stylesheet : css-stylesheet?
  old-name : string?
  new-name : string?
Renames one class selector throughout the stylesheet.

procedure

(css-prefix-selectors stylesheet prefix)  css-stylesheet?

  stylesheet : css-stylesheet?
  prefix : string?
Prefixes each selector group with prefix.

procedure

(css-rewrite-media-queries stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : 
(-> string?
    css-media-prelude-details?
    string?)
Rewrites @media preludes. The procedure receives the raw prelude string and its derived details, and must return a replacement prelude string.

procedure

(css-rewrite-supports-conditions stylesheet    
  proc)  css-stylesheet?
  stylesheet : css-stylesheet?
  proc : 
(-> string?
    css-supports-prelude-details?
    string?)
Rewrites @supports preludes. The procedure receives the raw prelude string and its derived details, and must return a replacement prelude string.

procedure

(css-rewrite-custom-properties stylesheet    
  proc)  css-stylesheet?
  stylesheet : css-stylesheet?
  proc : (-> string? string?)
Rewrites custom-property names in both declaration names and var(...) references. The procedure receives one custom-property name such as "--brand" and must return a replacement name.

procedure

(css-split-grouped-selectors stylesheet)  css-stylesheet?

  stylesheet : css-stylesheet?
Splits grouped selector rules into separate style rules, one per selector group.

procedure

(css-clone-rule stylesheet    
  selector-group    
  [#:transform proc])  css-stylesheet?
  stylesheet : css-stylesheet?
  selector-group : string?
  proc : (-> css-style-rule? css-style-rule?) = values
Clones each style rule whose selector groups include selector-group. The optional transform procedure receives the matched rule and must return the clone to insert immediately after it.

procedure

(css-insert-rule-before stylesheet    
  selector-group    
  new-rule)  css-stylesheet?
  stylesheet : css-stylesheet?
  selector-group : string?
  new-rule : css-style-rule?
Inserts new-rule before each style rule whose selector groups include selector-group.

procedure

(css-insert-rule-after stylesheet    
  selector-group    
  new-rule)  css-stylesheet?
  stylesheet : css-stylesheet?
  selector-group : string?
  new-rule : css-style-rule?
Inserts new-rule after each style rule whose selector groups include selector-group.

procedure

(css-remove-rules stylesheet pred?)  css-stylesheet?

  stylesheet : css-stylesheet?
  pred? : (-> css-style-rule? boolean?)
Removes style rules for which pred? returns true.

procedure

(css-remove-at-rules stylesheet pred?)  css-stylesheet?

  stylesheet : css-stylesheet?
  pred? : (-> css-at-rule? boolean?)
Removes at-rules for which pred? returns true.

procedure

(css-wrap-rules-in-media stylesheet    
  selector-group    
  prelude)  css-stylesheet?
  stylesheet : css-stylesheet?
  selector-group : string?
  prelude : string?
Wraps matching style rules in a new @media rule.

procedure

(css-wrap-rules-in-supports stylesheet    
  selector-group    
  prelude)  css-stylesheet?
  stylesheet : css-stylesheet?
  selector-group : string?
  prelude : string?
Wraps matching style rules in a new @supports rule.

procedure

(css-merge-adjacent-rules stylesheet)  css-stylesheet?

  stylesheet : css-stylesheet?
Merges adjacent compatible style rules and adjacent compatible at-rules.

procedure

(css-dedupe-declarations stylesheet    
  [#:keep keep])  css-stylesheet?
  stylesheet : css-stylesheet?
  keep : (or/c 'first 'last) = 'last
Removes duplicate declarations within each style rule, keeping either the first or last occurrence.

procedure

(css-sort-declarations stylesheet    
  [#:less-than less-than])  css-stylesheet?
  stylesheet : css-stylesheet?
  less-than : (-> string? string? boolean?) = string<?
Sorts declarations within each style rule using the given comparator on declaration names.

procedure

(css-rename-custom-property stylesheet    
  old-name    
  new-name)  css-stylesheet?
  stylesheet : css-stylesheet?
  old-name : string?
  new-name : string?
Renames one custom property in both declaration names and var(...) references.

procedure

(css-rewrite-var-functions stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : (-> string? string?)
Rewrites custom-property names only in var(...) references.

procedure

(css-rename-keyframes stylesheet    
  old-name    
  new-name)  css-stylesheet?
  stylesheet : css-stylesheet?
  old-name : string?
  new-name : string?
Renames one @keyframes identifier and matching animation references.

procedure

(css-rewrite-imports stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : (-> string? string?)
Rewrites @import preludes using a callback over the raw prelude string.

procedure

(css-rewrite-font-face stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : 
(-> css-declaration?
    (or/c css-declaration? #f))
Rewrites declarations inside @font-face blocks.

procedure

(css-rewrite-url-values stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : (-> string? string?)
Rewrites url(...) inner text in declarations and at-rule preludes.

procedure

(css-filter-comments stylesheet pred?)  css-stylesheet?

  stylesheet : css-stylesheet?
  pred? : (-> css-comment? boolean?)
Keeps only comments for which pred? returns true.

procedure

(css-hoist-nested-rules stylesheet)  css-stylesheet?

  stylesheet : css-stylesheet?
Hoists nested style rules into flat rule lists by combining selectors.

procedure

(css-lower-nesting stylesheet)  css-stylesheet?

  stylesheet : css-stylesheet?
Lowers nesting by hoisting nested rules into flat rule lists.

procedure

(css-rewrite-attribute-selectors stylesheet    
  proc)  css-stylesheet?
  stylesheet : css-stylesheet?
  proc : (-> string? string?)
Rewrites raw attribute-selector text inside selector groups.

procedure

(css-rewrite-pseudos stylesheet proc)  css-stylesheet?

  stylesheet : css-stylesheet?
  proc : (-> string? string?)
Rewrites raw pseudo-selector text inside selector groups.

procedure

(css-rewrite-selector-structure stylesheet    
  proc)  css-stylesheet?
  stylesheet : css-stylesheet?
  proc : (-> string? css-selector? string?)
Rewrites selector groups using both the raw selector-group string and the derived selector structure for that group.

procedure

(css-update-declaration-values-in-media-feature stylesheet 
  feature-name 
  property-name 
  updater) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  feature-name : string?
  property-name : string?
  updater : (-> string? string?)
Updates declaration values only inside @media rules whose derived feature set includes feature-name.

procedure

(css-update-declaration-values-in-media-feature/preserve-source 
  stylesheet 
  feature-name 
  property-name 
  updater) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  feature-name : string?
  property-name : string?
  updater : (-> string? string?)
Updates declaration values like css-update-declaration-values-in-media-feature, but preserves untouched source text when possible by editing the original source string in place and reparsing it.

procedure

(css-remove-declarations-in-media-feature stylesheet 
  feature-name 
  property-name) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  feature-name : string?
  property-name : string?
Removes declarations only inside @media rules whose derived feature set includes feature-name.

procedure

(css-remove-declarations-in-media-feature/preserve-source 
  stylesheet 
  feature-name 
  property-name) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  feature-name : string?
  property-name : string?
Removes declarations like css-remove-declarations-in-media-feature, but preserves untouched source text when possible by editing the original source string in place and reparsing it.

procedure

(css-update-declaration-values-in-supports-feature 
  stylesheet 
  feature-name 
  property-name 
  updater) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  feature-name : string?
  property-name : string?
  updater : (-> string? string?)
Updates declaration values only inside @supports rules whose derived feature tests include feature-name.

procedure

(css-update-declaration-values-in-supports-feature/preserve-source 
  stylesheet 
  feature-name 
  property-name 
  updater) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  feature-name : string?
  property-name : string?
  updater : (-> string? string?)
Updates declaration values like css-update-declaration-values-in-supports-feature, but preserves untouched source text when possible by editing the original source string in place and reparsing it.

procedure

(css-remove-declarations-in-supports-feature stylesheet 
  feature-name 
  property-name) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  feature-name : string?
  property-name : string?
Removes declarations only inside @supports rules whose derived feature tests include feature-name.

procedure

(css-remove-declarations-in-supports-feature/preserve-source 
  stylesheet 
  feature-name 
  property-name) 
  css-stylesheet?
  stylesheet : css-stylesheet?
  feature-name : string?
  property-name : string?
Removes declarations like css-remove-declarations-in-supports-feature, but preserves untouched source text when possible by editing the original source string in place and reparsing it.

1.11.3 Core AST And Derived Reference🔗ℹ

The parser is intended to return explicit AST nodes instead of ad hoc maps or lists.

The core AST forms are:

Derived helper APIs provide richer selector, component-value, media-query, and supports-condition structures when consumers need more detail.

struct

(struct css-stylesheet (rules source span)
    #:transparent)
  rules : 
(listof (or/c css-style-rule?
               css-at-rule?
               css-comment?
               css-recovery?))
  source : (or/c string? #f)
  span : (or/c css-source-span? #f)
Represents a complete stylesheet.

The rules field contains the top-level stylesheet nodes in source order. The source field contains the original stylesheet text when it is available; source-preserving serializers and rewrites use this value. The span field records the source extent of the stylesheet when available.

struct

(struct css-style-rule (selector-groups block raw-selector span)
    #:transparent)
  selector-groups : (listof string?)
  block : 
(listof (or/c css-declaration?
               css-comment?
               css-recovery?
               css-style-rule?
               css-at-rule?))
  raw-selector : string?
  span : (or/c css-source-span? #f)
Represents an ordinary CSS style rule.

The selector-groups field contains the comma-separated selector groups as exact source-text strings, with surrounding selector whitespace trimmed. The block field contains the rule body in source order: declarations, comments, recovery nodes, and any nested rule-bearing nodes the parser represented structurally. The raw-selector field preserves the full selector prelude text before the block. The span field records the rule source extent when available.

struct

(struct css-at-rule (name prelude block span)
    #:transparent)
  name : string?
  prelude : string?
  block : 
(or/c (listof (or/c css-style-rule?
                     css-at-rule?
                     css-declaration?
                     css-comment?
                     css-recovery?))
      #f)
  span : (or/c css-source-span? #f)
Represents an at-rule such as @media, @supports, @import, @font-face, or @keyframes.

The name field contains the at-keyword, including the leading @. The prelude field contains the raw prelude text between the at-rule name and the terminating semicolon or block. The block field contains the at-rule body in source order, or #f for at-rules without a block. The span field records the at-rule source extent when available.

struct

(struct css-declaration (name value important? span)
    #:transparent)
  name : string?
  value : string?
  important? : boolean?
  span : (or/c css-source-span? #f)
Represents a CSS declaration.

The name field contains the property name exactly as parsed. The value field contains the raw declaration value text, excluding the property name, colon, semicolon, and trailing !important marker. The important? field records whether the declaration was marked !important. The span field records the declaration source extent when available.

struct

(struct css-comment (text span)
    #:transparent)
  text : string?
  span : (or/c css-source-span? #f)
Represents a preserved CSS comment.

The text field contains the raw comment text, including the /* ... */ delimiters. The span field records the comment source extent when available.

struct

(struct css-recovery (kind reason text span detail)
    #:transparent)
  kind : symbol?
  reason : string?
  text : string?
  span : (or/c css-source-span? #f)
  detail : any/c
Represents a malformed source fragment that the parser skipped while recovering and continuing with the surrounding stylesheet.

The kind field classifies the skipped fragment, for example 'statement or 'declaration. The reason field contains a human-readable parse error message. The text field contains the raw skipped source text. The span field records the skipped source extent when available. The detail field contains parser-specific diagnostic data for tools that want more context.

struct

(struct css-source-span (start end)
    #:transparent)
  start : any/c
  end : any/c
Represents a source extent.

The start and end fields mark the beginning and end of a source range. In parsed stylesheets these are parser-tools position values; some tests and manually constructed ASTs use exact nonnegative offsets. Treat the values as source-location data rather than CSS syntax.

struct

(struct css-qualified-rule (prelude block)
    #:transparent)
  prelude : list?
  block : list?
Represents a generic qualified rule.

The prelude field contains the component-value prelude before the block. The block field contains the rule body representation. Most tooling should prefer the more specific css-style-rule struct when working with ordinary style rules.

procedure

(css-stylesheet? v)  boolean?

  v : any/c
Recognizes stylesheet AST nodes.

procedure

(css-stylesheet-rules stylesheet)

  
(listof (or/c css-style-rule?
              css-at-rule?
              css-comment?
              css-recovery?))
  stylesheet : css-stylesheet?
Returns the stylesheet’s rule list.

procedure

(css-stylesheet-source stylesheet)  (or/c string? #f)

  stylesheet : css-stylesheet?
Returns the original source associated with the stylesheet when available.

procedure

(css-stylesheet-span stylesheet)  (or/c css-source-span? #f)

  stylesheet : css-stylesheet?
Returns the stylesheet source span when available.

procedure

(css-source-span? v)  boolean?

  v : any/c
Recognizes source span values.

procedure

(css-source-span-start span)  any/c

  span : css-source-span?
Returns the start source-location value of a source span. Parsed stylesheets use parser-tools position values; manually constructed spans may use exact nonnegative offsets.

procedure

(css-source-span-end span)  any/c

  span : css-source-span?
Returns the end source-location value of a source span. Parsed stylesheets use parser-tools position values; manually constructed spans may use exact nonnegative offsets.

procedure

(css-comment? v)  boolean?

  v : any/c
Recognizes comment AST nodes.

procedure

(css-comment-text comment)  string?

  comment : css-comment?
Returns the raw comment text.

procedure

(css-comment-span comment)  (or/c css-source-span? #f)

  comment : css-comment?
Returns the source span for a comment when available.

procedure

(css-recovery? v)  boolean?

  v : any/c
Recognizes recovery AST nodes emitted when the parser skips a malformed fragment but continues parsing the surrounding stylesheet.

procedure

(css-recovery-kind recovery)  symbol?

  recovery : css-recovery?
Returns the recovery kind, such as 'statement or 'declaration.

procedure

(css-recovery-reason recovery)  string?

  recovery : css-recovery?
Returns the parse error message that triggered recovery.

procedure

(css-recovery-text recovery)  string?

  recovery : css-recovery?
Returns the raw source text that was skipped during recovery.

procedure

(css-recovery-span recovery)  (or/c css-source-span? #f)

  recovery : css-recovery?
Returns the source span for the skipped fragment when available.

procedure

(css-recovery-detail recovery)  any/c

  recovery : css-recovery?
Returns parser-specific recovery detail, typically derived from the underlying parse error.

procedure

(css-style-rule? v)  boolean?

  v : any/c
Recognizes style-rule AST nodes.

procedure

(css-style-rule-selector-groups rule)  (listof string?)

  rule : css-style-rule?
Returns the selector-group representation for a style rule.

procedure

(css-style-rule-selectors rule)  (listof css-selector?)

  rule : css-style-rule?
Returns selector nodes derived from the rule’s selector groups.

procedure

(css-selector? v)  boolean?

  v : any/c
Recognizes selector nodes.

procedure

(css-selector-text selector)  string?

  selector : css-selector?
Returns the selector text.

procedure

(css-selector-span selector)  (or/c css-source-span? #f)

  selector : css-selector?
Returns the selector span when available.

procedure

(css-selector-parts selector)

  
(listof (or/c css-selector-type?
              css-selector-namespaced-type?
              css-selector-class?
              css-selector-id?
              css-selector-attribute?
              css-selector-pseudo?
              css-selector-universal?
              css-selector-namespaced-universal?
              css-selector-combinator?))
  selector : css-selector?
Returns the derived selector parts for one selector group.

procedure

(css-selector-compounds selector)

  
(listof (or/c css-selector-compound?
              css-selector-combinator?))
  selector : css-selector?
Returns compound-selector groupings derived from one selector group.

procedure

(css-selector-compound? v)  boolean?

  v : any/c
Recognizes compound selector nodes.

procedure

(css-selector-compound-items compound)  list?

  compound : css-selector-compound?
Returns the selector parts in a compound selector.

procedure

(css-selector-compound-span compound)

  (or/c css-source-span? #f)
  compound : css-selector-compound?
Returns the source span for a compound selector when available.

procedure

(css-selector-combinator? v)  boolean?

  v : any/c
Recognizes selector combinator nodes.

procedure

(css-selector-combinator-text combinator)  string?

  combinator : css-selector-combinator?
Returns the combinator text, such as >, +, ~, or a space.

procedure

(css-selector-combinator-span combinator)

  (or/c css-source-span? #f)
  combinator : css-selector-combinator?
Returns the source span for a combinator when available.

procedure

(css-selector-type? v)  boolean?

  v : any/c
Recognizes type selector nodes.

procedure

(css-selector-type-name selector)  string?

  selector : css-selector-type?
Returns the type selector name.

procedure

(css-selector-type-span selector)  (or/c css-source-span? #f)

  selector : css-selector-type?
Returns the source span for a type selector when available.

procedure

(css-selector-namespaced-type? v)  boolean?

  v : any/c
Recognizes namespace-qualified type selector nodes such as svg|rect.

Returns the namespace prefix for a namespace-qualified type selector.

Returns the local type name for a namespace-qualified type selector.

procedure

(css-selector-namespaced-type-span selector)

  (or/c css-source-span? #f)
  selector : css-selector-namespaced-type?
Returns the source span for a namespace-qualified type selector when available.

procedure

(css-selector-class? v)  boolean?

  v : any/c
Recognizes class selector nodes.

procedure

(css-selector-class-name selector)  string?

  selector : css-selector-class?
Returns the class name without the leading dot.

procedure

(css-selector-class-span selector)  (or/c css-source-span? #f)

  selector : css-selector-class?
Returns the source span for a class selector when available.

procedure

(css-selector-id? v)  boolean?

  v : any/c
Recognizes id selector nodes.

procedure

(css-selector-id-name selector)  string?

  selector : css-selector-id?
Returns the ID name without the leading hash.

procedure

(css-selector-id-span selector)  (or/c css-source-span? #f)

  selector : css-selector-id?
Returns the source span for an ID selector when available.

procedure

(css-selector-attribute? v)  boolean?

  v : any/c
Recognizes attribute selector nodes.

procedure

(css-selector-attribute-name attribute)  string?

  attribute : css-selector-attribute?
Returns the raw attribute name text.

procedure

(css-selector-attribute-matcher attribute)  (or/c string? #f)

  attribute : css-selector-attribute?
Returns the attribute matcher, such as =, ~=, or ^=, when one is present.

procedure

(css-selector-attribute-value attribute)  (or/c string? #f)

  attribute : css-selector-attribute?
Returns the raw attribute value text when one is present.

procedure

(css-selector-attribute-modifier attribute)  (or/c string? #f)

  attribute : css-selector-attribute?
Returns the attribute selector modifier, such as i or s, when one is present.

procedure

(css-selector-attribute-text attribute)  string?

  attribute : css-selector-attribute?
Returns the full raw attribute selector text.

procedure

(css-selector-attribute-span attribute)

  (or/c css-source-span? #f)
  attribute : css-selector-attribute?
Returns the source span for an attribute selector when available.

Returns a derived structured view of an attribute selector.

This is the preferred accessor when you want namespace-aware attribute names or typed attribute values instead of manually interpreting the raw string fields.

procedure

(css-selector-attribute-details? v)  boolean?

  v : any/c
Recognizes derived attribute-detail nodes.

procedure

(css-selector-attribute-details-namespace details)

  (or/c string? #f)
  details : css-selector-attribute-details?
Returns the optional namespace prefix for an attribute selector, such as foo in [foo|href=button].

Returns the local attribute name.

procedure

(css-selector-attribute-details-matcher details)

  (or/c string? #f)
  details : css-selector-attribute-details?
Returns the attribute matcher when one is present.

Returns the typed attribute value when one is present.

procedure

(css-selector-attribute-details-modifier details)

  (or/c string? #f)
  details : css-selector-attribute-details?
Returns the attribute selector modifier when one is present.

Returns the full raw attribute selector text.

procedure

(css-selector-attribute-details-span details)

  (or/c css-source-span? #f)
  details : css-selector-attribute-details?
Returns the source span for derived attribute details when available.

procedure

(css-selector-attribute-identifier-value? v)  boolean?

  v : any/c
Recognizes identifier-valued attribute selectors such as [href=button].

Returns the raw identifier value text.

Returns the decoded identifier value.

Returns the source span for an identifier attribute value when available.

procedure

(css-selector-attribute-string-value? v)  boolean?

  v : any/c
Recognizes string-valued attribute selectors such as [href=\"button\"].

Returns the raw string value text, including quotes.

Returns the decoded string value.

Returns the source span for a string attribute value when available.

procedure

(css-selector-pseudo? v)  boolean?

  v : any/c
Recognizes pseudo-class and pseudo-element selector nodes.

procedure

(css-selector-pseudo-name pseudo)  string?

  pseudo : css-selector-pseudo?
Returns the pseudo selector name without leading colon characters.

procedure

(css-selector-pseudo-element? pseudo)  boolean?

  pseudo : css-selector-pseudo?
Reports whether the pseudo selector was written as a pseudo-element.

procedure

(css-selector-pseudo-text pseudo)  string?

  pseudo : css-selector-pseudo?
Returns the full raw pseudo selector text.

procedure

(css-selector-pseudo-span pseudo)  (or/c css-source-span? #f)

  pseudo : css-selector-pseudo?
Returns the source span for a pseudo selector when available.

For selector-like functional pseudos such as :not(...), :is(...), :where(...), and :has(...), the pseudo arguments are exposed as derived selector nodes. For other functional pseudos, the arguments remain component-value nodes.

procedure

(css-selector-pseudo-arguments pseudo)  list?

  pseudo : css-selector-pseudo?
Returns the backward-compatible flat argument list for a pseudo selector.

For selector-list pseudos this is a list of css-selector? values. For value-oriented pseudos this is a list of component-value nodes.

Returns the explicit pseudo-argument wrapper when one is available.

This is the preferred way to distinguish selector-list pseudos from value-oriented pseudos without inspecting the raw argument list by hand.

procedure

(css-selector-pseudo-selector-list? v)  boolean?

  v : any/c
Recognizes explicit selector-list pseudo arguments.

procedure

(css-selector-pseudo-value-list? v)  boolean?

  v : any/c
Recognizes explicit component-value pseudo arguments.

procedure

(css-selector-pseudo-nth-arguments? v)  boolean?

  v : any/c
Recognizes explicit nth-* pseudo arguments, including an optional of selector clause.

Returns the parsed selector arguments for a selector-list pseudo.

Returns the raw selector-list argument text.

Returns the source span for selector-list pseudo arguments when available.

Returns the parsed component-value arguments for a value-oriented pseudo.

Returns the raw component-value argument text.

Returns the source span for value-list pseudo arguments when available.

For the nth-* family, an+b arguments such as 2n+1, odd, and -n+6 are exposed as typed css-component-an-plus-b? nodes through css-selector-pseudo-nth-arguments?.

Returns the parsed an+b formula portion for an nth-* pseudo.

Returns the parsed selector list from an optional of clause.

For example, :nth-child(2n+1 of .item, #main) exposes .item and #main here.

Returns the raw nth-* argument text.

Returns the source span for nth-* arguments when available.

procedure

(css-selector-pseudo-identifier-list? v)  boolean?

  v : any/c
Recognizes identifier-like pseudo arguments such as those used by :lang(...) and :dir(...).

Returns the identifier argument nodes.

Returns the raw identifier-list argument text.

Returns the source span for identifier-list pseudo arguments when available.

procedure

(css-selector-pseudo-identifier? v)  boolean?

  v : any/c
Recognizes one identifier-like pseudo argument.

Returns the raw identifier argument text.

Returns the identifier-like pseudo argument text, such as en-US or rtl.

Returns the source span for an identifier pseudo argument when available.

procedure

(css-selector-universal? v)  boolean?

  v : any/c
Recognizes universal selector nodes.

procedure

(css-selector-universal-text selector)  string?

  selector : css-selector-universal?
Returns the raw universal selector text.

procedure

(css-selector-universal-span selector)

  (or/c css-source-span? #f)
  selector : css-selector-universal?
Returns the source span for a universal selector when available.

procedure

(css-selector-namespaced-universal? v)  boolean?

  v : any/c
Recognizes namespace-qualified universal selector nodes such as *|* or foo|*.

Returns the namespace prefix for a namespace-qualified universal selector.

Returns the raw namespace-qualified universal selector text.

Returns the source span for a namespace-qualified universal selector when available.

procedure

(css-style-rule-block rule)  
(listof (or/c css-declaration?
              css-comment?
              css-recovery?
              css-style-rule?
              css-at-rule?))
  rule : css-style-rule?
Returns the rule block.

procedure

(css-style-rule-raw-selector rule)  string?

  rule : css-style-rule?
Returns the raw selector text preserved by the style rule.

procedure

(css-style-rule-span rule)  (or/c css-source-span? #f)

  rule : css-style-rule?
Returns the source span for a style rule when available.

procedure

(css-at-rule? v)  boolean?

  v : any/c
Recognizes at-rule AST nodes.

procedure

(css-at-rule-name rule)  string?

  rule : css-at-rule?
Returns the at-rule name, such as "@media".

procedure

(css-at-rule-prelude rule)  string?

  rule : css-at-rule?
Returns the at-rule prelude representation.

procedure

(css-at-rule-prelude-values rule)

  
(listof (or/c css-component-token?
              css-component-an-plus-b?
              css-component-number?
              css-component-percentage?
              css-component-dimension?
              css-component-string?
              css-component-hash?
              css-component-url?
              css-component-function?
              css-component-block?))
  rule : css-at-rule?
Returns a lightweight component-value view of the at-rule prelude.

Returns a richer derived prelude view for recognized at-rules.

Currently this provides structured results for @media and @supports; other at-rules fall back to the lightweight component-value list.

procedure

(css-media-prelude-details? v)  boolean?

  v : any/c
Recognizes derived @media prelude nodes.

procedure

(css-media-prelude-details-queries details)

  (listof css-media-query?)
  details : css-media-prelude-details?
Returns the derived media queries in a @media prelude.

procedure

(css-media-prelude-details-text details)  string?

  details : css-media-prelude-details?
Returns the raw @media prelude text.

procedure

(css-media-prelude-details-span details)

  (or/c css-source-span? #f)
  details : css-media-prelude-details?
Returns the source span for derived media prelude details when available.

procedure

(css-media-query? v)  boolean?

  v : any/c
Recognizes one derived media query entry.

procedure

(css-media-query-modifier query)  (or/c string? #f)

  query : css-media-query?
Returns the media query modifier, such as not or only, when one is present.

procedure

(css-media-query-media-type query)  (or/c string? #f)

  query : css-media-query?
Returns the media type, such as screen, when one is present.

procedure

(css-media-query-features query)

  
(listof (or/c css-media-feature?
              css-media-feature-expression?
              css-media-feature-range?))
  query : css-media-query?
Returns the media feature fragments in the query.

procedure

(css-media-query-text query)  string?

  query : css-media-query?
Returns the raw media query text.

procedure

(css-media-query-span query)  (or/c css-source-span? #f)

  query : css-media-query?
Returns the source span for a media query when available.

procedure

(css-media-feature? v)  boolean?

  v : any/c
Recognizes one derived media feature fragment such as (width >= 40rem).

procedure

(css-media-feature-text feature)  string?

  feature : css-media-feature?
Returns the raw media feature text.

procedure

(css-media-feature-span feature)  (or/c css-source-span? #f)

  feature : css-media-feature?
Returns the source span for a media feature when available.

procedure

(css-media-feature-expression? v)  boolean?

  v : any/c
Recognizes a typed media feature expression such as (width >= 40rem) or (prefers-color-scheme: dark).

Returns the media feature name.

Returns the comparison operator, such as : or >=.

Returns the raw media feature value text.

Returns the raw media feature expression text.

procedure

(css-media-feature-expression-span feature)

  (or/c css-source-span? #f)
  feature : css-media-feature-expression?
Returns the source span for a media feature expression when available.

procedure

(css-media-feature-range? v)  boolean?

  v : any/c
Recognizes a typed chained media range such as (20rem <= width <= 60rem).

procedure

(css-media-feature-range-name feature)  string?

  feature : css-media-feature-range?
Returns the media feature name for a chained range.

procedure

(css-media-feature-range-lower feature)  string?

  feature : css-media-feature-range?
Returns the lower bound text for a chained range.

Returns the lower comparison operator for a chained range.

Returns the upper comparison operator for a chained range.

procedure

(css-media-feature-range-upper feature)  string?

  feature : css-media-feature-range?
Returns the upper bound text for a chained range.

procedure

(css-media-feature-range-text feature)  string?

  feature : css-media-feature-range?
Returns the raw chained range text.

procedure

(css-media-feature-range-span feature)

  (or/c css-source-span? #f)
  feature : css-media-feature-range?
Returns the source span for a chained media range when available.

procedure

(css-supports-prelude-details? v)  boolean?

  v : any/c
Recognizes derived @supports prelude nodes.

Returns the top-level derived supports conditions.

Returns the raw @supports prelude text.

procedure

(css-supports-prelude-details-span details)

  (or/c css-source-span? #f)
  details : css-supports-prelude-details?
Returns the source span for derived supports prelude details when available.

procedure

(css-supports-condition? v)  boolean?

  v : any/c
Recognizes one derived supports-condition node.

The current condition kinds include 'feature, 'not, 'and, 'or, and 'unknown.

procedure

(css-supports-condition-kind condition)  symbol?

  condition : css-supports-condition?
Returns the condition kind, such as 'feature, 'not, 'and, 'or, or 'unknown.

procedure

(css-supports-condition-text condition)  string?

  condition : css-supports-condition?
Returns the raw supports condition text.

procedure

(css-supports-condition-arguments condition)  list?

  condition : css-supports-condition?
Returns child conditions or feature nodes for this supports condition.

procedure

(css-supports-condition-span condition)

  (or/c css-source-span? #f)
  condition : css-supports-condition?
Returns the source span for a supports condition when available.

procedure

(css-supports-feature? v)  boolean?

  v : any/c
Recognizes one typed supports feature test such as (display: grid).

procedure

(css-supports-feature-name feature)  string?

  feature : css-supports-feature?
Returns the feature-test name, such as display.

procedure

(css-supports-feature-value feature)  string?

  feature : css-supports-feature?
Returns the raw feature-test value text, such as grid.

procedure

(css-supports-feature-text feature)  string?

  feature : css-supports-feature?
Returns the raw supports feature-test text.

procedure

(css-supports-feature-span feature)

  (or/c css-source-span? #f)
  feature : css-supports-feature?
Returns the source span for a supports feature when available.

procedure

(css-at-rule-block rule)

  
(or/c (listof (or/c css-style-rule?
                     css-at-rule?
                     css-declaration?
                     css-comment?
                     css-recovery?))
      #f)
  rule : css-at-rule?
Returns the at-rule body or block representation.

procedure

(css-at-rule-span rule)  (or/c css-source-span? #f)

  rule : css-at-rule?
Returns the source span for an at-rule when available.

procedure

(css-declaration? v)  boolean?

  v : any/c
Recognizes declaration AST nodes.

procedure

(css-declaration-name declaration)  string?

  declaration : css-declaration?
Returns the declaration property name.

procedure

(css-declaration-value declaration)  string?

  declaration : css-declaration?
Returns the declaration value representation.

procedure

(css-declaration-component-values declaration)

  
(listof (or/c css-component-token?
              css-component-an-plus-b?
              css-component-number?
              css-component-percentage?
              css-component-dimension?
              css-component-string?
              css-component-hash?
              css-component-url?
              css-component-function?
              css-component-block?))
  declaration : css-declaration?
Returns a lightweight component-value view of the declaration value.

procedure

(css-declaration-important? declaration)  boolean?

  declaration : css-declaration?
Reports whether the declaration is marked important.

procedure

(css-declaration-span declaration)  (or/c css-source-span? #f)

  declaration : css-declaration?
Returns the source span for a declaration when available.

procedure

(css-qualified-rule? v)  boolean?

  v : any/c
Recognizes qualified-rule AST nodes.

procedure

(css-qualified-rule-prelude rule)  list?

  rule : css-qualified-rule?
Returns the rule prelude.

procedure

(css-qualified-rule-block rule)  list?

  rule : css-qualified-rule?
Returns the block part of a qualified rule.

procedure

(css-component-token? v)  boolean?

  v : any/c
Recognizes simple component token nodes.

procedure

(css-component-token-text token)  string?

  token : css-component-token?
Returns the raw component token text.

procedure

(css-component-token-span token)  (or/c css-source-span? #f)

  token : css-component-token?
Returns the source span for a component token when available.

procedure

(css-component-an-plus-b? v)  boolean?

  v : any/c
Recognizes parsed an+b component nodes used by the nth-* pseudos.

Returns the raw an+b text.

Returns the a coefficient from an an+b node.

Returns the b offset from an an+b node.

Returns the source span for an an+b component when available.

procedure

(css-component-number? v)  boolean?

  v : any/c
Recognizes numeric component nodes.

Returns the raw number text.

Returns the parsed numeric value.

procedure

(css-component-number-span v)  (or/c css-source-span? #f)

  v : css-component-number?
Returns the source span for a number component when available.

procedure

(css-component-percentage? v)  boolean?

  v : any/c
Recognizes percentage component nodes.

Returns the raw percentage text.

Returns the parsed percentage number without the trailing percent sign.

Returns the source span for a percentage component when available.

procedure

(css-component-dimension? v)  boolean?

  v : any/c
Recognizes dimension component nodes such as 10px.

Returns the raw dimension text.

Returns the parsed numeric value of a dimension.

Returns the dimension unit text, such as px or rem.

Returns the source span for a dimension component when available.

procedure

(css-component-string? v)  boolean?

  v : any/c
Recognizes string component nodes.

Returns the raw string token text, including quotes.

Returns the decoded string value.

procedure

(css-component-string-span v)  (or/c css-source-span? #f)

  v : css-component-string?
Returns the source span for a string component when available.

procedure

(css-component-hash? v)  boolean?

  v : any/c
Recognizes hash component nodes such as #fff.

Returns the raw hash token text, including the leading hash.

Returns the hash value without the leading hash.

procedure

(css-component-hash-span v)  (or/c css-source-span? #f)

  v : css-component-hash?
Returns the source span for a hash component when available.

procedure

(css-component-url? v)  boolean?

  v : any/c
Recognizes url(...) component nodes.

Returns the raw url(...) text.

Returns the URL argument text.

procedure

(css-component-url-span v)  (or/c css-source-span? #f)

  v : css-component-url?
Returns the source span for a URL component when available.

procedure

(css-component-function? v)  boolean?

  v : any/c
Recognizes function component nodes.

Returns the function name, such as rgb, calc, or var.

Returns the component values inside the function argument list.

Returns the full raw function text, including the function name and parentheses.

Returns the source span for a function component when available.

procedure

(css-component-block? v)  boolean?

  v : any/c
Recognizes simple block component nodes.

Returns the opening delimiter character for the block.

Returns the component values inside the block.

Returns the raw block text, including delimiters.

procedure

(css-component-block-span v)  (or/c css-source-span? #f)

  v : css-component-block?
Returns the source span for a block component when available.

1.11.4 Query And Recovery Reference🔗ℹ

procedure

(css-flatten-rules stylesheet)

  (listof (or/c css-style-rule? css-at-rule?))
  stylesheet : css-stylesheet?
Returns a pre-order list of rules and at-rules, recursively flattening nested rule-bearing at-rules while skipping comments.

procedure

(css-find-rules-by-selector-group stylesheet 
  selector-group) 
  (listof css-style-rule?)
  stylesheet : css-stylesheet?
  selector-group : string?
Finds style rules whose selector groups include selector-group exactly.

The search preserves source order and flattens nested rule-bearing at-rules the same way as css-flatten-rules.

procedure

(css-find-rules-by-raw-selector stylesheet 
  raw-selector) 
  (listof css-style-rule?)
  stylesheet : css-stylesheet?
  raw-selector : string?
Finds style rules whose raw selector text exactly matches raw-selector.

The search preserves source order and uses the same nested-rule flattening as css-flatten-rules.

procedure

(css-find-declarations-in-selector-group stylesheet 
  selector-group 
  [property-name]) 
  (listof css-declaration?)
  stylesheet : css-stylesheet?
  selector-group : string?
  property-name : (or/c string? #f) = #f
Finds declarations in rules whose selector groups include selector-group exactly.

The result preserves source order. When property-name is provided, the result is filtered case-insensitively by property name.

procedure

(css-find-declarations-in-selector-groups stylesheet 
  selector-groups 
  [property-name]) 
  (listof css-declaration?)
  stylesheet : css-stylesheet?
  selector-groups : (listof string?)
  property-name : (or/c string? #f) = #f
Finds declarations in rules whose selector groups include any string from selector-groups exactly.

The result preserves source order and flattens nested rule-bearing at-rules the same way as css-flatten-rules. Each matching rule contributes its declarations at most once, even if it matches more than one requested selector group. When property-name is provided, the result is filtered case-insensitively by property name.

procedure

(css-collect-custom-properties-in-selector-group 
  stylesheet 
  selector-group) 
  (hash/c string? string?)
  stylesheet : css-stylesheet?
  selector-group : string?
Collects custom-property declarations from rules whose selector groups include selector-group exactly.

Declarations are processed in source order, and later declarations override earlier ones in the returned hash.

procedure

(css-collect-custom-properties-in-selector-groups 
  stylesheet 
  selector-groups) 
  (hash/c string? string?)
  stylesheet : css-stylesheet?
  selector-groups : (listof string?)
Collects custom-property declarations from rules whose selector groups include any string from selector-groups exactly.

Declarations are processed in source order, and later declarations override earlier ones in the returned hash. Nested rule-bearing at-rules are flattened the same way as css-flatten-rules, and each matching rule is processed at most once even if it matches more than one requested selector group.

procedure

(css-compute-style-for-selector-group 
  stylesheet 
  selector-group 
  [#:resolve-vars? resolve-vars? 
  #:defaults defaults 
  #:trace? trace?]) 
  
(or/c (hash/c string? string?)
      (values/c (hash/c string? string?)
                css-compute-style-trace?))
  stylesheet : css-stylesheet?
  selector-group : string?
  resolve-vars? : boolean? = #f
  defaults : (or/c (hash/c string? string?) #f) = #f
  trace? : boolean? = #f
Computes a reduced tooling-oriented style result for one exact selector-group.

Matching uses exact selector-group text only. The helper flattens nested rule-bearing at-rules the same way as css-flatten-rules, considers the declarations from matching rules in source order, and picks winners by !important, then selector specificity, then later source order.

The result is a hash from normalized property name to raw declaration value. Standard property names are normalized to lowercase. Custom properties are not included in this result; use css-compute-custom-properties-for-selector-group for the custom property environment.

This reduced computed-style layer also expands a small explicit shorthand set: border, the four side-specific border-* shorthands, padding, and margin. Shorthand declarations generate synthetic longhand candidates that participate in the same winner-selection pipeline as authored longhands, so a later authored longhand can still override one side from an earlier shorthand.

When all four border side values agree, the returned hash also exposes the shared aggregate property for border-width, border-style, or border-color. Otherwise those aggregate keys are omitted instead of being lossily reconstructed.

When resolve-vars? is true, var(...) references are resolved against computed custom properties for the same selector-group target and then against defaults. Unresolved references are left intact.

When trace? is true, the function returns two values: the computed hash and a css-compute-style-trace? struct.

procedure

(css-compute-custom-properties-for-selector-group 
  stylesheet 
  selector-group 
  [#:defaults defaults 
  #:resolve-vars? resolve-vars? 
  #:trace? trace?]) 
  
(or/c (hash/c string? string?)
      (values/c (hash/c string? string?)
                css-compute-style-trace?))
  stylesheet : css-stylesheet?
  selector-group : string?
  defaults : (or/c (hash/c string? string?) #f) = #f
  resolve-vars? : boolean? = #f
  trace? : boolean? = #f
Computes the final custom-property environment for one exact selector-group.

Winner selection follows the same rules as css-compute-style-for-selector-group: !important, then selector specificity, then later source order.

When resolve-vars? is true, custom-property values are resolved against other computed custom properties and then defaults. Cycles do not raise errors; cyclical values are left in their raw unresolved form. The returned hash contains those final resolved values directly, so downstream tooling does not need to run a second custom-property resolver for ordinary exact-target use cases.

When trace? is true, the function returns two values: the computed hash and a css-compute-style-trace? struct.

procedure

(css-compute-style-trace? v)  boolean?

  v : any/c
Recognizes trace payloads returned by the computed-style helpers when #:trace? #t is requested.

Returns the exact selector-group target used for the computation.

Returns the matched-rule records considered for the exact selector-group target. Each entry records the selector group, specificity, source order, and style rule.

Returns per-property winner-selection records for standard properties. Each result includes the considered candidates and the winning candidate.

Returns per-property winner-selection records for custom properties.

Returns variable-resolution records describing resolved values, referenced custom properties, and whether cycle handling was encountered.

procedure

(css-compute-matched-rule? v)  boolean?

  v : any/c
Recognizes trace entries for style rules that matched the exact selector-group target.

procedure

(css-compute-matched-rule-selector-group matched-rule)

  string?
  matched-rule : css-compute-matched-rule?
Returns the matched selector-group string.

procedure

(css-compute-matched-rule-specificity matched-rule)

  
(list/c exact-nonnegative-integer?
        exact-nonnegative-integer?
        exact-nonnegative-integer?)
  matched-rule : css-compute-matched-rule?
Returns the selector specificity tuple as (ids classes types).

Returns the source-order index used as the final winner-selection tie-breaker.

procedure

(css-compute-matched-rule-rule matched-rule)  css-style-rule?

  matched-rule : css-compute-matched-rule?
Returns the underlying matched style rule.

procedure

(css-compute-property-result? v)  boolean?

  v : any/c
Recognizes trace entries for one computed property name.

Returns the normalized property name for the result.

Returns the authored or shorthand-expanded candidates considered for this property.

Returns the candidate that won by importance, specificity, and source order.

procedure

(css-compute-candidate? v)  boolean?

  v : any/c
Recognizes one declaration candidate considered by the reduced computed-style winner selection.

procedure

(css-compute-candidate-name candidate)  string?

  candidate : css-compute-candidate?
Returns the property name being assigned by this candidate.

procedure

(css-compute-candidate-value candidate)  string?

  candidate : css-compute-candidate?
Returns the raw declaration value for this candidate.

procedure

(css-compute-candidate-important? candidate)  boolean?

  candidate : css-compute-candidate?
Reports whether the source declaration was marked !important.

procedure

(css-compute-candidate-specificity candidate)

  
(list/c exact-nonnegative-integer?
        exact-nonnegative-integer?
        exact-nonnegative-integer?)
  candidate : css-compute-candidate?
Returns the selector specificity tuple associated with this candidate.

Returns the source-order index associated with this candidate.

Returns the authored declaration that produced this candidate.

Returns the matched-rule trace entry associated with this candidate.

procedure

(css-compute-candidate-source-name candidate)  string?

  candidate : css-compute-candidate?
Returns the authored property name that produced a candidate.

If this differs from (css-compute-candidate-name candidate), then the candidate came from shorthand expansion rather than from an authored longhand.

procedure

(css-compute-var-resolution? v)  boolean?

  v : any/c
Recognizes trace entries for one custom-property or style-property variable resolution step.

procedure

(css-compute-var-resolution-name resolution)  string?

  resolution : css-compute-var-resolution?
Returns the property name whose value was resolved.

procedure

(css-compute-var-resolution-raw-value resolution)  string?

  resolution : css-compute-var-resolution?
Returns the raw value before var(...) substitution.

Returns the value after the reduced resolver substituted what it could.

procedure

(css-compute-var-resolution-references resolution)

  (listof string?)
  resolution : css-compute-var-resolution?
Returns the custom-property names referenced while resolving the value.

procedure

(css-compute-var-resolution-cycle? resolution)  boolean?

  resolution : css-compute-var-resolution?
Reports whether cycle handling was encountered while resolving the value.

procedure

(css-find-declarations stylesheet name)

  (listof css-declaration?)
  stylesheet : css-stylesheet?
  name : string?
Finds declarations whose property name matches name case-insensitively.

procedure

(css-query-selector stylesheet selector)

  (listof css-style-rule?)
  stylesheet : css-stylesheet?
  selector : string?
Finds style rules whose selector groups include selector.

procedure

(css-find-rules-by-pseudo stylesheet 
  pseudo-name) 
  (listof css-style-rule?)
  stylesheet : css-stylesheet?
  pseudo-name : string?
Finds style rules whose derived selector structure contains a pseudo selector with the given name.

procedure

(css-find-media-queries stylesheet)  (listof css-media-query?)

  stylesheet : css-stylesheet?
Returns the derived css-media-query? nodes collected from @media rules in the stylesheet.

procedure

(css-find-supports-features stylesheet 
  [name]) 
  (listof css-supports-feature?)
  stylesheet : css-stylesheet?
  name : (or/c string? #f) = #f
Returns the typed css-supports-feature? leaves collected from @supports rules.

When name is provided, the result is filtered case-insensitively by feature name.

procedure

(css-recovery-nodes stylesheet)  (listof css-recovery?)

  stylesheet : css-stylesheet?
Returns all recovery nodes in the stylesheet.

procedure

(css-has-recovery? stylesheet)  boolean?

  stylesheet : css-stylesheet?
Reports whether the stylesheet contains any recovery nodes.

procedure

(css-recovery-summary stylesheet)

  (listof (cons/c symbol? exact-nonnegative-integer?))
  stylesheet : css-stylesheet?
Summarizes recovery nodes by kind as a sorted association list of (kind . count) pairs.

1.11.5 Error Reference🔗ℹ

The parser uses a CSS-specific exception type rather than generic contract or read errors for parser failures.

procedure

(exn:fail:css? v)  boolean?

  v : any/c
Recognizes CSS parser exceptions.

procedure

(exn:fail:css-source e)  any/c

  e : exn:fail:css?
Returns the source value attached to a CSS parser exception.

procedure

(exn:fail:css-detail e)  any/c

  e : exn:fail:css?
Returns parser-specific detail attached to a CSS parser exception.

1.11.6 Parser Procedure Reference🔗ℹ

procedure

(css-parser? v)  boolean?

  v : any/c
Recognizes parser procedures created by make-css-parser.