readFromCss() — tailwindcss Function Reference
Architecture documentation for the readFromCss() function in plugin-functions.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD bdec5541_c088_b3c7_4457_73a4592c6631["readFromCss()"] 3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e["plugin-functions.ts"] bdec5541_c088_b3c7_4457_73a4592c6631 -->|defined in| 3d2f062b_d3ec_6b3a_dc32_9d2e4732e20e dabb13bc_6018_934b_19c4_595b7bea686d["createThemeFn()"] dabb13bc_6018_934b_19c4_595b7bea686d -->|calls| bdec5541_c088_b3c7_4457_73a4592c6631 1b59ba6b_4432_276c_dd0d_7664aec4893a["get()"] bdec5541_c088_b3c7_4457_73a4592c6631 -->|calls| 1b59ba6b_4432_276c_dd0d_7664aec4893a 45cb4617_2116_e947_4a90_d9e2642b9325["getOptions()"] bdec5541_c088_b3c7_4457_73a4592c6631 -->|calls| 45cb4617_2116_e947_4a90_d9e2642b9325 1767219e_c38a_227c_492b_5d47634d54a4["keyPathToCssProperty()"] bdec5541_c088_b3c7_4457_73a4592c6631 -->|calls| 1767219e_c38a_227c_492b_5d47634d54a4 c7866e06_1e4e_0568_c3b7_9934e976548a["namespace()"] bdec5541_c088_b3c7_4457_73a4592c6631 -->|calls| c7866e06_1e4e_0568_c3b7_9934e976548a c2e516d5_98ab_5008_963a_c5eda5f9d8a9["set()"] bdec5541_c088_b3c7_4457_73a4592c6631 -->|calls| c2e516d5_98ab_5008_963a_c5eda5f9d8a9 24bbf7d9_ff21_752d_5669_1a8f911d9ad1["keys()"] bdec5541_c088_b3c7_4457_73a4592c6631 -->|calls| 24bbf7d9_ff21_752d_5669_1a8f911d9ad1 style bdec5541_c088_b3c7_4457_73a4592c6631 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/compat/plugin-functions.ts lines 116–220
function readFromCss(
theme: Theme,
path: string[],
):
| [value: string | null | Record<string, unknown>, options: number]
| [value: Record<string, unknown>, options: Record<string, number>] {
// `--color-red-500` should resolve to the theme variable directly, no look up
// and handling of nested objects is required.
if (path.length === 1 && path[0].startsWith('--')) {
return [theme.get([path[0] as ThemeKey]), theme.getOptions(path[0])] as const
}
type ThemeValue =
// A normal string value
| string
// A nested tuple with additional data
| [main: string, extra: Record<string, string>]
let themeKey = keyPathToCssProperty(path)
let map = new Map<string | null, ThemeValue>()
let nested = new DefaultMap<string | null, Map<string, [value: string, options: number]>>(
() => new Map(),
)
let ns = theme.namespace(`--${themeKey}`)
if (ns.size === 0) {
return [null, ThemeOptions.NONE]
}
let options = new Map()
for (let [key, value] of ns) {
// Non-nested values can be set directly
if (!key || !key.includes('--')) {
map.set(key, value)
options.set(key, theme.getOptions(!key ? `--${themeKey}` : `--${themeKey}-${key}`))
continue
}
// Nested values are stored separately
let nestedIndex = key.indexOf('--')
let mainKey = key.slice(0, nestedIndex)
let nestedKey = key.slice(nestedIndex + 2)
// Make `nestedKey` camel case:
nestedKey = nestedKey.replace(/-([a-z])/g, (_, a) => a.toUpperCase())
nested
.get(mainKey === '' ? null : mainKey)
.set(nestedKey, [value, theme.getOptions(`--${themeKey}${key}`)])
}
let baseOptions = theme.getOptions(`--${themeKey}`)
for (let [key, extra] of nested) {
let value = map.get(key)
if (typeof value !== 'string') continue
let extraObj: Record<string, string> = {}
let extraOptionsObj: Record<string, number> = {}
for (let [nestedKey, [nestedValue, nestedOptions]] of extra) {
extraObj[nestedKey] = nestedValue
extraOptionsObj[nestedKey] = nestedOptions
}
map.set(key, [value, extraObj])
options.set(key, [baseOptions, extraOptionsObj])
}
// We have to turn the map into object-like structure for v3 compatibility
let obj: Record<string, unknown> = {}
let optionsObj: Record<string, number> = {}
for (let [key, value] of map) {
set(obj, [key ?? 'DEFAULT'], value)
}
for (let [key, value] of options) {
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does readFromCss() do?
readFromCss() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/compat/plugin-functions.ts.
Where is readFromCss() defined?
readFromCss() is defined in packages/tailwindcss/src/compat/plugin-functions.ts at line 116.
What does readFromCss() call?
readFromCss() calls 6 function(s): get, getOptions, keyPathToCssProperty, keys, namespace, set.
What calls readFromCss()?
readFromCss() is called by 1 function(s): createThemeFn.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free