style.ts — vue Source File
Architecture documentation for style.ts, a typescript file in the vue codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 9baf2011_2aa2_1c40_464d_e026d0ec7477["style.ts"] 973389ac_8625_30a3_53ce_b1b48fae58c5["vnode"] 9baf2011_2aa2_1c40_464d_e026d0ec7477 --> 973389ac_8625_30a3_53ce_b1b48fae58c5 09aa5370_2caa_6b33_3f44_6ac5211bd11b["util"] 9baf2011_2aa2_1c40_464d_e026d0ec7477 --> 09aa5370_2caa_6b33_3f44_6ac5211bd11b ba925ef2_b0f4_efe3_c23d_fe293c46b2c1["vnode"] 9baf2011_2aa2_1c40_464d_e026d0ec7477 --> ba925ef2_b0f4_efe3_c23d_fe293c46b2c1 style 9baf2011_2aa2_1c40_464d_e026d0ec7477 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import VNode from 'core/vdom/vnode'
import { cached, extend, toObject } from 'shared/util'
import type { VNodeData, VNodeWithData } from 'types/vnode'
export const parseStyleText = cached(function (cssText) {
const res = {}
const listDelimiter = /;(?![^(]*\))/g
const propertyDelimiter = /:(.+)/
cssText.split(listDelimiter).forEach(function (item) {
if (item) {
const tmp = item.split(propertyDelimiter)
tmp.length > 1 && (res[tmp[0].trim()] = tmp[1].trim())
}
})
return res
})
// merge static and dynamic style data on the same vnode
function normalizeStyleData(data: VNodeData): Record<string, any> {
const style = normalizeStyleBinding(data.style)
// static style is pre-processed into an object during compilation
// and is always a fresh object, so it's safe to merge into it
return data.staticStyle ? extend(data.staticStyle, style) : style
}
// normalize possible array / string values into Object
export function normalizeStyleBinding(bindingStyle: any): Record<string, any> {
if (Array.isArray(bindingStyle)) {
return toObject(bindingStyle)
}
if (typeof bindingStyle === 'string') {
return parseStyleText(bindingStyle)
}
return bindingStyle
}
/**
* parent component style should be after child's
* so that parent component's style could override it
*/
export function getStyle(vnode: VNodeWithData, checkChild: boolean): Object {
const res = {}
let styleData
if (checkChild) {
let childNode: VNodeWithData | VNode = vnode
while (childNode.componentInstance) {
childNode = childNode.componentInstance._vnode!
if (
childNode &&
childNode.data &&
(styleData = normalizeStyleData(childNode.data))
) {
extend(res, styleData)
}
}
}
if ((styleData = normalizeStyleData(vnode.data))) {
extend(res, styleData)
}
let parentNode: VNodeWithData | VNode | undefined = vnode
// @ts-expect-error parentNode.parent not VNodeWithData
while ((parentNode = parentNode.parent)) {
if (parentNode.data && (styleData = normalizeStyleData(parentNode.data))) {
extend(res, styleData)
}
}
return res
}
Domain
Subdomains
Dependencies
- util
- vnode
- vnode
Source
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 VueCore domain, GlobalAPI subdomain.
What functions are defined in style.ts?
style.ts defines 4 function(s): getStyle, normalizeStyleBinding, normalizeStyleData, parseStyleText.
What does style.ts depend on?
style.ts imports 3 module(s): util, vnode, vnode.
Where is style.ts in the architecture?
style.ts is located at src/platforms/web/util/style.ts (domain: VueCore, subdomain: GlobalAPI, directory: src/platforms/web/util).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free