class.ts 692 B

123456789101112131415161718
  1. import { ElementWithTransition } from '../components/Transition'
  2. // compiler should normalize class + :class bindings on the same element
  3. // into a single binding ['staticClass', dynamic]
  4. export function patchClass(el: Element, value: string, isSVG: boolean) {
  5. // directly setting className should be faster than setAttribute in theory
  6. if (isSVG) {
  7. el.setAttribute('class', value)
  8. } else {
  9. // if this is an element during a transition, take the temporary transition
  10. // classes into account.
  11. const transtionClasses = (el as ElementWithTransition)._vtc
  12. if (transtionClasses) {
  13. value = [value, ...transtionClasses].join(' ')
  14. }
  15. el.className = value
  16. }
  17. }