Home / File/ style.ts — vue Source File

style.ts — vue Source File

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

File typescript WebPlatform WebRuntime 3 imports 1 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  39bcf580_b87a_fcd4_c4dc_38d5e8e0495a["style.ts"]
  472b16b5_ed73_6ace_4ab4_82bfb52955ec["style"]
  39bcf580_b87a_fcd4_c4dc_38d5e8e0495a --> 472b16b5_ed73_6ace_4ab4_82bfb52955ec
  09aa5370_2caa_6b33_3f44_6ac5211bd11b["util"]
  39bcf580_b87a_fcd4_c4dc_38d5e8e0495a --> 09aa5370_2caa_6b33_3f44_6ac5211bd11b
  ba925ef2_b0f4_efe3_c23d_fe293c46b2c1["vnode"]
  39bcf580_b87a_fcd4_c4dc_38d5e8e0495a --> ba925ef2_b0f4_efe3_c23d_fe293c46b2c1
  7973a695_d0db_6940_134b_f6ff953b9e97["index.ts"]
  7973a695_d0db_6940_134b_f6ff953b9e97 --> 39bcf580_b87a_fcd4_c4dc_38d5e8e0495a
  style 39bcf580_b87a_fcd4_c4dc_38d5e8e0495a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { getStyle, normalizeStyleBinding } from 'web/util/style'
import {
  cached,
  camelize,
  extend,
  isDef,
  isUndef,
  hyphenate
} from 'shared/util'
import type { VNodeWithData } from 'types/vnode'

const cssVarRE = /^--/
const importantRE = /\s*!important$/
const setProp = (el, name, val) => {
  /* istanbul ignore if */
  if (cssVarRE.test(name)) {
    el.style.setProperty(name, val)
  } else if (importantRE.test(val)) {
    el.style.setProperty(
      hyphenate(name),
      val.replace(importantRE, ''),
      'important'
    )
  } else {
    const normalizedName = normalize(name)
    if (Array.isArray(val)) {
      // Support values array created by autoprefixer, e.g.
      // {display: ["-webkit-box", "-ms-flexbox", "flex"]}
      // Set them one by one, and the browser will only set those it can recognize
      for (let i = 0, len = val.length; i < len; i++) {
        el.style[normalizedName!] = val[i]
      }
    } else {
      el.style[normalizedName!] = val
    }
  }
}

const vendorNames = ['Webkit', 'Moz', 'ms']

let emptyStyle
const normalize = cached(function (prop) {
  emptyStyle = emptyStyle || document.createElement('div').style
  prop = camelize(prop)
  if (prop !== 'filter' && prop in emptyStyle) {
    return prop
  }
  const capName = prop.charAt(0).toUpperCase() + prop.slice(1)
  for (let i = 0; i < vendorNames.length; i++) {
    const name = vendorNames[i] + capName
    if (name in emptyStyle) {
      return name
    }
  }
})

function updateStyle(oldVnode: VNodeWithData, vnode: VNodeWithData) {
  const data = vnode.data
  const oldData = oldVnode.data

  if (
    isUndef(data.staticStyle) &&
    isUndef(data.style) &&
    isUndef(oldData.staticStyle) &&
    isUndef(oldData.style)
  ) {
    return
  }

  let cur, name
  const el: any = vnode.elm
  const oldStaticStyle: any = oldData.staticStyle
  const oldStyleBinding: any = oldData.normalizedStyle || oldData.style || {}

  // if static style exists, stylebinding already merged into it when doing normalizeStyleData
  const oldStyle = oldStaticStyle || oldStyleBinding

  const style = normalizeStyleBinding(vnode.data.style) || {}

  // store normalized style under a different key for next diff
  // make sure to clone it if it's reactive, since the user likely wants
  // to mutate it.
  vnode.data.normalizedStyle = isDef(style.__ob__) ? extend({}, style) : style

  const newStyle = getStyle(vnode, true)

  for (name in oldStyle) {
    if (isUndef(newStyle[name])) {
      setProp(el, name, '')
    }
  }
  for (name in newStyle) {
    cur = newStyle[name]
    // ie9 setting to null has no effect, must use empty string
    setProp(el, name, cur == null ? '' : cur)
  }
}

export default {
  create: updateStyle,
  update: updateStyle
}

Domain

Subdomains

Dependencies

  • style
  • util
  • vnode

Frequently Asked Questions

What does style.ts do?
style.ts is a source file in the vue codebase, written in typescript. It belongs to the WebPlatform domain, WebRuntime subdomain.
What functions are defined in style.ts?
style.ts defines 3 function(s): normalize, setProp, updateStyle.
What does style.ts depend on?
style.ts imports 3 module(s): style, util, vnode.
What files import style.ts?
style.ts is imported by 1 file(s): index.ts.
Where is style.ts in the architecture?
style.ts is located at src/platforms/web/runtime/modules/style.ts (domain: WebPlatform, subdomain: WebRuntime, directory: src/platforms/web/runtime/modules).

Analyze Your Own Codebase

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

Try Supermodel Free