Skip to content

Commit b333ec5

Browse files
feat: update to upstream @floating-ui/utils@0.2.10 (#161)
* feat: update to upstream @floating-ui/utils@0.2.10 * perf: reduce memory allocations --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Daniëlle Huisman <danielle@huisman.me>
1 parent 73485ab commit b333ec5

3 files changed

Lines changed: 37 additions & 23 deletions

File tree

packages/utils/src/dom.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn is_html_element(node: &Node) -> bool {
134134
}
135135

136136
const OVERFLOW_VALUES: [&str; 5] = ["auto", "scroll", "overlay", "hidden", "clip"];
137-
const DISPLAY_VALUES: [&str; 2] = ["inline", "contents"];
137+
const INVALID_OVERFLOW_DISPLAY_VALUES: [&str; 2] = ["inline", "contents"];
138138

139139
pub fn is_overflow_element(element: &Element) -> bool {
140140
let style = get_computed_style(element);
@@ -148,20 +148,29 @@ pub fn is_overflow_element(element: &Element) -> bool {
148148
OVERFLOW_VALUES
149149
.into_iter()
150150
.any(|s| overflow_combined.contains(s))
151-
&& !DISPLAY_VALUES.into_iter().any(|s| display == s)
151+
&& !INVALID_OVERFLOW_DISPLAY_VALUES
152+
.into_iter()
153+
.any(|s| display == s)
152154
}
153155

156+
const TABLE_ELEMENTS: [&str; 3] = ["table", "td", "th"];
157+
154158
pub fn is_table_element(element: &Element) -> bool {
155159
let node_name = get_node_name(element.into());
156-
["table", "td", "th"].into_iter().any(|s| node_name == s)
160+
TABLE_ELEMENTS.into_iter().any(|s| node_name == s)
157161
}
158162

163+
const TOP_LAYER_SELECTORS: [&str; 2] = [":popover-open", ":modal"];
164+
159165
pub fn is_top_layer(element: &Element) -> bool {
160-
[":popover-open", ":modal"]
166+
TOP_LAYER_SELECTORS
161167
.into_iter()
162168
.any(|selector| element.matches(selector).unwrap_or(false))
163169
}
164170

171+
const TRANSFORM_PROPERTIES: [&str; 5] =
172+
["transform", "translate", "scale", "rotate", "perspective"];
173+
165174
const WILL_CHANGE_VALUES: [&str; 6] = [
166175
"transform",
167176
"translate",
@@ -170,6 +179,7 @@ const WILL_CHANGE_VALUES: [&str; 6] = [
170179
"perspective",
171180
"filter",
172181
];
182+
173183
const CONTAIN_VALUES: [&str; 4] = ["paint", "layout", "strict", "content"];
174184

175185
pub enum ElementOrCss<'a> {
@@ -204,17 +214,14 @@ pub fn is_containing_block(element: ElementOrCss) -> bool {
204214

205215
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
206216
// https://drafts.csswg.org/css-transforms-2/#individual-transforms
207-
["transform", "translate", "scale", "rotate", "perspective"]
208-
.into_iter()
209-
.any(|property| {
210-
css.get_property_value(property)
211-
.map(|value| value != "none")
212-
.unwrap_or(false)
213-
})
214-
|| css
215-
.get_property_value("container-type")
216-
.map(|value| value != "normal")
217+
TRANSFORM_PROPERTIES.into_iter().any(|property| {
218+
css.get_property_value(property)
219+
.map(|value| value != "none")
217220
.unwrap_or(false)
221+
}) || css
222+
.get_property_value("container-type")
223+
.map(|value| value != "normal")
224+
.unwrap_or(false)
218225
|| (!webkit
219226
&& css
220227
.get_property_value("backdrop-filter")
@@ -262,9 +269,11 @@ pub fn is_web_kit() -> bool {
262269
css::supports_with_value("-webkit-backdrop-filter", "none").unwrap_or(false)
263270
}
264271

272+
const LAST_TRAVERSABLE_NODE_NAMES: [&str; 3] = ["html", "body", "#document"];
273+
265274
pub fn is_last_traversable_node(node: &Node) -> bool {
266275
let node_name = get_node_name(node.into());
267-
["html", "body", "#document"]
276+
LAST_TRAVERSABLE_NODE_NAMES
268277
.into_iter()
269278
.any(|s| node_name == s)
270279
}

packages/utils/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,29 +657,34 @@ pub fn get_opposite_alignment_placement(placement: Placement) -> Placement {
657657
placement.opposite_alignment()
658658
}
659659

660-
pub fn get_side_list(side: Side, is_start: bool, rtl: Option<bool>) -> Vec<Side> {
660+
const LR_SIDE_LIST: [Side; 2] = [Side::Left, Side::Right];
661+
const RL_SIDE_LIST: [Side; 2] = [Side::Right, Side::Left];
662+
const TB_SIDE_LIST: [Side; 2] = [Side::Top, Side::Bottom];
663+
const BT_SIDE_LIST: [Side; 2] = [Side::Bottom, Side::Top];
664+
665+
pub fn get_side_list(side: Side, is_start: bool, rtl: Option<bool>) -> [Side; 2] {
661666
match side {
662667
Side::Top | Side::Bottom => match rtl {
663668
Some(true) => {
664669
if is_start {
665-
vec![Side::Right, Side::Left]
670+
RL_SIDE_LIST
666671
} else {
667-
vec![Side::Left, Side::Right]
672+
LR_SIDE_LIST
668673
}
669674
}
670675
_ => {
671676
if is_start {
672-
vec![Side::Left, Side::Right]
677+
LR_SIDE_LIST
673678
} else {
674-
vec![Side::Right, Side::Left]
679+
RL_SIDE_LIST
675680
}
676681
}
677682
},
678683
Side::Right | Side::Left => {
679684
if is_start {
680-
vec![Side::Top, Side::Bottom]
685+
TB_SIDE_LIST
681686
} else {
682-
vec![Side::Bottom, Side::Top]
687+
BT_SIDE_LIST
683688
}
684689
}
685690
}

upstream.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[releases]
22
core = "1.7.1"
33
dom = "1.7.1"
4-
utils = "0.2.9"
4+
utils = "0.2.10"
55
vue = "1.1.6"

0 commit comments

Comments
 (0)