apply.ts — tailwindcss Source File
Architecture documentation for apply.ts, a typescript file in the tailwindcss codebase. 16 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR 3a015725_f8f3_769d_8ffe_6c8802c16649["apply.ts"] 247718b3_b5b8_7b17_49ec_2bb382291311["ast.ts"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> 247718b3_b5b8_7b17_49ec_2bb382291311 188249da_bfc5_9b59_1ede_6fdad1d687ef["cloneAstNode"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> 188249da_bfc5_9b59_1ede_6fdad1d687ef 6c2cd8f9_a144_c040_d511_b3a89a5968f3["rule"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> 6c2cd8f9_a144_c040_d511_b3a89a5968f3 a3d8a743_daba_13b1_78f3_470a016c5e47["toCss"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> a3d8a743_daba_13b1_78f3_470a016c5e47 cf1beec0_f740_c83b_e16e_889783f70ef8["compile.ts"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> cf1beec0_f740_c83b_e16e_889783f70ef8 10dc8daa_bbcc_0b91_fd3e_70f0edcef2e0["compileCandidates"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> 10dc8daa_bbcc_0b91_fd3e_70f0edcef2e0 7faf02eb_a5c2_19fb_3d42_fe877b62963e["design-system.ts"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> 7faf02eb_a5c2_19fb_3d42_fe877b62963e acc54e08_6881_f15e_58b3_23c3c8c8d5d7["source.ts"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> acc54e08_6881_f15e_58b3_23c3c8c8d5d7 4412655b_b72e_0408_b9f5_1d1103fe326b["default-map.ts"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> 4412655b_b72e_0408_b9f5_1d1103fe326b d3c325be_721a_fc84_603b_5d619a4bc6e8["DefaultMap"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> d3c325be_721a_fc84_603b_5d619a4bc6e8 1afa8ee8_5fcf_f2b9_c213_4e8b0972faa7["segment.ts"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> 1afa8ee8_5fcf_f2b9_c213_4e8b0972faa7 862e1f3f_8472_e5af_6d9d_2fa3de254d30["segment"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> 862e1f3f_8472_e5af_6d9d_2fa3de254d30 de024372_c459_7fda_5f4a_06bad3d1cb60["walk.ts"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> de024372_c459_7fda_5f4a_06bad3d1cb60 bb379d5c_9fdc_b83c_4c2a_dc331ebe547a["walk"] 3a015725_f8f3_769d_8ffe_6c8802c16649 --> bb379d5c_9fdc_b83c_4c2a_dc331ebe547a style 3a015725_f8f3_769d_8ffe_6c8802c16649 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 TailwindCore domain, DesignSystem 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 16 module(s): ., DefaultMap, WalkAction, ast.ts, cloneAstNode, compile.ts, compileCandidates, default-map.ts, and 8 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: TailwindCore, subdomain: DesignSystem, directory: packages/tailwindcss/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free