use crate::hot_diff::attrs::{
AttrSpec, is_test_id_attr, lookup_standalone_attr, lookup_typed_style_arg, prop_bits,
};
use crate::hot_diff::lexer::{Lex as PropLex, tokenize as prop_tokenize};
use crate::hot_diff::typed_style_chain::scan_typed_style_chain_with_aliases;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum DirectArgOverlap {
Disjoint,
Shadow(u64),
Bidirectional(u64),
}
pub(super) fn classify_direct_arg_overlap(name: &str) -> DirectArgOverlap {
use prop_bits as B;
if let Some(spec) = lookup_view_direct_spec(name) {
return DirectArgOverlap::Shadow(spec.bits);
}
match name {
"border" => DirectArgOverlap::Shadow(B::BORDER_WIDTH | B::BORDER_COLOR),
"padding_xy" | "padding_insets" => DirectArgOverlap::Shadow(B::PAD_ALL),
"margin_xy" | "margin_insets" => DirectArgOverlap::Shadow(B::MAR_ALL),
"surface" => DirectArgOverlap::Shadow(
B::BG | B::BORDER_WIDTH | B::BORDER_COLOR | B::BORDER_RADIUS | B::OPACITY,
),
"text_style" => DirectArgOverlap::Shadow(
B::TEXT_COLOR | B::FONT_SIZE | B::FONT_WEIGHT | B::TEXT_ALIGN | B::OPACITY,
),
"width_auto" => DirectArgOverlap::Shadow(B::WIDTH),
"height_auto" => DirectArgOverlap::Shadow(B::HEIGHT),
"flex_row" | "flex_col" | "flex_row_reverse" | "flex_col_reverse" => {
DirectArgOverlap::Shadow(B::FLEX_DIR)
}
"flex_1" => DirectArgOverlap::Shadow(B::FLEX_SHORTHAND),
"position_static"
| "position_relative"
| "position_absolute"
| "position_sticky"
| "position_fixed" => DirectArgOverlap::Shadow(B::POSITION),
"display_grid" => DirectArgOverlap::Shadow(B::DISPLAY),
"z_index_auto" => DirectArgOverlap::Shadow(B::Z_INDEX),
"padding_inline_start" | "padding_inline_end" => DirectArgOverlap::Bidirectional(B::PAD_X),
"margin_inline_start" | "margin_inline_end" => DirectArgOverlap::Bidirectional(B::MAR_X),
"id"
| "key"
| "text"
| "content"
| "disabled"
| "focusable"
| "tab_index"
| "role"
| "selectable"
| "horizontal"
| "vertical"
| "clip"
| "bounces"
| "scroll_enabled"
| "paging_enabled"
| "shows_scroll_indicator"
| "shows_horizontal_scroll_indicator"
| "shows_vertical_scroll_indicator"
| "max_lines"
| "number_of_lines"
| "ellipsize"
| "node_ref"
| "ref"
| "font_family"
| "user_select"
| "box_shadows"
| "background_fill"
| "linear_gradient"
| "radial_gradient"
| "overscroll_behavior"
| "overscroll_behavior_x"
| "overscroll_behavior_y"
| "overflow_anchor"
| "transform"
| "transform_origin"
| "translate"
| "scale"
| "scale_xy"
| "rotate"
| "direction"
| "rtl"
| "ltr"
| "pointer_events"
| "pointer_events_none"
| "capture_mode"
| "capture_on_primary_down"
| "container_type"
| "container_inline_size"
| "container_size"
| "grid_cols"
| "grid_rows"
| "grid_column"
| "grid_row"
| "grid_column_span"
| "grid_row_span"
| "show_on" => DirectArgOverlap::Disjoint,
_ if is_test_id_attr(name)
|| name.starts_with("on_")
|| name.starts_with("aria_")
|| name.starts_with("accessibility_") =>
{
DirectArgOverlap::Disjoint
}
_ => DirectArgOverlap::Bidirectional(B::ALL),
}
}
#[inline]
pub(super) fn is_ext_gap_direct_prop(name: &str) -> bool {
matches!(name, "row_gap" | "row-gap" | "column_gap" | "column-gap")
}
pub(super) fn style_expr_written_bits(raw: &str) -> u64 {
let Ok(tokens) = prop_tokenize(raw) else {
return prop_bits::ALL;
};
let lex = PropLex::new(raw, &tokens);
let mut steps = Vec::new();
if !scan_typed_style_chain_with_aliases(lex, 0, lex.len(), &mut steps, true) {
return prop_bits::ALL;
}
steps.iter().fold(0u64, |acc, &(_, bits)| acc | bits)
}
pub(super) fn lookup_view_direct_spec(name: &str) -> Option<&'static AttrSpec> {
if let Some(spec) = lookup_typed_style_arg(name, 0) {
if name != "border" && name != "padding_xy" && name != "margin_xy" {
return Some(spec);
}
}
match name {
"spacing" => lookup_typed_style_arg("gap", 0),
"background_color" => lookup_typed_style_arg("background", 0),
"padding_horizontal" => lookup_typed_style_arg("padding_x", 0),
"padding_vertical" => lookup_typed_style_arg("padding_y", 0),
"margin_horizontal" => lookup_typed_style_arg("margin_x", 0),
"margin_vertical" => lookup_typed_style_arg("margin_y", 0),
"top" => lookup_typed_style_arg("inset_top", 0),
"right" => lookup_typed_style_arg("inset_right", 0),
"bottom" => lookup_typed_style_arg("inset_bottom", 0),
"left" => lookup_typed_style_arg("inset_left", 0),
_ => lookup_standalone_attr(name),
}
}
pub(super) fn lookup_direct_float_spec(name: &str) -> Option<&'static AttrSpec> {
match name {
"width" => lookup_typed_style_arg("width_px", 0),
"height" => lookup_typed_style_arg("height_px", 0),
"min_width" => lookup_typed_style_arg("min_width_px", 0),
"min_height" => lookup_typed_style_arg("min_height_px", 0),
"max_width" => lookup_typed_style_arg("max_width_px", 0),
"max_height" => lookup_typed_style_arg("max_height_px", 0),
"flex_basis" => lookup_typed_style_arg("flex_basis_px", 0),
"top" | "inset_top" => lookup_typed_style_arg("inset_top_px", 0),
"right" | "inset_right" => lookup_typed_style_arg("inset_right_px", 0),
"bottom" | "inset_bottom" => lookup_typed_style_arg("inset_bottom_px", 0),
"left" | "inset_left" => lookup_typed_style_arg("inset_left_px", 0),
_ => None,
}
}