1
//! User-Agent Default Stylesheet for Azul
2
//!
3
//! This module provides the default CSS styling that browsers apply to HTML elements
4
//! before any author stylesheets are processed. It ensures consistent baseline behavior
5
//! across all applications.
6
//!
7
//! The user-agent stylesheet serves several critical functions:
8
//!
9
//! 1. **Prevents Layout Collapse**: Ensures root elements (`<html>`, `<body>`) have default
10
//!    dimensions so that percentage-based child sizing can work correctly.
11
//!
12
//! 2. **Establishes Display Types**: Defines the default `display` property for all HTML elements
13
//!    (e.g., `<div>` is `block`, `<span>` is `inline`).
14
//!
15
//! 3. **Provides Baseline Typography**: Sets reasonable defaults for font sizes, margins, and text
16
//!    styling for headings, paragraphs, and other text elements.
17
//!
18
//! 4. **Normalizes Browser Behavior**: Incorporates principles from normalize.css to provide
19
//!    consistent rendering across different platforms.
20
//!
21
//! # Licensing
22
//!
23
//! Based on principles from [normalize.css](https://github.com/necolas/normalize.css)
24
//! (MIT License, Copyright Nicolas Gallagher and Jonathan Neal).
25
//! This is NOT a direct copy but incorporates its principles and approach.
26
//!
27
//! # References
28
//!
29
//! - CSS 2.1 Specification: https://www.w3.org/TR/CSS21/
30
//! - HTML Living Standard: https://html.spec.whatwg.org/
31
//! - normalize.css: https://necolas.github.io/normalize.css/
32

            
33
use azul_css::{
34
    css::CssPropertyValue,
35
    dynamic_selector::{
36
        CssPropertyWithConditions, DynamicSelector, DynamicSelectorContext, OsCondition,
37
        ThemeCondition,
38
    },
39
    props::{
40
        basic::{font::StyleFontWeight, pixel::PixelValue, ColorU, StyleFontSize},
41
        layout::{
42
            dimensions::{LayoutHeight, LayoutWidth},
43
            display::LayoutDisplay,
44
            fragmentation::{BreakInside, PageBreak},
45
            spacing::{
46
                LayoutMarginBottom, LayoutMarginLeft, LayoutMarginRight, LayoutMarginTop,
47
                LayoutPaddingBottom, LayoutPaddingInlineEnd, LayoutPaddingInlineStart,
48
                LayoutPaddingLeft, LayoutPaddingRight, LayoutPaddingTop,
49
            },
50
        },
51
        property::{CssProperty, CssPropertyType},
52
        style::{
53
            border::{
54
                BorderStyle, LayoutBorderBottomWidth, LayoutBorderLeftWidth,
55
                LayoutBorderRightWidth, LayoutBorderTopWidth, StyleBorderBottomColor,
56
                StyleBorderBottomStyle, StyleBorderLeftColor, StyleBorderLeftStyle,
57
                StyleBorderRightColor, StyleBorderRightStyle, StyleBorderTopColor,
58
                StyleBorderTopStyle,
59
            },
60
            content::CounterReset,
61
            effects::StyleCursor,
62
            lists::StyleListStyleType,
63
            scrollbar::{
64
                LayoutScrollbarWidth, ScrollbarColorCustom, ScrollbarFadeDelay,
65
                ScrollbarFadeDuration, ScrollbarVisibilityMode, StyleScrollbarColor,
66
            },
67
            text::StyleTextDecoration,
68
            StyleTextAlign, StyleVerticalAlign,
69
        },
70
    },
71
};
72

            
73
use crate::dom::{NodeData, NodeType};
74

            
75
/// `white-space: pre` — the `<pre>` default (HTML rendering §15.3.3).
76
static WHITE_SPACE_PRE: CssProperty = CssProperty::WhiteSpace(CssPropertyValue::Exact(
77
    azul_css::props::style::StyleWhiteSpace::Pre,
78
));
79
/// `white-space: pre-wrap` — `<textarea>` (HTML rendering §15.5.14) and every
80
/// editing host (see [`get_ua_editing_host_property`]).
81
static WHITE_SPACE_PRE_WRAP: CssProperty = CssProperty::WhiteSpace(CssPropertyValue::Exact(
82
    azul_css::props::style::StyleWhiteSpace::PreWrap,
83
));
84
/// `overflow-wrap: break-word` — editable text wraps an overlong word instead
85
/// of running it out of the box (the textarea / contenteditable default in
86
/// every engine).
87
static OVERFLOW_WRAP_BREAK_WORD: CssProperty = CssProperty::OverflowWrap(
88
    CssPropertyValue::Exact(azul_css::props::style::StyleOverflowWrap::BreakWord),
89
);
90

            
91
/// 100% width
92
static WIDTH_100_PERCENT: CssProperty = CssProperty::Width(CssPropertyValue::Exact(
93
    LayoutWidth::Px(PixelValue::const_percent(100)),
94
));
95

            
96
/// 100% height
97
static HEIGHT_100_PERCENT: CssProperty = CssProperty::Height(CssPropertyValue::Exact(
98
    LayoutHeight::Px(PixelValue::const_percent(100)),
99
));
100

            
101
/// display: block
102
static DISPLAY_BLOCK: CssProperty =
103
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::Block));
104
static OVERFLOW_X_AUTO: CssProperty = CssProperty::OverflowX(CssPropertyValue::Exact(
105
    azul_css::props::layout::LayoutOverflow::Auto,
106
));
107
static OVERFLOW_Y_AUTO: CssProperty = CssProperty::OverflowY(CssPropertyValue::Exact(
108
    azul_css::props::layout::LayoutOverflow::Auto,
109
));
110

            
111
/// display: inline
112
static DISPLAY_INLINE: CssProperty =
113
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::Inline));
114

            
115
/// display: inline-block
116
static DISPLAY_INLINE_BLOCK: CssProperty =
117
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::InlineBlock));
118

            
119
/// display: none
120
// <transient-window> UA defaults. `position: absolute; top: 100%` is the web
121
// fallback in full: a closed popup is display:none, an open one is a block
122
// anchored to the bottom edge of its parent. The NATIVE path does not read
123
// these — it positions a real surface from the anchor edge instead — but they
124
// are the same statement in two dialects, so an app that opts into neither
125
// gets a popup that opens below its anchor on every target.
126
static POSITION_ABSOLUTE: CssProperty = CssProperty::Position(CssPropertyValue::Exact(
127
    azul_css::props::layout::position::LayoutPosition::Absolute,
128
));
129
static TOP_100_PERCENT: CssProperty = CssProperty::Top(CssPropertyValue::Exact(
130
    azul_css::props::layout::position::LayoutTop {
131
        inner: PixelValue::const_percent(100),
132
    },
133
));
134
static DISPLAY_NONE: CssProperty =
135
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::None));
136

            
137
/// break-before: page (the canonical `<pagebreak/>` element)
138
static BREAK_BEFORE_PAGE: CssProperty =
139
    CssProperty::BreakBefore(CssPropertyValue::Exact(PageBreak::Page));
140

            
141
/// display: table
142
static DISPLAY_TABLE: CssProperty =
143
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::Table));
144

            
145
/// display: table-row
146
static DISPLAY_TABLE_ROW: CssProperty =
147
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableRow));
148

            
149
/// display: table-cell
150
static DISPLAY_TABLE_CELL: CssProperty =
151
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableCell));
152

            
153
/// display: table-header-group
154
static DISPLAY_TABLE_HEADER_GROUP: CssProperty =
155
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableHeaderGroup));
156

            
157
/// display: table-row-group
158
static DISPLAY_TABLE_ROW_GROUP: CssProperty =
159
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableRowGroup));
160

            
161
/// display: table-footer-group
162
static DISPLAY_TABLE_FOOTER_GROUP: CssProperty =
163
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableFooterGroup));
164

            
165
/// display: table-caption
166
static DISPLAY_TABLE_CAPTION: CssProperty =
167
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableCaption));
168

            
169
/// display: table-column-group
170
static DISPLAY_TABLE_COLUMN_GROUP: CssProperty =
171
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableColumnGroup));
172

            
173
/// display: table-column
174
static DISPLAY_TABLE_COLUMN: CssProperty =
175
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::TableColumn));
176

            
177
/// display: list-item
178
static DISPLAY_LIST_ITEM: CssProperty =
179
    CssProperty::Display(CssPropertyValue::Exact(LayoutDisplay::ListItem));
180

            
181
/// cursor: pointer (for clickable elements like buttons, links)
182
static CURSOR_POINTER: CssProperty =
183
    CssProperty::Cursor(CssPropertyValue::Exact(StyleCursor::Pointer));
184

            
185
/// cursor: text (for selectable text elements)
186
static CURSOR_TEXT: CssProperty = CssProperty::Cursor(CssPropertyValue::Exact(StyleCursor::Text));
187

            
188
/// margin-top: 0
189
static MARGIN_TOP_ZERO: CssProperty =
190
    CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
191
        inner: PixelValue::const_px(0),
192
    }));
193

            
194
/// margin-bottom: 0
195
static MARGIN_BOTTOM_ZERO: CssProperty =
196
    CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
197
        inner: PixelValue::const_px(0),
198
    }));
199

            
200
/// margin-left: 0
201
static MARGIN_LEFT_ZERO: CssProperty =
202
    CssProperty::MarginLeft(CssPropertyValue::Exact(LayoutMarginLeft {
203
        inner: PixelValue::const_px(0),
204
    }));
205

            
206
/// margin-right: 0
207
static MARGIN_RIGHT_ZERO: CssProperty =
208
    CssProperty::MarginRight(CssPropertyValue::Exact(LayoutMarginRight {
209
        inner: PixelValue::const_px(0),
210
    }));
211

            
212
// Chrome User-Agent Stylesheet: body { margin: 8px; }
213
/// margin-top: 8px (Chrome UA default for body)
214
static MARGIN_TOP_8PX: CssProperty =
215
    CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
216
        inner: PixelValue::const_px(8),
217
    }));
218

            
219
/// margin-bottom: 8px (Chrome UA default for body)
220
static MARGIN_BOTTOM_8PX: CssProperty =
221
    CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
222
        inner: PixelValue::const_px(8),
223
    }));
224

            
225
/// margin-left: 8px (Chrome UA default for body)
226
static MARGIN_LEFT_8PX: CssProperty =
227
    CssProperty::MarginLeft(CssPropertyValue::Exact(LayoutMarginLeft {
228
        inner: PixelValue::const_px(8),
229
    }));
