1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
//! The webview renderer for [`makeover_layout`].
//!
//! <!-- wiki: makeover-webview -->
//!
//! This crate takes no `Palette`. It emits CSS that names intents
//! (`var(--surface-raised)`), and the browser resolves them against whatever
//! `themes.js` last wrote onto `:root`.
//!
//! # The stylesheet
//!
//! [`stylesheet`] writes the component CSS. Part of what it emits is the
//! withdrawal of user-agent chrome: [`reset`] is where a primitive says which
//! parts of its element's default look it does not take.
//!
//! Pressed carries its fill: [`interactive_rules`] emits [`Depth::pressed`]
//! whole, so a control presses to `--surface-well` and hovers to
//! `--hover-surface`. A badge is flat (`token_rules`). No class prefix ships
//! by default.
//!
//! # The markup's names
//!
//! The vocabulary's members (fields, choices, columns, figures, meters, charts,
//! acts and the rest) are drawn by the quasi hosts: `quasi-webview` for this
//! renderer. This crate keeps what those hosts and hand-written apps share
//! with it:
//!
//! - [`form`]: the escaper, [`form::Markup`] and [`form::Filling`], the field
//! classes and the rules behind them. One function covers element text and
//! attribute values.
//! - [`list`]: column names as classes, the kind, part and flow classes, the
//! cell wrapper and sizer, and the `short-N` and `stacks-N` ladders a table
//! narrows and stacks by.
//! - [`chart`], [`figure`], [`meter`]: class lists and rules only.
//! - [`facet`] renders `makeover_layout::Facet` itself: a dimension a set is
//! narrowed by, where one gesture both selects a value and moves the browse
//! position.
//! - [`placeholder`] draws the stand-in a region shows while it has nothing.
//!
//! The table rules (`table_rules`) are private and reach a consumer only
//! through [`stylesheet`]. Every class a host's markup can carry is in one of
//! the modules' class lists, and [`vocabulary::names`] is their union with the
//! generated sheet.
//!
//! # Interaction states
//!
//! [`interactive_rules`] emits four states, in emission order, and the order is
//! load-bearing: they are all specificity (0,2,0), so disabled beats hover by
//! coming last. No rule uses `:not(:disabled)`.
//!
//! Hover sits inside a capability query: `makeover-layout`'s `Affordance`
//! answers whether the pointer has hover and `makeover-geometry` spells the
//! condition.
//!
//! # The layer contract
//!
//! [`stylesheet`] emits into the `makeover` cascade layer ([`CSS_LAYER`],
//! defined in `makeover-geometry`). `makeover-geometry` layers the density and
//! size-class blocks of `geometry.css` the same way; the compactness block
//! that closes that file is unlayered.
//!
//! The cascade resolves origin and importance, then layer, then specificity,
//! then source order, and **unlayered normal declarations outrank every named
//! layer**. An app declares the order once, or the layer's position is decided
//! by whichever generated file the browser sees first:
//!
//! ```css
//! @layer makeover, base, components, responsive;
//! ```
//!
//! [`in_css_layer`] is re-exported for an app that assembles its own stylesheet
//! from this crate's pieces, so the rules it generates from them land in the
//! same layer.
//!
//! # Form rules
//!
//! The field markup is the hosts' and the look is this crate's. A few rules
//! key on a mark the markup carries rather than a class:
//!
//! - A markdown field is marked `data-format="markdown"`, and
//! `form::editor_rules` keys on that mark. The Write/Preview pair is a
//! segmented control, taking the depth, the focus ring and the chosen state
//! from the existing rules; the preview pane is a well. **This crate renders
//! no markdown**: the pane is filled by whatever binds the editor.
//! - A suggestion's second line, `.form-suggestion-detail`, is drawn in
//! `--content-muted` rather than in the disabled token, as are
//! `.form-option-detail` and `.form-unit`.
//! - An unavailable option's reason is `.form-option-reason`, and a group with
//! an error carries `has-error` while its message carries `visible`
//! ([`form::FIELD_STATE_CLASSES`]).
//!
//! # A cell says what it holds
//!
//! [`CellPart`](makeover_layout::CellPart) names the four things a cell holds,
//! and `table_rules` turns them into `.cell-value`, `.cell-tokens`,
//! `.cell-actions` and `.cell-link`. The value and the link take a colour; a
//! token carries its own tone and an action is a control. The colour goes on
//! `.cell-value`, not on `.cell`, so it does not cascade into a control in the
//! cell.
//!
//! # A table narrows itself
//!
//! No rule is written per table. `table_rules` lays every table out as flex
//! rows, each column starting at its declared floor and giving up room by its
//! [`Priority`](makeover_layout::Priority), so the browser narrows a table at
//! the width its floors add up to. A host puts the column's classes on every
//! cell (its name through [`list::push_column_name`], its width and drop tiers
//! from [`list::CELL_WIDTH_CLASSES`] and [`list::CELL_DROP_CLASSES`], its kind
//! from [`list::kind_class`]), and every cell's contents go in
//! [`list::CELL_IN`]. **A header row emitted by a renderer's own code has to do
//! both too**, or the header and the body disagree about which column just
//! closed and how wide the rest are.
//!
//! `.button` takes the four tones off `data-tone` as a background tint
//! (`--{tone}-surface`) and, unlike the badge, no edge colour. A list is reset
//! rather than left bulleted. A row's actions are never hidden until hover.
//!
//! # The depth classes are not controls
//!
//! `.raised` states a shape and carries no interactive set. `.button` is the
//! same depth and a control, and takes its states from `surface_rules`.
//! `.card` is a raised object that answers a pointer only when the element it
//! is written on is a control: `a`, `button`, `label`, or anything carrying
//! `data-act`.
//!
//! # A theme with no well
//!
//! Each renderer answers a theme with no `surface-well` its own way:
//!
//! - `makeover-immediate` substitutes nothing: its `Palette::from_theme` fails
//! with `MissingToken`.
//! - `makeover-tui` draws an edge instead.
//! - here, `var(--surface-well, var(--surface-page))` falls back in the
//! browser.
pub use ;
use ;
use ;
use ;
use table_rules;
use crate;
use ;
// Re-exported rather than redefined. An app assembling its own stylesheet out
// of this crate's pieces needs the same layer name, and most such apps depend
// on this crate and not on `makeover-geometry` directly.
pub use ;
/// This crate's version, as the generated stylesheet reports it.
///
/// [`stylesheet`] writes it into the sheet's banner.
pub const VERSION: &str = env!;
use ;
/// How the emitted CSS and markup are shaped, and the copy they carry.
///
/// Built with [`Emit::new`] and its setters. `#[non_exhaustive]`, so a new
/// knob is not a breaking change for anyone who configures one.
/// One setter per field, named after it, for building an [`Emit`] outside this
/// crate: `Emit::new().class_prefix("mk-")`.
setters!;
/// A string as CSS escapes, for a `content` value.
///
/// `\u{25B2}` becomes `\25B2`, so the stylesheet is ASCII whatever the
/// description spells.
///
/// The escape writes no trailing space, so every call site follows it with
/// the closing quote: a CSS hex escape takes up to six digits and ends at the
/// first character that cannot be one.
/// The CSS custom property holding a bevel's composition.
/// A `var()` reference to a fill intent, with the browser's own fallback where
/// the intent may be absent.
///
/// The fallback is CSS syntax, resolved by the browser.
/// The two-tone edge as a `box-shadow` value.
///
/// Two inset shadows, one per corner pair: the light one offset down and
/// right so it lands on the top and left edges, the dark one the other way.
/// The same assignment `makeover-immediate` draws with polylines and
/// `makeover-tui` draws with box-drawing characters.
/// The custom properties the bevels and edges resolve through, as `:root`
/// declarations: one per [`Bevel`] ([`bevel_var`]: raised, inset, raised
/// open), the open bevel turned a quarter (`--bevel-raised-open-side`), the
/// overlay cast (`--elevation-overlay`) and the control edge
/// (`--edge-control`). A consumer that wants an edge without the fill reads the
/// property directly.
/// The property holding [`Bevel::RaisedOpen`] turned a quarter.
///
/// Which run of an open bevel is left off is the arrangement's, not the edge's:
/// the run facing the surface the tab opens into. A strip across its pane
/// opens downward, which is the composition under [`bevel_var`]; a strip
/// running down beside its pane opens toward the inline end, and this is that.
/// Not a member of [`Bevel`]: the renderer drawing the arrangement says which
/// side.
const OPEN_SIDE_VAR: &str = "--bevel-raised-open-side";
/// [`bevel_shadow`] for a tab that joins its pane on the inline-end side.
///
/// The lit run stays on top and left, and the shaded run drops its horizontal
/// offset instead of its vertical one, so it lands on the bottom alone and the
/// right run is not drawn. Physical rather than logical sides, as every bevel
/// here is: `box-shadow` has no logical form.
/// The cast shadow of a surface that floats over the page.
///
/// `makeover` derives the tone (`--elevation`); this sets the geometry: a
/// hard 3px offset down and to the right, with no blur.
///
/// **Only for a surface that overlays the page**: a menu, a toast, a popover,
/// a dropdown. A surface *in* the page takes `.raised` and its bevel.
const ELEVATION_PROPERTY: &str = " --elevation-overlay: 3px 3px 0 var(--elevation);\n";
/// The class name for a depth: `raised`, `well` or `sunken`, prefixed, and
/// `None` for [`Depth::Flat`] and any depth this renderer does not know.
///
/// [`depth_rules`] writes no rule for `sunken`, and [`vocabulary::names`]
/// does not list it: a host that emits the class for [`Depth::Sunken`] gets
/// a class the stylesheet does not style.
/// A prefixed class name.
///
/// For a renderer that emits markup this crate does not: a class it writes
/// takes the same [`Emit::class_prefix`] the stylesheet does.
/// A prefixed class name, written into a buffer the caller already has.
///
/// The form the emitters use. [`class`] returns a `String` instead.
/// The attribute an element's custom properties ride in, instead of `style`.
///
/// A number this crate hands the stylesheet (a bar's value and its axis, a
/// facet's depth, a meter's fill) is a custom property the rules divide or
/// multiply. It rides in this attribute, and [`VARS_JS`] sets each property
/// through the CSSOM, so a page under a `style-src` without
/// `'unsafe-inline'` still draws it.
///
/// The value is `--name: value` pairs separated by `;`, the `style`
/// attribute's declaration syntax. Only custom properties are applied.
pub const VARS_ATTR: &str = "data-vars";
/// The script that applies [`VARS_ATTR`], for a host to serve beside its other
/// assets.
///
/// Without it every number the rules read from that attribute is missing: bars
/// and charts flat, tree rows unindented, a split screen at even halves.
///
/// It also restores this device's density choice onto the root element
/// ([`DENSITY_STORE_KEY`] into
/// [`DENSITY_ATTRIBUTE`](makeover_geometry::DENSITY_ATTRIBUTE)) and answers a
/// [`DENSITY_CHOICE_ATTR`] picker. Serve it as a classic script in the head,
/// not deferred, so its observer is
/// running before the parser reaches the body and the first paint already has
/// every property.
///
/// ```no_run
/// # fn main() -> std::io::Result<()> {
/// std::fs::write("static/vars.js", makeover_webview::VARS_JS)?;
/// # Ok(())
/// # }
/// ```
pub const VARS_JS: &str = include_str!;
/// The attribute a [`FieldKind::Density`](makeover_layout::FieldKind::Density)
/// picker carries, which is how [`VARS_JS`] finds it.
///
/// The picker is a `<select>` with this attribute and **no `name`**, so no
/// form or htmx request ever submits it: the device holds the answer, and the
/// script reads and writes it there.
pub const DENSITY_CHOICE_ATTR: &str = "data-density-choice";
/// The browser storage key a device's density choice is kept under.
///
/// The value is [`Density::attribute_value`](makeover_geometry::Density::attribute_value),
/// and an absent key is "follow detection". Browser storage is per origin:
/// per device for a hosted app, per app for a desktop one.
pub const DENSITY_STORE_KEY: &str = "makeover-density";
/// Write the options of a density picker, in
/// [`DENSITY_CHOICES`](makeover_layout::DENSITY_CHOICES) order.
///
/// None is marked selected. The server cannot know what this device chose,
/// so [`VARS_JS`] sets the picker's value from storage as it arrives, which
/// is before first paint on a page load and on insertion after a swap.
///
/// ```
/// let mut out = String::new();
/// makeover_webview::density_options_into(&mut out);
/// assert!(out.starts_with("<option value=\"\">Automatic</option>"));
/// assert!(out.contains("<option value=\"touch\">Touch</option>"));
/// ```
/// The class an option of a selector carries, which is what the rules key off.
///
/// Named for the option and not for the group: `selector_rules` styles the
/// thing that gets picked, so `Selector::Tabs` is `tab` and not `tabs`, and
/// the class goes on each option, not on the wrapping element.
///
/// The chosen option additionally carries `chosen`, the same way a latched
/// chip carries `latched`; `selector_rules` writes both.
/// The fill and edge declarations for a depth, as a rule body.
///
/// Empty for [`Depth::Flat`], which has neither and inherits what it sits on.
/// Callers skip the rule when it is empty.
///
/// Each half is emitted when the depth has it, so [`Depth::Sunken`], which
/// has a fill and no bevel, gets its fill. Both halves come off one `Depth`.
/// One rule giving a selector a depth, or nothing when the depth declares
/// nothing.
/// The media condition a hover rule has to sit inside, or `None` if hover is
/// unconditional.
///
/// `makeover-layout`'s [`Affordance`] answers *whether* hover exists at a
/// density, and `makeover-geometry` spells that capability as a media
/// condition. This asks both.
///
/// [`SizeClass`] is required by [`Affordance::available`] and ignored by this
/// member, which reports as much through `reads_size`. Passing Compact is not
/// a claim about width; the test below pins that every class agrees.
pub
/// The tones that carry a status, each of which a toned member draws.
pub const STATUS_TONES: = ;
/// The disabled state, native or announced, as one selector suffix.
pub const DISABLED: &str = ":is(:disabled, [aria-disabled=\"true\"])";
/// One `{selector}[data-tone="…"]` rule per status tone, `body` writing the
/// declarations for a tone token.
pub
/// A status drawn as an edge on the start side, the words keeping their ink.
pub
/// A status drawn as a tinted ground edged in the tone.
/// Put a rule inside a media query, or leave it alone.
pub
/// The keyboard focus ring, placed by the depth it lands on.
///
/// This is the webview's **focus ring** and nothing more. **Reach** and
/// **focus** are both the browser's, the document decides what is reachable
/// and `:focus-visible` decides which reached thing wears the ring, and no
/// description states either. The three terms are defined once in
/// `makeover_layout`'s crate header, "Reach, focus and the focus ring".
///
/// One ring for every component. Its placement comes off [`Depth`]: an
/// `outline` of [`Emit::focus_width`] in `--focus-ring`, offset inward by
/// that width on a well (an inset bevel) and outward by it on anything else.
/// The outline leaves the element's `box-shadow` bevel untouched.
///
/// The invalid-field ring in `surface_rules` is built differently: a
/// `box-shadow` of [`Emit::border_width`] composed after the bevel, flush with
/// the element.
/// A rest depth said out loud on both axes, for a rule that has to beat the
/// states above it.
///
/// [`depth_declarations`] states an axis only when the depth has something to
/// say about it. This states both: an axis the depth is silent on is
/// withdrawn, in the words [`reset`] spells, so a state above it does not
/// keep that axis. [`Depth::Flat`] withdraws fill and edge;
/// [`Depth::Sunken`] and [`Depth::Overlay`] withdraw the edge the pressed
/// rule hands out.
/// Present, visible, and not answering.
///
/// Matches `[aria-disabled="true"]` as well as `:disabled`, since a `div`
/// carrying `.chip` or `.tab` can never be `:disabled`.
///
/// The rest depth is re-asserted on both axes, through `rest_declarations`.
/// The rule beats the hover and pressed rules on source order at equal
/// specificity (0,2,0).
/// Every state a selector that answers a click implies: hover, pressed, focus
/// and disabled, in that order.
///
/// All four selectors are specificity (0,2,0), so disabled wins over hover
/// and pressed by coming last.
///
/// Pressed emits [`Depth::pressed`] in full, fill and edge together, so the
/// pressed fill comes from the description (`--surface-well`).
///
/// Hover has no member in the description and is renderer policy. It resolves
/// against `--hover-surface` and is gated on capability, via
/// `hover_condition`.
///
/// `depth` is the selector's **rest** depth, used to place the focus ring and
/// to restore the surface under a disabled control. The pressed rule inverts
/// from [`Depth::Raised`] whatever `depth` is, so a tab at rest
/// [`Depth::Sunken`] still presses.
/// The compound a card's interactive states are written against: the class
/// on an element that is itself a control.
///
/// `label` for a card wrapping a choice, `[data-act]` for an act a renderer
/// drew on some other element. Without the class prefix, the way every
/// selector handed to [`interactive_rules`] is.
/// The depth classes' rules, fill and edge together: `.raised` and `.well`.
/// [`depth_class`] also names `sunken`, which gets no rule here.
///
/// No hover, press, focus or disabled rule. `.button`, and `.card` written on
/// a control, get their states from `surface_rules`.
/// The component layer: the rules of every named component. No
/// scrollbar rules.
/// A notice that leaves on its own, floating over the page.
///
/// Its look is this crate's and where it floats is the host's: a toast takes
/// [`Notice::Toast`]'s fill, the control edge, the overlay cast and the notice
/// layer, and no position. A toned toast is the banner's answer: the tone's
/// surface under the
/// theme's own ink, edged in the tone.
/// A notice that stays until dealt with, across whatever it is about.
///
/// A banner is left-aligned and its words stop at the reading measure while
/// its ground keeps the width of the
/// box it was put in. The words are a bare text node beside an optional act, so
/// the measure is the far padding rather than a cap on a child: what is left of
/// the box past the measure, or the ordinary inset once the box is narrower
/// than that.
///
/// A status is the chip's answer: `*-surface` under the theme's own ink, edged
/// in the tone. A status colour is never the colour of words.
/// How a transient notice goes away.
///
/// `makeover-timing` says that `Moment::Dismiss` is how long a notice lives
/// *before it starts to leave*, and that the leaving itself is `Motion::Fade`.
/// The `build` module writes `--motion-fade` into every consumer's
/// `timing.css`, and this is the rule that reads it. A script sets
/// `data-leaving` on the notice when its dismiss is up and removes the node
/// once the fade has run.
///
/// The state is an attribute, outside [`Emit::class_prefix`]'s namespace, so
/// a script sets it without a prefix. The transition sits on the notice and
/// the opacity on the leaving state.
///
/// # Reduced motion
///
/// `timing.css` zeroes `--motion-fade` under `prefers-reduced-motion`. The
/// renderer that sets the attribute must remove the node on a timer, not on
/// `transitionend`: a zero-length transition may fire no event at all.
///
/// The fallback, with no timing sheet, is `0ms`.
/// The ink a native control draws its tick, dot and fill in.
///
/// A checkbox, a radio, a range and a `<progress>` are drawn by the browser.
/// `accent-color` is inherited, so one declaration on `:root` reaches every
/// native control in the document, including ones no emitter here wrote.
/// `--content`, not `--action`: the accent is reserved for the primary
/// action. The browser picks the tick's own colour against that ink.
const NATIVE_ACCENT: &str = " accent-color: var(--content);\n";
/// The whole phase-A stylesheet: properties, depth rules and components, in
/// [`CSS_LAYER`], under a generated-file banner.
///
/// The banner sits outside the layer, at the top of the file.