1
//! Builder function to convert CssPropertyCache → CompactLayoutCache.
2
//!
3
//! Called once after restyle + apply_ua_css + compute_inherited_values.
4
//! Uses typed getters on CssPropertyCache (which cascade through all sources)
5
//! to resolve each property for the "normal" state (all pseudo-states = false).
6

            
7
use alloc::vec::Vec;
8
use core::hash::{Hash, Hasher};
9

            
10
#[allow(clippy::wildcard_imports)]
11
use azul_css::compact_cache::*;
12
use azul_css::{
13
    css::CssPropertyValue,
14
    props::{
15
        basic::length::SizeMetric,
16
        layout::{
17
            dimensions::{LayoutHeight, LayoutWidth},
18
            flex::LayoutFlexBasis,
19
            position::LayoutZIndex,
20
        },
21
        property::CssProperty,
22
    },
23
};
24

            
25
// wildcard import: this module is the consumer of the whole compact_cache codec
26
// (encode/decode helpers + sentinel consts); enumerating them is unmaintainable.
27
use crate::hash::DefaultHasher;
28
use crate::{
29
    dom::{NodeData, NodeId},
30
    prop_cache::CssPropertyCache,
31
    styled_dom::StyledNodeState,
32
};
33

            
34
impl CssPropertyCache {
35
    /// Build a `CompactLayoutCache` from the current property cache state.
36
    ///
37
    /// Must be called after `restyle()`, `apply_ua_css()`, and `compute_inherited_values()`.
38
    /// Resolves all layout-relevant properties for every node in the "normal" state
39
    /// (no hover/active/focus) and encodes them into compact arrays.
40
    ///
41
    /// Tier 1/2/2b provide fast-path access for layout-hot properties.
42
    /// Non-compact properties (background, transform, box-shadow, etc.) are
43
    /// resolved via the slow cascade path in `get_property_slow()`.
44
    ///
45
    /// `prev_font_hashes` is the per-node font hash array from the previous frame.
46
    /// When non-empty, each node's new `font_family_hash` is compared against the
47
    /// previous value, and differing nodes are recorded in `font_dirty_nodes`.
48
    /// On the first build (empty slice), ALL text nodes are marked dirty.
49
    // fixed-point encoders: z-index and line-height (%×10) are range-checked
50
    // against the i16 sentinel threshold before the deliberate narrowing cast.
51
    #[allow(clippy::cast_possible_truncation)]
52
    #[allow(clippy::similar_names)] // domain-standard coordinate/control-point names
53
    #[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive:
54
                                                                   // single-purpose
55
                                                                   // parser/builder/dispatch (one
56
                                                                   // branch per input variant)
57
8
    pub fn build_compact_cache(
58
8
        &self,
59
8
        node_data: &[NodeData],
60
8
        prev_font_hashes: &[u64],
61
8
    ) -> CompactLayoutCache {
62
8
        let node_count = self.node_count;
63
8
        let default_state = StyledNodeState::default();
64
8
        let mut result = CompactLayoutCache::with_capacity(node_count);
65

            
66
19
        for (i, nd) in node_data.iter().enumerate().take(node_count) {
67
19
            let node_id = NodeId::new(i);
68

            
69
            // =====================================================================
70
            // Tier 1: Encode all 20 enum properties into u64
71
            // =====================================================================
72

            
73
19
            let display = self
74
19
                .get_display(nd, &node_id, &default_state)
75
19
                .and_then(|v| v.get_property().copied())
76
19
                .unwrap_or_default();
77
19
            let position = self
78
19
                .get_position(nd, &node_id, &default_state)
79
19
                .and_then(|v| v.get_property().copied())
80
19
                .unwrap_or_default();
81
19
            let float = self
82
19
                .get_float(nd, &node_id, &default_state)
83
19
                .and_then(|v| v.get_property().copied())
84
19
                .unwrap_or_default();
85
19
            let overflow_x = self
86
19
                .get_overflow_x(nd, &node_id, &default_state)
87
19
                .and_then(|v| v.get_property().copied())
88
19
                .unwrap_or_default();
89
19
            let overflow_y = self
90
19
                .get_overflow_y(nd, &node_id, &default_state)
91
19
                .and_then(|v| v.get_property().copied())
92
19
                .unwrap_or_default();
93
19
            let box_sizing = self
94
19
                .get_box_sizing(nd, &node_id, &default_state)
95
19
                .and_then(|v| v.get_property().copied())
96
19
                .unwrap_or_default();
97
19
            let flex_direction = self
98
19
                .get_flex_direction(nd, &node_id, &default_state)
99
19
                .and_then(|v| v.get_property().copied())
100
19
                .unwrap_or_default();
101
19
            let flex_wrap = self
102
19
                .get_flex_wrap(nd, &node_id, &default_state)
103
19
                .and_then(|v| v.get_property().copied())
104
19
                .unwrap_or_default();
105
19
            let justify_content = self
106
19
                .get_justify_content(nd, &node_id, &default_state)
107
19
                .and_then(|v| v.get_property().copied())
108
19
                .unwrap_or_default();
109
19
            let align_items = self
110
19
                .get_align_items(nd, &node_id, &default_state)
111
19
                .and_then(|v| v.get_property().copied())
112
19
                .unwrap_or_default();
113
19
            let align_content = self
114
19
                .get_align_content(nd, &node_id, &default_state)
115
19
                .and_then(|v| v.get_property().copied())
116
19
                .unwrap_or_default();
117
19
            let writing_mode = self
118
19
                .get_writing_mode(nd, &node_id, &default_state)
119
19
                .and_then(|v| v.get_property().copied())
120
19
                .unwrap_or_default();
121
19
            let clear = self
122
19
                .get_clear(nd, &node_id, &default_state)
123
19
                .and_then(|v| v.get_property().copied())
124
19
                .unwrap_or_default();
125
19
            let font_weight = self
126
19
                .get_font_weight(nd, &node_id, &default_state)
127
19
                .and_then(|v| v.get_property().copied())
128
19
                .unwrap_or_default();
129
19
            let font_style = self
130
19
                .get_font_style(nd, &node_id, &default_state)
131
19
                .and_then(|v| v.get_property().copied())
132
19
                .unwrap_or_default();
133
19
            let text_align = self
134
19
                .get_text_align(nd, &node_id, &default_state)
135
19
                .and_then(|v| v.get_property().copied())
136
19
                .unwrap_or_default();
137
19
            let visibility = self
138
19
                .get_visibility(nd, &node_id, &default_state)
139
19
                .and_then(|v| v.get_property().copied())
140
19
                .unwrap_or_default();
141
19
            let white_space = self
142
19
                .get_white_space(nd, &node_id, &default_state)
143
19
                .and_then(|v| v.get_property().copied())
144
19
                .unwrap_or_default();
145
19
            let direction = self
146
19
                .get_direction(nd, &node_id, &default_state)
147
19
                .and_then(|v| v.get_property().copied())
148
19
                .unwrap_or_default();
149
19
            let vertical_align = self
150
19
                .get_vertical_align(nd, &node_id, &default_state)
151
19
                .and_then(|v| v.get_property().copied())
152
19
                .unwrap_or_default();
153

            
154
19
            let border_collapse = self
155
19
                .get_border_collapse(nd, &node_id, &default_state)
156
19
                .and_then(|v| v.get_property().copied())
157
19
                .unwrap_or_default();
158

            
159
19
            result.tier1_enums[i] = encode_tier1(
160
19
                display,
161
19
                position,
162
19
                float,
163
19
                overflow_x,
164
19
                overflow_y,
165
19
                box_sizing,
166
19
                flex_direction,
167
19
                flex_wrap,
168
19
                justify_content,
169
19
                align_items,
170
19
                align_content,
171
19
                writing_mode,
172
19
                clear,
173
19
                font_weight,
174
19
                font_style,
175
19
                text_align,
176
19
                visibility,
177
19
                white_space,
178
19
                direction,
179
19
                vertical_align,
180
19
                border_collapse,
181
19
            );
182

            
183
            // =====================================================================
184
            // Tier 2: Encode numeric dimension properties
185
            // =====================================================================
186

            
187
            // Width/Height are enums: Auto | Px(PixelValue) | MinContent | MaxContent | Calc
188
19
            if let Some(val) = self.get_width(nd, &node_id, &default_state) {
189
                result.tier2_dims[i].width = encode_layout_width(val);
190
19
            }
191
19
            if let Some(val) = self.get_height(nd, &node_id, &default_state) {
192
                result.tier2_dims[i].height = encode_layout_height(val);
193
19
            }
194

            
195
            // Min/Max Width/Height are simple PixelValue wrappers
196
19
            if let Some(val) = self.get_min_width(nd, &node_id, &default_state) {
197
                result.tier2_dims[i].min_width = encode_pixel_prop(val);
198
19
            }
199
19
            if let Some(val) = self.get_max_width(nd, &node_id, &default_state) {
200
                result.tier2_dims[i].max_width = encode_pixel_prop(val);
201
19
            }
202
19
            if let Some(val) = self.get_min_height(nd, &node_id, &default_state) {
203
                result.tier2_dims[i].min_height = encode_pixel_prop(val);
204
19
            }
205
19
            if let Some(val) = self.get_max_height(nd, &node_id, &default_state) {
206
                result.tier2_dims[i].max_height = encode_pixel_prop(val);
207
19
            }
208

            
209
            // Flex basis (enum: Auto | Exact(PixelValue))
210
19
            if let Some(val) = self.get_flex_basis(nd, &node_id, &default_state) {
211
                result.tier2_dims[i].flex_basis = encode_flex_basis(val);
212
19
            }
213

            
214
            // Font size
215
19
            if let Some(val) = self.get_font_size(nd, &node_id, &default_state) {
216
                result.tier2_dims[i].font_size = encode_pixel_prop(val);
217
19
            }
218

            
219
            // Padding (i16 × 10 resolved px)
220
19
            if let Some(val) = self.get_padding_top(nd, &node_id, &default_state) {
221
                result.tier2_dims[i].padding_top = encode_css_pixel_as_i16(val);
222
19
            }
223
19
            if let Some(val) = self.get_padding_right(nd, &node_id, &default_state) {
224
                result.tier2_dims[i].padding_right = encode_css_pixel_as_i16(val);
225
19
            }
226
19
            if let Some(val) = self.get_padding_bottom(nd, &node_id, &default_state) {
227
                result.tier2_dims[i].padding_bottom = encode_css_pixel_as_i16(val);
228
19
            }
229
19
            if let Some(val) = self.get_padding_left(nd, &node_id, &default_state) {
230
                result.tier2_dims[i].padding_left = encode_css_pixel_as_i16(val);
231
19
            }
232

            
233
            // Margin (i16, auto is special)
234
19
            if let Some(val) = self.get_margin_top(nd, &node_id, &default_state) {
235
                result.tier2_dims[i].margin_top = encode_margin_i16(val);
236
19
            }
237
19
            if let Some(val) = self.get_margin_right(nd, &node_id, &default_state) {
238
                result.tier2_dims[i].margin_right = encode_margin_i16(val);
239
19
            }
240
19
            if let Some(val) = self.get_margin_bottom(nd, &node_id, &default_state) {
241
                result.tier2_dims[i].margin_bottom = encode_margin_i16(val);
242
19
            }
243
19
            if let Some(val) = self.get_margin_left(nd, &node_id, &default_state) {
244
                result.tier2_dims[i].margin_left = encode_margin_i16(val);
245
19
            }
246

            
247
            // Border widths (i16 × 10 resolved px)
248
19
            if let Some(val) = self.get_border_top_width(nd, &node_id, &default_state) {
249
                result.tier2_dims[i].border_top_width = encode_css_pixel_as_i16(val);
250
19
            }
251
19
            if let Some(val) = self.get_border_right_width(nd, &node_id, &default_state) {
252
                result.tier2_dims[i].border_right_width = encode_css_pixel_as_i16(val);
253
19
            }
254
19
            if let Some(val) = self.get_border_bottom_width(nd, &node_id, &default_state) {
255
                result.tier2_dims[i].border_bottom_width = encode_css_pixel_as_i16(val);
256
19
            }
257
19
            if let Some(val) = self.get_border_left_width(nd, &node_id, &default_state) {
258
                result.tier2_dims[i].border_left_width = encode_css_pixel_as_i16(val);
259
19
            }
260

            
261
            // Position offsets (top/right/bottom/left)
262
19
            if let Some(val) = self.get_top(nd, &node_id, &default_state) {
263
                result.tier2_dims[i].top = encode_css_pixel_as_i16(val);
264
19
            }
265
19
            if let Some(val) = self.get_right(nd, &node_id, &default_state) {
266
                result.tier2_dims[i].right = encode_css_pixel_as_i16(val);
267
19
            }
268
19
            if let Some(val) = self.get_bottom(nd, &node_id, &default_state) {
269
                result.tier2_dims[i].bottom = encode_css_pixel_as_i16(val);
270
19
            }
271
19
            if let Some(val) = self.get_left(nd, &node_id, &default_state) {
272
                result.tier2_dims[i].left = encode_css_pixel_as_i16(val);
273
19
            }
274

            
275
            // Flex grow/shrink (u16 × 100)
276
19
            if let Some(val) = self.get_flex_grow(nd, &node_id, &default_state) {
277
                if let Some(exact) = val.get_property() {
278
                    result.tier2_dims[i].flex_grow = encode_flex_u16(exact.inner.get());
279
                }
280
19
            }
281
19
            if let Some(val) = self.get_flex_shrink(nd, &node_id, &default_state) {
282
                if let Some(exact) = val.get_property() {
283
                    result.tier2_dims[i].flex_shrink = encode_flex_u16(exact.inner.get());
284
                }
285
19
            }
286

            
287
            // =====================================================================
288
            // Tier 2 cold: Paint-only properties
289
            // =====================================================================
290

            
291
            // Z-index
292
19
            if let Some(val) = self.get_z_index(nd, &node_id, &default_state) {
293
                if let Some(exact) = val.get_property() {
294
                    match exact {
295
                        LayoutZIndex::Auto => result.tier2_cold[i].z_index = I16_AUTO,
296
                        LayoutZIndex::Integer(z) => {
297
                            // Two-sided, like the line-height encoder: a large NEGATIVE z
298
                            // used to fall through to `*z as i16` and WRAP positive
299
                            // (-40000 -> +25536). Escape both out-of-range ends to the
300
                            // sentinel (tier 3) so the real value is preserved.
301
                            result.tier2_cold[i].z_index =
302
                                if *z >= -32768 && *z < i32::from(I16_SENTINEL_THRESHOLD) {
303
                                    *z as i16
304
                                } else {
305
                                    I16_SENTINEL
306
                                };
307
                        }
308
                    }
309
                }
310
19
            }
311

            
312
            // Border styles (packed into u16)
313
            {
314
19
                let bts = self
315
19
                    .get_border_top_style(nd, &node_id, &default_state)
316
19
                    .and_then(|v| v.get_property().copied())
317
19
                    .map(|v| v.inner)
318
19
                    .unwrap_or_default();
319
19
                let brs = self
320
19
                    .get_border_right_style(nd, &node_id, &default_state)
321
19
                    .and_then(|v| v.get_property().copied())
322
19
                    .map(|v| v.inner)
323
19
                    .unwrap_or_default();
324
19
                let bbs = self
325
19
                    .get_border_bottom_style(nd, &node_id, &default_state)
326
19
                    .and_then(|v| v.get_property().copied())
327
19
                    .map(|v| v.inner)
328
19
                    .unwrap_or_default();
329
19
                let bls = self
330
19
                    .get_border_left_style(nd, &node_id, &default_state)
331
19
                    .and_then(|v| v.get_property().copied())
332
19
                    .map(|v| v.inner)
333
19
                    .unwrap_or_default();
334
19
                result.tier2_cold[i].border_styles_packed =
335
19
                    encode_border_styles_packed(bts, brs, bbs, bls);
336
            }
337

            
338
            // Border colors (ColorU → u32 as 0xRRGGBBAA)
339
19
            if let Some(val) = self.get_border_top_color(nd, &node_id, &default_state) {
340
                if let Some(color) = val.get_property() {
341
                    result.tier2_cold[i].border_top_color = encode_color_u32(&color.inner);
342
                }
343
19
            }
344
19
            if let Some(val) = self.get_border_right_color(nd, &node_id, &default_state) {
345
                if let Some(color) = val.get_property() {
346
                    result.tier2_cold[i].border_right_color = encode_color_u32(&color.inner);
347
                }
348
19
            }
349
19
            if let Some(val) = self.get_border_bottom_color(nd, &node_id, &default_state) {
350
                if let Some(color) = val.get_property() {
351
                    result.tier2_cold[i].border_bottom_color = encode_color_u32(&color.inner);
352
                }
353
19
            }
354
19
            if let Some(val) = self.get_border_left_color(nd, &node_id, &default_state) {
355
                if let Some(color) = val.get_property() {
356
                    result.tier2_cold[i].border_left_color = encode_color_u32(&color.inner);
357
                }
358
19
            }
359

            
360
            // Border spacing (two PixelValue → i16 × 10 resolved px)
361
19
            if let Some(val) = self.get_border_spacing(nd, &node_id, &default_state) {
362
                if let Some(spacing) = val.get_property() {
363
                    if spacing.horizontal.metric == SizeMetric::Px {
364
                        result.tier2_cold[i].border_spacing_h =
365
                            encode_resolved_px_i16(spacing.horizontal.number.get());
366
                    }
367
                    if spacing.vertical.metric == SizeMetric::Px {
368
                        result.tier2_cold[i].border_spacing_v =
369
                            encode_resolved_px_i16(spacing.vertical.number.get());
370
                    }
371
                }
372
19
            }
373

            
374
            // Tab size (PixelValue → i16 × 10 resolved px)
375
19
            if let Some(val) = self.get_tab_size(nd, &node_id, &default_state) {
376
                result.tier2_cold[i].tab_size = encode_css_pixel_as_i16(val);
377
19
            }
378

            
379
            // =====================================================================
380
            // Tier 2b: Text properties
381
            // =====================================================================
382

            
383
            // Text color (ColorU → u32 as 0xRRGGBBAA)
384
19
            if let Some(val) = self.get_text_color(nd, &node_id, &default_state) {
385
7
                if let Some(color) = val.get_property() {
386
7
                    let c = &color.inner;
387
7
                    result.tier2b_text[i].text_color = (u32::from(c.r) << 24)
388
7
                        | (u32::from(c.g) << 16)
389
7
                        | (u32::from(c.b) << 8)
390
7
                        | u32::from(c.a);
391
7
                }
392
12
            }
393

            
394
            // Font-family (hash the whole StyleFontFamilyVec for fast comparison)
395
19
            if let Some(val) = self.get_font_family(nd, &node_id, &default_state) {
396
                if let Some(families) = val.get_property() {
397
                    let mut hasher = DefaultHasher::new();
398
                    families.hash(&mut hasher);
399
                    let h = hasher.finish();
400
                    let h = if h == 0 { 1 } else { h };
401
                    result.tier2b_text[i].font_family_hash = h;
402
                    result.font_hash_to_families.insert(h, families.clone());
403
                }
404
19
            }
405

            
406
            // Line-height. Parser convention: a NEGATIVE normalized() is an
407
            // ABSOLUTE pixel line-height, a positive one a unitless multiple
408
            // (or percentage) of font-size. The two need different i16
409
            // scales:
410
            //  - positive: multiple × 1000 (120% -> 1200; range up to ~32x)
411
            //  - negative: -px × 10 (line-height: 40px -> -400; ±3276.7px)
412
            // The old single ×1000 scale overflowed i16 for any absolute
413
            // line-height above 32.76px, stored the SENTINEL, and the getter
414
            // decoded that as "line-height: normal" - `line-height: 40px`
415
            // was silently dropped on every normal-state node.
416
19
            if let Some(val) = self.get_line_height(nd, &node_id, &default_state) {
417
                if let Some(lh) = val.get_property() {
418
                    let n = lh.inner.normalized();
419
                    let stored = if n < 0.0 {
420
                        // Absolute px: clamp to the representable range
421
                        // instead of falling to the sentinel ("normal").
422
                        ((n * 10.0).round() as i32).max(-32768)
423
                    } else {
424
                        (n * 1000.0).round() as i32
425
                    };
426
                    if stored >= -32768 && stored < i32::from(I16_SENTINEL_THRESHOLD) {
427
                        result.tier2b_text[i].line_height = stored as i16;
428
                    } else {
429
                        result.tier2b_text[i].line_height = I16_SENTINEL;
430
                    }
431
                }
432
19
            }
433

            
434
            // Letter-spacing (PixelValue wrapper → i16 × 10 resolved px)
435
19
            if let Some(val) = self.get_letter_spacing(nd, &node_id, &default_state) {
436
                result.tier2b_text[i].letter_spacing = encode_css_pixel_as_i16(val);
437
19
            }
438

            
439
            // Word-spacing (PixelValue wrapper → i16 × 10 resolved px)
440
19
            if let Some(val) = self.get_word_spacing(nd, &node_id, &default_state) {
441
                result.tier2b_text[i].word_spacing = encode_css_pixel_as_i16(val);
442
19
            }
443

            
444
            // Text-indent (PixelValue wrapper → i16 × 10 resolved px)
445
19
            if let Some(val) = self.get_text_indent(nd, &node_id, &default_state) {
446
                result.tier2b_text[i].text_indent = encode_css_pixel_as_i16(val);
447
19
            }
448
        }
449

            
450
        // =====================================================================
451
        // Per-node font dirty tracking (P4)
452
        // Compare each node's font_family_hash against the previous frame's hash.
453
        // Nodes whose hash changed are recorded in font_dirty_nodes for
454
        // incremental font chain re-resolution instead of all-or-nothing.
455
        // =====================================================================
456
8
        result.font_dirty_nodes.clear();
457
21
        for i in 0..node_count {
458
21
            let new_hash = result.tier2b_text[i].font_family_hash;
459
21
            let old_hash = prev_font_hashes.get(i).copied().unwrap_or(0);
460
21
            if new_hash != old_hash {
461
4
                result.font_dirty_nodes.push(i);
462
17
            }
463
        }
464
        // Save current hashes as prev_font_hashes for next frame comparison
465
8
        result.prev_font_hashes = result
466
8
            .tier2b_text
467
8
            .iter()
468
8
            .map(|t| t.font_family_hash)
469
8
            .collect();
470

            
471
8
        result
472
8
    }
473

            
474
    /// Build compact cache with inheritance in a single pass.
475
    ///
476
    /// Replaces the separate `compute_inherited_values()` + `build_compact_cache()` calls.
477
    /// For each node (in DOM index order, which is pre-order = parents before children):
478
    ///   1. Copy parent's compact values for INHERITABLE properties
479
    ///   2. Apply this node's CSS properties on top (from `css_props` + inline + UA)
480
    ///   3. Write directly to compact arrays
481
    ///
482
    /// This eliminates 50K Vec clones from `compute_inherited_values` and
483
    /// avoids re-reading properties from 5 separate data structures.
484
51932
    pub fn build_compact_cache_with_inheritance(
485
51932
        &self,
486
51932
        node_data: &[NodeData],
487
51932
        node_hierarchy: &[crate::styled_dom::NodeHierarchyItem],
488
51932
        prev_font_hashes: &[u64],
489
51932
    ) -> CompactLayoutCache {
490
51932
        self.build_compact_cache_with_inheritance_debug(
491
51932
            node_data,
492
51932
            node_hierarchy,
493
51932
            prev_font_hashes,
494
51932
            &mut None,
495
        )
496
51932
    }
497

            
498
    /// Same as `build_compact_cache_with_inheritance` but with optional debug logging.
499
    #[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive:
500
                                                                   // single-purpose
501
                                                                   // parser/builder/dispatch (one
502
                                                                   // branch per input variant)
503
51935
    pub fn build_compact_cache_with_inheritance_debug(
504
51935
        &self,
505
51935
        node_data: &[NodeData],
506
51935
        node_hierarchy: &[crate::styled_dom::NodeHierarchyItem],
507
51935
        prev_font_hashes: &[u64],
508
51935
        debug_messages: &mut Option<Vec<azul_css::LayoutDebugMessage>>,
509
51935
    ) -> CompactLayoutCache {
510
51935
        let node_count = self.node_count;
511
51935
        let default_state = StyledNodeState::default();
512
51935
        let mut result = CompactLayoutCache::with_capacity(node_count);
513

            
514
        // Pre-encode global CSS properties (from `*` rules) into compact form.
515
        // These are applied as baseline for every node before inheritance.
516
51935
        let mut global_tier1: u64 = 0;
517
51935
        let mut global_dims = CompactNodeProps::default();
518
51935
        let mut global_cold = CompactNodePropsCold::default();
519
51935
        let mut global_text = CompactTextProps::default();
520
51935
        let has_global = !self.global_css_props.is_empty();
521

            
522
51935
        if has_global {
523
            use azul_css::props::property::CssProperty;
524

            
525
54747
            for prop in &self.global_css_props {
526
48593
                result.uses_viewport_units |= css_property_uses_viewport_units(prop);
527
                // Apply each global property to the pre-encoded compact values
528
                macro_rules! global_tier1_enum {
529
                    ($variant:ident, $shift:ident, $mask:ident, $encoder:ident) => {
530
                        if let CssProperty::$variant(v) = prop {
531
                            if let Some(exact) = v.get_property() {
532
                                let encoded = u64::from($encoder(*exact));
533
                                let shifted_mask = $mask << $shift;
534
                                global_tier1 =
535
                                    (global_tier1 & !shifted_mask) | ((encoded & $mask) << $shift);
536
                            }
537
                        }
538
                    };
539
                }
540

            
541
48593
                global_tier1_enum!(Display, DISPLAY_SHIFT, DISPLAY_MASK, layout_display_to_u8);
542
48593
                global_tier1_enum!(
543
                    Position,
544
                    POSITION_SHIFT,
545
                    POSITION_MASK,
546
                    layout_position_to_u8
547
                );
548
48593
                global_tier1_enum!(Float, FLOAT_SHIFT, FLOAT_MASK, layout_float_to_u8);
549
48593
                global_tier1_enum!(
550
                    OverflowX,
551
                    OVERFLOW_X_SHIFT,
552
                    OVERFLOW_MASK,
553
                    layout_overflow_to_u8
554
                );
555
48593
                global_tier1_enum!(
556
                    OverflowY,
557
                    OVERFLOW_Y_SHIFT,
558
                    OVERFLOW_MASK,
559
                    layout_overflow_to_u8
560
                );
561
48593
                global_tier1_enum!(
562
                    BoxSizing,
563
                    BOX_SIZING_SHIFT,
564
                    BOX_SIZING_MASK,
565
                    layout_box_sizing_to_u8
566
                );
567
48593
                global_tier1_enum!(
568
                    FlexDirection,
569
                    FLEX_DIRECTION_SHIFT,
570
                    FLEX_DIR_MASK,
571
                    layout_flex_direction_to_u8
572
                );
573
48593
                global_tier1_enum!(
574
                    FlexWrap,
575
                    FLEX_WRAP_SHIFT,
576
                    FLEX_WRAP_MASK,
577
                    layout_flex_wrap_to_u8
578
                );
579
48593
                global_tier1_enum!(
580
                    JustifyContent,
581
                    JUSTIFY_CONTENT_SHIFT,
582
                    JUSTIFY_MASK,
583
                    layout_justify_content_to_u8
584
                );
585
48593
                global_tier1_enum!(
586
                    AlignItems,
587
                    ALIGN_ITEMS_SHIFT,
588
                    ALIGN_MASK,
589
                    layout_align_items_to_u8
590
                );
591
48593
                global_tier1_enum!(
592
                    AlignContent,
593
                    ALIGN_CONTENT_SHIFT,
594
                    ALIGN_MASK,
595
                    layout_align_content_to_u8
596
                );
597
48593
                global_tier1_enum!(Clear, CLEAR_SHIFT, CLEAR_MASK, layout_clear_to_u8);
598
48593
                global_tier1_enum!(
599
                    Visibility,
600
                    VISIBILITY_SHIFT,
601
                    VISIBILITY_MASK,
602
                    style_visibility_to_u8
603
                );
604
48593
                global_tier1_enum!(
605
                    WritingMode,
606
                    WRITING_MODE_SHIFT,
607
                    WRITING_MODE_MASK,
608
                    layout_writing_mode_to_u8
609
                );
610
48593
                global_tier1_enum!(
611
                    FontWeight,
612
                    FONT_WEIGHT_SHIFT,
613
                    FONT_WEIGHT_MASK,
614
                    style_font_weight_to_u8
615
                );
616
48593
                global_tier1_enum!(
617
                    FontStyle,
618
                    FONT_STYLE_SHIFT,
619
                    FONT_STYLE_MASK,
620
                    style_font_style_to_u8
621
                );
622
48593
                global_tier1_enum!(
623
                    TextAlign,
624
                    TEXT_ALIGN_SHIFT,
625
                    TEXT_ALIGN_MASK,
626
                    style_text_align_to_u8
627
                );
628
48593
                global_tier1_enum!(
629
                    WhiteSpace,
630
                    WHITE_SPACE_SHIFT,
631
                    WHITE_SPACE_MASK,
632
                    style_white_space_to_u8
633
                );
634
48593
                global_tier1_enum!(
635
                    Direction,
636
                    DIRECTION_SHIFT,
637
                    DIRECTION_MASK,
638
                    style_direction_to_u8
639
                );
640
48593
                global_tier1_enum!(
641
                    VerticalAlign,
642
                    VERTICAL_ALIGN_SHIFT,
643
                    VERTICAL_ALIGN_MASK,
644
                    style_vertical_align_to_u8
645
                );
646
48593
                global_tier1_enum!(
647
                    BorderCollapse,
648
                    BORDER_COLLAPSE_SHIFT,
649
                    BORDER_COLLAPSE_MASK,
650
                    border_collapse_to_u8
651
                );
652

            
653
                // Tier 2 dims
654
48593
                match prop {
655
5967
                    CssProperty::PaddingTop(v) => {
656
5967
                        global_dims.padding_top = encode_css_pixel_as_i16(v);
657
5967
                    }
658
5966
                    CssProperty::PaddingRight(v) => {
659
5966
                        global_dims.padding_right = encode_css_pixel_as_i16(v);
660
5966
                    }
661
5966
                    CssProperty::PaddingBottom(v) => {
662
5966
                        global_dims.padding_bottom = encode_css_pixel_as_i16(v);
663
5966
                    }
664
5966
                    CssProperty::PaddingLeft(v) => {
665
5966
                        global_dims.padding_left = encode_css_pixel_as_i16(v);
666
5966
                    }
667
6110
                    CssProperty::MarginTop(v) => {
668
6110
                        global_dims.margin_top = encode_margin_i16(v);
669
6110
                    }
670
6110
                    CssProperty::MarginRight(v) => {
671
6110
                        global_dims.margin_right = encode_margin_i16(v);
672
6110
                    }
673
6110
                    CssProperty::MarginBottom(v) => {
674
6110
                        global_dims.margin_bottom = encode_margin_i16(v);
675
6110
                    }
676
6110
                    CssProperty::MarginLeft(v) => {
677
6110
                        global_dims.margin_left = encode_margin_i16(v);
678
6110
                    }
679
                    CssProperty::Width(v) => {
680
                        global_dims.width = encode_layout_width(v);
681
                    }
682
                    CssProperty::Height(v) => {
683
                        global_dims.height = encode_layout_height(v);
684
                    }
685
                    CssProperty::FontSize(v) => {
686
                        global_dims.font_size = encode_pixel_prop(v);
687
                    }
688
                    CssProperty::BorderTopWidth(v) => {
689
                        global_dims.border_top_width = encode_css_pixel_as_i16(v);
690
                    }
691
                    CssProperty::BorderRightWidth(v) => {
692
                        global_dims.border_right_width = encode_css_pixel_as_i16(v);
693
                    }
694
                    CssProperty::BorderBottomWidth(v) => {
695
                        global_dims.border_bottom_width = encode_css_pixel_as_i16(v);
696
                    }
697
                    CssProperty::BorderLeftWidth(v) => {
698
                        global_dims.border_left_width = encode_css_pixel_as_i16(v);
699
                    }
700
288
                    _ => {}
701
                }
702
            }
703

            
704
6154
            if global_tier1 != 0 {
705
276
                global_tier1 |= TIER1_POPULATED_BIT;
706
5878
            }
707
45781
        }
708

            
709
        // Helper: push debug message if debug_messages is Some
710
        macro_rules! cascade_debug {
711
            ($($arg:tt)*) => {
712
                if let Some(ref mut msgs) = debug_messages {
713
                    msgs.push(azul_css::LayoutDebugMessage::css_getter(format!($($arg)*)));
714
                }
715
            };
716
        }
717

            
718
1244596
        for i in 0..node_count {
719
1244596
            let node_id = NodeId::new(i);
720
1244596
            let nd = &node_data[i];
721

            
722
            // Step 0: Apply UA CSS defaults first (lowest priority).
723
            // Then global `*` rules override UA (higher priority).
724
            // Then per-node CSS (Step 3) overrides both.
725
            //
726
            // CSS cascade priority: UA < author `*` < author specific < inline
727

            
728
            // Step 1: Inherit from parent's COMPACT values (not computed_values)
729
            // Parent index is always < i in pre-order arena, so already computed.
730
            //
731
            // Step 1: Inherit ONLY inheritable CSS properties from parent.
732
            // Non-inheritable fields (display, position, float, overflow, box-sizing,
733
            // flex-*, clear, vertical-align, writing-mode) stay at 0 (CSS initial value).
734
            // They get set by UA CSS (Step 2) and author CSS (Step 3).
735
1244596
            let parent_id = node_hierarchy[i].parent_id();
736
1244596
            if let Some(pid) = parent_id {
737
1192735
                let pi = pid.index();
738

            
739
                // AUDIT: inheritance assumes a PRE-ORDER arena, i.e. a node's
740
                // parent is always stored at a lower index (`pi < i`) and has
741
                // therefore already been fully cascaded. A forward reference
742
                // (`pi >= i`) would silently inherit that parent's still-default
743
                // (all-zero) values, and an out-of-bounds `pi >= node_count`
744
                // would panic. Guard against both: assert the pre-order
745
                // invariant in debug builds, and skip inheritance (treat the
746
                // node as a root) for any malformed reference in release builds.
747
1192735
                debug_assert!(
748
                    pi < i,
749
                    "compact cascade: non-pre-order arena — node {i}'s parent {pi} is not stored \
750
                     before it; inheritance would read default values",
751
                );
752
1192735
                if pi < i {
753
1192735
                    // Copy only inheritable tier1 fields from parent
754
1192735
                    result.tier1_enums[i] = result.tier1_enums[pi] & INHERITABLE_TIER1_MASK;
755
1192735

            
756
1192735
                    // Inheritable tier2: font_size
757
1192735
                    result.tier2_dims[i].font_size = result.tier2_dims[pi].font_size;
758
1192735

            
759
1192735
                    // Inheritable tier2_cold: border_spacing, tab_size
760
1192735
                    result.tier2_cold[i].border_spacing_h = result.tier2_cold[pi].border_spacing_h;
761
1192735
                    result.tier2_cold[i].border_spacing_v = result.tier2_cold[pi].border_spacing_v;
762
1192735
                    result.tier2_cold[i].tab_size = result.tier2_cold[pi].tab_size;
763
1192735
                    // `cursor` is inheritable per spec - a `cursor: pointer`
764
1192735
                    // on a button has to reach the text inside it.
765
1192735
                    result.tier2_cold[i].cursor = result.tier2_cold[pi].cursor;
766
1192735

            
767
1192735
                    // Inheritable tier2b: all text properties
768
1192735
                    result.tier2b_text[i] = result.tier2b_text[pi];
769
1192735
                }
770
51861
            }
771

            
772
            {
773
1244596
                let d = &result.tier2_dims[i];
774
1244596
                cascade_debug!(
775
2
                    "node[{}] {:?} after-inherit: pt={} pb={} pl={} pr={} mt={} mb={} ml={} mr={} \
776
2
                     w={} h={}",
777
                    i,
778
                    nd.node_type,
779
                    d.padding_top,
780
                    d.padding_bottom,
781
                    d.padding_left,
782
                    d.padding_right,
783
                    d.margin_top,
784
                    d.margin_bottom,
785
                    d.margin_left,
786
                    d.margin_right,
787
                    d.width,
788
                    d.height
789
                );
790
            }
791

            
792
            // Step 2: Apply UA CSS defaults for this node type directly to compact values.
793
            // UA defaults have lowest cascade priority — overridden by author CSS below.
794
            // THEMED, through the same table `apply_ua_css` reads: the `<hr>`
795
            // rule, the native button border and (on the root) the inherited
796
            // text colour follow the window's theme here exactly as they do
797
            // on the slow path, so the normal-state fast path and the slow
798
            // path agree (theme-chain analysis 2026-09-12, R1/I4).
799
1244596
            apply_ua_css_to_compact(
800
1244596
                nd,
801
1244596
                i == 0,
802
1244596
                self.dynamic_context.as_deref(),
803
1244596
                &mut result.tier1_enums[i],
804
1244596
                &mut result.tier2_dims[i],
805
1244596
                &mut result.tier2_cold[i],
806
1244596
                &mut result.tier2b_text[i],
807
1244596
                &mut result.font_hash_to_families,
808
            );
809

            
810
            {
811
1244596
                let d = &result.tier2_dims[i];
812
1244596
                cascade_debug!(
813
2
                    "node[{}] {:?} after-UA: pt={} pb={} pl={} pr={} mt={} mb={} ml={} mr={}",
814
                    i,
815
                    nd.node_type,
816
                    d.padding_top,
817
                    d.padding_bottom,
818
                    d.padding_left,
819
                    d.padding_right,
820
                    d.margin_top,
821
                    d.margin_bottom,
822
                    d.margin_left,
823
                    d.margin_right
824
                );
825
            }
826

            
827
            // Step 2.5: Apply global `*` author CSS (overrides UA, overridden by specific rules)
828
            // Apply each `*` rule property individually (not bulk-assign) so we only
829
            // override properties the `*` rule actually set, preserving UA CSS for others.
830
            //
831
            // Per CSS spec, `*` matches all ELEMENTS. Text nodes are not elements —
832
            // they must only inherit from their parent. Without this check, `* { color: #666 }`
833
            // would overwrite the inherited `color: red` on a Text child of `<p>`,
834
            // even though `<p>` correctly got red from `p { color: red }`.
835
1244596
            if !nd.is_text_node() {
836
1049041
                for prop in &self.global_css_props {
837
228401
                    // (flag already accumulated in the has_global pre-pass)
838
228401
                    apply_css_property_to_compact(
839
228401
                        prop,
840
228401
                        &mut result.tier1_enums[i],
841
228401
                        &mut result.tier2_dims[i],
842
228401
                        &mut result.tier2_cold[i],
843
228401
                        &mut result.tier2b_text[i],
844
228401
                        &mut result.font_hash_to_families,
845
228401
                    );
846
228401
                    update_dom_declared_flags(prop, &mut result.dom_declared_flags);
847
228401
                }
848
423956
            }
849

            
850
            {
851
1244596
                let d = &result.tier2_dims[i];
852
1244596
                cascade_debug!(
853
2
                    "node[{}] {:?} after-global-star: pt={} pb={} pl={} pr={} mt={} mb={} ml={} \
854
2
                     mr={}",
855
                    i,
856
                    nd.node_type,
857
                    d.padding_top,
858
                    d.padding_bottom,
859
                    d.padding_left,
860
                    d.padding_right,
861
                    d.margin_top,
862
                    d.margin_bottom,
863
                    d.margin_left,
864
                    d.margin_right
865
                );
866
1244596
                let n_props = self.css_props.get_slice(i).len();
867
1244596
                let n_inline = nd.style.iter_inline_properties().count();
868
1244596
                cascade_debug!(
869
2
                    "node[{}] css_props={} entries, inline={} entries",
870
                    i,
871
                    n_props,
872
                    n_inline
873
                );
874
1252411
                for prop in self.css_props.get_slice(i) {
875
1045642
                    cascade_debug!(
876
                        "node[{}]   css_prop: state={:?} type={:?}",
877
                        i,
878
                        prop.state,
879
                        prop.prop_type
880
                    );
881
                }
882
            }
883

            
884
            // Step 3: Apply this node's CSS properties directly to compact values.
885
            // Per-node author CSS has higher specificity than global `*`.
886

            
887
            // Scan css_props (stylesheet rules, sorted by (state, prop_type))
888
            // Typically 5-15 entries per node. Only Normal state matters for layout.
889
1252411
            for prop in self.css_props.get_slice(i) {
890
1045642
                if prop.state != azul_css::dynamic_selector::PseudoStateType::Normal {
891
1163
                    continue;
892
1044479
                }
893
1044479
                result.uses_viewport_units |= css_property_uses_viewport_units(&prop.property);
894
1044479
                apply_css_property_to_compact(
895
1044479
                    &prop.property,
896
1044479
                    &mut result.tier1_enums[i],
897
1044479
                    &mut result.tier2_dims[i],
898
1044479
                    &mut result.tier2_cold[i],
899
1044479
                    &mut result.tier2b_text[i],
900
1044479
                    &mut result.font_hash_to_families,
901
                );
902
1044479
                update_dom_declared_flags(&prop.property, &mut result.dom_declared_flags);
903
            }
904

            
905
            {
906
1244596
                let d = &result.tier2_dims[i];
907
1244596
                cascade_debug!(
908
2
                    "node[{}] {:?} after-css-props: pt={} pb={} pl={} pr={} mt={} mb={} ml={} \
909
2
                     mr={}",
910
                    i,
911
                    nd.node_type,
912
                    d.padding_top,
913
                    d.padding_bottom,
914
                    d.padding_left,
915
                    d.padding_right,
916
                    d.margin_top,
917
                    d.margin_bottom,
918
                    d.margin_left,
919
                    d.margin_right
920
                );
921
            }
922

            
923
            // Scan inline CSS (node_data.style — typically 0-3 properties).
924
            // Inline CSS has highest specificity — applied last to override stylesheet.
925
6772576
            for (prop, conds) in nd.style.iter_inline_properties() {
926
                // Apply when the conditions hold for the RESTING state:
927
                // pseudo-state conditions must be Normal, and every other
928
                // condition (viewport/@media, theme, OS...) is evaluated
929
                // against the window's dynamic context — the same rule
930
                // get_property_slow applies, so the fast path and the slow
931
                // path cannot disagree about a conditional property. A
932
                // non-pseudo condition also flags the cache, so the window
933
                // knows a context change requires a rebuild.
934
6760809
                let is_normal = conds.as_slice().is_empty()
935
1183499
                    || conds.as_slice().iter().all(|c| match c {
936
403181
                        azul_css::dynamic_selector::DynamicSelector::PseudoState(s) => {
937
403181
                            *s == azul_css::dynamic_selector::PseudoStateType::Normal
938
                        }
939
780318
                        non_pseudo => {
940
780318
                            result.has_dynamic_conditions = true;
941
                            // Harvest the thresholds this condition can flip
942
                            // at — the resize decision regenerates when the
943
                            // window crosses one (dedup/sort happens once,
944
                            // after the node loop).
945
780318
                            {
946
780318
                                let mut w = Vec::new();
947
780318
                                let mut h = Vec::new();
948
780318
                                azul_css::dynamic_selector::collect_viewport_thresholds(
949
780318
                                    core::slice::from_ref(non_pseudo),
950
780318
                                    &mut w,
951
780318
                                    &mut h,
952
780318
                                );
953
780318
                                result
954
780318
                                    .inline_viewport_w
955
780318
                                    .extend(w.into_iter().map(f32::to_bits));
956
780318
                                result
957
780318
                                    .inline_viewport_h
958
780318
                                    .extend(h.into_iter().map(f32::to_bits));
959
780318
                            }
960
780318
                            self.dynamic_context
961
780318
                                .as_deref()
962
780318
                                .is_some_and(|ctx| non_pseudo.matches(ctx))
963
                        }
964
1183499
                    });
965
6760809
                if !is_normal {
966
1182657
                    continue;
967
5578152
                }
968
5578152
                result.uses_viewport_units |= css_property_uses_viewport_units(prop);
969
                // Layout-critical props dispatched via single-variant `if let` (direct discriminant
970
                // COMPARES, no indirect jump). apply_css_property_to_compact's ~100-arm `match`
971
                // lowers to a jump table that remill mis-lifts (never reaches the
972
                // right arm) — same class as the CssProperty::clone bug. With the
973
                // conversion-clone fix the prop discriminant is now correct, so
974
                // these compares match and apply the value; everything else falls back.
975
                // (CssProperty is imported at module top.)
976
5578152
                if let CssProperty::Width(v) = prop {
977
168418
                    result.tier2_dims[i].width = encode_layout_width(v);
978
5409734
                } else if let CssProperty::Height(v) = prop {
979
195012
                    result.tier2_dims[i].height = encode_layout_height(v);
980
5214722
                } else if let CssProperty::FlexGrow(v) = prop {
981
454272
                    if let Some(e) = v.get_property() {
982
454272
                        result.tier2_dims[i].flex_grow = encode_flex_u16(e.inner.get());
983
454272
                    }
984
4760450
                } else if let CssProperty::Display(v) = prop {
985
266568
                    if let Some(e) = v.get_property() {
986
266568
                        let enc = u64::from(layout_display_to_u8(*e));
987
266568
                        let m = DISPLAY_MASK;
988
266568
                        let s = DISPLAY_SHIFT;
989
266568
                        result.tier1_enums[i] =
990
266568
                            (result.tier1_enums[i] & !(m << s)) | ((enc & m) << s);
991
266568
                    }
992
4493882
                } else {
993
4493882
                    apply_css_property_to_compact(
994
4493882
                        prop,
995
4493882
                        &mut result.tier1_enums[i],
996
4493882
                        &mut result.tier2_dims[i],
997
4493882
                        &mut result.tier2_cold[i],
998
4493882
                        &mut result.tier2b_text[i],
999
4493882
                        &mut result.font_hash_to_families,
4493882
                    );
4493882
                }
5578152
                update_dom_declared_flags(prop, &mut result.dom_declared_flags);
            }
            // Step 4b: user-overridden properties (runtime patches via
            // `set_css_property` / `restyle_user_property`). The resolver
            // consults this layer FIRST, so the compact cache must apply it
            // LAST — the cache is a projection of the same cascade and the
            // two must agree. Without this step a rebuilt cache resurrected
            // the pre-patch value: `restyle_user_property` rebuilds the cache
            // right after recording the override, and the layout fast path
            // then read the stale display/geometry the patch had just
            // changed. Same dispatch shape as the inline loop above (the
            // single-variant `if let`s exist for the remill lift, see there).
1244596
            if let Some(user_props) = self.user_overridden_properties.get(i) {
7200
                for (_, prop) in user_props {
1448
                    result.uses_viewport_units |= css_property_uses_viewport_units(prop);
1448
                    if let CssProperty::Width(v) = prop {
140
                        result.tier2_dims[i].width = encode_layout_width(v);
1365
                    } else if let CssProperty::Height(v) = prop {
                        result.tier2_dims[i].height = encode_layout_height(v);
1308
                    } else if let CssProperty::FlexGrow(v) = prop {
                        if let Some(e) = v.get_property() {
                            result.tier2_dims[i].flex_grow = encode_flex_u16(e.inner.get());
                        }
1308
                    } else if let CssProperty::Display(v) = prop {
14
                        if let Some(e) = v.get_property() {
14
                            let enc = u64::from(layout_display_to_u8(*e));
14
                            let m = DISPLAY_MASK;
14
                            let s = DISPLAY_SHIFT;
14
                            result.tier1_enums[i] =
14
                                (result.tier1_enums[i] & !(m << s)) | ((enc & m) << s);
14
                        }
1294
                    } else {
1294
                        apply_css_property_to_compact(
1294
                            prop,
1294
                            &mut result.tier1_enums[i],
1294
                            &mut result.tier2_dims[i],
1294
                            &mut result.tier2_cold[i],
1294
                            &mut result.tier2b_text[i],
1294
                            &mut result.font_hash_to_families,
1294
                        );
1294
                    }
1448
                    update_dom_declared_flags(prop, &mut result.dom_declared_flags);
                }
1238844
            }
            // Resolve font-size from em/percent/pt/etc. to px.
            // CSS 2.1: inherited font-size is the COMPUTED (px) value, not the specified value.
            // Pre-order traversal guarantees parent's font_size is already resolved.
1244596
            resolve_font_size_to_px(&mut result.tier2_dims, i, parent_id);
            // Set populated bit
1244596
            if result.tier1_enums[i] != 0 {
883535
                result.tier1_enums[i] |= TIER1_POPULATED_BIT;
888575
            }
        }
        // Font dirty tracking.
        // When prev_font_hashes is empty (first build for this DOM), mark ALL
        // text nodes dirty to force font resolution. Without this, a DOM with
        // no explicit font-family (all hashes 0) would compare 0==0 and skip
        // resolution, even though font-weight/font-style may differ from the
        // cached chains of a previous DOM.
51935
        result.font_dirty_nodes.clear();
51935
        let first_build = prev_font_hashes.is_empty();
1244596
        for i in 0..node_count {
1244596
            let new_hash = result.tier2b_text[i].font_family_hash;
1244596
            let old_hash = prev_font_hashes.get(i).copied().unwrap_or(0);
1244596
            if first_build || new_hash != old_hash {
854562
                result.font_dirty_nodes.push(i);
856562
            }
        }
51935
        result.prev_font_hashes = result
51935
            .tier2b_text
51935
            .iter()
51935
            .map(|t| t.font_family_hash)
51935
            .collect();
        // Normalize the harvested viewport thresholds once (pushed raw per
        // node above): sorted + deduped by bit pattern.
51935
        result.inline_viewport_w.sort_unstable();
51935
        result.inline_viewport_w.dedup();
51935
        result.inline_viewport_h.sort_unstable();
51935
        result.inline_viewport_h.dedup();
51935
        result
51935
    }
}
// =============================================================================
// Helpers extracted from build_compact_cache_with_inheritance_debug
// =============================================================================
/// Apply UA CSS defaults for a node type directly to compact values.
///
/// UA defaults have lowest cascade priority — overridden by author CSS.
/// Which tier-1 bits a node COPIES FROM ITS PARENT — the packed form of "this
/// property is inherited".
///
/// It must hold a slot exactly when that slot's property is `is_inheritable()`.
/// Getting it wrong is silent in BOTH directions: a missing slot makes every
/// descendant fall back to the CSS initial value while `get_property_slow` —
/// which inherits through `computed_values` — still answers correctly, so the
/// two cascade paths disagree about the computed value. That is the failure
/// mode that bit the `VirtualView` overflow default. An extra slot inherits a
/// property CSS says does not.
///
/// `every_inheritable_tier1_property_is_actually_inherited` checks the
/// correspondence slot by slot against `CssPropertyType::is_inheritable`, so a
/// slot added later cannot quietly omit itself.
pub const INHERITABLE_TIER1_MASK: u64 = (FONT_WEIGHT_MASK << FONT_WEIGHT_SHIFT)
    | (FONT_STYLE_MASK << FONT_STYLE_SHIFT)
    | (TEXT_ALIGN_MASK << TEXT_ALIGN_SHIFT)
    | (VISIBILITY_MASK << VISIBILITY_SHIFT)
    | (WHITE_SPACE_MASK << WHITE_SPACE_SHIFT)
    | (DIRECTION_MASK << DIRECTION_SHIFT)
    | (BORDER_COLLAPSE_MASK << BORDER_COLLAPSE_SHIFT)
    // `writing-mode` is inheritable per CSS and has had a tier-1 slot all
    // along, but was never copied from the parent: `writing-mode: vertical-rl`
    // on a container laid its children out horizontally in the compact path,
    // while the slow path inherited it correctly. Found by auditing this mask
    // against `is_inheritable()` — it was the only disagreement.
    | (WRITING_MODE_MASK << WRITING_MODE_SHIFT);
