2019-11-24 21:00:46 +00:00
|
|
|
import { ElementWithTransition } from '../components/Transition'
|
2019-11-22 20:31:55 +00:00
|
|
|
|
2019-10-05 14:35:19 +00:00
|
|
|
// compiler should normalize class + :class bindings on the same element
|
2018-09-19 15:35:38 +00:00
|
|
|
// into a single binding ['staticClass', dynamic]
|
2019-12-09 19:52:20 +00:00
|
|
|
export function patchClass(el: Element, value: string | null, isSVG: boolean) {
|
|
|
|
if (value == null) {
|
|
|
|
value = ''
|
|
|
|
}
|
2018-09-19 15:35:38 +00:00
|
|
|
// directly setting className should be faster than setAttribute in theory
|
|
|
|
if (isSVG) {
|
2018-09-24 23:11:14 +00:00
|
|
|
el.setAttribute('class', value)
|
2018-09-19 15:35:38 +00:00
|
|
|
} else {
|
2019-11-29 16:53:54 +00:00
|
|
|
// if this is an element during a transition, take the temporary transition
|
|
|
|
// classes into account.
|
|
|
|
const transtionClasses = (el as ElementWithTransition)._vtc
|
|
|
|
if (transtionClasses) {
|
|
|
|
value = [value, ...transtionClasses].join(' ')
|
|
|
|
}
|
2018-09-24 23:11:14 +00:00
|
|
|
el.className = value
|
2018-09-19 15:35:38 +00:00
|
|
|
}
|
|
|
|
}
|