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
  363fa6b2_c4f0_4185_e3df_4f8f902a2310["createPreComputedUtilitiesCache()"]
  207ada18_60f2_10b9_7c9e_99bdb32f4ed7["prepareDesignSystemStorage()"]
  207ada18_60f2_10b9_7c9e_99bdb32f4ed7 -->|calls| 363fa6b2_c4f0_4185_e3df_4f8f902a2310
  1dd167b2_b42d_8596_9276_d0e969bf2522["isValidSpacingMultiplier()"]
  363fa6b2_c4f0_4185_e3df_4f8f902a2310 -->|calls| 1dd167b2_b42d_8596_9276_d0e969bf2522
  0aa64a1c_efd8_a69d_48ed_649b7a86c854["get()"]
  363fa6b2_c4f0_4185_e3df_4f8f902a2310 -->|calls| 0aa64a1c_efd8_a69d_48ed_649b7a86c854
  style 363fa6b2_c4f0_4185_e3df_4f8f902a2310 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
  })
}

Domain

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