Home / File/ transform-style-map.ts — ui Source File

transform-style-map.ts — ui Source File

Architecture documentation for transform-style-map.ts, a typescript file in the ui codebase. 4 imports, 2 dependents.

File typescript FrameworkTooling TemplateSync 4 imports 2 dependents 18 functions

Entity Profile

Dependency Diagram

graph LR
  cef4e429_7112_fef5_ae0b_a838a57ccf71["transform-style-map.ts"]
  20ad6f91_6d0b_ef0e_6867_01a114c31d1d["create-style-map.ts"]
  cef4e429_7112_fef5_ae0b_a838a57ccf71 --> 20ad6f91_6d0b_ef0e_6867_01a114c31d1d
  04a81d5e_eda3_d553_3985_8aa01b279644["transform"]
  cef4e429_7112_fef5_ae0b_a838a57ccf71 --> 04a81d5e_eda3_d553_3985_8aa01b279644
  8f0d50d6_7103_5a47_9ef1_514d68c80604["tailwind-merge"]
  cef4e429_7112_fef5_ae0b_a838a57ccf71 --> 8f0d50d6_7103_5a47_9ef1_514d68c80604
  4f6f7e78_23ff_4f5f_c723_474454f64c85["ts-morph"]
  cef4e429_7112_fef5_ae0b_a838a57ccf71 --> 4f6f7e78_23ff_4f5f_c723_474454f64c85
  b6929276_0c11_78e4_0d6e_5cbe870a5cec["transform-style-map.test.ts"]
  b6929276_0c11_78e4_0d6e_5cbe870a5cec --> cef4e429_7112_fef5_ae0b_a838a57ccf71
  b35e7ac9_4f0f_f678_f1a6_1e42325d5108["transform.ts"]
  b35e7ac9_4f0f_f678_f1a6_1e42325d5108 --> cef4e429_7112_fef5_ae0b_a838a57ccf71
  style cef4e429_7112_fef5_ae0b_a838a57ccf71 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { TransformerStyle } from "@/src/styles/transform"
import { twMerge } from "tailwind-merge"
import {
  Node,
  type CallExpression,
  type NoSubstitutionTemplateLiteral,
  type SourceFile,
  type StringLiteral,
} from "ts-morph"

import { type StyleMap } from "./create-style-map"

/**
 * Classes that should never be removed during transformation.
 * These are typically used as CSS selectors or for other purposes
 * that require the class name to remain in the code.
 */
// TODO: all cn-* classes to be allowedlisted.
const ALLOWLIST = new Set(["cn-menu-target", "cn-logical-sides", "cn-rtl-flip"])

function isStringLiteralLike(
  node: Node
): node is StringLiteral | NoSubstitutionTemplateLiteral {
  return (
    Node.isStringLiteral(node) || Node.isNoSubstitutionTemplateLiteral(node)
  )
}

export const transformStyleMap: TransformerStyle<SourceFile> = async ({
  sourceFile,
  styleMap,
}) => {
  const matchedClasses = new Set<string>()

  applyToCvaCalls(sourceFile, styleMap, matchedClasses)
  applyToClassNameAttributes(sourceFile, styleMap, matchedClasses)
  applyToMergePropsCalls(sourceFile, styleMap, matchedClasses)

  return sourceFile
}

function applyStyleToCvaString(
  stringNode: StringLiteral,
  styleMap: StyleMap,
  matchedClasses: Set<string>
) {
  const stringValue = stringNode.getLiteralText()
  const cnClasses = extractCnClasses(stringValue)

  if (cnClasses.length === 0) {
    return
  }

  // Process all cn-* classes, not just the first one
  const unmatchedClasses = cnClasses.filter(
    (cnClass) => !matchedClasses.has(cnClass)
  )

  if (unmatchedClasses.length === 0) {
    // All classes already matched, just clean up non-allowlisted ones
// ... (528 more lines)

Subdomains

Dependencies

Frequently Asked Questions

What does transform-style-map.ts do?
transform-style-map.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, TemplateSync subdomain.
What functions are defined in transform-style-map.ts?
transform-style-map.ts defines 18 function(s): applyClassesToCnCall, applyClassesToElement, applyStyleToCvaString, applyToClassNameAttributes, applyToCvaCalls, applyToMergePropsCalls, cleanCnClassesFromAttribute, cleanCnClassesFromCnCall, extractCnClass, extractCnClasses, and 8 more.
What does transform-style-map.ts depend on?
transform-style-map.ts imports 4 module(s): create-style-map.ts, tailwind-merge, transform, ts-morph.
What files import transform-style-map.ts?
transform-style-map.ts is imported by 2 file(s): transform-style-map.test.ts, transform.ts.
Where is transform-style-map.ts in the architecture?
transform-style-map.ts is located at packages/shadcn/src/styles/transform-style-map.ts (domain: FrameworkTooling, subdomain: TemplateSync, directory: packages/shadcn/src/styles).

Analyze Your Own Codebase

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

Try Supermodel Free