MCPcopy
hub / github.com/vuejs/core / patchStyle

Function patchStyle

packages/runtime-dom/src/modules/style.ts:14–79  ·  view source on GitHub ↗
(el: Element, prev: Style, next: Style)

Source from the content-addressed store, hash-verified

12const displayRE = /(?:^|;)\s*display\s*:/
13
14export function patchStyle(el: Element, prev: Style, next: Style): void {
15 const style = (el as HTMLElement).style
16 const isCssString = isString(next)
17 let hasControlledDisplay = false
18 if (next && !isCssString) {
19 if (prev) {
20 if (!isString(prev)) {
21 for (const key in prev) {
22 if (next[key] == null) {
23 setStyle(style, key, '')
24 }
25 }
26 } else {
27 for (const prevStyle of prev.split(';')) {
28 const key = prevStyle.slice(0, prevStyle.indexOf(':')).trim()
29 if (next[key] == null) {
30 setStyle(style, key, '')
31 }
32 }
33 }
34 }
35 for (const key in next) {
36 if (key === 'display') {
37 hasControlledDisplay = true
38 }
39 const value = next[key]
40 if (value != null) {
41 if (
42 !shouldPreserveTextareaResizeStyle(
43 el,
44 key,
45 !isString(prev) && prev ? prev[key] : undefined,
46 value,
47 )
48 ) {
49 setStyle(style, key, value)
50 }
51 } else {
52 setStyle(style, key, '')
53 }
54 }
55 } else {
56 if (isCssString) {
57 if (prev !== next) {
58 // #9821
59 const cssVarText = (style as any)[CSS_VAR_TEXT]
60 if (cssVarText) {
61 ;(next as string) += ';' + cssVarText
62 }
63 style.cssText = next as string
64 hasControlledDisplay = displayRE.test(next)
65 }
66 } else if (prev) {
67 el.removeAttribute('style')
68 }
69 }
70 // indicates the element also has `v-show`.
71 if (vShowOriginalDisplay in el) {

Callers 1

patchPropFunction · 0.90

Calls 5

isStringFunction · 0.90
setStyleFunction · 0.85
indexOfMethod · 0.80
testMethod · 0.80

Tested by

no test coverage detected