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 SfcCompiler ScriptCompiler 2 imports 1 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  822b2e28_d690_8f44_42af_ffc75c6a194a["scoped.ts"]
  1aa815c2_41ad_6268_0ebd_effb0617ac66["postcss"]
  822b2e28_d690_8f44_42af_ffc75c6a194a --> 1aa815c2_41ad_6268_0ebd_effb0617ac66
  fa977a29_0296_3ac4_4f8a_d4cbfb73777f["postcss-selector-parser"]
  822b2e28_d690_8f44_42af_ffc75c6a194a --> fa977a29_0296_3ac4_4f8a_d4cbfb73777f
  1aad1b66_4ff0_fcc3_9eab_fd33ebad4a4c["compileStyle.ts"]
  1aad1b66_4ff0_fcc3_9eab_fd33ebad4a4c --> 822b2e28_d690_8f44_42af_ffc75c6a194a
  style 822b2e28_d690_8f44_42af_ffc75c6a194a 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 SfcCompiler domain, ScriptCompiler 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: SfcCompiler, subdomain: ScriptCompiler, 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