@datocms/svelte 1.2.1 → 1.2.2
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/README.md +33 -6
- package/package.json +169 -24
- package/components/Head/Head.svelte +0 -14
- package/components/Head/Head.svelte.d.ts +0 -61
- package/components/Head/README.md +0 -68
- package/components/Head/__tests__/Head.test.d.ts +0 -1
- package/components/Head/__tests__/Head.test.js +0 -11
- package/components/Head/__tests__/__fixtures__/head.d.ts +0 -2
- package/components/Head/__tests__/__fixtures__/head.js +0 -280
- package/components/Head/__tests__/__snapshots__/Head.test.ts.snap +0 -221
- package/components/Image/Image.svelte +0 -172
- package/components/Image/Image.svelte.d.ts +0 -83
- package/components/Image/Placeholder.svelte +0 -30
- package/components/Image/Placeholder.svelte.d.ts +0 -22
- package/components/Image/README.md +0 -167
- package/components/Image/Sizer.svelte +0 -17
- package/components/Image/Sizer.svelte.d.ts +0 -19
- package/components/Image/Source.svelte +0 -6
- package/components/Image/Source.svelte.d.ts +0 -18
- package/components/Image/__tests__/Image.svelte.test.d.ts +0 -1
- package/components/Image/__tests__/Image.svelte.test.js +0 -44
- package/components/Image/__tests__/__fixtures__/image.d.ts +0 -40
- package/components/Image/__tests__/__fixtures__/image.js +0 -40
- package/components/Image/__tests__/__snapshots__/Image.svelte.test.ts.snap +0 -903
- package/components/StructuredText/Node.svelte +0 -112
- package/components/StructuredText/Node.svelte.d.ts +0 -22
- package/components/StructuredText/README.md +0 -201
- package/components/StructuredText/StructuredText.svelte +0 -15
- package/components/StructuredText/StructuredText.svelte.d.ts +0 -19
- package/components/StructuredText/__tests__/StructuredText.svelte.test.d.ts +0 -1
- package/components/StructuredText/__tests__/StructuredText.svelte.test.js +0 -171
- package/components/StructuredText/__tests__/__fixtures__/Block.svelte +0 -11
- package/components/StructuredText/__tests__/__fixtures__/Block.svelte.d.ts +0 -19
- package/components/StructuredText/__tests__/__fixtures__/CustomSpan.svelte +0 -49
- package/components/StructuredText/__tests__/__fixtures__/CustomSpan.svelte.d.ts +0 -19
- package/components/StructuredText/__tests__/__fixtures__/IncreasedLevelHeading.svelte +0 -8
- package/components/StructuredText/__tests__/__fixtures__/IncreasedLevelHeading.svelte.d.ts +0 -19
- package/components/StructuredText/__tests__/__fixtures__/InlineItem.svelte +0 -8
- package/components/StructuredText/__tests__/__fixtures__/InlineItem.svelte.d.ts +0 -19
- package/components/StructuredText/__tests__/__fixtures__/ItemLink.svelte +0 -15
- package/components/StructuredText/__tests__/__fixtures__/ItemLink.svelte.d.ts +0 -21
- package/components/StructuredText/__tests__/__fixtures__/structuredText.d.ts +0 -7
- package/components/StructuredText/__tests__/__fixtures__/structuredText.js +0 -575
- package/components/StructuredText/__tests__/__fixtures__/types.d.ts +0 -27
- package/components/StructuredText/__tests__/__fixtures__/types.js +0 -1
- package/components/StructuredText/__tests__/__snapshots__/StructuredText.svelte.test.ts.snap +0 -531
- package/components/StructuredText/nodes/Blockquote.svelte +0 -5
- package/components/StructuredText/nodes/Blockquote.svelte.d.ts +0 -19
- package/components/StructuredText/nodes/Code.svelte +0 -6
- package/components/StructuredText/nodes/Code.svelte.d.ts +0 -17
- package/components/StructuredText/nodes/Heading.svelte +0 -8
- package/components/StructuredText/nodes/Heading.svelte.d.ts +0 -19
- package/components/StructuredText/nodes/Link.svelte +0 -20
- package/components/StructuredText/nodes/Link.svelte.d.ts +0 -19
- package/components/StructuredText/nodes/List.svelte +0 -10
- package/components/StructuredText/nodes/List.svelte.d.ts +0 -19
- package/components/StructuredText/nodes/ListItem.svelte +0 -5
- package/components/StructuredText/nodes/ListItem.svelte.d.ts +0 -19
- package/components/StructuredText/nodes/Paragraph.svelte +0 -5
- package/components/StructuredText/nodes/Paragraph.svelte.d.ts +0 -19
- package/components/StructuredText/nodes/Root.svelte +0 -5
- package/components/StructuredText/nodes/Root.svelte.d.ts +0 -19
- package/components/StructuredText/nodes/Span.svelte +0 -49
- package/components/StructuredText/nodes/Span.svelte.d.ts +0 -19
- package/components/StructuredText/nodes/ThematicBreak.svelte +0 -5
- package/components/StructuredText/nodes/ThematicBreak.svelte.d.ts +0 -17
- package/components/StructuredText/utils/Lines.svelte +0 -11
- package/components/StructuredText/utils/Lines.svelte.d.ts +0 -16
- package/index.d.ts +0 -9
- package/index.js +0 -3
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
export type Maybe<T> = T | null;
|
|
3
|
-
export type ResponsiveImageType = {
|
|
4
|
-
/** A base64-encoded thumbnail to offer during image loading */
|
|
5
|
-
base64?: Maybe<string>;
|
|
6
|
-
/** The height of the image */
|
|
7
|
-
height?: Maybe<number>;
|
|
8
|
-
/** The width of the image */
|
|
9
|
-
width?: number;
|
|
10
|
-
/** The aspect ratio (width/height) of the image */
|
|
11
|
-
aspectRatio?: number;
|
|
12
|
-
/** The HTML5 `sizes` attribute for the image */
|
|
13
|
-
sizes?: Maybe<string>;
|
|
14
|
-
/** The fallback `src` attribute for the image */
|
|
15
|
-
src?: Maybe<string>;
|
|
16
|
-
/** The HTML5 `srcSet` attribute for the image */
|
|
17
|
-
srcSet?: Maybe<string>;
|
|
18
|
-
/** The HTML5 `srcSet` attribute for the image in WebP format, for browsers that support the format */
|
|
19
|
-
webpSrcSet?: Maybe<string>;
|
|
20
|
-
/** The background color for the image placeholder */
|
|
21
|
-
bgColor?: Maybe<string>;
|
|
22
|
-
/** Alternate text (`alt`) for the image */
|
|
23
|
-
alt?: Maybe<string>;
|
|
24
|
-
/** Title attribute (`title`) for the image */
|
|
25
|
-
title?: Maybe<string>;
|
|
26
|
-
};
|
|
27
|
-
import type * as CSS from 'csstype';
|
|
28
|
-
declare const __propDef: {
|
|
29
|
-
props: {
|
|
30
|
-
alt?: string | null | undefined;
|
|
31
|
-
/** The actual response you get from a DatoCMS `responsiveImage` GraphQL query */ data: ResponsiveImageType;
|
|
32
|
-
/** Additional CSS className for root node */ class?: string | null | undefined;
|
|
33
|
-
/** Additional CSS class for the image inside the `<picture />` tag */ pictureClass?: string | null | undefined;
|
|
34
|
-
/** Duration (in ms) of the fade-in transition effect upoad image loading */ fadeInDuration?: number | undefined;
|
|
35
|
-
/** Indicate at what percentage of the placeholder visibility the loading of the image should be triggered. A value of 0 means that as soon as even one pixel is visible, the callback will be run. A value of 1.0 means that the threshold isn't considered passed until every pixel is visible */ intersectionThreshold?: number | undefined;
|
|
36
|
-
/** Margin around the placeholder. Can have values similar to the CSS margin property (top, right, bottom, left). The values can be percentages. This set of values serves to grow or shrink each side of the placeholder element's bounding box before computing intersections */ intersectionMargin?: string | undefined;
|
|
37
|
-
/** Whether enable lazy loading or not */ lazyLoad?: boolean | undefined;
|
|
38
|
-
/** Additional CSS rules to add to the root node */ style?: Record<string, string> | undefined;
|
|
39
|
-
/** Additional CSS rules to add to the image inside the `<picture />` tag */ pictureStyle?: string | null | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* The layout behavior of the image as the viewport changes size
|
|
42
|
-
*
|
|
43
|
-
* Possible values:
|
|
44
|
-
*
|
|
45
|
-
* * `intrinsic` (default): the image will scale the dimensions down for smaller viewports, but maintain the original dimensions for larger viewports
|
|
46
|
-
* * `fixed`: the image dimensions will not change as the viewport changes (no responsiveness) similar to the native img element
|
|
47
|
-
* * `responsive`: the image will scale the dimensions down for smaller viewports and scale up for larger viewports
|
|
48
|
-
* * `fill`: image will stretch both width and height to the dimensions of the parent element, provided the parent element is `relative`
|
|
49
|
-
**/ layout?: "fill" | "intrinsic" | "fixed" | "responsive" | undefined;
|
|
50
|
-
/** Defines how the image will fit into its parent container when using layout="fill" */ objectFit?: CSS.Properties['objectFit'];
|
|
51
|
-
/** Defines how the image is positioned within its parent element when using layout="fill". */ objectPosition?: CSS.Properties['objectPosition'];
|
|
52
|
-
/** Whether the component should use a blurred image placeholder */ usePlaceholder?: boolean | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* The HTML5 `sizes` attribute for the image
|
|
55
|
-
*
|
|
56
|
-
* Learn more about srcset and sizes:
|
|
57
|
-
* -> https://web.dev/learn/design/responsive-images/#sizes
|
|
58
|
-
* -> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-sizes
|
|
59
|
-
**/ sizes?: string | null | undefined;
|
|
60
|
-
/**
|
|
61
|
-
* When true, the image will be considered high priority. Lazy loading is automatically disabled, and fetchpriority="high" is added to the image.
|
|
62
|
-
* You should use the priority property on any image detected as the Largest Contentful Paint (LCP) element. It may be appropriate to have multiple priority images, as different images may be the LCP element for different viewport sizes.
|
|
63
|
-
* Should only be used when the image is visible above the fold.
|
|
64
|
-
**/ priority?: boolean | undefined;
|
|
65
|
-
/**
|
|
66
|
-
* If `data` does not contain `srcSet`, the candidates for the `srcset` of the image will be auto-generated based on these width multipliers
|
|
67
|
-
*
|
|
68
|
-
* Default candidate multipliers are [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4]
|
|
69
|
-
**/ srcSetCandidates?: number[] | undefined;
|
|
70
|
-
};
|
|
71
|
-
events: {
|
|
72
|
-
load: CustomEvent<any>;
|
|
73
|
-
} & {
|
|
74
|
-
[evt: string]: CustomEvent<any>;
|
|
75
|
-
};
|
|
76
|
-
slots: {};
|
|
77
|
-
};
|
|
78
|
-
export type ImageProps = typeof __propDef.props;
|
|
79
|
-
export type ImageEvents = typeof __propDef.events;
|
|
80
|
-
export type ImageSlots = typeof __propDef.slots;
|
|
81
|
-
export default class Image extends SvelteComponentTyped<ImageProps, ImageEvents, ImageSlots> {
|
|
82
|
-
}
|
|
83
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<script>export let base64 = null;
|
|
2
|
-
export let backgroundColor = null;
|
|
3
|
-
export let objectFit;
|
|
4
|
-
export let objectPosition;
|
|
5
|
-
export let showImage;
|
|
6
|
-
export let fadeInDuration = 0;
|
|
7
|
-
let transition = fadeInDuration > 0 ? `opacity ${fadeInDuration}ms` : void 0;
|
|
8
|
-
let opacity = showImage ? 0 : 1;
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<img
|
|
12
|
-
class="placeholder"
|
|
13
|
-
aria-hidden="true"
|
|
14
|
-
alt=""
|
|
15
|
-
src={base64}
|
|
16
|
-
style:backgroundColor
|
|
17
|
-
style:objectFit
|
|
18
|
-
style:objectPosition
|
|
19
|
-
style:transition
|
|
20
|
-
style:opacity
|
|
21
|
-
/>
|
|
22
|
-
|
|
23
|
-
<style>
|
|
24
|
-
.placeholder {
|
|
25
|
-
position: absolute;
|
|
26
|
-
width: 100%;
|
|
27
|
-
top: 0;
|
|
28
|
-
scale: 110%;
|
|
29
|
-
}
|
|
30
|
-
</style>
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type * as CSS from 'csstype';
|
|
3
|
-
declare const __propDef: {
|
|
4
|
-
props: {
|
|
5
|
-
base64?: string | null | undefined;
|
|
6
|
-
backgroundColor?: string | null | undefined;
|
|
7
|
-
objectFit: CSS.Properties['objectFit'];
|
|
8
|
-
objectPosition: CSS.Properties['objectPosition'];
|
|
9
|
-
showImage: boolean;
|
|
10
|
-
fadeInDuration?: number | undefined;
|
|
11
|
-
};
|
|
12
|
-
events: {
|
|
13
|
-
[evt: string]: CustomEvent<any>;
|
|
14
|
-
};
|
|
15
|
-
slots: {};
|
|
16
|
-
};
|
|
17
|
-
export type PlaceholderProps = typeof __propDef.props;
|
|
18
|
-
export type PlaceholderEvents = typeof __propDef.events;
|
|
19
|
-
export type PlaceholderSlots = typeof __propDef.slots;
|
|
20
|
-
export default class Placeholder extends SvelteComponentTyped<PlaceholderProps, PlaceholderEvents, PlaceholderSlots> {
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
## Progressive responsive image
|
|
2
|
-
|
|
3
|
-
`<Image>` is a Svelte component specially designed to work seamlessly with DatoCMS’s [`responsiveImage` GraphQL query](https://www.datocms.com/docs/content-delivery-api/uploads#responsive-images) that optimizes image loading for your sites.
|
|
4
|
-
|
|
5
|
-
### Table of contents
|
|
6
|
-
|
|
7
|
-
- [Out-of-the-box features](#out-of-the-box-features)
|
|
8
|
-
- [Setup](#setup)
|
|
9
|
-
- [Usage](#usage)
|
|
10
|
-
- [Example](#example)
|
|
11
|
-
- [Props](#props)
|
|
12
|
-
- [Layout mode](#layout-mode)
|
|
13
|
-
- [The `ResponsiveImage` object](#the-responsiveimage-object)
|
|
14
|
-
|
|
15
|
-
### Out-of-the-box features
|
|
16
|
-
|
|
17
|
-
- Offers optimized version of images for browsers that support WebP/AVIF format
|
|
18
|
-
- Generates multiple smaller images so smartphones and tablets don’t download desktop-sized images
|
|
19
|
-
- Efficiently lazy loads images to speed initial page load and save bandwidth
|
|
20
|
-
- Holds the image position so your page doesn’t jump while images load
|
|
21
|
-
- Uses either blur-up or background color techniques to show a preview of the image while it loads
|
|
22
|
-
|
|
23
|
-
## Intersection Observer
|
|
24
|
-
|
|
25
|
-
Intersection Observer is the API used to determine if the image is inside the viewport or not. [Browser support is really good](https://caniuse.com/intersectionobserver) - With Safari adding support in 12.1, all major browsers now support Intersection Observers natively.
|
|
26
|
-
|
|
27
|
-
If the IntersectionObserver object is not available, the component treats the image as it's always visible in the viewport. Feel free to add a [polyfill](https://www.npmjs.com/package/intersection-observer) so that it will also 100% work on older versions of iOS and IE11.
|
|
28
|
-
|
|
29
|
-
### Setup
|
|
30
|
-
|
|
31
|
-
You can import the components like this:
|
|
32
|
-
|
|
33
|
-
```js
|
|
34
|
-
import { Image } from '@datocms/svelte';
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Usage
|
|
38
|
-
|
|
39
|
-
1. Use `<Image>` it in place of the regular `<img />` tag
|
|
40
|
-
2. Write a GraphQL query to your DatoCMS project using the [`responsiveImage` query](https://www.datocms.com/docs/content-delivery-api/images-and-videos#responsive-images)
|
|
41
|
-
|
|
42
|
-
The GraphQL query returns multiple thumbnails with optimized compression. The `<Image>` component automatically sets up the "blur-up" effect as well as lazy loading of images further down the screen.
|
|
43
|
-
|
|
44
|
-
### Example
|
|
45
|
-
|
|
46
|
-
For a fully working example take a look at [`routes` directory](https://github.com/datocms/datocms-svelte/tree/main/src/routes/image/+page.svelte).
|
|
47
|
-
|
|
48
|
-
Here is a minimal starting point:
|
|
49
|
-
|
|
50
|
-
```svelte
|
|
51
|
-
<script>
|
|
52
|
-
|
|
53
|
-
import { onMount } from 'svelte';
|
|
54
|
-
|
|
55
|
-
import { Image } from '@datocms/svelte';
|
|
56
|
-
|
|
57
|
-
const query = gql`
|
|
58
|
-
query {
|
|
59
|
-
blogPost {
|
|
60
|
-
title
|
|
61
|
-
cover {
|
|
62
|
-
responsiveImage(
|
|
63
|
-
imgixParams: { fit: crop, w: 300, h: 300, auto: format }
|
|
64
|
-
) {
|
|
65
|
-
# always required
|
|
66
|
-
src
|
|
67
|
-
width
|
|
68
|
-
height
|
|
69
|
-
# not required, but strongly suggested!
|
|
70
|
-
alt
|
|
71
|
-
title
|
|
72
|
-
# blur-up placeholder, JPEG format, base64-encoded, or...
|
|
73
|
-
base64
|
|
74
|
-
# background color placeholder
|
|
75
|
-
bgColor
|
|
76
|
-
# you can omit `sizes` if you explicitly pass the `sizes` prop to the image component
|
|
77
|
-
sizes
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
`;
|
|
83
|
-
|
|
84
|
-
export let data = null;
|
|
85
|
-
|
|
86
|
-
onMount(async () => {
|
|
87
|
-
const response = await fetch('https://graphql.datocms.com/', {
|
|
88
|
-
method: 'POST',
|
|
89
|
-
headers: {
|
|
90
|
-
'Content-Type': 'application/json',
|
|
91
|
-
Authorization: "Bearer faeb9172e232a75339242faafb9e56de8c8f13b735f7090964",
|
|
92
|
-
},
|
|
93
|
-
body: JSON.stringify({ query })
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
const json = await response.json()
|
|
97
|
-
|
|
98
|
-
data = json.data;
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
</script>
|
|
102
|
-
|
|
103
|
-
{#if data}
|
|
104
|
-
<Image data={data.blogPost.cover.responsiveImage} />
|
|
105
|
-
{/if}
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### Props
|
|
109
|
-
|
|
110
|
-
| prop | type | default | required | description |
|
|
111
|
-
| --------------------- | ------------------------------------------------ | ----------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
112
|
-
| data | `ResponsiveImage` object | | :white_check_mark: | The actual response you get from a DatoCMS `responsiveImage` GraphQL query. |
|
|
113
|
-
| class | string | null | :x: | Additional CSS class of root node |
|
|
114
|
-
| style | CSS properties | null | :x: | Additional CSS rules to add to the root node |
|
|
115
|
-
| pictureClass | string | null | :x: | Additional CSS class for the inner `<picture />` tag |
|
|
116
|
-
| pictureStyle | CSS properties | null | :x: | Additional CSS rules to add to the inner `<picture />` tag |
|
|
117
|
-
| layout | 'intrinsic' \| 'fixed' \| 'responsive' \| 'fill' | "intrinsic" | :x: | The layout behavior of the image as the viewport changes size |
|
|
118
|
-
| fadeInDuration | integer | 500 | :x: | Duration (in ms) of the fade-in transition effect upoad image loading |
|
|
119
|
-
| intersectionThreshold | float | 0 | :x: | Indicate at what percentage of the placeholder visibility the loading of the image should be triggered. A value of 0 means that as soon as even one pixel is visible, the callback will be run. A value of 1.0 means that the threshold isn't considered passed until every pixel is visible. |
|
|
120
|
-
| intersectionMargin | string | "0px 0px 0px 0px" | :x: | Margin around the placeholder. Can have values similar to the CSS margin property (top, right, bottom, left). The values can be percentages. This set of values serves to grow or shrink each side of the placeholder element's bounding box before computing intersections. |
|
|
121
|
-
| lazyLoad | Boolean | true | :x: | Wheter enable lazy loading or not |
|
|
122
|
-
| explicitWidth | Boolean | false | :x: | Wheter the image wrapper should explicitely declare the width of the image or keep it fluid |
|
|
123
|
-
| objectFit | String | null | :x: | Defines how the image will fit into its parent container when using layout="fill" |
|
|
124
|
-
| objectPosition | String | null | :x: | Defines how the image is positioned within its parent element when using layout="fill". |
|
|
125
|
-
| priority | Boolean | false | :x: | Disables lazy loading, and sets the image [fetchPriority](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/fetchPriority) to "high" |
|
|
126
|
-
| srcSetCandidates | Array<number> | [0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4] | :x: | If `data` does not contain `srcSet`, the candidates for the `srcset` attribute of the image will be auto-generated based on these width multipliers |
|
|
127
|
-
| sizes | string | undefined | :x: | The HTML5 [`sizes`](https://web.dev/learn/design/responsive-images/#sizes) attribute for the image (will be used `data.sizes` as a fallback) |
|
|
128
|
-
| onLoad | () => void | undefined | :x: | Function triggered when the image has finished loading |
|
|
129
|
-
| usePlaceholder | Boolean | true | :x: | Whether the component should use a blurred image placeholder |
|
|
130
|
-
|
|
131
|
-
#### Layout mode
|
|
132
|
-
|
|
133
|
-
With the `layout` property, you can configure the behavior of the image as the viewport changes size:
|
|
134
|
-
|
|
135
|
-
- When `intrinsic`, the image will scale the dimensions down for smaller viewports, but maintain the original dimensions for larger viewports.
|
|
136
|
-
- When `fixed`, the image dimensions will not change as the viewport changes (no responsiveness) similar to the native `img` element.
|
|
137
|
-
- When `responsive` (default behaviour), the image will scale the dimensions down for smaller viewports and scale up for larger viewports.
|
|
138
|
-
- When `fill`, the image will stretch both width and height to the dimensions of the parent element, provided the parent element is relative.
|
|
139
|
-
- This is usually paired with the `objectFit` and `objectPosition` properties.
|
|
140
|
-
- Ensure the parent element has `position: relative` in their stylesheet.
|
|
141
|
-
|
|
142
|
-
#### The `ResponsiveImage` object
|
|
143
|
-
|
|
144
|
-
The `data` prop expects an object with the same shape as the one returned by `responsiveImage` GraphQL call. It's up to you to make a GraphQL query that will return the properties you need for a specific use of the `<datocms-image>` component.
|
|
145
|
-
|
|
146
|
-
- The minimum required properties for `data` are: `src`, `width` and `height`;
|
|
147
|
-
- `alt` and `title`, while not mandatory, are all highly suggested, so remember to use them!
|
|
148
|
-
- If you don't request `srcSet`, the component will auto-generate an `srcset` based on `src` + the `srcSetCandidates` prop (it can help reducing the GraphQL response size drammatically when many images are returned);
|
|
149
|
-
- We strongly to suggest to always specify [`{ auto: format }`](https://docs.imgix.com/apis/rendering/auto/auto#format) in your `imgixParams`, instead of requesting `webpSrcSet`, so that you can also take advantage of more performant optimizations (AVIF), without increasing GraphQL response size;
|
|
150
|
-
- If you request both the `bgColor` and `base64` property, the latter will take precedence, so just avoid querying both fields at the same time, as it will only make the GraphQL response bigger :wink:;
|
|
151
|
-
- You can avoid requesting `sizes` and directly pass a `sizes` prop to the component to reduce the GraphQL response size;
|
|
152
|
-
|
|
153
|
-
Here's a complete recap of what `responsiveImage` offers:
|
|
154
|
-
|
|
155
|
-
| property | type | required | description |
|
|
156
|
-
| ----------- | ------- | ------------------ | ----------------------------------------------------------------------------------------------- |
|
|
157
|
-
| src | string | :white_check_mark: | The `src` attribute for the image |
|
|
158
|
-
| width | integer | :white_check_mark: | The width of the image |
|
|
159
|
-
| height | integer | :white_check_mark: | The height of the image |
|
|
160
|
-
| alt | string | :x: | Alternate text (`alt`) for the image (not required, but strongly suggested!) |
|
|
161
|
-
| title | string | :x: | Title attribute (`title`) for the image (not required, but strongly suggested!) |
|
|
162
|
-
| sizes | string | :x: | The HTML5 `sizes` attribute for the image (omit it if you're already passing a `sizes` prop to the Image component) |
|
|
163
|
-
| base64 | string | :x: | A base64-encoded thumbnail to offer during image loading |
|
|
164
|
-
| bgColor | string | :x: | The background color for the image placeholder (omit it if you're already requesting `base64`) |
|
|
165
|
-
| srcSet | string | :x: | The HTML5 `srcSet` attribute for the image (can be omitted, the Image component knows how to build it based on `src`) |
|
|
166
|
-
| webpSrcSet | string | :x: | The HTML5 `srcSet` attribute for the image in WebP format (deprecated, it's better to use the [`auto=format`](https://docs.imgix.com/apis/rendering/auto/auto#format) Imgix transform instead) |
|
|
167
|
-
| aspectRatio | float | :x: | The aspect ratio (width/height) of the image |
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<script>import { encode } from "universal-base64";
|
|
2
|
-
let klass = null;
|
|
3
|
-
export { klass as class };
|
|
4
|
-
export let width;
|
|
5
|
-
export let height;
|
|
6
|
-
export let aspectRatio;
|
|
7
|
-
let svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height ?? (aspectRatio ? width / aspectRatio : 0)}"></svg>`;
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<img
|
|
11
|
-
class={klass}
|
|
12
|
-
style:display="block"
|
|
13
|
-
style:width="100%"
|
|
14
|
-
src="data:image/svg+xml;base64,{encode(svg)}"
|
|
15
|
-
aria-hidden="true"
|
|
16
|
-
alt=""
|
|
17
|
-
/>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: {
|
|
4
|
-
class?: string | null | undefined;
|
|
5
|
-
width: number;
|
|
6
|
-
height: number | null | undefined;
|
|
7
|
-
aspectRatio: number | undefined;
|
|
8
|
-
};
|
|
9
|
-
events: {
|
|
10
|
-
[evt: string]: CustomEvent<any>;
|
|
11
|
-
};
|
|
12
|
-
slots: {};
|
|
13
|
-
};
|
|
14
|
-
export type SizerProps = typeof __propDef.props;
|
|
15
|
-
export type SizerEvents = typeof __propDef.events;
|
|
16
|
-
export type SizerSlots = typeof __propDef.slots;
|
|
17
|
-
export default class Sizer extends SvelteComponentTyped<SizerProps, SizerEvents, SizerSlots> {
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: {
|
|
4
|
-
srcset: string | null;
|
|
5
|
-
sizes: string | null;
|
|
6
|
-
type?: string | null | undefined;
|
|
7
|
-
};
|
|
8
|
-
events: {
|
|
9
|
-
[evt: string]: CustomEvent<any>;
|
|
10
|
-
};
|
|
11
|
-
slots: {};
|
|
12
|
-
};
|
|
13
|
-
export type SourceProps = typeof __propDef.props;
|
|
14
|
-
export type SourceEvents = typeof __propDef.events;
|
|
15
|
-
export type SourceSlots = typeof __propDef.slots;
|
|
16
|
-
export default class Source extends SvelteComponentTyped<SourceProps, SourceEvents, SourceSlots> {
|
|
17
|
-
}
|
|
18
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import '@testing-library/jest-dom';
|
|
3
|
-
import { act, fireEvent, render, screen } from '@testing-library/svelte';
|
|
4
|
-
import { mockIntersectionObserver } from 'jsdom-testing-mocks';
|
|
5
|
-
import { completeData, minimalData, minimalDataWithRelativeUrl } from './__fixtures__/image';
|
|
6
|
-
import { Image } from '../../..';
|
|
7
|
-
const io = mockIntersectionObserver();
|
|
8
|
-
describe('Image', () => {
|
|
9
|
-
['intrinsic', 'fixed', 'responsive', 'fill'].forEach((layout) => {
|
|
10
|
-
Object.entries({ completeData, minimalData, minimalDataWithRelativeUrl }).forEach(([name, data]) => {
|
|
11
|
-
describe(`layout=${layout}`, () => {
|
|
12
|
-
describe(`data=${name}`, () => {
|
|
13
|
-
describe("when the component doesn't intersect the viewport", () => {
|
|
14
|
-
it('only renders the placeholder elements ', () => {
|
|
15
|
-
const onLoad = vi.fn();
|
|
16
|
-
const { container, component } = render(Image, { props: { data, layout } });
|
|
17
|
-
component.$on('load', onLoad);
|
|
18
|
-
const picture = screen.queryByTestId('picture');
|
|
19
|
-
expect(picture).not.toBeInTheDocument();
|
|
20
|
-
expect(onLoad).not.toHaveBeenCalled();
|
|
21
|
-
expect(container).toMatchSnapshot();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
describe('when the component intersects the viewport', () => {
|
|
25
|
-
it('shows the image ', async () => {
|
|
26
|
-
const onLoad = vi.fn();
|
|
27
|
-
const { container, component } = render(Image, { props: { data, layout } });
|
|
28
|
-
component.$on('load', onLoad);
|
|
29
|
-
await act(async () => {
|
|
30
|
-
io.enterNode(await screen.findByTestId('image'));
|
|
31
|
-
});
|
|
32
|
-
const picture = screen.getByTestId('picture');
|
|
33
|
-
const img = screen.getByTestId('img');
|
|
34
|
-
fireEvent.load(img);
|
|
35
|
-
expect(picture).toBeInTheDocument();
|
|
36
|
-
expect(onLoad).toHaveBeenCalled();
|
|
37
|
-
expect(container).toMatchSnapshot();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export declare const completeData: {
|
|
2
|
-
alt: string;
|
|
3
|
-
aspectRatio: number;
|
|
4
|
-
base64: string;
|
|
5
|
-
height: number;
|
|
6
|
-
sizes: string;
|
|
7
|
-
src: string;
|
|
8
|
-
srcSet: string;
|
|
9
|
-
title: string;
|
|
10
|
-
width: number;
|
|
11
|
-
};
|
|
12
|
-
export declare const minimalData: {
|
|
13
|
-
base64: string;
|
|
14
|
-
height: number;
|
|
15
|
-
src: string;
|
|
16
|
-
width: number;
|
|
17
|
-
};
|
|
18
|
-
export declare const minimalDataWithRelativeUrl: {
|
|
19
|
-
base64: string;
|
|
20
|
-
height: number;
|
|
21
|
-
src: string;
|
|
22
|
-
width: number;
|
|
23
|
-
};
|
|
24
|
-
export declare const completeData2: {
|
|
25
|
-
alt: null;
|
|
26
|
-
base64: string;
|
|
27
|
-
aspectRatio: number;
|
|
28
|
-
height: number;
|
|
29
|
-
sizes: string;
|
|
30
|
-
src: string;
|
|
31
|
-
srcSet: string;
|
|
32
|
-
title: null;
|
|
33
|
-
width: number;
|
|
34
|
-
};
|
|
35
|
-
export declare const minimalData2: {
|
|
36
|
-
base64: string;
|
|
37
|
-
height: number;
|
|
38
|
-
src: string;
|
|
39
|
-
width: number;
|
|
40
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export const completeData = {
|
|
2
|
-
alt: 'DatoCMS swag',
|
|
3
|
-
aspectRatio: 1.7777777777777777,
|
|
4
|
-
base64: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHBwgHBgoICAgLFQoLDhgQDg0NDh0eHREYIx8lJCIrHB0dLSs7GikyKSEuKjUlKDk1MjIyHyo4PTc+PDcxPjUBCgsLDg0OHBAQHDsoIig7Ozs7Ozs7OzsvOzs7Ozs7Ozs7Lzs7Ozs7Ozs7OzsvOzs7NTsvLy87NTU1Ly8vLzsvL//AABEIAA0AGAMBIgACEQEDEQH/xAAYAAACAwAAAAAAAAAAAAAAAAAGBwABBP/EACEQAAEEAAYDAAAAAAAAAAAAAAEAAgMEBQYHESEiFWFx/8QAFQEBAQAAAAAAAAAAAAAAAAAAAwL/xAAZEQADAAMAAAAAAAAAAAAAAAAAAQIRITH/2gAMAwEAAhEDEQA/AFxLgDWTsAd1J5TGy7hEYqNAaNgECX7sjLMQAHJTEy1Zcarfia4lJMauAxqBhLY6ZlaOzDurWvUOd3jZPfCiEh4xs//Z',
|
|
5
|
-
height: 421,
|
|
6
|
-
sizes: '(max-width: 750px) 100vw, 750px',
|
|
7
|
-
src: 'https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750',
|
|
8
|
-
srcSet: 'https://www.datocms-assets.com/205/image.png?ar=16%3A9&dpr=0.25&fit=crop&w=750 187w,↵https://www.datocms-assets.com/205/image.png?ar=16%3A9&dpr=0.5&fit=crop&w=750 375w,↵https://www.datocms-assets.com/205/image.png?ar=16%3A9&dpr=0.75&fit=crop&w=750 562w,↵https://www.datocms-assets.com/205/image.png?ar=16%3A9&dpr=1&fit=crop&w=750 750w,↵https://www.datocms-assets.com/205/image.png?ar=16%3A9&dpr=1.5&fit=crop&w=750 1125w,↵https://www.datocms-assets.com/205/image.png?ar=16%3A9&dpr=2&fit=crop&w=750 1500w,↵https://www.datocms-assets.com/205/image.png?ar=16%3A9&dpr=3&fit=crop&w=750 2250w,↵https://www.datocms-assets.com/205/image.png?ar=16%3A9&dpr=4&fit=crop&w=750 3000w',
|
|
9
|
-
title: 'These are awesome, we know that.',
|
|
10
|
-
width: 750
|
|
11
|
-
};
|
|
12
|
-
export const minimalData = {
|
|
13
|
-
base64: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHBwgHBgoICAgLFQoLDhgQDg0NDh0eHREYIx8lJCIrHB0dLSs7GikyKSEuKjUlKDk1MjIyHyo4PTc+PDcxPjUBCgsLDg0OHBAQHDsoIig7Ozs7Ozs7OzsvOzs7Ozs7Ozs7Lzs7Ozs7Ozs7OzsvOzs7NTsvLy87NTU1Ly8vLzsvL//AABEIAA0AGAMBIgACEQEDEQH/xAAYAAACAwAAAAAAAAAAAAAAAAAGBwABBP/EACEQAAEEAAYDAAAAAAAAAAAAAAEAAgMEBQYHESEiFWFx/8QAFQEBAQAAAAAAAAAAAAAAAAAAAwL/xAAZEQADAAMAAAAAAAAAAAAAAAAAAQIRITH/2gAMAwEAAhEDEQA/AFxLgDWTsAd1J5TGy7hEYqNAaNgECX7sjLMQAHJTEy1Zcarfia4lJMauAxqBhLY6ZlaOzDurWvUOd3jZPfCiEh4xs//Z',
|
|
14
|
-
height: 421,
|
|
15
|
-
src: 'https://www.datocms-assets.com/205/image.png?ar=16%3A9&fit=crop&w=750',
|
|
16
|
-
width: 750
|
|
17
|
-
};
|
|
18
|
-
export const minimalDataWithRelativeUrl = {
|
|
19
|
-
base64: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHBwgHBgoICAgLFQoLDhgQDg0NDh0eHREYIx8lJCIrHB0dLSs7GikyKSEuKjUlKDk1MjIyHyo4PTc+PDcxPjUBCgsLDg0OHBAQHDsoIig7Ozs7Ozs7OzsvOzs7Ozs7Ozs7Lzs7Ozs7Ozs7OzsvOzs7NTsvLy87NTU1Ly8vLzsvL//AABEIAA0AGAMBIgACEQEDEQH/xAAYAAACAwAAAAAAAAAAAAAAAAAGBwABBP/EACEQAAEEAAYDAAAAAAAAAAAAAAEAAgMEBQYHESEiFWFx/8QAFQEBAQAAAAAAAAAAAAAAAAAAAwL/xAAZEQADAAMAAAAAAAAAAAAAAAAAAQIRITH/2gAMAwEAAhEDEQA/AFxLgDWTsAd1J5TGy7hEYqNAaNgECX7sjLMQAHJTEy1Zcarfia4lJMauAxqBhLY6ZlaOzDurWvUOd3jZPfCiEh4xs//Z',
|
|
20
|
-
height: 421,
|
|
21
|
-
src: '/205/image.png?ar=16%3A9&fit=crop&w=750',
|
|
22
|
-
width: 750
|
|
23
|
-
};
|
|
24
|
-
export const completeData2 = {
|
|
25
|
-
alt: null,
|
|
26
|
-
base64: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHBwgHBgoIFAgLChEXDg0VDg0NGRUVDREVFxMZHRYVFiEaHysjGh0oHRUWJDUlKC0vMjIyHSI4PTcwPCsxMi8BCgsLDg0OFRAQHC8cIigvLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vL//AABEIABAAGAMBIgACEQEDEQH/xAAYAAACAwAAAAAAAAAAAAAAAAAABQEDBv/EAB0QAAEEAgMAAAAAAAAAAAAAAAQAAQIDETEFEhP/xAAVAQEBAAAAAAAAAAAAAAAAAAACAf/EABoRAAICAwAAAAAAAAAAAAAAAAABAgMSEzH/2gAMAwEAAhEDEQA/AN2QdCbbVNRUYvtJOXukFX2yo4Ilz3zlVzZFTHrHt17WMhBA3lDKEc5C1Vn/2Q==',
|
|
27
|
-
aspectRatio: 1.5,
|
|
28
|
-
height: 3456,
|
|
29
|
-
sizes: '(max-width: 5184px) 100vw, 5184px',
|
|
30
|
-
src: 'https://www.datocms-assets.com/23796/1612503468-jairph-ypl0a8v9qgo-unsplash.jpg',
|
|
31
|
-
srcSet: 'https://www.datocms-assets.com/23796/1612503468-jairph-ypl0a8v9qgo-unsplash.jpg?dpr=0.25 1296w,https://www.datocms-assets.com/23796/1612503468-jairph-ypl0a8v9qgo-unsplash.jpg?dpr=0.5 2592w,https://www.datocms-assets.com/23796/1612503468-jairph-ypl0a8v9qgo-unsplash.jpg?dpr=0.75 3888w,https://www.datocms-assets.com/23796/1612503468-jairph-ypl0a8v9qgo-unsplash.jpg 5184w',
|
|
32
|
-
title: null,
|
|
33
|
-
width: 5184
|
|
34
|
-
};
|
|
35
|
-
export const minimalData2 = {
|
|
36
|
-
base64: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHBwgHBgoICBELERULDg8VDg0NDxUOFhEPFxgrGRYfFiEaHysjJh0oKRcWJDUxKC0vMjIyGSI4PTcwPCsxMi8BCgsLDg0OHBAQHDslIig7Ozs7NTs7Ly81Lzw7Ozs7Ly8vLy8vLy8vLy8vLy8vLy8vLy8vLy81Ly8vLy8vLy8vL//AABEIABgAGAMBIgACEQEDEQH/xAAaAAACAgMAAAAAAAAAAAAAAAAABQEHAwQG/8QAHxAAAgEEAgMAAAAAAAAAAAAAAAEDAgQFEVFxEiFB/8QAFQEBAQAAAAAAAAAAAAAAAAAAAwT/xAAbEQEAAgMBAQAAAAAAAAAAAAABAAIREiETA//aAAwDAQACEQMRAD8Ap1LdQ/sIW4kJKqfCVHT41JwroNztH4kUZdOOjtgbGfibjTXxgKNoCA8ii79NMe4m43Et8EAM1G8mtdr8xJmv0pVokAH1JB6WXM//2Q==',
|
|
37
|
-
height: 1994,
|
|
38
|
-
src: 'https://www.datocms-assets.com/23796/1583844698-gift-habeshaw-pgxxjrtfnjq-unsplash-edited.png',
|
|
39
|
-
width: 1994
|
|
40
|
-
};
|