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. 18 imports, 2 dependents.

File typescript Oxide PreProcessors 18 imports 2 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e["plugin-functions.ts"]
  bdedd2f6_da4b_69dc_e990_0814b59fbe6e["design-system.ts"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> bdedd2f6_da4b_69dc_e990_0814b59fbe6e
  665aa4ed_d86e_30e5_80d5_cd56b8ca8b62["DesignSystem"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> 665aa4ed_d86e_30e5_80d5_cd56b8ca8b62
  e28cd4a7_4e1a_e79b_76f1_86c479c6640d["theme.ts"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> e28cd4a7_4e1a_e79b_76f1_86c479c6640d
  f504aa6c_d026_cb8e_0a17_653514de8526["ThemeOptions"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> f504aa6c_d026_cb8e_0a17_653514de8526
  ffde8eb7_7def_91ee_918c_be4f250f76a2["utilities.ts"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> ffde8eb7_7def_91ee_918c_be4f250f76a2
  2e8f6051_b6e8_4985_14e1_e11717a8d2ab["withAlpha"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> 2e8f6051_b6e8_4985_14e1_e11717a8d2ab
  28a2f72d_350c_6647_bf9d_77c69e637045["default-map.ts"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> 28a2f72d_350c_6647_bf9d_77c69e637045
  cfb4af0e_7b2d_34a1_693a_90088443cfec["DefaultMap"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> cfb4af0e_7b2d_34a1_693a_90088443cfec
  efac73cf_6ebb_d715_c95b_77e505446ee2["escape.ts"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> efac73cf_6ebb_d715_c95b_77e505446ee2
  87a17ea2_6c8d_3d38_bd46_25d9267eeac0["unescape"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> 87a17ea2_6c8d_3d38_bd46_25d9267eeac0
  1f643124_89df_1d95_f8fd_e4036c7301de["to-key-path.ts"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> 1f643124_89df_1d95_f8fd_e4036c7301de
  05d44181_6631_c1fa_4a63_96653e28f99c["toKeyPath"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> 05d44181_6631_c1fa_4a63_96653e28f99c
  8d84257d_f3b2_cdf8_542f_835967da0481["apply-config-to-theme.ts"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> 8d84257d_f3b2_cdf8_542f_835967da0481
  1767219e_c38a_227c_492b_5d47634d54a4["keyPathToCssProperty"]
  3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e --> 1767219e_c38a_227c_492b_5d47634d54a4
  style 3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e 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 Oxide 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 18 module(s): DefaultMap, DesignSystem, ThemeOptions, UserConfig, apply-config-to-theme.ts, deep-merge.ts, deepMerge, default-map.ts, and 10 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: Oxide, 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