Skip to content

Commit 5497b36

Browse files
committed
Add rust docs for rules
1 parent d2f0c79 commit 5497b36

19 files changed

+282
-16
lines changed

src/properties/grid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Default for TrackSize {
7474
#[derive(Debug, Clone, PartialEq, Default)]
7575
pub struct TrackSizeList(pub SmallVec<[TrackSize; 1]>);
7676

77-
/// A [`<track-breadth>`](https://drafts.csswg.org/css-grid-2/#typedef-track-breadth value.
77+
/// A [`<track-breadth>`](https://drafts.csswg.org/css-grid-2/#typedef-track-breadth) value.
7878
///
7979
/// See [TrackSize](TrackSize).
8080
#[derive(Debug, Clone, PartialEq)]

src/properties/transform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub struct Matrix3d<T> {
245245
pub m44: T,
246246
}
247247

248-
/// https://drafts.csswg.org/css-transforms-2/#mathematical-description
248+
// https://drafts.csswg.org/css-transforms-2/#mathematical-description
249249
impl Matrix3d<f32> {
250250
/// Creates an identity matrix.
251251
pub fn identity() -> Matrix3d<f32> {

src/rules/counter_style.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
//! The `@counter-style` rule.
2+
13
use super::Location;
24
use crate::declaration::DeclarationBlock;
35
use crate::error::PrinterError;
46
use crate::printer::Printer;
57
use crate::traits::ToCss;
68
use crate::values::ident::CustomIdent;
79

10+
/// A [@counter-style](https://drafts.csswg.org/css-counter-styles/#the-counter-style-rule) rule.
811
#[derive(Debug, PartialEq, Clone)]
912
pub struct CounterStyleRule<'i> {
13+
/// The name of the counter style to declare.
1014
pub name: CustomIdent<'i>,
1115
// TODO: eventually parse these properties
16+
/// Declarations in the `@counter-style` rule.
1217
pub declarations: DeclarationBlock<'i>,
18+
/// The location of the rule in the source file.
1319
pub loc: Location,
1420
}
1521

src/rules/custom_media.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
//! The `@custom-media` rule.
2+
13
use super::Location;
24
use crate::error::PrinterError;
35
use crate::media_query::MediaList;
46
use crate::printer::Printer;
57
use crate::traits::ToCss;
68
use crate::values::ident::DashedIdent;
79

10+
/// A [@custom-media](https://drafts.csswg.org/mediaqueries-5/#custom-mq) rule.
811
#[derive(Debug, PartialEq, Clone)]
912
pub struct CustomMediaRule<'i> {
13+
/// The name of the declared media query.
1014
pub name: DashedIdent<'i>,
15+
/// The media query to declare.
1116
pub query: MediaList<'i>,
17+
/// The location of the rule in the source file.
1218
pub loc: Location,
1319
}
1420

src/rules/document.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
//! The `@-moz-document` rule.
2+
13
use super::Location;
24
use super::{CssRuleList, MinifyContext};
35
use crate::error::{MinifyError, PrinterError};
46
use crate::printer::Printer;
57
use crate::traits::ToCss;
68

9+
/// A [@-moz-document](https://www.w3.org/TR/2012/WD-css3-conditional-20120911/#at-document) rule.
10+
///
11+
/// Note that only the `url-prefix()` function with no arguments is supported, and only the `-moz` prefix
12+
/// is allowed since Firefox was the only browser that ever implemented this rule.
713
#[derive(Debug, PartialEq, Clone)]
814
pub struct MozDocumentRule<'i> {
15+
/// Nested rules within the `@-moz-document` rule.
916
pub rules: CssRuleList<'i>,
17+
/// The location of the rule in the source file.
1018
pub loc: Location,
1119
}
1220

src/rules/font_face.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The `@font-face` rule.
2+
13
use super::Location;
24
use crate::error::{ParserError, PrinterError};
35
use crate::macros::enum_property;
@@ -11,27 +13,43 @@ use crate::values::url::Url;
1113
use cssparser::*;
1214
use std::fmt::Write;
1315

