From d4a8d6f352d765bcbd9ece0955c9bdf28fa87770 Mon Sep 17 00:00:00 2001 From: Bart Veneman <1536852+bartveneman@users.noreply.github.com> Date: Sat, 10 Jun 2023 09:17:54 +0200 Subject: [PATCH] Fix export of `compareSpecificity` (#333) fixes #323 --- package-lock.json | 16 ++++++++++------ package.json | 2 +- src/context-collection.js | 2 +- src/index.js | 25 +++++++++++++++++++------ src/selectors/utils.js | 18 ------------------ 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/package-lock.json b/package-lock.json index 34413ce..a05e76d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2137,9 +2137,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001375", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001375.tgz", - "integrity": "sha512-kWIMkNzLYxSvnjy0hL8w1NOaWNr2rn39RTAVyIwcw8juu60bZDWiF1/loOYANzjtJmy6qPgNmn38ro5Pygagdw==", + "version": "1.0.30001498", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001498.tgz", + "integrity": "sha512-LFInN2zAwx3ANrGCDZ5AKKJroHqNKyjXitdV5zRIVIaQlXKj3GmxUKagoKsjqUfckpAObPCEWnk5EeMlyMWcgw==", "dev": true, "funding": [ { @@ -2149,6 +2149,10 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ] }, @@ -6728,9 +6732,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001375", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001375.tgz", - "integrity": "sha512-kWIMkNzLYxSvnjy0hL8w1NOaWNr2rn39RTAVyIwcw8juu60bZDWiF1/loOYANzjtJmy6qPgNmn38ro5Pygagdw==", + "version": "1.0.30001498", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001498.tgz", + "integrity": "sha512-LFInN2zAwx3ANrGCDZ5AKKJroHqNKyjXitdV5zRIVIaQlXKj3GmxUKagoKsjqUfckpAObPCEWnk5EeMlyMWcgw==", "dev": true }, "chalk": { diff --git a/package.json b/package.json index 069c841..845eb06 100644 --- a/package.json +++ b/package.json @@ -52,4 +52,4 @@ "mangle": { "regex": "^_[^_]" } -} \ No newline at end of file +} diff --git a/src/context-collection.js b/src/context-collection.js index d5c5bad..9c922be 100644 --- a/src/context-collection.js +++ b/src/context-collection.js @@ -27,7 +27,7 @@ class ContextCollection { * @type {Map} */ diff --git a/src/index.js b/src/index.js index 2813bbd..a46b47c 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ import parse from 'css-tree/parser' import walk from 'css-tree/walker' import { calculate } from '@bramus/specificity/core' import { isSupportsBrowserhack, isMediaBrowserhack } from './atrules/atrules.js' -import { getComplexity, isAccessibility, compareSpecificity } from './selectors/utils.js' +import { getComplexity, isAccessibility } from './selectors/utils.js' import { colorFunctions, colorKeywords, namedColors, systemColors } from './values/colors.js' import { destructure, isSystemFont } from './values/destructure-font-shorthand.js' import { isValueKeyword } from './values/values.js' @@ -28,7 +28,7 @@ function ratio(part, total) { * Analyze CSS * @param {string} css */ -function analyze(css) { +export function analyze(css) { let start = Date.now() /** @@ -749,7 +749,20 @@ function analyze(css) { } } -export { - analyze, - compareSpecificity, -} +/** + * Compare specificity A to Specificity B + * @param {Specificity} a - Specificity A + * @param {Specificity} b - Specificity B + * @returns {number} sortIndex - 0 when a==b, 1 when ab + */ +export function compareSpecificity(a, b) { + if (a[0] === b[0]) { + if (a[1] === b[1]) { + return b[2] - a[2] + } + + return b[1] - a[1] + } + + return b[0] - a[0] +} \ No newline at end of file diff --git a/src/selectors/utils.js b/src/selectors/utils.js index c76edc2..9ed4852 100644 --- a/src/selectors/utils.js +++ b/src/selectors/utils.js @@ -2,24 +2,6 @@ import walk from 'css-tree/walker' import { startsWith, strEquals } from '../string-utils.js' import { hasVendorPrefix } from '../vendor-prefix.js' -/** - * Compare specificity A to Specificity B - * @param {[number,number,number]} a - Specificity A - * @param {[number,number,number]} b - Specificity B - * @returns {number} sortIndex - 0 when a==b, 1 when ab - */ -export function compareSpecificity(a, b) { - if (a[0] === b[0]) { - if (a[1] === b[1]) { - return b[2] - a[2] - } - - return b[1] - a[1] - } - - return b[0] - a[0] -} - /** * * @param {import('css-tree').SelectorList} selectorListAst