buildPluginApi() — tailwindcss Function Reference
Architecture documentation for the buildPluginApi() function in plugin-api.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 2efa0a66_c375_c031_24ad_1f7509bb9b14["buildPluginApi()"] af1a6ece_0432_a556_fd63_8cb4a91f12ad["plugin-api.ts"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|defined in| af1a6ece_0432_a556_fd63_8cb4a91f12ad 1a022c10_a26e_d793_740c_267a533619c4["upgradeToFullPluginSupport()"] 1a022c10_a26e_d793_740c_267a533619c4 -->|calls| 2efa0a66_c375_c031_24ad_1f7509bb9b14 e9bc21ee_17e0_ae31_b0b1_588755ffe2c6["objectToAst()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| e9bc21ee_17e0_ae31_b0b1_588755ffe2c6 cbcebe85_5027_3db6_180a_0ceaa8acbbfb["substituteFunctions()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| cbcebe85_5027_3db6_180a_0ceaa8acbbfb f9b19679_c1f0_28d6_4d1a_31a10c52e42d["atRule()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| f9b19679_c1f0_28d6_4d1a_31a10c52e42d ed78da58_8727_ad98_120c_61f35cea357a["walk()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| ed78da58_8727_ad98_120c_61f35cea357a 18a889b1_55e1_f503_1b79_6fc01095ebca["entries()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| 18a889b1_55e1_f503_1b79_6fc01095ebca e4fb3115_ed56_fc92_888c_5174adbc3ff5["parseVariantValue()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| e4fb3115_ed56_fc92_888c_5174adbc3ff5 759ab8d0_0e80_5789_e945_a5f814874e59["compoundsForSelectors()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| 759ab8d0_0e80_5789_e945_a5f814874e59 34338b14_fec6_6308_0fd7_15af8d4da01b["fromAst()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| 34338b14_fec6_6308_0fd7_15af8d4da01b 687e64a5_22c0_2f4f_117f_d39492284510["group()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| 687e64a5_22c0_2f4f_117f_d39492284510 f712ed47_45d4_4e5a_dd73_fdefa1da71da["segment()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| f712ed47_45d4_4e5a_dd73_fdefa1da71da a0e7559e_bcba_7de4_f51b_c146c7957bfd["replaceNestedClassNameReferences()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| a0e7559e_bcba_7de4_f51b_c146c7957bfd 96876152_5423_5f9b_9f88_1db666070351["substituteAtApply()"] 2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| 96876152_5423_5f9b_9f88_1db666070351 style 2efa0a66_c375_c031_24ad_1f7509bb9b14 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/compat/plugin-api.ts lines 93–542
export function buildPluginApi({
designSystem,
ast,
resolvedConfig,
featuresRef,
referenceMode,
src,
}: {
designSystem: DesignSystem
ast: AstNode[]
resolvedConfig: ResolvedConfig
featuresRef: { current: Features }
referenceMode: boolean
src: SourceLocation | undefined
}): PluginAPI {
let api: PluginAPI = {
addBase(css) {
if (referenceMode) return
let baseNodes = objectToAst(css)
featuresRef.current |= substituteFunctions(baseNodes, designSystem)
let rule = atRule('@layer', 'base', baseNodes)
walk([rule], (node) => {
node.src = src
})
ast.push(rule)
},
addVariant(name, variant) {
if (!IS_VALID_VARIANT_NAME.test(name)) {
throw new Error(
`\`addVariant('${name}')\` defines an invalid variant name. Variants should only contain alphanumeric, dashes, or underscore characters and start with a lowercase letter or number.`,
)
}
// Ignore variants emitting v3 `:merge(…)` rules. In v4, the `group-*` and `peer-*` variants
// compound automatically.
if (typeof variant === 'string') {
if (variant.includes(':merge(')) return
} else if (Array.isArray(variant)) {
if (variant.some((v) => v.includes(':merge('))) return
} else if (typeof variant === 'object') {
function keyIncludes(object: Record<string, any>, search: string): boolean {
return Object.entries(object).some(
([key, value]) =>
key.includes(search) || (typeof value === 'object' && keyIncludes(value, search)),
)
}
if (keyIncludes(variant, ':merge(')) return
}
// Single selector or multiple parallel selectors
if (typeof variant === 'string' || Array.isArray(variant)) {
designSystem.variants.static(
name,
(r) => {
r.nodes = parseVariantValue(variant, r.nodes)
},
{
compounds: compoundsForSelectors(typeof variant === 'string' ? [variant] : variant),
},
)
}
// CSS-in-JS object
else if (typeof variant === 'object') {
designSystem.variants.fromAst(name, objectToAst(variant), designSystem)
}
},
matchVariant(name, fn, options) {
function resolveVariantValue<T extends Parameters<typeof fn>[0]>(
value: T,
modifier: CandidateModifier | null,
nodes: AstNode[],
): AstNode[] {
let resolved = fn(value, { modifier: modifier?.value ?? null })
return parseVariantValue(resolved, nodes)
}
try {
// Sample variant value and ignore variants emitting v3 `:merge` rules. In
// v4, the `group-*` and `peer-*` variants compound automatically.
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does buildPluginApi() do?
buildPluginApi() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/compat/plugin-api.ts.
Where is buildPluginApi() defined?
buildPluginApi() is defined in packages/tailwindcss/src/compat/plugin-api.ts at line 93.
What does buildPluginApi() call?
buildPluginApi() calls 24 function(s): atRule, compoundsForSelectors, createThemeFn, entries, fromAst, functional, get, group, and 16 more.
What calls buildPluginApi()?
buildPluginApi() is called by 1 function(s): upgradeToFullPluginSupport.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free