16+
/// A [@font-face](https://drafts.csswg.org/css-fonts/#font-face-rule) rule.
1417
#[derive(Debug, PartialEq, Clone)]
1518
pub struct FontFaceRule<'i> {
19+
/// Declarations in the `@font-face` rule.
1620
pub properties: Vec<FontFaceProperty<'i>>,
21+
/// The location of the rule in the source file.
1722
pub loc: Location,
1823
}
1924

25+
/// A property within an `@font-face` rule.
26+
///
27+
/// See [FontFaceRule](FontFaceRule).
2028
#[derive(Debug, Clone, PartialEq)]
2129
pub enum FontFaceProperty<'i> {
30+
/// The `src` property.
2231
Source(Vec<Source<'i>>),
32+
/// The `font-family` property.
2333
FontFamily(FontFamily<'i>),
34+
/// The `font-style` property.
2435
FontStyle(FontStyle),
36+
/// The `font-weight` property.
2537
FontWeight(Size2D<FontWeight>),
38+
/// The `font-stretch` property.
2639
FontStretch(Size2D<FontStretch>),
40+
/// The `unicode-range` property.
2741
UnicodeRange(Vec<UnicodeRange>),
42+
/// An unknown or unsupported property.
2843
Custom(CustomProperty<'i>),
2944
}
3045

31-
/// https://www.w3.org/TR/2021/WD-css-fonts-4-20210729/#font-face-src-parsing
46+
/// A value for the [src](https://drafts.csswg.org/css-fonts/#src-desc)
47+
/// property in an `@font-face` rule.
3248
#[derive(Debug, Clone, PartialEq)]
3349
pub enum Source<'i> {
50+
/// A `url()` with optional format metadata.
3451
Url(UrlSource<'i>),
52+
/// The `local()` function.
3553
Local(FontFamily<'i>),
3654
}
3755

@@ -63,9 +81,13 @@ impl<'i> ToCss for Source<'i> {
6381
}
6482
}
6583

84+
/// A `url()` value for the [src](https://drafts.csswg.org/css-fonts/#src-desc)
85+
/// property in an `@font-face` rule.
6686
#[derive(Debug, Clone, PartialEq)]
6787
pub struct UrlSource<'i> {
88+
/// The URL.
6889
pub url: Url<'i>,
90+
/// Optional `format()` function.
6991
pub format: Option<Format<'i>>,
7092
}
7193

@@ -99,9 +121,14 @@ impl<'i> ToCss for UrlSource<'i> {
99121
}
100122
}
101123

124+
/// The `format()` function within the [src](https://drafts.csswg.org/css-fonts/#src-desc)
125+
/// property of an `@font-face` rule.
102126
#[derive(Debug, Clone, PartialEq)]
103127
pub struct Format<'i> {
128+
/// A font format name.
104129
pub format: FontFormat<'i>,
130+
/// The `supports()` function.
131+
// TODO: did this get renamed to `tech()`?
105132
pub supports: Vec<FontTechnology>,
106133
}
107134

@@ -144,15 +171,26 @@ impl<'i> ToCss for Format<'i> {
144171
}
145172
}
146173

174+
/// A font format keyword in the `format()` function of the the
175+
/// [src](https://drafts.csswg.org/css-fonts/#src-desc)
176+
/// property of an `@font-face` rule.
147177
#[derive(Debug, Clone, PartialEq)]
148178
pub enum FontFormat<'i> {
179+
/// A WOFF font.
149180
WOFF,
181+
/// A WOFF v2 font.
150182
WOFF2,
183+
/// A TrueType font.
151184
TrueType,
185+
/// An OpenType font.
152186
OpenType,
187+
/// An Embedded OpenType (.eot) font.
153188
EmbeddedOpenType,
189+
/// A font collection.
154190
Collection,
191+
/// An SVG font.
155192
SVG,
193+
/// An unknown format.
156194
String(CowArcStr<'i>),
157195
}
158196

