Home / Function/ createPreComputedUtilitiesCache() — tailwindcss Function Reference

createPreComputedUtilitiesCache() — tailwindcss Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  deab1064_60eb_011d_612d_5d14526c7a4a["createPreComputedUtilitiesCache()"]
  20406e7c_6ee8_4626_dbef_5b37708f4d30["prepareDesignSystemStorage()"]
  20406e7c_6ee8_4626_dbef_5b37708f4d30 -->|calls| deab1064_60eb_011d_612d_5d14526c7a4a
  c12acffb_80f9_0b95_b1a6_e663fbaca197["isValidSpacingMultiplier()"]
  deab1064_60eb_011d_612d_5d14526c7a4a -->|calls| c12acffb_80f9_0b95_b1a6_e663fbaca197
  4cd99e59_ac1e_2a1f_0946_33cc1afd2532["get()"]
  deab1064_60eb_011d_612d_5d14526c7a4a -->|calls| 4cd99e59_ac1e_2a1f_0946_33cc1afd2532
  style deab1064_60eb_011d_612d_5d14526c7a4a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/canonicalize-candidates.ts lines 2334–2379

function createPreComputedUtilitiesCache(
  designSystem: DesignSystem,
): DesignSystem['storage'][typeof PRE_COMPUTED_UTILITIES_KEY] {
  return new DefaultMap((options: SignatureOptions) => {
    let signatures = designSystem.storage[UTILITY_SIGNATURE_KEY].get(options)
    let lookup = new DefaultMap<string, string[]>(() => [])

    // Right now all plugins are implemented using functions so they are a black
    // box. Let's use the `getClassList` and consider every known suggestion as a
    // static utility for now.
    for (let [className, meta] of designSystem.getClassList()) {
      let signature = signatures.get(className)
      if (typeof signature !== 'string') continue

      // Skip the utility if `-{utility}-0` has the same signature as
      // `{utility}-0` (its positive version). This will prefer positive values
      // over negative values.
      if (className[0] === '-' && className.endsWith('-0')) {
        let positiveSignature = signatures.get(className.slice(1))
        if (typeof positiveSignature === 'string' && signature === positiveSignature) {
          continue
        }
      }

      lookup.get(signature).push(className)
      designSystem.storage[UTILITY_PROPERTIES_KEY].get(options).get(className)

      for (let modifier of meta.modifiers) {
        // Modifiers representing numbers can be computed and don't need to be
        // pre-computed. Doing the math and at the time of writing this, this
        // would save you 250k additionally pre-computed utilities...
        if (isValidSpacingMultiplier(modifier)) {
          continue
        }

        let classNameWithModifier = `${className}/${modifier}`
        let signature = signatures.get(classNameWithModifier)
        if (typeof signature !== 'string') continue
        lookup.get(signature).push(classNameWithModifier)
        designSystem.storage[UTILITY_PROPERTIES_KEY].get(options).get(classNameWithModifier)
      }
    }

    return lookup
  })
}

Subdomains

Frequently Asked Questions

What does createPreComputedUtilitiesCache() do?
createPreComputedUtilitiesCache() is a function in the tailwindcss codebase.
What does createPreComputedUtilitiesCache() call?
createPreComputedUtilitiesCache() calls 2 function(s): get, isValidSpacingMultiplier.
What calls createPreComputedUtilitiesCache()?
createPreComputedUtilitiesCache() 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