Skip to main content

whisker_css/
lib.rs

1//! # whisker-css
2//!
3//! Type-safe CSS [`Css`] builder for Whisker, mirroring the Lynx
4//! CSS surface 1-to-1.
5//!
6//! The crate is split into four layers:
7//!
8//! - [`data_type`] — the 11 data types Lynx exposes at
9//!   <https://lynxjs.org/api/css/data-type.html>. Each is mapped to a
10//!   Rust `enum` or `struct` with a [`ToCss`] implementation that
11//!   round-trips back to its CSS source form.
12//! - [`data_type_ext`] — data types Lynx uses inline inside property
13//!   pages but does not document independently (`<integer>`,
14//!   `<easing-function>`, `<position>`, the 147 [`NamedColor`]s).
15//! - [`keyword`] — closed keyword enums for property values
16//!   (`Display`, `FlexDirection`, …). Values Lynx explicitly rejects
17//!   (`position: static`, `overflow: scroll`) are absent from the
18//!   enums so they cause compile errors instead of silent runtime
19//!   warnings.
20//! - [`prop`] — one method per CSS longhand property on [`Css`],
21//!   each carrying a documentation link to the corresponding
22//!   `lynxjs.org/api/css/properties/<name>` page.
23//! - [`shorthand`] — compound builders (`Border`, `Background`,
24//!   `Transform`, `Transition`, `Animation`, `Flex`) for properties
25//!   whose CSS shorthand combines multiple longhands.
26//!
27//! Numeric literals get their unit through extension traits in
28//! [`ext`]: write `px(8)`, `8.px()`, or `0.5.rem()` to construct a
29//! [`data_type::Length`].
30//!
31//! ```ignore
32//! use whisker_css::ext::*;
33//! use whisker_css::{Css, FlexDirection, Color};
34//!
35//! let s = Css::new()
36//!     .display_flex()
37//!     .flex_direction(FlexDirection::Column)
38//!     .padding(px(12))
39//!     .background_color(Color::hex(0x1A1A2E))
40//!     .border_radius(px(10));
41//! ```
42
43#![warn(missing_docs)]
44
45mod css;
46pub mod data_type;
47pub mod data_type_ext;
48pub mod ext;
49pub mod keyword;
50pub mod prop;
51pub mod shorthand;
52mod to_css;
53pub mod value;
54
55// `css!(name: value, …)` — kwarg syntax for the [`Css`] builder.
56// Lives in `whisker-macros` so it can be a proc macro (the
57// partial-input recovery driving rust-analyzer completion needs
58// fine-grained control over the expansion). Re-exported here so
59// callers can spell `whisker_css::css!` without a direct dep on
60// the macros crate.
61pub use whisker_macros::css;
62
63pub use crate::css::{Css, CssProp};
64pub use crate::data_type::{
65    Angle, CalcExpr, Color, ColorStop, CssString, FitContent, Gradient, Length, LengthPercentage,
66    LinearDirection, MaxContent, NamedColor, Number, Percentage, RadialShape, StopPosition, Time,
67};
68pub use crate::data_type_ext::{EasingFunction, Integer, Position};
69pub use crate::keyword::*;
70pub use crate::shorthand::{
71    Animation, Background, BackgroundLayer, Border, Flex, Margin, MarginValue, Padding, Transform,
72    TransformFn, Transition,
73};
74pub use crate::to_css::ToCss;
75pub use crate::value::{
76    BorderRadius, FlexBasis, GridLine, GridTemplate, ImageRef, LineHeight, Repeated, Size,
77};