Home / Function/ createCanonicalizeCandidateCache() — tailwindcss Function Reference

createCanonicalizeCandidateCache() — tailwindcss Function Reference

Architecture documentation for the createCanonicalizeCandidateCache() function in canonicalize-candidates.ts from the tailwindcss codebase.

Function typescript OxideCore Scanner calls 4 called by 1

Entity Profile

Dependency Diagram

graph TD
  85c01f92_2868_9f10_aa0d_1b8b6eaeaaa3["createCanonicalizeCandidateCache()"]
  207ada18_60f2_10b9_7c9e_99bdb32f4ed7["prepareDesignSystemStorage()"]
  207ada18_60f2_10b9_7c9e_99bdb32f4ed7 -->|calls| 85c01f92_2868_9f10_aa0d_1b8b6eaeaaa3
  c98bf5b0_e31e_f92d_3810_96d1e1308d34["parseCandidate()"]
  85c01f92_2868_9f10_aa0d_1b8b6eaeaaa3 -->|calls| c98bf5b0_e31e_f92d_3810_96d1e1308d34
  4c29981d_a61a_00fb_b3b5_5a69228c4fff["printCandidate()"]
  85c01f92_2868_9f10_aa0d_1b8b6eaeaaa3 -->|calls| 4c29981d_a61a_00fb_b3b5_5a69228c4fff
  1febc78c_5fc5_7a9e_bbde_e23926ba37fc["printVariant()"]
  85c01f92_2868_9f10_aa0d_1b8b6eaeaaa3 -->|calls| 1febc78c_5fc5_7a9e_bbde_e23926ba37fc
  0aa64a1c_efd8_a69d_48ed_649b7a86c854["get()"]
  85c01f92_2868_9f10_aa0d_1b8b6eaeaaa3 -->|calls| 0aa64a1c_efd8_a69d_48ed_649b7a86c854
  style 85c01f92_2868_9f10_aa0d_1b8b6eaeaaa3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/canonicalize-candidates.ts lines 420–481

function createCanonicalizeCandidateCache(): DesignSystem['storage'][typeof CANONICALIZE_CANDIDATE_KEY] {
  return new DefaultMap((options: InternalCanonicalizeOptions) => {
    let ds = options.designSystem
    let prefix = ds.theme.prefix ? `${ds.theme.prefix}:` : ''
    let variantCache = ds.storage[CANONICALIZE_VARIANT_KEY].get(options)
    let utilityCache = ds.storage[CANONICALIZE_UTILITY_KEY].get(options)

    return new DefaultMap<string, string>((rawCandidate: string, self) => {
      for (let candidate of ds.parseCandidate(rawCandidate)) {
        let variants = candidate.variants
          .slice()
          .reverse()
          .flatMap((variant) => variantCache.get(variant))
        let important = candidate.important

        // Canonicalize the base candidate (utility), and re-attach the variants
        // and important flag afterwards. This way we can maximize cache hits for
        // the base candidate and each individual variant.
        if (important || variants.length > 0) {
          let canonicalizedUtility = self.get(
            ds.printCandidate({ ...candidate, variants: [], important: false }),
          )

          // Rebuild the final candidate
          let result = canonicalizedUtility

          // Remove the prefix if there are variants, because the variants exist
          // between the prefix and the base candidate.
          if (ds.theme.prefix !== null && variants.length > 0) {
            result = result.slice(prefix.length)
          }

          // Re-attach the variants
          if (variants.length > 0) {
            result = `${variants.map((v) => ds.printVariant(v)).join(':')}:${result}`
          }

          // Re-attach the important flag
          if (important) {
            result += '!'
          }

          // Re-attach the prefix if there were variants
          if (ds.theme.prefix !== null && variants.length > 0) {
            result = `${prefix}${result}`
          }

          return result
        }

        // We are guaranteed to have no variants and no important flag, just the
        // base candidate left to canonicalize.
        let result = utilityCache.get(rawCandidate)
        if (result !== rawCandidate) {
          return result
        }
      }

      return rawCandidate
    })
  })
}

Domain

Subdomains

Frequently Asked Questions

What does createCanonicalizeCandidateCache() do?
createCanonicalizeCandidateCache() is a function in the tailwindcss codebase.
What does createCanonicalizeCandidateCache() call?
createCanonicalizeCandidateCache() calls 4 function(s): get, parseCandidate, printCandidate, printVariant.
What calls createCanonicalizeCandidateCache()?
createCanonicalizeCandidateCache() is called by 1 function(s): prepareDesignSystemStorage.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free