Crates.io | lewp-css |
lib.rs | lewp-css |
version | 0.2.0 |
source | src |
created_at | 2022-03-04 16:27:17.465045 |
updated_at | 2022-03-26 09:57:54.198451 |
description | Domain model for CSS Stylesheets. Allowing effective minification and transformations such as autoprefixing and removal by other crates. Updated and maintained version for lewp. |
homepage | https://github.com/emirror-de/lewp-rs |
repository | https://github.com/emirror-de/lewp-rs.git |
max_upload_size | |
id | 543582 |
size | 756,037 |
This repo is a fork of https://github.com/lemonrock/css. I liked the initial work and wanted to further maintain it.
Because this crate seems to be no longer actively maintained and it was not possible for me to get a response from the author, this repository is published at crates.io under the name lewp-css
.
lewp-css is a rust crate that implements a CSS stylesheet parser and serializer. It uses the cssparser crate. It wraps source code originally forked of the style source code from servo. The great efforts and achievements of those at Mozilla that have built Servo are very much appreciated.
To get going add a dependency to Cargo.toml, eg:-
[dependencies]
lewp-css = "*"
And then add some simple code, say to lib.rs
of the form:-
use ::lewp_css::Stylesheet;
// Parse
let stylesheetUtf8String: String = ...;
let stylesheet = Stylesheet::parse(&stylesheetUtf8String).expect("Wasn't a valid stylesheet");
// Serialize
use ::std::fmt::Write;
let mut destination: Write = ...
const include_source_urls: bool = false;
stylesheet.to_css(&mut destination, include_source_urls).expect("Wrote out a stylesheet");
I've built this crate to allow me to create Rust-ified variants of Autoprefixer and PurifyCSS. Why? Because my cordial web server runs facing the internet, and, given the nature of NodeJS code, it's not acceptable to have it as a dependency. It can also be used to evaluate @media
, @viewport
and calc() / var() / attr()
rules and expressions.
It is, therefore, quite incomplete. I'd welcome patches to add support for parsing common (and less common) CSS properties. However, full support for parsing and calculating calc()
, attr()
and var()
is present.
Please note that unlike a web browser [css] does not ignore what it does not understand. This is deliberate; it makes it far easier to catch assumptions in CSS code. Please patch the source if there's something you think should be parsed.
This crate will break compatibility regularly and often as it matures. It also pays no attention whatsoever to semver. At some point, if I persist with it, it should settle down and then be suitable for a more considered approach.
[css] is starting to move away from its origins with a different approach for calc()
, attr()
, support for page selectors, evaluating attr()
, not normalising shorthand properties, and the like, all with the intention of making it easier to manipulate, optimize and serialize CSS.
The license for this project is Mozilla Public License 2.0 (MPL-2.0). The code forked from Servo is also licensed under Mozilla Public License 2.0. The Servo Developers, part of the Mozilla Foundation, retain copyright on the unaltered style source code, and also its implementation approach, forked from Servo.
There is a temporary fork of the selectors crate (and its dependency servo_arc), also from Servo, in src/selectors/temporary_fork (from "https://github.com/servo/servo", rev = "4f984a6428a0f497e311a0800efa55166c15aac6"). This will be removed once a newer version of the selectors crate (such as 0.19.0) is published to crates.io.
These are minor adjustments to CSS as it is parsed or serialized, mostly to make it more size efficient.
aural
media type is converted to speech
resolution
>=
)