apply.ts — tailwindcss Source File
Architecture documentation for apply.ts, a typescript file in the tailwindcss codebase. 18 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR 1721da0c_9e1d_5bee_ab0a_a192cfa6640d["apply.ts"] b9cbffa4_c352_cf3c_268f_cbb174fb3a47["ast.ts"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> b9cbffa4_c352_cf3c_268f_cbb174fb3a47 dbd80fa4_4b36_fb8e_fb6e_f2aec789aa6b["cloneAstNode"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> dbd80fa4_4b36_fb8e_fb6e_f2aec789aa6b 085cf56e_8188_afb1_04da_5ccd0fb7babc["rule"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> 085cf56e_8188_afb1_04da_5ccd0fb7babc 9b49f3c6_0c8d_5c62_965c_30a1db6499f8["toCss"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> 9b49f3c6_0c8d_5c62_965c_30a1db6499f8 eea0ec96_6369_abc2_64b3_490868392e31["compile.ts"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> eea0ec96_6369_abc2_64b3_490868392e31 ad08c258_e5c2_4cd4_c935_0925a940458e["compileCandidates"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> ad08c258_e5c2_4cd4_c935_0925a940458e bdedd2f6_da4b_69dc_e990_0814b59fbe6e["design-system.ts"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> bdedd2f6_da4b_69dc_e990_0814b59fbe6e 665aa4ed_d86e_30e5_80d5_cd56b8ca8b62["DesignSystem"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> 665aa4ed_d86e_30e5_80d5_cd56b8ca8b62 45262882_ddec_eb81_dedb_b4f286a3f721["source.ts"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> 45262882_ddec_eb81_dedb_b4f286a3f721 0befe1e4_cbdb_e481_9c0a_5c5c6d3e2a01["SourceLocation"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> 0befe1e4_cbdb_e481_9c0a_5c5c6d3e2a01 28a2f72d_350c_6647_bf9d_77c69e637045["default-map.ts"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> 28a2f72d_350c_6647_bf9d_77c69e637045 cfb4af0e_7b2d_34a1_693a_90088443cfec["DefaultMap"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> cfb4af0e_7b2d_34a1_693a_90088443cfec bb9924cc_8308_a1f9_0e30_76de45a64970["segment.ts"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> bb9924cc_8308_a1f9_0e30_76de45a64970 c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment"] 1721da0c_9e1d_5bee_ab0a_a192cfa6640d --> c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 style 1721da0c_9e1d_5bee_ab0a_a192cfa6640d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { Features } from '.'
import { cloneAstNode, rule, toCss, type AstNode } from './ast'
import { compileCandidates } from './compile'
import type { DesignSystem } from './design-system'
import type { SourceLocation } from './source-maps/source'
import { DefaultMap } from './utils/default-map'
import { segment } from './utils/segment'
import { walk, WalkAction } from './walk'
export function substituteAtApply(ast: AstNode[], designSystem: DesignSystem) {
let features = Features.None
// Wrap the whole AST in a root rule to make sure there is always a parent
// available for `@apply` at-rules. In some cases, the incoming `ast` just
// contains `@apply` at-rules which means that there is no proper parent to
// rely on.
let root = rule('&', ast)
// Track all nodes containing `@apply`
let parents = new Set<AstNode>()
// Track all the dependencies of an `AstNode`
let dependencies = new DefaultMap<AstNode, Set<string>>(() => new Set<string>())
// Track all `@utility` definitions by its root (name)
let definitions = new DefaultMap(() => new Set<AstNode>())
// Collect all new `@utility` definitions and all `@apply` rules first
walk([root], (node, ctx) => {
if (node.kind !== 'at-rule') return
// Do not allow `@apply` rules inside `@keyframes` rules.
if (node.name === '@keyframes') {
walk(node.nodes, (child) => {
if (child.kind === 'at-rule' && child.name === '@apply') {
throw new Error(`You cannot use \`@apply\` inside \`@keyframes\`.`)
}
})
return WalkAction.Skip
}
// `@utility` defines a utility, which is important information in order to
// do a correct topological sort later on.
if (node.name === '@utility') {
let name = node.params.replace(/-\*$/, '')
definitions.get(name).add(node)
// In case `@apply` rules are used inside `@utility` rules.
walk(node.nodes, (child) => {
if (child.kind !== 'at-rule' || child.name !== '@apply') return
parents.add(node)
for (let dependency of resolveApplyDependencies(child, designSystem)) {
dependencies.get(node).add(dependency)
}
})
return
}
// ... (265 more lines)
Domain
Subdomains
Dependencies
Imported By
Source
Frequently Asked Questions
What does apply.ts do?
apply.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the Oxide domain, Scanner subdomain.
What functions are defined in apply.ts?
apply.ts defines 2 function(s): resolveApplyDependencies, substituteAtApply.
What does apply.ts depend on?
apply.ts imports 18 module(s): ., DefaultMap, DesignSystem, SourceLocation, WalkAction, ast.ts, cloneAstNode, compile.ts, and 10 more.
What files import apply.ts?
apply.ts is imported by 3 file(s): canonicalize-candidates.ts, index.ts, plugin-api.ts.
Where is apply.ts in the architecture?
apply.ts is located at packages/tailwindcss/src/apply.ts (domain: Oxide, subdomain: Scanner, directory: packages/tailwindcss/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free