Home / File/ scoped.ts — vue Source File

scoped.ts — vue Source File

Architecture documentation for scoped.ts, a typescript file in the vue codebase. 2 imports, 1 dependents.

File typescript CompilerSFC StyleProcessor 2 imports 1 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  293256a5_d9c5_362a_dbb7_f610cfee392e["scoped.ts"]
  9f3f8004_6300_56b9_1cab_b3f6b495be1c["postcss"]
  293256a5_d9c5_362a_dbb7_f610cfee392e --> 9f3f8004_6300_56b9_1cab_b3f6b495be1c
  858e34e1_ba6b_a667_8ad8_8f3b6a848459["postcss-selector-parser"]
  293256a5_d9c5_362a_dbb7_f610cfee392e --> 858e34e1_ba6b_a667_8ad8_8f3b6a848459
  028e31ce_07f6_d5b2_134a_c0b5bb64823a["compileStyle.ts"]
  028e31ce_07f6_d5b2_134a_c0b5bb64823a --> 293256a5_d9c5_362a_dbb7_f610cfee392e
  style 293256a5_d9c5_362a_dbb7_f610cfee392e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { PluginCreator, Rule, AtRule } from 'postcss'
import selectorParser from 'postcss-selector-parser'

const animationNameRE = /^(-\w+-)?animation-name$/
const animationRE = /^(-\w+-)?animation$/

const scopedPlugin: PluginCreator<string> = (id = '') => {
  const keyframes = Object.create(null)
  const shortId = id.replace(/^data-v-/, '')

  return {
    postcssPlugin: 'vue-sfc-scoped',
    Rule(rule) {
      processRule(id, rule)
    },
    AtRule(node) {
      if (
        /-?keyframes$/.test(node.name) &&
        !node.params.endsWith(`-${shortId}`)
      ) {
        // register keyframes
        keyframes[node.params] = node.params = node.params + '-' + shortId
      }
    },
    OnceExit(root) {
      if (Object.keys(keyframes).length) {
        // If keyframes are found in this <style>, find and rewrite animation names
        // in declarations.
        // Caveat: this only works for keyframes and animation rules in the same
        // <style> element.
        // individual animation-name declaration
        root.walkDecls(decl => {
          if (animationNameRE.test(decl.prop)) {
            decl.value = decl.value
              .split(',')
              .map(v => keyframes[v.trim()] || v.trim())
              .join(',')
          }
          // shorthand
          if (animationRE.test(decl.prop)) {
            decl.value = decl.value
              .split(',')
              .map(v => {
                const vals = v.trim().split(/\s+/)
                const i = vals.findIndex(val => keyframes[val])
                if (i !== -1) {
                  vals.splice(i, 1, keyframes[vals[i]])
                  return vals.join(' ')
                } else {
                  return v
                }
              })
              .join(',')
          }
        })
      }
    }
  }
}

// ... (144 more lines)

Domain

Subdomains

Dependencies

  • postcss
  • postcss-selector-parser

Frequently Asked Questions

What does scoped.ts do?
scoped.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 scoped.ts?
scoped.ts defines 4 function(s): isSpaceCombinator, processRule, rewriteSelector, scopedPlugin.
What does scoped.ts depend on?
scoped.ts imports 2 module(s): postcss, postcss-selector-parser.
What files import scoped.ts?
scoped.ts is imported by 1 file(s): compileStyle.ts.
Where is scoped.ts in the architecture?
scoped.ts is located at packages/compiler-sfc/src/stylePlugins/scoped.ts (domain: CompilerSFC, subdomain: StyleProcessor, directory: packages/compiler-sfc/src/stylePlugins).

Analyze Your Own Codebase

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

Try Supermodel Free