Home / File/ transform-css-vars.ts — ui Source File

transform-css-vars.ts — ui Source File

Architecture documentation for transform-css-vars.ts, a typescript file in the ui codebase. 4 imports, 3 dependents.

File typescript FrameworkTooling CLICore 4 imports 3 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  68902008_e67e_dfe4_353e_be9dad09e8d9["transform-css-vars.ts"]
  a3b2545e_3d8c_699d_ef11_6ab18db14666["schema"]
  68902008_e67e_dfe4_353e_be9dad09e8d9 --> a3b2545e_3d8c_699d_ef11_6ab18db14666
  e69863ed_3e2f_ef94_648a_ef0155c386ef["transformers"]
  68902008_e67e_dfe4_353e_be9dad09e8d9 --> e69863ed_3e2f_ef94_648a_ef0155c386ef
  4f6f7e78_23ff_4f5f_c723_474454f64c85["ts-morph"]
  68902008_e67e_dfe4_353e_be9dad09e8d9 --> 4f6f7e78_23ff_4f5f_c723_474454f64c85
  6802ce19_522d_e5fb_e458_8826d9f6952e["zod"]
  68902008_e67e_dfe4_353e_be9dad09e8d9 --> 6802ce19_522d_e5fb_e458_8826d9f6952e
  800d6a7b_126c_42b5_bf8e_f313b0852251["transform-rtl.ts"]
  800d6a7b_126c_42b5_bf8e_f313b0852251 --> 68902008_e67e_dfe4_353e_be9dad09e8d9
  7edb575e_bbe2_1d90_7009_48ce3cf289ac["transform-tw-prefix.ts"]
  7edb575e_bbe2_1d90_7009_48ce3cf289ac --> 68902008_e67e_dfe4_353e_be9dad09e8d9
  3cdfbc67_84ba_982a_287c_bc42934b2efc["apply-color-mapping.test.ts"]
  3cdfbc67_84ba_982a_287c_bc42934b2efc --> 68902008_e67e_dfe4_353e_be9dad09e8d9
  style 68902008_e67e_dfe4_353e_be9dad09e8d9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { registryBaseColorSchema } from "@/src/schema"
import { Transformer } from "@/src/utils/transformers"
import { ScriptKind, SyntaxKind } from "ts-morph"
import { z } from "zod"

export const transformCssVars: Transformer = async ({
  sourceFile,
  config,
  baseColor,
}) => {
  // No transform if using css variables.
  if (config.tailwind?.cssVariables || !baseColor?.inlineColors) {
    return sourceFile
  }

  // Find jsx attributes with the name className.
  // const openingElements = sourceFile.getDescendantsOfKind(SyntaxKind.JsxElement)
  // console.log(openingElements)
  // const jsxAttributes = sourceFile
  //   .getDescendantsOfKind(SyntaxKind.JsxAttribute)
  //   .filter((node) => node.getName() === "className")

  // for (const jsxAttribute of jsxAttributes) {
  //   const value = jsxAttribute.getInitializer()?.getText()
  //   if (value) {
  //     const valueWithColorMapping = applyColorMapping(
  //       value.replace(/"/g, ""),
  //       baseColor.inlineColors
  //     )
  //     jsxAttribute.setInitializer(`"${valueWithColorMapping}"`)
  //   }
  // }
  sourceFile.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach((node) => {
    const raw = node.getLiteralText()
    const mapped = applyColorMapping(raw, baseColor.inlineColors).trim()
    if (mapped !== raw) {
      node.setLiteralValue(mapped)
    }
  })

  return sourceFile
}

// export default function transformer(file: FileInfo, api: API) {
//   const j = api.jscodeshift.withParser("tsx")

//   // Replace bg-background with "bg-white dark:bg-slate-950"
//   const $j = j(file.source)
//   return $j
//     .find(j.JSXAttribute, {
//       name: {
//         name: "className",
//       },
//     })
//     .forEach((path) => {
//       const { node } = path
//       if (node?.value?.type) {
//         if (node.value.type === "StringLiteral") {
//           node.value.value = applyColorMapping(node.value.value)
//           console.log(node.value.value)
// ... (136 more lines)

Subdomains

Dependencies

  • schema
  • transformers
  • ts-morph
  • zod

Frequently Asked Questions

What does transform-css-vars.ts do?
transform-css-vars.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, CLICore subdomain.
What functions are defined in transform-css-vars.ts?
transform-css-vars.ts defines 3 function(s): applyColorMapping, splitClassName, transformCssVars.
What does transform-css-vars.ts depend on?
transform-css-vars.ts imports 4 module(s): schema, transformers, ts-morph, zod.
What files import transform-css-vars.ts?
transform-css-vars.ts is imported by 3 file(s): apply-color-mapping.test.ts, transform-rtl.ts, transform-tw-prefix.ts.
Where is transform-css-vars.ts in the architecture?
transform-css-vars.ts is located at packages/shadcn/src/utils/transformers/transform-css-vars.ts (domain: FrameworkTooling, subdomain: CLICore, directory: packages/shadcn/src/utils/transformers).

Analyze Your Own Codebase

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

Try Supermodel Free