diff --git a/example/app.vue b/example/app.vue index 2e6d5a476..f3f6e4e61 100644 --- a/example/app.vue +++ b/example/app.vue @@ -8,6 +8,7 @@ width="300" height="200" class="rounded" + alt="Mountain landscape by Benjamin Voros" />
Photo by
Photo by @@ -20,6 +22,7 @@ placeholder width="500" height="500" + alt="" @load="() => { console.log('Image was loaded') }" /> @@ -35,12 +39,14 @@ :src="'nonexistent' + src" width="500" height="500" + alt="" @error="() => { console.log('Error loading image') }" /> diff --git a/playground/app/pages/img.vue b/playground/app/pages/img.vue index 63175f353..c40968f11 100644 --- a/playground/app/pages/img.vue +++ b/playground/app/pages/img.vue @@ -5,6 +5,7 @@ src="/images/colors.jpg" width="500" height="500" + alt="" @load="isLoaded = true" />

Received onLoad event: {{ isLoaded }}

@@ -15,6 +16,7 @@ placeholder width="500" height="500" + alt="" @load="isLoaded = true" /> diff --git a/playground/app/pages/ipx-layers.vue b/playground/app/pages/ipx-layers.vue index 57f4bcef5..a1f754deb 100644 --- a/playground/app/pages/ipx-layers.vue +++ b/playground/app/pages/ipx-layers.vue @@ -5,6 +5,7 @@ src="/images/colors.jpg" width="500" height="500" + alt="" @load="isLoadedRoot = true" />

Received onLoad event: {{ isLoadedRoot }}

@@ -14,6 +15,7 @@ src="/images/colors-layer.jpg" width="500" height="500" + alt="" @load="isLoadedLayer = true" />

Received onLoad event: {{ isLoadedLayer }}

@@ -23,6 +25,7 @@ src="/images/colors-layer-config.jpg" width="500" height="500" + alt="" @load="isLoadedLayerWithConfig = true" />

Received onLoad event: {{ isLoadedLayerWithConfig }}

diff --git a/playground/app/pages/picture.vue b/playground/app/pages/picture.vue index 895faec5c..93295a71a 100644 --- a/playground/app/pages/picture.vue +++ b/playground/app/pages/picture.vue @@ -5,6 +5,7 @@ format="avif,webp" width="500" height="500" + alt="" @load="isLoaded = true" />

Received onLoad event: {{ isLoaded }}

diff --git a/playground/app/pages/responsive.vue b/playground/app/pages/responsive.vue index 98a1fe86f..e7dda24d0 100644 --- a/playground/app/pages/responsive.vue +++ b/playground/app/pages/responsive.vue @@ -4,12 +4,14 @@

nuxt-picture

