Skip to main content

max / makeover-webview

4.3 KB · 103 lines History Blame Raw
1 # makeover-webview
2
3 The webview renderer for
4 [`makeover-layout`]https://makenot.work/git/max/makeover-layout. Emits CSS.
5
6 ## The renderer that needs no palette
7
8 `makeover-immediate` and `makeover-tui` both take a `Palette`, because egui and
9 a terminal need an actual colour before they can put anything on screen. A
10 webview does not. `var(--surface-raised)` *is* the late binding, and the browser
11 resolves it against whatever the theme layer last wrote onto `:root`.
12
13 So this crate emits text naming intents and never learns a colour, which is the
14 deferral rule with no adapter in the way. It is also why the webview was always
15 the wrong renderer to derive a vocabulary from: it can express anything, so it
16 never pushes back.
17
18 ## Phase A: the stylesheet
19
20 No markup here, deliberately. GoingsOn has 145 `innerHTML` sites and Balanced
21 Breakfast 175 `createElement` sites, so moving markup is a migration while
22 adopting a generated stylesheet is a deletion. The apps keep every line of their
23 markup and gain the classes.
24
25 ```css
26 :root {
27 --bevel-raised: inset 1px 1px 0 var(--bevel-light), inset -1px -1px 0 var(--bevel-dark);
28 --bevel-inset: inset 1px 1px 0 var(--bevel-dark), inset -1px -1px 0 var(--bevel-light);
29 }
30
31 .raised { background: var(--surface-raised); box-shadow: var(--bevel-raised); }
32 .well { background: var(--surface-well, var(--surface-page)); box-shadow: var(--bevel-inset); }
33 .card:active { background: var(--surface-well, var(--surface-page)); box-shadow: var(--bevel-inset); }
34 ```
35
36 Those two custom properties are byte-identical to what both apps already
37 hand-write, which is asserted in the tests. Adoption removes duplicated lines
38 rather than changing a pixel.
39
40 The depth classes are surfaces and nothing more. A raised object that is not
41 pressable is spelled `.raised`, and the states belong to the named surfaces:
42 `.card` and `.button` are that same depth *and* controls, so they carry hover,
43 press, focus and disabled.
44
45 `.card:active` is the one thing this renderer gets for free: the cascade carries
46 a pressed state that an immediate-mode renderer resolves per call site, eighteen
47 of them in audiofiles.
48
49 ## Phase B: form markup
50
51 `form::field_html` renders a `makeover_layout::Field` to the group both apps
52 build by hand today: label, control, hint, error, in goingson's shape and class
53 names, so adopting it deletes `renderFormField` rather than restyling anything.
54
55 ```rust
56 use makeover_layout::{Field, FieldKind};
57 use makeover_webview::{Emit, form::{Filling, Value, field_html}};
58
59 let field = Field::new(FieldKind::Text, "title", "Title");
60 let html = field_html(&field, &Filling::of(Value::Text("Ship it")), &Emit::default());
61 ```
62
63 It emits strings because both apps interpolate fields into larger string-built
64 forms, and it escapes them itself. One escaper covers both sinks: goingson needs
65 four and a correct choice at 543 call sites only because `textContent`
66 serialization will not encode a double quote, which is not a constraint Rust
67 has. The single hole is `form::Markup`, which a caller has to name.
68
69 Three things the emitter does that neither app does at initial render:
70
71 - `aria-invalid="true"` on an invalid control, which is what the generated
72 stylesheet keys its danger ring on. goingson sets it from its runtime
73 validation path and not from its renderer, so a field rendered already-invalid
74 is styled as though nothing were wrong.
75 - `aria-describedby` naming the hint as well as the error, so standing help
76 survives an error appearing.
77 - A secret never carries its value into the markup, on `FieldKind::confidential`.
78
79 Rows and tables are the other half of phase B and are not written yet.
80
81 ## Substitution, three ways
82
83 `Fill::Well` has no colour on makeover before 2.3.0, and the three renderers
84 answer that differently. That is the evidence that taking `Fill::fallback` out of
85 the description was right:
86
87 - `makeover-immediate` substitutes the page in Rust.
88 - `makeover-tui` refuses to substitute and draws an edge, because a terminal
89 quantises the two together.
90 - here, CSS already has the mechanism. `var(--surface-well, var(--surface-page))`
91 falls back in the browser and nothing in Rust decides anything.
92
93 ## Status
94
95 On crates.io at 0.5.1, which is the CSS half only; the form markup is unreleased.
96 Consumers are GoingsOn and Balanced Breakfast, both through makeover-build.
97
98 `cargo run --example dump` prints the stylesheet.
99
100 ## Licence
101
102 MIT.
103