MCPcopy
hub / github.com/tailwindlabs/tailwindcss / getClassOrder

Function getClassOrder

packages/tailwindcss/src/sort.ts:4–30  ·  view source on GitHub ↗
(design: DesignSystem, classes: string[])

Source from the content-addressed store, hash-verified

2import type { DesignSystem } from './design-system'
3
4export function getClassOrder(design: DesignSystem, classes: string[]): [string, bigint | null][] {
5 // Generate a sorted AST
6 let { astNodes, nodeSorting } = compileCandidates(Array.from(classes), design)
7
8 // Map class names to their order in the AST
9 // `null` indicates a non-Tailwind class
10 let sorted = new Map<string, bigint | null>(classes.map((className) => [className, null]))
11
12 // Assign each class a unique, sorted number
13 let idx = 0n
14
15 for (let node of astNodes) {
16 let candidate = nodeSorting.get(node)?.candidate
17 if (!candidate) continue
18
19 // When multiple rules match a candidate
20 // always take the position of the first one
21 sorted.set(candidate, sorted.get(candidate) ?? idx++)
22 }
23
24 // Pair classes with their assigned sorting number
25 return classes.map((className) => [
26 //
27 className,
28 sorted.get(className) ?? null,
29 ])
30}

Callers 1

getClassOrderFunction · 0.90

Calls 3

compileCandidatesFunction · 0.90
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected