/
lib.rs
1242 lines (1172 loc) · 34.4 KB
/
lib.rs
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
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#![forbid(unsafe_code)]
#![no_std]
#![doc(html_root_url = "https://docs.rs/lignin-schema/0.0.4")]
#![warn(clippy::pedantic)]
#![allow(clippy::semicolon_if_nothing_returned)]
#![allow(non_camel_case_types)]
#[cfg(doctest)]
pub mod readme {
doc_comment::doctest!("../README.md");
}
mod private {
pub trait Sealed {}
}
use private::Sealed;
pub trait Global<Aspect: ?Sized>: Sealed {}
pub trait HasContent: Sealed {
#[inline(always)]
fn static_validate_on(_: Self)
where
Self: Sized,
{
// Intentionally left empty.
}
}
#[deprecated = "Don't specify aspects directly, which may be too limiting. Generic type parameter resolution should never fail as there are no overloaded implementations."]
pub mod aspects {
enum Vacant {}
pub struct Content(Vacant);
pub struct Attribute(Vacant);
pub struct Event(Vacant);
}
#[allow(deprecated)]
use aspects::Attribute;
macro_rules! element_common {
(
$(#[$($attribute_token:tt)*])*
$(-$(-$deprecated:tt)?)?
$name:ident {
tag_name: $tag_name:expr,
}
) => {
$(
#[deprecated = "To quote MDN: Warning: \"These are old […] elements which are deprecated and should not be used. You should never use them in new projects, and should replace them in old projects as soon as you can. They are listed here for informational purposes only.\""]
$(compile_error!($deprecated))?
)?
$(#[$($attribute_token)*])*
pub struct $name;
#[allow(deprecated)]
impl $name {
#[must_use]
pub const TAG_NAME: &'static str = $tag_name;
}
#[allow(deprecated)]
impl Sealed for $name {}
#[allow(deprecated)]
impl<Aspect: ?Sized> Global<Aspect> for $name {}
#[allow(deprecated)]
impl<Aspect: ?Sized> crate::Global<Aspect> for $name {}
};
}
macro_rules! elements {
{$(
$(#[$($attribute_token:tt)*])*
$(-$(@$deprecated:tt)?)?
$(/$(@$empty:tt)?)?
$name:ident
),*$(,)?} => {$(
element_common! {
$(
$(@$empty)?
/// [***Empty.***](https://developer.mozilla.org/en-US/docs/Glossary/empty_element)
)?
$(#[$($attribute_token)*])*
$(-$(@$deprecated)?)? $name {
tag_name: heck_but_macros::stringify_SHOUTY_SNEK_CASE!($name),
}
}
$(
$(@$empty)?
#[cfg(FALSE)]
)?
#[allow(deprecated)]
impl HasContent for $name {}
)*};
}
macro_rules! attributes {
{$namespace:ident=>
$(
$(#[$($attribute_token:tt)*])*
$(-$(@$deprecated:tt)?)?
$(*$(@$experimental:tt)?)?
$(!$(@$obsolete:tt)?)?
$(%$(@$non_standard:tt)?)?
$name:ident on
$([$(
$(#[$($impl_attribute_token:tt)*])*
$(-$(@$deprecated_impl:tt)?)?
$(%$(@$non_standard_impl:tt)?)?
$element:ident
),*$(,)?])?
$(all $($global_marker:ident)?)?
),*$(,)?
} => {$(
$(
#[deprecated = "deprecated - probably still supported, but discouraged (usually in favor of a better alternative)."]
/// `deprecated`
$(@$deprecated)?
)?
$(
#[deprecated = "experimental - not for production code and likely not well supported yet."]
/// `experimental`
$(@$experimental)?
)?
$(
#[deprecated = "obsolete - most likely removed from most browsers that used to support it."]
/// `obsolete`
$(@$obsolete)?
)?
$(
#[deprecated = "non-standard - may behave differently between browsers or not work at all."]
/// `non-standard`
$(@$non_standard)?
)?
#[allow(deprecated)]
$(#[$($attribute_token)*])*
pub trait $name<Aspect: ?Sized = Attribute>: Sealed {
#[inline(always)]
fn static_validate_on(_: Self) where Self: Sized {
// Intentionally left blank.
}
}
#[allow(deprecated)]
impl dyn $name<Attribute> {
#[must_use]
pub const NAME: &'static str = heck_but_macros::stringify_kebab_case!($name);
}
$($(
$(
/// `deprecated`
//TODO: Is there a way to deprecate specific trait implementations?
$(@$deprecated_impl)?
)?
$(
/// `non-standard`
//TODO: Is there a way to deprecate specific trait implementations?
$(@$non_standard_impl)?
)?
#[allow(deprecated)]
$(#[$($impl_attribute_token)*])*
impl $name<Attribute> for crate::$namespace::elements::$element {
#[inline(always)]
fn static_validate_on(_: Self) {
// Intentionally left blank.
}
}
)*)?
$(
#[allow(deprecated)]
impl<T: crate::$namespace::Global<Attribute>> $name<Attribute> for T {}
$(compile_error!($global_marker))?
)?
)*};
}
pub mod html {
use crate::Sealed;
pub trait Global<Aspect: ?Sized>: Sealed {}
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Element>.
pub mod elements {
use super::Global;
#[allow(deprecated)]
use crate::{HasContent, Sealed};
// When you edit an element, also move it to its alphabetically-ordered position.
// Use a separate commit if it already had documentation or if you change its modifiers!
elements!(
/// Document-unique content and sectioning root.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body>.
///
/// # Accessibility
///
/// The default [`role`](`super::attributes::role`) of this element is [***document***](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Document_Role).
///
/// No alternative roles are permitted.
///
/// # Constraints
///
/// [`<body>`](`body`) may occur only as second child [***element***](https://developer.mozilla.org/en-US/docs/Glossary/Element)
/// of an [`<html>`](`html`) element, after [`<head>`](`head`).
///
/// # Scripting
///
/// The [`<body>`](`body`) element is available through the [***Document.body***](https://developer.mozilla.org/en-US/docs/Web/API/Document/body)
/// property.
///
/// # Styling
///
/// ## Overscroll
///
/// In browsers that support [overscroll](https://developer.mozilla.org/en-US/docs/Web/CSS/overscroll-behavior),
/// the main scroll container is usually [`<html>`](`html`).
///
/// By making sure the [`<body>`](`body`) is large enough to cover the viewport, you can style the overscroll area independently without extra elements:
///
/// ```css
/// html {
/// background: …;
/// }
///
/// body {
/// min-height: 100vh;
/// background: …;
/// }
/// ```
///
/// ## The Notch / Non-Rectangular Displays
///
/// > The styling situation in this regard is a bit too messy right now for me to give a recommendation,
/// > but such devices should still be taken into account when possible.
/// >
/// > (If you have experience in this regard, [please contribute](https://github.com/Tamschi/lignin-schema).)
///
/// # Optional Tags
///
/// The [`<body>`](`body`) element can be implied in serialized HTML as follows:
///
/// ## Start Tag
///
/// The start tag can be omitted iff no attributes are present and iff the first child node is **not** one of the following:
///
/// * a comment
/// * a [`<script>`](`script`) or [`<style>`](`style`) element,
/// * a text node starting with a space character.
///
/// ## End Tag
///
/// Can be omitted iff **both** of the following are true:
///
/// * The [`<body>`](`body`) has content or a start tag, and
/// * it is not immediately followed by a comment.
body,
/// Document-unique metadata header.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head>.
///
/// This element is intended only for machine-readable metadata.
/// For human-visible metadata, use [`<header>`](`header`) instead.
///
/// In HTML5-compliant browsers, [`<head>`](`head`) is created automatically in the DOM even if completely absent from markup. **Very** old browsers may behave differently here.
///
/// # Accessibility
///
/// This element has neither a default [`role`](`super::attributes::role`) nor permitted alternatives.
///
/// # Constraints
///
/// [`<head>`](`head`) may occur only as first child [***element***](https://developer.mozilla.org/en-US/docs/Glossary/Element)
/// of an [`<html>`](`html`) element.
///
/// # Optional Tags
///
/// The [`<head>`](`head`) element can be implied in serialized HTML as follows:
///
/// ## Start Tag
///
/// The start tag can be omitted iff this element's first child node is an [***element***](https://developer.mozilla.org/en-US/docs/Glossary/Element).
///
/// > Note that "child nodes" can include text containing only whitespace!
/// > Omitting `<head>` from serialized HTML will change the resulting DOM structure unless the next element follows **immediately**.
///
/// ## End Tag
///
/// Can be omitted iff this element's next sibling is neither a comment nor a text node starting with a space character.
head,
/// HTML document root.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html>.
///
/// # Accessibility
///
/// This element has neither a default [`role`](`super::attributes::role`) nor permitted alternatives.
///
/// While optional, you should specify the [`lang`](`super::attributes::lang`) attribute on this element according to the majority of content on the page.
/// Prefer this over setting it on [`<body>`](`body`), as this way also the metadata in [`<head>`](`head`), like for example [`<title>`](`title`), is affected accordingly.
///
/// > The [`lang`](`super::attributes::lang`) attribute can be set on **any** HTML element, so don't be afraid to be more specific for parts of the page if the content is mixed-language.
///
/// # Constraints
///
/// [`<html>`](`html`) must occur exactly once as single root element of an HTML document.
///
/// > However, sibling comments and *maybe* whitespace text nodes appear to be possible.
///
/// # Optional Tags
///
/// The [`<html>`](`html`) element can be implied in serialized HTML as follows:
///
/// ## Start Tag
///
/// The start tag can be omitted iff this element's first child node is **not** a comment.
///
/// ## End Tag
///
/// Can be omitted iff this element's next sibling is **not** a comment.
html,
style, title, /base, /link, /meta, address, article, aside, footer,
header, h1, h2, h3, h4, h5, h6, hgroup, main, nav, section,
blockquote, dd,
/// A generic layout container without semantic meaning, by default rendered with [***display: block***](https://developer.mozilla.org/en-US/docs/Web/CSS/display#outside).
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div>.
///
/// # Accessibility
///
/// A [`<div>`](`div`) itself (but not necessarily its content) is by default completely ignored when building the accessibility tree.
///
/// It's generally possible to adjust this behavior freely by applying [`aria_attributes`](`crate::aria_attributes`) directly to the element,
/// but this can be complex, error prone for developers not already very familiar with the topic and confusing
/// if the implemented behavior doesn't match what would be expected for its content and context.
///
/// Where available, strongly prefer semantic HTML elements with implicit [***WAI-ARIA Roles***](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles),
/// and don't overuse landmark rules as this can make a document "noisy" and harder to skim with assistive technology.
///
/// # See also
///
/// [`<span>`](`span`), [`class<Attribute>`](`super::attributes::class`)
div,
dl,
dt,
figcaption,
figure,
/// Thematic break, for example as sibling between [`<p>`](`p`) elements to mark a change of scene or topic within one containing section.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hr>.
///
// cSpell:ignore orizontal
/// [`<hr>`](`hr`) **used** to be defined as **h**orizontal **r**ule or line, but this definition has been replaced by its semantic function.
///
/// All element-specific attributes are deprecated or non-standard.
///
/// # Accessibility
///
/// [`<hr>`](`hr`)'s default ARIA [`role`](`super::attributes::role`) is [***separator***](https://w3c.github.io/aria/#separator).
///
/// Other permitted roles are [***presentation***](https://w3c.github.io/aria/#presentation)
/// and [***none***](https://w3c.github.io/aria/#none).
///
/// # Styling
///
/// Browsers will likely still display an unspecified line by default, but CSS should be used to define the presentation from the ground up.
///
/// When doing so, overwrite the [***border***](https://developer.mozilla.org/en-US/docs/Web/CSS/border)
/// CSS property, as this is normally how the default presentation is implemented,
/// and use [***margin-block-start***](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-block-start),
/// [***margin-block-end***](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-block-end),
/// [***margin-inline-start***](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-start)
/// and [***margin-inline-end***](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-end)
/// to change the positioning.
///
/// > Unlike the more specific properties, the shorthands [***margin-block***](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-block)
/// > and [***margin-inline***](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline)
/// > are not supported by Edge or Safari as of 2021-04¹⁻².
/// >
/// > 1. <https://caniuse.com/?search=margin-block>
/// > 2. <https://caniuse.com/?search=margin-inline>
/hr,
li, ol, p, pre, ul, a, abbr, b, bdi, bdo, cite, code, data, dfn, em, i, kbd, mark, q, rb, rp, rt, rtc,
ruby, s, samp, small, span, strong, sub, sup, time, u, var,
/// Produces a line break (carriage-return) in text.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br>.
///
/// # Accessibility
///
/// Do not use repetitions of this element to create spaced paragraphs.
/// Encountering these repetitions may be confusing when using a screen-reader,
/// which may announce each [`<br>`](`br`) separately.
///
/// Instead, prefer [`<p>`](`p`) elements and control [***margin***](https://developer.mozilla.org/en-US/docs/Web/CSS/margin)s
/// via CSS.
///
/// # Styling
///
/// [`<br>`](`br`) elements generally lack dimension and visual output, which means they mostly can't be styled.
///
/// Instead of setting a [***margin***](https://developer.mozilla.org/en-US/docs/Web/CSS/margin)
/// on [`<br>`](`br`), prefer changing the [***line-height***](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height)
/// of the surrounding element.
/br,
/wbr, audio, map, video, /area, /img, /track,
iframe, object, picture, /embed, /param, /source,
canvas, noscript, script,
del, ins,
caption, colgroup, table, tbody, td, tfoot, th, thead, tr, /col,
button, datalist, fieldset, form, label, legend, meter, optgroup, option, output,
progress, select, textarea, /input,
details, dialog, menu, summary,
slot, template,
-acronym, -applet, -big, -blink, -center, -content, -dir, -element, -font, -frameset,
-listing, -marquee, -multicol, -nobr, -noembed, -noframes, -plaintext, -shadow,
-strike, -tt, -xmp,
-/basefont, -/bgsound, -/command, -/frame,
/// > The spec doesn't actually say whether this allows content.
-/image,
-/isindex, -/keygen, -/menuitem, -/nextid, -/spacer
);
}
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Attribute>.
pub mod attributes {
use super::Sealed;
#[allow(deprecated)]
use crate::aspects::Attribute;
pub use crate::aria_attributes::*;
attributes! {html=>
accept on [input, -form],
// accept_charset on [form],
accesskey on all,
action on [form],
align on [
applet, caption, col, colgroup,
/// The alignment of the rule. Defaults to `left`.
-hr,
iframe, img, table, tbody, td, tfoot, th, thead, tr,
],
-alink on [
/// Text color of selected hyperlinks.
///
/// Prefer CSS:
///
/// ```css
/// *:active {
/// color: …;
/// }
/// ```
-body
],
allow on [iframe],
alt on [applet, area, img, input],
// r#async on [script],
autocapitalize on all,
autocomplete on [form, input, select, textarea],
autofocus on [button, input, keygen, select, textarea],
autoplay on [audio, video],
-background on [
/// URL of a background image.
///
/// Prefer CSS:
///
/// ```css
/// body {
/// background: url(…);
/// }
/// ```
-body,
table, td, th,
],
/// Use the CSS property [***background-color***](https://developer.mozilla.org/en-US/docs/Web/CSS/background-color)
/// instead.
///
/// While the intended use of this attribute was with named or hexadecimal colors,
/// [in practice various other strings are also accepted due to a lenient parsing scheme](https://stackoverflow.com/questions/8318911/why-does-html-think-chucknorris-is-a-color).
-bgcolor on [
/// Background color.
///
/// Prefer CSS:
///
/// ```css
/// body {
/// background-color: …;
/// }
/// ```
-body,
col, colgroup, marquee, table, tbody, tfoot, td, th, tr,
],
-border on [img, object, table],
-bottommargin on [
/// The bottom margin of the body.
///
/// Prefer CSS:
///
/// ```css
/// body {
/// margin-bottom: …;
/// }
/// ```
-body,
],
buffered on [audio, video],
capture on [input],
challenge on [keygen],
charset on [meta, script],
checked on [command, input],
cite on [blockquote, del, ins, q],
class on all,
code on [applet],
codebase on [applet],
-color on [
basefont, font,
/// The color of the rule, by name or hexadecimal value.
%hr,
],
cols on [textarea],
colspan on [td, th],
content on [meta],
contenteditable on all,
contextmenu on all,
controls on [audio, video],
coords on [area],
crossorigin on [audio, img, link, script, video],
*csp on [iframe],
data on [object],
//data-* on all,
datetime on [del, ins, time],
decoding on [img],
default on [track],
defer on [script],
dir on all,
dirname on [input, textarea],
disabled on [button, command, fieldset, input, keygen, optgroup, option, select, textarea],
download on [a, area],
draggable on all,
enctype on [form],
*enterkeyhint on all, // <textarea>, contenteditable
// r#for on [label, output],
form on [button, fieldset, input, keygen, label, meter, object, output, progress, select, textarea],
formaction on [input, button],
formenctype on [button, input],
formmethod on [button, input],
formnovalidate on [button, input],
formtarget on [button, input],
headers on [td, th],
height on [canvas, embed, iframe, img, input, object, video], // and deprecated `on all`, but this can't be expressed without min_specialization.
hidden on all,
high on [meter],
/// The [***URL***](https://url.spec.whatwg.org/) pointed to by a link-like element.
///
/// # Available on
///
/// [`<a>`](`super::elements::a`),
/// [`<area>`](`super::elements::area`),
/// [`<base>`](`super::elements::base`),
/// [`<link>`](`super::elements::link`).
///
/// # Notable [`href`] patterns
///
/// - Fragment URLs starting with `#` to link to a section of the current page,
/// - an absolute URL starting with `//` to remain on `http://` or `https://`,
/// - `mailto:` followed an email address,
/// - `tel:` followed by a phone number (primarily useful on mobile).
///
/// [Media fragment support appears to be limited.](https://caniuse.com/media-fragments)
href on [a, area, base, link],
hreflang on [a, area, link],
// http_equiv on [meta],
icon on [command],
id on all,
*importance on [iframe, img, link, script],
integrity on [link, script],
-intrinsicsize on [img],
inputmode on all, // <textarea>, contenteditable
ismap on [img],
itemprop on all,
keytype on [keygen],
kind on [track],
label on [optgroup, option, track],
lang on all,
-language on [script],
-leftmargin on [
/// The left margin of the body.
///
/// Prefer CSS:
///
/// ```css
/// body {
/// margin-left: …;
/// }
/// ```
-body,
],
list on [input],
-link on [
/// Text color of unvisited hyperlinks.
///
/// Prefer CSS:
///
/// ```css
/// *:link {
/// color: …;
/// }
/// ```
-body
],
*loading on [img, iframe],
// r#loop on [audio, bgsound, marquee, video],
low on [meter],
!manifest on [
/// The URI of a resource manifest that specifies caching behavior.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache> (and the included removal warnings!) for more information.
-html,
],
max on [input, meter, progress],
maxlength on [input, textarea],
minlength on [input, textarea],
media on [a, area, link, source, style],
method on [form],
min on [input, meter],
multiple on [input, select],
muted on [audio, video],
name on [button, form, fieldset, iframe, input, keygen, object, output, select, textarea, map, meta, param],
novalidate on [form],
noshade on [
/// Disables shading.
-hr,
],
onafterprint on [
/// `JS` Called after the user has printed the document.
body,
],
onbeforeprint on [
/// `JS` Called when the user requests printing the document.
body,
],
onbeforeunload on [
/// `JS` Called when the document is about to be unloaded.
body,
],
onblur on [
/// `JS` Called when the document loses focus.
body,
],
onerror on [
/// `JS` Called when the document fails to load properly.
body,
],
onfocus on [
/// `JS` Called when the document receives focus.
body,
],
onhashchange on [
/// `JS` Called after the fragment identifier of the document's current address changes.
body,
],
*onlanguagechange on [
/// `JS` Called after the preferred languages change.
body,
],
onload on [
/// `JS` Called when the document has finished loading.
body,
],
onmessage on [
/// `JS` Called when the document has received a message.
body,
],
onoffline on [
/// `JS` Called when network communication has failed.
body,
],
ononline on [
/// `JS` Called when network communication is available again after failure.
body,
],
onpopstate on [
/// `JS` Called when the user has navigated session history.
body,
],
onredo on [
/// `JS` Called when the user undoes an undo.
body,
],
onresize on [
/// `JS` Called after the document is resized.
body,
],
onstorage on [
//TODO: Find out what this means and elaborate.
/// `JS` Called when the storage area has changed.
body,
],
onundo on [
/// `JS` Called after the user undoes an action via undo transaction history.
body,
],
onunload on [
/// `JS` Called when the document is being unloaded.
body,
],
open on [details],
optimum on [meter],
pattern on [input],
ping on [a, area],
placeholder on [input, textarea],
poster on [video],
preload on [audio, video],
-profile on [
/// One or more space-separated metadata profile [***URI***](https://developer.mozilla.org/en-US/docs/Glossary/URI)s.
///
/// For more information, see <https://www.w3.org/TR/html401/struct/global.html#profiles>.
-head,
],
radiogroup on [command],
readonly on [input, textarea],
referrerpolicy on [a, area, iframe, img, link, script],
rel on [a, area, link],
required on [input, select, textarea],
reversed on [ol],
-rightmargin on [
/// The right margin of the body.
///
/// Prefer CSS:
///
/// ```css
/// body {
/// margin-right: …;
/// }
/// ```
-body,
],
rows on [textarea],
rowspan on [td, th],
sandbox on [iframe],
scope on [th],
!scoped on [style],
selected on [option],
shape on [a, area],
size on [
input,
/// The height of the rule in pixels.
-hr,
select,
],
sizes on [link, img, source],
slot on all,
span on [col, colgroup],
spellcheck on all,
src on [audio, embed, iframe, img, input, script, source, track, video],
srcdoc on [iframe],
srclang on [track],
srcset on [img, source],
start on [ol],
step on [input],
style on all,
-summary on [table],
tabindex on all,
target on [a, area, base, form],
-text on [
/// Text color.
///
/// Prefer CSS:
///
/// ```css
/// body {
/// color: …;
/// }
/// ```
-body,
],
title on all,
-topmargin on [
/// The top margin of the body.
///
/// Prefer CSS:
///
/// ```css
/// body {
/// margin-top: …;
/// }
/// ```
-body,
],
translate on all,
// r#type on [button, input, command, embed, object, script, source, style, menu],
usemap on [img, input, object],
value on [button, data, input, li, meter, option, progress, param],
-version on [
/// The HTML [***Document Type Definition***](https://developer.mozilla.org/en-US/docs/Glossary/Doctype) version.
///
/// Redundant in modern HTML documents starting with `<!DOCTYPE html>`.
-html
],
-vlink on [
/// Text color of visited hyperlinks.
///
/// Prefer CSS:
///
/// ```css
/// *:visited {
/// color: …;
/// }
/// ```
-body
],
width on [
canvas, embed, iframe, img, input,
/// The length of the rule as pixel or percentage value.
-hr,
object, video,
], // and deprecated `on all`, but this can't be expressed without min_specialization.
wrap on [textarea],
xmlns on [
/// XML namespace of the document.
///
/// Optional in HTML (where it defaults to `http://www.w3.org/1999/xhtml`) but required in XML documents.
html,
],
}
}
}
pub mod svg {
use crate::Sealed;
pub trait Global<Aspect: ?Sized>: Sealed {}
/// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Element>.
pub mod elements {
use super::Global;
#[allow(deprecated)]
use crate::{HasContent, Sealed};
// Separate element macros due to different name casing.
macro_rules! elements {
($(
$(#[$($attribute_token:tt)*])*
$(-$(-$deprecated:tt)?)?
$name:ident
),*$(,)?) => {$(
element_common! {
$(#[$($attribute_token)*])*
$(-$($deprecated)?)? $name {
tag_name: stringify!($name),
}
}
#[allow(deprecated)]
impl HasContent for $name {}
)*};
}
macro_rules! void_elements {
($(
$(#[$($attribute_token:tt)*])*
$(-$(-$deprecated:tt)?)?
$name:ident
),*$(,)?) => {$(
element_common! {
/// [***Empty.***](https://developer.mozilla.org/en-US/docs/Glossary/empty_element)
$(#[$($attribute_token)*])*
$(-$($deprecated)?)? $name {
tag_name: stringify!($name),
}
}
)*};
}
// Animation elements
elements!(
-animateColor,
animateMotion,
animateTransform,
discard,
mpath,
set
);
void_elements!(animate,); //?
// Basic shapes
elements!(circle, ellipse, line, polygon, polyline, rect);
// Container elements
//BUG: Fix casing so that it's `"missing-glyph"`!
elements!(
a,
defs,
g,
marker,
mask,
missing_glyph,
pattern,
svg,
switch,
symbol,
unknown,
);
// Descriptive elements
elements!(desc, metadata, title);
// Filter primitive elements
elements!(
feBlend,
feColorMatrix,
feComponentTransfer,
feComposite,
feConvolveMatrix,
feDiffuseLighting,
feDisplacementMap,
feDropShadow,
feFlood,
feFuncA,
feFuncB,
feFuncG,
feFuncR,
feGaussianBlur,
feImage,
feMerge,
feMergeNode,
feMorphology,
feOffset,
feSpecularLighting,
feTile,
feTurbulence,
);
// Font elements
//BUG: Fix casing!
elements!(-font, -font_face, -font_face_src, -font_face_uri);
void_elements!(-font_face_format, -font_face_name, -hkern, -vkern);
// Gradient elements
elements!(linearGradient, meshgradient, radialGradient, stop); //TODO: Check casing on `meshgradient`.
}
/// See <https://developer.mozilla.org/en-US/docs/Web/HTML/Attribute>.
pub mod attributes {
#[allow(unused_imports)] //TODO: Remove this once there is content here.
use super::Sealed;
pub use crate::aria_attributes::*;
attributes! {svg=>
}
}
}
/// See <https://www.w3.org/TR/wai-aria-1.1/#state_prop_def>.
pub mod aria_attributes {
#[allow(deprecated)]
use crate::{Attribute, Global, Sealed};
macro_rules! aria_attributes {
{$(
$(#[$($attribute_token:tt)*])*
$(-$(-$deprecated:tt)?)?
$(*$(*$experimental:tt)?)?
$(!$(!$obsolete:tt)?)?
$name:ident
),*$(,)?} => {$(
$(
#[deprecated = "deprecated - probably still supported, but discouraged (usually in favor of a better alternative)."]
/// `deprecated`
$(compile_error!($deprecated))?
)?
$(
#[deprecated = "experimental - not for production code and likely not well supported yet."]
/// `experimental`
$(compile_error!($experimental))?
)?
$(