vue3-yuanma/packages/runtime-dom/src/modules/class.ts

22 lines
741 B
TypeScript
Raw Normal View History

2019-11-24 21:00:46 +00:00
import { ElementWithTransition } from '../components/Transition'
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]
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 {
// 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
}
}