1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//! `<style>` block extraction + inline-style seeding — the
//! parse-and-apply glue between [`rdom_css`] (the parser) and
//! [`TuiDom`] (the tree being styled).
//!
//! Two helpers:
//!
//! - [`extend_from_style_tags`] walks a populated `TuiDom`, finds
//! every `<style>` element, concatenates its text-node children
//! into a single CSS source string, and parses + merges the
//! result into the target `Stylesheet`. Custom properties
//! declared in `:root` blocks are picked up too.
//! - [`seed_inline_styles`] walks a populated `TuiDom`, finds every
//! element with a `style="…"` attribute, parses the value, and
//! writes the resulting `TuiStyle` into the element's
//! `TuiExt::inline_style` slot.
//!
//! Both are one-shot snapshots. An [`App`](crate::runtime::App) needs
//! neither: it keeps `<style>` sheets live itself
//! (`cssom::style_elements`), seeds the `style="…"` attributes present
//! at mount, and the CSSOM observer re-parses `style="…"` on every
//! later write (`P7G-INLINE-STYLE-SEED-1`). Calling
//! `seed_inline_styles` before `App::new` is optional — it is
//! idempotent, and it is how to get the mount-time parse warnings.
//!
//! ## Layering
//!
//! `cssom/` is the canonical home for the rdom-css ↔ rdom-tui
//! glue. Step 26's `StyleDeclaration` lands as a sibling module
//! here. New code that needs both crates belongs in this module,
//! not scattered through the tree.
use ;
use ;
use Stylesheet;
use crateTuiDom;
/// Walk `dom` for `<style>` elements and merge their parsed CSS
/// into `sheet`. Returns the warnings collected from every
/// inner parse, concatenated in document order.
///
/// Behavior is fully additive: existing rules and vars on `sheet`
/// are preserved; the parsed rules are appended at the end (giving
/// them later source order, so they win cascade ties at equal
/// specificity).
///
/// A snapshot, for a cascade run without an `App`. An
/// [`App`](crate::runtime::App) applies the document's `<style>`
/// elements itself and keeps them live; merging them into a sheet
/// handed to an `App` as well applies their rules twice, and the
/// merged copy goes stale when the element's text changes.
/// Walk `dom` for every element with a `style="…"` attribute, parse
/// the value via [`rdom_css::parse_inline`], and write the resulting
/// `TuiStyle` into the element's `TuiExt::inline_style` slot. The
/// cascade then reads it through its existing inline rung — beating
/// every author rule short of `!important` per the CSS spec.
///
/// Returns the warnings collected from every inline parse,
/// concatenated in document order.
///
/// Idempotent: an element whose slot disagrees with its attribute has
/// the slot *replaced* by the attribute's parse; one whose attribute
/// already reads as the slot's serialization — a direct style setter or
/// CSSOM write since, which reflect into the attribute — keeps its slot
/// exactly (`cssom::inline`, `P7G-SEED-PRESERVE-1`). So a second call
/// changes nothing, and `set_width` before `App::build` survives it
/// alongside the markup's own `style` declarations. `App::build`
/// runs it (discarding the warnings — call it yourself first to see
/// them), and the CSSOM observer keeps the slots in step with later
/// `style` writes. Call it directly only for a `TuiDom` cascaded
/// without an `App`, whose `style` attributes were set before
/// `cssom::install_default_observers`.
/// Every node carrying a `style` attribute, in tree order: a pre-order
/// walk over the parent / sibling links — no recursion, so a very deep
/// tree cannot overflow the stack at mount.