@empathyco/x-components 10.4.0 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [10.5.0](https://github.com/empathyco/x/compare/@empathyco/x-components@10.3.0...@empathyco/x-components@10.5.0) (2026-11-05)
7
+
8
+ ### Features
9
+
10
+ * **search:** add priceFacetId to SearchConfig and update request accordingly (#2194)
11
+ * **x-components:** add responsive image props and loading events to BaseResultImage (#2195)
12
+
13
+
6
14
  ## [10.4.0](https://github.com/empathyco/x/compare/@empathyco/x-components@10.3.0...@empathyco/x-components@10.4.0) (2026-11-03)
7
15
 
8
16
  ### Features
@@ -6,6 +6,8 @@
6
6
 
7
7
  Component to be reused that renders an `<img>`<!-- -->.
8
8
 
9
+ Additional `<img>` attributes passed to the component (e.g. `decoding`<!-- -->, `crossorigin`<!-- -->, `referrerpolicy`<!-- -->, `fetchpriority`<!-- -->, `width` and `height`<!-- -->) are forwarded to the rendered images, while `class`<!-- -->, `style` and event listeners keep falling through to the root element, as before. Use the `imageLoaded` and `imageError` events to observe the image loading state.
10
+
9
11
  **Signature:**
10
12
 
11
13
  ```typescript
@@ -25,18 +27,36 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
25
27
  type: BooleanConstructor;
26
28
  default: boolean;
27
29
  };
30
+ srcset: {
31
+ type: PropType<string | (string | undefined)[]>;
32
+ };
33
+ sizes: {
34
+ type: StringConstructor;
35
+ };
36
+ loading: {
37
+ type: PropType<"lazy" | "eager">;
38
+ default: string;
39
+ };
28
40
  }>, {
29
- pendingImages: Ref<string[], string[]>;
30
- loadedImages: Ref<string[], string[]>;
41
+ imageAttrs: import("vue").ComputedRef<{
42
+ [k: string]: unknown;
43
+ }>;
44
+ rootAttrs: import("vue").ComputedRef<{
45
+ class: import("vue").ClassValue;
46
+ style: StyleValue;
47
+ }>;
48
+ pendingImages: Ref<ImageEntry[], ImageEntry[]>;
49
+ loadedImages: Ref<ImageEntry[], ImageEntry[]>;
31
50
  isHovering: Ref<boolean, boolean>;
32
51
  userHasHoveredImage: Ref<boolean, boolean>;
33
52
  loaderStyles: import("vue").CSSProperties;
34
53
  animation: import("vue").ComputedRef<string | Function | Record<string, any>>;
35
54
  imageSrc: import("vue").ComputedRef<string>;
55
+ imageSrcset: import("vue").ComputedRef<string | undefined>;
36
56
  shouldLoadNextImage: import("vue").ComputedRef<boolean>;
37
57
  flagImageAsFailed: () => void;
38
- flagImageLoaded: () => void;
39
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
58
+ flagImageLoaded: (event: Event) => void;
59
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("imageLoaded" | "imageError")[], "imageLoaded" | "imageError", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
40
60
  result: {
41
61
  type: PropType<Result>;
42
62
  required: true;
@@ -52,8 +72,22 @@ _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
52
72
  type: BooleanConstructor;
53
73
  default: boolean;
54
74
  };
55
- }>> & Readonly<{}>, {
75
+ srcset: {
76
+ type: PropType<string | (string | undefined)[]>;
77
+ };
78
+ sizes: {
79
+ type: StringConstructor;
80
+ };
81
+ loading: {
82
+ type: PropType<"lazy" | "eager">;
83
+ default: string;
84
+ };
85
+ }>> & Readonly<{
86
+ onImageLoaded?: ((...args: any[]) => any) | undefined;
87
+ onImageError?: ((...args: any[]) => any) | undefined;
88
+ }>, {
56
89
  loadAnimation: string | Function | Record<string, any>;
57
90
  showNextImageOnHover: boolean;
91
+ loading: "lazy" | "eager";
58
92
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>
59
93
  ```
@@ -4227,6 +4227,8 @@ Component that renders the [Result](./x-types.result.md) current price that may
4227
4227
 
4228
4228
  Component to be reused that renders an `<img>`<!-- -->.
4229
4229
 
4230
+ Additional `<img>` attributes passed to the component (e.g. `decoding`<!-- -->, `crossorigin`<!-- -->, `referrerpolicy`<!-- -->, `fetchpriority`<!-- -->, `width` and `height`<!-- -->) are forwarded to the rendered images, while `class`<!-- -->, `style` and event listeners keep falling through to the root element, as before. Use the `imageLoaded` and `imageError` events to observe the image loading state.
4231
+
4230
4232
 
4231
4233
  </td></tr>
4232
4234
  <tr><td>
@@ -8,14 +8,30 @@ title: BaseResultImage
8
8
 
9
9
  Component to be reused that renders an `<img>`.
10
10
 
11
+ Additional `<img>` attributes passed to the component (e.g. `decoding`, `crossorigin`,
12
+ `referrerpolicy`, `fetchpriority`, `width` and `height`) are forwarded to the rendered
13
+ images, while `class`, `style` and event listeners keep falling through to the root
14
+ element, as before. Use the `imageLoaded` and `imageError` events to observe the image
15
+ loading state.
16
+
11
17
  ## Props
12
18
 
13
- | Name | Description | Type | Default |
14
- | --------------------------------- | ------------------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------ |
15
- | <code>result</code> | (Required) The @empathyco/x-types#Result information. | <code>Result</code> | <code></code> |
16
- | <code>loadAnimation</code> | Animation to use when switching between the placeholder, the loaded image, or the failed<br />image fallback. | <code>AnimationProp</code> | <code>() => NoAnimation</code> |
17
- | <code>hoverAnimation</code> | Animation to use when switching between the loaded image and the hover image. | <code>AnimationProp</code> | <code></code> |
18
- | <code>showNextImageOnHover</code> | Indicates if the next valid image should be displayed on hover. | <code>boolean</code> | <code>false</code> |
19
+ | Name | Description | Type | Default |
20
+ | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | ------------------------------ |
21
+ | <code>result</code> | (Required) The @empathyco/x-types#Result information. | <code>Result</code> | <code></code> |
22
+ | <code>loadAnimation</code> | Animation to use when switching between the placeholder, the loaded image, or the failed<br />image fallback. | <code>AnimationProp</code> | <code>() => NoAnimation</code> |
23
+ | <code>hoverAnimation</code> | Animation to use when switching between the loaded image and the hover image. | <code>AnimationProp</code> | <code></code> |
24
+ | <code>showNextImageOnHover</code> | Indicates if the next valid image should be displayed on hover. | <code>boolean</code> | <code>false</code> |
25
+ | <code>srcset</code> | Responsive image candidates (`srcset`).<br /><br />- A single string is applied to every image of the result (e.g.<br /> `"image-480.jpg 480w, image-1024.jpg 1024w"`).<br />- An array is parallel to `result.images`, so each image can have its own candidates.<br /><br />When provided, the `src` is kept as a fallback for browsers without `srcset` support. | <code>string \| (string \| undefined)[]</code> | <code></code> |
26
+ | <code>sizes</code> | The sizes of the image for different page layouts (`sizes`).<br /><br />It is shared by all the images of the result, since it depends on the layout and not on<br />the image. Pass it together with `srcset`, since it is ignored otherwise. | <code>string</code> | <code></code> |
27
+ | <code>loading</code> | Image loading mode. | <code>string</code> | <code>'lazy'</code> |
28
+
29
+ ## Events
30
+
31
+ | Event name | Properties | Description |
32
+ | ----------- | ---------- | ----------- |
33
+ | imageLoaded | |
34
+ | imageError | |
19
35
 
20
36
  ## Slots
21
37
 
@@ -47,6 +63,34 @@ const result = {
47
63
  </script>
48
64
  ```
49
65
 
66
+ ### Responsive images with `srcset` and `sizes`
67
+
68
+ The `srcset` and `sizes` props are used to deliver the right image candidate according to the
69
+ device and the layout (like the native `<img>` attributes).
70
+
71
+ `srcset` can be a single string, applied to all the images of the result, or an array parallel to
72
+ `result.images`, so each image can have its own candidates.
73
+
74
+ ```vue
75
+ <template>
76
+ <BaseResultImage
77
+ :result="result"
78
+ srcset="image1-480.jpg?width=400 480w, image1-1024.jpg?width=1024 1024w"
79
+ sizes="(min-width: 600px) 33vw, 100vw"
80
+ />
81
+ </template>
82
+
83
+ <script setup>
84
+ import { BaseResultImage } from "@empathyco/x-components";
85
+ const result = {
86
+ name: "Jacket",
87
+ images: ["https://some-image-url.com/image1.jpg"],
88
+ };
89
+ </script>
90
+ ```
91
+
92
+ The `src` of the image is always kept, so it works as a fallback when `srcset` is not supported.
93
+
50
94
  ### Showing the next image on hover
51
95
 
52
96
  If a result has multiple images, it can show the next one on hover.
@@ -133,3 +177,114 @@ const result = {
133
177
  };
134
178
  </script>
135
179
  ```
180
+
181
+ ### Optimizing the first result for LCP
182
+
183
+ By default, images are loaded lazily. For the first (above-the-fold) result of the search results
184
+ page, the image is usually the **Largest Contentful Paint (LCP)** element: eager-loading it with
185
+ a high fetch priority avoids waiting for the lazy-load viewport check and lets the browser start
186
+ the request immediately.
187
+
188
+ Combine it with `width` and `height` so the browser can prioritize and reserve the space of the
189
+ LCP element from the start:
190
+
191
+ ```vue
192
+ <template>
193
+ <!-- First, above-the-fold result -->
194
+ <BaseResultImage
195
+ :result="firstResult"
196
+ loading="eager"
197
+ fetchPriority="high"
198
+ :width="256"
199
+ :height="371"
200
+ />
201
+ <!-- All the remaining results keep the default lazy loading -->
202
+ <BaseResultImage
203
+ v-for="result in otherResults"
204
+ :key="result.id"
205
+ :result="result"
206
+ />
207
+ </template>
208
+
209
+ <script setup>
210
+ import { BaseResultImage } from "@empathyco/x-components";
211
+ </script>
212
+ ```
213
+
214
+ Only the above-the-fold results should use `loading="eager"`; keep the rest lazy to avoid
215
+ requesting more images than needed.
216
+
217
+ ### Avoiding layout shift (CLS)
218
+
219
+ Passing `width` and `height` (the intrinsic dimensions of the image) helps the browser reserve
220
+ the right space before the image is loaded, preventing the layout shift caused by the image
221
+ replacing the placeholder.
222
+
223
+ ```vue
224
+ <template>
225
+ <BaseResultImage :result="result" :width="256" :height="371" />
226
+ </template>
227
+
228
+ <script setup>
229
+ import { BaseResultImage } from "@empathyco/x-components";
230
+ </script>
231
+ ```
232
+
233
+ ### Passing additional image attributes
234
+
235
+ Any additional `<img>` attribute passed to the component is forwarded to the rendered images
236
+ (the hidden preload image and the visible one), so there is no need for a specific prop per
237
+ attribute:
238
+
239
+ ```vue
240
+ <template>
241
+ <BaseResultImage
242
+ :result="result"
243
+ decoding="async"
244
+ crossorigin="anonymous"
245
+ fetchpriority="high"
246
+ referrerpolicy="no-referrer"
247
+ :width="256"
248
+ :height="371"
249
+ />
250
+ </template>
251
+
252
+ <script setup>
253
+ import { BaseResultImage } from "@empathyco/x-components";
254
+ </script>
255
+ ```
256
+
257
+ `class`, `style` and event listeners keep being applied to the root element, so the wrapper
258
+ can still be styled and listened to. Any other additional attribute is only applied to the
259
+ rendered images, never to the wrapper div. Observe the image loading state with the
260
+ `imageLoaded` and `imageError` events instead.
261
+
262
+ ### Image loading events
263
+
264
+ The component emits `imageLoaded` when an image finishes loading, and `imageError` when an image
265
+ fails to load (the next one of the queue will be tried).
266
+
267
+ ```vue
268
+ <template>
269
+ <BaseResultImage
270
+ :result="result"
271
+ @imageLoaded="imageLoaded"
272
+ @imageError="imageError"
273
+ />
274
+ </template>
275
+
276
+ <script setup>
277
+ import { BaseResultImage } from "@empathyco/x-components";
278
+ const result = {
279
+ name: "Jacket",
280
+ images: ["https://some-image-url.com/image1.jpg"],
281
+ };
282
+ const imageLoaded = ({ index, src, currentSrc }) => {
283
+ // For example, track the candidate actually downloaded by the browser
284
+ console.log(`Image ${index} loaded: ${src} (downloaded ${currentSrc})`);
285
+ };
286
+ const imageError = ({ index, src }) => {
287
+ console.log(`Image ${index} failed: ${src}`);
288
+ };
289
+ </script>
290
+ ```
@@ -1,52 +1,55 @@
1
1
  import _sfc_main from './base-result-image.vue2.js';
2
- import { openBlock, createElementBlock, normalizeStyle, createCommentVNode, createBlock, resolveDynamicComponent, withCtx, renderSlot } from 'vue';
2
+ import { openBlock, createElementBlock, mergeProps, createCommentVNode, createBlock, resolveDynamicComponent, withCtx, renderSlot } from 'vue';
3
3
  import './base-result-image.vue3.js';
4
4
  import _export_sfc from '../../_virtual/_plugin-vue_export-helper.js';
5
5
 
6
- const _hoisted_1 = ["src"];
7
- const _hoisted_2 = ["alt", "src"];
6
+ const _hoisted_1 = ["loading", "src", "srcset", "sizes"];
7
+ const _hoisted_2 = ["alt", "src", "srcset", "sizes"];
8
8
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
9
9
  return openBlock(), createElementBlock(
10
10
  "div",
11
- {
11
+ mergeProps(_ctx.rootAttrs, {
12
12
  class: "x-result-picture xds:picture",
13
13
  "data-test": "result-picture",
14
14
  onMouseenterOnce: _cache[2] || (_cache[2] = ($event) => _ctx.userHasHoveredImage = true),
15
15
  onMouseenter: _cache[3] || (_cache[3] = ($event) => _ctx.isHovering = true),
16
16
  onMouseleave: _cache[4] || (_cache[4] = ($event) => _ctx.isHovering = false)
17
- },
17
+ }),
18
18
  [
19
- _ctx.shouldLoadNextImage ? (openBlock(), createElementBlock("img", {
20
- key: 0,
21
- loading: "lazy",
22
- src: _ctx.pendingImages[0],
23
- style: normalizeStyle(_ctx.loaderStyles),
19
+ _ctx.shouldLoadNextImage ? (openBlock(), createElementBlock("img", mergeProps({ key: 0 }, _ctx.imageAttrs, {
20
+ loading: _ctx.loading,
21
+ src: _ctx.pendingImages[0].src,
22
+ srcset: _ctx.pendingImages[0].srcset,
23
+ sizes: _ctx.sizes,
24
+ style: _ctx.loaderStyles,
24
25
  class: "xds:picture-image",
25
26
  "data-test": "result-picture-loader",
26
27
  alt: "",
27
28
  role: "presentation",
28
29
  onLoad: _cache[0] || (_cache[0] = (...args) => _ctx.flagImageLoaded && _ctx.flagImageLoaded(...args)),
29
30
  onError: _cache[1] || (_cache[1] = (...args) => _ctx.flagImageAsFailed && _ctx.flagImageAsFailed(...args))
30
- }, null, 44, _hoisted_1)) : createCommentVNode("v-if", true),
31
+ }), null, 16, _hoisted_1)) : createCommentVNode("v-if", true),
31
32
  (openBlock(), createBlock(resolveDynamicComponent(_ctx.animation), {
32
33
  class: "xds:picture-image",
33
34
  appear: false
34
35
  }, {
35
36
  default: withCtx(() => [
36
- !_ctx.loadedImages.length && !_ctx.pendingImages.length ? renderSlot(_ctx.$slots, "fallback", {}, void 0, true, 0) : !_ctx.loadedImages.length ? renderSlot(_ctx.$slots, "placeholder", {}, void 0, true, 1) : (openBlock(), createElementBlock("img", {
37
+ !_ctx.loadedImages.length && !_ctx.pendingImages.length ? renderSlot(_ctx.$slots, "fallback", {}, void 0, true, 0) : !_ctx.loadedImages.length ? renderSlot(_ctx.$slots, "placeholder", {}, void 0, true, 1) : (openBlock(), createElementBlock("img", mergeProps({ key: 2 }, _ctx.imageAttrs, {
37
38
  key: _ctx.imageSrc,
38
39
  alt: _ctx.result.name,
39
40
  src: _ctx.imageSrc,
41
+ srcset: _ctx.imageSrcset,
42
+ sizes: _ctx.sizes,
40
43
  class: "x-result-picture-image",
41
44
  "data-test": "result-picture-image"
42
- }, null, 8, _hoisted_2))
45
+ }), null, 16, _hoisted_2))
43
46
  ]),
44
47
  _: 3
45
48
  /* FORWARDED */
46
49
  }))
47
50
  ],
48
- 32
49
- /* NEED_HYDRATION */
51
+ 16
52
+ /* FULL_PROPS */
50
53
  );
51
54
  }
52
55
  var baseResultImage = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-17531567"]]);
@@ -1 +1 @@
1
- {"version":3,"file":"base-result-image.vue.js","sources":["../../../../src/components/result/base-result-image.vue"],"sourcesContent":["<template>\n <!-- This is a div because using a picture causes the onload event of the image to fire twice. -->\n <!-- eslint-disable-next-line vuejs-accessibility/mouse-events-have-key-events -->\n <div\n class=\"x-result-picture xds:picture\"\n data-test=\"result-picture\"\n @mouseenter.once=\"userHasHoveredImage = true\"\n @mouseenter=\"isHovering = true\"\n @mouseleave=\"isHovering = false\"\n >\n <img\n v-if=\"shouldLoadNextImage\"\n loading=\"lazy\"\n :src=\"pendingImages[0]\"\n :style=\"loaderStyles\"\n class=\"xds:picture-image\"\n data-test=\"result-picture-loader\"\n alt=\"\"\n role=\"presentation\"\n @load=\"flagImageLoaded\"\n @error=\"flagImageAsFailed\"\n />\n <component :is=\"animation\" class=\"xds:picture-image\" :appear=\"false\">\n <!-- @slot Fallback image content. It will be rendered when all the images failed -->\n <slot v-if=\"!loadedImages.length && !pendingImages.length\" name=\"fallback\" />\n\n <!-- @slot Loading image content. It will be rendered while the real image is not loaded -->\n <slot v-else-if=\"!loadedImages.length\" name=\"placeholder\" />\n\n <img\n v-else\n :key=\"imageSrc\"\n :alt=\"result.name\"\n :src=\"imageSrc\"\n class=\"x-result-picture-image\"\n data-test=\"result-picture-image\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Result } from '@empathyco/x-types'\nimport type { PropType, Ref, StyleValue } from 'vue'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { AnimationProp } from '../../types'\nimport { NoAnimation } from '../animations'\n\n/**\n * Component to be reused that renders an `<img>`.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseResultImage',\n props: {\n /** (Required) The {@link @empathyco/x-types#Result} information. */\n result: {\n type: Object as PropType<Result>,\n required: true,\n },\n /**\n * Animation to use when switching between the placeholder, the loaded image, or the failed\n * image fallback.\n */\n loadAnimation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /** Animation to use when switching between the loaded image and the hover image. */\n hoverAnimation: {\n type: AnimationProp,\n },\n /**\n * Indicates if the next valid image should be displayed on hover.\n *\n * @public\n */\n showNextImageOnHover: {\n type: Boolean,\n default: false,\n },\n },\n setup(props) {\n /**\n * Copy of the images of the result.\n *\n * It is used as a queue of images to load, once an image loads/fails to load, it is removed\n * from this array.\n *\n * @internal\n */\n const pendingImages: Ref<string[]> = ref([])\n\n /**\n * Contains the images that have been loaded successfully.\n *\n * @internal\n */\n const loadedImages: Ref<string[]> = ref([])\n\n /**\n * Indicates if the user is hovering the image.\n *\n * @internal\n */\n const isHovering = ref(false)\n\n /**\n * Indicates if the user has hovered the image.\n *\n * @internal\n */\n const userHasHoveredImage = ref(false)\n\n /**\n * Styles to use inline in the image loader, to prevent override from CSS\n *\n * @internal\n */\n const loaderStyles: StyleValue = {\n // csstype issue: https://github.com/frenic/csstype/issues/160\n position: 'absolute !important' as 'absolute',\n top: '0 !important' as '0',\n left: '0 !important' as '0',\n width: '100% !important' as '100%',\n height: '100% !important' as '100%',\n pointerEvents: 'none !important' as 'none',\n visibility: 'hidden !important' as 'hidden',\n }\n\n /**\n * Initializes images state and resets when the result's images change.\n *\n * @internal\n */\n watch(\n () => props.result.images,\n () => {\n pendingImages.value = [...(props.result.images ?? [])]\n loadedImages.value = pendingImages.value.filter(image => loadedImages.value.includes(image))\n },\n { immediate: true },\n )\n\n /**\n * Animation to be used.\n *\n * @returns The animation to be used, taking into account if the user has hovered the image.\n *\n * @internal\n */\n const animation = computed(() => {\n return userHasHoveredImage.value\n ? (props.hoverAnimation ?? props.loadAnimation)\n : props.loadAnimation\n })\n\n /**\n * Gets the src from the result image.\n *\n * @returns The result image src.\n *\n * @internal\n */\n const imageSrc = computed(() => {\n return loadedImages.value[\n !props.showNextImageOnHover || !isHovering.value ? 0 : loadedImages.value.length - 1\n ]\n })\n\n /**\n * Indicates if the loader should try to load the next image.\n *\n * @returns True if it should try to load the next image.\n *\n * @internal\n */\n const shouldLoadNextImage = computed(() => {\n const numImagesToLoad = props.showNextImageOnHover && userHasHoveredImage.value ? 2 : 1\n return !!pendingImages.value.length && loadedImages.value.length < numImagesToLoad\n })\n\n /**\n * Sets an image as failed.\n *\n * @internal\n */\n const flagImageAsFailed = () => {\n pendingImages.value.shift()\n }\n\n /**\n * Sets an image as loaded.\n *\n * @internal\n */\n const flagImageLoaded = () => {\n const image = pendingImages.value.shift()\n if (image) {\n loadedImages.value.push(image)\n }\n }\n\n return {\n pendingImages,\n loadedImages,\n isHovering,\n userHasHoveredImage,\n loaderStyles,\n animation,\n imageSrc,\n shouldLoadNextImage,\n flagImageAsFailed,\n flagImageLoaded,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-result-picture {\n position: relative;\n min-width: 1px;\n min-height: 1px;\n}\n\n.x-result-picture-image {\n max-width: 100%;\n max-height: 100%;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\n### Basic example\n\nThis component is for the result image. It may be part of the search result page, recommendations or\nother section which needs to include results.\n\nThe result prop is required. It will render a `<img/>` with the result image:\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\n### Showing the next image on hover\n\nIf a result has multiple images, it can show the next one on hover.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" showNextImageOnHover />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg', 'https://some-image-url.com/image2.jpg'],\n}\n</script>\n```\n\n### Customizing slots content\n\nFallback and placeholder contents can be customized.\n\nThe fallback slot allows you to replace the content of the fallback image.\n\nThe other slot is called `placeholder`, and allows you to set the image that its going to be\ndisplayed while the real one is loaded.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\">\n <template #placeholder>\n <img alt=\"Placeholder image\" src=\"./placeholder-image.svg\" />\n </template>\n <template #fallback>\n <img alt=\"Fallback image\" src=\"./fallback-image.svg\" />\n </template>\n </BaseResultImage>\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\n### Customizing the animations\n\nTwo animations can be used in this component.\n\nThe `loadAnimation` is used to transition between the placeholder, the fallback and the image.\n\nThe `hoverAnimation` is used to transition between the image and the hover image, if the\n`showNextImageOnHover` prop is `true`.\n\n`hoverAnimation` will default to `loadAnimation` if it is not provided.\n\n```vue\n<template>\n <BaseResultImage\n :result=\"result\"\n :loadAnimation=\"loadAnimation\"\n :hoverAnimation=\"hoverAnimation\"\n showNextImageOnHover\n />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nimport { CrossFade, CollapseHeight } from '@empathyco/x-components/animations'\nconst loadAnimation = CrossFade\nconst hoverAnimation = CollapseHeight\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg', 'https://some-image-url.com/image2.jpg'],\n}\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_normalizeStyle","_createCommentVNode","_createBlock","_resolveDynamicComponent","_renderSlot"],"mappings":";;;;;;;;AAGE,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IAmCM,KAAA;AAAA,IAAA;AAAA,MAlCJ,KAAA,EAAM,8BAAA;AAAA,MACN,WAAA,EAAU,gBAAA;AAAA,MAAA,gBAAA,EAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,MAAA,KACQ,IAAA,CAAA,mBAAA,GAAmB,IAAA,CAAA;AAAA,MACpC,YAAA,EAAU,sCAAE,IAAA,CAAA,UAAA,GAAU,IAAA,CAAA;AAAA,MACtB,YAAA,EAAU,sCAAE,IAAA,CAAA,UAAA,GAAU,KAAA;AAAA,KAAA;;AAGf,MAAA,IAAA,CAAA,mBAAA,IAAAD,SAAA,EAAA,EADRC,kBAAA,CAWE,KAAA,EAAA;AAAA,QAAA,GAAA,EAAA,CAAA;QATA,OAAA,EAAQ,MAAA;AAAA,QACP,KAAK,IAAA,CAAA,aAAA,CAAa,CAAA,CAAA;AAAA,QAClB,KAAA,EAAKC,eAAE,IAAA,CAAA,YAAY,CAAA;AAAA,QACpB,KAAA,EAAM,mBAAA;AAAA,QACN,WAAA,EAAU,uBAAA;AAAA,QACV,GAAA,EAAI,EAAA;AAAA,QACJ,IAAA,EAAK,cAAA;AAAA,QACJ,QAAI,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,eAAA,IAAA,IAAA,CAAA,eAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,QACN,SAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,iBAAA,IAAA,IAAA,CAAA,iBAAA,CAAA,GAAA,IAAA,CAAA;AAAA,OAAA,EAAA,IAAA,EAAA,EAAA,EAAA,UAAA,CAAA,IAAAC,kBAAA,CAAA,MAAA,EAAA,IAAA,CAAA;AAEV,OAAAH,SAAA,EAAA,EAAAI,WAAA,CAeYC,wBAfI,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,QAAE,KAAA,EAAM,mBAAA;AAAA,QAAqB,MAAA,EAAQ;AAAA,OAAA,EAAA;yBAE5D,MAA6E;AAAA,UAAA,CAAhE,IAAA,CAAA,YAAA,CAAa,MAAA,IAAM,CAAK,IAAA,CAAA,aAAA,CAAc,MAAA,GAAnDC,UAAA,CAA6E,IAAA,CAAA,MAAA,EAAA,UAAA,EAAA,EAAA,EAAA,MAAA,EAAA,IAAA,EAAA,CAAA,CAAA,GAAA,CAG3D,IAAA,CAAA,YAAA,CAAa,MAAA,GAA/BA,UAAA,CAA4D,IAAA,CAAA,MAAA,EAAA,aAAA,EAAA,EAAA,EAAA,MAAA,EAAA,IAAA,EAAA,CAAA,CAAA,IAAAN,SAAA,EAAA,EAE5DC,kBAAA,CAOE,KAAA,EAAA;AAAA,YALC,GAAA,EAAK,IAAA,CAAA,QAAA;AAAA,YACL,KAAK,IAAA,CAAA,MAAA,CAAO,IAAA;AAAA,YACZ,GAAA,EAAK,IAAA,CAAA,QAAA;AAAA,YACN,KAAA,EAAM,wBAAA;AAAA,YACN,WAAA,EAAU;AAAA,WAAA,EAAA,IAAA,EAAA,CAAA,EAAA,UAAA,CAAA;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"base-result-image.vue.js","sources":["../../../../src/components/result/base-result-image.vue"],"sourcesContent":["<template>\n <!-- This is a div because using a picture causes the onload event of the image to fire twice. -->\n <!-- eslint-disable-next-line vuejs-accessibility/mouse-events-have-key-events -->\n <div\n v-bind=\"rootAttrs\"\n class=\"x-result-picture xds:picture\"\n data-test=\"result-picture\"\n @mouseenter.once=\"userHasHoveredImage = true\"\n @mouseenter=\"isHovering = true\"\n @mouseleave=\"isHovering = false\"\n >\n <img\n v-if=\"shouldLoadNextImage\"\n v-bind=\"imageAttrs\"\n :loading=\"loading\"\n :src=\"pendingImages[0].src\"\n :srcset=\"pendingImages[0].srcset\"\n :sizes=\"sizes\"\n :style=\"loaderStyles\"\n class=\"xds:picture-image\"\n data-test=\"result-picture-loader\"\n alt=\"\"\n role=\"presentation\"\n @load=\"flagImageLoaded\"\n @error=\"flagImageAsFailed\"\n />\n <component :is=\"animation\" class=\"xds:picture-image\" :appear=\"false\">\n <!-- @slot Fallback image content. It will be rendered when all the images failed -->\n <slot v-if=\"!loadedImages.length && !pendingImages.length\" name=\"fallback\" />\n\n <!-- @slot Loading image content. It will be rendered while the real image is not loaded -->\n <slot v-else-if=\"!loadedImages.length\" name=\"placeholder\" />\n\n <img\n v-else\n v-bind=\"imageAttrs\"\n :key=\"imageSrc\"\n :alt=\"result.name\"\n :src=\"imageSrc\"\n :srcset=\"imageSrcset\"\n :sizes=\"sizes\"\n class=\"x-result-picture-image\"\n data-test=\"result-picture-image\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Result } from '@empathyco/x-types'\nimport type { PropType, Ref, StyleValue } from 'vue'\nimport { computed, defineComponent, ref, useAttrs, watch } from 'vue'\n\nimport { AnimationProp } from '../../types'\nimport { NoAnimation } from '../animations'\n\n/**\n * An entry of the images queue: the image `src` and its optional `srcset`.\n *\n * @internal\n */\ninterface ImageEntry {\n /** Index of the image inside `result.images`. */\n index: number\n /** The image URL. */\n src: string\n /** Responsive candidates for the image, if provided. */\n srcset?: string\n}\n\n/**\n * Component to be reused that renders an `<img>`.\n *\n * Additional `<img>` attributes passed to the component (e.g. `decoding`, `crossorigin`,\n * `referrerpolicy`, `fetchpriority`, `width` and `height`) are forwarded to the rendered\n * images, while `class`, `style` and event listeners keep falling through to the root\n * element, as before. Use the `imageLoaded` and `imageError` events to observe the image\n * loading state.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseResultImage',\n inheritAttrs: false,\n props: {\n /** (Required) The {@link @empathyco/x-types#Result} information. */\n result: {\n type: Object as PropType<Result>,\n required: true,\n },\n /**\n * Animation to use when switching between the placeholder, the loaded image, or the failed\n * image fallback.\n */\n loadAnimation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /** Animation to use when switching between the loaded image and the hover image. */\n hoverAnimation: {\n type: AnimationProp,\n },\n /**\n * Indicates if the next valid image should be displayed on hover.\n *\n * @public\n */\n showNextImageOnHover: {\n type: Boolean,\n default: false,\n },\n /**\n * Responsive image candidates (`srcset`).\n *\n * - A single string is applied to every image of the result (e.g.\n * `\"image-480.jpg 480w, image-1024.jpg 1024w\"`).\n * - An array is parallel to `result.images`, so each image can have its own candidates.\n *\n * When provided, the `src` is kept as a fallback for browsers without `srcset` support.\n *\n * @public\n */\n srcset: {\n type: [String, Array] as PropType<string | (string | undefined)[]>,\n },\n /**\n * The sizes of the image for different page layouts (`sizes`).\n *\n * It is shared by all the images of the result, since it depends on the layout and not on\n * the image. Pass it together with `srcset`, since it is ignored otherwise.\n *\n * @public\n */\n sizes: {\n type: String,\n },\n /**\n * Image loading mode.\n *\n * @public\n */\n loading: {\n type: String as PropType<'lazy' | 'eager'>,\n default: 'lazy',\n },\n },\n emits: ['imageLoaded', 'imageError'],\n setup(props, { emit }) {\n const attrs = useAttrs()\n\n /**\n * Additional `<img>` attributes passed to the component (e.g. `decoding`,\n * `crossorigin`, `fetchpriority`, `width`, `height`), forwarded to the rendered images.\n *\n * Event listeners are excluded so they don't reach the hidden loader: they keep\n * falling through to the root element, and the image loading state is exposed through\n * the `imageLoaded` and `imageError` events.\n *\n * @internal\n */\n const imageAttrs = computed(() =>\n Object.fromEntries(Object.entries(attrs).filter(([key]) => !key.startsWith('on'))),\n )\n\n /**\n * The consumer's `class`, `style` and event listeners, applied to the root element.\n *\n * The component uses `inheritAttrs: false` so the remaining attributes (e.g.\n * `decoding`, `crossorigin`, `fetchpriority`, `width`, `height`) only reach the\n * rendered images through `imageAttrs` and don't leak to the wrapper div.\n *\n * @internal\n */\n const rootAttrs = computed(() => ({\n class: attrs.class,\n style: attrs.style,\n ...Object.fromEntries(Object.entries(attrs).filter(([key]) => key.startsWith('on'))),\n }))\n\n /**\n * Copy of the images of the result.\n *\n * It is used as a queue of images to load, once an image loads/fails to load, it is removed\n * from this array.\n *\n * @internal\n */\n const pendingImages: Ref<ImageEntry[]> = ref([])\n\n /**\n * Contains the images that have been loaded successfully.\n *\n * @internal\n */\n const loadedImages: Ref<ImageEntry[]> = ref([])\n\n /**\n * Indicates if the user is hovering the image.\n *\n * @internal\n */\n const isHovering = ref(false)\n\n /**\n * Indicates if the user has hovered the image.\n *\n * @internal\n */\n const userHasHoveredImage = ref(false)\n\n /**\n * Styles to use inline in the image loader, to prevent override from CSS\n *\n * @internal\n */\n const loaderStyles: StyleValue = {\n // csstype issue: https://github.com/frenic/csstype/issues/160\n position: 'absolute !important' as 'absolute',\n top: '0 !important' as '0',\n left: '0 !important' as '0',\n width: '100% !important' as '100%',\n height: '100% !important' as '100%',\n pointerEvents: 'none !important' as 'none',\n visibility: 'hidden !important' as 'hidden',\n }\n\n /**\n * Resolves the `srcset` to use for the image at the given index.\n *\n * @param index - Index of the image inside `result.images`.\n *\n * @returns The `srcset` for that image, if any.\n *\n * @internal\n */\n const resolveSrcset = (index: number): string | undefined =>\n Array.isArray(props.srcset) ? props.srcset[index] : props.srcset\n\n /**\n * Initializes images state and resets when the result's images change.\n *\n * @internal\n */\n watch(\n () => props.result.images,\n () => {\n pendingImages.value = (props.result.images ?? []).map((src, index) => ({\n index,\n src,\n srcset: resolveSrcset(index),\n }))\n loadedImages.value = pendingImages.value.filter(image =>\n loadedImages.value.some(loadedImage => loadedImage.src === image.src),\n )\n },\n { immediate: true },\n )\n\n /**\n * Animation to be used.\n *\n * @returns The animation to be used, taking into account if the user has hovered the image.\n *\n * @internal\n */\n const animation = computed(() => {\n return userHasHoveredImage.value\n ? (props.hoverAnimation ?? props.loadAnimation)\n : props.loadAnimation\n })\n\n /**\n * Gets the currently loaded image.\n *\n * @returns The currently loaded image entry, or undefined if none has been loaded.\n *\n * @internal\n */\n const currentImage = computed(() => {\n return loadedImages.value[\n !props.showNextImageOnHover || !isHovering.value ? 0 : loadedImages.value.length - 1\n ]\n })\n\n /**\n * Gets the src of the currently loaded image.\n *\n * @returns The current image src.\n *\n * @internal\n */\n const imageSrc = computed(() => currentImage.value?.src)\n\n /**\n * Gets the srcset of the currently loaded image.\n *\n * @returns The current image srcset, if any.\n *\n * @internal\n */\n const imageSrcset = computed(() => currentImage.value?.srcset)\n\n /**\n * Indicates if the loader should try to load the next image.\n *\n * @returns True if it should try to load the next image.\n *\n * @internal\n */\n const shouldLoadNextImage = computed(() => {\n const numImagesToLoad = props.showNextImageOnHover && userHasHoveredImage.value ? 2 : 1\n return !!pendingImages.value.length && loadedImages.value.length < numImagesToLoad\n })\n\n /**\n * Sets an image as failed.\n *\n * @param event - The error event of the loader image.\n *\n * @internal\n */\n const flagImageAsFailed = () => {\n const image = pendingImages.value.shift()\n if (image) {\n emit('imageError', { index: image.index, src: image.src, srcset: image.srcset })\n }\n }\n\n /**\n * Sets an image as loaded.\n *\n * @param event - The load event of the loader image.\n *\n * @internal\n */\n const flagImageLoaded = (event: Event) => {\n const image = pendingImages.value.shift()\n if (image) {\n loadedImages.value.push(image)\n const element = event.target as HTMLImageElement\n emit('imageLoaded', {\n index: image.index,\n src: image.src,\n srcset: image.srcset,\n currentSrc: element.currentSrc || image.src,\n element,\n })\n }\n }\n\n return {\n imageAttrs,\n rootAttrs,\n pendingImages,\n loadedImages,\n isHovering,\n userHasHoveredImage,\n loaderStyles,\n animation,\n imageSrc,\n imageSrcset,\n shouldLoadNextImage,\n flagImageAsFailed,\n flagImageLoaded,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-result-picture {\n position: relative;\n min-width: 1px;\n min-height: 1px;\n}\n\n.x-result-picture-image {\n max-width: 100%;\n max-height: 100%;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\n### Basic example\n\nThis component is for the result image. It may be part of the search result page, recommendations or\nother section which needs to include results.\n\nThe result prop is required. It will render a `<img/>` with the result image:\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\n### Responsive images with `srcset` and `sizes`\n\nThe `srcset` and `sizes` props are used to deliver the right image candidate according to the\ndevice and the layout (like the native `<img>` attributes).\n\n`srcset` can be a single string, applied to all the images of the result, or an array parallel to\n`result.images`, so each image can have its own candidates.\n\n```vue\n<template>\n <BaseResultImage\n :result=\"result\"\n srcset=\"image1-480.jpg?width=400 480w, image1-1024.jpg?width=1024 1024w\"\n sizes=\"(min-width: 600px) 33vw, 100vw\"\n />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\nThe `src` of the image is always kept, so it works as a fallback when `srcset` is not supported.\n\n### Showing the next image on hover\n\nIf a result has multiple images, it can show the next one on hover.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" showNextImageOnHover />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg', 'https://some-image-url.com/image2.jpg'],\n}\n</script>\n```\n\n### Customizing slots content\n\nFallback and placeholder contents can be customized.\n\nThe fallback slot allows you to replace the content of the fallback image.\n\nThe other slot is called `placeholder`, and allows you to set the image that its going to be\ndisplayed while the real one is loaded.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\">\n <template #placeholder>\n <img alt=\"Placeholder image\" src=\"./placeholder-image.svg\" />\n </template>\n <template #fallback>\n <img alt=\"Fallback image\" src=\"./fallback-image.svg\" />\n </template>\n </BaseResultImage>\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\n### Customizing the animations\n\nTwo animations can be used in this component.\n\nThe `loadAnimation` is used to transition between the placeholder, the fallback and the image.\n\nThe `hoverAnimation` is used to transition between the image and the hover image, if the\n`showNextImageOnHover` prop is `true`.\n\n`hoverAnimation` will default to `loadAnimation` if it is not provided.\n\n```vue\n<template>\n <BaseResultImage\n :result=\"result\"\n :loadAnimation=\"loadAnimation\"\n :hoverAnimation=\"hoverAnimation\"\n showNextImageOnHover\n />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nimport { CrossFade, CollapseHeight } from '@empathyco/x-components/animations'\nconst loadAnimation = CrossFade\nconst hoverAnimation = CollapseHeight\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg', 'https://some-image-url.com/image2.jpg'],\n}\n</script>\n```\n\n### Optimizing the first result for LCP\n\nBy default, images are loaded lazily. For the first (above-the-fold) result of the search results\npage, the image is usually the **Largest Contentful Paint (LCP)** element: eager-loading it with\na high fetch priority avoids waiting for the lazy-load viewport check and lets the browser start\nthe request immediately.\n\nCombine it with `width` and `height` so the browser can prioritize and reserve the space of the\nLCP element from the start:\n\n```vue\n<template>\n <!-- First, above-the-fold result -->\n <BaseResultImage\n :result=\"firstResult\"\n loading=\"eager\"\n fetchPriority=\"high\"\n :width=\"256\"\n :height=\"371\"\n />\n <!-- All the remaining results keep the default lazy loading -->\n <BaseResultImage v-for=\"result in otherResults\" :key=\"result.id\" :result=\"result\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\n</script>\n```\n\nOnly the above-the-fold results should use `loading=\"eager\"`; keep the rest lazy to avoid\nrequesting more images than needed.\n\n### Avoiding layout shift (CLS)\n\nPassing `width` and `height` (the intrinsic dimensions of the image) helps the browser reserve\nthe right space before the image is loaded, preventing the layout shift caused by the image\nreplacing the placeholder.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" :width=\"256\" :height=\"371\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\n</script>\n```\n\n### Passing additional image attributes\n\nAny additional `<img>` attribute passed to the component is forwarded to the rendered images\n(the hidden preload image and the visible one), so there is no need for a specific prop per\nattribute:\n\n```vue\n<template>\n <BaseResultImage\n :result=\"result\"\n decoding=\"async\"\n crossorigin=\"anonymous\"\n fetchpriority=\"high\"\n referrerpolicy=\"no-referrer\"\n :width=\"256\"\n :height=\"371\"\n />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\n</script>\n```\n\n`class`, `style` and event listeners keep being applied to the root element, so the wrapper\ncan still be styled and listened to. Any other additional attribute is only applied to the\nrendered images, never to the wrapper div. Observe the image loading state with the\n`imageLoaded` and `imageError` events instead.\n\n### Image loading events\n\nThe component emits `imageLoaded` when an image finishes loading, and `imageError` when an image\nfails to load (the next one of the queue will be tried).\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" @imageLoaded=\"imageLoaded\" @imageError=\"imageError\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\nconst imageLoaded = ({ index, src, currentSrc }) => {\n // For example, track the candidate actually downloaded by the browser\n console.log(`Image ${index} loaded: ${src} (downloaded ${currentSrc})`)\n}\nconst imageError = ({ index, src }) => {\n console.log(`Image ${index} failed: ${src}`)\n}\n</script>\n```\n</docs>\n"],"names":["_openBlock","_createElementBlock","_mergeProps","_createCommentVNode","_createBlock","_resolveDynamicComponent","_renderSlot"],"mappings":";;;;;;;;AAGE,EAAA,OAAAA,SAAA,EAAA,EAAAC,kBAAA;AAAA,IA0CM,KAAA;AAAA,IA1CNC,UAAA,CA0CM,KAzCI,SAAA,EAAS;AAAA,MACjB,KAAA,EAAM,8BAAA;AAAA,MACN,WAAA,EAAU,gBAAA;AAAA,MAAA,gBAAA,EAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,MAAA,KACQ,IAAA,CAAA,mBAAA,GAAmB,IAAA,CAAA;AAAA,MACpC,YAAA,EAAU,sCAAE,IAAA,CAAA,UAAA,GAAU,IAAA,CAAA;AAAA,MACtB,YAAA,EAAU,sCAAE,IAAA,CAAA,UAAA,GAAU,KAAA;AAAA,KAAA,CAAA;;AAGf,MAAA,IAAA,CAAA,mBAAA,IAAAF,SAAA,EAAA,EADRC,kBAAA,CAcE,KAAA,EAdFC,UAAA,CAcE,EAAA,GAAA,EAAA,CAAA,EAAA,EAZQ,IAAA,CAAA,UAAA,EAAU;AAAA,QACjB,OAAA,EAAS,IAAA,CAAA,OAAA;AAAA,QACT,GAAA,EAAK,mBAAa,CAAA,CAAA,CAAI,GAAA;AAAA,QACtB,MAAA,EAAQ,mBAAa,CAAA,CAAA,CAAI,MAAA;AAAA,QACzB,KAAA,EAAO,IAAA,CAAA,KAAA;AAAA,QACP,KAAA,EAAO,IAAA,CAAA,YAAA;AAAA,QACR,KAAA,EAAM,mBAAA;AAAA,QACN,WAAA,EAAU,uBAAA;AAAA,QACV,GAAA,EAAI,EAAA;AAAA,QACJ,IAAA,EAAK,cAAA;AAAA,QACJ,QAAI,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,eAAA,IAAA,IAAA,CAAA,eAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,QACN,SAAK,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,GAAA,IAAA,KAAE,IAAA,CAAA,iBAAA,IAAA,IAAA,CAAA,iBAAA,CAAA,GAAA,IAAA,CAAA;AAAA,OAAA,CAAA,EAAA,IAAA,EAAA,EAAA,EAAA,UAAA,CAAA,IAAAC,kBAAA,CAAA,MAAA,EAAA,IAAA,CAAA;AAEV,OAAAH,SAAA,EAAA,EAAAI,WAAA,CAkBYC,wBAlBI,IAAA,CAAA,SAAS,CAAA,EAAA;AAAA,QAAE,KAAA,EAAM,mBAAA;AAAA,QAAqB,MAAA,EAAQ;AAAA,OAAA,EAAA;yBAE5D,MAA6E;AAAA,UAAA,CAAhE,IAAA,CAAA,YAAA,CAAa,MAAA,IAAM,CAAK,IAAA,CAAA,aAAA,CAAc,SAAnDC,UAAA,CAA6E,IAAA,CAAA,MAAA,EAAA,UAAA,EAAA,EAAA,EAAA,MAAA,EAAA,IAAA,EAAA,CAAA,CAAA,GAAA,CAG3D,IAAA,CAAA,YAAA,CAAa,MAAA,GAA/BA,WAA4D,IAAA,CAAA,MAAA,EAAA,aAAA,EAAA,EAAA,EAAA,MAAA,EAAA,IAAA,EAAA,CAAA,CAAA,IAAAN,SAAA,EAAA,EAE5DC,kBAAA,CAUE,KAAA,EAVFC,UAAA,CAUE,YARQ,IAAA,CAAA,UAAA,EAAU;AAAA,YACjB,GAAA,EAAK,IAAA,CAAA,QAAA;AAAA,YACL,KAAK,IAAA,CAAA,MAAA,CAAO,IAAA;AAAA,YACZ,GAAA,EAAK,IAAA,CAAA,QAAA;AAAA,YACL,MAAA,EAAQ,IAAA,CAAA,WAAA;AAAA,YACR,KAAA,EAAO,IAAA,CAAA,KAAA;AAAA,YACR,KAAA,EAAM,wBAAA;AAAA,YACN,WAAA,EAAU;AAAA,WAAA,CAAA,EAAA,IAAA,EAAA,EAAA,EAAA,UAAA,CAAA;;;;;;;;;;;;;;"}
@@ -1,4 +1,4 @@
1
- import { defineComponent, ref, watch, computed } from 'vue';
1
+ import { defineComponent, useAttrs, computed, ref, watch } from 'vue';
2
2
  import { AnimationProp } from '../../types/animation-prop.js';
3
3
  import '../animations/animate-clip-path.vue2.js';
4
4
  import '../animations/animate-scale.vue2.js';
@@ -24,10 +24,17 @@ import '../animations/staggered-fade-and-slide.vue3.js';
24
24
  /**
25
25
  * Component to be reused that renders an `<img>`.
26
26
  *
27
+ * Additional `<img>` attributes passed to the component (e.g. `decoding`, `crossorigin`,
28
+ * `referrerpolicy`, `fetchpriority`, `width` and `height`) are forwarded to the rendered
29
+ * images, while `class`, `style` and event listeners keep falling through to the root
30
+ * element, as before. Use the `imageLoaded` and `imageError` events to observe the image
31
+ * loading state.
32
+ *
27
33
  * @public
28
34
  */
29
35
  var _sfc_main = defineComponent({
30
36
  name: 'BaseResultImage',
37
+ inheritAttrs: false,
31
38
  props: {
32
39
  /** (Required) The {@link @empathyco/x-types#Result} information. */
33
40
  result: {
@@ -55,8 +62,69 @@ var _sfc_main = defineComponent({
55
62
  type: Boolean,
56
63
  default: false,
57
64
  },
65
+ /**
66
+ * Responsive image candidates (`srcset`).
67
+ *
68
+ * - A single string is applied to every image of the result (e.g.
69
+ * `"image-480.jpg 480w, image-1024.jpg 1024w"`).
70
+ * - An array is parallel to `result.images`, so each image can have its own candidates.
71
+ *
72
+ * When provided, the `src` is kept as a fallback for browsers without `srcset` support.
73
+ *
74
+ * @public
75
+ */
76
+ srcset: {
77
+ type: [String, Array],
78
+ },
79
+ /**
80
+ * The sizes of the image for different page layouts (`sizes`).
81
+ *
82
+ * It is shared by all the images of the result, since it depends on the layout and not on
83
+ * the image. Pass it together with `srcset`, since it is ignored otherwise.
84
+ *
85
+ * @public
86
+ */
87
+ sizes: {
88
+ type: String,
89
+ },
90
+ /**
91
+ * Image loading mode.
92
+ *
93
+ * @public
94
+ */
95
+ loading: {
96
+ type: String,
97
+ default: 'lazy',
98
+ },
58
99
  },
59
- setup(props) {
100
+ emits: ['imageLoaded', 'imageError'],
101
+ setup(props, { emit }) {
102
+ const attrs = useAttrs();
103
+ /**
104
+ * Additional `<img>` attributes passed to the component (e.g. `decoding`,
105
+ * `crossorigin`, `fetchpriority`, `width`, `height`), forwarded to the rendered images.
106
+ *
107
+ * Event listeners are excluded so they don't reach the hidden loader: they keep
108
+ * falling through to the root element, and the image loading state is exposed through
109
+ * the `imageLoaded` and `imageError` events.
110
+ *
111
+ * @internal
112
+ */
113
+ const imageAttrs = computed(() => Object.fromEntries(Object.entries(attrs).filter(([key]) => !key.startsWith('on'))));
114
+ /**
115
+ * The consumer's `class`, `style` and event listeners, applied to the root element.
116
+ *
117
+ * The component uses `inheritAttrs: false` so the remaining attributes (e.g.
118
+ * `decoding`, `crossorigin`, `fetchpriority`, `width`, `height`) only reach the
119
+ * rendered images through `imageAttrs` and don't leak to the wrapper div.
120
+ *
121
+ * @internal
122
+ */
123
+ const rootAttrs = computed(() => ({
124
+ class: attrs.class,
125
+ style: attrs.style,
126
+ ...Object.fromEntries(Object.entries(attrs).filter(([key]) => key.startsWith('on'))),
127
+ }));
60
128
  /**
61
129
  * Copy of the images of the result.
62
130
  *
@@ -99,14 +167,28 @@ var _sfc_main = defineComponent({
99
167
  pointerEvents: 'none !important',
100
168
  visibility: 'hidden !important',
101
169
  };
170
+ /**
171
+ * Resolves the `srcset` to use for the image at the given index.
172
+ *
173
+ * @param index - Index of the image inside `result.images`.
174
+ *
175
+ * @returns The `srcset` for that image, if any.
176
+ *
177
+ * @internal
178
+ */
179
+ const resolveSrcset = (index) => Array.isArray(props.srcset) ? props.srcset[index] : props.srcset;
102
180
  /**
103
181
  * Initializes images state and resets when the result's images change.
104
182
  *
105
183
  * @internal
106
184
  */
107
185
  watch(() => props.result.images, () => {
108
- pendingImages.value = [...(props.result.images ?? [])];
109
- loadedImages.value = pendingImages.value.filter(image => loadedImages.value.includes(image));
186
+ pendingImages.value = (props.result.images ?? []).map((src, index) => ({
187
+ index,
188
+ src,
189
+ srcset: resolveSrcset(index),
190
+ }));
191
+ loadedImages.value = pendingImages.value.filter(image => loadedImages.value.some(loadedImage => loadedImage.src === image.src));
110
192
  }, { immediate: true });
111
193
  /**
112
194
  * Animation to be used.
@@ -121,15 +203,31 @@ var _sfc_main = defineComponent({
121
203
  : props.loadAnimation;
122
204
  });
123
205
  /**
124
- * Gets the src from the result image.
206
+ * Gets the currently loaded image.
125
207
  *
126
- * @returns The result image src.
208
+ * @returns The currently loaded image entry, or undefined if none has been loaded.
127
209
  *
128
210
  * @internal
129
211
  */
130
- const imageSrc = computed(() => {
212
+ const currentImage = computed(() => {
131
213
  return loadedImages.value[!props.showNextImageOnHover || !isHovering.value ? 0 : loadedImages.value.length - 1];
132
214
  });
215
+ /**
216
+ * Gets the src of the currently loaded image.
217
+ *
218
+ * @returns The current image src.
219
+ *
220
+ * @internal
221
+ */
222
+ const imageSrc = computed(() => currentImage.value?.src);
223
+ /**
224
+ * Gets the srcset of the currently loaded image.
225
+ *
226
+ * @returns The current image srcset, if any.
227
+ *
228
+ * @internal
229
+ */
230
+ const imageSrcset = computed(() => currentImage.value?.srcset);
133
231
  /**
134
232
  * Indicates if the loader should try to load the next image.
135
233
  *
@@ -144,23 +242,40 @@ var _sfc_main = defineComponent({
144
242
  /**
145
243
  * Sets an image as failed.
146
244
  *
245
+ * @param event - The error event of the loader image.
246
+ *
147
247
  * @internal
148
248
  */
149
249
  const flagImageAsFailed = () => {
150
- pendingImages.value.shift();
250
+ const image = pendingImages.value.shift();
251
+ if (image) {
252
+ emit('imageError', { index: image.index, src: image.src, srcset: image.srcset });
253
+ }
151
254
  };
152
255
  /**
153
256
  * Sets an image as loaded.
154
257
  *
258
+ * @param event - The load event of the loader image.
259
+ *
155
260
  * @internal
156
261
  */
157
- const flagImageLoaded = () => {
262
+ const flagImageLoaded = (event) => {
158
263
  const image = pendingImages.value.shift();
159
264
  if (image) {
160
265
  loadedImages.value.push(image);
266
+ const element = event.target;
267
+ emit('imageLoaded', {
268
+ index: image.index,
269
+ src: image.src,
270
+ srcset: image.srcset,
271
+ currentSrc: element.currentSrc || image.src,
272
+ element,
273
+ });
161
274
  }
162
275
  };
163
276
  return {
277
+ imageAttrs,
278
+ rootAttrs,
164
279
  pendingImages,
165
280
  loadedImages,
166
281
  isHovering,
@@ -168,6 +283,7 @@ var _sfc_main = defineComponent({
168
283
  loaderStyles,
169
284
  animation,
170
285
  imageSrc,
286
+ imageSrcset,
171
287
  shouldLoadNextImage,
172
288
  flagImageAsFailed,
173
289
  flagImageLoaded,
@@ -1 +1 @@
1
- {"version":3,"file":"base-result-image.vue2.js","sources":["../../../../src/components/result/base-result-image.vue"],"sourcesContent":["<template>\n <!-- This is a div because using a picture causes the onload event of the image to fire twice. -->\n <!-- eslint-disable-next-line vuejs-accessibility/mouse-events-have-key-events -->\n <div\n class=\"x-result-picture xds:picture\"\n data-test=\"result-picture\"\n @mouseenter.once=\"userHasHoveredImage = true\"\n @mouseenter=\"isHovering = true\"\n @mouseleave=\"isHovering = false\"\n >\n <img\n v-if=\"shouldLoadNextImage\"\n loading=\"lazy\"\n :src=\"pendingImages[0]\"\n :style=\"loaderStyles\"\n class=\"xds:picture-image\"\n data-test=\"result-picture-loader\"\n alt=\"\"\n role=\"presentation\"\n @load=\"flagImageLoaded\"\n @error=\"flagImageAsFailed\"\n />\n <component :is=\"animation\" class=\"xds:picture-image\" :appear=\"false\">\n <!-- @slot Fallback image content. It will be rendered when all the images failed -->\n <slot v-if=\"!loadedImages.length && !pendingImages.length\" name=\"fallback\" />\n\n <!-- @slot Loading image content. It will be rendered while the real image is not loaded -->\n <slot v-else-if=\"!loadedImages.length\" name=\"placeholder\" />\n\n <img\n v-else\n :key=\"imageSrc\"\n :alt=\"result.name\"\n :src=\"imageSrc\"\n class=\"x-result-picture-image\"\n data-test=\"result-picture-image\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Result } from '@empathyco/x-types'\nimport type { PropType, Ref, StyleValue } from 'vue'\nimport { computed, defineComponent, ref, watch } from 'vue'\nimport { AnimationProp } from '../../types'\nimport { NoAnimation } from '../animations'\n\n/**\n * Component to be reused that renders an `<img>`.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseResultImage',\n props: {\n /** (Required) The {@link @empathyco/x-types#Result} information. */\n result: {\n type: Object as PropType<Result>,\n required: true,\n },\n /**\n * Animation to use when switching between the placeholder, the loaded image, or the failed\n * image fallback.\n */\n loadAnimation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /** Animation to use when switching between the loaded image and the hover image. */\n hoverAnimation: {\n type: AnimationProp,\n },\n /**\n * Indicates if the next valid image should be displayed on hover.\n *\n * @public\n */\n showNextImageOnHover: {\n type: Boolean,\n default: false,\n },\n },\n setup(props) {\n /**\n * Copy of the images of the result.\n *\n * It is used as a queue of images to load, once an image loads/fails to load, it is removed\n * from this array.\n *\n * @internal\n */\n const pendingImages: Ref<string[]> = ref([])\n\n /**\n * Contains the images that have been loaded successfully.\n *\n * @internal\n */\n const loadedImages: Ref<string[]> = ref([])\n\n /**\n * Indicates if the user is hovering the image.\n *\n * @internal\n */\n const isHovering = ref(false)\n\n /**\n * Indicates if the user has hovered the image.\n *\n * @internal\n */\n const userHasHoveredImage = ref(false)\n\n /**\n * Styles to use inline in the image loader, to prevent override from CSS\n *\n * @internal\n */\n const loaderStyles: StyleValue = {\n // csstype issue: https://github.com/frenic/csstype/issues/160\n position: 'absolute !important' as 'absolute',\n top: '0 !important' as '0',\n left: '0 !important' as '0',\n width: '100% !important' as '100%',\n height: '100% !important' as '100%',\n pointerEvents: 'none !important' as 'none',\n visibility: 'hidden !important' as 'hidden',\n }\n\n /**\n * Initializes images state and resets when the result's images change.\n *\n * @internal\n */\n watch(\n () => props.result.images,\n () => {\n pendingImages.value = [...(props.result.images ?? [])]\n loadedImages.value = pendingImages.value.filter(image => loadedImages.value.includes(image))\n },\n { immediate: true },\n )\n\n /**\n * Animation to be used.\n *\n * @returns The animation to be used, taking into account if the user has hovered the image.\n *\n * @internal\n */\n const animation = computed(() => {\n return userHasHoveredImage.value\n ? (props.hoverAnimation ?? props.loadAnimation)\n : props.loadAnimation\n })\n\n /**\n * Gets the src from the result image.\n *\n * @returns The result image src.\n *\n * @internal\n */\n const imageSrc = computed(() => {\n return loadedImages.value[\n !props.showNextImageOnHover || !isHovering.value ? 0 : loadedImages.value.length - 1\n ]\n })\n\n /**\n * Indicates if the loader should try to load the next image.\n *\n * @returns True if it should try to load the next image.\n *\n * @internal\n */\n const shouldLoadNextImage = computed(() => {\n const numImagesToLoad = props.showNextImageOnHover && userHasHoveredImage.value ? 2 : 1\n return !!pendingImages.value.length && loadedImages.value.length < numImagesToLoad\n })\n\n /**\n * Sets an image as failed.\n *\n * @internal\n */\n const flagImageAsFailed = () => {\n pendingImages.value.shift()\n }\n\n /**\n * Sets an image as loaded.\n *\n * @internal\n */\n const flagImageLoaded = () => {\n const image = pendingImages.value.shift()\n if (image) {\n loadedImages.value.push(image)\n }\n }\n\n return {\n pendingImages,\n loadedImages,\n isHovering,\n userHasHoveredImage,\n loaderStyles,\n animation,\n imageSrc,\n shouldLoadNextImage,\n flagImageAsFailed,\n flagImageLoaded,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-result-picture {\n position: relative;\n min-width: 1px;\n min-height: 1px;\n}\n\n.x-result-picture-image {\n max-width: 100%;\n max-height: 100%;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\n### Basic example\n\nThis component is for the result image. It may be part of the search result page, recommendations or\nother section which needs to include results.\n\nThe result prop is required. It will render a `<img/>` with the result image:\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\n### Showing the next image on hover\n\nIf a result has multiple images, it can show the next one on hover.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" showNextImageOnHover />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg', 'https://some-image-url.com/image2.jpg'],\n}\n</script>\n```\n\n### Customizing slots content\n\nFallback and placeholder contents can be customized.\n\nThe fallback slot allows you to replace the content of the fallback image.\n\nThe other slot is called `placeholder`, and allows you to set the image that its going to be\ndisplayed while the real one is loaded.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\">\n <template #placeholder>\n <img alt=\"Placeholder image\" src=\"./placeholder-image.svg\" />\n </template>\n <template #fallback>\n <img alt=\"Fallback image\" src=\"./fallback-image.svg\" />\n </template>\n </BaseResultImage>\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\n### Customizing the animations\n\nTwo animations can be used in this component.\n\nThe `loadAnimation` is used to transition between the placeholder, the fallback and the image.\n\nThe `hoverAnimation` is used to transition between the image and the hover image, if the\n`showNextImageOnHover` prop is `true`.\n\n`hoverAnimation` will default to `loadAnimation` if it is not provided.\n\n```vue\n<template>\n <BaseResultImage\n :result=\"result\"\n :loadAnimation=\"loadAnimation\"\n :hoverAnimation=\"hoverAnimation\"\n showNextImageOnHover\n />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nimport { CrossFade, CollapseHeight } from '@empathyco/x-components/animations'\nconst loadAnimation = CrossFade\nconst hoverAnimation = CollapseHeight\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg', 'https://some-image-url.com/image2.jpg'],\n}\n</script>\n```\n</docs>\n"],"names":["NoAnimation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgDA;;;;AAIE;AACF,gBAAe,eAAe,CAAC;AAC7B,IAAA,IAAI,EAAE,iBAAiB;AACvB,IAAA,KAAK,EAAE;;AAEL,QAAA,MAAM,EAAE;AACN,YAAA,IAAI,EAAE,MAA0B;AAChC,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA;AACD;;;AAGE;AACF,QAAA,aAAa,EAAE;AACb,YAAA,IAAI,EAAE,aAAa;AACnB,YAAA,OAAO,EAAE,MAAMA,WAAW;AAC3B,SAAA;;AAED,QAAA,cAAc,EAAE;AACd,YAAA,IAAI,EAAE,aAAa;AACpB,SAAA;AACD;;;;AAIE;AACF,QAAA,oBAAoB,EAAE;AACpB,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,OAAO,EAAE,KAAK;AACf,SAAA;AACF,KAAA;AACD,IAAA,KAAK,CAAC,KAAK,EAAA;AACT;;;;;;;AAOE;AACF,QAAA,MAAM,aAAa,GAAkB,GAAG,CAAC,EAAE,CAAA;AAE3C;;;;AAIE;AACF,QAAA,MAAM,YAAY,GAAkB,GAAG,CAAC,EAAE,CAAA;AAE1C;;;;AAIE;AACF,QAAA,MAAM,UAAS,GAAI,GAAG,CAAC,KAAK,CAAA;AAE5B;;;;AAIE;AACF,QAAA,MAAM,sBAAsB,GAAG,CAAC,KAAK,CAAA;AAErC;;;;AAIE;AACF,QAAA,MAAM,YAAY,GAAe;;AAE/B,YAAA,QAAQ,EAAE,qBAAmC;AAC7C,YAAA,GAAG,EAAE,cAAqB;AAC1B,YAAA,IAAI,EAAE,cAAqB;AAC3B,YAAA,KAAK,EAAE,iBAA2B;AAClC,YAAA,MAAM,EAAE,iBAA2B;AACnC,YAAA,aAAa,EAAE,iBAA2B;AAC1C,YAAA,UAAU,EAAE,mBAA+B;SAC7C;AAEA;;;;AAIE;QACF,KAAK,CACH,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,EACzB,MAAI;AACF,YAAA,aAAa,CAAC,KAAI,GAAI,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAA;YACrD,YAAY,CAAC,KAAI,GAAI,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,KAAI,IAAK,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC7F,QAAA,CAAC,EACD,EAAE,SAAS,EAAE,MAAM,CACrB;AAEA;;;;;;AAME;AACF,QAAA,MAAM,SAAQ,GAAI,QAAQ,CAAC,MAAI;YAC7B,OAAO,mBAAmB,CAAC;mBACtB,KAAK,CAAC,cAAa,IAAK,KAAK,CAAC,aAAa;AAC9C,kBAAE,KAAK,CAAC,aAAY;AACxB,QAAA,CAAC,CAAA;AAED;;;;;;AAME;AACF,QAAA,MAAM,QAAO,GAAI,QAAQ,CAAC,MAAI;AAC5B,YAAA,OAAO,YAAY,CAAC,KAAK,CACvB,CAAC,KAAK,CAAC,oBAAmB,IAAK,CAAC,UAAU,CAAC,KAAI,GAAI,CAAA,GAAI,YAAY,CAAC,KAAK,CAAC,SAAS,CAAA,CACrF;AACF,QAAA,CAAC,CAAA;AAED;;;;;;AAME;AACF,QAAA,MAAM,mBAAkB,GAAI,QAAQ,CAAC,MAAI;AACvC,YAAA,MAAM,eAAc,GAAI,KAAK,CAAC,oBAAmB,IAAK,mBAAmB,CAAC,KAAI,GAAI,IAAI,CAAA;AACtF,YAAA,OAAO,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,MAAK,IAAK,YAAY,CAAC,KAAK,CAAC,MAAK,GAAI,eAAc;AACnF,QAAA,CAAC,CAAA;AAED;;;;AAIE;QACF,MAAM,iBAAgB,GAAI,MAAI;AAC5B,YAAA,aAAa,CAAC,KAAK,CAAC,KAAK,EAAC;AAC5B,QAAA,CAAA;AAEA;;;;AAIE;QACF,MAAM,kBAAkB,MAAI;YAC1B,MAAM,KAAI,GAAI,aAAa,CAAC,KAAK,CAAC,KAAK,EAAC;YACxC,IAAI,KAAK,EAAE;AACT,gBAAA,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAA;YAC/B;AACF,QAAA,CAAA;QAEA,OAAO;YACL,aAAa;YACb,YAAY;YACZ,UAAU;YACV,mBAAmB;YACnB,YAAY;YACZ,SAAS;YACT,QAAQ;YACR,mBAAmB;YACnB,iBAAiB;YACjB,eAAe;SACjB;IACF,CAAC;AACF,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"base-result-image.vue2.js","sources":["../../../../src/components/result/base-result-image.vue"],"sourcesContent":["<template>\n <!-- This is a div because using a picture causes the onload event of the image to fire twice. -->\n <!-- eslint-disable-next-line vuejs-accessibility/mouse-events-have-key-events -->\n <div\n v-bind=\"rootAttrs\"\n class=\"x-result-picture xds:picture\"\n data-test=\"result-picture\"\n @mouseenter.once=\"userHasHoveredImage = true\"\n @mouseenter=\"isHovering = true\"\n @mouseleave=\"isHovering = false\"\n >\n <img\n v-if=\"shouldLoadNextImage\"\n v-bind=\"imageAttrs\"\n :loading=\"loading\"\n :src=\"pendingImages[0].src\"\n :srcset=\"pendingImages[0].srcset\"\n :sizes=\"sizes\"\n :style=\"loaderStyles\"\n class=\"xds:picture-image\"\n data-test=\"result-picture-loader\"\n alt=\"\"\n role=\"presentation\"\n @load=\"flagImageLoaded\"\n @error=\"flagImageAsFailed\"\n />\n <component :is=\"animation\" class=\"xds:picture-image\" :appear=\"false\">\n <!-- @slot Fallback image content. It will be rendered when all the images failed -->\n <slot v-if=\"!loadedImages.length && !pendingImages.length\" name=\"fallback\" />\n\n <!-- @slot Loading image content. It will be rendered while the real image is not loaded -->\n <slot v-else-if=\"!loadedImages.length\" name=\"placeholder\" />\n\n <img\n v-else\n v-bind=\"imageAttrs\"\n :key=\"imageSrc\"\n :alt=\"result.name\"\n :src=\"imageSrc\"\n :srcset=\"imageSrcset\"\n :sizes=\"sizes\"\n class=\"x-result-picture-image\"\n data-test=\"result-picture-image\"\n />\n </component>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport type { Result } from '@empathyco/x-types'\nimport type { PropType, Ref, StyleValue } from 'vue'\nimport { computed, defineComponent, ref, useAttrs, watch } from 'vue'\n\nimport { AnimationProp } from '../../types'\nimport { NoAnimation } from '../animations'\n\n/**\n * An entry of the images queue: the image `src` and its optional `srcset`.\n *\n * @internal\n */\ninterface ImageEntry {\n /** Index of the image inside `result.images`. */\n index: number\n /** The image URL. */\n src: string\n /** Responsive candidates for the image, if provided. */\n srcset?: string\n}\n\n/**\n * Component to be reused that renders an `<img>`.\n *\n * Additional `<img>` attributes passed to the component (e.g. `decoding`, `crossorigin`,\n * `referrerpolicy`, `fetchpriority`, `width` and `height`) are forwarded to the rendered\n * images, while `class`, `style` and event listeners keep falling through to the root\n * element, as before. Use the `imageLoaded` and `imageError` events to observe the image\n * loading state.\n *\n * @public\n */\nexport default defineComponent({\n name: 'BaseResultImage',\n inheritAttrs: false,\n props: {\n /** (Required) The {@link @empathyco/x-types#Result} information. */\n result: {\n type: Object as PropType<Result>,\n required: true,\n },\n /**\n * Animation to use when switching between the placeholder, the loaded image, or the failed\n * image fallback.\n */\n loadAnimation: {\n type: AnimationProp,\n default: () => NoAnimation,\n },\n /** Animation to use when switching between the loaded image and the hover image. */\n hoverAnimation: {\n type: AnimationProp,\n },\n /**\n * Indicates if the next valid image should be displayed on hover.\n *\n * @public\n */\n showNextImageOnHover: {\n type: Boolean,\n default: false,\n },\n /**\n * Responsive image candidates (`srcset`).\n *\n * - A single string is applied to every image of the result (e.g.\n * `\"image-480.jpg 480w, image-1024.jpg 1024w\"`).\n * - An array is parallel to `result.images`, so each image can have its own candidates.\n *\n * When provided, the `src` is kept as a fallback for browsers without `srcset` support.\n *\n * @public\n */\n srcset: {\n type: [String, Array] as PropType<string | (string | undefined)[]>,\n },\n /**\n * The sizes of the image for different page layouts (`sizes`).\n *\n * It is shared by all the images of the result, since it depends on the layout and not on\n * the image. Pass it together with `srcset`, since it is ignored otherwise.\n *\n * @public\n */\n sizes: {\n type: String,\n },\n /**\n * Image loading mode.\n *\n * @public\n */\n loading: {\n type: String as PropType<'lazy' | 'eager'>,\n default: 'lazy',\n },\n },\n emits: ['imageLoaded', 'imageError'],\n setup(props, { emit }) {\n const attrs = useAttrs()\n\n /**\n * Additional `<img>` attributes passed to the component (e.g. `decoding`,\n * `crossorigin`, `fetchpriority`, `width`, `height`), forwarded to the rendered images.\n *\n * Event listeners are excluded so they don't reach the hidden loader: they keep\n * falling through to the root element, and the image loading state is exposed through\n * the `imageLoaded` and `imageError` events.\n *\n * @internal\n */\n const imageAttrs = computed(() =>\n Object.fromEntries(Object.entries(attrs).filter(([key]) => !key.startsWith('on'))),\n )\n\n /**\n * The consumer's `class`, `style` and event listeners, applied to the root element.\n *\n * The component uses `inheritAttrs: false` so the remaining attributes (e.g.\n * `decoding`, `crossorigin`, `fetchpriority`, `width`, `height`) only reach the\n * rendered images through `imageAttrs` and don't leak to the wrapper div.\n *\n * @internal\n */\n const rootAttrs = computed(() => ({\n class: attrs.class,\n style: attrs.style,\n ...Object.fromEntries(Object.entries(attrs).filter(([key]) => key.startsWith('on'))),\n }))\n\n /**\n * Copy of the images of the result.\n *\n * It is used as a queue of images to load, once an image loads/fails to load, it is removed\n * from this array.\n *\n * @internal\n */\n const pendingImages: Ref<ImageEntry[]> = ref([])\n\n /**\n * Contains the images that have been loaded successfully.\n *\n * @internal\n */\n const loadedImages: Ref<ImageEntry[]> = ref([])\n\n /**\n * Indicates if the user is hovering the image.\n *\n * @internal\n */\n const isHovering = ref(false)\n\n /**\n * Indicates if the user has hovered the image.\n *\n * @internal\n */\n const userHasHoveredImage = ref(false)\n\n /**\n * Styles to use inline in the image loader, to prevent override from CSS\n *\n * @internal\n */\n const loaderStyles: StyleValue = {\n // csstype issue: https://github.com/frenic/csstype/issues/160\n position: 'absolute !important' as 'absolute',\n top: '0 !important' as '0',\n left: '0 !important' as '0',\n width: '100% !important' as '100%',\n height: '100% !important' as '100%',\n pointerEvents: 'none !important' as 'none',\n visibility: 'hidden !important' as 'hidden',\n }\n\n /**\n * Resolves the `srcset` to use for the image at the given index.\n *\n * @param index - Index of the image inside `result.images`.\n *\n * @returns The `srcset` for that image, if any.\n *\n * @internal\n */\n const resolveSrcset = (index: number): string | undefined =>\n Array.isArray(props.srcset) ? props.srcset[index] : props.srcset\n\n /**\n * Initializes images state and resets when the result's images change.\n *\n * @internal\n */\n watch(\n () => props.result.images,\n () => {\n pendingImages.value = (props.result.images ?? []).map((src, index) => ({\n index,\n src,\n srcset: resolveSrcset(index),\n }))\n loadedImages.value = pendingImages.value.filter(image =>\n loadedImages.value.some(loadedImage => loadedImage.src === image.src),\n )\n },\n { immediate: true },\n )\n\n /**\n * Animation to be used.\n *\n * @returns The animation to be used, taking into account if the user has hovered the image.\n *\n * @internal\n */\n const animation = computed(() => {\n return userHasHoveredImage.value\n ? (props.hoverAnimation ?? props.loadAnimation)\n : props.loadAnimation\n })\n\n /**\n * Gets the currently loaded image.\n *\n * @returns The currently loaded image entry, or undefined if none has been loaded.\n *\n * @internal\n */\n const currentImage = computed(() => {\n return loadedImages.value[\n !props.showNextImageOnHover || !isHovering.value ? 0 : loadedImages.value.length - 1\n ]\n })\n\n /**\n * Gets the src of the currently loaded image.\n *\n * @returns The current image src.\n *\n * @internal\n */\n const imageSrc = computed(() => currentImage.value?.src)\n\n /**\n * Gets the srcset of the currently loaded image.\n *\n * @returns The current image srcset, if any.\n *\n * @internal\n */\n const imageSrcset = computed(() => currentImage.value?.srcset)\n\n /**\n * Indicates if the loader should try to load the next image.\n *\n * @returns True if it should try to load the next image.\n *\n * @internal\n */\n const shouldLoadNextImage = computed(() => {\n const numImagesToLoad = props.showNextImageOnHover && userHasHoveredImage.value ? 2 : 1\n return !!pendingImages.value.length && loadedImages.value.length < numImagesToLoad\n })\n\n /**\n * Sets an image as failed.\n *\n * @param event - The error event of the loader image.\n *\n * @internal\n */\n const flagImageAsFailed = () => {\n const image = pendingImages.value.shift()\n if (image) {\n emit('imageError', { index: image.index, src: image.src, srcset: image.srcset })\n }\n }\n\n /**\n * Sets an image as loaded.\n *\n * @param event - The load event of the loader image.\n *\n * @internal\n */\n const flagImageLoaded = (event: Event) => {\n const image = pendingImages.value.shift()\n if (image) {\n loadedImages.value.push(image)\n const element = event.target as HTMLImageElement\n emit('imageLoaded', {\n index: image.index,\n src: image.src,\n srcset: image.srcset,\n currentSrc: element.currentSrc || image.src,\n element,\n })\n }\n }\n\n return {\n imageAttrs,\n rootAttrs,\n pendingImages,\n loadedImages,\n isHovering,\n userHasHoveredImage,\n loaderStyles,\n animation,\n imageSrc,\n imageSrcset,\n shouldLoadNextImage,\n flagImageAsFailed,\n flagImageLoaded,\n }\n },\n})\n</script>\n\n<style lang=\"css\" scoped>\n.x-result-picture {\n position: relative;\n min-width: 1px;\n min-height: 1px;\n}\n\n.x-result-picture-image {\n max-width: 100%;\n max-height: 100%;\n}\n</style>\n\n<docs lang=\"mdx\">\n## Examples\n\n### Basic example\n\nThis component is for the result image. It may be part of the search result page, recommendations or\nother section which needs to include results.\n\nThe result prop is required. It will render a `<img/>` with the result image:\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\n### Responsive images with `srcset` and `sizes`\n\nThe `srcset` and `sizes` props are used to deliver the right image candidate according to the\ndevice and the layout (like the native `<img>` attributes).\n\n`srcset` can be a single string, applied to all the images of the result, or an array parallel to\n`result.images`, so each image can have its own candidates.\n\n```vue\n<template>\n <BaseResultImage\n :result=\"result\"\n srcset=\"image1-480.jpg?width=400 480w, image1-1024.jpg?width=1024 1024w\"\n sizes=\"(min-width: 600px) 33vw, 100vw\"\n />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\nThe `src` of the image is always kept, so it works as a fallback when `srcset` is not supported.\n\n### Showing the next image on hover\n\nIf a result has multiple images, it can show the next one on hover.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" showNextImageOnHover />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg', 'https://some-image-url.com/image2.jpg'],\n}\n</script>\n```\n\n### Customizing slots content\n\nFallback and placeholder contents can be customized.\n\nThe fallback slot allows you to replace the content of the fallback image.\n\nThe other slot is called `placeholder`, and allows you to set the image that its going to be\ndisplayed while the real one is loaded.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\">\n <template #placeholder>\n <img alt=\"Placeholder image\" src=\"./placeholder-image.svg\" />\n </template>\n <template #fallback>\n <img alt=\"Fallback image\" src=\"./fallback-image.svg\" />\n </template>\n </BaseResultImage>\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\n</script>\n```\n\n### Customizing the animations\n\nTwo animations can be used in this component.\n\nThe `loadAnimation` is used to transition between the placeholder, the fallback and the image.\n\nThe `hoverAnimation` is used to transition between the image and the hover image, if the\n`showNextImageOnHover` prop is `true`.\n\n`hoverAnimation` will default to `loadAnimation` if it is not provided.\n\n```vue\n<template>\n <BaseResultImage\n :result=\"result\"\n :loadAnimation=\"loadAnimation\"\n :hoverAnimation=\"hoverAnimation\"\n showNextImageOnHover\n />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nimport { CrossFade, CollapseHeight } from '@empathyco/x-components/animations'\nconst loadAnimation = CrossFade\nconst hoverAnimation = CollapseHeight\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg', 'https://some-image-url.com/image2.jpg'],\n}\n</script>\n```\n\n### Optimizing the first result for LCP\n\nBy default, images are loaded lazily. For the first (above-the-fold) result of the search results\npage, the image is usually the **Largest Contentful Paint (LCP)** element: eager-loading it with\na high fetch priority avoids waiting for the lazy-load viewport check and lets the browser start\nthe request immediately.\n\nCombine it with `width` and `height` so the browser can prioritize and reserve the space of the\nLCP element from the start:\n\n```vue\n<template>\n <!-- First, above-the-fold result -->\n <BaseResultImage\n :result=\"firstResult\"\n loading=\"eager\"\n fetchPriority=\"high\"\n :width=\"256\"\n :height=\"371\"\n />\n <!-- All the remaining results keep the default lazy loading -->\n <BaseResultImage v-for=\"result in otherResults\" :key=\"result.id\" :result=\"result\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\n</script>\n```\n\nOnly the above-the-fold results should use `loading=\"eager\"`; keep the rest lazy to avoid\nrequesting more images than needed.\n\n### Avoiding layout shift (CLS)\n\nPassing `width` and `height` (the intrinsic dimensions of the image) helps the browser reserve\nthe right space before the image is loaded, preventing the layout shift caused by the image\nreplacing the placeholder.\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" :width=\"256\" :height=\"371\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\n</script>\n```\n\n### Passing additional image attributes\n\nAny additional `<img>` attribute passed to the component is forwarded to the rendered images\n(the hidden preload image and the visible one), so there is no need for a specific prop per\nattribute:\n\n```vue\n<template>\n <BaseResultImage\n :result=\"result\"\n decoding=\"async\"\n crossorigin=\"anonymous\"\n fetchpriority=\"high\"\n referrerpolicy=\"no-referrer\"\n :width=\"256\"\n :height=\"371\"\n />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\n</script>\n```\n\n`class`, `style` and event listeners keep being applied to the root element, so the wrapper\ncan still be styled and listened to. Any other additional attribute is only applied to the\nrendered images, never to the wrapper div. Observe the image loading state with the\n`imageLoaded` and `imageError` events instead.\n\n### Image loading events\n\nThe component emits `imageLoaded` when an image finishes loading, and `imageError` when an image\nfails to load (the next one of the queue will be tried).\n\n```vue\n<template>\n <BaseResultImage :result=\"result\" @imageLoaded=\"imageLoaded\" @imageError=\"imageError\" />\n</template>\n\n<script setup>\nimport { BaseResultImage } from '@empathyco/x-components'\nconst result = {\n name: 'Jacket',\n images: ['https://some-image-url.com/image1.jpg'],\n}\nconst imageLoaded = ({ index, src, currentSrc }) => {\n // For example, track the candidate actually downloaded by the browser\n console.log(`Image ${index} loaded: ${src} (downloaded ${currentSrc})`)\n}\nconst imageError = ({ index, src }) => {\n console.log(`Image ${index} failed: ${src}`)\n}\n</script>\n```\n</docs>\n"],"names":["NoAnimation"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-components",
3
- "version": "10.4.0",
3
+ "version": "10.5.0",
4
4
  "description": "Empathy X Components",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -67,10 +67,10 @@
67
67
  "vuex": "4.0.2"
68
68
  },
69
69
  "dependencies": {
70
- "@empathyco/x-adapter": "8.2.1",
71
- "@empathyco/x-adapter-platform": "2.0.1",
72
- "@empathyco/x-types": "11.0.1",
73
- "@empathyco/x-utils": "1.1.1",
70
+ "@empathyco/x-adapter": "8.2.2",
71
+ "@empathyco/x-adapter-platform": "2.0.2",
72
+ "@empathyco/x-types": "11.0.2",
73
+ "@empathyco/x-utils": "1.1.2",
74
74
  "@vue/devtools-api": "~6.6.4",
75
75
  "@vueuse/core": "~12.8.2",
76
76
  "js-md5": "~0.9.2",
@@ -82,7 +82,7 @@
82
82
  },
83
83
  "devDependencies": {
84
84
  "@babel/preset-env": "8.0.7",
85
- "@empathyco/x-design-system": "1.2.1",
85
+ "@empathyco/x-design-system": "1.2.2",
86
86
  "@microsoft/api-documenter": "7.30.19",
87
87
  "@microsoft/api-extractor": "7.60.0",
88
88
  "@tailwindcss/vite": "4.3.3",
@@ -117,5 +117,5 @@
117
117
  "access": "public",
118
118
  "directory": "dist"
119
119
  },
120
- "gitHead": "8cbae67c1d388227ccfe6adaf2c7413ff3962e07"
120
+ "gitHead": "f252645300a5faa7d42075010b01a8fe0fc23b58"
121
121
  }
@@ -11322,7 +11322,7 @@
11322
11322
  {
11323
11323
  "kind": "Variable",
11324
11324
  "canonicalReference": "@empathyco/x-components!BaseResultImage:var",
11325
- "docComment": "/**\n * Component to be reused that renders an `<img>`.\n *\n * @public\n */\n",
11325
+ "docComment": "/**\n * Component to be reused that renders an `<img>`.\n *\n * Additional `<img>` attributes passed to the component (e.g. `decoding`, `crossorigin`,\n * `referrerpolicy`, `fetchpriority`, `width` and `height`) are forwarded to the rendered\n * images, while `class`, `style` and event listeners keep falling through to the root\n * element, as before. Use the `imageLoaded` and `imageError` events to observe the image\n * loading state.\n *\n * @public\n */\n",
11326
11326
  "excerptTokens": [
11327
11327
  {
11328
11328
  "kind": "Content",
@@ -11438,7 +11438,70 @@
11438
11438
  },
11439
11439
  {
11440
11440
  "kind": "Content",
11441
- "text": ";\n default: boolean;\n };\n}>, {\n pendingImages: "
11441
+ "text": ";\n default: boolean;\n };\n srcset: {\n type: "
11442
+ },
11443
+ {
11444
+ "kind": "Reference",
11445
+ "text": "PropType",
11446
+ "canonicalReference": "@vue/runtime-core!PropType:type"
11447
+ },
11448
+ {
11449
+ "kind": "Content",
11450
+ "text": "<string | (string | undefined)[]>;\n };\n sizes: {\n type: "
11451
+ },
11452
+ {
11453
+ "kind": "Reference",
11454
+ "text": "StringConstructor",
11455
+ "canonicalReference": "!StringConstructor:interface"
11456
+ },
11457
+ {
11458
+ "kind": "Content",
11459
+ "text": ";\n };\n loading: {\n type: "
11460
+ },
11461
+ {
11462
+ "kind": "Reference",
11463
+ "text": "PropType",
11464
+ "canonicalReference": "@vue/runtime-core!PropType:type"
11465
+ },
11466
+ {
11467
+ "kind": "Content",
11468
+ "text": "<\"lazy\" | \"eager\">;\n default: string;\n };\n}>, {\n imageAttrs: import(\"vue\")."
11469
+ },
11470
+ {
11471
+ "kind": "Reference",
11472
+ "text": "ComputedRef",
11473
+ "canonicalReference": "@vue/reactivity!ComputedRef:interface"
11474
+ },
11475
+ {
11476
+ "kind": "Content",
11477
+ "text": "<{\n [k: string]: unknown;\n }>;\n rootAttrs: import(\"vue\")."
11478
+ },
11479
+ {
11480
+ "kind": "Reference",
11481
+ "text": "ComputedRef",
11482
+ "canonicalReference": "@vue/reactivity!ComputedRef:interface"
11483
+ },
11484
+ {
11485
+ "kind": "Content",
11486
+ "text": "<{\n class: import(\"vue\")."
11487
+ },
11488
+ {
11489
+ "kind": "Reference",
11490
+ "text": "ClassValue",
11491
+ "canonicalReference": "@vue/runtime-dom!ClassValue:type"
11492
+ },
11493
+ {
11494
+ "kind": "Content",
11495
+ "text": ";\n style: "
11496
+ },
11497
+ {
11498
+ "kind": "Reference",
11499
+ "text": "StyleValue",
11500
+ "canonicalReference": "@vue/runtime-dom!StyleValue:type"
11501
+ },
11502
+ {
11503
+ "kind": "Content",
11504
+ "text": ";\n }>;\n pendingImages: "
11442
11505
  },
11443
11506
  {
11444
11507
  "kind": "Reference",
@@ -11447,7 +11510,25 @@
11447
11510
  },
11448
11511
  {
11449
11512
  "kind": "Content",
11450
- "text": "<string[], string[]>;\n loadedImages: "
11513
+ "text": "<"
11514
+ },
11515
+ {
11516
+ "kind": "Reference",
11517
+ "text": "ImageEntry",
11518
+ "canonicalReference": "@empathyco/x-components!~ImageEntry:interface"
11519
+ },
11520
+ {
11521
+ "kind": "Content",
11522
+ "text": "[], "
11523
+ },
11524
+ {
11525
+ "kind": "Reference",
11526
+ "text": "ImageEntry",
11527
+ "canonicalReference": "@empathyco/x-components!~ImageEntry:interface"
11528
+ },
11529
+ {
11530
+ "kind": "Content",
11531
+ "text": "[]>;\n loadedImages: "
11451
11532
  },
11452
11533
  {
11453
11534
  "kind": "Reference",
@@ -11456,7 +11537,25 @@
11456
11537
  },
11457
11538
  {
11458
11539
  "kind": "Content",
11459
- "text": "<string[], string[]>;\n isHovering: "
11540
+ "text": "<"
11541
+ },
11542
+ {
11543
+ "kind": "Reference",
11544
+ "text": "ImageEntry",
11545
+ "canonicalReference": "@empathyco/x-components!~ImageEntry:interface"
11546
+ },
11547
+ {
11548
+ "kind": "Content",
11549
+ "text": "[], "
11550
+ },
11551
+ {
11552
+ "kind": "Reference",
11553
+ "text": "ImageEntry",
11554
+ "canonicalReference": "@empathyco/x-components!~ImageEntry:interface"
11555
+ },
11556
+ {
11557
+ "kind": "Content",
11558
+ "text": "[]>;\n isHovering: "
11460
11559
  },
11461
11560
  {
11462
11561
  "kind": "Reference",
@@ -11519,7 +11618,7 @@
11519
11618
  },
11520
11619
  {
11521
11620
  "kind": "Content",
11522
- "text": "<string>;\n shouldLoadNextImage: import(\"vue\")."
11621
+ "text": "<string>;\n imageSrcset: import(\"vue\")."
11523
11622
  },
11524
11623
  {
11525
11624
  "kind": "Reference",
@@ -11528,7 +11627,25 @@
11528
11627
  },
11529
11628
  {
11530
11629
  "kind": "Content",
11531
- "text": "<boolean>;\n flagImageAsFailed: () => void;\n flagImageLoaded: () => void;\n}, {}, {}, {}, import(\"vue\")."
11630
+ "text": "<string | undefined>;\n shouldLoadNextImage: import(\"vue\")."
11631
+ },
11632
+ {
11633
+ "kind": "Reference",
11634
+ "text": "ComputedRef",
11635
+ "canonicalReference": "@vue/reactivity!ComputedRef:interface"
11636
+ },
11637
+ {
11638
+ "kind": "Content",
11639
+ "text": "<boolean>;\n flagImageAsFailed: () => void;\n flagImageLoaded: (event: "
11640
+ },
11641
+ {
11642
+ "kind": "Reference",
11643
+ "text": "Event",
11644
+ "canonicalReference": "!Event:interface"
11645
+ },
11646
+ {
11647
+ "kind": "Content",
11648
+ "text": ") => void;\n}, {}, {}, {}, import(\"vue\")."
11532
11649
  },
11533
11650
  {
11534
11651
  "kind": "Reference",
@@ -11546,7 +11663,7 @@
11546
11663
  },
11547
11664
  {
11548
11665
  "kind": "Content",
11549
- "text": ", {}, string, import(\"vue\")."
11666
+ "text": ", (\"imageLoaded\" | \"imageError\")[], \"imageLoaded\" | \"imageError\", import(\"vue\")."
11550
11667
  },
11551
11668
  {
11552
11669
  "kind": "Reference",
@@ -11663,7 +11780,34 @@
11663
11780
  },
11664
11781
  {
11665
11782
  "kind": "Content",
11666
- "text": ";\n default: boolean;\n };\n}>> & "
11783
+ "text": ";\n default: boolean;\n };\n srcset: {\n type: "
11784
+ },
11785
+ {
11786
+ "kind": "Reference",
11787
+ "text": "PropType",
11788
+ "canonicalReference": "@vue/runtime-core!PropType:type"
11789
+ },
11790
+ {
11791
+ "kind": "Content",
11792
+ "text": "<string | (string | undefined)[]>;\n };\n sizes: {\n type: "
11793
+ },
11794
+ {
11795
+ "kind": "Reference",
11796
+ "text": "StringConstructor",
11797
+ "canonicalReference": "!StringConstructor:interface"
11798
+ },
11799
+ {
11800
+ "kind": "Content",
11801
+ "text": ";\n };\n loading: {\n type: "
11802
+ },
11803
+ {
11804
+ "kind": "Reference",
11805
+ "text": "PropType",
11806
+ "canonicalReference": "@vue/runtime-core!PropType:type"
11807
+ },
11808
+ {
11809
+ "kind": "Content",
11810
+ "text": "<\"lazy\" | \"eager\">;\n default: string;\n };\n}>> & "
11667
11811
  },
11668
11812
  {
11669
11813
  "kind": "Reference",
@@ -11672,7 +11816,7 @@
11672
11816
  },
11673
11817
  {
11674
11818
  "kind": "Content",
11675
- "text": "<{}>, {\n loadAnimation: string | "
11819
+ "text": "<{\n onImageLoaded?: ((...args: any[]) => any) | undefined;\n onImageError?: ((...args: any[]) => any) | undefined;\n}>, {\n loadAnimation: string | "
11676
11820
  },
11677
11821
  {
11678
11822
  "kind": "Reference",
@@ -11690,7 +11834,7 @@
11690
11834
  },
11691
11835
  {
11692
11836
  "kind": "Content",
11693
- "text": "<string, any>;\n showNextImageOnHover: boolean;\n}, {}, {}, {}, string, import(\"vue\")."
11837
+ "text": "<string, any>;\n showNextImageOnHover: boolean;\n loading: \"lazy\" | \"eager\";\n}, {}, {}, {}, string, import(\"vue\")."
11694
11838
  },
11695
11839
  {
11696
11840
  "kind": "Reference",
@@ -11708,7 +11852,7 @@
11708
11852
  "name": "BaseResultImage",
11709
11853
  "variableTypeTokenRange": {
11710
11854
  "startIndex": 1,
11711
- "endIndex": 84
11855
+ "endIndex": 116
11712
11856
  }
11713
11857
  },
11714
11858
  {
@@ -34,6 +34,7 @@ import { default as ChevronTinyLeftIcon } from './chevron-tiny-left.vue';
34
34
  import { default as ChevronTinyRightIcon } from './chevron-tiny-right.vue';
35
35
  import { default as ChevronTinyUpIcon } from './chevron-tiny-up.vue';
36
36
  import { default as ChevronUpIcon } from './chevron-up.vue';
37
+ import { ClassValue } from 'vue';
37
38
  import type { Component } from 'vue';
38
39
  import { ComponentOptionsMixin } from 'vue';
39
40
  import { ComponentProvideOptions } from 'vue';
@@ -1424,18 +1425,36 @@ showNextImageOnHover: {
1424
1425
  type: BooleanConstructor;
1425
1426
  default: boolean;
1426
1427
  };
1428
+ srcset: {
1429
+ type: PropType<string | (string | undefined)[]>;
1430
+ };
1431
+ sizes: {
1432
+ type: StringConstructor;
1433
+ };
1434
+ loading: {
1435
+ type: PropType<"lazy" | "eager">;
1436
+ default: string;
1437
+ };
1427
1438
  }>, {
1428
- pendingImages: Ref<string[], string[]>;
1429
- loadedImages: Ref<string[], string[]>;
1439
+ imageAttrs: ComputedRef< {
1440
+ [k: string]: unknown;
1441
+ }>;
1442
+ rootAttrs: ComputedRef< {
1443
+ class: ClassValue;
1444
+ style: StyleValue;
1445
+ }>;
1446
+ pendingImages: Ref<ImageEntry[], ImageEntry[]>;
1447
+ loadedImages: Ref<ImageEntry[], ImageEntry[]>;
1430
1448
  isHovering: Ref<boolean, boolean>;
1431
1449
  userHasHoveredImage: Ref<boolean, boolean>;
1432
1450
  loaderStyles: CSSProperties;
1433
1451
  animation: ComputedRef<string | Function | Record<string, any>>;
1434
1452
  imageSrc: ComputedRef<string>;
1453
+ imageSrcset: ComputedRef<string | undefined>;
1435
1454
  shouldLoadNextImage: ComputedRef<boolean>;
1436
1455
  flagImageAsFailed: () => void;
1437
- flagImageLoaded: () => void;
1438
- }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes< {
1456
+ flagImageLoaded: (event: Event) => void;
1457
+ }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ("imageLoaded" | "imageError")[], "imageLoaded" | "imageError", PublicProps, Readonly<ExtractPropTypes< {
1439
1458
  result: {
1440
1459
  type: PropType<Result>;
1441
1460
  required: true;
@@ -1451,9 +1470,23 @@ showNextImageOnHover: {
1451
1470
  type: BooleanConstructor;
1452
1471
  default: boolean;
1453
1472
  };
1454
- }>> & Readonly<{}>, {
1473
+ srcset: {
1474
+ type: PropType<string | (string | undefined)[]>;
1475
+ };
1476
+ sizes: {
1477
+ type: StringConstructor;
1478
+ };
1479
+ loading: {
1480
+ type: PropType<"lazy" | "eager">;
1481
+ default: string;
1482
+ };
1483
+ }>> & Readonly<{
1484
+ onImageLoaded?: ((...args: any[]) => any) | undefined;
1485
+ onImageError?: ((...args: any[]) => any) | undefined;
1486
+ }>, {
1455
1487
  loadAnimation: string | Function | Record<string, any>;
1456
1488
  showNextImageOnHover: boolean;
1489
+ loading: "lazy" | "eager";
1457
1490
  }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
1458
1491
 
1459
1492
  // @public
@@ -10767,6 +10800,7 @@ export type XStoreModuleOptions<StoreModule extends AnyXStoreModule> = StoreModu
10767
10800
  // dist/types/src/components/filters/labels/base-price-filter-label.vue.d.ts:13:13 - (ae-forgotten-export) The symbol "RangeValue" needs to be exported by the entry point index.d.ts
10768
10801
  // dist/types/src/components/filters/labels/base-rating-filter-label.vue.d.ts:16:9 - (ae-forgotten-export) The symbol "BooleanFilter" needs to be exported by the entry point index.d.ts
10769
10802
  // dist/types/src/components/page-selector.vue.d.ts:71:5 - (ae-forgotten-export) The symbol "PageItem" needs to be exported by the entry point index.d.ts
10803
+ // dist/types/src/components/result/base-result-image.vue.d.ts:96:5 - (ae-forgotten-export) The symbol "ImageEntry" needs to be exported by the entry point index.d.ts
10770
10804
  // dist/types/src/components/sort/sort-list.vue.d.ts:41:5 - (ae-forgotten-export) The symbol "SortListItem" needs to be exported by the entry point index.d.ts
10771
10805
  // dist/types/src/components/sort/sort-picker-list.vue.d.ts:44:5 - (ae-forgotten-export) The symbol "SortPickerItem" needs to be exported by the entry point index.d.ts
10772
10806
  // dist/types/src/components/suggestions/base-suggestion.vue.d.ts:31:9 - (ae-forgotten-export) The symbol "Suggestion" needs to be exported by the entry point index.d.ts
@@ -1,8 +1,27 @@
1
1
  import type { Result } from '@empathyco/x-types';
2
- import type { PropType, Ref } from 'vue';
2
+ import type { PropType, Ref, StyleValue } from 'vue';
3
+ /**
4
+ * An entry of the images queue: the image `src` and its optional `srcset`.
5
+ *
6
+ * @internal
7
+ */
8
+ interface ImageEntry {
9
+ /** Index of the image inside `result.images`. */
10
+ index: number;
11
+ /** The image URL. */
12
+ src: string;
13
+ /** Responsive candidates for the image, if provided. */
14
+ srcset?: string;
15
+ }
3
16
  /**
4
17
  * Component to be reused that renders an `<img>`.
5
18
  *
19
+ * Additional `<img>` attributes passed to the component (e.g. `decoding`, `crossorigin`,
20
+ * `referrerpolicy`, `fetchpriority`, `width` and `height`) are forwarded to the rendered
21
+ * images, while `class`, `style` and event listeners keep falling through to the root
22
+ * element, as before. Use the `imageLoaded` and `imageError` events to observe the image
23
+ * loading state.
24
+ *
6
25
  * @public
7
26
  */
8
27
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
@@ -32,18 +51,60 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
32
51
  type: BooleanConstructor;
33
52
  default: boolean;
34
53
  };
54
+ /**
55
+ * Responsive image candidates (`srcset`).
56
+ *
57
+ * - A single string is applied to every image of the result (e.g.
58
+ * `"image-480.jpg 480w, image-1024.jpg 1024w"`).
59
+ * - An array is parallel to `result.images`, so each image can have its own candidates.
60
+ *
61
+ * When provided, the `src` is kept as a fallback for browsers without `srcset` support.
62
+ *
63
+ * @public
64
+ */
65
+ srcset: {
66
+ type: PropType<string | (string | undefined)[]>;
67
+ };
68
+ /**
69
+ * The sizes of the image for different page layouts (`sizes`).
70
+ *
71
+ * It is shared by all the images of the result, since it depends on the layout and not on
72
+ * the image. Pass it together with `srcset`, since it is ignored otherwise.
73
+ *
74
+ * @public
75
+ */
76
+ sizes: {
77
+ type: StringConstructor;
78
+ };
79
+ /**
80
+ * Image loading mode.
81
+ *
82
+ * @public
83
+ */
84
+ loading: {
85
+ type: PropType<"lazy" | "eager">;
86
+ default: string;
87
+ };
35
88
  }>, {
36
- pendingImages: Ref<string[], string[]>;
37
- loadedImages: Ref<string[], string[]>;
89
+ imageAttrs: import("vue").ComputedRef<{
90
+ [k: string]: unknown;
91
+ }>;
92
+ rootAttrs: import("vue").ComputedRef<{
93
+ class: import("vue").ClassValue;
94
+ style: StyleValue;
95
+ }>;
96
+ pendingImages: Ref<ImageEntry[], ImageEntry[]>;
97
+ loadedImages: Ref<ImageEntry[], ImageEntry[]>;
38
98
  isHovering: Ref<boolean, boolean>;
39
99
  userHasHoveredImage: Ref<boolean, boolean>;
40
100
  loaderStyles: import("vue").CSSProperties;
41
101
  animation: import("vue").ComputedRef<string | Function | Record<string, any>>;
42
102
  imageSrc: import("vue").ComputedRef<string>;
103
+ imageSrcset: import("vue").ComputedRef<string | undefined>;
43
104
  shouldLoadNextImage: import("vue").ComputedRef<boolean>;
44
105
  flagImageAsFailed: () => void;
45
- flagImageLoaded: () => void;
46
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
106
+ flagImageLoaded: (event: Event) => void;
107
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("imageLoaded" | "imageError")[], "imageLoaded" | "imageError", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
47
108
  /** (Required) The {@link @empathyco/x-types#Result} information. */
48
109
  result: {
49
110
  type: PropType<Result>;
@@ -70,9 +131,47 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
70
131
  type: BooleanConstructor;
71
132
  default: boolean;
72
133
  };
73
- }>> & Readonly<{}>, {
134
+ /**
135
+ * Responsive image candidates (`srcset`).
136
+ *
137
+ * - A single string is applied to every image of the result (e.g.
138
+ * `"image-480.jpg 480w, image-1024.jpg 1024w"`).
139
+ * - An array is parallel to `result.images`, so each image can have its own candidates.
140
+ *
141
+ * When provided, the `src` is kept as a fallback for browsers without `srcset` support.
142
+ *
143
+ * @public
144
+ */
145
+ srcset: {
146
+ type: PropType<string | (string | undefined)[]>;
147
+ };
148
+ /**
149
+ * The sizes of the image for different page layouts (`sizes`).
150
+ *
151
+ * It is shared by all the images of the result, since it depends on the layout and not on
152
+ * the image. Pass it together with `srcset`, since it is ignored otherwise.
153
+ *
154
+ * @public
155
+ */
156
+ sizes: {
157
+ type: StringConstructor;
158
+ };
159
+ /**
160
+ * Image loading mode.
161
+ *
162
+ * @public
163
+ */
164
+ loading: {
165
+ type: PropType<"lazy" | "eager">;
166
+ default: string;
167
+ };
168
+ }>> & Readonly<{
169
+ onImageLoaded?: ((...args: any[]) => any) | undefined;
170
+ onImageError?: ((...args: any[]) => any) | undefined;
171
+ }>, {
74
172
  loadAnimation: string | Function | Record<string, any>;
75
173
  showNextImageOnHover: boolean;
174
+ loading: "lazy" | "eager";
76
175
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
77
176
  export default _default;
78
177
  //# sourceMappingURL=base-result-image.vue?vue&type=script&lang.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-result-image.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../../src/components/result/base-result-image.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAc,MAAM,KAAK,CAAA;AAKpD;;;;GAIG;;IAIC,oEAAoE;;cAElD,QAAQ,CAAC,MAAM,CAAC;;;IAGlC;;;OAGG;;;;;IAKH,oFAAoF;;;;IAIpF;;;;OAIG;;;;;;;;;;;;;;;;;IArBH,oEAAoE;;cAElD,QAAQ,CAAC,MAAM,CAAC;;;IAGlC;;;OAGG;;;;;IAKH,oFAAoF;;;;IAIpF;;;;OAIG;;;;;;;;;AAxBP,wBAoKE"}
1
+ {"version":3,"file":"base-result-image.vue?vue&type=script&lang.d.ts","sourceRoot":"","sources":["../../../../../src/components/result/base-result-image.vue?vue&type=script&lang.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAMpD;;;;GAIG;AACH,UAAU,UAAU;IAClB,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAA;IACb,qBAAqB;IACrB,GAAG,EAAE,MAAM,CAAA;IACX,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;GAUG;;IAKC,oEAAoE;;cAElD,QAAQ,CAAC,MAAM,CAAC;;;IAGlC;;;OAGG;;;;;IAKH,oFAAoF;;;;IAIpF;;;;OAIG;;;;;IAKH;;;;;;;;;;OAUG;;cAEwB,QAAQ,CAAC,MAAM,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;;IAEpE;;;;;;;OAOG;;;;IAIH;;;;OAIG;;cAEe,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;6BAiMZ,KAAK;;IA1PrC,oEAAoE;;cAElD,QAAQ,CAAC,MAAM,CAAC;;;IAGlC;;;OAGG;;;;;IAKH,oFAAoF;;;;IAIpF;;;;OAIG;;;;;IAKH;;;;;;;;;;OAUG;;cAEwB,QAAQ,CAAC,MAAM,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;;IAEpE;;;;;;;OAOG;;;;IAIH;;;;OAIG;;cAEe,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC;;;;;;;;;;;AA7DhD,wBA6RE"}