@@ -196,28 +234,49 @@ impl<'i> ToCss for FontFormat<'i> {
196234
}
197235

198236
enum_property! {
237+
/// A font feature tech descriptor in the `supports()`function of the
238+
/// [src](https://drafts.csswg.org/css-fonts/#src-desc)
239+
/// property of an `@font-face` rule.
199240
pub enum FontFeatureTechnology {
241+
/// Supports OpenType features.
200242
OpenType,
243+
/// Supports Apple Advanced Typography features.
201244
AAT,
245+
/// Supports Graphite features.
202246
Graphite,
203247
}
204248
}
205249

206250
enum_property! {
251+
/// A color font tech descriptor in the `supports()`function of the
252+
/// [src](https://drafts.csswg.org/css-fonts/#src-desc)
253+
/// property of an `@font-face` rule.
207254
pub enum ColorFontTechnology {
255+
/// Supports the `COLR` v0 table.
208256
COLRv0,
257+
/// Supports the `COLR` v1 table.
209258
COLRv1,
259+
/// Supports SVG glyphs.
210260
SVG,
261+
/// Supports the `sbix` table.
211262
SBIX,
263+
/// Supports the `CBDT` table.
212264
CBDT,
213265
}
214266
}
215267

268+
/// A font technology descriptor in the `supports()`function of the
269+
/// [src](https://drafts.csswg.org/css-fonts/#src-desc)
270+
/// property of an `@font-face` rule.
216271
#[derive(Debug, Clone, PartialEq)]
217272
pub enum FontTechnology {
273+
/// Supports font features.
218274
Features(FontFeatureTechnology),
275+
/// Supports variations.
219276
Variations,
277+
/// Supports color glyphs.
220278
Color(ColorFontTechnology),
279+
/// Supports color palettes.
221280
Palettes,
222281
}
223282

src/rules/font_palette_values.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The `@font-palette-values` rule.
2+
13
use super::supports::SupportsRule;
24
use super::{CssRule, CssRuleList, Location, MinifyContext};
35
use crate::error::{ParserError, PrinterError};
@@ -11,34 +13,51 @@ use crate::values::ident::DashedIdent;
1113
use crate::values::number::CSSInteger;
1214
use cssparser::*;
1315

14-
/// https://drafts.csswg.org/css-fonts-4/#font-palette-values
16+
/// A [@font-palette-values](https://drafts.csswg.org/css-fonts-4/#font-palette-values) rule.
1517
#[derive(Debug, PartialEq, Clone)]
1618
pub struct FontPaletteValuesRule<'i> {
19+
/// The name of the font palette.
1720
pub name: DashedIdent<'i>,
21+
/// Declarations in the `@font-palette-values` rule.
1822
pub properties: Vec<FontPaletteValuesProperty<'i>>,
23+
/// The location of the rule in the source file.
1924
pub loc: Location,
2025
}
2126

