Skip to main content

Module media_query_transform

Module media_query_transform 

Source
Expand description

Media query transformation functionality.

Implements the β€œlast media query wins” transformation logic for CSS-in-JS. This ensures proper specificity handling when multiple media queries target the same properties.

This implementation provides media query transformation:

  1. DFS traversal of the style object
  2. At depth >= 1, apply negation-based media query transformation
  3. Use pure AST manipulation, not range-based logic

FunctionsΒ§

are_media_queries_disjoint πŸ”’
Check if all media queries represent disjoint width/height ranges
combine_media_query_with_negations πŸ”’
Combine media query with negations - matches JS combineMediaQueryWithNegations exactly
create_object_from_key_values πŸ”’
Helper function to create ObjectLit from key-value pairs
dfs_process_queries_with_depth πŸ”’
DFS traversal with depth tracking - matches JS dfsProcessQueries exactly
extract_width_height_range πŸ”’
Extract width/height range from a media query if it’s a simple range
key_value_to_str πŸ”’
Helper function to extract key as string from KeyValueProp
last_media_query_wins_transform
Main entry point - equivalent to lastMediaQueryWinsTransform in JS
last_media_query_wins_transform_internal
Internal helper function for backwards compatibility with existing tests This preserves the old Vec -> Vec signature for internal use
normalize_media_query_syntax πŸ”’
Just normalize media query syntax without applying negation logic
ranges_overlap πŸ”’
Check if two ranges overlap
transform_media_queries_in_result πŸ”’
Transform media queries in the result object - matches JS logic exactly