|
1 | | -//! Selectors. |
2 | | -
|
3 | | -#![allow(missing_docs)] |
| 1 | +//! CSS selectors. |
4 | 2 |
|
5 | 3 | use crate::compat::Feature; |
6 | 4 | use crate::error::{ParserError, PrinterError}; |
@@ -33,9 +31,13 @@ mod private { |
33 | 31 |
|
34 | 32 | use private::Selectors; |
35 | 33 |
|
| 34 | +/// A list of selectors. |
36 | 35 | pub type SelectorList<'i> = parcel_selectors::SelectorList<'i, Selectors>; |
| 36 | +/// A CSS selector, including a list of components. |
37 | 37 | pub type Selector<'i> = parcel_selectors::parser::Selector<'i, Selectors>; |
| 38 | +/// An individual component within a selector. |
38 | 39 | pub type Component<'i> = parcel_selectors::parser::Component<'i, Selectors>; |
| 40 | +/// A combinator. |
39 | 41 | pub use parcel_selectors::parser::Combinator; |
40 | 42 |
|
41 | 43 | impl<'i> SelectorImpl<'i> for Selectors { |
@@ -307,101 +309,159 @@ impl<'a, 'o, 'i, T> parcel_selectors::parser::Parser<'i> for SelectorParser<'a, |
307 | 309 | } |
308 | 310 |
|
309 | 311 | enum_property! { |
| 312 | + /// The [:dir()](https://drafts.csswg.org/selectors-4/#the-dir-pseudo) pseudo class. |
310 | 313 | #[derive(Eq)] |
311 | 314 | pub enum Direction { |
| 315 | + /// Left to right |
312 | 316 | Ltr, |
| 317 | + /// Right to left |
313 | 318 | Rtl, |
314 | 319 | } |
315 | 320 | } |
316 | 321 |
|
317 | | -/// https://drafts.csswg.org/selectors-4/#structural-pseudos |
| 322 | +/// A pseudo class. |
318 | 323 | #[derive(Clone, PartialEq)] |
319 | 324 | pub enum PseudoClass<'i> { |
320 | 325 | // https://drafts.csswg.org/selectors-4/#linguistic-pseudos |
| 326 | + /// The [:lang()](https://drafts.csswg.org/selectors-4/#the-lang-pseudo) pseudo class. |
321 | 327 | Lang(Vec<CowArcStr<'i>>), |
| 328 | + /// The [:dir()](https://drafts.csswg.org/selectors-4/#the-dir-pseudo) pseudo class. |
322 | 329 | Dir(Direction), |
323 | 330 |
|
324 | 331 | // https://drafts.csswg.org/selectors-4/#useraction-pseudos |
| 332 | + /// The [:hover](https://drafts.csswg.org/selectors-4/#the-hover-pseudo) pseudo class. |
325 | 333 | Hover, |
| 334 | + /// The [:active](https://drafts.csswg.org/selectors-4/#the-active-pseudo) pseudo class. |
326 | 335 | Active, |
| 336 | + /// The [:focus](https://drafts.csswg.org/selectors-4/#the-focus-pseudo) pseudo class. |
327 | 337 | Focus, |
| 338 | + /// The [:focus-visible](https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo) pseudo class. |
328 | 339 | FocusVisible, |
| 340 | + /// The [:focus-within](https://drafts.csswg.org/selectors-4/#the-focus-within-pseudo) pseudo class. |
329 | 341 | FocusWithin, |
330 | 342 |
|
331 | 343 | // https://drafts.csswg.org/selectors-4/#time-pseudos |
| 344 | + /// The [:current](https://drafts.csswg.org/selectors-4/#the-current-pseudo) pseudo class. |
332 | 345 | Current, |
| 346 | + /// The [:past](https://drafts.csswg.org/selectors-4/#the-past-pseudo) pseudo class. |
333 | 347 | Past, |
| 348 | + /// The [:future](https://drafts.csswg.org/selectors-4/#the-future-pseudo) pseudo class. |
334 | 349 | Future, |
335 | 350 |
|
336 | 351 | // https://drafts.csswg.org/selectors-4/#resource-pseudos |
| 352 | + /// The [:playing](https://drafts.csswg.org/selectors-4/#selectordef-playing) pseudo class. |
337 | 353 | Playing, |
| 354 | + /// The [:paused](https://drafts.csswg.org/selectors-4/#selectordef-paused) pseudo class. |
338 | 355 | Paused, |
| 356 | + /// The [:seeking](https://drafts.csswg.org/selectors-4/#selectordef-seeking) pseudo class. |
339 | 357 | Seeking, |
| 358 | + /// The [:buffering](https://drafts.csswg.org/selectors-4/#selectordef-buffering) pseudo class. |
340 | 359 | Buffering, |
| 360 | + /// The [:stalled](https://drafts.csswg.org/selectors-4/#selectordef-stalled) pseudo class. |
341 | 361 | Stalled, |
| 362 | + /// The [:muted](https://drafts.csswg.org/selectors-4/#selectordef-muted) pseudo class. |
342 | 363 | Muted, |
| 364 | + /// The [:volume-locked](https://drafts.csswg.org/selectors-4/#selectordef-volume-locked) pseudo class. |
343 | 365 | VolumeLocked, |
344 | 366 |
|
345 | | - // https://fullscreen.spec.whatwg.org/#:fullscreen-pseudo-class |
| 367 | + /// The [:fullscreen](https://fullscreen.spec.whatwg.org/#:fullscreen-pseudo-class) pseudo class. |
346 | 368 | Fullscreen(VendorPrefix), |
347 | 369 |
|
348 | | - // https://drafts.csswg.org/selectors-4/#the-defined-pseudo |
| 370 | + /// The [:defined](https://drafts.csswg.org/selectors-4/#the-defined-pseudo) pseudo class. |
349 | 371 | Defined, |
350 | 372 |
|
351 | 373 | // https://drafts.csswg.org/selectors-4/#location |
| 374 | + /// The [:any-link](https://drafts.csswg.org/selectors-4/#the-any-link-pseudo) pseudo class. |
352 | 375 | AnyLink(VendorPrefix), |
| 376 | + /// The [:link](https://drafts.csswg.org/selectors-4/#link-pseudo) pseudo class. |
353 | 377 | Link, |
| 378 | + /// The [:local-link](https://drafts.csswg.org/selectors-4/#the-local-link-pseudo) pseudo class. |
354 | 379 | LocalLink, |
| 380 | + /// The [:target](https://drafts.csswg.org/selectors-4/#the-target-pseudo) pseudo class. |
355 | 381 | Target, |
| 382 | + /// The [:target-within](https://drafts.csswg.org/selectors-4/#the-target-within-pseudo) pseudo class. |
356 | 383 | TargetWithin, |
| 384 | + /// The [:visited](https://drafts.csswg.org/selectors-4/#visited-pseudo) pseudo class. |
357 | 385 | Visited, |
358 | 386 |
|
359 | 387 | // https://drafts.csswg.org/selectors-4/#input-pseudos |
| 388 | + /// The [:enabled](https://drafts.csswg.org/selectors-4/#enabled-pseudo) pseudo class. |
360 | 389 | Enabled, |
| 390 | + /// The [:disabled](https://drafts.csswg.org/selectors-4/#disabled-pseudo) pseudo class. |
361 | 391 | Disabled, |
| 392 | + /// The [:read-only](https://drafts.csswg.org/selectors-4/#read-only-pseudo) pseudo class. |
362 | 393 | ReadOnly(VendorPrefix), |
| 394 | + /// The [:read-write](https://drafts.csswg.org/selectors-4/#read-write-pseudo) pseudo class. |
363 | 395 | ReadWrite(VendorPrefix), |
| 396 | + /// The [:placeholder-shown](https://drafts.csswg.org/selectors-4/#placeholder) pseudo class. |
364 | 397 | PlaceholderShown(VendorPrefix), |
| 398 | + /// The [:default](https://drafts.csswg.org/selectors-4/#the-default-pseudo) pseudo class. |
365 | 399 | Default, |
| 400 | + /// The [:checked](https://drafts.csswg.org/selectors-4/#checked) pseudo class. |
366 | 401 | Checked, |
| 402 | + /// The [:indeterminate](https://drafts.csswg.org/selectors-4/#indeterminate) pseudo class. |
367 | 403 | Indeterminate, |
| 404 | + /// The [:blank](https://drafts.csswg.org/selectors-4/#blank) pseudo class. |
368 | 405 | Blank, |
| 406 | + /// The [:valid](https://drafts.csswg.org/selectors-4/#valid-pseudo) pseudo class. |
369 | 407 | Valid, |
| 408 | + /// The [:invalid](https://drafts.csswg.org/selectors-4/#invalid-pseudo) pseudo class. |
370 | 409 | Invalid, |
| 410 | + /// The [:in-range](https://drafts.csswg.org/selectors-4/#in-range-pseudo) pseudo class. |
371 | 411 | InRange, |
| 412 | + /// The [:out-of-range](https://drafts.csswg.org/selectors-4/#out-of-range-pseudo) pseudo class. |
372 | 413 | OutOfRange, |
| 414 | + /// The [:required](https://drafts.csswg.org/selectors-4/#required-pseudo) pseudo class. |
373 | 415 | Required, |
| 416 | + /// The [:optional](https://drafts.csswg.org/selectors-4/#optional-pseudo) pseudo class. |
374 | 417 | Optional, |
| 418 | + /// The [:user-valid](https://drafts.csswg.org/selectors-4/#user-valid-pseudo) pseudo class. |
375 | 419 | UserValid, |
| 420 | + /// The [:used-invalid](https://drafts.csswg.org/selectors-4/#user-invalid-pseudo) pseudo class. |
376 | 421 | UserInvalid, |
377 | 422 |
|
378 | | - // https://html.spec.whatwg.org/multipage/semantics-other.html#selector-autofill |
| 423 | + /// The [:autofill](https://html.spec.whatwg.org/multipage/semantics-other.html#selector-autofill) pseudo class. |
379 | 424 | Autofill(VendorPrefix), |
380 | 425 |
|
381 | 426 | // CSS modules |
| 427 | + /// The CSS modules :local() pseudo class. |
382 | 428 | Local(Box<Selector<'i>>), |
| 429 | + /// The CSS modules :global() pseudo class. |
383 | 430 | Global(Box<Selector<'i>>), |
384 | 431 |
|
385 | | - // https://webkit.org/blog/363/styling-scrollbars/ |
| 432 | + /// A [webkit scrollbar](https://webkit.org/blog/363/styling-scrollbars/) pseudo class. |
386 | 433 | WebKitScrollbar(WebKitScrollbarPseudoClass), |
387 | 434 |
|
| 435 | + /// An unknown pseudo class. |
388 | 436 | Custom(CowArcStr<'i>), |
| 437 | + /// An unknown functional pseudo class. |
389 | 438 | CustomFunction(CowArcStr<'i>, TokenList<'i>), |
390 | 439 | } |
391 | 440 |
|
392 | | -/// https://webkit.org/blog/363/styling-scrollbars/ |
| 441 | +/// A [webkit scrollbar](https://webkit.org/blog/363/styling-scrollbars/) pseudo class. |
393 | 442 | #[derive(Clone, Eq, PartialEq)] |
394 | 443 | pub enum WebKitScrollbarPseudoClass { |
| 444 | + /// :horizontal |
395 | 445 | Horizontal, |
| 446 | + /// :vertical |
396 | 447 | Vertical, |
| 448 | + /// :decrement |
397 | 449 | Decrement, |
| 450 | + /// :increment |
398 | 451 | Increment, |
| 452 | + /// :start |
399 | 453 | Start, |
| 454 | + /// :end |
400 | 455 | End, |
| 456 | + /// :double-button |
401 | 457 | DoubleButton, |
| 458 | + /// :single-button |
402 | 459 | SingleButton, |
| 460 | + /// :no-button |
403 | 461 | NoButton, |
| 462 | + /// :corner-present |
404 | 463 | CornerPresent, |
| 464 | + /// :window-inactive |
405 | 465 | WindowInactive, |
406 | 466 | } |
407 | 467 |
|
@@ -664,26 +724,44 @@ impl<'i> PseudoClass<'i> { |
664 | 724 | } |
665 | 725 | } |
666 | 726 |
|
| 727 | +/// A pseudo element. |
667 | 728 | #[derive(PartialEq, Clone, Debug)] |
668 | 729 | pub enum PseudoElement<'i> { |
| 730 | + /// The [::after](https://drafts.csswg.org/css-pseudo-4/#selectordef-after) pseudo element. |
669 | 731 | After, |
| 732 | + /// The [::before](https://drafts.csswg.org/css-pseudo-4/#selectordef-before) pseudo element. |
670 | 733 | Before, |
| 734 | + /// The [::first-line](https://drafts.csswg.org/css-pseudo-4/#first-line-pseudo) pseudo element. |
671 | 735 | FirstLine, |
| 736 | + /// The [::first-letter](https://drafts.csswg.org/css-pseudo-4/#first-letter-pseudo) pseudo element. |
672 | 737 | FirstLetter, |
| 738 | + /// The [::selection](https://drafts.csswg.org/css-pseudo-4/#selectordef-selection) pseudo element. |
673 | 739 | Selection(VendorPrefix), |
| 740 | + /// The [::placeholder](https://drafts.csswg.org/css-pseudo-4/#placeholder-pseudo) pseudo element. |
674 | 741 | Placeholder(VendorPrefix), |
| 742 | + /// The [::marker](https://drafts.csswg.org/css-pseudo-4/#marker-pseudo) pseudo element. |
675 | 743 | Marker, |
| 744 | + /// The [::backdrop](https://fullscreen.spec.whatwg.org/#::backdrop-pseudo-element) pseudo element. |
676 | 745 | Backdrop(VendorPrefix), |
| 746 | + /// The [::file-selector-button](https://drafts.csswg.org/css-pseudo-4/#file-selector-button-pseudo) pseudo element. |
677 | 747 | FileSelectorButton(VendorPrefix), |
| 748 | + /// A [webkit scrollbar](https://webkit.org/blog/363/styling-scrollbars/) pseudo element. |
678 | 749 | WebKitScrollbar(WebKitScrollbarPseudoElement), |
| 750 | + /// The [::cue](https://w3c.github.io/webvtt/#the-cue-pseudo-element) pseudo element. |
679 | 751 | Cue, |
| 752 | + /// The [::cue-region](https://w3c.github.io/webvtt/#the-cue-region-pseudo-element) pseudo element. |
680 | 753 | CueRegion, |
| 754 | + /// The [::cue()](https://w3c.github.io/webvtt/#cue-selector) functional pseudo element. |
681 | 755 | CueFunction(Box<Selector<'i>>), |
| 756 | + /// The [::cue-region()](https://w3c.github.io/webvtt/#cue-region-selector) functional pseudo element. |
682 | 757 | CueRegionFunction(Box<Selector<'i>>), |
| 758 | + /// An unknown pseudo element. |
683 | 759 | Custom(CowArcStr<'i>), |
| 760 | + /// An unknown functional pseudo element. |
684 | 761 | CustomFunction(CowArcStr<'i>, TokenList<'i>), |
685 | 762 | } |
686 | 763 |
|
| 764 | +/// A [webkit scrollbar](https://webkit.org/blog/363/styling-scrollbars/) pseudo element. |
687 | 765 | #[derive(PartialEq, Eq, Clone, Debug, Hash)] |
688 | 766 | pub enum WebKitScrollbarPseudoElement { |
689 | 767 | /// ::-webkit-scrollbar |
|
0 commit comments