Skip to content

Commit

Permalink
fix: parse srcset attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jlalmes authored and oct16 committed Apr 22, 2021
1 parent c1957dd commit a4ea53f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/virtual-dom/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,20 @@ export function setAttribute(node: HTMLElement, name: string, value: string | bo
}

// The srcset attribute specifies the URL of the image to use in different situations
if (name === 'srcset' || name === 'sizes') {
if (name === 'srcset') {
const srcArray = value.split(',')
value = srcArray.map(src => completeAttrHref(src.trim(), node)).join(', ')
value = srcArray
.map(src => {
const [url, size] = src.trim().split(' ')
if (url && size) {
return `${completeAttrHref(url, node)} ${size}`
}
if (url) {
return completeAttrHref(url, node)
}
return ''
})
.join(', ')
// decode uri
value = decodeURIComponent(value)
}
Expand Down

0 comments on commit a4ea53f

Please sign in to comment.