strata-ui 0.1.2

Universal frontend framework in pure Rust with pixel-perfect CSS emulation and React/TSX ergonomics
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
//! Spatial hit-testing for pointer events, clicks, cursors, and CSS properties.

use super::*;

#[derive(Clone, Copy, Debug)]
pub(crate) struct HitClipStep {
    pub clip: Option<strata_layout::Rect>,
    pub is_abs_cb: bool,
    pub is_fixed_cb: bool,
}

impl AppRuntime {
    /// Unprojects a world pointer coordinate into an element's local coordinate system if transformed.
    #[inline]
    pub fn unproject_point(layout: &LayoutNode, px: f32, py: f32) -> (f32, f32) {
        if layout.style.has_transform() {
            let mat = layout.style.compute_transform_matrix(
                layout.geometry.border_box.width,
                layout.geometry.border_box.height,
            );
            if let Some(inv) = mat.inverse() {
                let lx = px - layout.geometry.border_box.x;
                let ly = py - layout.geometry.border_box.y;
                let (un_lx, un_ly) = inv.transform_point(lx, ly);
                (
                    layout.geometry.border_box.x + un_lx,
                    layout.geometry.border_box.y + un_ly,
                )
            } else {
                (px, py)
            }
        } else {
            (px, py)
        }
    }

    /// Ancestor clip step tracked along the DOM path so `position: fixed` and `position: absolute`
    /// elements escape clips from ancestors that do not contain their CSS containing block.
    #[inline]
    pub(crate) fn hit_clip_step_for(layout: &LayoutNode) -> HitClipStep {
        let is_fixed_cb = layout.style.establishes_fixed_containing_block();
        let is_abs_cb =
            layout.style.position != strata_style::types::Position::Static || is_fixed_cb;
        let clips = layout.style.overflow_x != strata_style::types::Overflow::Visible
            || layout.style.overflow_y != strata_style::types::Overflow::Visible;
        HitClipStep {
            clip: if clips {
                Some(layout.geometry.border_box)
            } else {
                None
            },
            is_abs_cb,
            is_fixed_cb,
        }
    }