230

            
231
/// margin-right: 8px (Chrome UA default for body)
232
static MARGIN_RIGHT_8PX: CssProperty =
233
    CssProperty::MarginRight(CssPropertyValue::Exact(LayoutMarginRight {
234
        inner: PixelValue::const_px(8),
235
    }));
236

            
237
/// font-size: 2em (for H1)
238
static FONT_SIZE_2EM: CssProperty = CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
239
    inner: PixelValue::const_em(2),
240
}));
241

            
242
/// font-size: 1.5em (for H2)
243
static FONT_SIZE_1_5EM: CssProperty =
244
    CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
245
        inner: PixelValue::const_em_fractional(1, 5),
246
    }));
247

            
248
/// font-size: 1.17em (for H3)
249
static FONT_SIZE_1_17EM: CssProperty =
250
    CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
251
        inner: PixelValue::const_em_fractional(1, 17),
252
    }));
253

            
254
/// font-size: 1em (for H4)
255
static FONT_SIZE_1EM: CssProperty = CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
256
    inner: PixelValue::const_em(1),
257
}));
258

            
259
/// font-size: 0.83em (for H5)
260
static FONT_SIZE_0_83EM: CssProperty =
261
    CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
262
        inner: PixelValue::const_em_fractional(0, 83),
263
    }));
264

            
265
/// font-size: 0.67em (for H6)
266
static FONT_SIZE_0_67EM: CssProperty =
267
    CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
268
        inner: PixelValue::const_em_fractional(0, 67),
269
    }));
270

            
271
/// margin-top: 1em (for P)
272
static MARGIN_TOP_1EM: CssProperty =
273
    CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
274
        inner: PixelValue::const_em(1),
275
    }));
276

            
277
/// margin-bottom: 1em (for P)
278
static MARGIN_BOTTOM_1EM: CssProperty =
279
    CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
280
        inner: PixelValue::const_em(1),
281
    }));
282

            
283
/// margin-top: 0.67em (for H1)
284
static MARGIN_TOP_0_67EM: CssProperty =
285
    CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
286
        inner: PixelValue::const_em_fractional(0, 67),
287
    }));
288

            
289
/// margin-bottom: 0.67em (for H1)
290
static MARGIN_BOTTOM_0_67EM: CssProperty =
291
    CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
292
        inner: PixelValue::const_em_fractional(0, 67),
293
    }));
294

            
295
/// margin-top: 0.83em (for H2)
296
static MARGIN_TOP_0_83EM: CssProperty =
297
    CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
298
        inner: PixelValue::const_em_fractional(0, 83),
299
    }));
300

            
301
/// margin-bottom: 0.83em (for H2)
302
static MARGIN_BOTTOM_0_83EM: CssProperty =
303
    CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
304
        inner: PixelValue::const_em_fractional(0, 83),
305
    }));
306

            
307
/// margin-top: 1.33em (for H4)
308
static MARGIN_TOP_1_33EM: CssProperty =
309
    CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
310
        inner: PixelValue::const_em_fractional(1, 33),
311
    }));
312

            
313
/// margin-bottom: 1.33em (for H4)
314
static MARGIN_BOTTOM_1_33EM: CssProperty =
315
    CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
316
        inner: PixelValue::const_em_fractional(1, 33),
317
    }));
318

            
319
/// margin-top: 1.67em (for H5)
320
static MARGIN_TOP_1_67EM: CssProperty =
321
    CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
322
        inner: PixelValue::const_em_fractional(1, 67),
323
    }));
324

            
325
/// margin-bottom: 1.67em (for H5)
326
static MARGIN_BOTTOM_1_67EM: CssProperty =
327
    CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
328
        inner: PixelValue::const_em_fractional(1, 67),
329
    }));
330

            
331
/// margin-top: 2.33em (for H6)
332
static MARGIN_TOP_2_33EM: CssProperty =
333
    CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
334
        inner: PixelValue::const_em_fractional(2, 33),
335
    }));
336

            
337
/// margin-bottom: 2.33em (for H6)
338
static MARGIN_BOTTOM_2_33EM: CssProperty =
339
    CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
340
        inner: PixelValue::const_em_fractional(2, 33),
341
    }));
342

            
343
/// font-weight: bold (for headings)
344
static FONT_WEIGHT_BOLD: CssProperty =
345
    CssProperty::FontWeight(CssPropertyValue::Exact(StyleFontWeight::Bold));
346

            
347
/// font-weight: bolder
348
static FONT_WEIGHT_BOLDER: CssProperty =
349
    CssProperty::FontWeight(CssPropertyValue::Exact(StyleFontWeight::Bolder));
350

            
351
// Table cell padding - Chrome UA CSS default: 1px
352
static PADDING_TOP_1PX: CssProperty =
353
    CssProperty::PaddingTop(CssPropertyValue::Exact(LayoutPaddingTop {
354
        inner: PixelValue::const_px(1),
355
    }));
356

            
357
static PADDING_BOTTOM_1PX: CssProperty =
358
    CssProperty::PaddingBottom(CssPropertyValue::Exact(LayoutPaddingBottom {
359
        inner: PixelValue::const_px(1),
360
    }));
361

            
362
static PADDING_LEFT_1PX: CssProperty =
363
    CssProperty::PaddingLeft(CssPropertyValue::Exact(LayoutPaddingLeft {
364
        inner: PixelValue::const_px(1),
365
    }));
366

            
367
static PADDING_RIGHT_1PX: CssProperty =
368
    CssProperty::PaddingRight(CssPropertyValue::Exact(LayoutPaddingRight {
369
        inner: PixelValue::const_px(1),
370
    }));
371

            
372
/// text-align: center (for th elements)
373
static TEXT_ALIGN_CENTER: CssProperty =
374
    CssProperty::TextAlign(CssPropertyValue::Exact(StyleTextAlign::Center));
375

            
376
/// vertical-align: middle (for table elements)
377
static VERTICAL_ALIGN_MIDDLE: CssProperty =
378
    CssProperty::VerticalAlign(CssPropertyValue::Exact(StyleVerticalAlign::Middle));
379

            
380
/// list-style-type: disc (default for <ul>)
381
static LIST_STYLE_TYPE_DISC: CssProperty =
382
    CssProperty::ListStyleType(CssPropertyValue::Exact(StyleListStyleType::Disc));
383

            
384
/// list-style-type: decimal (default for <ol>)
385
static LIST_STYLE_TYPE_DECIMAL: CssProperty =
386
    CssProperty::ListStyleType(CssPropertyValue::Exact(StyleListStyleType::Decimal));
387

            
388
// --- HR Element Defaults ---
389
// Per HTML spec, <hr> renders as a horizontal line with inset border style
390

            
391
/// margin-top: 0.5em (for hr)
392
static MARGIN_TOP_0_5EM: CssProperty =
393
    CssProperty::MarginTop(CssPropertyValue::Exact(LayoutMarginTop {
394
        inner: PixelValue::const_em_fractional(0, 5),
395
    }));
396

            
397
/// margin-bottom: 0.5em (for hr)
398
static MARGIN_BOTTOM_0_5EM: CssProperty =
399
    CssProperty::MarginBottom(CssPropertyValue::Exact(LayoutMarginBottom {
400
        inner: PixelValue::const_em_fractional(0, 5),
401
    }));
402

            
403
/// border-top-style: inset (for hr - default browser style)
404
static BORDER_TOP_STYLE_INSET: CssProperty =
405
    CssProperty::BorderTopStyle(CssPropertyValue::Exact(StyleBorderTopStyle {
406
        inner: BorderStyle::Inset,
407
    }));
408

            
409
/// border-top-width: 1px (for hr)
410
static BORDER_TOP_WIDTH_1PX: CssProperty =
411
    CssProperty::BorderTopWidth(CssPropertyValue::Exact(LayoutBorderTopWidth {
412
        inner: PixelValue::const_px(1),
413
    }));
414

            
415
/// border-top-color: gray (for hr - default visible color)
416
static BORDER_TOP_COLOR_GRAY: CssProperty =
417
    CssProperty::BorderTopColor(CssPropertyValue::Exact(StyleBorderTopColor {
418
        inner: ColorU {
419
            r: 128,
420
            g: 128,
421
            b: 128,
422
            a: 255,
423
        },
424
    }));
425

            
426
/// border-top-color for hr on a DARK window: a subtle divider, like the
427
/// platforms' own separators on dark (#5a5a5a), where the light rule's mid
428
/// grey would read as a bright bar.
429
static BORDER_TOP_COLOR_GRAY_DARK: CssProperty =
430
    CssProperty::BorderTopColor(CssPropertyValue::Exact(StyleBorderTopColor {
431
        inner: ColorU {
432
            r: 90,
433
            g: 90,
434
            b: 90,
435
            a: 255,
436
        },
437
    }));
438
/// height: 0 (for hr - the line comes from the border, not height)
439
static HEIGHT_ZERO: CssProperty = CssProperty::Height(CssPropertyValue::Exact(LayoutHeight::Px(
440
    PixelValue::const_px(0),
441
)));
442

            
443
/// counter-reset: list-item 0 (default for <ul>, <ol>)
444
/// Per CSS Lists Module Level 3, list containers automatically reset the list-item counter
445
static COUNTER_RESET_LIST_ITEM: CssProperty =
446
    CssProperty::CounterReset(CssPropertyValue::Exact(CounterReset::list_item()));
447

            
448
// CSS Fragmentation (Page Breaking) Properties
449
//
450
// Per CSS Fragmentation Level 3 and paged media best practices,
451
// certain elements should avoid page breaks inside them
452

            
453
/// break-inside: avoid
454
/// Used for elements that should not be split across page boundaries
455
/// Applied to: h1-h6, table, thead, tbody, tfoot, figure, figcaption
456
static BREAK_INSIDE_AVOID: CssProperty = CssProperty::break_inside(BreakInside::Avoid);
457

            
458
/// break-after: avoid
459
/// Avoids a page break after the element (useful for headings)
460
static BREAK_AFTER_AVOID: CssProperty = CssProperty::break_after(PageBreak::Avoid);
461

            
462
/// padding-inline-start: 40px (default for <li>)
463
///
464
/// Creates space for list markers in the inline-start direction (left in LTR, right in RTL)
465
/// padding-inline-start: 40px for list items per CSS Lists Module Level 3
466
/// Applied to <li> items to create gutter space for `::marker` pseudo-elements
467
///
468
/// NOTE: This should be on the list items, not the container, because:
469
///
470
/// 1. `::marker` pseudo-elements are children of <li>, not <ul>/<ol>
471
/// 2. The marker needs to be positioned relative to the list item's content box
472
/// 3. Padding on <li> creates space between the marker and the text content TODO: Change to
473
///    `PaddingInlineStart` once logical property resolution is implemented
474
static PADDING_INLINE_START_40PX: CssProperty =
475
    CssProperty::PaddingLeft(CssPropertyValue::Exact(LayoutPaddingLeft {
476
        inner: PixelValue::const_px(40),
477
    }));
