Home / Function/ createPreComputedUtilitiesCache() — tailwindcss Function Reference

createPreComputedUtilitiesCache() — tailwindcss Function Reference

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

Function typescript Oxide Extractor calls 2 called by 1

Entity Profile

Dependency Diagram

graph TD
  dbfa5ba9_5aac_d383_9103_72d694d1c1d3["createPreComputedUtilitiesCache()"]
  f6c14bbb_2e42_58cc_18f1_c89a243da9c0["canonicalize-candidates.ts"]
  dbfa5ba9_5aac_d383_9103_72d694d1c1d3 -->|defined in| f6c14bbb_2e42_58cc_18f1_c89a243da9c0
  26169039_1fd2_e320_1f63_11ec10a6fc52["prepareDesignSystemStorage()"]
  26169039_1fd2_e320_1f63_11ec10a6fc52 -->|calls| dbfa5ba9_5aac_d383_9103_72d694d1c1d3
  09df19e7_0346_145d_40c4_e93ff14a2ff9["isValidSpacingMultiplier()"]
  dbfa5ba9_5aac_d383_9103_72d694d1c1d3 -->|calls| 09df19e7_0346_145d_40c4_e93ff14a2ff9
  2820372c_b982_9e06_fc23_f8f4ac308d00["get()"]
  dbfa5ba9_5aac_d383_9103_72d694d1c1d3 -->|calls| 2820372c_b982_9e06_fc23_f8f4ac308d00
  style dbfa5ba9_5aac_d383_9103_72d694d1c1d3 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, defined in packages/tailwindcss/src/canonicalize-candidates.ts.
Where is createPreComputedUtilitiesCache() defined?
createPreComputedUtilitiesCache() is defined in packages/tailwindcss/src/canonicalize-candidates.ts at line 2334.
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