mirror of https://github.com/vuejs/core.git
27 lines
712 B
TypeScript
27 lines
712 B
TypeScript
// style properties that should NOT have "px" added when numeric
|
|
const nonNumericRE = /acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i
|
|
|
|
export function patchStyle(el: any, prev: any, next: any, data: any) {
|
|
const { style } = el
|
|
if (!next) {
|
|
el.removeAttribute('style')
|
|
} else if (typeof next === 'string') {
|
|
style.cssText = next
|
|
} else {
|
|
for (const key in next) {
|
|
let value = next[key]
|
|
if (typeof value === 'number' && !nonNumericRE.test(key)) {
|
|
value = value + 'px'
|
|
}
|
|
style[key] = value
|
|
}
|
|
if (prev && typeof prev !== 'string') {
|
|
for (const key in prev) {
|
|
if (!next[key]) {
|
|
style[key] = ''
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|