478

            
479
/// Text decoration: underline - used for <a> and <u> elements
480
static TEXT_DECORATION_UNDERLINE: CssProperty =
481
    CssProperty::TextDecoration(CssPropertyValue::Exact(StyleTextDecoration::Underline));
482

            
483
// --- Button Element Defaults ---
484
// Per browser UA CSS, <button> has padding, border, and a system font size.
485
// These ensure a button is visible even without author CSS.
486

            
487
/// font-size: 13px (standard button font size on macOS/Linux)
488
static FONT_SIZE_13PX: CssProperty =
489
    CssProperty::FontSize(CssPropertyValue::Exact(StyleFontSize {
490
        inner: PixelValue::const_px(13),
491
    }));
492

            
493
/// padding-top: 5px (button)
494
static PADDING_TOP_5PX: CssProperty =
495
    CssProperty::PaddingTop(CssPropertyValue::Exact(LayoutPaddingTop {
496
        inner: PixelValue::const_px(5),
497
    }));
498

            
499
/// padding-bottom: 5px (button)
500
static PADDING_BOTTOM_5PX: CssProperty =
501
    CssProperty::PaddingBottom(CssPropertyValue::Exact(LayoutPaddingBottom {
502
        inner: PixelValue::const_px(5),
503
    }));
504

            
505
/// padding-left: 10px (button)
506
static PADDING_LEFT_10PX: CssProperty =
507
    CssProperty::PaddingLeft(CssPropertyValue::Exact(LayoutPaddingLeft {
508
        inner: PixelValue::const_px(10),
509
    }));
510

            
511
/// padding-right: 10px (button)
512
static PADDING_RIGHT_10PX: CssProperty =
513
    CssProperty::PaddingRight(CssPropertyValue::Exact(LayoutPaddingRight {
514
        inner: PixelValue::const_px(10),
515
    }));
516

            
517
/// Border color for button: #c8c8c8 (light gray)
518
static BUTTON_BORDER_COLOR: ColorU = ColorU {
519
    r: 200,
520
    g: 200,
521
    b: 200,
522
    a: 255,
523
};
524

            
525
/// Border color for a native button on a DARK window: #5a5a5a. The light
526
/// rule's #c8c8c8 is chosen for a white surface and glares on a dark one.
527
static BUTTON_BORDER_COLOR_DARK: ColorU = ColorU {
528
    r: 90,
529
    g: 90,
530
    b: 90,
531
    a: 255,
532
};
533
static BUTTON_BORDER_TOP_COLOR_DARK: CssProperty =
534
    CssProperty::BorderTopColor(CssPropertyValue::Exact(StyleBorderTopColor {
535
        inner: BUTTON_BORDER_COLOR_DARK,
536
    }));
537
static BUTTON_BORDER_BOTTOM_COLOR_DARK: CssProperty =
538
    CssProperty::BorderBottomColor(CssPropertyValue::Exact(StyleBorderBottomColor {
539
        inner: BUTTON_BORDER_COLOR_DARK,
540
    }));
541
static BUTTON_BORDER_LEFT_COLOR_DARK: CssProperty =
542
    CssProperty::BorderLeftColor(CssPropertyValue::Exact(StyleBorderLeftColor {
543
        inner: BUTTON_BORDER_COLOR_DARK,
544
    }));
545
static BUTTON_BORDER_RIGHT_COLOR_DARK: CssProperty =
546
    CssProperty::BorderRightColor(CssPropertyValue::Exact(StyleBorderRightColor {
547
        inner: BUTTON_BORDER_COLOR_DARK,
548
    }));
549
static BUTTON_BORDER_TOP_COLOR: CssProperty =
550
    CssProperty::BorderTopColor(CssPropertyValue::Exact(StyleBorderTopColor {
551
        inner: BUTTON_BORDER_COLOR,
552
    }));
553
static BUTTON_BORDER_BOTTOM_COLOR: CssProperty =
554
    CssProperty::BorderBottomColor(CssPropertyValue::Exact(StyleBorderBottomColor {
555
        inner: BUTTON_BORDER_COLOR,
556
    }));
557
static BUTTON_BORDER_LEFT_COLOR: CssProperty =
558
    CssProperty::BorderLeftColor(CssPropertyValue::Exact(StyleBorderLeftColor {
559
        inner: BUTTON_BORDER_COLOR,
560
    }));
561
static BUTTON_BORDER_RIGHT_COLOR: CssProperty =
562
    CssProperty::BorderRightColor(CssPropertyValue::Exact(StyleBorderRightColor {
563
        inner: BUTTON_BORDER_COLOR,
564
    }));
565

            
566
static BUTTON_BORDER_TOP_STYLE: CssProperty =
567
    CssProperty::BorderTopStyle(CssPropertyValue::Exact(StyleBorderTopStyle {
568
        inner: BorderStyle::Solid,
569
    }));
570
static BUTTON_BORDER_BOTTOM_STYLE: CssProperty =
571
    CssProperty::BorderBottomStyle(CssPropertyValue::Exact(StyleBorderBottomStyle {
572
        inner: BorderStyle::Solid,
573
    }));
574
static BUTTON_BORDER_LEFT_STYLE: CssProperty =
575
    CssProperty::BorderLeftStyle(CssPropertyValue::Exact(StyleBorderLeftStyle {
576
        inner: BorderStyle::Solid,
577
    }));
578
static BUTTON_BORDER_RIGHT_STYLE: CssProperty =
579
    CssProperty::BorderRightStyle(CssPropertyValue::Exact(StyleBorderRightStyle {
580
        inner: BorderStyle::Solid,
581
    }));
582

            
583
static BUTTON_BORDER_TOP_WIDTH: CssProperty =
584
    CssProperty::BorderTopWidth(CssPropertyValue::Exact(LayoutBorderTopWidth {
585
        inner: PixelValue::const_px(1),
586
    }));
587
static BUTTON_BORDER_BOTTOM_WIDTH: CssProperty =
588
    CssProperty::BorderBottomWidth(CssPropertyValue::Exact(LayoutBorderBottomWidth {
589
        inner: PixelValue::const_px(1),
590
    }));
591
static BUTTON_BORDER_LEFT_WIDTH: CssProperty =
592
    CssProperty::BorderLeftWidth(CssPropertyValue::Exact(LayoutBorderLeftWidth {
593
        inner: PixelValue::const_px(1),
594
    }));
595
static BUTTON_BORDER_RIGHT_WIDTH: CssProperty =
596
    CssProperty::BorderRightWidth(CssPropertyValue::Exact(LayoutBorderRightWidth {
597
        inner: PixelValue::const_px(1),
598
    }));
599

            
600
/// Returns the default user-agent CSS property value for a given node type and property.
601
///
602
/// This function provides the baseline styling that should be applied before any author
603
/// styles. It ensures that elements have sensible defaults that prevent layout issues.
604
///
605
/// # Arguments
606
///
607
/// * `node_type` - The type of DOM node (e.g., `Body`, `H1`, `Div`)
608
/// * `property_type` - The specific CSS property to query (e.g., `Width`, `Display`)
609
///
610
/// # Returns
611
///
612
/// `Some(CssProperty)` if a default value is defined for this combination, otherwise `None`.
613
// Exhaustive (node-type, property-type) → default-value lookup table: many
614
// element types share a default (e.g. all block elements → DISPLAY_BLOCK). One
615
// arm per (NT, PT) case is intentional for readability; merging into giant
616
// or-patterns would collapse the UA stylesheet table.
617
#[allow(clippy::match_same_arms)]
618
#[allow(clippy::too_many_lines)] // large but cohesive: single-purpose parser/builder/dispatch (one branch per input variant)
619
#[must_use]
620
148684154
pub fn get_ua_property(
621
148684154
    node_type: &NodeType,
622
148684154
    property_type: CssPropertyType,
623
148684154
) -> Option<&'static CssProperty> {
624
    use CssPropertyType as PT;
625
    use NodeType as NT;