1244613
fn apply_ua_css_to_compact(
1244613
    node: &NodeData,
1244613
    is_root: bool,
1244613
    ctx: Option<&azul_css::dynamic_selector::DynamicSelectorContext>,
1244613
    tier1: &mut u64,
1244613
    dims: &mut CompactNodeProps,
1244613
    cold: &mut CompactNodePropsCold,
1244613
    text: &mut CompactTextProps,
1244613
    font_hash_map: &mut alloc::collections::BTreeMap<
1244613
        u64,
1244613
        azul_css::props::basic::font::StyleFontFamilyVec,
1244613
    >,
1244613
) {
    // The ONE property-type list both cascade passes walk (`ua_css.rs`); the
    // per-pass copies this replaced had drifted apart (see its doc).
73432167
    for pt in crate::ua_css::UA_PROPERTY_TYPES {
72187554
        if let Some(ua_prop) = crate::ua_css::get_ua_default(node, is_root, *pt, ctx) {
3097822
            apply_css_property_to_compact(ua_prop, tier1, dims, cold, text, font_hash_map);
69089732
        }
    }
1244613
}
/// Resolve a node's font-size from relative units (em, %, rem, pt) to absolute px.
/// CSS 2.1: inherited font-size is the COMPUTED (px) value, not the specified value.
/// Pre-order traversal guarantees parent's `font_size` is already resolved.
1244608
fn resolve_font_size_to_px(
1244608
    tier2_dims: &mut [CompactNodeProps],
1244608
    node_idx: usize,
1244608
    parent_id: Option<NodeId>,
1244608
) {
1244608
    let raw_fs = tier2_dims[node_idx].font_size;
1244608
    if raw_fs == U32_SENTINEL || raw_fs >= U32_SENTINEL_THRESHOLD {
272371
        return;
972237
    }
972237
    let pv = match decode_pixel_value_u32(raw_fs) {
972237
        Some(pv) if pv.metric != SizeMetric::Px => pv,
971837
        _ => return,
    };
    // AUDIT: pre-order arena assumed — the parent's font-size is already
    // resolved to px only when `pid < node_idx`. Use checked `get` so an
    // out-of-bounds parent ref cannot panic, and require `pid < node_idx` so a
    // forward reference falls back to the 16px CSS initial value instead of
    // reading an unresolved (still em/%) parent value.
400
    let parent_font_size_px = parent_id.map_or(16.0, |pid| {
347
        let pi = pid.index();
347
        debug_assert!(
            pi < node_idx,
            "compact font-size resolve: non-pre-order arena — node {node_idx}'s parent {pi} \
             font-size is not yet resolved",
        );
347
        if pi < node_idx {
347
            tier2_dims
347
                .get(pi)
347
                .and_then(|p| decode_pixel_value_u32(p.font_size))
347
                .map_or(16.0, |ppv| ppv.number.get())
        } else {
            16.0
        }
347
    });
400
    let resolved_px = match pv.metric {
346
        SizeMetric::Em => pv.number.get() * parent_font_size_px,
39
        SizeMetric::Percent => pv.number.get() / 100.0 * parent_font_size_px,
        SizeMetric::Rem => {
            // rem = the ROOT element's font size. For the root itself that is circular,
            // so CSS resolves root rem against the 16px INITIAL value (Selectors/Values:
            // "when specified on the root element, rem refers to the initial value").
            // tier2_dims[0] IS the root's slot, but while resolving the root it still
            // holds the root's own unresolved raw rem — so `html { font-size: 2rem }`
            // computed 2*2 = 4px instead of 2*16 = 32px.
2
            let rem_base = if parent_id.is_none() {
1
                16.0
            } else {
1
                tier2_dims
1
                    .first()
1
                    .and_then(|r| decode_pixel_value_u32(r.font_size))
1
                    .map_or(16.0, |rpv| rpv.number.get())
            };
2
            rem_base * pv.number.get()
        }
1
        SizeMetric::Pt => pv.number.get() * 96.0 / 72.0,
12
        _ => pv.number.get(),
    };
400
    tier2_dims[node_idx].font_size =
400
        encode_pixel_value_u32(&azul_css::props::basic::pixel::PixelValue::px(resolved_px));
1244608
}
/// Does this property's value use a viewport-relative unit (vw/vh/vmin/vmax)?
///
/// Feeds `CompactLayoutCache::uses_viewport_units` from the property loops of
/// `build_compact_cache_with_inheritance` — one call per (node, property), on
/// data the loops are already iterating. See that field's docs for what the
/// flag buys (solver3 skips per-resize invalidation of every inline collection
/// for the overwhelming majority of documents that never mention a viewport
/// unit).
///
/// Coverage = the pixel-carrying properties the compact cache itself encodes,
/// which is a superset of what inline collection/measurement reads (the only
/// consumer). `calc()` widths/heights are flagged CONSERVATIVELY without
/// walking the AST — a false positive merely keeps the old always-invalidate
/// behaviour.
6672672
fn css_property_uses_viewport_units(prop: &CssProperty) -> bool {
    use azul_css::props::basic::{length::SizeMetric, pixel::PixelValue};
2602304
    const fn pv(p: &PixelValue) -> bool {
2601428
        matches!(
2602304
            p.metric,
            SizeMetric::Vw | SizeMetric::Vh | SizeMetric::Vmin | SizeMetric::Vmax
        )
2602304
    }
2158663
    fn inner<T: HasInnerPixelValue>(v: &CssPropertyValue<T>) -> bool {
2158483
        matches!(v, CssPropertyValue::Exact(x) if pv(&x.get_inner_pixel()))
2158663
    }
    use azul_css::props::layout::{
        dimensions::{LayoutHeight, LayoutWidth},
        flex::LayoutFlexBasis,
    };
6672672
    match prop {
200009
        CssProperty::Width(v) => matches!(v, CssPropertyValue::Exact(w) if match w {
199940
            LayoutWidth::Px(p) | LayoutWidth::FitContent(p) => pv(p),
19
            LayoutWidth::Calc(_) => true,
            _ => false,
19
        }),
231137
        CssProperty::Height(v) => matches!(v, CssPropertyValue::Exact(h) if match h {
231137
            LayoutHeight::Px(p) | LayoutHeight::FitContent(p) => pv(p),
            LayoutHeight::Calc(_) => true,
            _ => false,
        }),
12768
        CssProperty::FlexBasis(v) => {
12744
            matches!(v, CssPropertyValue::Exact(LayoutFlexBasis::Exact(p)) if pv(p))
        }
36379
        CssProperty::MinWidth(v) => inner(v),
1064
        CssProperty::MaxWidth(v) => inner(v),
7920
        CssProperty::MinHeight(v) => inner(v),
684
        CssProperty::MaxHeight(v) => inner(v),
261154
        CssProperty::FontSize(v) => inner(v),
198324
        CssProperty::PaddingTop(v) => inner(v),
166787
        CssProperty::PaddingRight(v) => inner(v),
161711
        CssProperty::PaddingBottom(v) => inner(v),
167502
        CssProperty::PaddingLeft(v) => inner(v),
247329
        CssProperty::MarginTop(v) => inner(v),
26521
        CssProperty::MarginRight(v) => inner(v),
295118
        CssProperty::MarginBottom(v) => inner(v),
66866
        CssProperty::MarginLeft(v) => inner(v),
115850
        CssProperty::BorderTopWidth(v) => inner(v),
128690
        CssProperty::BorderRightWidth(v) => inner(v),
144710
        CssProperty::BorderBottomWidth(v) => inner(v),
103730
        CssProperty::BorderLeftWidth(v) => inner(v),
12655
        CssProperty::Top(v) => inner(v),
1771
        CssProperty::Right(v) => inner(v),
1423
        CssProperty::Bottom(v) => inner(v),
12415
        CssProperty::Left(v) => inner(v),
36
        CssProperty::LetterSpacing(v) => inner(v),
12
        CssProperty::WordSpacing(v) => inner(v),
12
        CssProperty::TextIndent(v) => inner(v),
        CssProperty::TabSize(v) => inner(v),
4070095
        _ => false,
    }
6672672
}
// =============================================================================
// Direct CssProperty → compact field writer
// =============================================================================
/// Apply a single `CssProperty` directly to the compact representation.
/// Called once per property per node — replaces the old 56+ getter approach.
#[inline]
// The scrollbar-* and counter-* arms have identical bodies
// (`if v.get_property().is_some() { flags |= … }`) but each variant wraps a
// DIFFERENT value type (StyleBackgroundContentValue, LayoutScrollbarWidthValue,
// StyleScrollbarColorValue, CounterResetValue, CounterIncrementValue, …), so an
// or-pattern binding `v` cannot be expressed across them.
#[allow(clippy::match_same_arms)]
// fixed-point encoders: z-index / line-height are range-checked before the
// narrowing cast, and opacity is clamped to [0,1] then scaled to [0,254] (u8).
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] // large but cohesive: single-purpose
                                                               // parser/builder/dispatch (one
                                                               // branch per input variant)
