Skip to main content

max / makeover-webview

4.0 KB · 98 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 .raised:active { 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 `.raised:active` is the one thing this renderer gets for free: the cascade
41 carries a pressed state that an immediate-mode renderer resolves per call site,
42 eighteen of them in audiofiles.
43
44 ## Phase B: form markup
45
46 `form::field_html` renders a `makeover_layout::Field` to the group both apps
47 build by hand today: label, control, hint, error, in goingson's shape and class
48 names, so adopting it deletes `renderFormField` rather than restyling anything.
49
50 ```rust
51 use makeover_layout::{Field, FieldKind};
52 use makeover_webview::{Emit, form::{Filling, Value, field_html}};
53
54 let field = Field::new(FieldKind::Text, "title", "Title");
55 let html = field_html(&field, &Filling::of(Value::Text("Ship it")), &Emit::default());
56 ```
57
58 It emits strings because both apps interpolate fields into larger string-built
59 forms, and it escapes them itself. One escaper covers both sinks: goingson needs
60 four and a correct choice at 543 call sites only because `textContent`
61 serialization will not encode a double quote, which is not a constraint Rust
62 has. The single hole is `form::Markup`, which a caller has to name.
63
64 Three things the emitter does that neither app does at initial render:
65
66 - `aria-invalid="true"` on an invalid control, which is what the generated
67 stylesheet keys its danger ring on. goingson sets it from its runtime
68 validation path and not from its renderer, so a field rendered already-invalid
69 is styled as though nothing were wrong.
70 - `aria-describedby` naming the hint as well as the error, so standing help
71 survives an error appearing.
72 - A secret never carries its value into the markup, on `FieldKind::confidential`.
73
74 Rows and tables are the other half of phase B and are not written yet.
75
76 ## Substitution, three ways
77
78 `Fill::Well` has no colour on makeover before 2.3.0, and the three renderers
79 answer that differently. That is the evidence that taking `Fill::fallback` out of
80 the description was right:
81
82 - `makeover-immediate` substitutes the page in Rust.
83 - `makeover-tui` refuses to substitute and draws an edge, because a terminal
84 quantises the two together.
85 - here, CSS already has the mechanism. `var(--surface-well, var(--surface-page))`
86 falls back in the browser and nothing in Rust decides anything.
87
88 ## Status
89
90 On crates.io at 0.5.1, which is the CSS half only; the form markup is unreleased.
91 Consumers are GoingsOn and Balanced Breakfast, both through makeover-build.
92
93 `cargo run --example dump` prints the stylesheet.
94
95 ## Licence
96
97 MIT.
98