| 172 | } |
| 173 | |
| 174 | function parseSrcset(string: string): ImageCandidate[] { |
| 175 | const matches = string |
| 176 | .trim() |
| 177 | .replace(escapedSpaceCharactersRE, ' ') |
| 178 | .replace(/\r?\n/, '') |
| 179 | .replace(/,\s+/, ', ') |
| 180 | .replaceAll(/\s+/g, ' ') |
| 181 | .matchAll(imageCandidateRE) |
| 182 | return Array.from(matches, ({ groups }) => ({ |
| 183 | url: groups?.url?.trim() ?? '', |
| 184 | descriptor: groups?.descriptor?.trim() ?? '', |
| 185 | })).filter(({ url }) => !!url) |
| 186 | } |
| 187 | |
| 188 | function joinSrcset(ret: ImageCandidate[]) { |
| 189 | return ret.map(({ url, descriptor }) => url + (descriptor ? ` ${descriptor}` : '')).join(', ') |