max / makeover-webview
| 1 | //! The webview renderer for [`makeover_layout`]. |
| 2 | //! |
| 3 | //! <!-- wiki: makeover-webview --> |
| 4 | //! |
| 5 | //! # The renderer that needs no palette |
| 6 | //! |
| 7 | //! `makeover-immediate` and `makeover-tui` both take a `Palette`, because egui |
| 8 | //! and a terminal need an actual colour before they can put anything on |
| 9 | //! screen. A webview does not: `var(--surface-raised)` *is* the late binding, |
| 10 | //! and the browser resolves it against whatever `themes.js` last wrote onto |
| 11 | //! `:root`. |
| 12 | //! |
| 13 | //! So this crate emits text naming intents, and never learns a colour. It is |
| 14 | //! the deferral rule with no adapter in the way, and it is why the webview was |
| 15 | //! always the wrong renderer to derive a vocabulary from: it can express |
| 16 | //! anything, so it never pushes back. |
| 17 | //! |
| 18 | //! # Phase A: the stylesheet |
| 19 | //! |
| 20 | //! This module emits component CSS and no markup, deliberately. GoingsOn has |
| 21 | //! 145 `innerHTML` sites and Balanced Breakfast 175 `createElement` sites, so |
| 22 | //! moving markup is a migration where adopting a generated stylesheet is not. |
| 23 | //! The apps keep every line of their markup and gain the classes. |
| 24 | //! |
| 25 | //! It is not a deletion either, which this header claimed until the measurement |
| 26 | //! came in. Adoption across goingson removed 49 declarations net and *added* 25 |
| 27 | //! lines: a rule loses its depth declarations and gains a variant selector next |
| 28 | //! to it, so the file stays the same size. What phase A moves is where depth is |
| 29 | //! defined, not how much CSS exists. Numbers and method in the wiki note under |
| 30 | //! "The deletion test, run". |
| 31 | //! |
| 32 | //! The bevel properties are byte-identical to what both apps already |
| 33 | //! hand-write, which is asserted below. |
| 34 | //! |
| 35 | //! # Phase B: the markup, one description at a time |
| 36 | //! |
| 37 | //! [`form`] renders [`makeover_layout::Field`], which is the half of phase B |
| 38 | //! whose description is settled. It emits strings, because both apps |
| 39 | //! interpolate their fields into larger string-built forms and returning nodes |
| 40 | //! would rewrite those too. It owns its own escaping, on the reasoning in that |
| 41 | //! module: a Rust encoder can cover element text and attribute values with one |
| 42 | //! function, where the apps need four and have to choose correctly at every |
| 43 | //! call site. |
| 44 | //! |
| 45 | //! [`list`] is the other half: column tracks, the narrowing rules, and the cell |
| 46 | //! containers a row is made of. It stops at the cell boundary and does not |
| 47 | //! render what goes inside one, on the reasoning in that module. So phase B is |
| 48 | //! now the frame around content in both directions, and what an app still owns |
| 49 | //! is the content itself. |
| 50 | //! |
| 51 | //! # What phase A settled, and what it costs |
| 52 | //! |
| 53 | //! Decided 2026-07-29 against goingson's `styles.css` rather than against a |
| 54 | //! component list. The useful finding there was that `.btn` (line 644), |
| 55 | //! `.card` (768) and `.tag, .badge` (882) each hand-write the same |
| 56 | //! composition, so three quarters of phase A is one rule with several names. |
| 57 | //! |
| 58 | //! Two of the four decisions change how goingson looks, and adoption should |
| 59 | //! not be described as a pure deletion: |
| 60 | //! |
| 61 | //! - **Pressed carries its fill.** [`interactive_rules`] emits |
| 62 | //! [`Depth::pressed`] whole. goingson presses to `--surface-sunken` today and |
| 63 | //! will press to `--surface-well`, and hovers to `--surface-overlay` today |
| 64 | //! and will hover to `--hover-surface`. Since `surface-well` inverts by theme |
| 65 | //! where `surface-sunken` does not, a dark theme presses *lighter* than it |
| 66 | //! hovers. That falls out of `makeover`'s own derivation, which says outright |
| 67 | //! that `surface-sunken` cannot serve as a well, so if it reads wrong the |
| 68 | //! answer is there and not here. |
| 69 | //! - **Badges go flat.** See [`token_rules`]. |
| 70 | //! |
| 71 | //! The other two: the progress trough is renderer-local and the scrollbar |
| 72 | //! track was dropped ([`component_rules`]), and no class prefix ships by |
| 73 | //! default, so adoption means deleting the app's hand-written rule in the same |
| 74 | //! commit that adds the generated one. `.card`, `.badge` and the tab classes |
| 75 | //! all already exist in goingson, and while both rules exist the cascade order |
| 76 | //! decides which wins. That is the one real risk in adopting this, and it is |
| 77 | //! why the migration lands per component rather than in one commit. |
| 78 | //! |
| 79 | //! # 0.10.0: the states this crate used to leave to its consumers |
| 80 | //! |
| 81 | //! [`interactive_rules`] emitted hover and pressed and stopped, because |
| 82 | //! `makeover-layout` modelled no interaction state. Focus and disabled were |
| 83 | //! therefore unsayable, and every app completed the primitive from outside the |
| 84 | //! only way that works: by out-specifying a rule it does not own. goingson |
| 85 | //! carries 19 such rules and the MNW server 21, and the three focus rings do |
| 86 | //! not match each other. |
| 87 | //! |
| 88 | //! That also blocked the cascade-layer work outright. An app that declares |
| 89 | //! `@layer` puts its own rules in a named layer, and unlayered declarations |
| 90 | //! outrank every named layer regardless of specificity, so all of those |
| 91 | //! overrides lose in the commit that adopts layers. They cannot simply be |
| 92 | //! deleted, because they are the only thing supplying the missing states. |
| 93 | //! Emitting the states here is what turns that adoption into a deletion. |
| 94 | //! |
| 95 | //! Four states now, in emission order, and the order is load-bearing: they are |
| 96 | //! all specificity (0,2,0), so disabled beats hover by coming last and by |
| 97 | //! nothing else. Nothing here reaches for `:not(:disabled)`, which would raise |
| 98 | //! a selector this crate will shortly be wrapping in its own layer. |
| 99 | //! |
| 100 | //! Hover additionally sits inside a capability query now. `makeover-touch` |
| 101 | //! answers whether a fingertip has hover and `makeover-geometry` spells the |
| 102 | //! condition; this crate asks and does not decide. goingson's section 60 exists |
| 103 | //! solely to take the hover state back on touch, which is a fight it should |
| 104 | //! never have been handed. |
| 105 | //! |
| 106 | //! # 0.11.0: the layer contract |
| 107 | //! |
| 108 | //! [`stylesheet`] emits into the `makeover` cascade layer ([`CSS_LAYER`], which |
| 109 | //! lives in `makeover-geometry` because that is the one crate every CSS emitter |
| 110 | //! in the family already depends on). `makeover-geometry` 0.6.0 does the same |
| 111 | //! for `geometry.css`. |
| 112 | //! |
| 113 | //! The cascade resolves origin and importance, then layer, then specificity, |
| 114 | //! then source order, and **unlayered normal declarations outrank every named |
| 115 | //! layer**. So before this, an app that declared `@layer base, components, |
| 116 | //! responsive` put every rule it owns into a named layer and lost all of them to |
| 117 | //! this unlayered file, regardless of specificity and regardless of loading |
| 118 | //! last. Nothing errors when that happens: the CSS is valid, the minifier is |
| 119 | //! happy, and buttons and badges look subtly wrong. |
| 120 | //! |
| 121 | //! That is why the layer belongs here rather than in each app. An app cannot fix |
| 122 | //! it from its own stylesheet, because the fix is to layer the file it does not |
| 123 | //! own. |
| 124 | //! |
| 125 | //! **What it flips**, and the reason each app wants a look when it bumps the |
| 126 | //! pin: a generated rule that currently beats an app rule by being more specific |
| 127 | //! stops beating it. The direction is always "the app wins", which is what the |
| 128 | //! apps already assume, but a hand-written rule an app thought was dead can come |
| 129 | //! back to life. |
| 130 | //! |
| 131 | //! An app should declare the order once, or the layer's position is decided by |
| 132 | //! whichever generated file the browser happens to see first: |
| 133 | //! |
| 134 | //! ```css |
| 135 | //! @layer makeover, base, components, responsive; |
| 136 | //! ``` |
| 137 | //! |
| 138 | //! [`in_css_layer`] is re-exported for an app that assembles its own stylesheet |
| 139 | //! from this crate's pieces. goingson builds `tables.css` in its own `build.rs` |
| 140 | //! out of [`list::narrowing_css`] and [`list::grid_template_columns`], and those |
| 141 | //! rules are as generated as the ones here, so they belong in the same layer and |
| 142 | //! this crate cannot put them there on the app's behalf. |
| 143 | //! |
| 144 | //! # 0.12.0: the ring gets its own width |
| 145 | //! |
| 146 | //! [`focus_rule`] reused [`Emit::border_width`] and emitted a 1px ring. That was |
| 147 | //! an implementation convenience dressed as consistency with the invalid-field |
| 148 | //! ring: a bevel and a focus indicator answer different questions, and only one |
| 149 | //! of them has to be noticed from across a desk. |
| 150 | //! |
| 151 | //! Caught while adopting 0.11.0 into goingson, by the check the adoption tasks |
| 152 | //! ask for. Every consumer had already written its own ring and all three chose |
| 153 | //! at least 2px: the MNW server 2px across 10 rules, Balanced Breakfast 2px, |
| 154 | //! goingson 2px on three rules and 3px on the one covering twelve selectors. The |
| 155 | //! design system was the only thing in the tree saying 1px, so deleting the app |
| 156 | //! rules in favour of it would have thinned the focus indicator everywhere. |
| 157 | //! |
| 158 | //! [`Emit::focus_width`] now carries it, defaulting to `2px`, and the offset is |
| 159 | //! the same magnitude with its sign off the depth. Both values are the measured |
| 160 | //! consensus rather than a new opinion. |
| 161 | //! |
| 162 | //! # 0.47.0: a range, a chooser's ghost text, and an option that cannot be |
| 163 | //! picked yet |
| 164 | //! |
| 165 | //! `makeover-layout` 0.28.0's three form findings, all of them cheap here and |
| 166 | //! none of them cheap in the app that found them. |
| 167 | //! |
| 168 | //! - `FieldKind::Range` emits `<input type="range">`, and `Field::step` emits |
| 169 | //! `step`. The step is emitted only when the description carries one: the |
| 170 | //! browser's own default is `step="1"`, which is what a description means by |
| 171 | //! saying nothing, and is also what turns a 0-to-1 threshold into a |
| 172 | //! two-position control. |
| 173 | //! - A select with nothing chosen emits a disabled, selected, valueless first |
| 174 | //! option carrying `Field::placeholder`. HTML has no placeholder attribute on |
| 175 | //! `<select>`; this is the idiom, and `required` keeps working through it |
| 176 | //! because the option's value is empty. |
| 177 | //! - `Choice::unavailable` emits `disabled` plus the reason. Where it goes |
| 178 | //! differs by control and the difference is forced: a radio group gets a |
| 179 | //! `.form-option-reason` span beside the label, and a `<select>` option has |
| 180 | //! room for no element at all, so the reason runs into its text. |
| 181 | //! |
| 182 | //! # 0.25.0: a cell says what it holds |
| 183 | //! |
| 184 | //! 0.23.0 gave a table its layout and left every cell the same. One `.cell` |
| 185 | //! carried the whole thing, so a cell holding text and a cell holding a button |
| 186 | //! were one class and one content colour, and a control in a cell was painted |
| 187 | //! as text. That is the drift [`RowPart::intent`](makeover_layout::RowPart) |
| 188 | //! has prevented for list rows since 0.2.0 and prevented for nothing here. |
| 189 | //! |
| 190 | //! makeover-layout 0.14.0's [`CellPart`](makeover_layout::CellPart) names the |
| 191 | //! four things a cell holds, and [`table_rules`] turns them into |
| 192 | //! `.cell-value`, `.cell-tokens`, `.cell-actions` and `.cell-link`. Only the |
| 193 | //! first takes a colour: a token carries its own tone, an action is a control |
| 194 | //! rather than text, and a link takes the action colour from the anchor it is. |
| 195 | //! |
| 196 | //! The colour going on `.cell-value` rather than on `.cell` is the fix rather |
| 197 | //! than an implementation detail. On the container it cascades into the parts |
| 198 | //! that are not text, which is the bug said in one rule. |
| 199 | //! |
| 200 | //! [`list::Cell::part`] is `Option<CellPart>` here, where it was |
| 201 | //! `Option<RowPart>`. A table cell borrowing the list row's vocabulary was the |
| 202 | //! drift with a type on it: the two answer different questions, and only one of |
| 203 | //! them was ever about a cell. |
| 204 | //! |
| 205 | //! # 0.23.0: a table lays itself out, and a row shows its controls |
| 206 | //! |
| 207 | //! Three things a description could say and this renderer had no rule for, |
| 208 | //! found together by rendering the MNW server's SSH-keys settings tab through |
| 209 | //! `quasi` and preferring the hand-written Askama original. |
| 210 | //! |
| 211 | //! **A table had no layout at all.** [`list::narrowing_css`] emits the track |
| 212 | //! list, and it has to be called with the columns, so it works where the |
| 213 | //! columns are known at build time: goingson builds `tables.css` in its own |
| 214 | //! `build.rs` and is untouched. A table a description produced knows its |
| 215 | //! columns at render time, and the rules would have had to travel with the |
| 216 | //! markup: a `<style>` element per table, which needs `style-src |
| 217 | //! 'unsafe-inline'` that the MNW server is working to drop, or the head, which |
| 218 | //! an htmx fragment swap does not carry. [`table_rules`] lays a table out with |
| 219 | //! `display: table` instead, which aligns columns across rows knowing nothing |
| 220 | //! about how many there are. [`Priority`](makeover_layout::Priority) hiding |
| 221 | //! moves from a generated rule per dropped column to one rule per drop class, |
| 222 | //! and [`list::column_classes`] is what puts those classes on a cell. A header |
| 223 | //! row emitted by a renderer's own code should call it too, or the header and |
| 224 | //! the body disagree about which column just dropped. |
| 225 | //! |
| 226 | //! **A destructive button had nowhere for its tone to land.** `.button` carried |
| 227 | //! no tone, on the reading that a control's colour is its surface. Every |
| 228 | //! consumer had written the danger rule itself. It joins the badge in taking |
| 229 | //! the four tones as colour, off `data-tone`. |
| 230 | //! |
| 231 | //! **A list rendered as a bulleted list**, because nothing here reset the `ul` |
| 232 | //! a renderer emits for one. |
| 233 | //! |
| 234 | //! `RowPart::revealed_on_hover` also stops being honoured, which its own doc |
| 235 | //! sanctioned: a renderer decides. It was retired outright in makeover-layout |
| 236 | //! 0.13.0, once this had been its only consumer for a release. The rule hid a |
| 237 | //! row's actions until hover, |
| 238 | //! and every escape it grew was a report that hiding was wrong for somebody: |
| 239 | //! `focus-within` for the keyboard, the capability gate for a fingertip with no |
| 240 | //! way to unhide. What survived hid the controls from pointer users alone, who |
| 241 | //! are the ones scanning a list to learn what can be done to a row. |
| 242 | //! |
| 243 | //! # 0.17.0: the depth classes stop being controls |
| 244 | //! |
| 245 | //! [`depth_rules`] gave `.raised` the whole interactive set. A depth is a |
| 246 | //! statement about shape, so that left the vocabulary with no raised surface |
| 247 | //! that is merely an object, and an app wanting one had two moves: write its |
| 248 | //! own class from tokens, or take a control class and cancel the control half. |
| 249 | //! goingson took the second, in three variants over sixteen elements |
| 250 | //! (`.card--static` at 14 call sites, `.card--muted` at 2, `.card--shell` at 1), |
| 251 | //! each re-asserting the resting fill and bevel on `:hover` and `:active`. |
| 252 | //! |
| 253 | //! Measured before changing it: `.raised` is emitted into goingson, Balanced |
| 254 | //! Breakfast and the MNW server, and none of the three has a single call site. |
| 255 | //! The states were unasked-for everywhere at once, and dropping them costs no |
| 256 | //! migration anywhere. |
| 257 | //! |
| 258 | //! `.card` and `.button` are unchanged. They are the same depth *and* controls, |
| 259 | //! and they take their states from [`surface_rules`], which is where a state |
| 260 | //! belongs: on the thing that claims to answer a pointer. |
| 261 | //! |
| 262 | //! # Substitution, three ways |
| 263 | //! |
| 264 | //! `Fill::Well` has no colour on makeover before 2.3.0, and each renderer |
| 265 | //! answers that differently, which is the evidence that dropping |
| 266 | //! `Fill::fallback` from the description was right: |
| 267 | //! |
| 268 | //! - `makeover-immediate` substitutes the page in Rust. |
| 269 | //! - `makeover-tui` refuses to substitute and draws an edge instead, because a |
| 270 | //! terminal would quantise the two together. |
| 271 | //! - here, CSS already has the mechanism: `var(--surface-well, |
| 272 | //! var(--surface-page))` falls back in the browser, and nothing in Rust |
| 273 | //! decides anything. |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | use crate; |
| 285 | use ; |
| 286 | // Re-exported rather than redefined. An app assembling its own stylesheet out |
| 287 | // of this crate's pieces needs the same layer name, and most such apps depend |
| 288 | // on this crate and not on `makeover-geometry` directly: goingson builds |
| 289 | // `tables.css` in its own build.rs from [`list::narrowing_css`], and those |
| 290 | // rules are as generated as the ones here. |
| 291 | pub use ; |
| 292 | use |
| 293 | Bevel, CellPart, Depth, Fill, Intent, RowPart, Selector, Sort, State, Token, Tone, |
| 294 | ; |
| 295 | use Affordance; |
| 296 | use Write as _; |
| 297 | |
| 298 | /// How the emitted CSS is shaped. |
| 299 | |
| 300 | |
| 301 | /// Bevel thickness, as a CSS length. |
| 302 | /// |
| 303 | /// A value, so it arrives from the caller: border widths belong to |
| 304 | /// `makeover-geometry` and will come from there once it carries them. |
| 305 | pub border_width: &'static str, |
| 306 | /// Focus ring thickness, as a CSS length. |
| 307 | /// |
| 308 | /// Separate from [`border_width`](Self::border_width), which it reused |
| 309 | /// until 0.12.0. That reuse was an implementation convenience dressed as |
| 310 | /// consistency, and it emitted a 1px ring: a bevel and a focus indicator |
| 311 | /// are answering different questions, and only one of them has to be |
| 312 | /// noticed from across a desk. |
| 313 | /// |
| 314 | /// The default is the measured consensus rather than a new opinion. Every |
| 315 | /// consumer had already written its own ring and all three chose at least |
| 316 | /// 2px: the MNW server 2px across 10 rules, Balanced Breakfast 2px, |
| 317 | /// goingson 2px on three rules and 3px on the one covering twelve |
| 318 | /// selectors. The design system was the only thing in the tree saying 1px. |
| 319 | pub focus_width: &'static str, |
| 320 | /// Prefix for emitted class names, without the leading dot. |
| 321 | pub class_prefix: &'static str, |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | Self |
| 327 | border_width: "1px", |
| 328 | focus_width: "2px", |
| 329 | class_prefix: "", |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | /// A string as CSS escapes, for a `content` value. |
| 335 | /// |
| 336 | /// `\u{25B2}` becomes `\25B2`. Emitted escaped rather than literally so the |
| 337 | /// stylesheet is ASCII whatever the description spells: a `content` string is |
| 338 | /// read by whatever encoding the consumer serves the file as, and a caret that |
| 339 | /// depends on that is a caret that works on one machine. |
| 340 | /// |
| 341 | /// Terminated by the closing quote at every site here. A CSS hex escape takes |
| 342 | /// up to six digits and ends at the first character that cannot be one, so an |
| 343 | /// escape followed by more text would need a space that these do not. |
| 344 | |
| 345 | text.chars.fold |
| 346 | let _ = write!; |
| 347 | out |
| 348 | |
| 349 | |
| 350 | |
| 351 | /// The CSS custom property holding a bevel's composition. |
| 352 | |
| 353 | |
| 354 | match bevel |
| 355 | Raised => "--bevel-raised", |
| 356 | Inset => "--bevel-inset", |
| 357 | |
| 358 | |
| 359 | |
| 360 | /// A `var()` reference to a fill intent, with the browser's own fallback where |
| 361 | /// the intent may be absent. |
| 362 | /// |
| 363 | /// The fallback is CSS syntax, not a decision made here. That is the whole |
| 364 | /// difference between this renderer and the other two. |
| 365 | |
| 366 | |
| 367 | match fill |
| 368 | Well => format!, |
| 369 | other => format!, |
| 370 | |
| 371 | |
| 372 | |
| 373 | /// The two-tone edge as a `box-shadow` value. |
| 374 | /// |
| 375 | /// Two inset shadows, one per corner pair: the light one offset down and |
| 376 | /// right so it lands on the top and left edges, the dark one the other way. |
| 377 | /// The same assignment `makeover-immediate` draws with polylines and |
| 378 | /// `makeover-tui` draws with box-drawing characters. |
| 379 | |
| 380 | |
| 381 | let = bevel.edges; |
| 382 | let w = opts.border_width; |
| 383 | format! |
| 384 | "inset {w} {w} 0 var(--{}), inset -{w} -{w} 0 var(--{})" |
| 385 | top_left.token, |
| 386 | bottom_right.token |
| 387 | ) |
| 388 | |
| 389 | |
| 390 | /// The custom properties both bevels resolve through. |
| 391 | /// |
| 392 | /// Emitted as properties rather than inlined into every rule because that is |
| 393 | /// what the apps already do, and because a consumer that wants the edge |
| 394 | /// without the fill reads the property directly. |
| 395 | |
| 396 | |
| 397 | let mut css = Stringnew; |
| 398 | for bevel in |
| 399 | let _ = writeln! |
| 400 | css, |
| 401 | " {}: {};" |
| 402 | bevel_var, |
| 403 | bevel_shadow |
| 404 | ); |
| 405 | |
| 406 | css.push_str; |
| 407 | css |
| 408 | |
| 409 | |
| 410 | /// The cast shadow of a surface that floats over the page. |
| 411 | /// |
| 412 | /// Composed here for the reason the bevel pair is: `makeover` derives the tone, |
| 413 | /// this crate owns the geometry, and neither has to know the other's numbers. |
| 414 | /// |
| 415 | /// **Only for a surface that overlays the page.** A menu, a toast, a popover, a |
| 416 | /// dropdown. A surface *in* the page takes `.raised` and its bevel, and a rule |
| 417 | /// that reaches for this on a card or a plate has renamed a literal rather than |
| 418 | /// replaced it. |
| 419 | /// |
| 420 | /// Two lengths rather than one, because a single blur reads as a smudge at |
| 421 | /// plate size and as a halo at menu size. The offset is small and downward: a |
| 422 | /// Platinum-era menu sits just off the page rather than hovering above it. |
| 423 | const ELEVATION_PROPERTY: &str = |
| 424 | " --elevation-overlay: 0 2px 4px var(--elevation), 0 8px 24px var(--elevation);\n"; |
| 425 | |
| 426 | /// The class name for a depth. |
| 427 | |
| 428 | |
| 429 | let name = match depth |
| 430 | Flat => return None, |
| 431 | Raised => "raised", |
| 432 | Well => "well", |
| 433 | Sunken => "sunken", |
| 434 | // A depth added to the description since this renderer was last |
| 435 | // built. No class, on the same footing as Flat: emitting a name |
| 436 | // whose rule body we cannot write would put a class in the markup |
| 437 | // that the stylesheet never defines. |
| 438 | _ => return None, |
| 439 | ; |
| 440 | Some |
| 441 | |
| 442 | |
| 443 | /// A prefixed class name. |
| 444 | /// |
| 445 | /// Public since 0.27.0, for the renderers that emit markup this crate does not. |
| 446 | /// A screen renderer writing `class="row"` has to prefix it the way the |
| 447 | /// stylesheet half does or a prefixed app gets rules matching everything except |
| 448 | /// the elements that renderer wrote, and the failure is invisible: the CSS |
| 449 | /// stays valid and one element is unstyled. quasi-webview carried a byte |
| 450 | /// identical copy of this function until it could call this one. |
| 451 | |
| 452 | |
| 453 | let mut out = Stringwith_capacity; |
| 454 | push_class; |
| 455 | out |
| 456 | |
| 457 | |
| 458 | /// A prefixed class name, written into a buffer the caller already has. |
| 459 | /// |
| 460 | /// The form the emitters use, and the reason it exists is [`escape_into`]'s: |
| 461 | /// every class on every element went through a `format!` before 0.40.0, |
| 462 | /// including the default case where the prefix is empty and the answer is the |
| 463 | /// argument. A described table row carried roughly eighty transient |
| 464 | /// allocations, and this and the escaper were most of them. |
| 465 | /// |
| 466 | /// [`class`] stays for callers holding a name rather than a buffer. |
| 467 | /// |
| 468 | /// [`escape_into`]: crate::form::escape_into |
| 469 | |
| 470 | out.push_str; |
| 471 | out.push_str; |
| 472 | |
| 473 | |
| 474 | /// The class an option of a selector carries, which is what the rules key off. |
| 475 | /// |
| 476 | /// Named for the option and not for the group: [`selector_rules`] styles the |
| 477 | /// thing that gets picked, so `Selector::Tabs` is `tab` and not `tabs`. The |
| 478 | /// distinction is not pedantry. quasi-webview spelled these `tabs`, `segmented` |
| 479 | /// and `option`, put `toggle` on the wrapping element rather than on the |
| 480 | /// buttons inside it, and every described selector in that renderer came out |
| 481 | /// with no depth, no focus ring and no chosen state, while the toggle group got |
| 482 | /// a bevel meant for its buttons. |
| 483 | /// |
| 484 | /// The chosen option additionally carries `chosen`, the same way a latched chip |
| 485 | /// carries `latched`. That name is this crate's too; there is no reason for a |
| 486 | /// caller to spell it, and [`selector_rules`] is where it is written down. |
| 487 | |
| 488 | |
| 489 | match selector |
| 490 | Tabs => "tab", |
| 491 | Segmented => "segment", |
| 492 | Toggle => "toggle", |
| 493 | |
| 494 | |
| 495 | |
| 496 | /// The fill and edge declarations for a depth, as a rule body. |
| 497 | /// |
| 498 | /// Empty for [`Depth::Flat`], which has neither and inherits what it sits on. |
| 499 | /// Callers lean on the emptiness to skip the rule rather than emit a class that |
| 500 | /// sets nothing: a class that sets no properties is a class that means "I |
| 501 | /// thought about this", which is what comments are for. |
| 502 | /// |
| 503 | /// The two halves are emitted independently because [`Depth::Sunken`] has a |
| 504 | /// fill and no bevel. Requiring both, which this did before makeover-layout |
| 505 | /// 0.3.0, silently dropped the fill for exactly that case. Independent does not |
| 506 | /// mean unpaired: both halves still come off one `Depth`, so they cannot |
| 507 | /// disagree about what the region is. |
| 508 | |
| 509 | |
| 510 | let mut css = Stringnew; |
| 511 | if let Some = depth.fill |
| 512 | let _ = writeln!; |
| 513 | |
| 514 | if let Some = depth.bevel |
| 515 | let _ = writeln!; |
| 516 | |
| 517 | css |
| 518 | |
| 519 | |
| 520 | /// One rule giving a selector a depth, or nothing when the depth declares |
| 521 | /// nothing. |
| 522 | |
| 523 | |
| 524 | let body = depth_declarations; |
| 525 | if body.is_empty |
| 526 | return Stringnew; |
| 527 | |
| 528 | format! |
| 529 | |
| 530 | |
| 531 | /// The media condition a hover rule has to sit inside, or `None` if hover is |
| 532 | /// unconditional. |
| 533 | /// |
| 534 | /// Two crates answer this and neither answer is made here. `makeover-touch` |
| 535 | /// owns *whether* hover exists at a density, and `makeover-geometry` owns how |
| 536 | /// that capability is spelled as a media condition. Asking both is what stops |
| 537 | /// this renderer minting a third opinion, which is what all three apps did: |
| 538 | /// goingson sniffed the user agent, Balanced Breakfast used `(hover: none)` |
| 539 | /// alone, and the MNW server had no gate at all. |
| 540 | /// |
| 541 | /// [`SizeClass`] is required by [`Affordance::available`] and ignored by this |
| 542 | /// member, which reports as much through `reads_size`. Passing Compact is not |
| 543 | /// a claim about width; the test below pins that every class agrees. |
| 544 | |
| 545 | if Hover.available |
| 546 | // A fingertip grew a hover state. Nothing to gate, and this renderer |
| 547 | // should not invent a reason to gate anyway. |
| 548 | None |
| 549 | else |
| 550 | Some |
| 551 | |
| 552 | |
| 553 | |
| 554 | /// Put a rule inside a media query, or leave it alone. |
| 555 | |
| 556 | let Some = condition else |
| 557 | return rule.to_string; |
| 558 | ; |
| 559 | let mut css = format!; |
| 560 | for line in rule.lines |
| 561 | // Blank lines stay blank. Indenting one leaves trailing whitespace, |
| 562 | // which is the sort of thing a formatter later reverts and calls a diff. |
| 563 | if line.is_empty |
| 564 | css.push; |
| 565 | else |
| 566 | let _ = writeln!; |
| 567 | |
| 568 | |
| 569 | css.push_str; |
| 570 | css |
| 571 | |
| 572 | |
| 573 | /// The keyboard focus ring, placed by the depth it lands on. |
| 574 | /// |
| 575 | /// This is the webview's **focus ring** and nothing more. **Reach** and |
| 576 | /// **focus** are both the browser's — the document decides what is reachable |
| 577 | /// and `:focus-visible` decides which reached thing wears the ring — and no |
| 578 | /// description states either. The three terms are defined once in |
| 579 | /// `makeover_layout`'s crate header, "Reach, focus and the focus ring". |
| 580 | /// |
| 581 | /// One ring for the whole system, because a focus ring's job is to be |
| 582 | /// recognised and three apps having three of them is the failure. What varies |
| 583 | /// is where it sits, and that comes off [`Depth`] rather than off a per- |
| 584 | /// component choice: a well takes the ring inside its own edge, and anything |
| 585 | /// standing proud of the page takes it outside. |
| 586 | /// |
| 587 | /// `outline` rather than the composed `box-shadow` the invalid-field ring at |
| 588 | /// [`field_rules`] uses, and deliberately the one place the two rings are built |
| 589 | /// differently. A `box-shadow` ring has to restate the bevel beside it, because |
| 590 | /// `box-shadow` is not additive and a lone ring silently drops the well out |
| 591 | /// from under the element. That restatement is a second copy of the depth, |
| 592 | /// living in a different function from the first, and it is exactly the |
| 593 | /// duplication `Depth` exists to prevent. `outline` occupies its own property, |
| 594 | /// so the bevel survives untouched and there is nothing to keep in agreement. |
| 595 | /// They render the same: both are a flush ring one border-width wide. |
| 596 | |
| 597 | |
| 598 | let w = opts.focus_width; |
| 599 | // Same magnitude either way, and only the sign comes off the depth. Both |
| 600 | // values are what the consumers had already converged on independently: |
| 601 | // 2px out is what all three wrote, and 2px in is the MNW server's own |
| 602 | // answer for the one inset ring it had. |
| 603 | let offset = match depth.bevel |
| 604 | // Inside the well, clear of its edge rather than painted over it. |
| 605 | Some => format!, |
| 606 | // Raised, or no edge at all. Outside, standing off by its own width. |
| 607 | _ => w.to_string, |
| 608 | ; |
| 609 | // The token by name. It is `makeover`'s, derived from the action colour, |
| 610 | // and reaching it through a description member was a second path to the |
| 611 | // same variable for as long as one existed. |
| 612 | format! |
| 613 | ".{selector}:focus-visible {{\n outline: {w} solid var(--focus-ring);\n outline-offset: {offset};\n}}\n" |
| 614 | |
| 615 | |
| 616 | |
| 617 | /// Present, visible, and not answering. |
| 618 | /// |
| 619 | /// Matches the ARIA attribute as well as the pseudo-class, because `:disabled` |
| 620 | /// only matches form elements and half the things this crate emits are not |
| 621 | /// one: a `div` carrying `.chip` or `.tab` can never be `:disabled`. Keying on |
| 622 | /// the accessible state is the pattern [`field_rules`] already establishes for |
| 623 | /// `aria-invalid`, on the reasoning that one fact read by both the styling and |
| 624 | /// the accessibility tree cannot drift from itself. |
| 625 | /// |
| 626 | /// The rest depth is re-asserted rather than assumed, because this rule has to |
| 627 | /// beat the hover and pressed rules above it. It does that on source order at |
| 628 | /// equal specificity, not by out-specifying them: every rule this function's |
| 629 | /// caller emits is (0,2,0), and adding a `:not(:disabled)` anywhere would raise |
| 630 | /// one of them and have to be unpicked when this output moves inside its own |
| 631 | /// cascade layer. |
| 632 | |
| 633 | |
| 634 | format! |
| 635 | ".{selector}:disabled,\n.{selector}[aria-disabled=\"true\"] {{\n{} color: var(--{});\n cursor: not-allowed;\n}}\n" |
| 636 | depth_declarations, |
| 637 | Disabled.token |
| 638 | ) |
| 639 | |
| 640 | |
| 641 | /// Every state a selector that answers a click implies: hover, pressed, focus |
| 642 | /// and disabled, in that order. |
| 643 | /// |
| 644 | /// Order is the whole cascade mechanism here. All four selectors are |
| 645 | /// specificity (0,2,0), so disabled wins over hover and pressed by coming last |
| 646 | /// and by nothing else. |
| 647 | /// |
| 648 | /// Pressed emits [`Depth::pressed`] in full, fill and edge together. Emitting |
| 649 | /// only the edge is what left goingson hand-writing `background: |
| 650 | /// var(--surface-sunken)` on three separate rules, and a fill that does not |
| 651 | /// travel with its edge is precisely the disagreement `Depth` exists to make |
| 652 | /// unrepresentable. So the pressed fill comes from the description |
| 653 | /// (`--surface-well`) rather than from whatever each app reached for. |
| 654 | /// |
| 655 | /// Hover has no member in the description and is renderer policy: a terminal |
| 656 | /// and an immediate-mode painter have no hover to express. It resolves against |
| 657 | /// `--hover-surface`, which `makeover` already derives and which nothing |
| 658 | /// consumed until now. What it *is* gated on is capability, via |
| 659 | /// [`hover_condition`]. Before that gate existed the apps each wrote their own: |
| 660 | /// goingson's section 60 exists solely to take back the hover state this |
| 661 | /// function had just handed it, by out-specifying a rule it does not own. |
| 662 | /// |
| 663 | /// `depth` is the selector's **rest** depth, used to place the focus ring and |
| 664 | /// to restore the surface under a disabled control. The pressed rule keeps |
| 665 | /// inverting from [`Depth::Raised`] regardless, which is what every caller got |
| 666 | /// before this parameter existed: a tab's unchosen depth is |
| 667 | /// [`Depth::Sunken`], and `Sunken.pressed()` is `Sunken`, so deriving the press |
| 668 | /// from the rest depth would leave a tab with no press at all. |
| 669 | |
| 670 | |
| 671 | let mut css = gated |
| 672 | hover_condition, |
| 673 | &format!, |
| 674 | ; |
| 675 | css.push_str |
| 676 | &format!, |
| 677 | Raised.pressed, |
| 678 | ; |
| 679 | css.push_str; |
| 680 | css.push_str; |
| 681 | css |
| 682 | |
| 683 | |
| 684 | /// One rule per depth: its fill and its edge, together. |
| 685 | /// |
| 686 | /// A depth and nothing else. `.raised` says a surface sits on what is behind |
| 687 | /// it, which is a statement about the shape and not about what happens when a |
| 688 | /// pointer arrives, so it emits no hover, press, focus or disabled rule. The |
| 689 | /// named surfaces are where interaction lives: `.card` and `.button` are the |
| 690 | /// same depth *and* controls, and they get their states from |
| 691 | /// [`surface_rules`]. |
| 692 | /// |
| 693 | /// This class carried the interactive set until 0.17.0, which left the |
| 694 | /// vocabulary with no raised surface that is merely an object. Consumers that |
| 695 | /// needed one took a control class and cancelled half of it instead: sixteen |
| 696 | /// elements in goingson across three `.card--*` variants, each re-asserting the |
| 697 | /// resting fill and bevel on `:hover` and `:active`. Nothing anywhere used |
| 698 | /// `.raised` itself, so the states were unasked-for in every consumer at once. |
| 699 | |
| 700 | |
| 701 | let mut css = Stringnew; |
| 702 | for depth in |
| 703 | let Some = depth_class else |
| 704 | continue; |
| 705 | ; |
| 706 | css.push_str; |
| 707 | |
| 708 | css |
| 709 | |
| 710 | |
| 711 | /// The three surfaces that are a depth with a name. |
| 712 | /// |
| 713 | /// `button` and `card` are both [`Depth::Raised`], and `field` is a |
| 714 | /// [`Depth::Well`] because that is the reading `Depth`'s own documentation |
| 715 | /// gives a text field. Their bodies come out identical by construction rather |
| 716 | /// than by hand: three hand-written copies in goingson's stylesheet is what |
| 717 | /// phase A deletes, and generating them from one call is what stops them |
| 718 | /// drifting apart again. |
| 719 | |
| 720 | let mut css = Stringnew; |
| 721 | for name in |
| 722 | let c = class; |
| 723 | css.push_str; |
| 724 | css.push_str; |
| 725 | |
| 726 | |
| 727 | let field = class; |
| 728 | css.push_str; |
| 729 | |
| 730 | // A field takes focus and refuses input like everything else here, and got |
| 731 | // neither until now, which is why all three apps hand-write a focus ring |
| 732 | // for it and no two of them match. No hover or pressed: a text field does |
| 733 | // not light up under the pointer and does not invert when clicked, so the |
| 734 | // two states `interactive_rules` would add are the two it does not have. |
| 735 | css.push_str; |
| 736 | css.push_str; |
| 737 | |
| 738 | // Keyed on the ARIA attribute rather than on a class, so the visual state |
| 739 | // and the accessible state cannot drift apart: there is one fact and both |
| 740 | // read it. goingson already drove its invalid styling this way and was |
| 741 | // right to; the `.invalid` class this emitted before 0.5.0 was a second |
| 742 | // place to forget. |
| 743 | // |
| 744 | // The ring composes *after* the bevel rather than replacing it. box-shadow |
| 745 | // is not additive, so a lone ring silently dropped the well out from under |
| 746 | // an invalid field. Flat and unlit: this edge is saying "wrong", and |
| 747 | // lighting one side would have it say "raised" at the same time. |
| 748 | let _ = writeln! |
| 749 | css, |
| 750 | ".{field}[aria-invalid=\"true\"] {{\n box-shadow: var({}), 0 0 0 {} var(--danger);\n}}" |
| 751 | bevel_var, |
| 752 | opts.border_width |
| 753 | ); |
| 754 | css |
| 755 | |
| 756 | |
| 757 | /// Badges and chips. |
| 758 | /// |
| 759 | /// The one place phase A changes how goingson looks rather than only where its |
| 760 | /// rules live. [`Token::Badge`] is [`Depth::Flat`], so a badge emits no fill |
| 761 | /// and no edge at all, where goingson ships `.tag, .badge` as a single rule |
| 762 | /// carrying the raised bevel. Splitting that means reading every call site to |
| 763 | /// decide which of the two it always was. |
| 764 | /// |
| 765 | /// What a badge does carry is a [`Tone`], the intent family it shares with |
| 766 | /// notices and nothing else. Neutral is the bare class rather than a variant, |
| 767 | /// because it is the absence of a status and not a status called "none". |
| 768 | /// Text that goes somewhere. |
| 769 | /// |
| 770 | /// The one inline control, and the vocabulary had no word for it until a |
| 771 | /// description layer needed one. A table cell has carried `cell-link` since |
| 772 | /// 0.14.0's part list, deliberately unruled because the cell's own rule covers |
| 773 | /// it; what was missing is the same thing outside a table, which is what a |
| 774 | /// described run holds when a sentence contains a link. |
| 775 | /// |
| 776 | /// Colour and underline only. Whether a link is inline in a sentence or sitting |
| 777 | /// on its own line is the app's layout, and how much room it takes is |
| 778 | /// `makeover-geometry`'s. What is here is the pair of signals that say "this |
| 779 | /// goes somewhere" and nothing that says where it sits. |
| 780 | /// |
| 781 | /// The visited arm is deliberately absent. A link inside an app points at the |
| 782 | /// app's own screens, which the user is expected to have been to, so painting |
| 783 | /// them differently marks almost everything and distinguishes nothing. |
| 784 | |
| 785 | let mut css = Stringnew; |
| 786 | let link = class; |
| 787 | |
| 788 | let _ = writeln! |
| 789 | css, |
| 790 | ".{link} {{\n color: var(--action);\n \ |
| 791 | text-decoration: underline;\n}}" |
| 792 | ; |
| 793 | // The hover step is the same one every other control takes, and it is a |
| 794 | // colour rather than a surface: a link has no box to raise. |
| 795 | let _ = writeln! |
| 796 | css, |
| 797 | "@media (hover: hover) and (pointer: fine) {{\n .{link}:hover \ |
| 798 | {{\n color: var(--action-hover);\n }}\n}}" |
| 799 | ; |
| 800 | let _ = writeln! |
| 801 | css, |
| 802 | ".{link}:focus-visible {{\n outline: {} solid var(--focus-ring);\n \ |
| 803 | outline-offset: 2px;\n}}" |
| 804 | opts.focus_width |
| 805 | ); |
| 806 | // A link is often a `<button>` rather than an `<a>`: a renderer picks the |
| 807 | // element from the method, so a link that writes is a button that has to |
| 808 | // stop looking like one. |
| 809 | let _ = writeln! |
| 810 | css, |
| 811 | "button.{link} {{\n background: none;\n border: none;\n \ |
| 812 | padding: 0;\n font: inherit;\n cursor: pointer;\n}}" |
| 813 | ; |
| 814 | css |
| 815 | |
| 816 | |
| 817 | |
| 818 | let mut css = Stringnew; |
| 819 | |
| 820 | // No `depth_rule` call here, deliberately: `Token::Badge.depth(_)` is Flat, |
| 821 | // and a label with an edge says it can be pressed. |
| 822 | let badge = class; |
| 823 | let _ = writeln! |
| 824 | css, |
| 825 | ".{badge} {{\n color: var(--{});\n}}" |
| 826 | Neutral.token |
| 827 | ); |
| 828 | for tone in |
| 829 | let _ = writeln! |
| 830 | css, |
| 831 | ".{badge}[data-tone=\"{0}\"] {{\n color: var(--{0});\n}}" |
| 832 | tone.token |
| 833 | ); |
| 834 | |
| 835 | |
| 836 | // A button carries the four tones a badge does. It had none, on the reading |
| 837 | // that a control's colour is its surface rather than its text, and that |
| 838 | // reading has one hole big enough to matter: the button that destroys |
| 839 | // something. Every consumer had written that rule itself, and a description |
| 840 | // that says `Tone::Danger` on an act had nowhere for it to land. |
| 841 | // |
| 842 | // Colour and not a fill, matching the badge. A red surface is a decision |
| 843 | // about emphasis that belongs to an app's own layer, and two of them |
| 844 | // fighting is worse than neither. |
| 845 | let button = class; |
| 846 | for tone in |
| 847 | let _ = writeln! |
| 848 | css, |
| 849 | ".{button}[data-tone=\"{0}\"] {{\n color: var(--{0});\n}}" |
| 850 | tone.token |
| 851 | ); |
| 852 | |
| 853 | |
| 854 | // A chip holds itself down, which is `Depth::pressed` arrived at |
| 855 | // independently by two apps. `removable` is a remove affordance, so it is |
| 856 | // markup and waits for phase B. |
| 857 | let chip = class; |
| 858 | let unlatched = Chip ; |
| 859 | css.push_str; |
| 860 | css.push_str; |
| 861 | css.push_str |
| 862 | &format!, |
| 863 | unlatched.depth, |
| 864 | ; |
| 865 | css |
| 866 | |
| 867 | |
| 868 | /// The three selectors, each named by what it picks. |
| 869 | /// |
| 870 | /// A tab comes *forward* to join the pane it opens, which is why |
| 871 | /// [`Selector::Tabs`] chooses [`Depth::Raised`] where a segment and a toggle |
| 872 | /// are held in. That is the folder semantic, and it is the whole reason the |
| 873 | /// three are not one member with a flag. |
| 874 | /// |
| 875 | /// [`Selector::abutting`] is not emitted: whether the options touch is |
| 876 | /// spacing, and spacing is `makeover-geometry`'s question to answer. |
| 877 | /// |
| 878 | /// Both states emit as of makeover-layout 0.3.0. Before it the description |
| 879 | /// named only the chosen option, so an unchosen one fell through to |
| 880 | /// [`Depth::Flat`] and nothing was drawn for it, which left goingson's tab |
| 881 | /// strip hand-writing the recess that makes its chosen tab read as forward. |
| 882 | |
| 883 | let mut css = Stringnew; |
| 884 | for selector in |
| 885 | let c = class; |
| 886 | css.push_str; |
| 887 | css.push_str; |
| 888 | css.push_str; |
| 889 | |
| 890 | css |
| 891 | |
| 892 | |
| 893 | /// The parts of a list row. |
| 894 | /// |
| 895 | /// The list is written out rather than derived because `RowPart` is |
| 896 | /// `#[non_exhaustive]` as of makeover-layout 0.9.0, so there is nothing to |
| 897 | /// iterate. A member added upstream emits no rule until it is named here, which |
| 898 | /// is the trade `non_exhaustive` makes: a silent gap instead of a build break. |
| 899 | /// [`part_class`] carries the same list and the same obligation. |
| 900 | |
| 901 | let mut css = Stringnew; |
| 902 | |
| 903 | // The container the rows sit in. Three zeroes and a keyword, all of them |
| 904 | // undoing a browser default the description never asked for: a described |
| 905 | // list of SSH keys is not a bulleted list, and it rendered as one because |
| 906 | // nothing here said otherwise. Not a size: there is no magnitude in it, |
| 907 | // which is the line this crate holds. |
| 908 | let _ = writeln! |
| 909 | css, |
| 910 | ".{} {{\n list-style: none;\n margin: 0;\n padding: 0;\n}}" |
| 911 | class |
| 912 | ); |
| 913 | |
| 914 | for part in |
| 915 | Primary, |
| 916 | Secondary, |
| 917 | Meta, |
| 918 | Actions, |
| 919 | Tokens, |
| 920 | Proportion, |
| 921 | ] |
| 922 | let c = class; |
| 923 | |
| 924 | // Actions carry controls rather than text, and `RowPart::intent` says |
| 925 | // so by returning the same intent inheriting already gives. Pinning it |
| 926 | // would be louder than saying nothing. Tokens answer alike, for their |
| 927 | // own reason: each token carries its own tone, and a colour on the |
| 928 | // strip would fight the things sitting in it. A proportion is the same |
| 929 | // case again: the meter inside carries the tone. |
| 930 | if !matches! |
| 931 | part, |
| 932 | Actions | Tokens | Proportion |
| 933 | |
| 934 | let _ = writeln!; |
| 935 | |
| 936 | |
| 937 | // A row's actions are shown at rest. `RowPart::revealed_on_hover` said |
| 938 | // otherwise and was not honoured here from 0.23.0; makeover-layout |
| 939 | // 0.13.0 retired the method, so there is no longer a description saying |
| 940 | // one thing and a renderer doing another. |
| 941 | // |
| 942 | // The rule was `opacity: 0` gated to pointer devices, revealed on |
| 943 | // `:hover` and on `:focus-within`. Each escape it needed was a report |
| 944 | // that hiding was wrong for somebody: `focus-within` because tabbing |
| 945 | // could never reach an action; the gate because a fingertip had no way |
| 946 | // to unhide, which both webview apps had already hand-written |
| 947 | // `opacity: 1` to undo. What was left was a control hidden from |
| 948 | // exactly one group: people using a pointer, who are also the group |
| 949 | // scanning a list to find out what can be done to a row. |
| 950 | // |
| 951 | // A settings screen is where that reads worst: the whole reason to be |
| 952 | // on it is to remove a key, and the button doing so was invisible |
| 953 | // until pointed at. A table cell's actions were never hidden, so the |
| 954 | // two arrangements now agree. |
| 955 | |
| 956 | css |
| 957 | |
| 958 | |
| 959 | /// The progress trough these rules fill. |
| 960 | /// |
| 961 | /// This was renderer-local chrome with nothing behind it until makeover-layout |
| 962 | /// 0.10.0, which is the unusual order: the tones below were emitted for every |
| 963 | /// bar in the tree while the only way to describe one was to concatenate the |
| 964 | /// numbers into a heading. `Meter` is the word that arrived late, and |
| 965 | /// [`meter::meter_html`](crate::meter::meter_html) is what now fills these. |
| 966 | /// |
| 967 | /// The rules stay a superset of what a description can ask for. An app drawing |
| 968 | /// its own bar keeps these classes, which is what the four goingson grew |
| 969 | /// independently were adopted onto. |
| 970 | /// |
| 971 | /// The trough is a [`Depth::Well`], the same reading a text field gets: |
| 972 | /// something with its content down inside it. |
| 973 | |
| 974 | let progress = class; |
| 975 | // `progress-fill` rather than a bare `fill`: an unprefixed build claims |
| 976 | // these names in the app's own stylesheet, and `.fill` is grabby enough to |
| 977 | // catch things that have nothing to do with progress. goingson already |
| 978 | // calls it `.progress-fill`, so this is also the name that deletes. |
| 979 | let fill = class; |
| 980 | let mut css = depth_rule; |
| 981 | |
| 982 | // The untoned bar is `--action`, not [`Tone::Neutral`]. That is the one |
| 983 | // place this differs from the badge rules, and deliberately: a badge with |
| 984 | // no status is a muted label, while a bar with no status is still |
| 985 | // reporting progress, and `content-muted` would read as disabled. |
| 986 | let _ = writeln! |
| 987 | css, |
| 988 | ".{progress} > .{fill} {{\n background: var(--action);\n}}" |
| 989 | ; |
| 990 | |
| 991 | // A bar can be saying something, same as a badge: goingson colours subtask |
| 992 | // progress as success and an over-estimate as danger, which is real |
| 993 | // information rather than decoration. Emitting the tones is what lets that |
| 994 | // survive adoption instead of staying hand-written. |
| 995 | for tone in |
| 996 | let _ = writeln! |
| 997 | css, |
| 998 | ".{progress} > .{fill}[data-tone=\"{0}\"] {{\n background: var(--{0});\n}}" |
| 999 | tone.token |
| 1000 | ); |
| 1001 | |
| 1002 | css |
| 1003 | |
| 1004 | |
| 1005 | /// A strip of figures, and the two spans inside each one. |
| 1006 | /// |
| 1007 | /// Colour only, which is the deferral rule applied to a component that badly |
| 1008 | /// wants to break it. A figure reads as a figure because the value is set large |
| 1009 | /// over a small caption, and that is a size: `makeover-geometry` answers how |
| 1010 | /// much space and this crate answers what the thing is. Emitting `font-size` |
| 1011 | /// here would be this crate naming a value, which is the one thing it is defined |
| 1012 | /// by not doing, and `progress_rules` is the precedent — it emits the tones and |
| 1013 | /// never the width, because the width is not its to know. |
| 1014 | /// |
| 1015 | /// So the arrangement and the type scale are the app's, and what is generated is |
| 1016 | /// the part an app cannot get right by itself: which of the two spans carries |
| 1017 | /// the tone. |
| 1018 | |
| 1019 | let figure = class; |
| 1020 | let value = class; |
| 1021 | let caption = class; |
| 1022 | let change = class; |
| 1023 | let mut css = Stringnew; |
| 1024 | |
| 1025 | let _ = writeln! |
| 1026 | css, |
| 1027 | ".{figure} > .{value} {{\n color: var(--{});\n}}" |
| 1028 | Neutral.token |
| 1029 | ); |
| 1030 | let _ = writeln! |
| 1031 | css, |
| 1032 | ".{figure} > .{caption} {{\n color: var(--content-muted);\n}}" |
| 1033 | ; |
| 1034 | let _ = writeln! |
| 1035 | css, |
| 1036 | ".{figure} > .{change} {{\n color: var(--content-muted);\n}}" |
| 1037 | ; |
| 1038 | |
| 1039 | // A toned figure tones one part and never the caption. The caption is the |
| 1040 | // noun and stays muted. |
| 1041 | // |
| 1042 | // Which part depends on whether there is a change, and that is the whole of |
| 1043 | // what 0.13.0 changed here. A figure with a delta is an ordinary number that |
| 1044 | // has moved in a direction worth reading, so the delta takes the colour and |
| 1045 | // the number stays plain; a figure without one has nowhere else to put it. |
| 1046 | // `:has` is what lets one attribute mean both, and the alternative was the |
| 1047 | // emitter deciding by writing the attribute onto a different element, which |
| 1048 | // leaves two elements able to disagree about a figure's one meaning. |
| 1049 | for tone in |
| 1050 | let _ = writeln! |
| 1051 | css, |
| 1052 | ".{figure}[data-tone=\"{0}\"] > .{change} {{\n color: var(--{0});\n}}" |
| 1053 | tone.token |
| 1054 | ); |
| 1055 | let _ = writeln! |
| 1056 | css, |
| 1057 | ".{figure}[data-tone=\"{0}\"]:not(:has(> .{change})) > .{value} \ |
| 1058 | {{\n color: var(--{0});\n}}" |
| 1059 | tone.token |
| 1060 | ); |
| 1061 | |
| 1062 | css |
| 1063 | |
| 1064 | |
| 1065 | /// A picture, its frame and its caption. |
| 1066 | /// |
| 1067 | /// `makeover_layout::Image` arrived at 0.21.0, found by trying to describe MNW's |
| 1068 | /// carousel and discovering nothing named a picture. |
| 1069 | /// |
| 1070 | /// # The frame is a border, and this is the one place a bevel is wrong |
| 1071 | /// |
| 1072 | /// 0.36.0 emitted [`Depth::Raised`] here through [`depth_rule`], the same call |
| 1073 | /// `button` and `card` make. It was wrong, and MNW's landing page is where it |
| 1074 | /// showed: **the frames had no visible edge at all.** |
| 1075 | /// |
| 1076 | /// `Depth::Raised`'s edge is `--bevel-raised`, which is an *inset* shadow — a |
| 1077 | /// 1px light run at the top-left and a dark one at the bottom-right, drawn |
| 1078 | /// **inside** the element's box. On a button or a card that box is a surface |
| 1079 | /// this crate owns, so an inset edge reads as the surface catching the light. |
| 1080 | /// On a picture it is drawn on top of the picture, over whatever pixels the |
| 1081 | /// image happens to have at its border. MNW's screenshots are light-on-light |
| 1082 | /// parchment, so the light half landed on a light image and the frame |
| 1083 | /// disappeared. |
| 1084 | /// |
| 1085 | /// **You cannot bevel a surface you do not own.** A picture's content is the |
| 1086 | /// app's, arrives at request time, and can be any colour, so its edge has to |
| 1087 | /// sit *outside* the content rather than on it. That is a border. |
| 1088 | /// |
| 1089 | /// The fill stays, and it is not decoration: it is what shows through a |
| 1090 | /// transparent PNG and what stands in the frame's place while the image is |
| 1091 | /// still loading. |
| 1092 | /// |
| 1093 | /// This is a real limit on [`Depth`] rather than a special case. Every other |
| 1094 | /// consumer of a depth draws its own surface; a picture is the first member |
| 1095 | /// whose surface belongs to someone else. |
| 1096 | /// |
| 1097 | /// # No size |
| 1098 | /// |
| 1099 | /// `width: 100%` and nothing else. How large a picture is depends on the box it |
| 1100 | /// was put in, which is the app's arrangement and `makeover-geometry`'s scales, |
| 1101 | /// and a renderer that picked one would be answering for every consumer at |
| 1102 | /// once. This is where `figure_rules` landed for the same reason. |
| 1103 | |
| 1104 | let picture = class; |
| 1105 | let img = class; |
| 1106 | let caption = class; |
| 1107 | let mut css = Stringnew; |
| 1108 | |
| 1109 | // Block, or an inline image sits on the text baseline and carries a |
| 1110 | // descender's worth of space under it that no app ever wants and every app |
| 1111 | // deletes by hand. The border is the frame; see the type docs for why it is |
| 1112 | // not the bevel every other surface here gets. |
| 1113 | let _ = writeln! |
| 1114 | css, |
| 1115 | ".{img} {{\n display: block;\n width: 100%;\n height: auto;\n \ |
| 1116 | background: var(--{});\n border: {} solid var(--border);\n}}" |
| 1117 | Raised.token, |
| 1118 | opts.border_width |
| 1119 | ); |
| 1120 | |
| 1121 | // The two fits that need a rule. `Fit::Natural` emits no attribute at all, |
| 1122 | // so it is the bare rule above and needs nothing here. |
| 1123 | let _ = writeln! |
| 1124 | css, |
| 1125 | ".{img}[data-fit=\"cover\"] {{\n height: 100%;\n object-fit: cover;\n}}" |
| 1126 | ; |
| 1127 | let _ = writeln! |
| 1128 | css, |
| 1129 | ".{img}[data-fit=\"contain\"] {{\n height: 100%;\n object-fit: contain;\n}}" |
| 1130 | ; |
| 1131 | |
| 1132 | // A caption reads back one step, which is `figure-caption`'s answer and the |
| 1133 | // same claim: it says what the thing above it is, and it is not the thing. |
| 1134 | let _ = writeln! |
| 1135 | css, |
| 1136 | ".{picture} > .{caption} {{\n color: var(--content-muted);\n}}" |
| 1137 | ; |
| 1138 | |
| 1139 | css |
| 1140 | |
| 1141 | |
| 1142 | /// A region showing one child at a time, and the chrome that moves between them. |
| 1143 | /// |
| 1144 | /// [`makeover_layout::Showing`] lets a description say that a region holds |
| 1145 | /// several children and shows some of them. A renderer derives its own chrome |
| 1146 | /// from that, which is what stops every renderer growing a `match` on a widget |
| 1147 | /// name; these are the rules the derived chrome needs. |
| 1148 | /// |
| 1149 | /// # Why the default is every child, and the enhancement takes them away |
| 1150 | /// |
| 1151 | /// The controls are a lie until something binds them. A prev button rendered |
| 1152 | /// into a document with no script is a control that looks live and answers |
| 1153 | /// nothing, and the reader it lies to is exactly the one who cannot see the |
| 1154 | /// other children either — the collapsing and the moving are the same half. |
| 1155 | /// |
| 1156 | /// So the rules run in the direction the enhancement does. Nothing here hides a |
| 1157 | /// child and nothing here shows a control. Whatever binds the region sets |
| 1158 | /// `data-ready` on it, and that is what collapses the stack to one and reveals |
| 1159 | /// the row that moves it. A reader with no script gets every child in order and |
| 1160 | /// no controls, which is more content rather than less, and a reader with |
| 1161 | /// script gets a settled page rather than a stack that jumps to one frame after |
| 1162 | /// load. |
| 1163 | /// |
| 1164 | /// MNW proved this shape by hand — a `<noscript>` stylesheet opening its |
| 1165 | /// carousel back out — and it is here rather than there because the property is |
| 1166 | /// the description's, not one app's. |
| 1167 | /// |
| 1168 | /// # Not spacing |
| 1169 | /// |
| 1170 | /// The row's gaps are `makeover-geometry`'s question and are absent for |
| 1171 | /// [`row_rules`]'s reason. What is here is `display`, which carries no |
| 1172 | /// magnitude, and the muted readout, which is the same claim `picture-caption` |
| 1173 | /// makes: it says where you are among the children and it is not one of them. |
| 1174 | |
| 1175 | let controls = class; |
| 1176 | let position = class; |
| 1177 | let frame = class; |
| 1178 | let mut css = Stringnew; |
| 1179 | |
| 1180 | // Hidden until something binds it, which is the whole argument above. |
| 1181 | let _ = writeln!; |
| 1182 | // Block, and nothing about how the three sit in it. A button and a span are |
| 1183 | // inline already, so they make a row without this crate saying so, and |
| 1184 | // saying so is where `align-items` and a gap would follow -- both spacing, |
| 1185 | // both `makeover-geometry`'s, and `row_rules` refuses them for the same |
| 1186 | // reason. |
| 1187 | let _ = writeln! |
| 1188 | css, |
| 1189 | "[data-ready] > .{controls} {{\n display: block;\n}}" |
| 1190 | ; |
| 1191 | |
| 1192 | // A child is in flow until the region is bound, and then only the current |
| 1193 | // one is. `.current` is a modifier for the reason `.chosen` and `.latched` |
| 1194 | // are: one name for the state, set by whoever knows it. |
| 1195 | let _ = writeln! |
| 1196 | css, |
| 1197 | "[data-ready] > .{frame}:not(.current) {{\n display: none;\n}}" |
| 1198 | ; |
| 1199 | |
| 1200 | // Reads back one step. `picture-caption`'s rule and its reason. |
| 1201 | let _ = writeln!; |
| 1202 | |
| 1203 | css |
| 1204 | |
| 1205 | |
| 1206 | /// A time axis: the container, its gridlines and ruler, and the placed things. |
| 1207 | /// |
| 1208 | /// `makeover-layout` 0.24.0's [`Track`](makeover_layout::Track), and the first |
| 1209 | /// member here whose whole point is *position*. That makes the magnitude line |
| 1210 | /// this crate keeps worth restating rather than assuming. |
| 1211 | /// |
| 1212 | /// # Where the numbers come from |
| 1213 | /// |
| 1214 | /// Every value that varies per item is a custom property the caller sets |
| 1215 | /// inline, and every rule here reads one. `--track-at` and `--track-for` are |
| 1216 | /// percentages of the span, which |
| 1217 | /// [`Track::fraction`](makeover_layout::Track::fraction) computes once so three |
| 1218 | /// renderers cannot disagree about it. Nothing here knows a pixel. |
| 1219 | /// |
| 1220 | /// That is what lets the stylesheet stay static while the items move: an entry |
| 1221 | /// carries `style="--track-at: 37.5%; --track-for: 4.166%"` and the rule below |
| 1222 | /// turns it into a box. The alternative was emitting a rule per item, which is |
| 1223 | /// a stylesheet that grows with the data. |
| 1224 | /// |
| 1225 | /// **The height of the track is the app's**, not this crate's. 96 quarter-hour |
| 1226 | /// slots at some slot height is a size, and a size is `makeover-geometry`'s |
| 1227 | /// question -- the same refusal `figure_rules` and `placeholder_rules` make. |
| 1228 | /// Percentages need a resolved height above them, so `.track` gets |
| 1229 | /// `position: relative` and nothing else; the app says how tall a day is. |
| 1230 | /// |
| 1231 | /// # Overlap |
| 1232 | /// |
| 1233 | /// Two things at the same time is intrinsic to an axis and has no analogue in a |
| 1234 | /// list. The description does not declare it -- `Placement::overlaps` derives it |
| 1235 | /// from the times -- so what arrives here is a lane index and a lane count, and |
| 1236 | /// the rule divides the width. A renderer that would rather stack them ignores |
| 1237 | /// both properties and the defaults give it one full-width lane. |
| 1238 | |
| 1239 | let track = class; |
| 1240 | let slot = class; |
| 1241 | let tick = class; |
| 1242 | let entry = class; |
| 1243 | let mut css = Stringnew; |
| 1244 | |
| 1245 | // The positioning context every entry resolves against, and the whole of |
| 1246 | // what this crate says about the container. No height: see the doc above. |
| 1247 | let _ = writeln!; |
| 1248 | |
| 1249 | // Gridlines and the ruler are the axis reading itself back, which is |
| 1250 | // `picture-caption` and `showing-position`'s claim: about the thing rather |
| 1251 | // than one of the things. |
| 1252 | // |
| 1253 | // `border_width` rather than a literal, the way `depth_rule` writes its |
| 1254 | // edge. A gridline is the one place a timeline would most naturally reach |
| 1255 | // for a hardcoded 1px, and a hardcoded 1px is this crate naming a size. |
| 1256 | let _ = writeln! |
| 1257 | css, |
| 1258 | ".{slot} {{\n border-top: {} solid var(--border);\n}}" |
| 1259 | opts.border_width |
| 1260 | ); |
| 1261 | let _ = writeln!; |
| 1262 | |
| 1263 | // The one rule that does real work. Top and height are the placement; |
| 1264 | // left and width are the lane. Both lane properties default so an entry |
| 1265 | // that names neither is full width, which is the common case and the one a |
| 1266 | // renderer gets for free. |
| 1267 | let _ = writeln! |
| 1268 | css, |
| 1269 | ".{entry} {{\n \ |
| 1270 | position: absolute;\n \ |
| 1271 | top: var(--track-at, 0%);\n \ |
| 1272 | height: var(--track-for, 100%);\n \ |
| 1273 | left: calc(var(--track-lane, 0) / var(--track-lanes, 1) * 100%);\n \ |
| 1274 | width: calc(100% / var(--track-lanes, 1));\n\ |
| 1275 | }}" |
| 1276 | ; |
| 1277 | |
| 1278 | css |
| 1279 | |
| 1280 | |
| 1281 | /// A region's stand-in, and the header of a table that can be reordered. |
| 1282 | /// |
| 1283 | /// Both are 0.12.0 members and both are colour and affordance only, which is |
| 1284 | /// where `figure_rules` landed after trying to emit a type scale. How much room |
| 1285 | /// a stand-in gets is a size — goingson has the same one at three, as |
| 1286 | /// `--compact`, `--dashboard` and `--padded` — and a size is |
| 1287 | /// `makeover-geometry`'s question. |
| 1288 | /// |
| 1289 | /// The caret is the one thing here that is neither colour nor affordance, and it |
| 1290 | /// is a renderer's own expression rather than a value the description named: |
| 1291 | /// `aria-sort` is what the table actually says, and this turns it into something |
| 1292 | /// visible for everyone not using a screen reader. A terminal draws its own; an |
| 1293 | /// immediate-mode painter draws its own. |
| 1294 | |
| 1295 | let placeholder = class; |
| 1296 | let text = class; |
| 1297 | let heading = class; |
| 1298 | let mut css = Stringnew; |
| 1299 | |
| 1300 | let _ = writeln! |
| 1301 | css, |
| 1302 | ".{placeholder} > .{text} {{\n color: var(--content-muted);\n}}" |
| 1303 | ; |
| 1304 | // Only the failure is toned. An empty list is the normal state of a new |
| 1305 | // install, and `Readiness::tone` is what says so. |
| 1306 | let _ = writeln! |
| 1307 | css, |
| 1308 | ".{placeholder}[data-tone=\"{0}\"] > .{text} {{\n color: var(--{0});\n}}" |
| 1309 | Danger.token |
| 1310 | ); |
| 1311 | |
| 1312 | // A header that reorders the table is a control, and the pointer is the |
| 1313 | // only part of saying so that is not the app's own type and spacing. |
| 1314 | let _ = writeln! |
| 1315 | css, |
| 1316 | ".{heading}[data-sortable] {{\n cursor: pointer;\n}}" |
| 1317 | ; |
| 1318 | // The caret carries its own leading space, the way `makeover-tui` and |
| 1319 | // `makeover-immediate` both write `" \u{25B2}"`. It used to be emitted bare, |
| 1320 | // and both apps that adopted the vocabulary had to put the gap back in their |
| 1321 | // own stylesheets on the same afternoon -- each having to work out first that |
| 1322 | // app CSS outranks this crate's cascade layer, so adding the space the |
| 1323 | // obvious way, as `content`, silently wins over the glyph and leaves the |
| 1324 | // heading with no caret at all. A consumer should not have to know that, and |
| 1325 | // with the space emitted here there is nothing left for one to add. |
| 1326 | // |
| 1327 | // Three states, three tones, on the convention in wiki |
| 1328 | // `three-tone-convention`. A column in force is `content`; a column offering |
| 1329 | // to reorder and not doing it now is `content-secondary`, because it still |
| 1330 | // answers a press; a column that is not sortable emits no caret at all and |
| 1331 | // takes nothing. The idle arm used to hide its glyph and reserve the box, |
| 1332 | // which cost a reflow-free press and said nothing. It draws now, and the |
| 1333 | // reservation stops being a thing to get right. |
| 1334 | // |
| 1335 | // The glyph is `Sort::glyph`, escaped rather than written: a CSS `content` |
| 1336 | // string cannot carry the character literally through this file's own |
| 1337 | // escaping, and spelling it here as well would put the third copy back that |
| 1338 | // `makeover-layout` 0.27.5 exists to remove. |
| 1339 | let _ = writeln! |
| 1340 | css, |
| 1341 | ".{heading}[data-sortable]::after \ |
| 1342 | {{\n content: \" {}\";\n color: var(--content-secondary);\n}}" |
| 1343 | css_escape |
| 1344 | ); |
| 1345 | for direction in |
| 1346 | let _ = writeln! |
| 1347 | css, |
| 1348 | ".{heading}[aria-sort=\"{}\"]::after \ |
| 1349 | {{\n content: \" {}\";\n color: var(--content);\n}}" |
| 1350 | direction.as_str, |
| 1351 | css_escape |
| 1352 | ); |
| 1353 | |
| 1354 | css |
| 1355 | |
| 1356 | |
| 1357 | /// The frame a table sits in. |
| 1358 | /// |
| 1359 | /// # Why this is a CSS table and not the grid the rest of the module assumes |
| 1360 | /// |
| 1361 | /// A grid row needs `grid-template-columns`, which has to name every column in |
| 1362 | /// order, so it cannot be written without knowing the columns. That is what |
| 1363 | /// [`list::narrowing_css`] is for, and it works: goingson builds `tables.css` in |
| 1364 | /// its own `build.rs` out of it, and nothing here changes that. |
| 1365 | /// |
| 1366 | /// It does not work for a table a *description* produced. Those columns are |
| 1367 | /// known at render time rather than at build time, and the rules would have to |
| 1368 | /// travel with the markup: a `<style>` element per table, which needs |
| 1369 | /// `style-src 'unsafe-inline'` and so blocks the MNW server's standing plan to |
| 1370 | /// drop it. The head is not an escape: a table swapped in by htmx after a |
| 1371 | /// delete arrives as a fragment with no head at all. |
| 1372 | /// |
| 1373 | /// A CSS table aligns its columns across rows knowing nothing about how many |
| 1374 | /// there are, so there is no track list to emit and nothing per-table to carry. |
| 1375 | /// The cost is that a described table cannot take a per-column fixed length, |
| 1376 | /// which costs nothing today: [`Sizing`](list::Sizing) is looked up by column |
| 1377 | /// name and a description carries no lengths to put in it, so every track a |
| 1378 | /// described table could ask for is already content, fill or auto. |
| 1379 | /// |
| 1380 | /// [`Priority`] hiding is unchanged in kind. It moves from a generated |
| 1381 | /// `display: none` per dropped column to one rule per drop class, which is the |
| 1382 | /// same fact addressed by class rather than by cutoff, and still never by |
| 1383 | /// position. |
| 1384 | |
| 1385 | let table = class; |
| 1386 | let head = class; |
| 1387 | let row = class; |
| 1388 | let heading = class; |
| 1389 | let cell = class; |
| 1390 | let mut css = Stringnew; |
| 1391 | |
| 1392 | let _ = writeln! |
| 1393 | css, |
| 1394 | ".{table} {{\n display: table;\n width: 100%;\n}}" |
| 1395 | ; |
| 1396 | let _ = writeln!; |
| 1397 | let _ = writeln!; |
| 1398 | |
| 1399 | // A content column shrinks to what is in it. `width: 1%` is how a CSS table |
| 1400 | // is told that: auto layout hands the slack to the columns that asked for |
| 1401 | // room, and a column asking for almost none gets what it needs and no more. |
| 1402 | // The `nowrap` is what stops it being given less by wrapping. |
| 1403 | let _ = writeln! |
| 1404 | css, |
| 1405 | ".{} {{\n white-space: nowrap;\n width: 1%;\n}}" |
| 1406 | class |
| 1407 | ); |
| 1408 | |
| 1409 | // A fixed column has no length to be fixed to. The description carries none |
| 1410 | // and `Sizing` is not reachable from here, so it behaves as content: the |
| 1411 | // honest answer to a width nobody supplied, and the same one `Sizing::track` |
| 1412 | // gives it. |
| 1413 | let _ = writeln! |
| 1414 | css, |
| 1415 | ".{} {{\n white-space: nowrap;\n}}" |
| 1416 | class |
| 1417 | ); |
| 1418 | |
| 1419 | // Optional columns go at the narrowest class, secondary ones go with them, |
| 1420 | // which is the cutoff walk `kept_at` describes said as two media queries. |
| 1421 | // Essential columns have no rule at all, because never dropping is what not |
| 1422 | // being mentioned already means. |
| 1423 | for in |
| 1424 | |
| 1425 | Compact, |
| 1426 | &, |
| 1427 | , |
| 1428 | , |
| 1429 | ] |
| 1430 | let selectors: = drops |
| 1431 | .iter |
| 1432 | .map |
| 1433 | .collect; |
| 1434 | css.push_str |
| 1435 | Some, |
| 1436 | &format!, |
| 1437 | ; |
| 1438 | |
| 1439 | |
| 1440 | // What is inside a cell, which the table side could not say until |
| 1441 | // makeover-layout 0.14.0. Every cell was one `.cell` and one content |
| 1442 | // colour, so a button in a cell was painted as text -- the drift |
| 1443 | // `RowPart::intent` has prevented for list rows since 0.2.0 and prevented |
| 1444 | // for nothing here. |
| 1445 | // |
| 1446 | // The colour goes on `.cell-value` rather than on `.cell`, and that |
| 1447 | // placement is the whole fix. On the container it would cascade into the |
| 1448 | // tokens and the controls sitting beside the text, which is the bug said |
| 1449 | // in one rule; on the part that is text, it reaches text and stops. |
| 1450 | for part in |
| 1451 | Value, |
| 1452 | Tokens, |
| 1453 | Actions, |
| 1454 | Link, |
| 1455 | ] |
| 1456 | // Three of the four inherit, each for its own reason: a token carries |
| 1457 | // its own tone, an action is a control rather than text, and a link |
| 1458 | // takes the action colour from the anchor it is. `CellPart::intent` |
| 1459 | // says so by answering with the intent inheriting already gives, and |
| 1460 | // pinning that would be louder than saying nothing. |
| 1461 | // |
| 1462 | // Written as a skip-list rather than as a match on Value, so a member |
| 1463 | // added upstream gets its intent emitted rather than being silently |
| 1464 | // dropped. That is the same trade `part_class`'s fallback makes: land |
| 1465 | // plainly, never land as nothing. |
| 1466 | if !matches! |
| 1467 | let _ = writeln! |
| 1468 | css, |
| 1469 | ".{} {{\n color: var(--{});\n}}" |
| 1470 | class, |
| 1471 | part.intent |
| 1472 | ); |
| 1473 | |
| 1474 | |
| 1475 | |
| 1476 | css |
| 1477 | |
| 1478 | |
| 1479 | /// The component layer: every named thing phase A emits. |
| 1480 | /// |
| 1481 | /// No scrollbar track. It was on the phase A list and came off: eight lines of |
| 1482 | /// `::-webkit-scrollbar` with no shape a terminal or an immediate-mode painter |
| 1483 | /// would want handed to it, so it stays with the apps. |
| 1484 | |
| 1485 | |
| 1486 | let mut css = Stringnew; |
| 1487 | css.push_str; |
| 1488 | css.push_str; |
| 1489 | css.push_str; |
| 1490 | css.push_str; |
| 1491 | css.push_str; |
| 1492 | css.push_str; |
| 1493 | css.push_str; |
| 1494 | css.push_str; |
| 1495 | css.push_str; |
| 1496 | css.push_str; |
| 1497 | css.push_str; |
| 1498 | css.push_str; |
| 1499 | css |
| 1500 | |
| 1501 | |
| 1502 | /// The whole phase-A stylesheet: properties, depth rules and components, in |
| 1503 | /// [`CSS_LAYER`], under a generated-file banner. |
| 1504 | /// |
| 1505 | /// The banner sits outside the layer, because a comment participates in no |
| 1506 | /// cascade and a reader opening the file should see what it is before seeing |
| 1507 | /// an at-rule. |
| 1508 | |
| 1509 | |
| 1510 | format! |
| 1511 | "/* Generated by makeover-webview from makeover-layout. Do not edit.\n \ |
| 1512 | Depth is a fill and an edge together; naming them apart is what let\n \ |
| 1513 | them disagree. See the crate's README and wiki note makeover-layout.\n\n \ |
| 1514 | Everything below is in the `{CSS_LAYER}` cascade layer. Declare the\n \ |
| 1515 | order once in your own stylesheet, or this layer's position is decided\n \ |
| 1516 | by whichever generated file the browser happens to see first:\n\n \ |
| 1517 | @layer {CSS_LAYER}, base, components, responsive; */\n{}" |
| 1518 | in_css_layer |
| 1519 | ":root {{\n{}}}\n\n{}\n{}" |
| 1520 | bevel_properties, |
| 1521 | depth_rules, |
| 1522 | component_rules |
| 1523 | ) |
| 1524 | ) |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | use *; |
| 1530 | use Edge; |
| 1531 | |
| 1532 | |
| 1533 | |
| 1534 | // Balanced Breakfast's styles.css, verbatim. Adoption has to be a |
| 1535 | // deletion, not a redesign, or nobody will take it. |
| 1536 | let opts = default; |
| 1537 | assert_eq! |
| 1538 | bevel_shadow, |
| 1539 | "inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark)" |
| 1540 | ; |
| 1541 | assert_eq! |
| 1542 | bevel_shadow, |
| 1543 | "inset 1px 1px 0 var(--bevel-dark), inset -1px -1px 0 var(--bevel-light)" |
| 1544 | ; |
| 1545 | |
| 1546 | |
| 1547 | |
| 1548 | |
| 1549 | let css = stylesheet; |
| 1550 | assert!; |
| 1551 | assert! |
| 1552 | !css.contains, |
| 1553 | "a colour function escaped into the CSS" |
| 1554 | ; |
| 1555 | // Every colour is named, never resolved. |
| 1556 | assert!; |
| 1557 | assert!; |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | assert_eq! |
| 1563 | fill_var, |
| 1564 | "var(--surface-well, var(--surface-page))" |
| 1565 | ; |
| 1566 | // Nothing else needs one. |
| 1567 | assert_eq!; |
| 1568 | assert_eq!; |
| 1569 | |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | let css = depth_rules; |
| 1574 | assert!; |
| 1575 | assert!; |
| 1576 | assert!; |
| 1577 | assert!; |
| 1578 | |
| 1579 | |
| 1580 | /// The cast shadow is composed here from the tone `makeover` derives, so |
| 1581 | /// neither crate has to hold the other's numbers. |
| 1582 | /// |
| 1583 | /// It is a `:root` property and deliberately not a depth class. There is no |
| 1584 | /// `Depth::Overlay` in the description layer, and adding one would be a |
| 1585 | /// claim about what a screen means rather than about how it is painted; |
| 1586 | /// until something asks for it, a consumer names the property on the rule |
| 1587 | /// for the menu or the toast it already has. |
| 1588 | |
| 1589 | |
| 1590 | let css = bevel_properties; |
| 1591 | assert!; |
| 1592 | assert!; |
| 1593 | assert! |
| 1594 | !depth_rules.contains, |
| 1595 | "elevation is not a depth class" |
| 1596 | ; |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | |
| 1601 | let css = surface_rules; |
| 1602 | // The one thing this renderer gets free that the other two resolve by |
| 1603 | // hand, eighteen call sites deep in audiofiles' case. Asserted on a |
| 1604 | // named surface: pressing belongs to the control, not to the depth. |
| 1605 | assert!; |
| 1606 | assert!; |
| 1607 | |
| 1608 | |
| 1609 | |
| 1610 | |
| 1611 | let css = depth_rules; |
| 1612 | // The static surface the vocabulary was missing. Sixteen goingson |
| 1613 | // elements wore .card and cancelled its hover and press to get this, |
| 1614 | // because a raised object that is not pressable had no other spelling. |
| 1615 | for state in |
| 1616 | assert! |
| 1617 | !css.contains, |
| 1618 | "the depth class claimed {state}: {css}" |
| 1619 | ; |
| 1620 | |
| 1621 | assert!; |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | // The decision-1 guard, and the regression that mattered: emitting the |
| 1627 | // bevel flip alone is what left goingson hand-writing `background: |
| 1628 | // var(--surface-sunken)` on .btn, .card and .tag/.badge alike, so none |
| 1629 | // of the three could be deleted. |
| 1630 | let pressed = interactive_rules; |
| 1631 | assert!; |
| 1632 | assert! |
| 1633 | pressed.contains, |
| 1634 | "pressed dropped its fill: {pressed}" |
| 1635 | ; |
| 1636 | assert!; |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | // goingson presses to --surface-sunken. The description says a pressed |
| 1642 | // raised region reads as a well, and makeover says outright that |
| 1643 | // surface-sunken cannot serve as one, so the app is the thing that |
| 1644 | // moves. |
| 1645 | // |
| 1646 | // Scoped to the pressed rules rather than to the whole sheet: since |
| 1647 | // makeover-layout 0.3.0 an unchosen tab is legitimately |
| 1648 | // --surface-sunken, so the token appearing somewhere in the output no |
| 1649 | // longer means the app's choice leaked in. |
| 1650 | let css = stylesheet; |
| 1651 | let mut checked = 0; |
| 1652 | for rule in css.split |
| 1653 | if !rule.contains |
| 1654 | continue; |
| 1655 | |
| 1656 | checked += 1; |
| 1657 | assert! |
| 1658 | !rule.contains, |
| 1659 | "a pressed rule took the app's fill: {rule}" |
| 1660 | ; |
| 1661 | |
| 1662 | assert!; |
| 1663 | assert_eq! |
| 1664 | Raised.pressed.fill, |
| 1665 | Some, |
| 1666 | "the description changed under us" |
| 1667 | ; |
| 1668 | |
| 1669 | |
| 1670 | |
| 1671 | |
| 1672 | // The point of 0.11.0. Unlayered normal declarations outrank every |
| 1673 | // named layer, so an app declaring `@layer base, components` loses |
| 1674 | // every rule it owns to this file until this file is layered too. |
| 1675 | let css = stylesheet; |
| 1676 | assert!; |
| 1677 | |
| 1678 | // Exactly one layer block, and nothing outside it but the banner. |
| 1679 | assert_eq!; |
| 1680 | let opened = css.find.expect; |
| 1681 | for in css.lines.enumerate |
| 1682 | let before_layer = css.lines.take.map. < opened; |
| 1683 | if before_layer || line.is_empty |
| 1684 | continue; |
| 1685 | |
| 1686 | assert! |
| 1687 | line.starts_with || line == "}" || line.starts_with, |
| 1688 | "line outside the layer: {line:?}" |
| 1689 | ; |
| 1690 | |
| 1691 | |
| 1692 | |
| 1693 | |
| 1694 | |
| 1695 | // A checked-in generated file that a formatter wants to rewrite is a |
| 1696 | // diff every time somebody saves it. |
| 1697 | let css = stylesheet; |
| 1698 | for in css.lines.enumerate |
| 1699 | assert_eq!; |
| 1700 | |
| 1701 | |
| 1702 | |
| 1703 | |
| 1704 | |
| 1705 | // Without a declared order the layer's position depends on which |
| 1706 | // generated file the browser sees first, which is not a contract. |
| 1707 | let css = stylesheet; |
| 1708 | assert!; |
| 1709 | // And the banner is outside the layer, not a rule inside it. |
| 1710 | assert!; |
| 1711 | |
| 1712 | |
| 1713 | |
| 1714 | |
| 1715 | // The whole point of 0.10.0. Anything emitting a hover rule owes the |
| 1716 | // other three, or the consuming app supplies them by out-specifying a |
| 1717 | // rule it does not own: 19 such rules in goingson, 21 in the MNW |
| 1718 | // server, and three focus rings that do not match. |
| 1719 | let css = stylesheet; |
| 1720 | for selector in |
| 1721 | assert!; |
| 1722 | assert! |
| 1723 | css.contains, |
| 1724 | "{selector}" |
| 1725 | ; |
| 1726 | assert! |
| 1727 | css.contains, |
| 1728 | "{selector} has no focus ring" |
| 1729 | ; |
| 1730 | assert! |
| 1731 | css.contains, |
| 1732 | "{selector} has no disabled state" |
| 1733 | ; |
| 1734 | |
| 1735 | |
| 1736 | |
| 1737 | |
| 1738 | |
| 1739 | // A text field does not light up under the pointer, so it gets the two |
| 1740 | // states it has and not the two it does not. |
| 1741 | let css = stylesheet; |
| 1742 | assert!; |
| 1743 | assert!; |
| 1744 | assert!; |
| 1745 | assert!; |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | |
| 1750 | // Every one of these selectors is specificity (0,2,0), so nothing but |
| 1751 | // order decides which wins. A disabled button taking the hover fill is |
| 1752 | // the exact bug goingson's `.button:disabled:hover` was written to fix, |
| 1753 | // and the reason it had to reach (0,3,0) to do it. |
| 1754 | let css = interactive_rules; |
| 1755 | let hover = css.find.expect; |
| 1756 | let active = css.find.expect; |
| 1757 | let focus = css.find.expect; |
| 1758 | let disabled = css.find.expect; |
| 1759 | assert!; |
| 1760 | |
| 1761 | // And it restores the surface, or the hover fill survives underneath. |
| 1762 | let tail = &css; |
| 1763 | assert!; |
| 1764 | |
| 1765 | |
| 1766 | |
| 1767 | |
| 1768 | // `:disabled` matches form elements only, and a chip is a div. Keying |
| 1769 | // on the ARIA attribute too is the pattern the invalid field already |
| 1770 | // set: one fact, read by the styling and the accessibility tree alike. |
| 1771 | let css = disabled_rule; |
| 1772 | assert!; |
| 1773 | assert!; |
| 1774 | assert!; |
| 1775 | |
| 1776 | |
| 1777 | |
| 1778 | |
| 1779 | // `outline` has its own property, so unlike the invalid ring there is |
| 1780 | // no bevel to restate beside it and nothing to keep in agreement. |
| 1781 | let opts = default; |
| 1782 | let css = focus_rule; |
| 1783 | assert!; |
| 1784 | assert!; |
| 1785 | |
| 1786 | |
| 1787 | |
| 1788 | |
| 1789 | // One ring, placed by depth. The offset comes off `Depth::bevel` and |
| 1790 | // not off a per-component choice, which is what gave three apps three |
| 1791 | // different rings. |
| 1792 | let opts = default; |
| 1793 | assert!; |
| 1794 | assert!; |
| 1795 | // Nothing to sit inside of, so it sits outside. |
| 1796 | assert!; |
| 1797 | |
| 1798 | // And the ring is not the bevel. Reusing border_width emitted a 1px |
| 1799 | // ring that every consumer had already overridden. |
| 1800 | assert_ne!; |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | |
| 1805 | // goingson's section 60 exists only to take back the hover state this |
| 1806 | // crate handed it. Gating at the source is what deletes that section |
| 1807 | // in all three apps rather than having each fight for it. |
| 1808 | let css = stylesheet; |
| 1809 | let condition = format!; |
| 1810 | assert!; |
| 1811 | |
| 1812 | // What is gated is every hover state the surfaces carry. The row's |
| 1813 | // actions used to be the other half of this test and are not gated any |
| 1814 | // more, because they are not hidden any more: a rule that reveals |
| 1815 | // nothing needs no capability answer. |
| 1816 | let gated: = css.lines.filter.collect; |
| 1817 | assert!; |
| 1818 | for line in gated |
| 1819 | let indent = line.len - line.trim_start.len; |
| 1820 | assert!; |
| 1821 | |
| 1822 | assert!; |
| 1823 | |
| 1824 | |
| 1825 | |
| 1826 | |
| 1827 | // Both halves come from the crates that own them. If `makeover-touch` |
| 1828 | // ever says a fingertip has hover, this stops gating on its own. |
| 1829 | assert!; |
| 1830 | assert!; |
| 1831 | assert_eq!; |
| 1832 | |
| 1833 | // And the size class passed to that call is not a claim about width. |
| 1834 | assert!; |
| 1835 | for size in |
| 1836 | assert!; |
| 1837 | |
| 1838 | |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | let css = interactive_rules; |
| 1843 | assert!; |
| 1844 | assert!; |
| 1845 | // Not the app's choice, which was --surface-overlay. |
| 1846 | assert!; |
| 1847 | |
| 1848 | |
| 1849 | |
| 1850 | |
| 1851 | // Decision 2, and the one visible redesign in phase A. Token::Badge is |
| 1852 | // Flat: an edge on a label says it can be pressed. |
| 1853 | let css = token_rules; |
| 1854 | let badge = css |
| 1855 | .lines |
| 1856 | .skip_while |
| 1857 | .take_while |
| 1858 | . |
| 1859 | .join; |
| 1860 | assert!; |
| 1861 | assert!; |
| 1862 | assert_eq!; |
| 1863 | assert_eq!; |
| 1864 | |
| 1865 | |
| 1866 | |
| 1867 | |
| 1868 | let css = token_rules; |
| 1869 | // Neutral is the absence of a status, not a status named "none". |
| 1870 | assert!; |
| 1871 | assert!; |
| 1872 | for tone in |
| 1873 | assert! |
| 1874 | css.contains, |
| 1875 | "missing tone {tone}" |
| 1876 | ; |
| 1877 | assert!; |
| 1878 | |
| 1879 | |
| 1880 | |
| 1881 | |
| 1882 | |
| 1883 | let css = token_rules; |
| 1884 | assert!; |
| 1885 | assert!; |
| 1886 | assert!; |
| 1887 | // The whole difference from a badge: it answers a click. |
| 1888 | assert!; |
| 1889 | assert!; |
| 1890 | |
| 1891 | |
| 1892 | |
| 1893 | |
| 1894 | // The folder semantic. Collapsing the three selectors would lose it. |
| 1895 | let css = selector_rules; |
| 1896 | assert!; |
| 1897 | assert!; |
| 1898 | assert!; |
| 1899 | assert_eq!; |
| 1900 | assert_eq!; |
| 1901 | assert_eq!; |
| 1902 | |
| 1903 | let tab = css |
| 1904 | .lines |
| 1905 | .skip_while |
| 1906 | .take_while |
| 1907 | . |
| 1908 | .join; |
| 1909 | assert! |
| 1910 | tab.contains, |
| 1911 | "tab was held in: {tab}" |
| 1912 | ; |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 | let css = selector_rules; |
| 1918 | // Recessed by colour and given no edge. An edge would make every option |
| 1919 | // look picked; flat would leave the chosen one nothing to come forward |
| 1920 | // from, which is the gap makeover-layout 0.3.0 closed. |
| 1921 | assert! |
| 1922 | css.contains, |
| 1923 | "unchosen tab is not recessed: {css}" |
| 1924 | ; |
| 1925 | assert_eq!; |
| 1926 | assert!; |
| 1927 | |
| 1928 | |
| 1929 | |
| 1930 | |
| 1931 | // The inverse of the tab, and why the three selectors are not one |
| 1932 | // member with a flag. |
| 1933 | let css = selector_rules; |
| 1934 | assert!; |
| 1935 | assert_eq!; |
| 1936 | assert_eq!; |
| 1937 | |
| 1938 | |
| 1939 | |
| 1940 | |
| 1941 | let css = row_rules; |
| 1942 | |
| 1943 | // The hover reveal is gone, and with it every escape it needed. What |
| 1944 | // it hid was hidden from pointer users alone, who are the ones |
| 1945 | // scanning a list to learn what can be done to a row. |
| 1946 | assert!; |
| 1947 | assert!; |
| 1948 | assert!; |
| 1949 | assert!; |
| 1950 | |
| 1951 | // Nor is it hidden any other way. `display: none` would reflow the row |
| 1952 | // and `visibility: hidden` would take the actions out of the focus |
| 1953 | // order; the point is that neither is reached for. |
| 1954 | assert!; |
| 1955 | assert!; |
| 1956 | |
| 1957 | |
| 1958 | |
| 1959 | |
| 1960 | // 0.13.0. The delta is the part that reads as good or bad; the number |
| 1961 | // itself is an ordinary fact. A figure with no delta has nowhere else to |
| 1962 | // put the colour, so the value takes it, and `:has` is what lets one |
| 1963 | // attribute mean both without the emitter choosing an element. |
| 1964 | let css = stylesheet; |
| 1965 | |
| 1966 | assert! |
| 1967 | css.contains, |
| 1968 | "{css}" |
| 1969 | ; |
| 1970 | assert! |
| 1971 | css.contains |
| 1972 | ".figure[data-tone=\"success\"]:not(:has(> .figure-change)) > .figure-value" |
| 1973 | , |
| 1974 | "{css}" |
| 1975 | ; |
| 1976 | // The caption is the noun and never takes the tone. |
| 1977 | assert! |
| 1978 | !css.contains, |
| 1979 | "{css}" |
| 1980 | ; |
| 1981 | |
| 1982 | |
| 1983 | |
| 1984 | |
| 1985 | let css = row_rules; |
| 1986 | assert!; |
| 1987 | assert!; |
| 1988 | assert!; |
| 1989 | // Actions carry controls, not text. Pinning the colour it would inherit |
| 1990 | // anyway is louder than saying nothing. |
| 1991 | assert!; |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | |
| 1996 | // makeover-layout 0.9.0. A token carries its own tone, so a colour on |
| 1997 | // the strip would be a rule fighting the things sitting in it -- the |
| 1998 | // same reasoning as actions, reached for a different reason. |
| 1999 | let css = row_rules; |
| 2000 | assert!; |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | // What `#[non_exhaustive]` bought and what it cost. `part_class` can no |
| 2006 | // longer be exhaustive, so a member added upstream lands as a bare |
| 2007 | // class with no rule instead of stopping the build. Asserting the |
| 2008 | // fallback exists is what keeps it from being written as `unreachable!` |
| 2009 | // by someone who reads the match as closed. |
| 2010 | assert_eq!; |
| 2011 | assert_eq!; |
| 2012 | |
| 2013 | |
| 2014 | |
| 2015 | |
| 2016 | // `--action-primary` shipped here for months and no theme has ever |
| 2017 | // defined it, so every `.link` dropped its colour declaration outright |
| 2018 | // and fell back to inherited text. Nothing caught it because the sheet |
| 2019 | // is valid CSS either way; MNW's no-undefined-token lint is what found |
| 2020 | // it, 2026-08-14. The hover arm two lines below was always `--action-hover`, |
| 2021 | // which is what makes the typo legible in hindsight. |
| 2022 | let css = link_rules; |
| 2023 | assert!; |
| 2024 | assert!; |
| 2025 | assert!; |
| 2026 | |
| 2027 | |
| 2028 | |
| 2029 | |
| 2030 | let css = progress_rules; |
| 2031 | assert!; |
| 2032 | assert!; |
| 2033 | assert!; |
| 2034 | assert!; |
| 2035 | // A bare `.fill` would catch things that have nothing to do with |
| 2036 | // progress once the sheet lands unprefixed. |
| 2037 | assert!; |
| 2038 | |
| 2039 | |
| 2040 | |
| 2041 | |
| 2042 | let css = progress_rules; |
| 2043 | // Untoned is --action, not Tone::Neutral's content-muted: a bar with no |
| 2044 | // status is still reporting progress, and muted would read as disabled. |
| 2045 | assert!; |
| 2046 | assert!; |
| 2047 | for tone in |
| 2048 | assert! |
| 2049 | css.contains, |
| 2050 | "missing progress tone {tone}" |
| 2051 | ; |
| 2052 | |
| 2053 | // goingson's two live cases, which is why the tones are emitted at all. |
| 2054 | assert!; |
| 2055 | assert!; |
| 2056 | |
| 2057 | |
| 2058 | |
| 2059 | |
| 2060 | // Decision 3's negative half. It was on the phase A list and came off; |
| 2061 | // this is what stops it drifting back in. |
| 2062 | let css = stylesheet; |
| 2063 | assert!; |
| 2064 | assert!; |
| 2065 | |
| 2066 | |
| 2067 | |
| 2068 | |
| 2069 | let css = surface_rules; |
| 2070 | assert!; |
| 2071 | // The ARIA attribute, not a class: one fact, read by both the visual |
| 2072 | // and the accessible state, so they cannot drift. |
| 2073 | assert!; |
| 2074 | assert!; |
| 2075 | // A flat ring: this edge says "wrong", and a two-tone bevel would have |
| 2076 | // it say "raised" at the same time. |
| 2077 | assert!; |
| 2078 | |
| 2079 | |
| 2080 | |
| 2081 | |
| 2082 | // box-shadow is not additive. A lone ring replaces the bevel and drops |
| 2083 | // the well out from under the field, which is what this emitted before |
| 2084 | // 0.5.0 and is the whole reason the rule composes. |
| 2085 | let css = surface_rules; |
| 2086 | let invalid = css |
| 2087 | .lines |
| 2088 | .skip_while |
| 2089 | .take_while |
| 2090 | . |
| 2091 | .join; |
| 2092 | assert! |
| 2093 | invalid.contains, |
| 2094 | "the well was dropped: {invalid}" |
| 2095 | ; |
| 2096 | assert!; |
| 2097 | |
| 2098 | |
| 2099 | |
| 2100 | |
| 2101 | // The duplication phase A deletes. They are the same composition, so |
| 2102 | // the only honest way to emit both is from one call. |
| 2103 | let opts = default; |
| 2104 | let css = surface_rules; |
| 2105 | assert_eq! |
| 2106 | depth_declarations, |
| 2107 | depth_declarations |
| 2108 | ; |
| 2109 | assert!; |
| 2110 | assert!; |
| 2111 | assert_eq! |
| 2112 | interactive_rules.replace, |
| 2113 | interactive_rules |
| 2114 | ; |
| 2115 | |
| 2116 | |
| 2117 | |
| 2118 | |
| 2119 | let opts = Emit |
| 2120 | class_prefix: "mo-", |
| 2121 | ..default |
| 2122 | ; |
| 2123 | let css = stylesheet; |
| 2124 | for name in |
| 2125 | "mo-button", |
| 2126 | "mo-card", |
| 2127 | "mo-field", |
| 2128 | "mo-badge", |
| 2129 | "mo-chip", |
| 2130 | "mo-tab", |
| 2131 | "mo-row-primary", |
| 2132 | "mo-progress", |
| 2133 | "mo-progress-fill", |
| 2134 | ] |
| 2135 | assert!; |
| 2136 | |
| 2137 | // The bare names must be gone entirely, or a prefixed build still |
| 2138 | // collides with the app's own stylesheet. |
| 2139 | assert!; |
| 2140 | assert!; |
| 2141 | assert!; |
| 2142 | |
| 2143 | |
| 2144 | |
| 2145 | |
| 2146 | // `option_class` is the contract a screen renderer writes markup |
| 2147 | // against, and the rules below are the other half of it. They come off |
| 2148 | // one mapping now, so this asserts the mapping is the one that reaches |
| 2149 | // the stylesheet rather than that two lists still agree. |
| 2150 | let css = stylesheet; |
| 2151 | for selector in |
| 2152 | let name = option_class; |
| 2153 | assert!; |
| 2154 | assert!; |
| 2155 | |
| 2156 | assert_eq!; |
| 2157 | |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | let css = stylesheet; |
| 2162 | |
| 2163 | // The space is inside the glyph, which is what the other two renderers |
| 2164 | // write. Emitted bare, every consumer has to add it back, and the |
| 2165 | // obvious way to add it -- `content` in an app stylesheet, which is |
| 2166 | // unlayered and so outranks this sheet -- deletes the caret instead. |
| 2167 | assert!; |
| 2168 | assert!; |
| 2169 | assert!; |
| 2170 | |
| 2171 | // The arrows this renderer used to draw alone are gone. Composition |
| 2172 | // rather than agreement: the glyph comes from `Sort::glyph`, so a |
| 2173 | // fourth spelling cannot appear here without appearing everywhere. |
| 2174 | assert!; |
| 2175 | assert!; |
| 2176 | |
| 2177 | // Three states, three tones. An idle sortable heading draws its caret |
| 2178 | // now rather than reserving a hidden box for it, so there is no |
| 2179 | // visibility to order and no reflow left to guard against; what |
| 2180 | // separates the states is the colour, and the sorted arms come after |
| 2181 | // the idle one because the specificity is the same. |
| 2182 | let idle = css |
| 2183 | .find |
| 2184 | .expect; |
| 2185 | let sorted = css |
| 2186 | .find |
| 2187 | .expect; |
| 2188 | assert!; |
| 2189 | assert! |
| 2190 | css.contains, |
| 2191 | "{css}" |
| 2192 | ; |
| 2193 | assert!; |
| 2194 | assert!; |
| 2195 | |
| 2196 | |
| 2197 | |
| 2198 | |
| 2199 | let css = component_rules; |
| 2200 | |
| 2201 | for tone in |
| 2202 | assert! |
| 2203 | css.contains, |
| 2204 | "{css}" |
| 2205 | ; |
| 2206 | |
| 2207 | // Colour, not a fill. A red surface is an app's decision about emphasis. |
| 2208 | assert!; |
| 2209 | |
| 2210 | |
| 2211 | |
| 2212 | |
| 2213 | let css = component_rules; |
| 2214 | assert!; |
| 2215 | |
| 2216 | |
| 2217 | |
| 2218 | |
| 2219 | // The whole point of the CSS table. A described table's columns are |
| 2220 | // known at render time, so anything the stylesheet has to be told about |
| 2221 | // them would have to travel with the markup. |
| 2222 | let css = component_rules; |
| 2223 | |
| 2224 | assert!; |
| 2225 | assert!; |
| 2226 | assert!; |
| 2227 | assert!; |
| 2228 | |
| 2229 | |
| 2230 | |
| 2231 | |
| 2232 | // The point of makeover-layout 0.14.0's CellPart, and the table-side |
| 2233 | // twin of `the_three_text_parts_take_their_intents_and_actions_inherits` |
| 2234 | // above. One `.cell` and one content colour meant a button in a cell |
| 2235 | // inherited it. |
| 2236 | let css = table_rules; |
| 2237 | |
| 2238 | assert! |
| 2239 | css.contains, |
| 2240 | "{css}" |
| 2241 | ; |
| 2242 | assert!; |
| 2243 | assert!; |
| 2244 | assert!; |
| 2245 | |
| 2246 | // The colour is on the part that is text, never on the container. On |
| 2247 | // `.cell` it would cascade into the three parts that are not text, |
| 2248 | // which is the bug written as one rule. |
| 2249 | assert!; |
| 2250 | |
| 2251 | |
| 2252 | |
| 2253 | |
| 2254 | // `part_class`'s obligation, taken on for the table side too. CellPart |
| 2255 | // is `#[non_exhaustive]`, so a member added upstream must land as a |
| 2256 | // bare class rather than as a build that stops. |
| 2257 | assert_eq!; |
| 2258 | assert_eq!; |
| 2259 | |
| 2260 | |
| 2261 | |
| 2262 | |
| 2263 | let css = component_rules; |
| 2264 | |
| 2265 | // Optional goes at the narrowest class and secondary goes with it, |
| 2266 | // which is `kept_at`'s cutoff walk said as two queries. |
| 2267 | let compact = css |
| 2268 | .find |
| 2269 | .expect; |
| 2270 | let medium = css |
| 2271 | .find |
| 2272 | .expect; |
| 2273 | assert!; |
| 2274 | assert!; |
| 2275 | |
| 2276 | // Essential columns are never mentioned, because not being mentioned is |
| 2277 | // already what never dropping means. |
| 2278 | assert!; |
| 2279 | |
| 2280 | // And nothing counts. `nth-child` is the bug the priority vocabulary |
| 2281 | // exists to end. |
| 2282 | assert!; |
| 2283 | |
| 2284 | |
| 2285 | |
| 2286 | |
| 2287 | let css = track_rules; |
| 2288 | |
| 2289 | // Placement arrives from the caller, computed once by Track::fraction. |
| 2290 | // If either of these becomes a literal, three renderers have started |
| 2291 | // disagreeing about where 09:30 is. |
| 2292 | assert!; |
| 2293 | assert!; |
| 2294 | |
| 2295 | // Overlap lanes default so an entry naming neither is full width. |
| 2296 | assert!; |
| 2297 | assert!; |
| 2298 | |
| 2299 | // The refusal that matters. A slot height here would be this crate |
| 2300 | // deciding how tall a quarter of an hour is, which is the thing |
| 2301 | // makeover-geometry owns and the reason `.track` gets no height at all. |
| 2302 | assert!; |
| 2303 | for size in |
| 2304 | let bare = css |
| 2305 | .lines |
| 2306 | .filter |
| 2307 | .any; |
| 2308 | assert!; |
| 2309 | |
| 2310 | |
| 2311 | |
| 2312 | |
| 2313 | |
| 2314 | // The crate's founding property, asserted over the component layer and |
| 2315 | // not only the primitives. |
| 2316 | let css = stylesheet; |
| 2317 | assert!; |
| 2318 | assert!; |
| 2319 | for line in css.lines |
| 2320 | // Declarations only: a selector or an at-rule can carry a colon of |
| 2321 | // its own (`:root`, `:hover`, `@media (hover: hover)`) and declares |
| 2322 | // nothing. Keyed on the trailing semicolon rather than on leading |
| 2323 | // indentation, which only ever worked as a proxy for nesting depth |
| 2324 | // and stopped when the sheet gained a cascade layer around it. |
| 2325 | let trimmed = line.trim; |
| 2326 | if !trimmed.ends_with |
| 2327 | continue; |
| 2328 | |
| 2329 | let Some = trimmed.split_once else |
| 2330 | continue; |
| 2331 | ; |
| 2332 | if value.contains |
| 2333 | continue; |
| 2334 | |
| 2335 | // Everything left has to be a keyword, a number or a |
| 2336 | // caller-supplied length, never a colour. |
| 2337 | // |
| 2338 | // The length arm is what the comment above always claimed and the |
| 2339 | // list never covered: `border_width` arrives from `Emit` and lands |
| 2340 | // bare in the focus ring's offset, where the bevel had only ever |
| 2341 | // used it inside an `inset` shadow. |
| 2342 | let opts = default; |
| 2343 | assert! |
| 2344 | value.contains |
| 2345 | || value.contains |
| 2346 | || value.contains |
| 2347 | // 0.12.0's two: a sortable header is a control and says so |
| 2348 | // with the pointer, and the caret is this renderer's own |
| 2349 | // expression of `aria-sort`. Neither is a colour, which is |
| 2350 | // what this test is actually about, and neither is a size, |
| 2351 | // which is the other thing this crate must not name. The |
| 2352 | // leading space inside the glyph is the same thing the other |
| 2353 | // two renderers write into theirs, so it is part of the |
| 2354 | // caret rather than spacing this crate decided on. |
| 2355 | || value |
| 2356 | .trim_start_matches |
| 2357 | .trim_start |
| 2358 | .starts_with |
| 2359 | || matches! |
| 2360 | value.trim_end_matches, |
| 2361 | "0" | "1" |
| 2362 | | "none" |
| 2363 | | "auto" |
| 2364 | | "not-allowed" |
| 2365 | | "pointer" |
| 2366 | // The caret's reserved box. Visibility is presence, |
| 2367 | // not magnitude and not colour. |
| 2368 | | "hidden" |
| 2369 | | "visible" |
| 2370 | // The link's two signals. `underline` is a line and |
| 2371 | // `inherit` defers to whatever the app set, so |
| 2372 | // neither names a colour or a magnitude. |
| 2373 | | "underline" |
| 2374 | | "inherit" |
| 2375 | // The table frame. `display` is structure and not a |
| 2376 | // size; `nowrap` is what makes a content column |
| 2377 | // content. The two widths are the awkward pair and |
| 2378 | // they are still not sizes: `100%` is "all of |
| 2379 | // whatever you were given" and `1%` is the CSS |
| 2380 | // table idiom for "shrink to fit", which is a |
| 2381 | // behaviour spelled as a number because CSS has no |
| 2382 | // keyword for it. Neither names a magnitude, which |
| 2383 | // is the thing this crate leaves to |
| 2384 | // makeover-geometry. |
| 2385 | | "table" |
| 2386 | | "table-row" |
| 2387 | | "table-cell" |
| 2388 | | "nowrap" |
| 2389 | | "100%" |
| 2390 | | "1%" |
| 2391 | // The time axis, 0.42.0. `position` is the one |
| 2392 | // property whose whole job is where a thing sits, |
| 2393 | // which is exactly what this crate spent its life |
| 2394 | // refusing to say -- so it is worth being exact |
| 2395 | // about why these two are not that refusal |
| 2396 | // breaking. |
| 2397 | // |
| 2398 | // Neither names a magnitude. `relative` says the |
| 2399 | // track is what its entries resolve against, and |
| 2400 | // `absolute` says an entry is placed rather than |
| 2401 | // flowed. *Where* each entry lands is |
| 2402 | // `--track-at` and `--track-for`, custom |
| 2403 | // properties the caller sets from |
| 2404 | // `Track::fraction`, and they are skipped by the |
| 2405 | // `var(--` arm above like every other value this |
| 2406 | // crate refuses to decide. |
| 2407 | // |
| 2408 | // The rule that would break the refusal is a slot |
| 2409 | // height, and there is none: the track's height is |
| 2410 | // the app's, so the percentages have something to |
| 2411 | // resolve against and this crate still never says |
| 2412 | // how tall a day is. |
| 2413 | | "relative" |
| 2414 | | "absolute" |
| 2415 | // A picture's three, 0.36.0. `block` is structure |
| 2416 | // for the reason `table` is: an inline image sits |
| 2417 | // on the baseline and carries a descender's worth |
| 2418 | // of space under it, which is a fact about |
| 2419 | // replaced elements rather than a size this crate |
| 2420 | // chose. `cover` and `contain` are `Fit`'s two |
| 2421 | // named members reaching CSS unchanged, which is |
| 2422 | // an intent arriving rather than a value being |
| 2423 | // picked. |
| 2424 | | "block" |
| 2425 | | "cover" |
| 2426 | | "contain" |
| 2427 | , |
| 2428 | "unrecognised literal value: {line}" |
| 2429 | ; |
| 2430 | |
| 2431 | |
| 2432 | |
| 2433 | |
| 2434 | |
| 2435 | assert_eq!; |
| 2436 | assert!; |
| 2437 | |
| 2438 | |
| 2439 | |
| 2440 | |
| 2441 | let opts = Emit |
| 2442 | class_prefix: "mo-", |
| 2443 | ..default |
| 2444 | ; |
| 2445 | let css = depth_rules; |
| 2446 | assert!; |
| 2447 | assert!; |
| 2448 | assert!; |
| 2449 | |
| 2450 | |
| 2451 | |
| 2452 | |
| 2453 | let opts = Emit |
| 2454 | border_width: "2px", |
| 2455 | ..default |
| 2456 | ; |
| 2457 | assert!; |
| 2458 | |
| 2459 | |
| 2460 | |
| 2461 | |
| 2462 | // Not a tautology: it is the guard that a CSS-shaped convenience never |
| 2463 | // quietly reverses which side is lit. |
| 2464 | let = Raised.edges; |
| 2465 | assert_eq!; |
| 2466 | assert_eq!; |
| 2467 | |
| 2468 | |
| 2469 |