(input)
| 29 | } |
| 30 | |
| 31 | export async function convertImagesInInput (input) { |
| 32 | if (!input.files || input.files.length === 0) return |
| 33 | |
| 34 | const dt = new DataTransfer() |
| 35 | let didConvert = false |
| 36 | |
| 37 | for (const file of Array.from(input.files)) { |
| 38 | let converted = file |
| 39 | |
| 40 | try { |
| 41 | if (['image/bmp', 'image/vnd.microsoft.icon', 'image/svg+xml', 'image/gif'].includes(file.type)) { |
| 42 | converted = await convertImage(file, 'image/png') |
| 43 | didConvert = true |
| 44 | } else if (['image/heic', 'image/heif', 'image/heic-sequence', 'image/heif-sequence', 'image/avif', 'image/avif-sequence', 'image/webp'].includes(file.type)) { |
| 45 | converted = await convertImage(file, 'image/jpeg', 0.9) |
| 46 | didConvert = true |
| 47 | } |
| 48 | } catch (e) { |
| 49 | alert(e.message) |
| 50 | } |
| 51 | |
| 52 | dt.items.add(converted) |
| 53 | } |
| 54 | |
| 55 | if (didConvert) { |
| 56 | input.files = dt.files |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | export default class extends HTMLElement { |
| 61 | connectedCallback () { |
no test coverage detected