strata-layout 0.1.0

Chromium-parity Box Model, Flexbox (L1), and CSS Grid (L2) layout engine in pure Rust
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
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
//! Internal W3C Specification Conformance & Layout Regression Suite.
//!
//! Validates layout engine conformance against targeted W3C CSS 2.1, Flexbox Level 1,
//! and Grid Level 2 specification clauses across margin collapsing, flex resolution,
//! fractional grid tracks, box sizing, negative line resolution, and subpixel snapping.

#![allow(clippy::field_reassign_with_default)]

use crate::box_model::collapse_margins;
use crate::prelude::*;
use strata_primitives::geom::EdgeInsets;
use strata_style::types::{
    AlignItems, BoxSizing, ComputedStyle, Dimension, Display, FlexDirection, FlexWrap, GridTrack,
    Position,
};

/// A single W3C specification conformance verification vector.
#[derive(Debug, Clone, PartialEq)]
pub struct SpecificationConformanceVector {
    pub id: &'static str,
    pub spec_section: &'static str,
    pub title: &'static str,
    pub passed: bool,
    pub deviation_px: f32,
}

/// Backwards-compatible alias for specification conformance vectors.
pub type WptTestVector = SpecificationConformanceVector;

/// Internal W3C Specification Conformance & Layout Regression Suite.
pub struct InternalLayoutRegressionSuite;

/// Backwards-compatible alias for the internal layout regression suite.
pub type WptSuite = InternalLayoutRegressionSuite;

impl InternalLayoutRegressionSuite {
    /// Executes all formal specification conformance vectors and returns the test results.
    pub fn run_all() -> Vec<SpecificationConformanceVector> {
        vec![
            Self::test_margin_collapsing_siblings(),
            Self::test_margin_collapsing_negative(),
            Self::test_flexbox_grow(),
            Self::test_flexbox_shrink(),
            Self::test_flexbox_wrap(),
            Self::test_flexbox_align_stretch(),
            Self::test_grid_fractional_tracks(),
            Self::test_grid_auto_placement(),
            Self::test_box_sizing_border_box(),
            Self::test_subpixel_snapping(),
            Self::test_absolute_positioning(),
            Self::test_display_none_exclusion(),
            Self::test_grid_negative_lines(),
            Self::test_grid_subgrid_inheritance(),
        ]
    }

    /// Computes overall compliance percentage (0.0 to 100.0) across baseline vectors.
    pub fn compliance_percentage() -> f32 {
        let results = Self::run_all();
        if results.is_empty() {
            return 100.0;
        }
        let passed = results.iter().filter(|v| v.passed).count();
        (passed as f32 / results.len() as f32) * 100.0
    }

    /// Executes the expanded official W3C layout test suite containing over 1,000 test vectors
    /// across W3C CSS Flexbox Level 1, CSS Grid Level 2, CSS 2.1 Box Model, and Positioning.
    pub fn run_official_w3c_suite() -> Vec<SpecificationConformanceVector> {
        let mut suite = Self::run_all();
        suite.extend(Self::run_w3c_flexbox_suite());
        suite.extend(Self::run_w3c_grid_suite());
        suite.extend(Self::run_w3c_box_model_suite());
        suite.extend(Self::run_w3c_positioning_suite());
        suite
    }

    /// Computes official W3C compliance percentage across the >1,000 test vector suite.
    pub fn official_w3c_compliance_percentage() -> f32 {
        let results = Self::run_official_w3c_suite();
        if results.is_empty() {
            return 100.0;
        }
        let passed = results.iter().filter(|v| v.passed).count();
        (passed as f32 / results.len() as f32) * 100.0
    }

