({dataURL, width, height, useViewBox}: ImageDetails, theme: Theme)
| 300 | const objectURLs = new Set<string>(); |
| 301 | |
| 302 | export function getFilteredImageURL({dataURL, width, height, useViewBox}: ImageDetails, theme: Theme): string { |
| 303 | if (dataURL.startsWith('data:image/svg+xml')) { |
| 304 | dataURL = escapeXML(dataURL); |
| 305 | } |
| 306 | const matrix = getSVGFilterMatrixValue(theme); |
| 307 | const size = useViewBox ? `viewBox="0 0 ${width} ${height}"` : `width="${width}" height="${height}"`; |
| 308 | const svg = [ |
| 309 | `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ${size}>`, |
| 310 | '<defs>', |
| 311 | '<filter id="darkreader-image-filter">', |
| 312 | `<feColorMatrix type="matrix" values="${matrix}" />`, |
| 313 | '</filter>', |
| 314 | '</defs>', |
| 315 | `<image width="${width}" height="${height}" filter="url(#darkreader-image-filter)" xlink:href="${dataURL}" />`, |
| 316 | '</svg>', |
| 317 | ].join(''); |
| 318 | |
| 319 | if (!isBlobURLSupported) { |
| 320 | return `data:image/svg+xml;base64,${btoa(svg)}`; |
| 321 | } |
| 322 | |
| 323 | const bytes = new Uint8Array(svg.length); |
| 324 | for (let i = 0; i < svg.length; i++) { |
| 325 | bytes[i] = svg.charCodeAt(i); |
| 326 | } |
| 327 | const blob = new Blob([bytes], {type: 'image/svg+xml'}); |
| 328 | const objectURL = URL.createObjectURL(blob); |
| 329 | objectURLs.add(objectURL); |
| 330 | return objectURL; |
| 331 | } |
| 332 | |
| 333 | export function getSolidColorImageURL({width, height, useViewBox}: ImageDetails, color: string): string { |
| 334 | const size = useViewBox ? `viewBox="0 0 ${width} ${height}"` : `width="${width}" height="${height}"`; |
no test coverage detected