8865924
fn apply_css_property_to_compact(
8865924
    prop: &CssProperty,
8865924
    tier1: &mut u64,
8865924
    dims: &mut CompactNodeProps,
8865924
    cold: &mut CompactNodePropsCold,
8865924
    text: &mut CompactTextProps,
8865924
    font_hash_map: &mut alloc::collections::BTreeMap<
8865924
        u64,
8865924
        azul_css::props::basic::font::StyleFontFamilyVec,
8865924
    >,
8865924
) {
    macro_rules! set_tier1 {
        ($v:expr, $shift:expr, $mask:expr, $encoder:ident) => {
            if let Some(exact) = $v.get_property() {
                let encoded = u64::from($encoder(*exact));
                let shifted_mask = $mask << $shift;
                *tier1 = (*tier1 & !shifted_mask) | ((encoded & $mask) << $shift);
            }
        };
    }
8865924
    match prop {
        // Tier 1 enums
1321154
        CssProperty::Display(v) => set_tier1!(v, DISPLAY_SHIFT, DISPLAY_MASK, layout_display_to_u8),
33957
        CssProperty::Position(v) => {
33957
            set_tier1!(v, POSITION_SHIFT, POSITION_MASK, layout_position_to_u8);
        }
468
        CssProperty::Float(v) => set_tier1!(v, FLOAT_SHIFT, FLOAT_MASK, layout_float_to_u8),
26557
        CssProperty::OverflowX(v) => {
26557
            set_tier1!(v, OVERFLOW_X_SHIFT, OVERFLOW_MASK, layout_overflow_to_u8);
        }
27255
        CssProperty::OverflowY(v) => {
27255
            set_tier1!(v, OVERFLOW_Y_SHIFT, OVERFLOW_MASK, layout_overflow_to_u8);
        }
        // +spec:overflow:17654b - overflow-block / overflow-inline resolve to
        // the physical axis through the writing mode. Application is in
        // declaration order (a later physical declaration overwrites the
        // same tier1 slot and vice versa), which is exactly CSS's
        // equal-specificity last-wins rule for logical/physical pairs. The
        // writing mode is read from tier1 AT THIS POINT: the inherited value
        // is already present (inheritance runs first), so only the exotic
        // "writing-mode declared AFTER a logical overflow on the SAME node"
        // ordering maps against the pre-declaration mode.
        CssProperty::OverflowBlock(v) => {
            if let Some(val) = v.get_property() {
                let wm_bits = ((*tier1 >> WRITING_MODE_SHIFT) & WRITING_MODE_MASK) as u8;
                let vertical = wm_bits
                    == layout_writing_mode_to_u8(
                        azul_css::props::layout::wrapping::LayoutWritingMode::VerticalRl,
                    )
                    || wm_bits
                        == layout_writing_mode_to_u8(
                            azul_css::props::layout::wrapping::LayoutWritingMode::VerticalLr,
                        );
                let shift = if vertical {
                    OVERFLOW_X_SHIFT
                } else {
                    OVERFLOW_Y_SHIFT
                };
                let enc = u64::from(layout_overflow_to_u8(*val));
                *tier1 = (*tier1 & !(OVERFLOW_MASK << shift)) | ((enc & OVERFLOW_MASK) << shift);
            }
        }
24
        CssProperty::OverflowInline(v) => {
24
            if let Some(val) = v.get_property() {
24
                let wm_bits = ((*tier1 >> WRITING_MODE_SHIFT) & WRITING_MODE_MASK) as u8;
24
                let vertical = wm_bits
24
                    == layout_writing_mode_to_u8(
24
                        azul_css::props::layout::wrapping::LayoutWritingMode::VerticalRl,
24
                    )
24
                    || wm_bits
24
                        == layout_writing_mode_to_u8(
24
                            azul_css::props::layout::wrapping::LayoutWritingMode::VerticalLr,
24
                        );
24
                let shift = if vertical {
                    OVERFLOW_Y_SHIFT
                } else {
24
                    OVERFLOW_X_SHIFT
                };
24
                let enc = u64::from(layout_overflow_to_u8(*val));
24
                *tier1 = (*tier1 & !(OVERFLOW_MASK << shift)) | ((enc & OVERFLOW_MASK) << shift);
            }
        }
142116
        CssProperty::BoxSizing(v) => set_tier1!(
142116
            v,
            BOX_SIZING_SHIFT,
            BOX_SIZING_MASK,
            layout_box_sizing_to_u8
        ),
268159
        CssProperty::FlexDirection(v) => set_tier1!(
268159
            v,
            FLEX_DIRECTION_SHIFT,
            FLEX_DIR_MASK,
            layout_flex_direction_to_u8
        ),
3199
        CssProperty::FlexWrap(v) => {
3199
            set_tier1!(v, FLEX_WRAP_SHIFT, FLEX_WRAP_MASK, layout_flex_wrap_to_u8);
        }
78643
        CssProperty::JustifyContent(v) => set_tier1!(
78643
            v,
            JUSTIFY_CONTENT_SHIFT,
            JUSTIFY_MASK,
            layout_justify_content_to_u8
        ),
213866
        CssProperty::AlignItems(v) => {
213866
            set_tier1!(v, ALIGN_ITEMS_SHIFT, ALIGN_MASK, layout_align_items_to_u8);
        }
        CssProperty::AlignContent(v) => set_tier1!(
            v,
            ALIGN_CONTENT_SHIFT,
            ALIGN_MASK,
            layout_align_content_to_u8
        ),
60
        CssProperty::WritingMode(v) => set_tier1!(
60
            v,
            WRITING_MODE_SHIFT,
            WRITING_MODE_MASK,
            layout_writing_mode_to_u8
        ),
84
        CssProperty::Clear(v) => set_tier1!(v, CLEAR_SHIFT, CLEAR_MASK, layout_clear_to_u8),
1966
        CssProperty::FontWeight(v) => set_tier1!(
1966
            v,
            FONT_WEIGHT_SHIFT,
            FONT_WEIGHT_MASK,
            style_font_weight_to_u8
        ),
24
        CssProperty::FontStyle(v) => {
24
            set_tier1!(v, FONT_STYLE_SHIFT, FONT_STYLE_MASK, style_font_style_to_u8);
        }
92304
        CssProperty::TextAlign(v) => {
92304
            set_tier1!(v, TEXT_ALIGN_SHIFT, TEXT_ALIGN_MASK, style_text_align_to_u8);
        }
19
        CssProperty::Visibility(v) => {
19
            set_tier1!(v, VISIBILITY_SHIFT, VISIBILITY_MASK, style_visibility_to_u8);
        }
41136
        CssProperty::WhiteSpace(v) => set_tier1!(
41136
            v,
            WHITE_SPACE_SHIFT,
            WHITE_SPACE_MASK,
            style_white_space_to_u8
        ),
36
        CssProperty::Direction(v) => {
36
            set_tier1!(v, DIRECTION_SHIFT, DIRECTION_MASK, style_direction_to_u8);
        }
3300
        CssProperty::VerticalAlign(v) => set_tier1!(
3300
            v,
            VERTICAL_ALIGN_SHIFT,
            VERTICAL_ALIGN_MASK,
            style_vertical_align_to_u8
        ),
        // `cursor` is INHERITABLE and is resolved on every mouse move to pick
        // the pointer shape, so it wants a flat per-node read. It is NOT in
        // the tier-1 word: that word is full, and the bit range it was given
        // belonged to `align-self`, so writing a cursor re-aligned the node.
660704
        CssProperty::Cursor(v) => {
660704
            if let Some(exact) = v.get_property() {
660704
                cold.cursor = cursor_to_u8(*exact);
660704
            }
        }
97
        CssProperty::BorderCollapse(v) => set_tier1!(
97
            v,
            BORDER_COLLAPSE_SHIFT,
            BORDER_COLLAPSE_MASK,
            border_collapse_to_u8
        ),
9360
        CssProperty::AlignSelf(v) => set_tier1!(
9360
            v,
            ALIGN_SELF_SHIFT,
            ALIGN_SELF_MASK,
            layout_align_self_to_u8
        ),
        CssProperty::JustifySelf(v) => set_tier1!(
            v,
            JUSTIFY_SELF_SHIFT,
            JUSTIFY_SELF_MASK,
            layout_justify_self_to_u8
        ),
        CssProperty::GridAutoFlow(v) => set_tier1!(
            v,
            GRID_AUTO_FLOW_SHIFT,
            GRID_AUTO_FLOW_MASK,
            layout_grid_auto_flow_to_u8
        ),
        CssProperty::JustifyItems(v) => set_tier1!(
            v,
            JUSTIFY_ITEMS_SHIFT,
            JUSTIFY_ITEMS_MASK,
            layout_justify_items_to_u8
        ),
        // Tier 2 dimensions
31452
        CssProperty::Width(v) => {
31452
            dims.width = encode_layout_width(v);
31452
        }
36125
        CssProperty::Height(v) => {
36125
            dims.height = encode_layout_height(v);
36125
        }
36379
        CssProperty::MinWidth(v) => {
36379
            dims.min_width = encode_pixel_prop(v);
36379
        }
1064
        CssProperty::MaxWidth(v) => {
1064
            dims.max_width = encode_pixel_prop(v);
1064
        }
7920
        CssProperty::MinHeight(v) => {
7920
            dims.min_height = encode_pixel_prop(v);
7920
        }
684
        CssProperty::MaxHeight(v) => {
684
            dims.max_height = encode_pixel_prop(v);
684
        }
12768
        CssProperty::FlexBasis(v) => {
12768
            dims.flex_basis = encode_flex_basis(v);
12768
        }
303079
        CssProperty::FontSize(v) => {
303079
            dims.font_size = encode_pixel_prop(v);
303079
        }
262279
        CssProperty::PaddingTop(v) => {
262279
            dims.padding_top = encode_css_pixel_as_i16(v);
262279
        }
230742
        CssProperty::PaddingRight(v) => {
230742
            dims.padding_right = encode_css_pixel_as_i16(v);
230742
        }
225666
        CssProperty::PaddingBottom(v) => {
225666
            dims.padding_bottom = encode_css_pixel_as_i16(v);
225666
        }
232777
        CssProperty::PaddingLeft(v) => {
232777
            dims.padding_left = encode_css_pixel_as_i16(v);
232777
        }
537432
        CssProperty::MarginTop(v) => {
537432
            dims.margin_top = encode_margin_i16(v);
537432
        }
79858
        CssProperty::MarginRight(v) => {
79858
            dims.margin_right = encode_margin_i16(v);
79858
        }
585221
        CssProperty::MarginBottom(v) => {
585221
            dims.margin_bottom = encode_margin_i16(v);
585221
        }
120203
        CssProperty::MarginLeft(v) => {
120203
            dims.margin_left = encode_margin_i16(v);
120203
        }
156168
        CssProperty::BorderTopWidth(v) => {
156168
            dims.border_top_width = encode_css_pixel_as_i16(v);
156168
        }
169008
        CssProperty::BorderRightWidth(v) => {
169008
            dims.border_right_width = encode_css_pixel_as_i16(v);
169008
        }
185028
        CssProperty::BorderBottomWidth(v) => {
185028
            dims.border_bottom_width = encode_css_pixel_as_i16(v);
185028
        }
144048
        CssProperty::BorderLeftWidth(v) => {
144048
            dims.border_left_width = encode_css_pixel_as_i16(v);
144048
        }
12655
        CssProperty::Top(v) => {
12655
            dims.top = encode_css_pixel_as_i16(v);
12655
        }
1771
        CssProperty::Right(v) => {
1771
            dims.right = encode_css_pixel_as_i16(v);
1771
        }
1423
        CssProperty::Bottom(v) => {
1423
            dims.bottom = encode_css_pixel_as_i16(v);
1423
        }
12415
        CssProperty::Left(v) => {
12415
            dims.left = encode_css_pixel_as_i16(v);
12415
        }
5647
        CssProperty::FlexGrow(v) => {
5647
            if let Some(exact) = v.get_property() {
5647
                dims.flex_grow = encode_flex_u16(exact.inner.get());
5647
            }
        }
142321
        CssProperty::FlexShrink(v) => {
142321
            if let Some(exact) = v.get_property() {
142321
                dims.flex_shrink = encode_flex_u16(exact.inner.get());
142321
            }
        }
3048
        CssProperty::RowGap(v) => {
3048
            if let Some(g) = v.get_property() {
3048
                if g.inner.metric == SizeMetric::Px {
3048
                    dims.row_gap = encode_resolved_px_i16(g.inner.number.get());
3048
                }
            }
        }
3048
        CssProperty::ColumnGap(v) => {
3048
            if let Some(g) = v.get_property() {
3048
                if g.inner.metric == SizeMetric::Px {
3048
                    dims.column_gap = encode_resolved_px_i16(g.inner.number.get());
3048
                }
            }
        }
2
        CssProperty::Gap(v) => {
2
            if let Some(g) = v.get_property() {
2
                if g.inner.metric == SizeMetric::Px {
1
                    let enc = encode_resolved_px_i16(g.inner.number.get());
1
                    dims.row_gap = enc;
1
                    dims.column_gap = enc;
1
                }
            }
        }
        // Grid placement (compact encoding for common Auto/Line cases)
121
        CssProperty::GridColumn(v) => {
121
            if let Some(gp) = v.get_property() {
121
                cold.grid_col_start = encode_grid_line(&gp.grid_start);
121
                cold.grid_col_end = encode_grid_line(&gp.grid_end);
121
            }
        }
120
        CssProperty::GridRow(v) => {
120
            if let Some(gp) = v.get_property() {
120
                cold.grid_row_start = encode_grid_line(&gp.grid_start);
120
                cold.grid_row_end = encode_grid_line(&gp.grid_end);
120
            }
        }
        // Tier 2 cold
3677
        CssProperty::ZIndex(v) => {
3677
            if let Some(exact) = v.get_property() {
3665
                match exact {
1
                    LayoutZIndex::Auto => cold.z_index = I16_AUTO,
3664
                    LayoutZIndex::Integer(z) => {
                        // Two-sided (see the tier2_cold path above): a large negative z
                        // used to wrap positive via `*z as i16`. Escape both ends.
3664
                        cold.z_index = if *z >= -32768 && *z < i32::from(I16_SENTINEL_THRESHOLD) {
3621
                            *z as i16
                        } else {
43
                            I16_SENTINEL
                        };
                    }
                }
12
            }
        }
146666
        CssProperty::BorderTopStyle(v) => {
146666
            if let Some(exact) = v.get_property() {
146594
                let bs = u16::from(border_style_to_u8(exact.inner));
146594
                cold.border_styles_packed = (cold.border_styles_packed & !0x000F) | bs;
146594
            }
        }
159504
        CssProperty::BorderRightStyle(v) => {
159504
            if let Some(exact) = v.get_property() {
159492
                let bs = u16::from(border_style_to_u8(exact.inner));
159492
                cold.border_styles_packed = (cold.border_styles_packed & !0x00F0) | (bs << 4);
159492
            }
        }
175524
        CssProperty::BorderBottomStyle(v) => {
175524
            if let Some(exact) = v.get_property() {
175512
                let bs = u16::from(border_style_to_u8(exact.inner));
175512
                cold.border_styles_packed = (cold.border_styles_packed & !0x0F00) | (bs << 8);
175512
            }
        }
134544
        CssProperty::BorderLeftStyle(v) => {
134544
            if let Some(exact) = v.get_property() {
134532
                let bs = u16::from(border_style_to_u8(exact.inner));
134532
                cold.border_styles_packed = (cold.border_styles_packed & !0xF000) | (bs << 12);
134532
            }
        }
152988
        CssProperty::BorderTopColor(v) => {
152988
            if let Some(c) = v.get_property() {
152928
                cold.border_top_color = encode_color_u32(&c.inner);
152928
            }
        }
192660
        CssProperty::BorderRightColor(v) => {
192660
            if let Some(c) = v.get_property() {
192660
                cold.border_right_color = encode_color_u32(&c.inner);
192660
            }
        }
185016
        CssProperty::BorderBottomColor(v) => {
185016
            if let Some(c) = v.get_property() {
185016
                cold.border_bottom_color = encode_color_u32(&c.inner);
185016
            }
        }
140868
        CssProperty::BorderLeftColor(v) => {
140868
            if let Some(c) = v.get_property() {
140868
                cold.border_left_color = encode_color_u32(&c.inner);
140868
            }
        }
24
        CssProperty::BorderSpacing(v) => {
24
            if let Some(spacing) = v.get_property() {
24
                if spacing.horizontal.metric == SizeMetric::Px {
24
                    cold.border_spacing_h = encode_resolved_px_i16(spacing.horizontal.number.get());
24
                }
24
                if spacing.vertical.metric == SizeMetric::Px {
24
                    cold.border_spacing_v = encode_resolved_px_i16(spacing.vertical.number.get());
24
                }
            }
        }
        CssProperty::TabSize(v) => {
            cold.tab_size = encode_css_pixel_as_i16(v);
        }
        // Tier 2b text
299090
        CssProperty::TextColor(v) => {
299090
            if let Some(color) = v.get_property() {
299090
                let c = &color.inner;
299090
                text.text_color = (u32::from(c.r) << 24)
299090
                    | (u32::from(c.g) << 16)
299090
                    | (u32::from(c.b) << 8)
299090
                    | u32::from(c.a);
299090
            }
        }
23864
        CssProperty::FontFamily(v) => {
23864
            if let Some(families) = v.get_property() {
23864
                let mut hasher = DefaultHasher::new();
23864
                families.hash(&mut hasher);
23864
                let h = hasher.finish();
23864
                let h = if h == 0 { 1 } else { h };
23864
                text.font_family_hash = h;
23864
                font_hash_map.insert(h, families.clone());
            }
        }
1398
        CssProperty::LineHeight(v) => {
1398
            if let Some(lh) = v.get_property() {
                // Split scale by SIGN (see the builder's line-height pre-pass
                // and compact_cache.rs field doc): negative normalized =
                // absolute px, stored as -px x 10; positive = multiple,
                // stored x 1000. A single x1000 scale overflowed i16 for any
                // absolute line-height above 32.76px and silently became
                // "normal" via the sentinel.
1398
                let n = lh.inner.normalized();
1398
                let stored = if n < 0.0 {
225
                    ((n * 10.0).round() as i32).max(-32768)
                } else {
1173
                    (n * 1000.0).round() as i32
                };
1398
                if stored >= -32768 && stored < i32::from(I16_SENTINEL_THRESHOLD) {
1397
                    text.line_height = stored as i16;
1397
                } else {
1
                    text.line_height = I16_SENTINEL;
1
                }
            }
        }
36
        CssProperty::LetterSpacing(v) => {
36
            text.letter_spacing = encode_css_pixel_as_i16(v);
36
        }
12
        CssProperty::WordSpacing(v) => {
12
            text.word_spacing = encode_css_pixel_as_i16(v);
12
        }
12
        CssProperty::TextIndent(v) => {
12
            text.text_indent = encode_css_pixel_as_i16(v);
12
        }
        // Border radii (cold): encode px × 10 into i16; sentinel stays = unset/0
61610
        CssProperty::BorderTopLeftRadius(v) => {
61610
            if let Some(exact) = v.get_property() {
61610
                if exact.inner.metric == SizeMetric::Px {
61598
                    cold.border_top_left_radius = encode_resolved_px_i16(exact.inner.number.get());
61598
                }
            }
        }
61610
        CssProperty::BorderTopRightRadius(v) => {
61610
            if let Some(exact) = v.get_property() {
61610
                if exact.inner.metric == SizeMetric::Px {
61598
                    cold.border_top_right_radius = encode_resolved_px_i16(exact.inner.number.get());
61598
                }
            }
        }
62030
        CssProperty::BorderBottomLeftRadius(v) => {
62030
            if let Some(exact) = v.get_property() {
62030
                if exact.inner.metric == SizeMetric::Px {
62018
                    cold.border_bottom_left_radius =
62018
                        encode_resolved_px_i16(exact.inner.number.get());
62018
                }
            }
        }
62030
        CssProperty::BorderBottomRightRadius(v) => {
62030
            if let Some(exact) = v.get_property() {
62030
                if exact.inner.metric == SizeMetric::Px {
62018
                    cold.border_bottom_right_radius =
62018
                        encode_resolved_px_i16(exact.inner.number.get());
62018
                }
            }
        }
        // Opacity: encode as 0-254, 255 = sentinel (unset/default = 1.0)
8827
        CssProperty::Opacity(v) => {
8827
            if let Some(exact) = v.get_property() {
8827
                let o = exact.inner.normalized().clamp(0.0, 1.0);
8827
                let byte = (o * 254.0).round() as u8;
8827
                // byte is in [0, 254], never collides with OPACITY_SENTINEL=255
8827
                cold.opacity = byte;
8827
            }
        }
        // has-flags: set bit whenever property is set (regardless of value).
        // Getter uses this as a fast "is the default" bail-out.
652
        CssProperty::Transform(v) => {
652
            if v.get_property().is_some() {
652
                cold.hot_flags |= HOT_FLAG_HAS_TRANSFORM;
652
            }
        }
        CssProperty::TransformOrigin(v) => {
            if v.get_property().is_some() {
                cold.hot_flags |= HOT_FLAG_HAS_TRANSFORM_ORIGIN;
            }
        }
        // All four shadow sides wrap the same StyleBoxShadowValue and set the
        // single has-box-shadow bit.
852
        CssProperty::BoxShadowTop(v)
852
        | CssProperty::BoxShadowBottom(v)
852
        | CssProperty::BoxShadowLeft(v)
852
        | CssProperty::BoxShadowRight(v) => {
3408
            if v.get_property().is_some() {
3408
                cold.hot_flags |= HOT_FLAG_HAS_BOX_SHADOW;
3408
            }
        }
1502
        CssProperty::TextDecoration(v) => {
1502
            if v.get_property().is_some() {
1501
                cold.hot_flags |= HOT_FLAG_HAS_TEXT_DECORATION;
1501
            }
        }
3
        CssProperty::ScrollbarGutter(v) => {
3
            if let Some(exact) = v.get_property() {
                use azul_css::props::layout::overflow::StyleScrollbarGutter;
2
                let bits: u8 = match exact {
1
                    StyleScrollbarGutter::Auto => SCROLLBAR_GUTTER_AUTO,
1
                    StyleScrollbarGutter::Stable => SCROLLBAR_GUTTER_STABLE,
                    StyleScrollbarGutter::StableBothEdges => SCROLLBAR_GUTTER_BOTH_EDGES,
                };
2
                cold.hot_flags = (cold.hot_flags & !HOT_FLAG_SCROLLBAR_GUTTER_MASK)
2
                    | ((bits << HOT_FLAG_SCROLLBAR_GUTTER_SHIFT) & HOT_FLAG_SCROLLBAR_GUTTER_MASK);
1
            }
        }
244338
        CssProperty::BackgroundContent(v) => {
244338
            if v.get_property().is_some() {
244338
                cold.hot_flags |= HOT_FLAG_HAS_BACKGROUND;
244338
            }
        }
        CssProperty::ClipPath(v) => {
            if v.get_property().is_some() {
                cold.hot_flags |= HOT_FLAG_HAS_CLIP_PATH;
            }
        }
        // Any scrollbar customisation sets the single `has_any_scrollbar_css`
        // bit. When unset, get_scrollbar_style can bail to UA defaults without
        // doing 8 cascade walks.
        CssProperty::ScrollbarTrack(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_SCROLLBAR_CSS;
            }
        }
        CssProperty::ScrollbarThumb(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_SCROLLBAR_CSS;
            }
        }
        CssProperty::ScrollbarButton(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_SCROLLBAR_CSS;
            }
        }
        CssProperty::ScrollbarCorner(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_SCROLLBAR_CSS;
            }
        }
3194
        CssProperty::ScrollbarWidth(v) => {
3194
            if v.get_property().is_some() {
3084
                cold.extra_flags |= EXTRA_FLAG_HAS_SCROLLBAR_CSS;
3098
            }
        }
        CssProperty::ScrollbarColor(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_SCROLLBAR_CSS;
            }
        }
        CssProperty::ScrollbarVisibility(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_SCROLLBAR_CSS;
            }
        }
        CssProperty::ScrollbarFadeDelay(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_SCROLLBAR_CSS;
            }
        }
        CssProperty::ScrollbarFadeDuration(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_SCROLLBAR_CSS;
            }
        }
        // Rare paint/layout props with dedicated fast-path bits.
1320
        CssProperty::CounterReset(v) => {
1320
            if v.get_property().is_some() {
1320
                cold.extra_flags |= EXTRA_FLAG_HAS_COUNTER;
1320
            }
        }
        CssProperty::CounterIncrement(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_COUNTER;
            }
        }
        // Both break-before/after wrap PageBreakValue and set the has-break bit.
1607
        CssProperty::BreakBefore(v) | CssProperty::BreakAfter(v) => {
1679
            if v.get_property().is_some() {
1679
                cold.extra_flags |= EXTRA_FLAG_HAS_BREAK;
1679
            }
        }
        CssProperty::TextOrientation(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_TEXT_ORIENTATION;
            }
        }
        CssProperty::TextShadow(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_TEXT_SHADOW;
            }
        }
        CssProperty::BackdropFilter(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_BACKDROP_FILTER;
            }
        }
        CssProperty::Filter(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_FILTER;
            }
        }
        CssProperty::MixBlendMode(v) => {
            if v.get_property().is_some() {
                cold.extra_flags |= EXTRA_FLAG_HAS_MIX_BLEND_MODE;
            }
        }
        // Non-compact properties (background, etc.) — handled by get_property_slow fallback
