Home / Function/ keyPathToCssProperty() — tailwindcss Function Reference

keyPathToCssProperty() — tailwindcss Function Reference

Architecture documentation for the keyPathToCssProperty() function in apply-config-to-theme.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  1767219e_c38a_227c_492b_5d47634d54a4["keyPathToCssProperty()"]
  8d84257d_f3b2_cdf8_542f_835967da0481["apply-config-to-theme.ts"]
  1767219e_c38a_227c_492b_5d47634d54a4 -->|defined in| 8d84257d_f3b2_cdf8_542f_835967da0481
  253815a9_405f_ff30_32b6_577fe2d91fb2["migrateTheme()"]
  253815a9_405f_ff30_32b6_577fe2d91fb2 -->|calls| 1767219e_c38a_227c_492b_5d47634d54a4
  0838eb2e_5580_246c_b5a8_b68fb91edccc["migratePreflight()"]
  0838eb2e_5580_246c_b5a8_b68fb91edccc -->|calls| 1767219e_c38a_227c_492b_5d47634d54a4
  f1c7fb37_4a69_f6f5_b7f4_9f3d8b534c40["createConverter()"]
  f1c7fb37_4a69_f6f5_b7f4_9f3d8b534c40 -->|calls| 1767219e_c38a_227c_492b_5d47634d54a4
  7f0ac26e_d200_2f14_4236_46ff9eed21ef["createConverterCache()"]
  7f0ac26e_d200_2f14_4236_46ff9eed21ef -->|calls| 1767219e_c38a_227c_492b_5d47634d54a4
  652fb7ad_2f22_0667_c96e_43b408d0edbe["applyConfigToTheme()"]
  652fb7ad_2f22_0667_c96e_43b408d0edbe -->|calls| 1767219e_c38a_227c_492b_5d47634d54a4
  bdec5541_c088_b3c7_4457_73a4592c6631["readFromCss()"]
  bdec5541_c088_b3c7_4457_73a4592c6631 -->|calls| 1767219e_c38a_227c_492b_5d47634d54a4
  style 1767219e_c38a_227c_492b_5d47634d54a4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/compat/apply-config-to-theme.ts lines 177–240

export function keyPathToCssProperty(path: string[]) {
  // In some special cases the `DEFAULT` key did not map to a "default" utility
  // e.g. `ringColor.DEFAULT` wasn't *just* used for `ring`. It was used for
  // all ring utilities as the color when one wasn't specified.
  //
  // We place these specialty values under the `--default-*` namespace to signal
  // that they are defaults used by (potentially) multiple utilities.
  let specialDefault = SPECIAL_DEFAULT_KEYS[path[0]]
  if (specialDefault && path[1] === 'DEFAULT') return `default-${specialDefault}`

  // The legacy container component config should not be included in the Theme
  if (path[0] === 'container') return null

  for (let part of path) {
    if (!IS_VALID_KEY.test(part)) return null
  }

  // Map old v3 namespaces to new theme namespaces
  let ns = OLD_TO_NEW_NAMESPACE[path[0]]
  if (ns) {
    path = path.slice()
    path[0] = ns
  }

  return (
    path
      // [1] should move into the nested object tuple. To create the CSS variable
      // name for this, we replace it with an empty string that will result in two
      // subsequent dashes when joined.
      //
      // E.g.:
      // - `fontSize.xs.1.lineHeight` -> `font-size-xs--line-height`
      // - `spacing.1` -> `--spacing-1`
      .map((path, idx, all) => (path === '1' && idx !== all.length - 1 ? '' : path))

      // Resolve the key path to a CSS variable segment
      .map((part, idx) => {
        part = part.replaceAll('.', '_')

        let shouldConvert =
          // The first "namespace" part should be converted to kebab-case
          // This converts things like backgroundColor to `background-color`
          idx === 0 ||
          // Any tuple nested key should be converted to kebab-case
          // These are identified with a leading `-`
          // e.g. `fontSize.xs.1.lineHeight` -> `font-size-xs--line-height`
          part.startsWith('-') ||
          // `lineHeight` is a bit of a special case in which it does not
          // always begin with a leading `-` even when as a nested tuple key
          part === 'lineHeight'

        if (shouldConvert) {
          part = part.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}-${b.toLowerCase()}`)
        }

        return part
      })

      // Remove the `DEFAULT` key at the end of a path
      // We're reading from CSS anyway so it'll be a string
      .filter((part, index) => part !== 'DEFAULT' || index !== path.length - 1)
      .join('-')
  )
}

Domain

Subdomains

Frequently Asked Questions

What does keyPathToCssProperty() do?
keyPathToCssProperty() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/compat/apply-config-to-theme.ts.
Where is keyPathToCssProperty() defined?
keyPathToCssProperty() is defined in packages/tailwindcss/src/compat/apply-config-to-theme.ts at line 177.
What calls keyPathToCssProperty()?
keyPathToCssProperty() is called by 6 function(s): applyConfigToTheme, createConverter, createConverterCache, migratePreflight, migrateTheme, readFromCss.

Analyze Your Own Codebase

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

Try Supermodel Free