626

            
627
148684154
    match (node_type, property_type) {
628
        // Body Element - CRITICAL for preventing layout collapse
629
59670
        (NT::Body, PT::Display) => Some(&DISPLAY_BLOCK),
630
        // NOTE: Body does NOT have width: 100% in standard UA CSS - it inherits from ICB
631
        // (NT::Body, PT::Height) => Some(&HEIGHT_100_PERCENT),
632
53076
        (NT::Body, PT::MarginTop) => Some(&MARGIN_TOP_8PX),
633
53057
        (NT::Body, PT::MarginBottom) => Some(&MARGIN_BOTTOM_8PX),
634
53057
        (NT::Body, PT::MarginLeft) => Some(&MARGIN_LEFT_8PX),
635
53057
        (NT::Body, PT::MarginRight) => Some(&MARGIN_RIGHT_8PX),
636

            
637
        // Block-level Elements
638
        // NOTE: Do NOT set width: 100% here! Block elements have width: auto by default
639
        // in CSS spec. width: auto for blocks means "fill available width" but it's NOT
640
        // the same as width: 100%. The difference is critical for flexbox: width: auto
641
        // allows flex-grow/flex-shrink to control sizing, while width: 100% prevents it.
642
627097
        (NT::Div, PT::Display) => Some(&DISPLAY_BLOCK),
643
        // <transient-window>: see the statics' comment. `display` is resolved
644
        // per node from `TransientWindowConfig::open` in the layout tree, so
645
        // the UA value here is only the OPEN case's block-ness; a closed one is
646
        // cut out before display is consulted.
647
2908
        (NT::TransientWindow(_), PT::Display) => Some(&DISPLAY_BLOCK),
648
2908
        (NT::TransientWindow(_), PT::Position) => Some(&POSITION_ABSOLUTE),
649
        (NT::TransientWindow(_), PT::Top) => Some(&TOP_100_PERCENT),
650
430785
        (NT::P, PT::Display) => Some(&DISPLAY_BLOCK),
651
        // REMOVED - blocks have width: auto by default
652
        // (NT::Div, PT::Width) => Some(&WIDTH_100_PERCENT),
653
        // REMOVED - blocks have width: auto by default
654
        // (NT::P, PT::Width) => Some(&WIDTH_100_PERCENT),
655
272265
        (NT::P, PT::MarginTop) => Some(&MARGIN_TOP_1EM),
656
237417
        (NT::P, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1EM),
657
5
        (NT::Main, PT::Display) => Some(&DISPLAY_BLOCK),
658
4
        (NT::Header, PT::Display) => Some(&DISPLAY_BLOCK),
659
4
        (NT::Footer, PT::Display) => Some(&DISPLAY_BLOCK),
660
43
        (NT::Section, PT::Display) => Some(&DISPLAY_BLOCK),
661
42
        (NT::Article, PT::Display) => Some(&DISPLAY_BLOCK),
662
4
        (NT::Aside, PT::Display) => Some(&DISPLAY_BLOCK),
663
4
        (NT::Nav, PT::Display) => Some(&DISPLAY_BLOCK),
664

            
665
        // Headings - Chrome UA CSS values
666
        // Per CSS Fragmentation Level 3: headings should avoid page breaks inside
667
        // and after them (to keep heading with following content)
668
2691
        (NT::H1, PT::Display) => Some(&DISPLAY_BLOCK),
669
1514
        (NT::H1, PT::FontSize) => Some(&FONT_SIZE_2EM),
670
2690
        (NT::H1, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
671
2623
        (NT::H1, PT::MarginTop) => Some(&MARGIN_TOP_0_67EM),
672
1471
        (NT::H1, PT::MarginBottom) => Some(&MARGIN_BOTTOM_0_67EM),
673
2690
        (NT::H1, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
674
2690
        (NT::H1, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
675

            
676
485
        (NT::H2, PT::Display) => Some(&DISPLAY_BLOCK),
677
244
        (NT::H2, PT::FontSize) => Some(&FONT_SIZE_1_5EM),
678
484
        (NT::H2, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
679
388
        (NT::H2, PT::MarginTop) => Some(&MARGIN_TOP_0_83EM),
680
244
        (NT::H2, PT::MarginBottom) => Some(&MARGIN_BOTTOM_0_83EM),
681
484
        (NT::H2, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
682
484
        (NT::H2, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
683

            
684
53
        (NT::H3, PT::Display) => Some(&DISPLAY_BLOCK),
685
28
        (NT::H3, PT::FontSize) => Some(&FONT_SIZE_1_17EM),
686
52
        (NT::H3, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
687
28
        (NT::H3, PT::MarginTop) => Some(&MARGIN_TOP_1EM),
688
28
        (NT::H3, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1EM),
689
52
        (NT::H3, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
690
52
        (NT::H3, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
691

            
692
5
        (NT::H4, PT::Display) => Some(&DISPLAY_BLOCK),
693
4
        (NT::H4, PT::FontSize) => Some(&FONT_SIZE_1EM),
694
4
        (NT::H4, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
695
4
        (NT::H4, PT::MarginTop) => Some(&MARGIN_TOP_1_33EM),
696
4
        (NT::H4, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1_33EM),
697
4
        (NT::H4, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
698
4
        (NT::H4, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
699

            
700
5
        (NT::H5, PT::Display) => Some(&DISPLAY_BLOCK),
701
4
        (NT::H5, PT::FontSize) => Some(&FONT_SIZE_0_83EM),
702
4
        (NT::H5, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
703
4
        (NT::H5, PT::MarginTop) => Some(&MARGIN_TOP_1_67EM),
704
4
        (NT::H5, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1_67EM),
705
4
        (NT::H5, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
706
4
        (NT::H5, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
707

            
708
5
        (NT::H6, PT::Display) => Some(&DISPLAY_BLOCK),
709
4
        (NT::H6, PT::FontSize) => Some(&FONT_SIZE_0_67EM),
710
4
        (NT::H6, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
711
4
        (NT::H6, PT::MarginTop) => Some(&MARGIN_TOP_2_33EM),
712
4
        (NT::H6, PT::MarginBottom) => Some(&MARGIN_BOTTOM_2_33EM),
713
4
        (NT::H6, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
714
4
        (NT::H6, PT::BreakAfter) => Some(&BREAK_AFTER_AVOID),
715

            
716
        // Lists - padding on container creates gutter for markers
717
2645
        (NT::Ul, PT::Display) => Some(&DISPLAY_BLOCK),
718
2644
        (NT::Ul, PT::ListStyleType) => Some(&LIST_STYLE_TYPE_DISC),
719
2644
        (NT::Ul, PT::CounterReset) => Some(&COUNTER_RESET_LIST_ITEM),
720
2644
        (NT::Ul, PT::PaddingLeft) => Some(&PADDING_INLINE_START_40PX),
721
2643
        (NT::Ul, PT::MarginTop) => Some(&MARGIN_TOP_1EM),
722
1467
        (NT::Ul, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1EM),
723
5
        (NT::Ol, PT::Display) => Some(&DISPLAY_BLOCK),
724
4
        (NT::Ol, PT::ListStyleType) => Some(&LIST_STYLE_TYPE_DECIMAL),
725
4
        (NT::Ol, PT::CounterReset) => Some(&COUNTER_RESET_LIST_ITEM),
726
4
        (NT::Ol, PT::PaddingLeft) => Some(&PADDING_INLINE_START_40PX),
727
3
        (NT::Ol, PT::MarginTop) => Some(&MARGIN_TOP_1EM),
728
3
        (NT::Ol, PT::MarginBottom) => Some(&MARGIN_BOTTOM_1EM),
729
7829
        (NT::Li, PT::Display) => Some(&DISPLAY_LIST_ITEM),
730
4
        (NT::Dl, PT::Display) => Some(&DISPLAY_BLOCK),
731
4
        (NT::Dt, PT::Display) => Some(&DISPLAY_BLOCK),
732
4
        (NT::Dd, PT::Display) => Some(&DISPLAY_BLOCK),
733

            
734
        // Inline Elements
735
5360
        (NT::Span, PT::Display) => Some(&DISPLAY_INLINE),
736
3004
        (NT::A, PT::Display) => Some(&DISPLAY_INLINE),
737
3004
        (NT::A, PT::TextDecoration) => Some(&TEXT_DECORATION_UNDERLINE),
738
52
        (NT::Strong, PT::Display) => Some(&DISPLAY_INLINE),
739
28
        (NT::Strong, PT::FontWeight) => Some(&FONT_WEIGHT_BOLDER),
740
76
        (NT::Em, PT::Display) => Some(&DISPLAY_INLINE),
741
4
        (NT::B, PT::Display) => Some(&DISPLAY_INLINE),
742
4
        (NT::B, PT::FontWeight) => Some(&FONT_WEIGHT_BOLDER),
743
4
        (NT::I, PT::Display) => Some(&DISPLAY_INLINE),
744
4
        (NT::U, PT::Display) => Some(&DISPLAY_INLINE),
745
4
        (NT::U, PT::TextDecoration) => Some(&TEXT_DECORATION_UNDERLINE),
746
4
        (NT::Small, PT::Display) => Some(&DISPLAY_INLINE),
747
52
        (NT::Code, PT::Display) => Some(&DISPLAY_INLINE),
748
4
        (NT::Kbd, PT::Display) => Some(&DISPLAY_INLINE),
749
4
        (NT::Samp, PT::Display) => Some(&DISPLAY_INLINE),
750
4
        (NT::Sub, PT::Display) => Some(&DISPLAY_INLINE),
751
4
        (NT::Sup, PT::Display) => Some(&DISPLAY_INLINE),
752

            
753
        // Text Content
754
100
        (NT::Pre, PT::Display) => Some(&DISPLAY_BLOCK),
755
52
        (NT::Pre, PT::WhiteSpace) => Some(&WHITE_SPACE_PRE),
756
52
        (NT::BlockQuote, PT::Display) => Some(&DISPLAY_BLOCK),
757
4
        (NT::Hr, PT::Display) => Some(&DISPLAY_BLOCK),
758
4
        (NT::Hr, PT::Width) => Some(&WIDTH_100_PERCENT),
759
4
        (NT::Hr, PT::Height) => Some(&HEIGHT_ZERO),
760
3
        (NT::Hr, PT::MarginTop) => Some(&MARGIN_TOP_0_5EM),
761
3
        (NT::Hr, PT::MarginBottom) => Some(&MARGIN_BOTTOM_0_5EM),
762
4
        (NT::Hr, PT::BorderTopStyle) => Some(&BORDER_TOP_STYLE_INSET),
763
4
        (NT::Hr, PT::BorderTopWidth) => Some(&BORDER_TOP_WIDTH_1PX),
764
5
        (NT::Hr, PT::BorderTopColor) => Some(&BORDER_TOP_COLOR_GRAY),
765

            
766
        // Table Elements
767
        // Per CSS Fragmentation Level 3: table ROWS should avoid breaks inside
768
        // Tables themselves should NOT have break-inside: avoid (they can span pages)
769
1685
        (NT::Table, PT::Display) => Some(&DISPLAY_TABLE),
770
        // NOTE: Removed break-inside: avoid from Table - tables CAN break across pages
771
120
        (NT::PageBreak, PT::Display) => Some(&DISPLAY_BLOCK),
772
120
        (NT::PageBreak, PT::BreakBefore) => Some(&BREAK_BEFORE_PAGE),
773
149
        (NT::THead, PT::Display) => Some(&DISPLAY_TABLE_HEADER_GROUP),
774
147
        (NT::THead, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
775
148
        (NT::THead, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
776
101
        (NT::TBody, PT::Display) => Some(&DISPLAY_TABLE_ROW_GROUP),
777
99
        (NT::TBody, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
778
        // NOTE: Removed break-inside: avoid from TBody - tbody CAN break across pages
779
5
        (NT::TFoot, PT::Display) => Some(&DISPLAY_TABLE_FOOTER_GROUP),
780
3
        (NT::TFoot, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
781
4
        (NT::TFoot, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
782
2237
        (NT::Tr, PT::Display) => Some(&DISPLAY_TABLE_ROW),
783
2235
        (NT::Tr, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
784
2236
        (NT::Tr, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
785
101
        (NT::Th, PT::Display) => Some(&DISPLAY_TABLE_CELL),
786
52
        (NT::Th, PT::TextAlign) => Some(&TEXT_ALIGN_CENTER),
787
100
        (NT::Th, PT::FontWeight) => Some(&FONT_WEIGHT_BOLD),
788
100
        (NT::Th, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
789
52
        (NT::Th, PT::PaddingTop) => Some(&PADDING_TOP_1PX),
790
52
        (NT::Th, PT::PaddingBottom) => Some(&PADDING_BOTTOM_1PX),
791
52
        (NT::Th, PT::PaddingLeft) => Some(&PADDING_LEFT_1PX),
792
52
        (NT::Th, PT::PaddingRight) => Some(&PADDING_RIGHT_1PX),
793
3989
        (NT::Td, PT::Display) => Some(&DISPLAY_TABLE_CELL),
794
3988
        (NT::Td, PT::VerticalAlign) => Some(&VERTICAL_ALIGN_MIDDLE),
795
3820
        (NT::Td, PT::PaddingTop) => Some(&PADDING_TOP_1PX),
796
3820
        (NT::Td, PT::PaddingBottom) => Some(&PADDING_BOTTOM_1PX),
797
3820
        (NT::Td, PT::PaddingLeft) => Some(&PADDING_LEFT_1PX),
798
3820
        (NT::Td, PT::PaddingRight) => Some(&PADDING_RIGHT_1PX),
799

            
800
        // Form Elements
801
916
        (NT::Form, PT::Display) => Some(&DISPLAY_BLOCK),
802
1468
        (NT::Input, PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
803
41677
        (NT::Button, PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
804
41677
        (NT::Button, PT::Cursor) => Some(&CURSOR_POINTER),
805
80639
        (NT::Button, PT::FontSize) => Some(&FONT_SIZE_13PX),
806
41867
        (NT::Button, PT::PaddingTop) => Some(&PADDING_TOP_5PX),
807
41867
        (NT::Button, PT::PaddingBottom) => Some(&PADDING_BOTTOM_5PX),
808
41867
        (NT::Button, PT::PaddingLeft) => Some(&PADDING_LEFT_10PX),
809
41867
        (NT::Button, PT::PaddingRight) => Some(&PADDING_RIGHT_10PX),
810
41676
        (NT::Button, PT::BorderTopWidth) => Some(&BUTTON_BORDER_TOP_WIDTH),
811
41676
        (NT::Button, PT::BorderBottomWidth) => Some(&BUTTON_BORDER_BOTTOM_WIDTH),
812
41676
        (NT::Button, PT::BorderLeftWidth) => Some(&BUTTON_BORDER_LEFT_WIDTH),
813
41676
        (NT::Button, PT::BorderRightWidth) => Some(&BUTTON_BORDER_RIGHT_WIDTH),
814
51144
        (NT::Button, PT::BorderTopStyle) => Some(&BUTTON_BORDER_TOP_STYLE),
815
51144
        (NT::Button, PT::BorderBottomStyle) => Some(&BUTTON_BORDER_BOTTOM_STYLE),
816
51144
        (NT::Button, PT::BorderLeftStyle) => Some(&BUTTON_BORDER_LEFT_STYLE),
817
51144
        (NT::Button, PT::BorderRightStyle) => Some(&BUTTON_BORDER_RIGHT_STYLE),
818
51109
        (NT::Button, PT::BorderTopColor) => Some(&BUTTON_BORDER_TOP_COLOR),
819
51101
        (NT::Button, PT::BorderBottomColor) => Some(&BUTTON_BORDER_BOTTOM_COLOR),
820
51101
        (NT::Button, PT::BorderLeftColor) => Some(&BUTTON_BORDER_LEFT_COLOR),
821
51101
        (NT::Button, PT::BorderRightColor) => Some(&BUTTON_BORDER_RIGHT_COLOR),
822
        // Text nodes get I-beam cursor for text selection
823
        // The cursor resolution algorithm ensures that explicit cursor properties
824
        // on parent elements (e.g., cursor:pointer on button) take precedence
825
608592
        (NT::Text(_), PT::Cursor) => Some(&CURSOR_TEXT),
826
652
        (NT::Select, PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
827
1972
        (NT::TextArea, PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
828
1972
        (NT::TextArea, PT::WhiteSpace) => Some(&WHITE_SPACE_PRE_WRAP),
829
1971
        (NT::TextArea, PT::OverflowWrap) => Some(&OVERFLOW_WRAP_BREAK_WORD),
830
        // TextArea gets I-beam cursor since it's an editable text field
831
1972
        (NT::TextArea, PT::Cursor) => Some(&CURSOR_TEXT),
832
4
        (NT::Label, PT::Display) => Some(&DISPLAY_INLINE),
833
        // Hidden Elements
834
29
        (NT::Head, PT::Display) => Some(&DISPLAY_NONE),
835
5
        (NT::Title, PT::Display) => Some(&DISPLAY_NONE),
836
5
        (NT::Script, PT::Display) => Some(&DISPLAY_NONE),
837
5
        (NT::Style, PT::Display) => Some(&DISPLAY_NONE),
838
5
        (NT::Link, PT::Display) => Some(&DISPLAY_NONE),
839

            
840
        // Special Elements
841
        // <br> is an inline-level element that forces a line break WITHIN the
842
        // inline formatting context (HTML §4.5.28). Giving it `display: block`
843
        // made `<p>text<br>more</p>` split into three stacked block boxes (an
844
        // extra empty <br> box between two anonymous paragraphs), over-advancing
845
        // vertically and, inside a table cell, dropping the line after the break.
846
        // As inline it is turned into a hard `LineBreak` by the IFC collectors.
847
90
        (NT::Br, PT::Display) => Some(&DISPLAY_INLINE),
848
        // Images are replaced elements - inline-block so they respect width/height
849
732
        (NT::Image(_), PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
850

            
851
        // Media Elements
852
4
        (NT::Video, PT::Display) => Some(&DISPLAY_INLINE),
853
4
        (NT::Audio, PT::Display) => Some(&DISPLAY_INLINE),
854
4
        (NT::Canvas, PT::Display) => Some(&DISPLAY_INLINE),
855
        // An SVG SHAPE is a painted box, not inline content. The default
856
        // display is `inline`, and `paint_node_background_and_border` skips
857
        // inline boxes on purpose - their backgrounds belong to text layout,
858
        // which knows nothing about these - so a shape's fill was dropped and
859
        // an SVG in a DOM painted nothing at all. Block is what an absolutely
860
        // positioned box is anyway (CSS blockifies `position: absolute`).
861
        (
862
            NT::SvgPath
863
            | NT::SvgCircle
864
            | NT::SvgRect
865
            | NT::SvgEllipse
866
            | NT::SvgLine
867
            | NT::SvgPolygon
868
            | NT::SvgPolyline
869
            | NT::SvgG
870
            | NT::SvgUse,
871
            PT::Display,
872
981
        ) => Some(&DISPLAY_BLOCK),
873
        // `<defs>` and friends define, they do not draw.
874
51
        (NT::SvgDefs | NT::SvgSymbol | NT::SvgClipPathElement, PT::Display) => Some(&DISPLAY_NONE),
875
        // An `<svg>` is a REPLACED element, like `<img>` above - inline-level,
876
        // but with a box of its own. `inline` is what it used to be, and an
877
        // inline box has no width or height, so the intrinsic size the parser
878
        // now takes off `viewBox`/`width`/`height` was inert and the element
879
        // took no space at all: an SVG in a DOM laid out as nothing and
880
        // painted nothing.
881
1061
        (NT::Svg, PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
882
        // VirtualView is a block-level replaced element (like div) — must be block
883
        // so it participates in flex layout (flex-grow, etc.)
884
2537
        (NT::VirtualView, PT::Display) => Some(&DISPLAY_BLOCK),
885
        // A VirtualView exists to virtualize scrollable content, so scrolling
886
        // is its DEFAULT: `auto` gets it a scroll id (wheel target) and — via
887
        // the virtual-size-aware necessity rule — a scrollbar exactly when
888
        // the published `virtual_scroll_size` overflows the viewport. A VV
889
        // that must NOT wheel-scroll (the map pans+zooms, the video widget)
890
        // opts out explicitly with `overflow: hidden`, which both already do.
891
2057
        (NT::VirtualView, PT::OverflowX) => Some(&OVERFLOW_X_AUTO),
892
2045
        (NT::VirtualView, PT::OverflowY) => Some(&OVERFLOW_Y_AUTO),
893

            
894
        // Icon Elements - inline-block so they have width/height but flow inline
895
81320
        (NT::Icon(_), PT::Display) => Some(&DISPLAY_INLINE_BLOCK),
896

            
897
4
        (NT::SelectOption, PT::Display) => Some(&DISPLAY_NONE),
898
4
        (NT::OptGroup, PT::Display) => Some(&DISPLAY_NONE),
899

            
900
        // Other Inline Elements
901
4
        (NT::Abbr, PT::Display) => Some(&DISPLAY_INLINE),
902
4
        (NT::Cite, PT::Display) => Some(&DISPLAY_INLINE),
903
4
        (NT::Del, PT::Display) => Some(&DISPLAY_INLINE),
904
4
        (NT::Ins, PT::Display) => Some(&DISPLAY_INLINE),
905
4
        (NT::Mark, PT::Display) => Some(&DISPLAY_INLINE),
906
4
        (NT::Q, PT::Display) => Some(&DISPLAY_INLINE),
907
4
        (NT::Dfn, PT::Display) => Some(&DISPLAY_INLINE),
908
4
        (NT::Var, PT::Display) => Some(&DISPLAY_INLINE),
909
4
        (NT::Time, PT::Display) => Some(&DISPLAY_INLINE),
910
4
        (NT::Data, PT::Display) => Some(&DISPLAY_INLINE),
911
4
        (NT::Wbr, PT::Display) => Some(&DISPLAY_INLINE),
912
4
        (NT::Bdi, PT::Display) => Some(&DISPLAY_INLINE),
913
4
        (NT::Bdo, PT::Display) => Some(&DISPLAY_INLINE),
914
4
        (NT::Rp, PT::Display) => Some(&DISPLAY_INLINE),
915
4
        (NT::Rt, PT::Display) => Some(&DISPLAY_INLINE),
916
4
        (NT::Rtc, PT::Display) => Some(&DISPLAY_INLINE),
917
4
        (NT::Ruby, PT::Display) => Some(&DISPLAY_INLINE),
918

            
919
        // Block Container Elements
920
        // Per CSS Fragmentation Level 3: figures should avoid page breaks inside
921
4
        (NT::FieldSet, PT::Display) => Some(&DISPLAY_BLOCK),
922
4
        (NT::Figure, PT::Display) => Some(&DISPLAY_BLOCK),
923
3
        (NT::Figure, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
924
4
        (NT::FigCaption, PT::Display) => Some(&DISPLAY_BLOCK),
925
3
        (NT::FigCaption, PT::BreakInside) => Some(&BREAK_INSIDE_AVOID),
926
4
        (NT::Details, PT::Display) => Some(&DISPLAY_BLOCK),
927
4
        (NT::Summary, PT::Display) => Some(&DISPLAY_BLOCK),
928
4
        (NT::Dialog, PT::Display) => Some(&DISPLAY_BLOCK),
929

            
930
        // Table Caption
931
5
        (NT::Caption, PT::Display) => Some(&DISPLAY_TABLE_CAPTION),
932
5
        (NT::ColGroup, PT::Display) => Some(&DISPLAY_TABLE_COLUMN_GROUP),
933
5
        (NT::Col, PT::Display) => Some(&DISPLAY_TABLE_COLUMN),
934

            
935
        // Legacy/Deprecated Elements
936
4
        (NT::Menu, PT::Display) => Some(&DISPLAY_BLOCK),
937
4
        (NT::Dir, PT::Display) => Some(&DISPLAY_BLOCK),
938

            
939
        // Html (root) Element
940
        //
941
        // In browsers, the viewport itself provides scrolling when <html> overflows.
942
        // Since Azul has no separate viewport scroll mechanism, we set `height: 100%`
943
        // on the <html> element so it fills the Initial Containing Block (the viewport).
944
        // This constrains child elements like <body> to the viewport height, enabling
945
        // overflow:scroll on <body> to create scrollable content areas.
946
        //
947
        // Without this, <html> has height:auto and grows to fit all content,
948
        // making container_size == content_size, which results in a useless 100% scrollbar.
949
10626
        (NT::Html, PT::Display) => Some(&DISPLAY_BLOCK),
950
        // ⚠ DIAG (2026-06-02, REVERT): the lifted get_ua_property jump table mis-dispatches
951
        // (Text/Button, Height) → THIS (Html, Height) arm → children wrongly get height:100%
952
        // → fill parent (600) instead of content. Commenting it out tests whether removing the
953
        // ONLY HEIGHT_100_PERCENT producer makes the children auto-height (confirms the chain).
954
        // REAL fix = the node_type jump-table dispatch/table-mirror in the lift, not this.
955
        // (NT::Html, PT::Height) => Some(&HEIGHT_100_PERCENT),
956

            
957
        // Universal fallback for display property
958
        // Per CSS spec, unknown/custom elements should default to inline
959
        // Text nodes will be filtered out before this function is called
960
846366
        (_, PT::Display) => Some(&DISPLAY_INLINE),
961

            
962
        // No default defined for other combinations
963
144276952
        _ => None,
964
    }
965
148684154
}
966

            
967
/// Every property type the UA sheet can answer.
968
///
969
/// For the cascade passes that walk the table per node:
970
/// `CssPropertyCache::apply_ua_css` (the `cascaded_props` / `computed_values`
971
/// reader) and the compact-cache builder (`apply_ua_css_to_compact`, the
972
/// layout fast path).
973
///
974
/// ONE list for both, on purpose. Each pass used to carry its own copy with
975
/// the instruction to keep them in sync, and they were not: the compact list
976
/// had the three non-top button border edges and `TextColor`, the cascaded
977
/// list had `FontFamily` and the heading `break-*` defaults, and neither had
978
/// everything — so the two readers disagreed about a node's computed value
979
/// depending on which one a getter happened to ask (the `VirtualView` overflow
980
/// default was the first instance found). A type only one pass can store is
981
/// harmless in the other: `apply_css_property_to_compact` ignores what has no
982
/// compact slot, and a cascaded entry nothing reads costs one push.
983
pub const UA_PROPERTY_TYPES: &[CssPropertyType] = &[
984
    // Tier1 enum properties
985
    CssPropertyType::Display,
986
    CssPropertyType::Position,
987
    CssPropertyType::Float,
988
    CssPropertyType::Clear,
989
    CssPropertyType::OverflowX,
990
    CssPropertyType::OverflowY,
991
    CssPropertyType::BoxSizing,
992
    CssPropertyType::FlexDirection,
993
    CssPropertyType::FlexWrap,
994
    CssPropertyType::JustifyContent,
995
    CssPropertyType::AlignItems,
996
    CssPropertyType::AlignContent,
997
    CssPropertyType::WritingMode,
998
    CssPropertyType::FontWeight,
999
    CssPropertyType::FontStyle,
    CssPropertyType::TextAlign,
    CssPropertyType::Visibility,
    CssPropertyType::WhiteSpace,
    // Only the editing-host / textarea defaults set it; the compact tier has
    // no slot for it, which the doc above covers (the slow path stores it).
    CssPropertyType::OverflowWrap,
    CssPropertyType::Direction,
    CssPropertyType::VerticalAlign,
    CssPropertyType::BorderCollapse,
    // Tier2 dimension properties
    CssPropertyType::Width,
    CssPropertyType::Height,
    CssPropertyType::FontSize,
    CssPropertyType::FontFamily,
    CssPropertyType::MarginTop,
    CssPropertyType::MarginBottom,
    CssPropertyType::MarginLeft,
    CssPropertyType::MarginRight,
    CssPropertyType::PaddingTop,
    CssPropertyType::PaddingBottom,
    CssPropertyType::PaddingLeft,
    CssPropertyType::PaddingRight,
    CssPropertyType::BorderTopWidth,
    CssPropertyType::BorderTopStyle,
    CssPropertyType::BorderTopColor,
    CssPropertyType::BorderRightWidth,
    CssPropertyType::BorderRightStyle,
    CssPropertyType::BorderRightColor,
    CssPropertyType::BorderBottomWidth,
    CssPropertyType::BorderBottomStyle,
    CssPropertyType::BorderBottomColor,
    CssPropertyType::BorderLeftWidth,
    CssPropertyType::BorderLeftStyle,
    CssPropertyType::BorderLeftColor,
    // Fragmentation (headings avoid breaks)
    CssPropertyType::BreakInside,
    CssPropertyType::BreakAfter,
    CssPropertyType::BreakBefore,
    // Text properties
    CssPropertyType::TextColor,
    CssPropertyType::LineHeight,
    CssPropertyType::LetterSpacing,
    CssPropertyType::WordSpacing,
    CssPropertyType::TextDecoration,
    CssPropertyType::Cursor,
    CssPropertyType::ListStyleType,
    // Counters: the UA sheet resets `list-item` on <ol>/<ul> so each list
    // restarts numbering. Without these here the has_counter fast-path bit
    // stays unset for list containers, compute_counters skips the reset, and
    // the list-item counter runs globally (a <ul> then <ol> numbered 1,2 then
    // 3,4 instead of restarting at 1).
    CssPropertyType::CounterReset,
    CssPropertyType::CounterIncrement,
];
/// The UA defaults of the DOCUMENT ROOT (the node at index 0), themed.
///
/// These are the defaults that hold for the whole document and reach every
/// node by inheritance rather than by node type — today that is the inherited
/// text colour, `color`, from [`UA_ROOT_TEXT_COLOR_CSS`]: black on a light
/// window, near-white on a dark one. Keyed on the root's POSITION, not on
/// `<body>`/`<html>`: a body-rooted subtree appended under another document
/// must keep inheriting its new parent's colour, and a document rooted in a
/// `<div>` (tests, popups) needs the default as much as one rooted in
/// `<body>`.
///
/// Consumed by the same three readers as [`get_ua_property_themed`], so the
/// default is IN the resolved style (`cascaded_props` on the root,
/// `computed_values` below it, the compact text tier everywhere) and no
/// paint-time reader has to invent it. `None` for the context answers the
/// light table, like the per-type resolver.
#[must_use]
12443013
pub fn get_ua_root_property_themed(
12443013
    property_type: CssPropertyType,
12443013
    ctx: Option<&DynamicSelectorContext>,
12443013
) -> Option<&'static CssProperty> {
12443013
    if property_type != CssPropertyType::TextColor {
12343603
        return None;
99410
    }
99410
    UA_ROOT_TEXT_COLOR_CSS
99410
        .iter()
        // No window yet: only the unconditional entry applies.
198510
        .find(|prop| ctx.map_or_else(|| !prop.is_conditional(), |c| prop.matches(c)))
99410
        .map(|prop| &prop.property)
12443013
}
/// THE UA default for one node and one property: the per-type table
/// ([`get_ua_property_themed`]) or, on the document root, the document-wide
/// table ([`get_ua_root_property_themed`]).
///
/// The one lookup all three readers share — `CssPropertyCache::apply_ua_css`,
/// the compact-cache builder and `get_property_slow`'s last-resort fallback —
/// so they cannot disagree about a default. `is_root` is "node index 0".
///
/// Order: the element's own row first (`<pre contenteditable>` keeps `pre`),
/// then the editing-host defaults, then the document root's.
#[must_use]
147313245
pub fn get_ua_default(
147313245
    node: &NodeData,
147313245
    is_root: bool,
147313245
    property_type: CssPropertyType,
147313245
    ctx: Option<&DynamicSelectorContext>,
147313245
) -> Option<&'static CssProperty> {
147313245
    get_ua_property_themed(&node.node_type, property_type, ctx)
147313245
        .or_else(|| {
142906865
            if node.is_contenteditable() {
1130920
                get_ua_editing_host_property(property_type)
            } else {
141775945
                None
            }
142906865
        })
147313245
        .or_else(|| {
142866643
            if is_root {
12443006
                get_ua_root_property_themed(property_type, ctx)
            } else {
130423637
                None
            }
142866643
        })
147313245
}
/// UA defaults of an EDITING HOST (a `contenteditable` node), inherited by
/// everything inside it.
///
/// `white-space: pre-wrap`, because an editor must show exactly what the user
/// typed. Under the initial `normal`, CSS Text 3 removes a space at the end of
/// a line and collapses a run of spaces to one. The typed space then had no
/// position, so the caret did not move and nothing repainted until the next
/// letter. `pre-wrap` preserves every space and HANGS the trailing ones: they
/// keep their advance for the caret but do not count toward fitting the line
/// (CSS Text 3 §4.1.2). Browsers get there by rewriting typed spaces to NBSP
/// under `normal` (Gecko, `WebKit`) or by forcing `pre-wrap` on
/// `contenteditable=plaintext-only` (Chromium); whatwg/html#11350 proposes
/// exactly this UA rule, `<textarea>` has always had it, and the editor
/// frameworks (`ProseMirror`, Lexical) require it on their root. azul stores
/// plain spaces, so it takes the UA rule. Author CSS overrides it.
///
/// `overflow-wrap: break-word`: an overlong word in an editor wraps instead of
/// overflowing the box (Chromium's contenteditable default).
#[must_use]
1130920
pub fn get_ua_editing_host_property(
1130920
    property_type: CssPropertyType,
1130920
) -> Option<&'static CssProperty> {
1130920
    match property_type {
19361
        CssPropertyType::WhiteSpace => Some(&WHITE_SPACE_PRE_WRAP),
20861
        CssPropertyType::OverflowWrap => Some(&OVERFLOW_WRAP_BREAK_WORD),
1090698
        _ => None,
    }
1130920
}
/// [`get_ua_property`], with the theme taken into account.
///
/// The UA sheet is a static table, which is what keeps the property cache a
/// pure function of node type — but a handful of its defaults are COLOURS, and
/// a colour default cannot be one constant: a button border or an `<hr>` rule
/// chosen for a white window is wrong on a dark one. Those few resolve through
/// here: with a dark context they answer their dark twin, otherwise the plain
/// table. The inherited text colour has the same shape in
/// [`UA_ROOT_TEXT_COLOR_CSS`], answered by [`get_ua_root_property_themed`].
///
/// This pair is THE themed UA table. All three readers go through it —
/// `apply_ua_css` (cascaded/computed values), the compact-cache builder (the
/// layout fast path) and `get_property_slow`'s last-resort fallback — so a
/// theme flip changes the same answer everywhere, and a getter that asks the
/// compact tier gets what the slow path would have said.
///
/// `None` for the context means "no window yet" and falls back to the light
/// table, which is what every caller did before this existed.
#[must_use]
147313269
pub fn get_ua_property_themed(
147313269
    node_type: &NodeType,
147313269
    property_type: CssPropertyType,
147313269
    ctx: Option<&DynamicSelectorContext>,
147313269
) -> Option<&'static CssProperty> {
    use CssPropertyType as PT;
    use crate::dom::NodeType as NT;
147313269
    let dark = ctx.is_some_and(|c| c.theme == ThemeCondition::Dark);
147313269
    if dark {
100264
        let twin = match (node_type, property_type) {
1
            (NT::Hr, PT::BorderTopColor) => Some(&BORDER_TOP_COLOR_GRAY_DARK),
54
            (NT::Button, PT::BorderTopColor) => Some(&BUTTON_BORDER_TOP_COLOR_DARK),
45
            (NT::Button, PT::BorderBottomColor) => Some(&BUTTON_BORDER_BOTTOM_COLOR_DARK),
45
            (NT::Button, PT::BorderLeftColor) => Some(&BUTTON_BORDER_LEFT_COLOR_DARK),
45
            (NT::Button, PT::BorderRightColor) => Some(&BUTTON_BORDER_RIGHT_COLOR_DARK),
100074
            _ => None,
        };
100264
        if twin.is_some() {
190
            return twin;
100074
        }
147213005
    }
147313079
    get_ua_property(node_type, property_type)
147313269
}
// ============================================================================
// UA Scrollbar Defaults — individual CssPropertyWithConditions
// ============================================================================
//
// These rules define the default scrollbar appearance per OS and theme,
// using the same `@os` / `@theme` condition system as author CSS.
// Each entry is a single CSS property (scrollbar-color or scrollbar-width)
// with its conditions.  Rules are evaluated first-match-wins per property type.
//
// Conceptually equivalent to:
//
//   @os macos                { scrollbar-width: thin; }
//   @os ios                  { scrollbar-width: thin; }
//   @os android              { scrollbar-width: thin; }
//   /* default */            { scrollbar-width: auto; }
//
//   @os macos                { -azul-scrollbar-visibility: when-scrolling; }
//   @os ios                  { -azul-scrollbar-visibility: when-scrolling; }
//   @os android              { -azul-scrollbar-visibility: when-scrolling; }
//   /* default */            { -azul-scrollbar-visibility: always; }
//
//   @os macos                { -azul-scrollbar-fade-delay: 500ms; }
//   @os ios                  { -azul-scrollbar-fade-delay: 500ms; }
//   @os android              { -azul-scrollbar-fade-delay: 300ms; }
//   /* default */            { -azul-scrollbar-fade-delay: 0; }
//
//   @os macos                { -azul-scrollbar-fade-duration: 200ms; }
//   @os ios                  { -azul-scrollbar-fade-duration: 200ms; }
//   @os android              { -azul-scrollbar-fade-duration: 150ms; }
//   /* default */            { -azul-scrollbar-fade-duration: 0; }
//
//   @os macos @theme dark    { scrollbar-color: rgba(180,180,180,0.78) rgba(40,40,40,0.31); }
//   @os macos @theme light   { scrollbar-color: rgba(80,80,80,0.78) rgba(200,200,200,0.31); }
//   @os windows @theme dark  { scrollbar-color: #6e6e6e #202020; }
//   @os windows @theme light { scrollbar-color: #828282 #f1f1f1; }
//   @os ios @theme dark      { scrollbar-color: rgba(255,255,255,0.4) transparent; }
//   @os ios @theme light     { scrollbar-color: rgba(0,0,0,0.4) transparent; }
//   @os android @theme dark  { scrollbar-color: rgba(255,255,255,0.3) transparent; }
//   @os android @theme light { scrollbar-color: rgba(0,0,0,0.3) transparent; }
//   @theme dark              { scrollbar-color: #646464 #2d2d2d; }
//   /* default */            { scrollbar-color: #c1c1c1 #f1f1f1; }
/// Helper to create a const `scrollbar-color` `CssProperty`.
4
const fn scrollbar_color(thumb: ColorU, track: ColorU) -> CssProperty {
4
    CssProperty::ScrollbarColor(CssPropertyValue::Exact(StyleScrollbarColor::Custom(
4
        ScrollbarColorCustom { thumb, track },
4
    )))
4
}
/// Helper to create a const `scrollbar-width` `CssProperty`.
3
const fn scrollbar_width(w: LayoutScrollbarWidth) -> CssProperty {
3
    CssProperty::ScrollbarWidth(CssPropertyValue::Exact(w))
3
}
/// Helper to create a const `-azul-scrollbar-visibility` `CssProperty`.
3
const fn scrollbar_visibility(v: ScrollbarVisibilityMode) -> CssProperty {
3
    CssProperty::ScrollbarVisibility(CssPropertyValue::Exact(v))
3
}
/// Helper to create a const `-azul-scrollbar-fade-delay` `CssProperty`.
15
const fn scrollbar_fade_delay(ms: u32) -> CssProperty {
15
    CssProperty::ScrollbarFadeDelay(CssPropertyValue::Exact(ScrollbarFadeDelay::new(ms)))
15
}
/// Helper to create a const `-azul-scrollbar-fade-duration` `CssProperty`.
12
const fn scrollbar_fade_duration(ms: u32) -> CssProperty {
12
    CssProperty::ScrollbarFadeDuration(CssPropertyValue::Exact(ScrollbarFadeDuration::new(ms)))
12
}
/// UA scrollbar CSS properties with `@os` / `@theme` conditions.
///
/// Ordered most-specific first.  The evaluation function picks the
/// first matching entry for each property type (`scrollbar-color`,
/// `scrollbar-width`, `-azul-scrollbar-visibility`,
/// `-azul-scrollbar-fade-delay`, `-azul-scrollbar-fade-duration`).
pub(crate) static UA_SCROLLBAR_CSS: &[CssPropertyWithConditions] = &[
    // ── scrollbar-width per OS ──────────────────────────────────────────
    // macOS → thin (overlay)
    CssPropertyWithConditions::with_single_condition(
        scrollbar_width(LayoutScrollbarWidth::Thin),
        &[DynamicSelector::Os(OsCondition::MacOS)],
    ),
    // iOS → thin
    CssPropertyWithConditions::with_single_condition(
        scrollbar_width(LayoutScrollbarWidth::Thin),
        &[DynamicSelector::Os(OsCondition::IOS)],
    ),
    // Android → thin
    CssPropertyWithConditions::with_single_condition(
        scrollbar_width(LayoutScrollbarWidth::Thin),
        &[DynamicSelector::Os(OsCondition::Android)],
    ),
    // default → auto (classic)
    CssPropertyWithConditions::simple(scrollbar_width(LayoutScrollbarWidth::Auto)),
    // ── scrollbar-visibility per OS ─────────────────────────────────────
    // macOS → overlay (show only when scrolling)
    CssPropertyWithConditions::with_single_condition(
        scrollbar_visibility(ScrollbarVisibilityMode::WhenScrolling),
        &[DynamicSelector::Os(OsCondition::MacOS)],
    ),
    // iOS → overlay
    CssPropertyWithConditions::with_single_condition(
        scrollbar_visibility(ScrollbarVisibilityMode::WhenScrolling),
        &[DynamicSelector::Os(OsCondition::IOS)],
    ),
    // Android → overlay
    CssPropertyWithConditions::with_single_condition(
        scrollbar_visibility(ScrollbarVisibilityMode::WhenScrolling),
        &[DynamicSelector::Os(OsCondition::Android)],
    ),
    // default → always visible (classic)
    CssPropertyWithConditions::simple(scrollbar_visibility(ScrollbarVisibilityMode::Always)),
    // ── scrollbar-fade-delay per OS ─────────────────────────────────────
    CssPropertyWithConditions::with_single_condition(
        scrollbar_fade_delay(500),
        &[DynamicSelector::Os(OsCondition::MacOS)],
    ),
    CssPropertyWithConditions::with_single_condition(
        scrollbar_fade_delay(500),
        &[DynamicSelector::Os(OsCondition::IOS)],
    ),
    CssPropertyWithConditions::with_single_condition(
        scrollbar_fade_delay(300),
        &[DynamicSelector::Os(OsCondition::Android)],
    ),
    // default → 0 (no fade)
    CssPropertyWithConditions::simple(scrollbar_fade_delay(0)),
    // ── scrollbar-fade-duration per OS ──────────────────────────────────
    CssPropertyWithConditions::with_single_condition(
        scrollbar_fade_duration(200),
        &[DynamicSelector::Os(OsCondition::MacOS)],
    ),
    CssPropertyWithConditions::with_single_condition(
        scrollbar_fade_duration(200),
        &[DynamicSelector::Os(OsCondition::IOS)],
    ),
    CssPropertyWithConditions::with_single_condition(
        scrollbar_fade_duration(150),
        &[DynamicSelector::Os(OsCondition::Android)],
    ),
    // default → 0 (instant)
    CssPropertyWithConditions::simple(scrollbar_fade_duration(0)),
    // ── scrollbar-color per OS + theme ──────────────────────────────────
    // macOS dark: light grey thumb on dark semi-transparent track
    CssPropertyWithConditions::with_single_condition(
        scrollbar_color(
            ColorU {
                r: 180,
                g: 180,
                b: 180,
                a: 200,
            },
            ColorU {
                r: 40,
                g: 40,
                b: 40,
                a: 80,
            },
        ),
        &[
            DynamicSelector::Os(OsCondition::MacOS),
            DynamicSelector::Theme(ThemeCondition::Dark),
        ],
    ),
    // macOS light: dark grey thumb on light semi-transparent track
    CssPropertyWithConditions::with_single_condition(
        scrollbar_color(
            ColorU {
                r: 80,
                g: 80,
                b: 80,
                a: 200,
            },
            ColorU {
                r: 200,
                g: 200,
                b: 200,
                a: 80,
            },
        ),
        &[
            DynamicSelector::Os(OsCondition::MacOS),
            DynamicSelector::Theme(ThemeCondition::Light),
        ],
    ),
    // Windows dark
    CssPropertyWithConditions::with_single_condition(
        scrollbar_color(
            ColorU {
                r: 110,
                g: 110,
                b: 110,
                a: 255,
            },
            ColorU {
                r: 32,
                g: 32,
                b: 32,
                a: 255,
            },
        ),
        &[
            DynamicSelector::Os(OsCondition::Windows),
            DynamicSelector::Theme(ThemeCondition::Dark),
        ],
    ),
    // Windows light
    CssPropertyWithConditions::with_single_condition(
        scrollbar_color(
            ColorU {
                r: 130,
                g: 130,
                b: 130,
                a: 255,
            },
            ColorU {
                r: 241,
                g: 241,
                b: 241,
                a: 255,
            },
        ),
        &[
            DynamicSelector::Os(OsCondition::Windows),
            DynamicSelector::Theme(ThemeCondition::Light),
        ],
    ),
    // iOS dark
    CssPropertyWithConditions::with_single_condition(
        scrollbar_color(
            ColorU {
                r: 255,
                g: 255,
                b: 255,
                a: 100,
            },
            ColorU::TRANSPARENT,
        ),
        &[
            DynamicSelector::Os(OsCondition::IOS),
            DynamicSelector::Theme(ThemeCondition::Dark),
        ],
    ),
    // iOS light
    CssPropertyWithConditions::with_single_condition(
        scrollbar_color(
            ColorU {
                r: 0,
                g: 0,
                b: 0,
                a: 100,
            },
            ColorU::TRANSPARENT,
        ),
        &[
            DynamicSelector::Os(OsCondition::IOS),
            DynamicSelector::Theme(ThemeCondition::Light),
        ],
    ),
    // Android dark
    CssPropertyWithConditions::with_single_condition(
        scrollbar_color(
            ColorU {
                r: 255,
                g: 255,
                b: 255,
                a: 77,
            },
            ColorU::TRANSPARENT,
        ),
        &[
            DynamicSelector::Os(OsCondition::Android),
            DynamicSelector::Theme(ThemeCondition::Dark),
        ],
    ),
    // Android light
    CssPropertyWithConditions::with_single_condition(
        scrollbar_color(
            ColorU {
                r: 0,
                g: 0,
                b: 0,
                a: 77,
            },
            ColorU::TRANSPARENT,
        ),
        &[
            DynamicSelector::Os(OsCondition::Android),
            DynamicSelector::Theme(ThemeCondition::Light),
        ],
    ),
    // Linux / unknown dark fallback
    CssPropertyWithConditions::with_single_condition(
        scrollbar_color(
            ColorU {
                r: 100,
                g: 100,
                b: 100,
                a: 255,
            },
            ColorU {
                r: 45,
                g: 45,
                b: 45,
                a: 255,
            },
        ),
        &[DynamicSelector::Theme(ThemeCondition::Dark)],
    ),
    // Unconditional fallback (classic light)
    CssPropertyWithConditions::simple(scrollbar_color(
        ColorU {
            r: 193,
            g: 193,
            b: 193,
            a: 255,
        },
        ColorU {
            r: 241,
            g: 241,
            b: 241,
            a: 255,
        },
    )),
];
/// Resolved UA scrollbar defaults after evaluating conditions.
///
/// All fields are guaranteed to resolve because `UA_SCROLLBAR_CSS`
/// contains unconditional fallback entries for every property type.
#[derive(Debug, Copy, Clone)]
pub struct ResolvedUaScrollbar {
    pub color: StyleScrollbarColor,
    pub width: LayoutScrollbarWidth,
    pub visibility: ScrollbarVisibilityMode,
    pub fade_delay: ScrollbarFadeDelay,
    pub fade_duration: ScrollbarFadeDuration,
}
/// Evaluate UA scrollbar CSS rules against a `DynamicSelectorContext`.
///
/// Iterates `UA_SCROLLBAR_CSS` and picks the first matching entry per
/// property type.  Unconditional fallback entries in the table guarantee
/// that every field resolves.
/// The default `color` for text that inherits none, as a static table the
/// dynamic context resolves.
///
/// A UA default cannot be one constant: black text is correct on the light
/// window background and invisible on the dark one, and which of those the
/// window has is not known until a `DynamicSelectorContext` exists. Declaring
/// BOTH here — the plain rule and its `@theme dark` variant — keeps the table
/// static (so the UA property cache stays a pure function of node type) and
/// defers the choice to the same evaluation step the scrollbar defaults use.
///
/// Ordered most-specific first, like [`UA_SCROLLBAR_CSS`].
pub(crate) static UA_ROOT_TEXT_COLOR_CSS: &[CssPropertyWithConditions] = &[
    // Dark window background -> near-white text, matching the platform's own
    // "label" colour rather than pure white, which glares.
    CssPropertyWithConditions::with_single_condition(
        CssProperty::TextColor(CssPropertyValue::Exact(
            azul_css::props::style::text::StyleTextColor {
                inner: ColorU {
                    r: 0xe8,
                    g: 0xe8,
                    b: 0xe8,
                    a: 255,
                },
            },
        )),
        &[DynamicSelector::Theme(ThemeCondition::Dark)],
    ),
    // default -> opaque black, the CSS initial value.
    CssPropertyWithConditions::simple(CssProperty::TextColor(CssPropertyValue::Exact(
        azul_css::defaults::DEFAULT_TEXT_COLOR,
    ))),
];
/// The inherited-text-colour default for `ctx`'s theme, as a value.
///
/// The cascade consumes the same table through
/// [`get_ua_root_property_themed`], so after a cascade has run this answer is
/// already in every node's resolved style; the remaining callers are the
/// `debug_assert!`-guarded paint-time fallbacks, which should never be
/// reached on a cascaded DOM. Falls back to the CSS initial value if the
/// table somehow matches nothing, so this can never return "no colour".
#[must_use]
pub fn evaluate_ua_root_text_color(
    ctx: &DynamicSelectorContext,
) -> azul_css::props::style::text::StyleTextColor {
    match get_ua_root_property_themed(CssPropertyType::TextColor, Some(ctx)) {
        Some(CssProperty::TextColor(CssPropertyValue::Exact(c))) => *c,
        _ => azul_css::defaults::DEFAULT_TEXT_COLOR,
    }
}
#[must_use]
949723
pub fn evaluate_ua_scrollbar_css(ctx: &DynamicSelectorContext) -> ResolvedUaScrollbar {
949723
    let mut color: Option<StyleScrollbarColor> = None;
949723
    let mut width: Option<LayoutScrollbarWidth> = None;
949723
    let mut visibility: Option<ScrollbarVisibilityMode> = None;
949723
    let mut fade_delay: Option<ScrollbarFadeDelay> = None;
949723
    let mut fade_duration: Option<ScrollbarFadeDuration> = None;
24668397
    for prop in UA_SCROLLBAR_CSS {
24668397
        if !prop.matches(ctx) {
19910986
            continue;
4757411
        }
951922
        match &prop.property {
949723
            CssProperty::ScrollbarColor(CssPropertyValue::Exact(c)) => {
949723
                if color.is_none() {
949723
                    color = Some(*c);
949723
                }
            }
951922
            CssProperty::ScrollbarWidth(CssPropertyValue::Exact(w)) => {
951922
                if width.is_none() {
949723
                    width = Some(*w);
949723
                }
            }
951922
            CssProperty::ScrollbarVisibility(CssPropertyValue::Exact(v)) => {
951922
                if visibility.is_none() {
949723
                    visibility = Some(*v);
949723
                }
            }
951922
            CssProperty::ScrollbarFadeDelay(CssPropertyValue::Exact(d)) => {
951922
                if fade_delay.is_none() {
949723
                    fade_delay = Some(*d);
949723
                }
            }
951922
            CssProperty::ScrollbarFadeDuration(CssPropertyValue::Exact(d)) => {
951922
                if fade_duration.is_none() {
949723
                    fade_duration = Some(*d);
949723
                }
            }
            _ => {}
        }
4757411
        if color.is_some()
949723
            && width.is_some()
949723
            && visibility.is_some()
949723
            && fade_delay.is_some()
949723
            && fade_duration.is_some()
        {
949723
            break;
3807688
        }
    }
    // Unconditional `simple` entries in UA_SCROLLBAR_CSS guarantee all
    // fields resolve; these defaults match those entries as a safety net.
949723
    ResolvedUaScrollbar {
949723
        color: color.unwrap_or(StyleScrollbarColor::Custom(ScrollbarColorCustom {
949723
            thumb: ColorU {
949723
                r: 193,
949723
                g: 193,
949723
                b: 193,
949723
                a: 255,
949723
            },
949723
            track: ColorU {
949723
                r: 241,
949723
                g: 241,
949723
                b: 241,
949723
                a: 255,
949723
            },
949723
        })),
949723
        width: width.unwrap_or(LayoutScrollbarWidth::Auto),
949723
        visibility: visibility.unwrap_or(ScrollbarVisibilityMode::Always),
949723
        fade_delay: fade_delay.unwrap_or(ScrollbarFadeDelay { ms: 0 }),
949723
        fade_duration: fade_duration.unwrap_or(ScrollbarFadeDuration { ms: 0 }),
949723
    }
949723
}
#[cfg(test)]
#[path = "ua_css_test.rs"]
mod ua_css_test;