Utilities Class — tailwindcss Architecture
Architecture documentation for the Utilities class in utilities.ts from the tailwindcss codebase.
Entity Profile
Relationship Graph
Source Code
packages/tailwindcss/src/utilities.ts lines 100–154
export class Utilities {
private utilities = new DefaultMap<string, Utility[]>(() => [])
private completions = new Map<string, () => SuggestionGroup[]>()
static(name: string, compileFn: CompileFn<'static'>) {
this.utilities.get(name).push({ kind: 'static', compileFn })
}
functional(name: string, compileFn: CompileFn<'functional'>, options?: UtilityOptions) {
this.utilities.get(name).push({ kind: 'functional', compileFn, options })
}
has(name: string, kind: 'static' | 'functional') {
return this.utilities.has(name) && this.utilities.get(name).some((fn) => fn.kind === kind)
}
get(name: string) {
return this.utilities.has(name) ? this.utilities.get(name) : []
}
getCompletions(name: string): SuggestionGroup[] {
if (this.has(name, 'static')) {
return (
this.completions.get(name)?.() ?? [{ supportsNegative: false, values: [], modifiers: [] }]
)
}
return this.completions.get(name)?.() ?? []
}
suggest(name: string, groups: () => SuggestionGroup[]) {
let existingGroups = this.completions.get(name)
if (existingGroups) {
this.completions.set(name, () => [...existingGroups?.(), ...groups?.()])
} else {
this.completions.set(name, groups)
}
}
keys(kind: 'static' | 'functional') {
let keys: string[] = []
for (let [key, fns] of this.utilities.entries()) {
for (let fn of fns) {
if (fn.kind === kind) {
keys.push(key)
break
}
}
}
return keys
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free