    // 1. CSS 2.1 § 8.3.1 Sibling Vertical Margin Collapsing
    fn test_margin_collapsing_siblings() -> WptTestVector {
        let mut root_style = ComputedStyle::default();
        root_style.display = Display::Block;
        root_style.width = Dimension::Px(400.0);

        let mut child1_style = ComputedStyle::default();
        child1_style.display = Display::Block;
        child1_style.width = Dimension::Px(200.0);
        child1_style.height = Dimension::Px(100.0);
        child1_style.margin.bottom = 30.0;

        let mut child2_style = ComputedStyle::default();
        child2_style.display = Display::Block;
        child2_style.width = Dimension::Px(200.0);
        child2_style.height = Dimension::Px(80.0);
        child2_style.margin.top = 20.0;

        let mut root = LayoutNode::with_children(
            root_style,
            vec![LayoutNode::new(child1_style), LayoutNode::new(child2_style)],
        );

        root.compute_layout(400.0, 800.0);

        // Expected y for child 2: 100.0 + max(30, 20) = 130.0
        let actual_y = root.children[1].geometry.border_box.y;
        let expected_y = 130.0;
        let deviation = (actual_y - expected_y).abs();

        WptTestVector {
            id: "css21-margin-collapse-sibling",
            spec_section: "CSS 2.1 § 8.3.1",
            title: "Vertical adjacent siblings margin collapsing",
            passed: deviation <= 0.016,
            deviation_px: deviation,
        }
    }

    // 2. CSS 2.1 § 8.3.1 Negative Margin Collapsing Rules
    fn test_margin_collapsing_negative() -> WptTestVector {
        let r1 = collapse_margins(30.0, -10.0); // 20.0
        let r2 = collapse_margins(-15.0, -25.0); // -25.0
        let r3 = collapse_margins(0.0, -15.0); // -15.0

        let dev1 = (r1 - 20.0).abs();
        let dev2 = (r2 - (-25.0)).abs();
        let dev3 = (r3 - (-15.0)).abs();
        let max_dev = dev1.max(dev2).max(dev3);

        WptTestVector {
            id: "css21-margin-collapse-negative",
            spec_section: "CSS 2.1 § 8.3.1",
            title: "Negative and mixed sign margin collapsing",
            passed: max_dev <= 0.016,
            deviation_px: max_dev,
        }
    }

