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