272878
        _ => {}
    }
8865924
}
/// OR the DOM-level declared-flag for rarely-set text properties. Called once
/// per property per node so that when a flag bit is clear, callers
/// (e.g. `translate_to_text3_constraints`) can skip the cascade walk and use
/// the default value — the slow walk would never find a declaration anyway.
#[allow(clippy::too_many_lines)] // large but cohesive: one arm per declared-flag property
6852494
const fn update_dom_declared_flags(prop: &CssProperty, flags: &mut u32) {
    // Only mark if the property value is actually "set" (not Auto/Initial/etc.).
    // Using `get_property().is_some()` mirrors the pattern used elsewhere in
    // this builder for has-X bits.
6852494
    match prop {
        CssProperty::ShapeInside(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_SHAPE_INSIDE;
            }
        }
        CssProperty::ShapeOutside(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_SHAPE_OUTSIDE;
            }
        }
        CssProperty::TextJustify(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_TEXT_JUSTIFY;
            }
        }
18
        CssProperty::TextIndent(v) => {
18
            if v.get_property().is_some() {
16
                *flags |= DOM_HAS_TEXT_INDENT;
16
            }
        }
        CssProperty::ColumnCount(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_COLUMN_COUNT;
            }
        }
3048
        CssProperty::ColumnGap(v) => {
3048
            if v.get_property().is_some() {
3048
                *flags |= DOM_HAS_COLUMN_GAP;
3048
            }
        }
        CssProperty::ColumnWidth(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_COLUMN_WIDTH;
            }
        }
        CssProperty::InitialLetter(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_INITIAL_LETTER;
            }
        }
        CssProperty::InitialLetterAlign(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_INITIAL_LETTER_ALIGN;
            }
        }
        CssProperty::LineClamp(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_LINE_CLAMP;
            }
        }
        CssProperty::HangingPunctuation(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_HANGING_PUNCTUATION;
            }
        }
        CssProperty::TextCombineUpright(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_TEXT_COMBINE_UPRIGHT;
            }
        }
        CssProperty::ExclusionMargin(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_EXCLUSION_MARGIN;
            }
        }
        CssProperty::ShapeMargin(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_SHAPE_MARGIN;
            }
        }
        CssProperty::HyphenationLanguage(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_HYPHENATION_LANGUAGE;
            }
        }
        CssProperty::UnicodeBidi(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_UNICODE_BIDI;
            }
        }
