| 22 | * @return {Srcset<SrcsetSourceDef>} |
| 23 | */ |
| 24 | export function srcsetFromElement(element) { |
| 25 | const srcsetAttr = element.getAttribute('srcset'); |
| 26 | if (srcsetAttr) { |
| 27 | return parseSrcset(srcsetAttr); |
| 28 | } |
| 29 | // We can't push `src` via `parseSrcset` because URLs in `src` are not always |
| 30 | // RFC compliant and can't be easily parsed as an `srcset`. For instance, |
| 31 | // they sometimes contain space characters. |
| 32 | const srcAttr = element.getAttribute('src'); |
| 33 | userAssert( |
| 34 | srcAttr, |
| 35 | 'Either non-empty "srcset" or "src" attribute must be specified: %s', |
| 36 | element |
| 37 | ); |
| 38 | return srcsetFromSrc(srcAttr); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Creates a Srcset from a `src` attribute value. |