Home / File/ plugin-functions.ts — tailwindcss Source File

plugin-functions.ts — tailwindcss Source File

Architecture documentation for plugin-functions.ts, a typescript file in the tailwindcss codebase. 16 imports, 2 dependents.

File typescript OxideEngine PreProcessors 16 imports 2 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  20b59de8_11c6_2432_2a83_24f6f6e741a7["plugin-functions.ts"]
  7fd72d4c_e95c_d849_1002_1e1c9d8aca1a["design-system.ts"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> 7fd72d4c_e95c_d849_1002_1e1c9d8aca1a
  80295787_127f_69e6_91b3_4bea3a484544["theme.ts"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> 80295787_127f_69e6_91b3_4bea3a484544
  e64872c9_9835_78a8_455b_ad5e699f9543["ThemeOptions"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> e64872c9_9835_78a8_455b_ad5e699f9543
  2bc6f8eb_6339_d09c_79df_e9025a479c97["utilities.ts"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> 2bc6f8eb_6339_d09c_79df_e9025a479c97
  b71e300f_d366_e92d_f71f_413f7ee24e95["withAlpha"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> b71e300f_d366_e92d_f71f_413f7ee24e95
  c056448b_f7a2_9149_54e8_f0f8470fe3aa["default-map.ts"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> c056448b_f7a2_9149_54e8_f0f8470fe3aa
  bf2992f6_4a37_8536_70f8_94b13631027d["DefaultMap"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> bf2992f6_4a37_8536_70f8_94b13631027d
  e28f6b6c_be9a_6950_8075_180c1b66f0ea["escape.ts"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> e28f6b6c_be9a_6950_8075_180c1b66f0ea
  dfc91ad5_bcf3_d363_efd7_01a5223f7b74["unescape"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> dfc91ad5_bcf3_d363_efd7_01a5223f7b74
  e3e0c6b9_7cc3_bd6c_ce01_14f8efdc5a0d["to-key-path.ts"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> e3e0c6b9_7cc3_bd6c_ce01_14f8efdc5a0d
  1b250eae_0bea_d404_ca9e_42da26c56b45["toKeyPath"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> 1b250eae_0bea_d404_ca9e_42da26c56b45
  245c850a_c551_a2cf_854e_bba95b5a1339["apply-config-to-theme.ts"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> 245c850a_c551_a2cf_854e_bba95b5a1339
  ae20c4fb_29d7_ca79_3c49_ca02c45d5369["keyPathToCssProperty"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> ae20c4fb_29d7_ca79_3c49_ca02c45d5369
  4c30b1b3_1514_10e0_6b6c_251cab3f6b7b["deep-merge.ts"]
  20b59de8_11c6_2432_2a83_24f6f6e741a7 --> 4c30b1b3_1514_10e0_6b6c_251cab3f6b7b
  style 20b59de8_11c6_2432_2a83_24f6f6e741a7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { DesignSystem } from '../design-system'
import { ThemeOptions, type Theme, type ThemeKey } from '../theme'
import { withAlpha } from '../utilities'
import { DefaultMap } from '../utils/default-map'
import { unescape } from '../utils/escape'
import { toKeyPath } from '../utils/to-key-path'
import { keyPathToCssProperty } from './apply-config-to-theme'
import { deepMerge } from './config/deep-merge'
import type { UserConfig } from './config/types'

export function createThemeFn(
  designSystem: DesignSystem,
  configTheme: () => UserConfig['theme'],
  resolveValue: (value: any) => any,
) {
  return function theme(path: string, defaultValue?: unknown) {
    // Extract an eventual modifier from the path. e.g.:
    // - "colors.red.500 / 50%" -> "50%"
    // - "foo/bar/baz/50%"      -> "50%"
    let lastSlash = path.lastIndexOf('/')
    let modifier: string | null = null
    if (lastSlash !== -1) {
      modifier = path.slice(lastSlash + 1).trim()
      path = path.slice(0, lastSlash).trim()
    }

    let resolvedValue = (() => {
      let keypath = toKeyPath(path)
      let [cssValue, options] = readFromCss(designSystem.theme, keypath)

      let configValue = resolveValue(get(configTheme() ?? {}, keypath) ?? null)

      if (typeof configValue === 'string') {
        configValue = configValue.replace('<alpha-value>', '1')
      }

      // Resolved to a primitive value.
      if (typeof cssValue !== 'object') {
        if (typeof options !== 'object' && options & ThemeOptions.DEFAULT) {
          return configValue ?? cssValue
        }

        return cssValue
      }

      if (configValue !== null && typeof configValue === 'object' && !Array.isArray(configValue)) {
        let configValueCopy: Record<string, unknown> & { __CSS_VALUES__?: Record<string, number> } =
          // We want to make sure that we don't mutate the original config
          // value. Ideally we use `structuredClone` here, but it's not possible
          // because it can contain functions.
          deepMerge({}, [configValue], (_, b) => b)

        // There is no `cssValue`, which means we can back-fill it with values
        // from the `configValue`.
        if (cssValue === null && Object.hasOwn(configValue, '__CSS_VALUES__')) {
          let localCssValue: Record<string, unknown> = {}
          for (let key in configValue.__CSS_VALUES__) {
            localCssValue[key] = configValue[key]
            delete configValueCopy[key]
          }
// ... (198 more lines)

Domain

Subdomains

Types

Frequently Asked Questions

What does plugin-functions.ts do?
plugin-functions.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the OxideEngine domain, PreProcessors subdomain.
What functions are defined in plugin-functions.ts?
plugin-functions.ts defines 4 function(s): createThemeFn, get, readFromCss, set.
What does plugin-functions.ts depend on?
plugin-functions.ts imports 16 module(s): DefaultMap, ThemeOptions, apply-config-to-theme.ts, deep-merge.ts, deepMerge, default-map.ts, design-system.ts, escape.ts, and 8 more.
What files import plugin-functions.ts?
plugin-functions.ts is imported by 2 file(s): plugin-api.ts, resolve-config.ts.
Where is plugin-functions.ts in the architecture?
plugin-functions.ts is located at packages/tailwindcss/src/compat/plugin-functions.ts (domain: OxideEngine, subdomain: PreProcessors, directory: packages/tailwindcss/src/compat).

Analyze Your Own Codebase

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

Try Supermodel Free