Home / Function/ buildPluginApi() — tailwindcss Function Reference

buildPluginApi() — tailwindcss Function Reference

Architecture documentation for the buildPluginApi() function in plugin-api.ts from the tailwindcss codebase.

Function typescript Oxide Extractor calls 24 called by 1

Entity Profile

Dependency Diagram

graph TD
  31653e23_464a_3652_4a48_0c82332a92c4["buildPluginApi()"]
  da5d1116_ab2a_437a_6b13_c1429fd546fa["plugin-api.ts"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|defined in| da5d1116_ab2a_437a_6b13_c1429fd546fa
  2351a59d_92ba_1342_1dcb_39b34492170e["upgradeToFullPluginSupport()"]
  2351a59d_92ba_1342_1dcb_39b34492170e -->|calls| 31653e23_464a_3652_4a48_0c82332a92c4
  2e310eb5_4501_1335_aeaa_0b16be3953d3["objectToAst()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| 2e310eb5_4501_1335_aeaa_0b16be3953d3
  6bed2e43_7855_2758_8396_9f9e9a11be52["substituteFunctions()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| 6bed2e43_7855_2758_8396_9f9e9a11be52
  2f6881be_62d9_4b96_7331_a962ced095f7["atRule()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| 2f6881be_62d9_4b96_7331_a962ced095f7
  4982d9ce_98d4_85d9_44af_7cc47b93c482["walk()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| 4982d9ce_98d4_85d9_44af_7cc47b93c482
  4137fbb0_2dd7_d72c_217e_8188fb959114["entries()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| 4137fbb0_2dd7_d72c_217e_8188fb959114
  18e3ad78_ceaa_f1dc_df00_cefc3e549b9c["parseVariantValue()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| 18e3ad78_ceaa_f1dc_df00_cefc3e549b9c
  ed286c50_134b_5b5b_ff58_76456160010c["compoundsForSelectors()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| ed286c50_134b_5b5b_ff58_76456160010c
  63907b21_884d_e864_81c9_68f20a13c40b["fromAst()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| 63907b21_884d_e864_81c9_68f20a13c40b
  15fe2878_a9ae_f5b5_2f4c_e3238b9272fe["group()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| 15fe2878_a9ae_f5b5_2f4c_e3238b9272fe
  c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61
  bc71102c_3f3f_0a7f_c5dc_2ea1f291aec2["replaceNestedClassNameReferences()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| bc71102c_3f3f_0a7f_c5dc_2ea1f291aec2
  7ad9d996_c0ff_47f5_d131_ab2ead06506e["substituteAtApply()"]
  31653e23_464a_3652_4a48_0c82332a92c4 -->|calls| 7ad9d996_c0ff_47f5_d131_ab2ead06506e
  style 31653e23_464a_3652_4a48_0c82332a92c4 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

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