-->
i'm 50vw @@ -18,12 +20,14 @@ src="/logos/nuxt.png" sizes="sm:100vw md:50vw lg:400px" loading="lazy" + alt="" />
@@ -34,6 +38,7 @@ sizes="sm:100vw md:50vw lg:400px" placeholder class="responsive-placeholder-img" + alt="" />
diff --git a/playground/app/providers.ts b/playground/app/providers.ts index 6417d39fb..98a7d1101 100644 --- a/playground/app/providers.ts +++ b/playground/app/providers.ts @@ -4,6 +4,7 @@ interface Provider { name: keyof ImageProviders samples: { src: string + alt: string from?: string link?: string width?: number @@ -23,6 +24,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://unsplash.com/@jeremythomasphoto?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText', + alt: '', }, { src: '/images/everest.jpg', @@ -30,6 +32,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://en.wikipedia.org/wiki/Mount_Everest', + alt: '', }, { src: '/images/tacos.svg', @@ -37,6 +40,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://icons8.com/illustrations/illustration/abstract-1419', + alt: '', }, { src: '/unsplash/photo-1606112219348-204d7d8b94ee', @@ -44,6 +48,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://unsplash.com/@omidarmin?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText', + alt: '', }, ], }, @@ -57,6 +62,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://unsplash.com/@jeremythomasphoto?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText', + alt: '', }, { src: '/images/colors-layer.jpg', @@ -64,6 +70,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://unsplash.com/@jeremythomasphoto?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText', + alt: '', }, { src: '/images/colors-layer-config.jpg', @@ -71,6 +78,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://unsplash.com/@jeremythomasphoto?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText', + alt: '', }, { src: '/images/everest.jpg', @@ -78,6 +86,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://en.wikipedia.org/wiki/Mount_Everest', + alt: '', }, { src: '/images/tacos.svg', @@ -85,6 +94,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://icons8.com/illustrations/illustration/abstract-1419', + alt: '', }, { src: '/unsplash/photo-1606112219348-204d7d8b94ee', @@ -92,6 +102,7 @@ export const providers: Provider[] = [ width: 300, height: 300, link: 'https://unsplash.com/@omidarmin?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText', + alt: '', }, ], }, @@ -102,15 +113,18 @@ export const providers: Provider[] = [ { src: '/nuxt.png', height: 200, + alt: '', }, { src: '/nuxt.png', height: 300, width: 300, + alt: '', }, { src: '/nuxt.png', quality: 50, + alt: '', }, { src: '/nuxt.png', @@ -122,6 +136,7 @@ export const providers: Provider[] = [ fh: 200, }, }, + alt: '', }, ], }, @@ -132,6 +147,7 @@ export const providers: Provider[] = [ { src: '/test.jpg', width: 300, + alt: '', }, ], }, @@ -141,17 +157,20 @@ export const providers: Provider[] = [ samples: [ { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', + alt: '', }, { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', width: 450, height: 300, + alt: '', }, { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', width: 300, height: 300, format: 'webp', + alt: '', }, { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', @@ -159,6 +178,7 @@ export const providers: Provider[] = [ height: 300, fit: 'contain', format: 'webp', + alt: '', }, { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', @@ -166,6 +186,7 @@ export const providers: Provider[] = [ height: 300, fit: 'cover', format: 'webp', + alt: '', }, { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', @@ -173,6 +194,7 @@ export const providers: Provider[] = [ height: 300, fit: 'fill', format: 'webp', + alt: '', }, { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', @@ -182,6 +204,7 @@ export const providers: Provider[] = [ modifiers: { position: 'top', }, + alt: '', }, { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', @@ -191,18 +214,21 @@ export const providers: Provider[] = [ modifiers: { position: 'left bottom', }, + alt: '', }, { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', width: 300, height: 300, quality: 80, + alt: '', }, { src: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F869bfbaec9c64415ae68235d9b7b1425', width: 300, height: 300, format: 'png', + alt: '', }, ], }, @@ -218,6 +244,7 @@ export const providers: Provider[] = [ sharpen: true, aspectRatio: '16:9', }, + alt: '', }, { src: '/bunny2.jpg', @@ -225,6 +252,7 @@ export const providers: Provider[] = [ crop: '750,750', crop_gravity: 'north', }, + alt: '', }, { src: '/bunny3.jpg', @@ -232,6 +260,7 @@ export const providers: Provider[] = [ flop: true, auto_optimize: 'high', }, + alt: '', }, ], }, @@ -243,6 +272,7 @@ export const providers: Provider[] = [ src: 'https://s3.that-test.site/burger.jpeg', height: 300, fit: 'contain', + alt: '', }, ], }, @@ -252,12 +282,14 @@ export const providers: Provider[] = [ samples: [ { src: '/remote/nuxt-org/blog/going-full-static/main', + alt: '', }, { src: '/blog/going-full-static/main', width: 200, height: 200, fit: 'cropping', + alt: '', }, { src: '/remote/nuxt-org/blog/going-full-static/main', @@ -265,6 +297,7 @@ export const providers: Provider[] = [ height: 200, fit: 'thumbnail', roundCorner: 'max', + alt: '', }, ], }, @@ -274,17 +307,20 @@ export const providers: Provider[] = [ samples: [ { src: '//images.ctfassets.net/fbr4i5aajb0w/6y0psij2o02YIwGScEo4kS/1b3f09b8fcedece1d17ea58417b55eb4/photo-1421986527537-888d998adb74.jpeg', + alt: '', }, { src: '//images.ctfassets.net/fbr4i5aajb0w/6y0psij2o02YIwGScEo4kS/1b3f09b8fcedece1d17ea58417b55eb4/photo-1421986527537-888d998adb74.jpeg', width: 200, height: 133, + alt: '', }, { src: '//images.ctfassets.net/fbr4i5aajb0w/6y0psij2o02YIwGScEo4kS/1b3f09b8fcedece1d17ea58417b55eb4/photo-1421986527537-888d998adb74.jpeg', width: 200, height: 200, fit: 'contain', + alt: '', }, ], }, @@ -300,12 +336,14 @@ export const providers: Provider[] = [ fit: 'contain', quality: 65, format: 'webp', + alt: '', }, { src: 'bag.jpg', width: 500, height: 500, fit: 'contain', + alt: '', }, { src: 'boat.jpg', @@ -313,6 +351,7 @@ export const providers: Provider[] = [ height: 800, quality: 75, fit: 'cover', + alt: '', }, { src: 'img.jpg', @@ -320,6 +359,7 @@ export const providers: Provider[] = [ height: 300, format: 'webp', fit: 'fill', + alt: '', }, ], }, @@ -327,8 +367,14 @@ export const providers: Provider[] = [ { name: 'fastly', samples: [ - { src: '/image.jpg' }, - { src: '/plant.jpeg' }, + { + src: '/image.jpg', + alt: '', + }, + { + src: '/plant.jpeg', + alt: '', + }, ], }, // Filerobot @@ -343,12 +389,14 @@ export const providers: Provider[] = [ fit: 'contain', quality: 65, format: 'webp', + alt: '', }, { src: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b', width: 500, height: 500, fit: 'contain', + alt: '', }, { src: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b', @@ -356,6 +404,7 @@ export const providers: Provider[] = [ height: 800, quality: 75, fit: 'cover', + alt: '', }, { src: '/monitoring3/boat-2023-03-06T15%3A03%3A12.6382894Z?vh=b3583b', @@ -363,6 +412,7 @@ export const providers: Provider[] = [ height: 300, format: 'webp', fit: 'fill', + alt: '', }, ], }, @@ -372,12 +422,14 @@ export const providers: Provider[] = [ samples: [ { src: '/girl.jpeg', + alt: '', }, { src: '/girl.jpeg', width: 400, height: 300, fit: 'fill', + alt: '', }, { src: '/girl.jpeg', @@ -386,6 +438,7 @@ export const providers: Provider[] = [ modifiers: { focus: 'auto', }, + alt: '', }, { src: '/girl.jpeg', @@ -394,6 +447,7 @@ export const providers: Provider[] = [ modifiers: { focus: 'face', }, + alt: '', }, { src: '/girl.jpeg', @@ -403,6 +457,7 @@ export const providers: Provider[] = [ focus: 'face', radius: 'max', }, + alt: '', }, ], }, @@ -414,14 +469,17 @@ export const providers: Provider[] = [ src: 'npm', width: 50, height: 50, + alt: '', }, { src: 'nuxt', width: 50, height: 100, + alt: '', }, { src: 'unjs', + alt: '', }, ], }, @@ -434,6 +492,7 @@ export const providers: Provider[] = [ width: 300, height: 300, fit: 'cover', + alt: '', }, ], }, @@ -446,6 +505,7 @@ export const providers: Provider[] = [ width: 300, height: 300, fit: 'cover', + alt: '', }, ], }, @@ -459,6 +519,7 @@ export const providers: Provider[] = [ height: 300, fit: 'inside', modifiers: { metadata: 'true', sharpen: 10 }, + alt: '', }, ], }, @@ -471,6 +532,7 @@ export const providers: Provider[] = [ width: 1000, quality: 70, modifiers: { gam: 0.9, sharp: 8 }, + alt: '', }, ], }, @@ -482,11 +544,13 @@ export const providers: Provider[] = [ width: 100, height: 100, fit: 'cover', + alt: '', }, { src: '/images/apple.jpg', width: 400, height: 300, + alt: '', }, ], }, @@ -497,12 +561,14 @@ export const providers: Provider[] = [ src: '/images/apple.jpg', width: 101, fit: 'contain', + alt: '', }, { src: '/images/apple.jpg', width: 200, height: 200, fit: 'fill', + alt: '', }, ], }, @@ -514,6 +580,7 @@ export const providers: Provider[] = [ src: 'id/237', width: 200, height: 300, + alt: '', }, { src: 'id/870', @@ -522,6 +589,7 @@ export const providers: Provider[] = [ modifiers: { grayscale: true, }, + alt: '', }, { src: 'id/1025', @@ -530,11 +598,13 @@ export const providers: Provider[] = [ modifiers: { blur: 5, }, + alt: '', }, { src: 'seed/picsum', width: 200, height: 200, + alt: '', }, ], }, @@ -542,16 +612,34 @@ export const providers: Provider[] = [ { name: 'prepr', samples: [ - { src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', quality: 5 }, - { src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', height: 200 }, - { src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', width: 200 }, - { src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', width: 200, height: 200 }, + { + src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', + quality: 5, + alt: '', + }, + { + src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', + height: 200, + alt: '', + }, + { + src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', + width: 200, + alt: '', + }, + { + src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', + width: 200, + height: 200, + alt: '', + }, { src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', modifiers: { w: 250, h: 250, }, + alt: '', }, { src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', @@ -560,6 +648,7 @@ export const providers: Provider[] = [ modifiers: { crop: 'southeast', }, + alt: '', }, { src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', @@ -568,12 +657,14 @@ export const providers: Provider[] = [ modifiers: { crop: 'centre', }, + alt: '', }, { src: '4rhkcc7xzk7d-claymemoirscom-spider-pic.jpg', width: 250, height: 200, fit: 'cover', + alt: '', }, ], }, @@ -583,20 +674,24 @@ export const providers: Provider[] = [ samples: [ { src: 'https://images.prismic.io/200629-sms-hoy/f596a543-d593-4296-9abd-3d3ac15f1e39_ray-hennessy-mpw37yXc_WQ-unsplash.jpg?auto=compress,format&w=600&h=900', + alt: '', }, { src: 'https://images.prismic.io/200629-sms-hoy/f596a543-d593-4296-9abd-3d3ac15f1e39_ray-hennessy-mpw37yXc_WQ-unsplash.jpg?auto=compress,format&w=600&h=900', width: 200, + alt: '', }, { src: 'https://images.prismic.io/200629-sms-hoy/f596a543-d593-4296-9abd-3d3ac15f1e39_ray-hennessy-mpw37yXc_WQ-unsplash.jpg?auto=compress,format&w=600&h=900', height: 200, + alt: '', }, { src: 'https://images.prismic.io/200629-sms-hoy/f596a543-d593-4296-9abd-3d3ac15f1e39_ray-hennessy-mpw37yXc_WQ-unsplash.jpg?auto=compress,format&w=600&h=900', width: 200, height: 200, fit: 'crop', + alt: '', }, ], }, @@ -606,30 +701,35 @@ export const providers: Provider[] = [ samples: [ { src: '/football.jpg', + alt: '', }, // basic { src: '/football.jpg', width: 501, height: 501, fit: 'cover', + alt: '', }, // cover { src: '/football.jpg', width: 501, height: 1001, fit: 'contain', + alt: '', }, // contain { src: '/football.jpg', width: 501, height: 1001, fit: 'fill', + alt: '', }, // fill { src: '/football.jpg', width: 501, height: 501, fit: 'inside', + alt: '', }, // inside { src: 'cat_1x1.jpg', @@ -637,48 +737,58 @@ export const providers: Provider[] = [ height: 600, fit: 'inside', background: 'red', + alt: '', }, // ratio { src: '/football.jpg', width: 501, height: 1001, fit: 'outside', + alt: '', }, // outside { src: '/icon-500.png', width: 501, background: 'red', + alt: '', }, // background transformation { src: '/peacock.jpg', width: 501, format: 'avif', + alt: '', }, // output format { src: '/peacock.jpg', width: 501, format: 'preview', + alt: '', }, // output format : mode preview { src: '/peacock.jpg', width: 501, format: 'maincolor', + alt: '', }, // output format : mode maincolor { src: '/peacock.jpg', width: 501, format: 'blank', + alt: '', }, // output format : blank { src: '/peacock.jpg', quality: 100, + alt: '', }, // output quality : max { src: '/peacock.jpg', quality: 1, + alt: '', }, // output quality : poor quality { src: '/woman-14.jpg', + alt: '', }, // original { src: '/woman-14.jpg', @@ -688,6 +798,7 @@ export const providers: Provider[] = [ { focus: 'auto', }, + alt: '', }, // cover 501x301 { src: '/woman-14.jpg', @@ -697,6 +808,7 @@ export const providers: Provider[] = [ { focus: 'auto', }, + alt: '', }, // inside width 501 { src: 'cat_1x1.jpg', @@ -706,6 +818,7 @@ export const providers: Provider[] = [ { cover: '4:3', }, + alt: '', }, // ratio { src: '/cat.jpg', @@ -713,6 +826,7 @@ export const providers: Provider[] = [ { crop: '500x100', }, + alt: '', }, // crop api { src: '/cat.jpg', @@ -721,6 +835,7 @@ export const providers: Provider[] = [ { crop: '500x100@700x400', }, + alt: '', }, // crop api with coordinates { src: '/cat.jpg', @@ -730,6 +845,7 @@ export const providers: Provider[] = [ focus: 'auto', crop: '500x100', }, + alt: '', }, // crop api with focus auto { src: '/cat_1x1.jpg', @@ -738,6 +854,7 @@ export const providers: Provider[] = [ focus: 'auto', crop: '500x500', }, + alt: '', }, // crop api with focus auto { src: '/football.jpg', @@ -746,6 +863,7 @@ export const providers: Provider[] = [ focus: 'auto', cover: '1:1', }, + alt: '', }, // crop api with focus auto { src: '/puppy.jpg', @@ -754,6 +872,7 @@ export const providers: Provider[] = [ { flip: 'both', }, + alt: '', }, // flip api { src: '/peacock.jpg', @@ -762,6 +881,7 @@ export const providers: Provider[] = [ { truecolor: true, }, + alt: '', }, // truecolor api { src: '/peacock.jpg', @@ -770,6 +890,7 @@ export const providers: Provider[] = [ { truecolor: false, }, + alt: '', }, // truecolor api { src: '/man-13.jpg', @@ -778,6 +899,7 @@ export const providers: Provider[] = [ { turn: 'left', }, + alt: '', }, // turn api { src: '/man-13.jpg', @@ -786,6 +908,7 @@ export const providers: Provider[] = [ { turn: 80, }, + alt: '', }, // turn api { src: '/man-13.jpg', @@ -794,6 +917,7 @@ export const providers: Provider[] = [ { turn: 90, }, + alt: '', }, // turn api { src: '/cherry-3.jpg', @@ -804,6 +928,7 @@ export const providers: Provider[] = [ focus: 'auto', zoom: 1.5, }, + alt: '', }, // zoom api { src: '/cherry-3.jpg', @@ -814,6 +939,7 @@ export const providers: Provider[] = [ focus: 'auto', zoom: 3, }, + alt: '', }, // zoom api { src: '/football.jpg', @@ -823,6 +949,7 @@ export const providers: Provider[] = [ focus: 'auto', turn: 'left', }, + alt: '', }, { src: '/football.jpg', @@ -832,6 +959,7 @@ export const providers: Provider[] = [ turn: 'left', cover: '16:9', }, + alt: '', }, ], }, @@ -841,24 +969,28 @@ export const providers: Provider[] = [ samples: [ { src: 'image-G3i4emG6B8JnTmGoN0UjgAp8-300x450-jpg', + alt: '', }, { src: 'image-G3i4emG6B8JnTmGoN0UjgAp8-300x450-jpg', width: 200, height: 200, fit: 'fill', + alt: '', }, { src: 'image-G3i4emG6B8JnTmGoN0UjgAp8-300x450-jpg', width: 200, height: 200, fit: 'cover', + alt: '', }, { src: 'image-G3i4emG6B8JnTmGoN0UjgAp8-300x450-jpg', width: 200, height: 200, fit: 'contain', + alt: '', }, { src: 'image-G3i4emG6B8JnTmGoN0UjgAp8-300x450-jpg', @@ -879,6 +1011,7 @@ export const providers: Provider[] = [ y: 0.32778302629507167, }, }, + alt: '', }, ], }, @@ -888,11 +1021,13 @@ export const providers: Provider[] = [ samples: [ { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', width: 450, height: 300, + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', @@ -901,6 +1036,7 @@ export const providers: Provider[] = [ modifiers: { padColor: 'ff0000', }, + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', @@ -909,6 +1045,7 @@ export const providers: Provider[] = [ modifiers: { crop: 'center', }, + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', @@ -917,6 +1054,7 @@ export const providers: Provider[] = [ modifiers: { crop: 'top', }, + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', @@ -925,6 +1063,7 @@ export const providers: Provider[] = [ modifiers: { crop: 'bottom', }, + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', @@ -933,6 +1072,7 @@ export const providers: Provider[] = [ modifiers: { crop: 'left', }, + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', @@ -941,6 +1081,7 @@ export const providers: Provider[] = [ modifiers: { crop: 'right', }, + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', @@ -951,18 +1092,21 @@ export const providers: Provider[] = [ cropWidth: 450, cropHeight: 300, }, + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', width: 300, height: 300, format: 'png', + alt: '', }, { src: 'https://cdn.shopify.com/static/sample-images/garnished.jpeg', width: 300, height: 300, quality: 1, + alt: '', }, ], }, @@ -1101,18 +1245,21 @@ export const providers: Provider[] = [ src: '/test.png', width: 300, height: 200, + alt: '', }, { src: '/test.png', width: 400, height: 300, quality: 80, + alt: '', }, { src: '/test.png', width: 500, height: 500, fit: 'cover', + alt: '', }, ], }, @@ -1129,6 +1276,7 @@ export const providers: Provider[] = [ format: 'auto', from: 'Photo by Omid Armin', link: 'https://unsplash.com/@omidarmin?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText', + alt: '', }, { src: 'https://images.unsplash.com/photo-1532236204992-f5e85c024202?crop=entropy&cs=tinysrgb&ixid=MnwxOTgwMDZ8MHwxfHNlYXJjaHwyOHx8dG9reW98ZW58MHx8fHwxNjczNzk3MDIz&w=500', @@ -1139,6 +1287,7 @@ export const providers: Provider[] = [ format: 'auto', from: 'Photo by Jezael Melgoza', link: 'https://unsplash.com/@jezar?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText', + alt: '', }, ], }, @@ -1150,6 +1299,7 @@ export const providers: Provider[] = [ src: 'colors.jpg', width: 750, quality: 75, + alt: '', }, ], }, @@ -1161,20 +1311,24 @@ export const providers: Provider[] = [ src: 'c160afba-8b42-45a9-a46a-d393248b0072', width: 512, height: 512, + alt: '', }, { src: '4740215e-ed0f-478f-8dbd-4859d8ea4e60', width: 512, + alt: '', }, { src: '2e36710d-21ea-42b3-ac9e-3caa80f7e7bc', height: 512, + alt: '', }, { src: '678053e2-ad98-42be-8443-e114b8a1b294', width: 1080, height: 300, fit: 'cover', + alt: '', }, { src: '034e80f0-14af-408a-9eae-1e233c361256', @@ -1184,24 +1338,28 @@ export const providers: Provider[] = [ modifiers: { setfill: '000000', }, + alt: '', }, { src: '6d7dd597-a829-4f03-a3cc-f87ff8a94d14', width: 1080, height: 300, fit: 'fill', + alt: '', }, { src: 'beb68506-f5c3-4b85-8d8c-143ad62d5390', width: 1080, height: 300, fit: 'inside', + alt: '', }, { src: '31e84033-f22e-4ed0-9462-76f9179e13e1', width: 1080, height: 300, fit: 'outside', + alt: '', }, ], }, @@ -1294,21 +1452,25 @@ export const providers: Provider[] = [ { src: 'https://picsum.photos/200', format: 'webp', + alt: '', }, { src: 'https://picsum.photos/200', format: 'webp', modifiers: { mask: 'circle' }, + alt: '', }, { src: 'https://picsum.photos/200', format: 'webp', modifiers: { mask: 'circle', filter: 'sepia' }, + alt: '', }, { src: 'https://picsum.photos/200', format: 'webp', modifiers: { mask: 'circle', filter: 'sepia', quality: 80 }, + alt: '', }, ], }, @@ -1320,42 +1482,50 @@ export const providers: Provider[] = [ src: '/test.png', width: 750, quality: 75, + alt: '', }, { src: '/harris-large.jpg', width: 500, format: 'png', + alt: '', }, { src: '/lacoste.jpg', width: 500, quality: 95, modifiers: { crop: 'trim' }, + alt: '', }, { src: '/look-big.jpg', height: 500, fit: 'contain', + alt: '', }, { src: '/look-big.jpg', height: 500, modifiers: { crop: 'face' }, + alt: '', }, { src: '/QW.pdf', width: 500, modifiers: { pdfPage: 1 }, + alt: '', }, { src: '/look-big.jpg', height: 500, modifiers: { text: 'Hello', textAlign: 'center', textPositionGravity: 'south', textBackgroundColor: '#ffff', textSize: 60, textFontFamily: 'Arial', textColor: 'white' }, + alt: '', }, { src: 't-shirt-man.jpg', height: 500, modifiers: { watermark: '/watermark-v1.png', watermarkPosition: 'center', watermarkWidth: '30%' }, + alt: '', }, ], }, @@ -1369,12 +1539,14 @@ export const providers: Provider[] = [ height: 500, fit: 'crop', quality: 90, + alt: '', }, { src: 'https://eu-central-1-shared-euc1-02.graphassets.com/cltsj3mii0pvd07vwb5cyh1ig/cltsrex89477t08unlckqx9ue', width: 500, fit: 'max', format: 'auto_image', + alt: '', }, { src: 'https://eu-central-1-shared-euc1-02.graphassets.com/cltsj3mii0pvd07vwb5cyh1ig/cltsrex89477t08unlckqx9ue', @@ -1382,6 +1554,7 @@ export const providers: Provider[] = [ height: 300, fit: 'clip', format: 'jpeg', + alt: '', }, ], }, @@ -1394,6 +1567,7 @@ export const providers: Provider[] = [ width: 500, height: 500, quality: 90, + alt: '', }, ], }, diff --git a/src/runtime/utils/props.ts b/src/runtime/utils/props.ts index dee657590..b733dd449 100644 --- a/src/runtime/utils/props.ts +++ b/src/runtime/utils/props.ts @@ -25,6 +25,7 @@ export interface BaseImageProps preload?: boolean | { fetchPriority: 'auto' | 'high' | 'low' } // attributes + alt: string width?: string | number height?: string | number crossorigin?: 'anonymous' | 'use-credentials' | boolean @@ -46,6 +47,7 @@ export const useImageProps = (p height: parseSize(props.height), crossorigin: props.crossorigin === true ? 'anonymous' : props.crossorigin || undefined, nonce: props.nonce, + alt: props.alt, })) const imageModifiers = computed(() => { diff --git a/test/e2e/no-ssr.test.ts b/test/e2e/no-ssr.test.ts index ded8b4827..4882313d7 100644 --- a/test/e2e/no-ssr.test.ts +++ b/test/e2e/no-ssr.test.ts @@ -33,7 +33,7 @@ describe('browser (ssr: false)', () => { await page.goto(url(providerPath), { waitUntil: 'networkidle' }) await page.waitForSelector('img') - const images = await page.getByRole('img').all() + const images = await page.locator('img').all() expect(images).toHaveLength(provider.samples.length) diff --git a/test/e2e/ssr.test.ts b/test/e2e/ssr.test.ts index cab6c08de..6256e7594 100644 --- a/test/e2e/ssr.test.ts +++ b/test/e2e/ssr.test.ts @@ -32,7 +32,7 @@ describe('browser (ssr: true)', () => { await page.goto(url(providerPath), { waitUntil: 'networkidle' }) await page.waitForSelector('img') - const images = await page.getByRole('img').all() + const images = await page.locator('img').all() expect(images).toHaveLength(provider.samples.length) diff --git a/test/nuxt/image.test.ts b/test/nuxt/image.test.ts index 60446a74a..86fbd9eeb 100644 --- a/test/nuxt/image.test.ts +++ b/test/nuxt/image.test.ts @@ -18,11 +18,12 @@ describe('Renders simple image', () => { height: 200, sizes: '200,500:500,900:900', src, + alt: '', }) }) it('Matches snapshot', () => { - expect(wrapper.html()).toMatchInlineSnapshot(`""`) + expect(wrapper.html()).toMatchInlineSnapshot(`""`) }) it('props.src is picked up by getImage()', () => { @@ -51,8 +52,9 @@ describe('Renders simple image', () => { sizes: '300:300px,400:400px', densities: '1x 2x 3x', src: 'image.png', + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('empty densities (fallback to global)', () => { @@ -62,8 +64,9 @@ describe('Renders simple image', () => { sizes: '300:300px,400:400px', densities: '', src: 'image.png', + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('empty string densities (fallback to global)', () => { @@ -73,8 +76,9 @@ describe('Renders simple image', () => { sizes: '300:300px,400:400px', densities: ' ', src: 'image.png', + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('error on invalid densities', () => { @@ -83,6 +87,7 @@ describe('Renders simple image', () => { height: 300, densities: 'x', src: 'image.png', + alt: '', })).toThrow(Error) }) @@ -92,8 +97,9 @@ describe('Renders simple image', () => { width: 300, height: 400, sizes: '150', + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('with single sizes entry (responsive)', () => { @@ -102,8 +108,9 @@ describe('Renders simple image', () => { width: 300, height: 400, sizes: 'sm:150', + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('de-duplicates sizes & srcset', () => { @@ -112,8 +119,9 @@ describe('Renders simple image', () => { height: 300, sizes: '200:200px,300:200px,400:400px,400:400px,500:500px,800:800px', src: 'image.png', + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('encodes characters', () => { @@ -122,8 +130,9 @@ describe('Renders simple image', () => { height: 200, sizes: '200,500:500,900:900', src: '/汉字.png', + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('correctly sets crop', () => { @@ -132,8 +141,9 @@ describe('Renders simple image', () => { width: 1000, height: 2000, sizes: 'sm:100vw md:300px lg:350px xl:350px 2xl:350px', + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('without sizes', () => { @@ -141,8 +151,9 @@ describe('Renders simple image', () => { src: '/image.png', width: 300, height: 400, + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('without sizes, but densities', () => { @@ -151,8 +162,9 @@ describe('Renders simple image', () => { width: 300, height: 400, densities: '1x 2x 3x', + alt: '', }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('with nonce', () => { @@ -161,6 +173,7 @@ describe('Renders simple image', () => { width: 300, height: 400, nonce: 'stub-nonce', + alt: '', }) const domNonce = img.element.getAttribute('nonce') expect(domNonce).toBe('stub-nonce') @@ -172,6 +185,7 @@ describe('Renders simple image', () => { width: 300, height: 400, nonce: 'stub-nonce', + alt: '', }) expect(img.getCurrentComponent().exposed?.imgEl).toBeDefined() expect(img.getCurrentComponent().exposed?.imgEl.value).toBeInstanceOf(HTMLImageElement) @@ -227,6 +241,7 @@ describe('Renders placeholder image', () => { height: 200, src, placeholder: true, + alt: '', }, }) }) @@ -258,6 +273,7 @@ describe('Renders placeholder image', () => { src, sizes: '200,500:500,900:900', placeholder: true, + alt: '', }, }) }) @@ -283,6 +299,7 @@ describe('Renders placeholder image', () => { src, placeholder: true, placeholderClass: 'placeholder', + alt: '', }, attrs: { class: [{ test: true }, 'other'], @@ -319,6 +336,7 @@ describe('Renders placeholder image', () => { height: 200, src, placeholder: true, + alt: '', }, }) }) @@ -336,6 +354,7 @@ describe('Sizes and densities behavior', () => { width: 300, height: 400, // Both sizes and densities are undefined + alt: '', }) const imgElement = img.find('img').element @@ -357,6 +376,7 @@ describe('Sizes and densities behavior', () => { height: 400, densities: '1x 2x', // sizes is undefined + alt: '', }) const imgElement = img.find('img').element @@ -378,6 +398,7 @@ describe('Sizes and densities behavior', () => { height: 400, sizes: 'sm:100vw md:50vw', densities: '1x 2x', // densities will be applied to each size variant + alt: '', }) const imgElement = img.find('img').element @@ -441,6 +462,7 @@ describe('Preset sizes and densities inheritance', () => { height: 400, preset: 'highDensity', // densities is intentionally undefined to test preset inheritance + alt: '', }, }) @@ -523,9 +545,10 @@ describe('Renders image, applies module config', () => { width: 200, height: 200, sizes: '200,500:500,900:900', + alt: '', }, }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('Module config .quality + props.quality => props.quality applies', () => { @@ -537,9 +560,10 @@ describe('Renders image, applies module config', () => { height: 200, sizes: '200,500:500,900:900', quality: 90, + alt: '', }, }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) it('Without quality config => default image', () => { @@ -551,9 +575,10 @@ describe('Renders image, applies module config', () => { width: 200, height: 200, sizes: '200,500:500,900:900', + alt: '', }, }) - expect(img.html()).toMatchInlineSnapshot(`""`) + expect(img.html()).toMatchInlineSnapshot(`""`) }) }) @@ -572,6 +597,7 @@ describe('Renders NuxtImg with the custom prop and default slot', () => { height: 200, src: src, custom: true, + alt: '', }, slots: { default: ({ imgAttrs, src, isLoaded }) => { diff --git a/test/nuxt/picture.test.ts b/test/nuxt/picture.test.ts index 448d2a2c0..bb26198df 100644 --- a/test/nuxt/picture.test.ts +++ b/test/nuxt/picture.test.ts @@ -43,6 +43,7 @@ describe('Renders simple image', () => { height: 200, sizes: '200,500:500,900:900', src, + alt: '', }, }) }) @@ -50,7 +51,7 @@ describe('Renders simple image', () => { it('Matches snapshot', () => { expect(wrapper.html()).toMatchInlineSnapshot(` " - + " `) }) @@ -63,11 +64,12 @@ describe('Renders simple image', () => { width: 200, height: 200, src, + alt: '', }, }) expect(img.html()).toMatchInlineSnapshot(` " - + " `) }) @@ -90,6 +92,7 @@ describe('Renders simple image', () => { height: 200, format: 'avif', src, + alt: '', }, }) expect(img.find('source[type="image/avif"]').exists()).toBe(true) @@ -103,6 +106,7 @@ describe('Renders simple image', () => { height: 200, format: 'avif,webp', src, + alt: '', }, }) expect(img.find('source[type="image/avif"]').exists()).toBe(true) @@ -117,6 +121,7 @@ describe('Renders simple image', () => { height: 200, format: 'avif,gif', src, + alt: '', }, }) expect(img.find('source[type="image/avif"]').exists()).toBe(true) @@ -145,9 +150,10 @@ describe('Renders simple image', () => { const wrapper = mount(NuxtPicture, { propsData: { src: '/image.svg', + alt: '', }, }) - expect(wrapper.html()).toMatchInlineSnapshot('""') + expect(wrapper.html()).toMatchInlineSnapshot('""') }) it('encodes characters', () => { @@ -158,11 +164,12 @@ describe('Renders simple image', () => { height: 200, sizes: '200,500:500,900:900', src: '/汉字.png', + alt: '', }, }) expect(img.html()).toMatchInlineSnapshot(` " - + " `) }) @@ -172,6 +179,7 @@ describe('Renders simple image', () => { propsData: { format: 'avif', src: '/test.png', + alt: '', }, }) expect(img.find('img').exists()).toBe(true) @@ -196,11 +204,12 @@ describe('Renders image, applies module config', () => { height: 200, sizes: '200,500:500,900:900', src, + alt: '', }, }) expect(picture.html()).toMatchInlineSnapshot(` " - + " `) }) @@ -220,11 +229,12 @@ describe('Renders image, applies module config', () => { height: 200, sizes: '200,500:500,900:900', src, + alt: '', }, }) expect(picture.html()).toMatchInlineSnapshot(` " - + " `) }) @@ -244,12 +254,13 @@ describe('Renders image, applies module config', () => { height: 200, sizes: '200,500:500,900:900', src, + alt: '', }, }) expect(picture.html()).toMatchInlineSnapshot(` " - + " `) }) @@ -270,11 +281,12 @@ describe('Renders image, applies module config', () => { sizes: '200,500:500,900:900', format: 'avif', src, + alt: '', }, }) expect(picture.html()).toMatchInlineSnapshot(` " - + " `) }) @@ -294,9 +306,10 @@ describe('Renders image, applies module config', () => { height: 200, sizes: '200,500:500,900:900', src: 'image.svg', + alt: '', }, }) - expect(picture.html()).toMatchInlineSnapshot('""') + expect(picture.html()).toMatchInlineSnapshot('""') }) it('Module config .quality applies', () => { @@ -314,12 +327,13 @@ describe('Renders image, applies module config', () => { width: 200, height: 200, sizes: '200,500:500,900:900', + alt: '', }, }) expect(picture.html()).toMatchInlineSnapshot(` " - + " `) }) diff --git a/test/unit/bundle.test.ts b/test/unit/bundle.test.ts index eea4df32d..a31c9cdbc 100644 --- a/test/unit/bundle.test.ts +++ b/test/unit/bundle.test.ts @@ -21,7 +21,7 @@ describe.skipIf(process.env.ECOSYSTEM_CI || isWindows)('nuxt image bundle size', image: { provider: 'ipx' }, }) - expect(roundToKilobytes(withImage.totalBytes - withoutImage.totalBytes)).toMatchInlineSnapshot(`"12.6k"`) + expect(roundToKilobytes(withImage.totalBytes - withoutImage.totalBytes)).toMatchInlineSnapshot(`"12.7k"`) }) })