    #[inline]
    pub(crate) fn effective_hit_clip_steps<'a>(
        node: &LayoutNode,
        steps: &'a [HitClipStep],
    ) -> &'a [HitClipStep] {
        match node.style.position {
            strata_style::types::Position::Fixed => {
                if let Some(last_idx) = steps.iter().rposition(|s| s.is_fixed_cb) {
                    &steps[..=last_idx]
                } else {
                    &[]
                }
            }
            strata_style::types::Position::Absolute => {
                if let Some(last_idx) = steps.iter().rposition(|s| s.is_abs_cb) {
                    &steps[..=last_idx]
                } else {
                    &[]
                }
            }
            _ => steps,
        }
    }

    #[inline]
    pub(crate) fn hit_clip_steps_allow(steps: &[HitClipStep], px: f32, py: f32) -> bool {
        steps
            .iter()
            .all(|s| s.clip.is_none_or(|r| r.contains_point(px, py)))
    }

    /// Returns true if `node` establishes an atomic stacking context for paint and hit-testing.
    #[inline]
    pub fn establishes_stacking_context(node: &LayoutNode, is_root: bool) -> bool {
        node.establishes_stacking_context_in(None, is_root)
    }

    /// Returns true if `node` establishes an atomic stacking context given `parent_display`.
    #[inline]
    pub fn establishes_stacking_context_in(
        node: &LayoutNode,
        parent_display: Option<strata_style::types::Display>,
        is_root: bool,
    ) -> bool {
        node.establishes_stacking_context_in(parent_display, is_root)
    }

    /// Pairs flattened blueprint children with `node_layout.children`, preserving flattened child indices
    /// and resolving keyed `EntityId` children when reordered.
    pub(crate) fn paired_blueprint_children<'a>(
        node_bp: &'a NodeBlueprint,
        node_layout: &'a LayoutNode,
    ) -> Vec<(usize, &'a NodeBlueprint, &'a LayoutNode)> {
        let mut flat_children = Vec::new();
        match node_bp {
            NodeBlueprint::Element { children, .. } | NodeBlueprint::Fragment(children) => {
                for c in children {
                    Self::flatten_blueprints(c, &mut flat_children);
                }
            }
            _ => {}
        }

        let mut out = Vec::with_capacity(node_layout.children.len());
        for (idx, child_layout) in node_layout.children.iter().enumerate() {
            let resolved_bp = if child_layout.entity_id.is_valid() {
                if let Some(&cand) = flat_children.get(idx) {
                    if cand.entity_id() == Some(child_layout.entity_id) {
                        Some(cand)
                    } else {
                        node_bp
                            .find_by_entity_id(child_layout.entity_id)
                            .or(Some(cand))
                    }
                } else {
                    node_bp.find_by_entity_id(child_layout.entity_id)
                }
            } else {
                flat_children.get(idx).copied()
            };

            if let Some(child_bp) = resolved_bp {
                out.push((idx, child_bp, child_layout));
            }
        }
        out
    }

    fn collect_top_layer_portals<'a>(
        bp: &'a NodeBlueprint,
        layout: &'a LayoutNode,
        out: &mut Vec<(&'a NodeBlueprint, &'a LayoutNode)>,
        depth: usize,
    ) {
        if depth >= 256 {
            return;
        }
        for (_idx, child_bp, child_layout) in Self::paired_blueprint_children(bp, layout) {
            if child_layout.style.display == strata_style::types::Display::None {
                continue;
            }
            if child_layout.is_top_layer {
                out.push((child_bp, child_layout));
            }
            if !child_layout.children.is_empty() {
                Self::collect_top_layer_portals(child_bp, child_layout, out, depth + 1);
            }
        }
    }

    fn collect_hoisted_stacking_participants<'a>(
        bp: &'a NodeBlueprint,
        layout: &'a LayoutNode,
        steps: &[HitClipStep],
        negative_z: &mut Vec<(&'a NodeBlueprint, &'a LayoutNode, Vec<HitClipStep>)>,
        auto_or_zero_z: &mut Vec<(&'a NodeBlueprint, &'a LayoutNode, bool, Vec<HitClipStep>)>,
        positive_z: &mut Vec<(&'a NodeBlueprint, &'a LayoutNode, Vec<HitClipStep>)>,
        depth: usize,
    ) {
        if depth >= 256 {
            return;
        }
        let parent_display = Some(layout.style.display);
        for (_idx, child_bp, child_layout) in Self::paired_blueprint_children(bp, layout) {
            if child_layout.style.display == strata_style::types::Display::None
                || child_layout.is_top_layer
            {
                continue;
            }
            if Self::establishes_stacking_context_in(child_layout, parent_display, false) {
                let eff_steps = Self::effective_hit_clip_steps(child_layout, steps).to_vec();
                let z = child_layout.style.z_index.unwrap_or(0);
                if z < 0 {
                    negative_z.push((child_bp, child_layout, eff_steps));
                } else if z > 0 {
                    positive_z.push((child_bp, child_layout, eff_steps));
                } else {
                    auto_or_zero_z.push((child_bp, child_layout, true, eff_steps));
                }
            } else {
                let eff_for_child = Self::effective_hit_clip_steps(child_layout, steps);
                if child_layout.style.position != strata_style::types::Position::Static {
                    auto_or_zero_z.push((child_bp, child_layout, false, eff_for_child.to_vec()));
                }
                let mut child_steps = Vec::with_capacity(eff_for_child.len() + 1);
                child_steps.extend_from_slice(eff_for_child);
                let step = Self::hit_clip_step_for(child_layout);
                if step.clip.is_some() || step.is_abs_cb || step.is_fixed_cb {
                    child_steps.push(step);
                }
                Self::collect_hoisted_stacking_participants(
                    child_bp,
                    child_layout,
                    &child_steps,
                    negative_z,
                    auto_or_zero_z,
                    positive_z,
                    depth + 1,
                );
            }
        }
    }

    fn hit_test_direct_in_flow_children<'a, T, F>(
        bp: &'a NodeBlueprint,
        layout: &'a LayoutNode,
        px: f32,
        py: f32,
        depth: usize,
        test_self: &mut F,
    ) -> Option<T>
    where
        F: FnMut(&'a NodeBlueprint, &'a LayoutNode, f32, f32) -> Option<T>,
    {
        let paired = Self::paired_blueprint_children(bp, layout);
        if paired.is_empty() {
            return None;
        }

        let parent_display = Some(layout.style.display);
        let is_in_flow_non_sc = |c: &LayoutNode| {
            c.style.display != strata_style::types::Display::None
                && !c.is_top_layer
                && !Self::establishes_stacking_context_in(c, parent_display, false)
                && c.style.position == strata_style::types::Position::Static
        };
        let is_inline_level = |c: &LayoutNode| {
            matches!(
                c.style.display,
                strata_style::types::Display::Inline
                    | strata_style::types::Display::InlineBlock
                    | strata_style::types::Display::InlineFlex
                    | strata_style::types::Display::InlineGrid
            )
        };

        // Layer 5: In-flow inline-level descendants (front-to-back)
        for &(_idx, child_bp, child_layout) in paired.iter().rev() {
            if is_in_flow_non_sc(child_layout)
                && child_layout.style.float == strata_style::types::Float::None
                && is_inline_level(child_layout)
            {
                if let Some(hit) = Self::hit_test_in_flow_non_hoisted(
                    child_bp,
                    child_layout,
                    px,
                    py,
                    &[],
                    depth + 1,
                    test_self,
                ) {
                    return Some(hit);
                }
            }
        }

        // Layer 4: Non-positioned floats (front-to-back)
        for &(_idx, child_bp, child_layout) in paired.iter().rev() {
            if is_in_flow_non_sc(child_layout)
                && child_layout.style.float != strata_style::types::Float::None
            {
                if let Some(hit) = Self::hit_test_in_flow_non_hoisted(
                    child_bp,
                    child_layout,
                    px,
                    py,
                    &[],
                    depth + 1,
                    test_self,
                ) {
                    return Some(hit);
                }
            }
        }

        // Layer 3: In-flow block-level descendants (front-to-back)
        for &(_idx, child_bp, child_layout) in paired.iter().rev() {
            if is_in_flow_non_sc(child_layout)
                && child_layout.style.float == strata_style::types::Float::None
                && !is_inline_level(child_layout)
            {
                if let Some(hit) = Self::hit_test_in_flow_non_hoisted(
                    child_bp,
                    child_layout,
                    px,
                    py,
                    &[],
                    depth + 1,
                    test_self,
                ) {
                    return Some(hit);
                }
            }
        }

        None
    }

    fn hit_test_in_flow_non_hoisted<'a, T, F>(
        bp: &'a NodeBlueprint,
        layout: &'a LayoutNode,
        px: f32,
        py: f32,
        inherited_steps: &[HitClipStep],
        depth: usize,
        test_self: &mut F,
    ) -> Option<T>
    where
        F: FnMut(&'a NodeBlueprint, &'a LayoutNode, f32, f32) -> Option<T>,
    {
        if depth >= 256 || layout.style.display == strata_style::types::Display::None {
            return None;
        }
        let eff_inherited = Self::effective_hit_clip_steps(layout, inherited_steps);
        if !Self::hit_clip_steps_allow(eff_inherited, px, py) {
            return None;
        }
        if (layout.style.overflow_x != strata_style::types::Overflow::Visible
            || layout.style.overflow_y != strata_style::types::Overflow::Visible)
            && !layout.geometry.border_box.contains_point(px, py)
        {
            return None;
        }
        if let Some(hit) =
            Self::hit_test_direct_in_flow_children(bp, layout, px, py, depth, test_self)
        {
            return Some(hit);
        }
        test_self(bp, layout, px, py)
    }

    fn hit_test_stacking_context_with<'a, T, F>(
        bp: &'a NodeBlueprint,
        layout: &'a LayoutNode,
        px: f32,
        py: f32,
        inherited_steps: &[HitClipStep],
        depth: usize,
        test_self: &mut F,
    ) -> Option<T>
    where
        F: FnMut(&'a NodeBlueprint, &'a LayoutNode, f32, f32) -> Option<T>,
    {
        if depth >= 256 || layout.style.display == strata_style::types::Display::None {
            return None;
        }

        if depth == 0 {
            let mut top_layer_portals = Vec::new();
            Self::collect_top_layer_portals(bp, layout, &mut top_layer_portals, 0);
            for &(p_bp, p_layout) in top_layer_portals.iter().rev() {
                if let Some(hit) =
                    Self::hit_test_stacking_context_with(p_bp, p_layout, px, py, &[], 1, test_self)
                {
                    return Some(hit);
                }
            }
        }

        let eff_inherited = Self::effective_hit_clip_steps(layout, inherited_steps);
        let inherited_allows = Self::hit_clip_steps_allow(eff_inherited, px, py);

        let (px, py) = Self::unproject_point(layout, px, py);

        let own_clips = layout.style.overflow_x != strata_style::types::Overflow::Visible
            || layout.style.overflow_y != strata_style::types::Overflow::Visible;
        let own_allows = !own_clips || layout.geometry.border_box.contains_point(px, py);

        let mut base_steps = Vec::with_capacity(eff_inherited.len() + 1);
        base_steps.extend_from_slice(eff_inherited);
        let own_step = Self::hit_clip_step_for(layout);
        if own_step.clip.is_some() || own_step.is_abs_cb || own_step.is_fixed_cb {
            base_steps.push(own_step);
        }

        let mut negative_z = Vec::new();
        let mut auto_or_zero_z = Vec::new();
        let mut positive_z = Vec::new();
        Self::collect_hoisted_stacking_participants(
            bp,
            layout,
            &base_steps,
            &mut negative_z,
            &mut auto_or_zero_z,
            &mut positive_z,
            depth + 1,
        );

        negative_z.sort_by_key(|(_, l, _)| l.style.z_index.unwrap_or(0));
        positive_z.sort_by_key(|(_, l, _)| l.style.z_index.unwrap_or(0));

        // Layer 7: Child stacking contexts with positive z-index (highest z-index first, reverse DOM on ties)
        for (c_bp, c_layout, c_steps) in positive_z.iter().rev() {
            if let Some(hit) = Self::hit_test_stacking_context_with(
                c_bp,
                c_layout,
                px,
                py,
                c_steps,
                depth + 1,
                test_self,
            ) {
                return Some(hit);
            }
        }

        // Layer 6: Positioned descendants with z-index: auto and child stacking contexts with z-index: 0
        for (c_bp, c_layout, is_sc, c_steps) in auto_or_zero_z.iter().rev() {
            let hit = if *is_sc {
                Self::hit_test_stacking_context_with(
                    c_bp,
                    c_layout,
                    px,
                    py,
                    c_steps,
                    depth + 1,
                    test_self,
                )
            } else {
                Self::hit_test_in_flow_non_hoisted(
                    c_bp,
                    c_layout,
                    px,
                    py,
                    c_steps,
                    depth + 1,
                    test_self,
                )
            };
            if hit.is_some() {
                return hit;
            }
        }

        // Layers 5, 4, 3: In-flow inline, float, and block descendants
        if inherited_allows && own_allows {
            if let Some(hit) =
                Self::hit_test_direct_in_flow_children(bp, layout, px, py, depth, test_self)
            {
                return Some(hit);
            }
        }

        // Layer 2: Child stacking contexts with negative z-index (closest to 0 first, reverse DOM on ties)
        for (c_bp, c_layout, c_steps) in negative_z.iter().rev() {
            if let Some(hit) = Self::hit_test_stacking_context_with(
                c_bp,
                c_layout,
                px,
                py,
                c_steps,
                depth + 1,
                test_self,
            ) {
                return Some(hit);
            }
        }

        // Layer 1: Stacking context root element itself
        if inherited_allows {
            test_self(bp, layout, px, py)
        } else {
            None
        }
    }

    /// Recursively hit tests a coordinate point against the blueprint and computed layout hierarchy,
    /// returning the nearest listener registered for `event_type`, its element border box, and its `EntityId`.
    pub fn hit_test_event_with_box_and_entity<'a>(
        blueprint: &'a NodeBlueprint,
        layout: &'a LayoutNode,
        px: f32,
        py: f32,
        event_type: strata_dom::EventType,
    ) -> Option<(
        std::rc::Rc<dyn Fn(strata_dom::Event)>,
        &'a strata_layout::Rect,
        strata_primitives::EntityId,
    )> {
        Self::hit_test_stacking_context_with(
            blueprint,
            layout,
            px,
            py,
            &[],
            0,
            &mut |bp, node_layout, lx, ly| {
                if matches!(
                    node_layout.style.visibility,
                    strata_style::types::Visibility::Hidden
                ) || matches!(
                    node_layout.style.pointer_events,
                    strata_style::types::PointerEvents::None
                ) {
                    return None;
                }
                if let NodeBlueprint::Element { attributes, .. } = bp {
                    if node_layout.geometry.border_box.contains_point(lx, ly) {
                        for attr in attributes {
                            if let strata_dom::Attribute::EventListener { event: ev, handler } =
                                attr
                            {
                                if *ev == event_type {
                                    return Some((
                                        handler.clone(),
                                        &node_layout.geometry.border_box,
                                        node_layout.entity_id,
                                    ));
                                }
                            }
                        }
                    }
                }
                None
            },
        )
    }

    /// Recursively hit tests a coordinate point against the blueprint and computed layout hierarchy,
    /// returning the nearest listener registered for `event_type` and its element border box.
    pub fn hit_test_event_with_box<'a>(
        blueprint: &'a NodeBlueprint,
        layout: &'a LayoutNode,
        px: f32,
        py: f32,
        event_type: strata_dom::EventType,
    ) -> Option<(
        std::rc::Rc<dyn Fn(strata_dom::Event)>,
        &'a strata_layout::Rect,
    )> {
        Self::hit_test_event_with_box_and_entity(blueprint, layout, px, py, event_type)
            .map(|(h, r, _)| (h, r))
    }

    /// Walks from `path` up toward the root to find the nearest ancestor (or self)
    /// registering a listener for `event_type`, returning `(handler, border_box, entity_id)`.
    pub fn find_event_at_or_above_path<'a>(
        blueprint: &'a NodeBlueprint,
        layout: &'a LayoutNode,
        path: &[usize],
        event_type: strata_dom::EventType,
    ) -> Option<(
        std::rc::Rc<dyn Fn(strata_dom::Event)>,
        &'a strata_layout::Rect,
        strata_primitives::EntityId,
    )> {
        for len in (0..=path.len()).rev() {
            let prefix = &path[..len];
            let Some(bp) = Self::find_blueprint_at_path(blueprint, prefix) else {
                continue;
            };
            let mut node_layout = layout;
            let mut valid = true;
            for &idx in prefix {
                if let Some(child) = node_layout.children.get(idx) {
                    node_layout = child;
                } else {
                    valid = false;
                    break;
                }
            }
            if !valid {
                continue;
            }
            if let NodeBlueprint::Element { attributes, .. } = bp {
                for attr in attributes {
                    if let strata_dom::Attribute::EventListener { event: ev, handler } = attr {
                        if *ev == event_type {
                            return Some((
                                handler.clone(),
                                &node_layout.geometry.border_box,
                                node_layout.entity_id,
                            ));
                        }
                    }
                }
            }
        }
        None
    }

    /// Recursively hit tests a coordinate point against the blueprint and computed layout hierarchy,
    /// returning the nearest (deepest, front-most) listener registered for `event_type`.
    pub fn hit_test_event(
        blueprint: &NodeBlueprint,
        layout: &LayoutNode,
        px: f32,
        py: f32,
        event_type: strata_dom::EventType,
    ) -> Option<std::rc::Rc<dyn Fn(strata_dom::Event)>> {
        Self::hit_test_event_with_box(blueprint, layout, px, py, event_type).map(|(h, _)| h)
    }

    /// Hit tests for the nearest `onclick` listener at a coordinate point.
    pub fn hit_test_click(
        blueprint: &NodeBlueprint,
        layout: &LayoutNode,
        px: f32,
        py: f32,
    ) -> Option<std::rc::Rc<dyn Fn(strata_dom::Event)>> {
        Self::hit_test_event(blueprint, layout, px, py, strata_dom::EventType::Click)
    }

    /// Recursively hit tests a coordinate point against the blueprint and computed layout hierarchy to determine cursor style.
    pub fn hit_test_cursor(
        blueprint: &NodeBlueprint,
        layout: &LayoutNode,
        px: f32,
        py: f32,
    ) -> strata_platform::window::CursorIcon {
        Self::hit_test_stacking_context_with(
            blueprint,
            layout,
            px,
            py,
            &[],
            0,
            &mut |bp, node_layout, lx, ly| {
                if matches!(
                    node_layout.style.visibility,
                    strata_style::types::Visibility::Hidden
                ) || matches!(
                    node_layout.style.pointer_events,
                    strata_style::types::PointerEvents::None
                ) {
                    return None;
                }
                if let NodeBlueprint::Element {
                    tag,
                    classes,
                    attributes,
                    ..
                } = bp
                {
                    if node_layout.geometry.border_box.contains_point(lx, ly) {
                        match node_layout.style.cursor {
                            strata_style::types::Cursor::Pointer => {
                                return Some(strata_platform::window::CursorIcon::Pointer)
                            }
                            strata_style::types::Cursor::Text => {
                                return Some(strata_platform::window::CursorIcon::Text)
                            }
                            strata_style::types::Cursor::Crosshair => {
                                return Some(strata_platform::window::CursorIcon::Crosshair)
                            }
                            strata_style::types::Cursor::Move => {
                                return Some(strata_platform::window::CursorIcon::Move)
                            }
                            strata_style::types::Cursor::NotAllowed => {
                                return Some(strata_platform::window::CursorIcon::NotAllowed)
                            }
                            strata_style::types::Cursor::Wait => {
                                return Some(strata_platform::window::CursorIcon::Wait)
                            }
                            strata_style::types::Cursor::Grab => {
                                return Some(strata_platform::window::CursorIcon::Grab)
                            }
                            strata_style::types::Cursor::Grabbing => {
                                return Some(strata_platform::window::CursorIcon::Grabbing)
                            }
                            strata_style::types::Cursor::ColResize => {
                                return Some(strata_platform::window::CursorIcon::ColResize)
                            }
                            strata_style::types::Cursor::RowResize => {
                                return Some(strata_platform::window::CursorIcon::RowResize)
                            }
                            strata_style::types::Cursor::Help => {
                                return Some(strata_platform::window::CursorIcon::Help)
                            }
                            strata_style::types::Cursor::None => {
                                return Some(strata_platform::window::CursorIcon::None)
                            }
                            strata_style::types::Cursor::Default => {}
                        }

                        let has_pointer = matches!(tag, Tag::Button | Tag::A)
                            || classes.iter().any(|c| {
                                c.split_whitespace()
                                    .any(|tok| tok == "cursor-pointer" || tok == "pointer")
                            })
                            || attributes.iter().any(|a| {
                                matches!(
                                    a,
                                    strata_dom::Attribute::EventListener {
                                        event: strata_dom::EventType::Click,
                                        ..
                                    }
                                )
                            });

                        if has_pointer {
                            return Some(strata_platform::window::CursorIcon::Pointer);
                        }

                        let has_text_cursor = matches!(tag, Tag::Input | Tag::Textarea)
                            || classes.iter().any(|c| {
                                c.split_whitespace()
                                    .any(|tok| tok == "cursor-text" || tok == "select-text")
                            });

                        if has_text_cursor {
                            return Some(strata_platform::window::CursorIcon::Text);
                        }
                    }
                }
                None
            },
        )
        .unwrap_or(strata_platform::window::CursorIcon::Default)
    }

    /// Finds the value of the deepest element property `key` whose border box contains the point.
    /// Elements are tested front-to-back according to CSS stacking contexts so overlays win over what they cover.
    pub fn hit_test_property(
        blueprint: &NodeBlueprint,
        layout: &LayoutNode,
        px: f32,
        py: f32,
        key: &str,
    ) -> Option<String> {
        Self::hit_test_stacking_context_with(
            blueprint,
            layout,
            px,
            py,
            &[],
            0,
            &mut |bp, node_layout, lx, ly| {
                if matches!(
                    node_layout.style.visibility,
                    strata_style::types::Visibility::Hidden
                ) || matches!(
                    node_layout.style.pointer_events,
                    strata_style::types::PointerEvents::None
                ) {
                    return None;
                }
                if let NodeBlueprint::Element { attributes, .. } = bp {
                    if node_layout.geometry.border_box.contains_point(lx, ly) {
                        for attr in attributes {
                            if let strata_dom::Attribute::Property { key: k, value } = attr {
                                if k == key {
                                    return Some(value.clone());
                                }
                            }
                        }
                    }
                }
                None
            },
        )
    }
}