compare-breakpoints.ts — tailwindcss Source File
Architecture documentation for compare-breakpoints.ts, a typescript file in the tailwindcss codebase. 0 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR 51f244f2_138c_0d69_05db_b2df310d0f23["compare-breakpoints.ts"] 340330a5_8048_84e2_77ad_8f6da2f8b8d0["container.ts"] 340330a5_8048_84e2_77ad_8f6da2f8b8d0 --> 51f244f2_138c_0d69_05db_b2df310d0f23 2bc6f8eb_6339_d09c_79df_e9025a479c97["utilities.ts"] 2bc6f8eb_6339_d09c_79df_e9025a479c97 --> 51f244f2_138c_0d69_05db_b2df310d0f23 db9eae47_695c_23c3_68bd_bae5bb363efe["variants.ts"] db9eae47_695c_23c3_68bd_bae5bb363efe --> 51f244f2_138c_0d69_05db_b2df310d0f23 style 51f244f2_138c_0d69_05db_b2df310d0f23 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
export function compareBreakpoints(a: string, z: string, direction: 'asc' | 'desc') {
if (a === z) return 0
// Assumption: when a `(` exists, we are dealing with a CSS function.
//
// E.g.: `calc(100% - 1rem)`
let aIsCssFunction = a.indexOf('(')
let zIsCssFunction = z.indexOf('(')
let aBucket =
aIsCssFunction === -1
? // No CSS function found, bucket by unit instead
a.replace(/[\d.]+/g, '')
: // CSS function found, bucket by function name
a.slice(0, aIsCssFunction)
let zBucket =
zIsCssFunction === -1
? // No CSS function found, bucket by unit
z.replace(/[\d.]+/g, '')
: // CSS function found, bucket by function name
z.slice(0, zIsCssFunction)
let order =
// Compare by bucket name
(aBucket === zBucket ? 0 : aBucket < zBucket ? -1 : 1) ||
// If bucket names are the same, compare by value
(direction === 'asc' ? parseInt(a) - parseInt(z) : parseInt(z) - parseInt(a))
// If the groups are the same, and the contents are not numbers, the
// `order` will result in `NaN`. In this case, we want to make sorting
// stable by falling back to a string comparison.
//
// This can happen when using CSS functions such as `calc`.
//
// E.g.:
//
// - `min-[calc(100%-1rem)]` and `min-[calc(100%-2rem)]`
// - `@[calc(100%-1rem)]` and `@[calc(100%-2rem)]`
//
// In this scenario, we want to alphabetically sort `calc(100%-1rem)` and
// `calc(100%-2rem)` to make it deterministic.
if (Number.isNaN(order)) {
return a < z ? -1 : 1
}
return order
}
Domain
Subdomains
Functions
Imported By
Source
Frequently Asked Questions
What does compare-breakpoints.ts do?
compare-breakpoints.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the OxideEngine domain, Extractor subdomain.
What functions are defined in compare-breakpoints.ts?
compare-breakpoints.ts defines 1 function(s): compareBreakpoints.
What files import compare-breakpoints.ts?
compare-breakpoints.ts is imported by 3 file(s): container.ts, utilities.ts, variants.ts.
Where is compare-breakpoints.ts in the architecture?
compare-breakpoints.ts is located at packages/tailwindcss/src/utils/compare-breakpoints.ts (domain: OxideEngine, subdomain: Extractor, directory: packages/tailwindcss/src/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free