Home / File/ cssVars.ts — vue Source File

cssVars.ts — vue Source File

Architecture documentation for cssVars.ts, a typescript file in the vue codebase. 8 imports, 3 dependents.

File typescript CompilerSFC StyleProcessor 8 imports 3 dependents 8 functions

Entity Profile

Dependency Diagram

graph LR
  b08241c7_738d_9e08_b885_fad82facd4f3["cssVars.ts"]
  1502a238_61f0_9afa_8c3c_71d2bb769820["types.ts"]
  b08241c7_738d_9e08_b885_fad82facd4f3 --> 1502a238_61f0_9afa_8c3c_71d2bb769820
  3865741e_556d_ec8c_c327_fe6fdcb59cfd["BindingMetadata"]
  b08241c7_738d_9e08_b885_fad82facd4f3 --> 3865741e_556d_ec8c_c327_fe6fdcb59cfd
  ecb7777f_63cc_7bf6_1f6a_fedf933d43a4["parseComponent.ts"]
  b08241c7_738d_9e08_b885_fad82facd4f3 --> ecb7777f_63cc_7bf6_1f6a_fedf933d43a4
  723c94a2_276b_7491_3957_5f4e8a659b73["SFCDescriptor"]
  b08241c7_738d_9e08_b885_fad82facd4f3 --> 723c94a2_276b_7491_3957_5f4e8a659b73
  799ac4a1_7d08_dd24_f075_2bfd21b8092b["prefixIdentifiers.ts"]
  b08241c7_738d_9e08_b885_fad82facd4f3 --> 799ac4a1_7d08_dd24_f075_2bfd21b8092b
  fefea729_cf80_e4f2_675b_000b41fc85a5["prefixIdentifiers"]
  b08241c7_738d_9e08_b885_fad82facd4f3 --> fefea729_cf80_e4f2_675b_000b41fc85a5
  9f3f8004_6300_56b9_1cab_b3f6b495be1c["postcss"]
  b08241c7_738d_9e08_b885_fad82facd4f3 --> 9f3f8004_6300_56b9_1cab_b3f6b495be1c
  47553a6e_bec9_3256_f70a_cfd5dfa0f98e["hash-sum"]
  b08241c7_738d_9e08_b885_fad82facd4f3 --> 47553a6e_bec9_3256_f70a_cfd5dfa0f98e
  b9f12a63_b611_1b00_0717_3ff21d7ce156["compileScript.ts"]
  b9f12a63_b611_1b00_0717_3ff21d7ce156 --> b08241c7_738d_9e08_b885_fad82facd4f3
  028e31ce_07f6_d5b2_134a_c0b5bb64823a["compileStyle.ts"]
  028e31ce_07f6_d5b2_134a_c0b5bb64823a --> b08241c7_738d_9e08_b885_fad82facd4f3
  c09840ce_bc86_fdc3_93a1_cf7e368a9a93["parse.ts"]
  c09840ce_bc86_fdc3_93a1_cf7e368a9a93 --> b08241c7_738d_9e08_b885_fad82facd4f3
  style b08241c7_738d_9e08_b885_fad82facd4f3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { BindingMetadata } from './types'
import { SFCDescriptor } from './parseComponent'
import { PluginCreator } from 'postcss'
import hash from 'hash-sum'
import { prefixIdentifiers } from './prefixIdentifiers'

export const CSS_VARS_HELPER = `useCssVars`

export function genCssVarsFromList(
  vars: string[],
  id: string,
  isProd: boolean,
  isSSR = false
): string {
  return `{\n  ${vars
    .map(
      key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`
    )
    .join(',\n  ')}\n}`
}

function genVarName(id: string, raw: string, isProd: boolean): string {
  if (isProd) {
    return hash(id + raw)
  } else {
    return `${id}-${raw.replace(/([^\w-])/g, '_')}`
  }
}

function normalizeExpression(exp: string) {
  exp = exp.trim()
  if (
    (exp[0] === `'` && exp[exp.length - 1] === `'`) ||
    (exp[0] === `"` && exp[exp.length - 1] === `"`)
  ) {
    return exp.slice(1, -1)
  }
  return exp
}

const vBindRE = /v-bind\s*\(/g

export function parseCssVars(sfc: SFCDescriptor): string[] {
  const vars: string[] = []
  sfc.styles.forEach(style => {
    let match
    // ignore v-bind() in comments /* ... */
    const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '')
    while ((match = vBindRE.exec(content))) {
      const start = match.index + match[0].length
      const end = lexBinding(content, start)
      if (end !== null) {
        const variable = normalizeExpression(content.slice(start, end))
        if (!vars.includes(variable)) {
          vars.push(variable)
        }
      }
    }
  })
  return vars
// ... (120 more lines)

Domain

Subdomains

Frequently Asked Questions

What does cssVars.ts do?
cssVars.ts is a source file in the vue codebase, written in typescript. It belongs to the CompilerSFC domain, StyleProcessor subdomain.
What functions are defined in cssVars.ts?
cssVars.ts defines 8 function(s): cssVarsPlugin, genCssVarsCode, genCssVarsFromList, genNormalScriptCssVarsCode, genVarName, lexBinding, normalizeExpression, parseCssVars.
What does cssVars.ts depend on?
cssVars.ts imports 8 module(s): BindingMetadata, SFCDescriptor, hash-sum, parseComponent.ts, postcss, prefixIdentifiers, prefixIdentifiers.ts, types.ts.
What files import cssVars.ts?
cssVars.ts is imported by 3 file(s): compileScript.ts, compileStyle.ts, parse.ts.
Where is cssVars.ts in the architecture?
cssVars.ts is located at packages/compiler-sfc/src/cssVars.ts (domain: CompilerSFC, subdomain: StyleProcessor, directory: packages/compiler-sfc/src).

Analyze Your Own Codebase

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

Try Supermodel Free