27+
/// A property within an `@font-palette-values` rule.
28+
///
29+
/// See [FontPaletteValuesRule](FontPaletteValuesRule).
2230
#[derive(Debug, Clone, PartialEq)]
2331
pub enum FontPaletteValuesProperty<'i> {
32+
/// The `font-family` property.
2433
FontFamily(FontFamily<'i>),
34+
/// The `base-palette` property.
2535
BasePalette(BasePalette),
36+
/// The `override-colors` property.
2637
OverrideColors(Vec<OverrideColors>),
38+
/// An unknown or unsupported property.
2739
Custom(CustomProperty<'i>),
2840
}
2941

30-
/// https://drafts.csswg.org/css-fonts-4/#base-palette-desc
42+
/// A value for the [base-palette](https://drafts.csswg.org/css-fonts-4/#base-palette-desc)
43+
/// property in an `@font-palette-values` rule.
3144
#[derive(Debug, PartialEq, Clone)]
3245
pub enum BasePalette {
46+
/// A light color palette as defined within the font.
3347
Light,
48+
/// A dark color palette as defined within the font.
3449
Dark,
50+
/// A palette index within the font.
3551
Integer(u16),
3652
}
3753

38-
/// https://drafts.csswg.org/css-fonts-4/#override-color
54+
/// A value for the [override-colors](https://drafts.csswg.org/css-fonts-4/#override-color)
55+
/// property in an `@font-palette-values` rule.
3956
#[derive(Debug, PartialEq, Clone)]
4057
pub struct OverrideColors {
58+
/// The index of the color within the palette to override.
4159
index: u16,
60+
/// The replacement color.
4261
color: CssColor,
4362
}
4463

src/rules/import.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The `@import` rule.
2+
13
use super::layer::LayerName;
24
use super::supports::SupportsCondition;
35
use super::Location;
@@ -8,13 +10,18 @@ use crate::traits::ToCss;
810
use crate::values::string::CowArcStr;
911
use cssparser::*;
1012

11-
/// https://drafts.csswg.org/css-cascade/#at-import
13+
/// A [@import](https://drafts.csswg.org/css-cascade/#at-import) rule.
1214
#[derive(Debug, PartialEq, Clone)]
1315
pub struct ImportRule<'i> {
16+
/// The url to import.
1417
pub url: CowArcStr<'i>,
18+
/// An optional cascade layer name, or `None` for an anonymous layer.
1519
pub layer: Option<Option<LayerName<'i>>>,
20+
/// An optional `supports()` condition.
1621
pub supports: Option<SupportsCondition<'i>>,
22+
/// A media query.
1723
pub media: MediaList<'i>,
24+
/// The location of the rule in the source file.
1825
pub loc: Location,
1926
}
2027

src/rules/keyframes.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The `@keyframes` rule.
2+
13
use super::supports::SupportsRule;
24
use super::MinifyContext;
35
use super::{CssRule, CssRuleList, Location};
@@ -16,11 +18,16 @@ use crate::values::percentage::Percentage;
1618
use crate::vendor_prefix::VendorPrefix;
1719
use cssparser::*;
1820

21+
/// A [@keyframes](https://drafts.csswg.org/css-animations/#keyframes) rule.
1922
#[derive(Debug, PartialEq, Clone)]
2023
pub struct KeyframesRule<'i> {
24+
/// The animation name.
2125
pub name: CustomIdent<'i>,
26+
/// A list of keyframes in the animation.
2227
pub keyframes: Vec<Keyframe<'i>>,
28+
/// A vendor prefix for the rule, e.g. `@-webkit-keyframes`.
2329
pub vendor_prefix: VendorPrefix,
30+
/// The location of the rule in the source file.
2431
pub loc: Location,
2532
}
2633

@@ -173,11 +180,15 @@ impl<'i> ToCss for KeyframesRule<'i> {
173180
}
174181
}
175182

176-
/// https://drafts.csswg.org/css-animations/#typedef-keyframe-selector
183+
/// A [keyframe selector](https://drafts.csswg.org/css-animations/#typedef-keyframe-selector)
184+
/// within an `@keyframes` rule.
177185
#[derive(Debug, PartialEq, Clone)]
178186
pub enum KeyframeSelector {
187+
/// An explicit percentage.
179188
Percentage(Percentage),
189+
/// The `from` keyword. Equivalent to 0%.
180190
From,
191+
/// The `to` keyword. Equivalent to 100%.
181192
To,
182193
}
183194

@@ -224,9 +235,14 @@ impl ToCss for KeyframeSelector {
224235
}
225236
}
226237

238+
/// An individual keyframe within an `@keyframes` rule.
239+
///
240+
/// See [KeyframesRule](KeyframesRule).
227241
#[derive(Debug, PartialEq, Clone)]
228242
pub struct Keyframe<'i> {
243+
/// A list of keyframe selectors to associate with the declarations in this keyframe.
229244
pub selectors: Vec<KeyframeSelector>,
245+
/// The declarations for this keyframe.
230246
pub declarations: DeclarationBlock<'i>,
231247
}
232248

0 commit comments

Comments
 (0)