Skip to content

Releases: trananhtung/specificity

specificity v0.1.0

Choose a tag to compare

@trananhtung trananhtung released this 22 Jun 05:30

First release.

Calculate the CSS specificity (a, b, c) of a selector — the Rust counterpart of the specificity npm package. For CSS linters, cascade analysis, devtools, and CSS-in-JS.

use specificity::{specificity, Specificity};
assert_eq!(specificity("#id .cls a"), Specificity::new(1, 1, 1));
assert_eq!(specificity(":is(.a, #b)"), Specificity::new(1, 0, 0)); // max of args
assert!(specificity("#id") > specificity(".a.b.c"));               // Ord
  • specificity(selector) / specificity_list(list); Specificity is Ord + Display
  • Spec-accurate: :is/:not/:has/:nth-child(… of S) max-of-args, :where=0, pseudo-elements, namespaces, escapes, :global/:local
  • CSS comments stripped; pathological nesting handled (no stack overflow)
  • Zero dependencies; #![no_std]

Differential-tested against the real keeganstreet specificity (0 mismatches over 4312 selectors). Fills a real gap — no standalone specificity crate existed.

📦 https://crates.io/crates/specificity