| 3 | // compiler should normalize class + :class bindings on the same element |
| 4 | // into a single binding ['staticClass', dynamic] |
| 5 | export function patchClass( |
| 6 | el: Element, |
| 7 | value: string | null, |
| 8 | isSVG: boolean, |
| 9 | ): void { |
| 10 | // directly setting className should be faster than setAttribute in theory |
| 11 | // if this is an element during a transition, take the temporary transition |
| 12 | // classes into account. |
| 13 | const transitionClasses = (el as ElementWithTransition)[vtcKey] |
| 14 | if (transitionClasses) { |
| 15 | value = ( |
| 16 | value ? [value, ...transitionClasses] : [...transitionClasses] |
| 17 | ).join(' ') |
| 18 | } |
| 19 | if (value == null) { |
| 20 | el.removeAttribute('class') |
| 21 | } else if (isSVG) { |
| 22 | el.setAttribute('class', value) |
| 23 | } else { |
| 24 | el.className = value |
| 25 | } |
| 26 | } |