48
        CssProperty::TextBoxTrim(v) => {
48
            if v.get_property().is_some() {
48
                *flags |= DOM_HAS_TEXT_BOX_TRIM;
48
            }
        }
        CssProperty::Hyphens(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_HYPHENS;
            }
        }
        CssProperty::WordBreak(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_WORD_BREAK;
            }
        }
24
        CssProperty::OverflowWrap(v) => {
24
            if v.get_property().is_some() {
24
                *flags |= DOM_HAS_OVERFLOW_WRAP;
24
            }
        }
        CssProperty::LineBreak(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_LINE_BREAK;
            }
        }
        CssProperty::TextAlignLast(v) => {
            if v.get_property().is_some() {
                *flags |= DOM_HAS_TEXT_ALIGN_LAST;
            }
        }
1399
        CssProperty::LineHeight(v) => {
1399
            if v.get_property().is_some() {
1398
                *flags |= DOM_HAS_LINE_HEIGHT;
1398
            }
        }
6847957
        _ => {}
    }
6852494
}
// =============================================================================
// Helper encoders for dimension properties
// =============================================================================
/// Encode a `GridLine` into i16: `Auto=I16_AUTO`, Line(n)=n, Span(n)=-(n).
/// Named lines fall back to `I16_SENTINEL` (not compact-encodable).
// const fn: the `n as i16` casts are guarded by explicit +/-32000 range checks.
#[allow(clippy::cast_possible_truncation)]
511
const fn encode_grid_line(line: &azul_css::props::layout::grid::GridLine) -> i16 {
    use azul_css::props::layout::grid::GridLine;
511
    match line {
1
        GridLine::Auto => I16_AUTO,
17
        GridLine::Line(n) => {
17
            if *n >= -32000 && *n <= 32000 {
13
                *n as i16
            } else {
4
                I16_SENTINEL
            }
        }
12
        GridLine::Span(n) => {
12
            if *n >= 1 && *n <= 32000 {
7
                -(*n as i16)
            } else {
5
                I16_SENTINEL
            }
        }
481
        GridLine::Named(_) => I16_SENTINEL,
    }
511
}
/// Encode a `CssPropertyValue`<LayoutWidth> into u32 compact form.
431184
fn encode_layout_width<T: LayoutWidthLike>(val: &CssPropertyValue<T>) -> u32 {
431184
    match val {
431124
        CssPropertyValue::Exact(w) => w.encode_compact_u32(),
50
        CssPropertyValue::Auto => U32_AUTO,
1
        CssPropertyValue::Initial => U32_INITIAL,
1
        CssPropertyValue::Inherit => U32_INHERIT,
2
        CssPropertyValue::None => U32_NONE,
6
        _ => U32_SENTINEL,
    }
431184
}
/// Encode a `CssPropertyValue`<LayoutHeight> into u32 compact form.
231145
fn encode_layout_height<T: LayoutWidthLike>(val: &CssPropertyValue<T>) -> u32 {
231145
    encode_layout_width(val)
231145
}
/// Trait for types that can be encoded as compact u32 dimension values.
/// Implemented for `LayoutWidth`, `LayoutHeight` (which are Auto|Px|MinContent|MaxContent|Calc
/// enums).
trait LayoutWidthLike {
    fn encode_compact_u32(&self) -> u32;
}
impl LayoutWidthLike for LayoutWidth {
199987
    fn encode_compact_u32(&self) -> u32 {
199987
        match self {
3
            Self::Auto => U32_AUTO,
199958
            Self::Px(pv) => encode_pixel_value_u32(pv),
3
            Self::MinContent => U32_MIN_CONTENT,
3
            Self::MaxContent => U32_MAX_CONTENT,
            // FitContent/Calc are not compact-encodable → overflow to tier 3.
20
            Self::FitContent(_) | Self::Calc(_) => U32_SENTINEL,
        }
199987
    }
}
impl LayoutWidthLike for LayoutHeight {
231137
    fn encode_compact_u32(&self) -> u32 {
231137
        match self {
            Self::Auto => U32_AUTO,
231137
            Self::Px(pv) => encode_pixel_value_u32(pv),
            Self::MinContent => U32_MIN_CONTENT,
            Self::MaxContent => U32_MAX_CONTENT,
            // FitContent/Calc are not compact-encodable → overflow to tier 3.
            Self::FitContent(_) | Self::Calc(_) => U32_SENTINEL,
        }
231137
    }
}
/// Encode a `CssPropertyValue` wrapping a simple `PixelValue` struct (`LayoutMinWidth`, etc.)
349141
fn encode_pixel_prop<T: HasInnerPixelValue>(val: &CssPropertyValue<T>) -> u32 {
349141
    match val {
349135
        CssPropertyValue::Exact(inner) => encode_pixel_value_u32(&inner.get_inner_pixel()),
1
        CssPropertyValue::Auto => U32_AUTO,
1
        CssPropertyValue::Initial => U32_INITIAL,
1
        CssPropertyValue::Inherit => U32_INHERIT,
1
        CssPropertyValue::None => U32_NONE,
2
        _ => U32_SENTINEL,
    }
349141
}
/// Trait for dimension structs wrapping `inner: PixelValue`.
trait HasInnerPixelValue {
    fn get_inner_pixel(&self) -> azul_css::props::basic::pixel::PixelValue;
}
macro_rules! impl_has_inner_pixel {
    ($($ty:ty),*) => {
        $(
            impl HasInnerPixelValue for $ty {
5512532
                fn get_inner_pixel(&self) -> azul_css::props::basic::pixel::PixelValue {
5512532
                    self.inner
5512532
                }
            }
        )*
    };
}
impl_has_inner_pixel!(
    azul_css::props::layout::dimensions::LayoutMinWidth,
    azul_css::props::layout::dimensions::LayoutMaxWidth,
    azul_css::props::layout::dimensions::LayoutMinHeight,
    azul_css::props::layout::dimensions::LayoutMaxHeight,
    azul_css::props::basic::font::StyleFontSize,
    azul_css::props::layout::spacing::LayoutPaddingTop,
    azul_css::props::layout::spacing::LayoutPaddingRight,
    azul_css::props::layout::spacing::LayoutPaddingBottom,
    azul_css::props::layout::spacing::LayoutPaddingLeft,
    azul_css::props::layout::spacing::LayoutMarginTop,
    azul_css::props::layout::spacing::LayoutMarginRight,
    azul_css::props::layout::spacing::LayoutMarginBottom,
    azul_css::props::layout::spacing::LayoutMarginLeft,
    azul_css::props::style::border::LayoutBorderTopWidth,
    azul_css::props::style::border::LayoutBorderRightWidth,
    azul_css::props::style::border::LayoutBorderBottomWidth,
    azul_css::props::style::border::LayoutBorderLeftWidth,
    azul_css::props::layout::position::LayoutTop,
    azul_css::props::layout::position::LayoutRight,
    azul_css::props::layout::position::LayoutInsetBottom,
    azul_css::props::layout::position::LayoutLeft,
    azul_css::props::style::text::StyleLetterSpacing,
    azul_css::props::style::text::StyleWordSpacing,
    azul_css::props::style::text::StyleTextIndent,
    azul_css::props::style::text::StyleTabSize
);
/// Encode a `CssPropertyValue`<T> where T wraps a `PixelValue`, as i16 (×10 resolved px).
/// Delegates to the canonical `azul_css::compact_cache::encode_css_pixel_as_i16`.
3005101
fn encode_css_pixel_as_i16<T: HasInnerPixelValue>(val: &CssPropertyValue<T>) -> i16 {
3005101
    let mapped = match val {
3004914
        CssPropertyValue::Exact(inner) => CssPropertyValue::Exact(inner.get_inner_pixel()),
122
        CssPropertyValue::Auto => CssPropertyValue::Auto,
1
        CssPropertyValue::Initial => CssPropertyValue::Initial,
1
        CssPropertyValue::Inherit => CssPropertyValue::Inherit,
61
        CssPropertyValue::None => CssPropertyValue::None,
2
        _ => return I16_SENTINEL,
    };
3005099
    azul_css::compact_cache::encode_css_pixel_as_i16(&mapped)
3005101
}
/// Encode margin: same as `encode_css_pixel_as_i16` but Auto is a distinct value.
1347161
fn encode_margin_i16<T: HasInnerPixelValue>(val: &CssPropertyValue<T>) -> i16 {
1347161
    encode_css_pixel_as_i16(val)
1347161
}
/// Encode `CssPropertyValue`<LayoutFlexBasis> — `LayoutFlexBasis` is Auto | Exact(PixelValue).
12778
fn encode_flex_basis(val: &CssPropertyValue<LayoutFlexBasis>) -> u32 {
12778
    match val {
12748
        CssPropertyValue::Exact(fb) => match fb {
1
            LayoutFlexBasis::Auto => U32_AUTO,
12747
            LayoutFlexBasis::Exact(pv) => encode_pixel_value_u32(pv),
        },
25
        CssPropertyValue::Auto => U32_AUTO,
1
        CssPropertyValue::Initial => U32_INITIAL,
1
        CssPropertyValue::Inherit => U32_INHERIT,
1
        CssPropertyValue::None => U32_NONE,
2
        _ => U32_SENTINEL,
    }
12778
}
#[cfg(test)]
#[path = "compact_test.rs"]
mod compact_test;