style.js 530 B

123456789101112131415161718192021
  1. /* @flow */
  2. import { escape } from 'he'
  3. import { hyphenate } from 'shared/util'
  4. import { getStyle } from 'web/util/style'
  5. function genStyleText (vnode: VNode): string {
  6. let styleText = ''
  7. const style = getStyle(vnode, false)
  8. for (const key in style) {
  9. styleText += `${hyphenate(key)}:${style[key]};`
  10. }
  11. return styleText
  12. }
  13. export default function renderStyle (vnode: VNodeWithData): ?string {
  14. const styleText = genStyleText(vnode)
  15. if (styleText) {
  16. return ` style=${JSON.stringify(escape(styleText))}`
  17. }
  18. }