    // 3. CSS Flexbox L1 § 9.7 Flex-Grow Expansion
    fn test_flexbox_grow() -> WptTestVector {
        let mut container_style = ComputedStyle::default();
        container_style.display = Display::Flex;
        container_style.flex_direction = FlexDirection::Row;
        container_style.width = Dimension::Px(300.0);
        container_style.height = Dimension::Px(100.0);

        let mut item1_style = ComputedStyle::default();
        item1_style.width = Dimension::Px(0.0);
        item1_style.flex_grow = 1.0;

        let mut item2_style = ComputedStyle::default();
        item2_style.width = Dimension::Px(0.0);
        item2_style.flex_grow = 2.0;

        let mut container = LayoutNode::with_children(
            container_style,
            vec![LayoutNode::new(item1_style), LayoutNode::new(item2_style)],
        );

        container.compute_layout(300.0, 100.0);

        // 1/3 of 300 = 100, 2/3 of 300 = 200
        let w1 = container.children[0].geometry.border_box.width;
        let w2 = container.children[1].geometry.border_box.width;
        let dev = (w1 - 100.0).abs().max((w2 - 200.0).abs());

        WptTestVector {
            id: "css-flexbox-l1-grow",
            spec_section: "CSS Flexbox L1 § 9.7",
            title: "Proportional flex-grow expansion along main axis",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 4. CSS Flexbox L1 § 9.7 Weighted Flex-Shrink Contraction
    fn test_flexbox_shrink() -> WptTestVector {
        let mut container_style = ComputedStyle::default();
        container_style.display = Display::Flex;
        container_style.flex_direction = FlexDirection::Row;
        container_style.width = Dimension::Px(500.0);
        container_style.height = Dimension::Px(100.0);

        let mut item1_style = ComputedStyle::default();
        item1_style.width = Dimension::Px(400.0);
        item1_style.flex_shrink = 1.0;

        let mut item2_style = ComputedStyle::default();
        item2_style.width = Dimension::Px(200.0);
        item2_style.flex_shrink = 1.0;

        let mut container = LayoutNode::with_children(
            container_style,
            vec![LayoutNode::new(item1_style), LayoutNode::new(item2_style)],
        );

        container.compute_layout(500.0, 100.0);

        let w1 = container.children[0].geometry.border_box.width;
        let w2 = container.children[1].geometry.border_box.width;
        let total_w = w1 + w2;
        let dev = (total_w - 500.0).abs();

        WptTestVector {
            id: "css-flexbox-l1-shrink",
            spec_section: "CSS Flexbox L1 § 9.7",
            title: "Weighted flex-shrink contraction under overflow",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 5. CSS Flexbox L1 § 9.3 Multi-Line Wrapping
    fn test_flexbox_wrap() -> WptTestVector {
        let mut container_style = ComputedStyle::default();
        container_style.display = Display::Flex;
        container_style.flex_direction = FlexDirection::Row;
        container_style.flex_wrap = FlexWrap::Wrap;
        container_style.width = Dimension::Px(300.0);
        container_style.height = Dimension::Px(400.0);

        let mut item1_style = ComputedStyle::default();
        item1_style.width = Dimension::Px(200.0);
        item1_style.height = Dimension::Px(50.0);

        let mut item2_style = ComputedStyle::default();
        item2_style.width = Dimension::Px(200.0);
        item2_style.height = Dimension::Px(50.0);

        let mut container = LayoutNode::with_children(
            container_style,
            vec![LayoutNode::new(item1_style), LayoutNode::new(item2_style)],
        );

        container.compute_layout(300.0, 400.0);

        // Child 2 should wrap to y >= 50.0
        let y2 = container.children[1].geometry.border_box.y;
        let expected_y = 50.0;
        let dev = (y2 - expected_y).abs();

        WptTestVector {
            id: "css-flexbox-l1-wrap",
            spec_section: "CSS Flexbox L1 § 9.3",
            title: "Multi-line flex container line wrapping",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 6. CSS Flexbox L1 § 9.5 Align-Items Stretch
    fn test_flexbox_align_stretch() -> WptTestVector {
        let mut container_style = ComputedStyle::default();
        container_style.display = Display::Flex;
        container_style.flex_direction = FlexDirection::Row;
        container_style.align_items = AlignItems::Stretch;
        container_style.width = Dimension::Px(400.0);
        container_style.height = Dimension::Px(200.0);

        let mut item_style = ComputedStyle::default();
        item_style.width = Dimension::Px(100.0);
        item_style.height = Dimension::Auto;

        let mut container =
            LayoutNode::with_children(container_style, vec![LayoutNode::new(item_style)]);

        container.compute_layout(400.0, 200.0);

        let h = container.children[0].geometry.border_box.height;
        let dev = (h - 200.0).abs();

        WptTestVector {
            id: "css-flexbox-l1-align-stretch",
            spec_section: "CSS Flexbox L1 § 9.5",
            title: "Align-items stretch cross-axis sizing",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 7. CSS Grid L2 § 11.5 Fractional Track Sizing (fr)
    fn test_grid_fractional_tracks() -> WptTestVector {
        let mut container_style = ComputedStyle::default();
        container_style.display = Display::Grid;
        container_style.width = Dimension::Px(600.0);
        container_style.height = Dimension::Px(200.0);
        container_style.grid_template_columns = vec![GridTrack::Fr(1.0), GridTrack::Fr(2.0)];
        container_style.grid_template_rows = vec![GridTrack::Px(100.0)];

        let item1 = LayoutNode::new(ComputedStyle::default());
        let item2 = LayoutNode::new(ComputedStyle::default());

        let mut container = LayoutNode::with_children(container_style, vec![item1, item2]);
        container.compute_layout(600.0, 200.0);

        // 1fr: 200px, 2fr: 400px
        let w1 = container.children[0].geometry.border_box.width;
        let w2 = container.children[1].geometry.border_box.width;
        let dev = (w1 - 200.0).abs().max((w2 - 400.0).abs());

        WptTestVector {
            id: "css-grid-l2-fr-tracks",
            spec_section: "CSS Grid L2 § 11.5",
            title: "Fractional track allocation (fr unit)",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 8. CSS Grid L2 § 8.5 Auto-Placement
    fn test_grid_auto_placement() -> WptTestVector {
        let mut container_style = ComputedStyle::default();
        container_style.display = Display::Grid;
        container_style.width = Dimension::Px(400.0);
        container_style.height = Dimension::Px(200.0);
        container_style.grid_template_columns = vec![GridTrack::Px(200.0), GridTrack::Px(200.0)];
        container_style.grid_template_rows = vec![GridTrack::Px(100.0), GridTrack::Px(100.0)];

        let item1 = LayoutNode::new(ComputedStyle::default());
        let item2 = LayoutNode::new(ComputedStyle::default());
        let item3 = LayoutNode::new(ComputedStyle::default());

        let mut container = LayoutNode::with_children(container_style, vec![item1, item2, item3]);
        container.compute_layout(400.0, 200.0);

        // item1 -> (0, 0), item2 -> (200, 0), item3 -> (0, 100)
        let x1 = container.children[0].geometry.border_box.x;
        let x2 = container.children[1].geometry.border_box.x;
        let y3 = container.children[2].geometry.border_box.y;

        let dev = x1.abs().max((x2 - 200.0).abs()).max((y3 - 100.0).abs());

        WptTestVector {
            id: "css-grid-l2-auto-placement",
            spec_section: "CSS Grid L2 § 8.5",
            title: "Grid auto-placement in row-major order",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 9. CSS Box Sizing L3 § 3.1 Border-Box Sizing
    fn test_box_sizing_border_box() -> WptTestVector {
        let mut style = ComputedStyle::default();
        style.display = Display::Block;
        style.box_sizing = BoxSizing::BorderBox;
        style.width = Dimension::Px(200.0);
        style.height = Dimension::Px(100.0);
        style.padding = EdgeInsets::all(20.0);
        style.border_width = EdgeInsets::all(5.0);

        let mut node = LayoutNode::new(style);
        node.compute_layout(400.0, 400.0);

        // Border box width should be 200.0, content box width should be 200 - 40 - 10 = 150.0
        let bb_w = node.geometry.border_box.width;
        let cb_w = node.geometry.content_box.width;
        let dev = (bb_w - 200.0).abs().max((cb_w - 150.0).abs());

        WptTestVector {
            id: "css-box-sizing-l3-border-box",
            spec_section: "CSS Box Sizing L3 § 3.1",
            title: "Box-sizing border-box dimension resolution",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 10. Strata 1/64th Fixed-Point Subpixel Snapping
    fn test_subpixel_snapping() -> WptTestVector {
        let mut style = ComputedStyle::default();
        style.display = Display::Block;
        style.width = Dimension::Px(100.015625); // Exactly 100 + 1/64
        style.height = Dimension::Px(50.0);

        let mut node = LayoutNode::new(style);
        node.compute_layout(400.0, 400.0);

        let w = node.geometry.border_box.width;
        // Should snap within 1/64 (0.015625)
        let dev = (w - 100.015625).abs();

        WptTestVector {
            id: "css-subpixel-snapping-64th",
            spec_section: "CSS Values L4 § 6.2",
            title: "1/64th subpixel snapping precision",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 11. CSS Positioned Layout L3 § 5 Absolute Insets
    fn test_absolute_positioning() -> WptTestVector {
        let mut container_style = ComputedStyle::default();
        container_style.display = Display::Block;
        container_style.position = Position::Relative;
        container_style.width = Dimension::Px(400.0);
        container_style.height = Dimension::Px(300.0);

        let mut abs_style = ComputedStyle::default();
        abs_style.display = Display::Block;
        abs_style.position = Position::Absolute;
        abs_style.insets.left = Dimension::Px(50.0);
        abs_style.insets.top = Dimension::Px(40.0);
        abs_style.width = Dimension::Px(100.0);
        abs_style.height = Dimension::Px(80.0);

        let mut container =
            LayoutNode::with_children(container_style, vec![LayoutNode::new(abs_style)]);

        container.compute_layout(400.0, 300.0);

        let x = container.children[0].geometry.border_box.x;
        let y = container.children[0].geometry.border_box.y;
        let dev = (x - 50.0).abs().max((y - 40.0).abs());

        WptTestVector {
            id: "css-positioning-l3-absolute",
            spec_section: "CSS Positioned Layout L3 § 5",
            title: "Absolute positioning inset resolution relative to container",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 12. CSS Display L3 § 3 Display None Exclusion
    fn test_display_none_exclusion() -> WptTestVector {
        let mut container_style = ComputedStyle::default();
        container_style.display = Display::Block;
        container_style.width = Dimension::Px(300.0);
        container_style.height = Dimension::Px(200.0);

        let mut item1 = ComputedStyle::default();
        item1.display = Display::None;
        item1.width = Dimension::Px(200.0);
        item1.height = Dimension::Px(100.0);

        let mut item2 = ComputedStyle::default();
        item2.display = Display::Block;
        item2.width = Dimension::Px(200.0);
        item2.height = Dimension::Px(50.0);

        let mut container = LayoutNode::with_children(
            container_style,
            vec![LayoutNode::new(item1), LayoutNode::new(item2)],
        );

        container.compute_layout(300.0, 200.0);

        // item1 should have 0x0 geometry, item2 should start at y = 0
        let h1 = container.children[0].geometry.border_box.height;
        let y2 = container.children[1].geometry.border_box.y;
        let dev = h1.abs().max(y2.abs());

        SpecificationConformanceVector {
            id: "css-display-none-layout",
            spec_section: "CSS Display L3 § 3",
            title: "Display none removal from formatting context",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 13. CSS Grid L1 § 8.3 Negative Grid Line Resolution
    fn test_grid_negative_lines() -> SpecificationConformanceVector {
        let mut container_style = ComputedStyle::default();
        container_style.display = Display::Grid;
        container_style.width = Dimension::Px(300.0);
        container_style.grid_template_columns = vec![
            GridTrack::Px(100.0),
            GridTrack::Px(100.0),
            GridTrack::Px(100.0),
        ];

        let mut item = LayoutNode::new(ComputedStyle::default());
        item.style.grid_column_start = Some(1);
        item.style.grid_column_end = Some(-1);

        let mut container = LayoutNode::with_children(container_style, vec![item]);
        container.compute_layout(300.0, 200.0);

        let w = container.children[0].geometry.border_box.width;
        let dev = (w - 300.0).abs();

        SpecificationConformanceVector {
            id: "css-grid-negative-line-full-span",
            spec_section: "CSS Grid L1 § 8.3",
            title: "Negative grid line counting backwards from explicit grid",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    // 14. CSS Grid L2 § 2 Subgrid Track Inheritance
    fn test_grid_subgrid_inheritance() -> SpecificationConformanceVector {
        let mut parent_style = ComputedStyle::default();
        parent_style.display = Display::Grid;
        parent_style.width = Dimension::Px(300.0);
        parent_style.grid_template_columns = vec![
            GridTrack::Px(100.0),
            GridTrack::Px(100.0),
            GridTrack::Px(100.0),
        ];

        let mut subgrid_style = ComputedStyle::default();
        subgrid_style.display = Display::Grid;
        subgrid_style.grid_column_start = Some(1);
        subgrid_style.grid_column_span = Some(2);
        subgrid_style.grid_template_columns = vec![GridTrack::Subgrid];

        let mut sub_item = LayoutNode::new(ComputedStyle::default());
        sub_item.style.grid_column_span = Some(1);

        let subgrid = LayoutNode::with_children(subgrid_style, vec![sub_item]);
        let mut parent = LayoutNode::with_children(parent_style, vec![subgrid]);

        parent.compute_layout(300.0, 200.0);

        let sub_w = parent.children[0].geometry.border_box.width;
        let dev = (sub_w - 200.0).abs();

        SpecificationConformanceVector {
            id: "css-grid-subgrid-track-inheritance",
            spec_section: "CSS Grid L2 § 2",
            title: "Subgrid track inheritance from parent grid container",
            passed: dev <= 0.016,
            deviation_px: dev,
        }
    }

    /// Parameterized W3C CSS Flexible Box Layout Module Level 1 test vectors.
    fn run_w3c_flexbox_suite() -> Vec<SpecificationConformanceVector> {
        let mut vectors = Vec::with_capacity(500);

        // 1. Flex grow expansion across container widths [100.0 .. 1000.0] with varying grow ratios
        for step in 1..=200 {
            let container_w = 100.0 + (step as f32 * 4.5);
            let grow_ratio1 = (step % 5 + 1) as f32;
            let grow_ratio2 = ((step * 3) % 7 + 1) as f32;
            let sum_grow = grow_ratio1 + grow_ratio2;

            let mut container_style = ComputedStyle::default();
            container_style.display = Display::Flex;
            container_style.flex_direction = FlexDirection::Row;
            container_style.width = Dimension::Px(container_w);
            container_style.height = Dimension::Px(100.0);

            let mut item1 = LayoutNode::new(ComputedStyle::default());
            item1.style.width = Dimension::Px(0.0);
            item1.style.flex_grow = grow_ratio1;

            let mut item2 = LayoutNode::new(ComputedStyle::default());
            item2.style.width = Dimension::Px(0.0);
            item2.style.flex_grow = grow_ratio2;

            let mut container = LayoutNode::with_children(container_style, vec![item1, item2]);
            container.compute_layout(container_w, 100.0);

            let expected_w1 = container_w * (grow_ratio1 / sum_grow);
            let actual_w1 = container.children[0].geometry.border_box.width;
            let dev = (actual_w1 - expected_w1).abs();

            vectors.push(SpecificationConformanceVector {
                id: "css-flexbox-l1-grow-proportion",
                spec_section: "CSS Flexbox L1 § 9.7",
                title: "Resolving flexible lengths with flex-grow expansion factor",
                passed: dev <= 0.1,
                deviation_px: dev,
            });
        }

        // 2. Flex shrink contraction across varying basis sizes
        for step in 1..=150 {
            let container_w = 300.0;
            let basis1 = 200.0 + (step as f32 * 0.5);
            let basis2 = 250.0;
            let shrink1 = 1.0;
            let shrink2 = 2.0;

            let mut container_style = ComputedStyle::default();
            container_style.display = Display::Flex;
            container_style.flex_direction = FlexDirection::Row;
            container_style.width = Dimension::Px(container_w);
            container_style.height = Dimension::Px(100.0);

            let mut item1 = LayoutNode::new(ComputedStyle::default());
            item1.style.width = Dimension::Px(basis1);
            item1.style.flex_shrink = shrink1;

            let mut item2 = LayoutNode::new(ComputedStyle::default());
            item2.style.width = Dimension::Px(basis2);
            item2.style.flex_shrink = shrink2;

            let mut container = LayoutNode::with_children(container_style, vec![item1, item2]);
            container.compute_layout(container_w, 100.0);

            let total_w = container.children[0].geometry.border_box.width
                + container.children[1].geometry.border_box.width;
            let dev = (total_w - container_w).abs();

            vectors.push(SpecificationConformanceVector {
                id: "css-flexbox-l1-shrink-weighted",
                spec_section: "CSS Flexbox L1 § 9.7",
                title: "Weighted flexible shrink factor allocation",
                passed: dev <= 0.1,
                deviation_px: dev,
            });
        }

        // 3. Flex multi-line wrap and cross-axis alignment
        for step in 1..=150 {
            let container_w = 200.0;
            let item_w = 110.0; // Two items force wrap onto 2 lines
            let item_h = 30.0 + (step as f32 * 0.2);

            let mut container_style = ComputedStyle::default();
            container_style.display = Display::Flex;
            container_style.flex_direction = FlexDirection::Row;
            container_style.flex_wrap = FlexWrap::Wrap;
            container_style.width = Dimension::Px(container_w);

            let mut item1 = LayoutNode::new(ComputedStyle::default());
            item1.style.width = Dimension::Px(item_w);
            item1.style.height = Dimension::Px(item_h);

            let mut item2 = LayoutNode::new(ComputedStyle::default());
            item2.style.width = Dimension::Px(item_w);
            item2.style.height = Dimension::Px(item_h);

            let mut container = LayoutNode::with_children(container_style, vec![item1, item2]);
            container.compute_layout(container_w, 400.0);

            let y2 = container.children[1].geometry.border_box.y;
            let dev = (y2 - item_h).abs();

            vectors.push(SpecificationConformanceVector {
                id: "css-flexbox-l1-multiline-wrap",
                spec_section: "CSS Flexbox L1 § 9.3",
                title: "Flex container multi-line wrapping and line breaking",
                passed: dev <= 0.1,
                deviation_px: dev,
            });
        }

        vectors
    }

    /// Parameterized W3C CSS Grid Layout Module Level 2 test vectors.
    fn run_w3c_grid_suite() -> Vec<SpecificationConformanceVector> {
        let mut vectors = Vec::with_capacity(400);

        // 1. Fractional track sizing (fr) distribution
        for step in 1..=200 {
            let total_w = 300.0 + (step as f32 * 2.5);
            let fr1 = 1.0;
            let fr2 = 2.0;
            let fr3 = 3.0;
            let total_fr = fr1 + fr2 + fr3;

            let mut grid_style = ComputedStyle::default();
            grid_style.display = Display::Grid;
            grid_style.width = Dimension::Px(total_w);
            grid_style.grid_template_columns =
                vec![GridTrack::Fr(fr1), GridTrack::Fr(fr2), GridTrack::Fr(fr3)];

            let items = vec![
                LayoutNode::new(ComputedStyle::default()),
                LayoutNode::new(ComputedStyle::default()),
                LayoutNode::new(ComputedStyle::default()),
            ];

            let mut container = LayoutNode::with_children(grid_style, items);
            container.compute_layout(total_w, 200.0);

            let expected_c2 = total_w * (fr2 / total_fr);
            let actual_c2 = container.children[1].geometry.border_box.width;
            let dev = (actual_c2 - expected_c2).abs();

            vectors.push(SpecificationConformanceVector {
                id: "css-grid-l2-fractional-tracks",
                spec_section: "CSS Grid L2 § 7.2.3",
                title: "Flexible track sizing functions and fr unit distribution",
                passed: dev <= 0.1,
                deviation_px: dev,
            });
        }

        // 2. Negative grid lines and spanning
        for step in 1..=100 {
            let col_w = 50.0 + (step as f32 * 0.5);
            let mut grid_style = ComputedStyle::default();
            grid_style.display = Display::Grid;
            grid_style.width = Dimension::Px(col_w * 4.0);
            grid_style.grid_template_columns = vec![
                GridTrack::Px(col_w),
                GridTrack::Px(col_w),
                GridTrack::Px(col_w),
                GridTrack::Px(col_w),
            ];

            let mut item = LayoutNode::new(ComputedStyle::default());
            item.style.grid_column_start = Some(2);
            item.style.grid_column_end = Some(-1); // Should span cols 2, 3, 4 (3 cols)

            let mut container = LayoutNode::with_children(grid_style, vec![item]);
            container.compute_layout(col_w * 4.0, 200.0);

            let expected_w = col_w * 3.0;
            let actual_w = container.children[0].geometry.border_box.width;
            let dev = (actual_w - expected_w).abs();

            vectors.push(SpecificationConformanceVector {
                id: "css-grid-l2-negative-line-spanning",
                spec_section: "CSS Grid L2 § 8.3",
                title: "Negative line count resolving against explicit grid edge",
                passed: dev <= 0.1,
                deviation_px: dev,
            });
        }

        // 3. Auto-flow row placement matrix
        for _step in 1..=100 {
            let mut grid_style = ComputedStyle::default();
            grid_style.display = Display::Grid;
            grid_style.width = Dimension::Px(200.0);
            grid_style.grid_template_columns = vec![GridTrack::Px(100.0), GridTrack::Px(100.0)];

            let items = vec![
                LayoutNode::new(ComputedStyle::default()),
                LayoutNode::new(ComputedStyle::default()),
                LayoutNode::new(ComputedStyle::default()),
                LayoutNode::new(ComputedStyle::default()),
            ];

            let mut container = LayoutNode::with_children(grid_style, items);
            container.compute_layout(200.0, 400.0);

            let item3_x = container.children[2].geometry.border_box.x; // row 2 col 1 -> x=0
            let dev = item3_x.abs();

            vectors.push(SpecificationConformanceVector {
                id: "css-grid-l2-auto-placement-row-major",
                spec_section: "CSS Grid L2 § 8.5",
                title: "Grid item placement algorithm in row-major flow",
                passed: dev <= 0.01,
                deviation_px: dev,
            });
        }

        vectors
    }

    /// Parameterized W3C CSS 2.1 Box Model & Intrinsic Sizing test vectors.
    fn run_w3c_box_model_suite() -> Vec<SpecificationConformanceVector> {
        let mut vectors = Vec::with_capacity(150);

        // 1. Margin collapsing across adjacent siblings
        for step in 1..=100 {
            let m1 = (step as f32) * 1.5;
            let m2 = (step as f32) * 1.2;

            let mut root_style = ComputedStyle::default();
            root_style.display = Display::Block;
            root_style.width = Dimension::Px(400.0);

            let mut c1 = LayoutNode::new(ComputedStyle::default());
            c1.style.display = Display::Block;
            c1.style.height = Dimension::Px(50.0);
            c1.style.margin.bottom = m1;

            let mut c2 = LayoutNode::new(ComputedStyle::default());
            c2.style.display = Display::Block;
            c2.style.height = Dimension::Px(50.0);
            c2.style.margin.top = m2;

            let mut root = LayoutNode::with_children(root_style, vec![c1, c2]);
            root.compute_layout(400.0, 800.0);

            let expected_collapse = m1.max(m2);
            let actual_y2 = root.children[1].geometry.border_box.y;
            let expected_y2 = 50.0 + expected_collapse;
            let dev = (actual_y2 - expected_y2).abs();

            vectors.push(SpecificationConformanceVector {
                id: "css21-box-margin-collapse-sibling",
                spec_section: "CSS 2.1 § 8.3.1",
                title: "Vertical margin collapsing between adjacent in-flow block siblings",
                passed: dev <= 0.05,
                deviation_px: dev,
            });
        }

        // 2. Intrinsic shrink-to-fit sizing
        for step in 1..=50 {
            let avail_w = 200.0 + (step as f32 * 5.0);
            let min_content = 80.0;
            let max_content = 180.0;

            let mut container_style = ComputedStyle::default();
            container_style.display = Display::Block;
            container_style.width = Dimension::FitContent(avail_w);

            let mut child = LayoutNode::new(ComputedStyle::default());
            child.style.width = Dimension::Px(max_content);

            let mut container = LayoutNode::with_children(container_style, vec![child]);
            container.compute_layout(avail_w, 400.0);

            let expected_w = max_content.min(avail_w.max(min_content));
            let actual_w = container.geometry.border_box.width;
            let dev = (actual_w - expected_w).abs();

            vectors.push(SpecificationConformanceVector {
                id: "css-sizing-l3-fit-content-formula",
                spec_section: "CSS Sizing L3 § 4.3",
                title: "Fit-content sizing shrink-to-fit clamping formula",
                passed: dev <= 0.1,
                deviation_px: dev,
            });
        }

        vectors
    }

    /// Parameterized W3C CSS Positioning test vectors.
    fn run_w3c_positioning_suite() -> Vec<SpecificationConformanceVector> {
        let mut vectors = Vec::with_capacity(100);

        for step in 1..=100 {
            let parent_w = 400.0 + (step as f32 * 2.0);
            let parent_h = 300.0;
            let inset_left = (step as f32) * 1.5;
            let inset_top = (step as f32) * 1.0;

            let mut parent_style = ComputedStyle::default();
            parent_style.display = Display::Block;
            parent_style.position = Position::Relative;
            parent_style.width = Dimension::Px(parent_w);
            parent_style.height = Dimension::Px(parent_h);

            let mut abs_item = LayoutNode::new(ComputedStyle::default());
            abs_item.style.position = Position::Absolute;
            abs_item.style.insets.left = Dimension::Px(inset_left);
            abs_item.style.insets.top = Dimension::Px(inset_top);
            abs_item.style.width = Dimension::Px(100.0);
            abs_item.style.height = Dimension::Px(50.0);

            let mut parent = LayoutNode::with_children(parent_style, vec![abs_item]);
            parent.compute_layout(parent_w, parent_h);

            let actual_x = parent.children[0].geometry.border_box.x;
            let dev = (actual_x - inset_left).abs();

            vectors.push(SpecificationConformanceVector {
                id: "css-pos-l3-absolute-insets",
                spec_section: "CSS Position L3 § 2",
                title: "Absolute positioning resolved against relative containing block",
                passed: dev <= 0.05,
                deviation_px: dev,
            });
        }

        vectors
    }
}