Releases: bramus/specificity
Releases · bramus/specificity
2.3.0 (2023.04.08)
Changes & Additions
- ✨ Add view-transition specificity calculation
- 🐛 Do not throw when :is/:any/:matches do not contain children
- 🐛 Fix case sensitivity issue
Thanks to @bartveneman for contributing these changes and additions.
2.2.0 (2022.12.14)
Changes & Additions
- ✨ Support
::slotted()
- ✨ Support
:host()
and:host-context()
2.1.0 (2022.04.01)
Changes & Additions
- ✨ Also accept single CSSTree
Selector
ASTs as input intocalculate
2.0.0 (2022.03.30)
The main change in this next iteration of @bramus/specificity
is that everything is now exposed as part of a newly introduced Specificity
class. The class represents specificity value, and also holds several static methods to calculate and work with specificities.
Changes & Additions
- ✨ Introduce and use a
Specificity
class - ✨ Support SelectorLists
- ♻️ Import only
selector-parser
fromcss-tree
(reducing bundle size) - ✨ Expose new utility functions for comparing, sorting, and filtering (static or standalone)
- ✨ Add Type Definitions
- ✨ Expose the CLI script
- 🚑 Fix CJS build
Code Example
import Specificity from '@bramus/specificity';
// ✨ Calculate specificity for each Selector in the given Selector List
const specificities = Specificity.calculate('header:where(#top) nav li:nth-child(2n), #doormat');
// 🚚 The values in the array are instances of the Specificity class
const specificity = specificities[0]; // Instance of Specificity
// 🛠 From an instance you can get the value in various formats
specificity.value; // { a: 0, b: 1, c: 3 }
specificity.a; // 0
specificity.b; // 1
specificity.c; // 3
specificity.toString(); // "(0,1,3)"
specificity.toArray(); // [0, 1, 3]
specificity.toObject(); // { a: 0, b: 1, c: 3 }
// 💡 From an instance you can also get the selector (as a String)
specificity.selectorString(); // "header:where(#top) nav li:nth-child(2n)"
// 💻 These instances also play nice with JSON.stringify()
console.log(JSON.stringify(specificity));
// {
// "selector": 'header:where(#top) nav li:nth-child(2n)',
// "asObject": { "a": 0, "b": 1, "c": 3 },
// "asArray": [0, 1, 3],
// "asString": "(0,1,3)",
// }
// 🔀 Need to compare against another instance? That's possible!
specificity.isEqualTo(specificities[1])); // false
specificity.isGreaterThan(specificities[1])); // false
specificity.isLessThan(specificities[1])); // true
2.0.0-beta.11 (2022.03.22)
Changing since 2.0.0-beta.9
- REFACTOR: No longer expose
calculate
or any of the utility methods from the main file. Instead, provide them as static methods onSpecificity
which is now the default export. - REFACTOR: All utility methods that required one single array before, now work with an arbitrary number of arguments
- REFACTOR: Rename
ascending
/descending
tosortAsc
/sortDesc
- REMOVE: No longer expose standalone
sort
2.0.0-beta.9 (2022.03.11)
Changes since 2.0.0-beta.8
- ♻️ Rename Specificity.equals to Specificity.isEqualTo
2.0.0-beta.8 (2022.03.11)
Changes since 2.0.0-beta.7
- 🚑 Fix typings
- 🐛 Include "bin" in package-lock.json
2.0.0-beta.7 (2022.03.10)
Changes since 2.0.0-beta.2:
- ✨ Types: Specificity: Allow selector to be a string
- ✨ Don't unnecessarily try parsing AST if no
selectorList
is given - ✨ Add Type Definitions
- ✨ Expose the CLI script
- ♻️ Rework export structure, adding subpath exports along the way
- ♻️ Internal Code Refactors
2.0.0-beta.2 (2022.03.06)
- REFACTOR: Rename
lowest
/highest
tomin
/max
2.0.0-beta.1 (2022.02.28)
- REFACTOR: Import only selector-parser from
css-tree
(reducing bundle size)