@jetshop/ui 6.3.8-alpha.33 → 6.3.8
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/ErrorBoundary/Generic.js +4 -0
- package/ErrorBoundary/Generic.js.map +1 -1
- package/Gallery/Gallery.js +1 -1
- package/Gallery/Gallery.js.map +1 -1
- package/Image/useConstructImage.js.map +1 -1
- package/ProductList/GridProduct.js +1 -1
- package/ProductList/GridProduct.js.map +1 -1
- package/package.json +2 -2
- package/CloudflareImage/BaseImage.d.ts +0 -40
- package/CloudflareImage/BaseImage.js +0 -192
- package/CloudflareImage/BaseImage.js.map +0 -1
- package/CloudflareImage/Fallback.d.ts +0 -5
- package/CloudflareImage/Fallback.js +0 -4
- package/CloudflareImage/Fallback.js.map +0 -1
- package/CloudflareImage/FlightImage.d.ts +0 -51
- package/CloudflareImage/FlightImage.js +0 -61
- package/CloudflareImage/FlightImage.js.map +0 -1
- package/CloudflareImage/FlightImage.test.js +0 -277
- package/CloudflareImage/Image.d.ts +0 -2
- package/CloudflareImage/Image.js +0 -3
- package/CloudflareImage/Image.js.map +0 -1
- package/CloudflareImage/index.d.ts +0 -1
- package/CloudflareImage/index.js +0 -2
- package/CloudflareImage/index.js.map +0 -1
- package/CloudflareImage/useConstructImage.d.ts +0 -49
- package/CloudflareImage/useConstructImage.js +0 -122
- package/CloudflareImage/useConstructImage.js.map +0 -1
- package/CloudflareImage/utils/aspectRatioToFraction.d.ts +0 -2
- package/CloudflareImage/utils/aspectRatioToFraction.js +0 -11
- package/CloudflareImage/utils/aspectRatioToFraction.js.map +0 -1
- package/CloudflareImage/utils/getFullUrl.d.ts +0 -6
- package/CloudflareImage/utils/getFullUrl.js +0 -18
- package/CloudflareImage/utils/getFullUrl.js.map +0 -1
- package/CloudflareImage/utils/getImageWidth.d.ts +0 -1
- package/CloudflareImage/utils/getImageWidth.js +0 -12
- package/CloudflareImage/utils/getImageWidth.js.map +0 -1
- package/CloudflareImage/utils/getImageWidths.d.ts +0 -2
- package/CloudflareImage/utils/getImageWidths.js +0 -21
- package/CloudflareImage/utils/getImageWidths.js.map +0 -1
- package/CloudflareImage/utils/getLQIP.d.ts +0 -8
- package/CloudflareImage/utils/getLQIP.js +0 -21
- package/CloudflareImage/utils/getLQIP.js.map +0 -1
- package/CloudflareImage/utils/getLargestSize.d.ts +0 -7
- package/CloudflareImage/utils/getLargestSize.js +0 -17
- package/CloudflareImage/utils/getLargestSize.js.map +0 -1
- package/CloudflareImage/utils/getSizeForBreakpoint.d.ts +0 -2
- package/CloudflareImage/utils/getSizeForBreakpoint.js +0 -16
- package/CloudflareImage/utils/getSizeForBreakpoint.js.map +0 -1
- package/CloudflareImage/utils/getSizesMap.d.ts +0 -2
- package/CloudflareImage/utils/getSizesMap.js +0 -35
- package/CloudflareImage/utils/getSizesMap.js.map +0 -1
- package/CloudflareImage/utils/getSmallestSize.d.ts +0 -2
- package/CloudflareImage/utils/getSmallestSize.js +0 -12
- package/CloudflareImage/utils/getSmallestSize.js.map +0 -1
- package/CloudflareImage/utils/getSrcSetFromWidths.d.ts +0 -10
- package/CloudflareImage/utils/getSrcSetFromWidths.js +0 -10
- package/CloudflareImage/utils/getSrcSetFromWidths.js.map +0 -1
- package/CloudflareImage/utils/getSrcWithParams.d.ts +0 -3
- package/CloudflareImage/utils/getSrcWithParams.js +0 -33
- package/CloudflareImage/utils/getSrcWithParams.js.map +0 -1
- package/CloudflareImage/utils/paddingForAspectRatio.d.ts +0 -1
- package/CloudflareImage/utils/paddingForAspectRatio.js +0 -6
- package/CloudflareImage/utils/paddingForAspectRatio.js.map +0 -1
- package/CloudflareImage/utils/remToPx.d.ts +0 -1
- package/CloudflareImage/utils/remToPx.js +0 -2
- package/CloudflareImage/utils/remToPx.js.map +0 -1
- package/CloudflareImage/utils/sizeToNumber.d.ts +0 -2
- package/CloudflareImage/utils/sizeToNumber.js +0 -27
- package/CloudflareImage/utils/sizeToNumber.js.map +0 -1
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import { ChannelProvider } from '@jetshop/core/components/ChannelContext';
|
|
2
|
-
import t from '@jetshop/intl';
|
|
3
|
-
import testImage from '@jetshop/ui/test-utils/fixtures/test-image.png';
|
|
4
|
-
import { fireEvent, queryByText, render } from '@testing-library/react';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { useInView } from 'react-intersection-observer';
|
|
7
|
-
import Image from './FlightImage';
|
|
8
|
-
import { ChannelHandler } from '@jetshop/core/ChannelHandler/ChannelHandler';
|
|
9
|
-
import { selectedChannel, channels } from '@jetshop/core/test-utils/variables';
|
|
10
|
-
import { ConfigProvider } from '@jetshop/core/components/ConfigProvider';
|
|
11
|
-
import mockShopConfig from '@jetshop/core/test-utils/mockShopConfig';
|
|
12
|
-
|
|
13
|
-
// Mock intersection observer so we can always return true/false
|
|
14
|
-
jest.mock('react-intersection-observer');
|
|
15
|
-
// Suppress warnings from translations
|
|
16
|
-
jest.mock('@jetshop/intl');
|
|
17
|
-
t.mockImplementation((t) => t);
|
|
18
|
-
|
|
19
|
-
// browser mocks
|
|
20
|
-
global.IntersectionObserver = jest.fn(function () {
|
|
21
|
-
this.observe = jest.fn();
|
|
22
|
-
this.unobserve = jest.fn();
|
|
23
|
-
this.disconnect = jest.fn();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const transparent =
|
|
27
|
-
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
|
|
28
|
-
|
|
29
|
-
global.__IN_SERVER__ = false;
|
|
30
|
-
|
|
31
|
-
describe('Hooks image component', () => {
|
|
32
|
-
describe('on initial load', () => {
|
|
33
|
-
beforeAll(() => {
|
|
34
|
-
useInView.mockImplementation(() => [null, false]);
|
|
35
|
-
});
|
|
36
|
-
it('renders a lqip version of the image by default', () => {
|
|
37
|
-
const { placeholderImage } = setup();
|
|
38
|
-
|
|
39
|
-
const src = placeholderImage.getAttribute('src');
|
|
40
|
-
|
|
41
|
-
expect(src).toEqual(expect.stringContaining('sigma=2.5'));
|
|
42
|
-
expect(src).toEqual(expect.stringContaining('minampl=0.5'));
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('sets the lqip to the smallest of the calculated sizes', () => {
|
|
46
|
-
const { placeholderImage } = setup({ sizes: [0.5, 0.85, 1] });
|
|
47
|
-
// Should be 160
|
|
48
|
-
// The smallest breakpoint is 20rem, which is 360px.
|
|
49
|
-
// 0.5 x 360 = 160
|
|
50
|
-
|
|
51
|
-
const src = placeholderImage.getAttribute('src');
|
|
52
|
-
|
|
53
|
-
expect(src).toEqual(expect.stringContaining('width=160'));
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('does not render an lqip if critical is true', () => {
|
|
57
|
-
const { placeholderImage } = setup({ critical: true });
|
|
58
|
-
|
|
59
|
-
const src = placeholderImage.getAttribute('src');
|
|
60
|
-
|
|
61
|
-
// Sets the src to transaprent data image instead
|
|
62
|
-
expect(src).toEqual(expect.stringContaining('data:image'));
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('accepts sizes as pixel values', () => {
|
|
66
|
-
const { placeholderImage } = setup({ sizes: [123] });
|
|
67
|
-
|
|
68
|
-
const src = placeholderImage.getAttribute('src');
|
|
69
|
-
|
|
70
|
-
expect(src).toEqual(expect.stringContaining('width=123'));
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('sets opacity to 0.6 while image has not loaded', () => {
|
|
74
|
-
const { placeholderImage } = setup();
|
|
75
|
-
|
|
76
|
-
expect(placeholderImage).toHaveStyle('opacity: 0.6');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('sets the sizing method', () => {
|
|
81
|
-
it('to thumbnail if no aspect ratio is provided', () => {
|
|
82
|
-
const { placeholderImage } = setup();
|
|
83
|
-
});
|
|
84
|
-
it('to fit if an aspect ratio is provided', () => {
|
|
85
|
-
const { placeholderImage } = setup({ aspect: '1:1' });
|
|
86
|
-
|
|
87
|
-
expect(placeholderImage.getAttribute('src')).toEqual(
|
|
88
|
-
expect.stringContaining('&height=320')
|
|
89
|
-
);
|
|
90
|
-
expect(placeholderImage.getAttribute('src')).toEqual(
|
|
91
|
-
expect.stringContaining('&width=320')
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
it('to crop if crop prop is true', () => {
|
|
95
|
-
const { placeholderImage } = setup({ aspect: '1:1', crop: true });
|
|
96
|
-
|
|
97
|
-
expect(placeholderImage.getAttribute('src')).toEqual(
|
|
98
|
-
expect.stringContaining('&method=crop')
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
it('warns if gravity is provided without crop', () => {
|
|
102
|
-
console.warn = jest.fn();
|
|
103
|
-
setup({ aspect: '1:1', crop: false, gravity: 'north' });
|
|
104
|
-
expect(console.warn).toHaveBeenCalled();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('when image is in view', () => {
|
|
109
|
-
beforeAll(() => {
|
|
110
|
-
useInView.mockImplementation(() => [null, true]);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('renders full image', () => {
|
|
114
|
-
const { image } = setup({
|
|
115
|
-
imageSrc: testImage
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
expect(image).toHaveAttribute('src', 'test-image.png');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('applies the given alt as an aria-label', () => {
|
|
122
|
-
const { image } = setup({
|
|
123
|
-
alt: 'test alt'
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
expect(image).toHaveAttribute('alt', 'test alt');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('defaults aspect to 1:1', () => {
|
|
130
|
-
const { imageContainer } = setup();
|
|
131
|
-
|
|
132
|
-
expect(imageContainer).toHaveStyle('padding-bottom : 100%');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('sets aspect ratio using padding if aspect is passed', () => {
|
|
136
|
-
const { imageContainer } = setup({ aspect: '3:2' });
|
|
137
|
-
|
|
138
|
-
expect(imageContainer).toHaveStyle('padding-bottom : 66.6667%');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('defaults to background-size contain', () => {
|
|
142
|
-
const { image } = setup();
|
|
143
|
-
|
|
144
|
-
expect(image).toHaveStyle('object-fit : contain');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('sets background-size to cover if `cover` is passed', () => {
|
|
148
|
-
const { image } = setup({ cover: true });
|
|
149
|
-
|
|
150
|
-
expect(image).toHaveStyle('object-fit : cover');
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('sets up image to fill available space if `fillAvailableSpace` is passed', () => {
|
|
154
|
-
const { image } = setup({ fillAvailableSpace: true });
|
|
155
|
-
|
|
156
|
-
expect(image).toHaveStyle('object-fit : cover');
|
|
157
|
-
expect(image).toHaveStyle('padding-top : 0');
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('sets opacity to 1 when image loads', () => {
|
|
161
|
-
const { image } = setup();
|
|
162
|
-
fireEvent.load(image);
|
|
163
|
-
|
|
164
|
-
expect(image).toHaveStyle('opacity: 1');
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('fades lqip when image loads', () => {
|
|
168
|
-
const { image, placeholderImage } = setup();
|
|
169
|
-
fireEvent.load(image);
|
|
170
|
-
|
|
171
|
-
expect(placeholderImage).toHaveStyle('opacity: 0');
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test('sets quality to quality prop', () => {
|
|
175
|
-
const { image } = setup({ quality: 1 });
|
|
176
|
-
|
|
177
|
-
expect(image.getAttribute('srcSet')).toEqual(
|
|
178
|
-
expect.stringContaining('&quality=1')
|
|
179
|
-
);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
describe('when there is an image error', () => {
|
|
184
|
-
beforeAll(() => {
|
|
185
|
-
useInView.mockImplementation(() => [null, true]);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('renders default error', () => {
|
|
189
|
-
const { image, getByText } = setup();
|
|
190
|
-
fireEvent.error(image);
|
|
191
|
-
|
|
192
|
-
expect(getByText('Image Not Found'));
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('renders error component', () => {
|
|
196
|
-
const { image, getByText, container } = setup({
|
|
197
|
-
error: () => <div>some error found</div>
|
|
198
|
-
});
|
|
199
|
-
fireEvent.error(image);
|
|
200
|
-
|
|
201
|
-
expect(getByText('some error found'));
|
|
202
|
-
expect(queryByText(container, 'Image Not Found')).not.toBeInTheDocument();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
describe('when image url is falsy', () => {
|
|
207
|
-
it('renders a transparent background image when null', () => {
|
|
208
|
-
const { image } = setup({ falsySrc: true, imageSrc: null });
|
|
209
|
-
|
|
210
|
-
expect(image).toHaveAttribute(`src`, transparent);
|
|
211
|
-
expect(image).toHaveStyle('opacity : 1');
|
|
212
|
-
});
|
|
213
|
-
it('renders a transparent background image when undefined', () => {
|
|
214
|
-
const { image } = setup({ falsySrc: true, imageSrc: undefined });
|
|
215
|
-
|
|
216
|
-
expect(image).toHaveAttribute(`src`, transparent);
|
|
217
|
-
expect(image).toHaveStyle('opacity: 1');
|
|
218
|
-
});
|
|
219
|
-
it('renders nothing and warns if false', () => {
|
|
220
|
-
console.warn = jest.fn();
|
|
221
|
-
const { image } = setup({ falsySrc: true, imageSrc: false });
|
|
222
|
-
|
|
223
|
-
expect(image).not.toBeInTheDocument();
|
|
224
|
-
expect(console.warn).toHaveBeenCalled();
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('renders a webp and jpeg source', () => {
|
|
229
|
-
const { imageContainer } = setup();
|
|
230
|
-
|
|
231
|
-
const sources = imageContainer.querySelectorAll('source');
|
|
232
|
-
expect(sources.length).toBe(2);
|
|
233
|
-
expect(sources[0]).toHaveAttribute('type', 'image/webp');
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
function setup({
|
|
238
|
-
imageSrc,
|
|
239
|
-
falsySrc = false,
|
|
240
|
-
error,
|
|
241
|
-
alt,
|
|
242
|
-
sizes,
|
|
243
|
-
aspect,
|
|
244
|
-
cover,
|
|
245
|
-
...rest
|
|
246
|
-
} = {}) {
|
|
247
|
-
const channelHandler = new ChannelHandler({
|
|
248
|
-
selectedChannel,
|
|
249
|
-
channels
|
|
250
|
-
});
|
|
251
|
-
const utils = render(
|
|
252
|
-
<ChannelProvider channelHandler={channelHandler}>
|
|
253
|
-
<ConfigProvider config={mockShopConfig}>
|
|
254
|
-
<Image
|
|
255
|
-
src={falsySrc ? imageSrc : imageSrc || 'default.png'}
|
|
256
|
-
error={error}
|
|
257
|
-
alt={alt}
|
|
258
|
-
sizes={sizes}
|
|
259
|
-
aspect={aspect}
|
|
260
|
-
cover={cover}
|
|
261
|
-
{...rest}
|
|
262
|
-
/>
|
|
263
|
-
</ConfigProvider>
|
|
264
|
-
</ChannelProvider>
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
return {
|
|
268
|
-
...utils,
|
|
269
|
-
image: utils.container.querySelector('[data-flight-image] img'),
|
|
270
|
-
placeholderImage: utils.container.querySelector(
|
|
271
|
-
'[data-flight-image-placeholder] img'
|
|
272
|
-
),
|
|
273
|
-
imageContainer: utils.container.querySelector(
|
|
274
|
-
'[data-flight-image-container]'
|
|
275
|
-
)
|
|
276
|
-
};
|
|
277
|
-
}
|
package/CloudflareImage/Image.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Image.js","sourceRoot":"","sources":["Image.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './FlightImage';
|
package/CloudflareImage/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { ImageValue, ProductImageSize } from '@jetshop/core/types';
|
|
2
|
-
type ImageSrcType = string | ProductImageSize[] | ImageValue;
|
|
3
|
-
export type Gravity = 'north' | 'south' | 'west' | 'east' | 'centre' | 'smart';
|
|
4
|
-
export type ImageBreakpointSize = number | string;
|
|
5
|
-
export type ImageBreakpointSizes = ImageBreakpointSize | ImageBreakpointSize[];
|
|
6
|
-
interface ImageParameters {
|
|
7
|
-
/** The image src
|
|
8
|
-
* Also accepts an array of objects with `url` keys (deprecated image field)
|
|
9
|
-
*/
|
|
10
|
-
src: ImageSrcType;
|
|
11
|
-
/**
|
|
12
|
-
* Whether to crop the image instead of resizing it when aspect ratio is provided
|
|
13
|
-
* @default false
|
|
14
|
-
*/
|
|
15
|
-
crop?: boolean;
|
|
16
|
-
gravity?: Gravity;
|
|
17
|
-
quality?: number;
|
|
18
|
-
/** An array of image sizes, will be mapped against breakpoints.
|
|
19
|
-
* @see https://docs.dev.jetshop.se/ui/image#the-sizes-prop
|
|
20
|
-
*/
|
|
21
|
-
sizes: ImageBreakpointSizes;
|
|
22
|
-
/**
|
|
23
|
-
* The aspect ratio of the image
|
|
24
|
-
* If unknown, use null to preserve original aspect ratio
|
|
25
|
-
*/
|
|
26
|
-
aspect?: string;
|
|
27
|
-
critical?: boolean;
|
|
28
|
-
modifiedDate?: string;
|
|
29
|
-
breakpoints: Record<string, string>;
|
|
30
|
-
baseUrl: string;
|
|
31
|
-
focalPointX?: number;
|
|
32
|
-
focalPointY?: number;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Dynamically constructs the query parameters used by ImageMagick to size the image appropriately.
|
|
36
|
-
* Also generates a LQIP using query parameters, to display while the full image loads.
|
|
37
|
-
*/
|
|
38
|
-
export declare function useConstructImage({ gravity, crop, src, sizes, aspect, critical, quality, modifiedDate, breakpoints, baseUrl, focalPointX, focalPointY }: ImageParameters): {
|
|
39
|
-
srcset: string;
|
|
40
|
-
webpSrcset: string;
|
|
41
|
-
sizes: string;
|
|
42
|
-
sizesMobile: string;
|
|
43
|
-
lqip: string;
|
|
44
|
-
src: string;
|
|
45
|
-
hasFalsySrc: boolean;
|
|
46
|
-
srcsetMobile: string;
|
|
47
|
-
webpSrcsetMobile: string;
|
|
48
|
-
};
|
|
49
|
-
export {};
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import useWarningInDev from '@jetshop/core/hooks/useWarningInDev';
|
|
2
|
-
import { getFullUrl } from './utils/getFullUrl';
|
|
3
|
-
import { getImageWidths } from './utils/getImageWidths';
|
|
4
|
-
import { getLargestSize } from './utils/getLargestSize';
|
|
5
|
-
import { getLQIP } from './utils/getLQIP';
|
|
6
|
-
import { getSizesMap } from './utils/getSizesMap';
|
|
7
|
-
import { getSrcSetFromWidths } from './utils/getSrcSetFromWidths';
|
|
8
|
-
import React from 'react';
|
|
9
|
-
/**
|
|
10
|
-
* Dynamically constructs the query parameters used by ImageMagick to size the image appropriately.
|
|
11
|
-
* Also generates a LQIP using query parameters, to display while the full image loads.
|
|
12
|
-
*/
|
|
13
|
-
export function useConstructImage({ gravity, crop, src, sizes, aspect, critical, quality, modifiedDate, breakpoints, baseUrl, focalPointX, focalPointY }) {
|
|
14
|
-
// Warn if gravity was provided but crop was not
|
|
15
|
-
useWarningInDev(gravity && !crop, 'You have provided a gravity without setting crop to true. Your image will not be cropped, and the `gravity` prop will do nothing. Please remove the `gravity` prop.');
|
|
16
|
-
// Warn if the src is a falsy value
|
|
17
|
-
useWarningInDev(!!!src, 'You have provided a falsy value to the Image component. If you intentionally want to display a blank Image component, you may import `transparentDataImg` and use it for the src. Otherwise, this is probably a bug.');
|
|
18
|
-
/*
|
|
19
|
-
For backwards-compatibility (and dev convenience) reasons, we accept a
|
|
20
|
-
falsy `src` prop on Image. undefined | null will act just like the normal
|
|
21
|
-
Image component does, except that it will show a transparent image where
|
|
22
|
-
the image would normally load. This may be useful in cases where the end
|
|
23
|
-
user is lazy and wants to do this:
|
|
24
|
-
|
|
25
|
-
const { imageSrc } = someDataRequest();
|
|
26
|
-
<Image src={imageSrc} />
|
|
27
|
-
|
|
28
|
-
Where imageSrc may be undefined | null while the request is occurring. The
|
|
29
|
-
preferred method is to be more explicit:
|
|
30
|
-
|
|
31
|
-
const {imageSrc, loading} = someDataRequest();
|
|
32
|
-
<Image src={loading ? transparentDataImg : imageSrc } />
|
|
33
|
-
|
|
34
|
-
Therefore, whilst we will handle a null | undefined src, we will warn
|
|
35
|
-
against its usage in dev.
|
|
36
|
-
*/
|
|
37
|
-
let hasFalsySrc = true;
|
|
38
|
-
let imageSrc = '';
|
|
39
|
-
if (Array.isArray(src)) {
|
|
40
|
-
// maintain support for deprecated image sizes array
|
|
41
|
-
hasFalsySrc = false;
|
|
42
|
-
imageSrc = getFullUrl(getLargestSize(src), baseUrl);
|
|
43
|
-
}
|
|
44
|
-
// When we have a string for the src
|
|
45
|
-
if (!!src && typeof src === 'string') {
|
|
46
|
-
hasFalsySrc = false;
|
|
47
|
-
imageSrc = getFullUrl(src, baseUrl);
|
|
48
|
-
}
|
|
49
|
-
if (!!src && typeof src === 'object' && src.value) {
|
|
50
|
-
hasFalsySrc = false;
|
|
51
|
-
imageSrc = getFullUrl(src.value, baseUrl);
|
|
52
|
-
}
|
|
53
|
-
// useMemo so this runs only if the image props change. It calculates the
|
|
54
|
-
// strings used for `sizes`, `srcset`, and the `lqip`
|
|
55
|
-
const { sizesMap, sizesMapMobile, srcset, lqip, webpSrcset, srcsetMobile, webpSrcsetMobile } = React.useMemo(() => {
|
|
56
|
-
if (hasFalsySrc) {
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
const widths = getImageWidths(breakpoints, sizes);
|
|
60
|
-
const mobileWidths = getImageWidths(breakpoints, sizes, true);
|
|
61
|
-
const srcSetFromWidths = ({ webp }) => getSrcSetFromWidths(imageSrc, widths, aspect, {
|
|
62
|
-
crop,
|
|
63
|
-
gravity,
|
|
64
|
-
quality,
|
|
65
|
-
webp,
|
|
66
|
-
focalPointX,
|
|
67
|
-
focalPointY
|
|
68
|
-
}, modifiedDate, baseUrl);
|
|
69
|
-
const mobileSrcSetFromWidths = ({ webp }) => getSrcSetFromWidths(imageSrc, mobileWidths, aspect, {
|
|
70
|
-
crop,
|
|
71
|
-
gravity,
|
|
72
|
-
quality,
|
|
73
|
-
webp,
|
|
74
|
-
focalPointX,
|
|
75
|
-
focalPointY
|
|
76
|
-
}, modifiedDate, baseUrl);
|
|
77
|
-
const srcset = srcSetFromWidths({ webp: false });
|
|
78
|
-
const webpSrcset = srcSetFromWidths({ webp: true });
|
|
79
|
-
const srcsetMobile = mobileSrcSetFromWidths({ webp: false });
|
|
80
|
-
const webpSrcsetMobile = mobileSrcSetFromWidths({ webp: true });
|
|
81
|
-
// If this is a critical image, don't calculate LQIP
|
|
82
|
-
const lqip = critical
|
|
83
|
-
? null
|
|
84
|
-
: getLQIP(imageSrc, widths, aspect, crop, modifiedDate, baseUrl);
|
|
85
|
-
const sizesMap = getSizesMap(breakpoints, sizes);
|
|
86
|
-
const sizesMapMobile = getSizesMap(breakpoints, sizes, true);
|
|
87
|
-
return {
|
|
88
|
-
sizesMap,
|
|
89
|
-
sizesMapMobile,
|
|
90
|
-
srcset,
|
|
91
|
-
lqip,
|
|
92
|
-
webpSrcset,
|
|
93
|
-
srcsetMobile,
|
|
94
|
-
webpSrcsetMobile
|
|
95
|
-
};
|
|
96
|
-
}, [
|
|
97
|
-
aspect,
|
|
98
|
-
breakpoints,
|
|
99
|
-
crop,
|
|
100
|
-
gravity,
|
|
101
|
-
hasFalsySrc,
|
|
102
|
-
imageSrc,
|
|
103
|
-
quality,
|
|
104
|
-
sizes,
|
|
105
|
-
critical,
|
|
106
|
-
modifiedDate,
|
|
107
|
-
focalPointX,
|
|
108
|
-
focalPointY
|
|
109
|
-
]);
|
|
110
|
-
return {
|
|
111
|
-
srcset,
|
|
112
|
-
webpSrcset,
|
|
113
|
-
sizes: sizesMap,
|
|
114
|
-
sizesMobile: sizesMapMobile,
|
|
115
|
-
lqip,
|
|
116
|
-
src: imageSrc,
|
|
117
|
-
hasFalsySrc,
|
|
118
|
-
srcsetMobile,
|
|
119
|
-
webpSrcsetMobile
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=useConstructImage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useConstructImage.js","sourceRoot":"","sources":["useConstructImage.tsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,MAAM,OAAO,CAAC;AAsC1B;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,OAAO,EACP,IAAI,EACJ,GAAG,EACH,KAAK,EACL,MAAM,EACN,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,WAAW,EACX,OAAO,EACP,WAAW,EACX,WAAW,EACK;IAChB,gDAAgD;IAChD,eAAe,CACb,OAAO,IAAI,CAAC,IAAI,EAChB,qKAAqK,CACtK,CAAC;IACF,mCAAmC;IACnC,eAAe,CACb,CAAC,CAAC,CAAC,GAAG,EACN,sNAAsN,CACvN,CAAC;IAEF;;;;;;;;;;;;;;;;;;MAkBE;IACF,IAAI,WAAW,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;QACJ,GAAG,EAAE,QAAQ;QACb,WAAW;QACX,YAAY;QACZ,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const aspectRatioToFraction = (aspect) => {
|
|
2
|
-
if (typeof aspect === 'string' && aspect.indexOf(':') > 0) {
|
|
3
|
-
const [a, b] = aspect.split(':');
|
|
4
|
-
return b / a;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof aspect === 'number') {
|
|
7
|
-
return aspect;
|
|
8
|
-
}
|
|
9
|
-
throw new TypeError('Aspect ratio is not a Number or String with the format n:m');
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=aspectRatioToFraction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aspectRatioToFraction.js","sourceRoot":"","sources":["aspectRatioToFraction.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,MAAmB,EAAE,EAAE;IAC3D,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACzD,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAwB,CAAC;QACxD,OAAO,CAAC,GAAG,CAAC,CAAC;KACd;SAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QACrC,OAAO,MAAM,CAAC;KACf;IACD,MAAM,IAAI,SAAS,CACjB,4DAA4D,CAC7D,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constructs the image url by combining the passed-in url with the selected channel
|
|
3
|
-
* @param url The image url
|
|
4
|
-
* @param baseUrl The baseUrl from the currently-selected channel
|
|
5
|
-
*/
|
|
6
|
-
export const getFullUrl = (url, baseUrl) => {
|
|
7
|
-
if (!baseUrl || !url) {
|
|
8
|
-
return url;
|
|
9
|
-
}
|
|
10
|
-
url = url.trim();
|
|
11
|
-
if (url.indexOf('/') === 0 &&
|
|
12
|
-
url.indexOf('//:') === -1 &&
|
|
13
|
-
url.indexOf('static/media') === -1) {
|
|
14
|
-
return baseUrl + url;
|
|
15
|
-
}
|
|
16
|
-
return url;
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=getFullUrl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFullUrl.js","sourceRoot":"","sources":["getFullUrl.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,OAAe,EAAE,EAAE;IACzD,IAAI,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE;QACpB,OAAO,GAAG,CAAC;KACZ;IACD,GAAG,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACjB,IACE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;QACtB,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACzB,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAClC;QACA,OAAO,OAAO,GAAG,GAAG,CAAC;KACtB;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getImageWidth: (size: number | string, vw: number, pixelRatio: number) => number;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { sizeToNumber } from './sizeToNumber';
|
|
2
|
-
export const getImageWidth = (size = 1, vw, pixelRatio) => {
|
|
3
|
-
// Convert input size to fraction or px value
|
|
4
|
-
size = sizeToNumber(size);
|
|
5
|
-
// Size is in px
|
|
6
|
-
if (size > 2) {
|
|
7
|
-
return Math.round(size * pixelRatio);
|
|
8
|
-
}
|
|
9
|
-
// Size is a fraction
|
|
10
|
-
return Math.round(vw * size * pixelRatio);
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=getImageWidth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getImageWidth.js","sourceRoot":"","sources":["getImageWidth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAAwB,CAAC,EACzB,EAAU,EACV,UAAkB,EAClB,EAAE;IACF,6CAA6C;IAC7C,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAC1B,gBAAgB;IAChB,IAAI,IAAI,GAAG,CAAC,EAAE;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,UAAU,CAAC,CAAC;KACtC;IACD,qBAAqB;IACrB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,GAAG,UAAU,CAAC,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { getImageWidth } from './getImageWidth';
|
|
2
|
-
import { remToPx } from './remToPx';
|
|
3
|
-
import { getSizeForBreakpoint } from './getSizeForBreakpoint';
|
|
4
|
-
export const getImageWidths = (breakpoints, sizes, mobile = false) => {
|
|
5
|
-
const all = new Set();
|
|
6
|
-
const breakpointArray = Object.entries(breakpoints).map(([key, value]) => ({
|
|
7
|
-
key,
|
|
8
|
-
value
|
|
9
|
-
}));
|
|
10
|
-
for (let i = 0; i < breakpointArray.length; i++) {
|
|
11
|
-
const bpSize = getSizeForBreakpoint(sizes, i);
|
|
12
|
-
const px = remToPx(breakpointArray[i].value);
|
|
13
|
-
all.add(getImageWidth(bpSize, px, 1));
|
|
14
|
-
all.add(getImageWidth(bpSize, px, 2));
|
|
15
|
-
if (mobile && breakpointArray[i].key === 'sm') {
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return Array.from(all).sort();
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=get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@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a LQIP (Low Quality Image Placeholder) using the Flight image
|
|
3
|
-
* handling API (via query params)
|
|
4
|
-
* @param src The image src
|
|
5
|
-
* @param widths An array of image widths
|
|
6
|
-
* @param aspect The desired aspect ratio of the placeholder
|
|
7
|
-
*/
|
|
8
|
-
export declare function getLQIP(src: string, widths: number[], aspect: string, crop: boolean, modifiedDate: string, baseUrl: string): string;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createSrcWithProperties } from './getSrcWithParams';
|
|
2
|
-
/**
|
|
3
|
-
* Generates a LQIP (Low Quality Image Placeholder) using the Flight image
|
|
4
|
-
* handling API (via query params)
|
|
5
|
-
* @param src The image src
|
|
6
|
-
* @param widths An array of image widths
|
|
7
|
-
* @param aspect The desired aspect ratio of the placeholder
|
|
8
|
-
*/
|
|
9
|
-
export function getLQIP(src, widths, aspect, crop = false, modifiedDate, baseUrl) {
|
|
10
|
-
const transparent = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
|
|
11
|
-
if (!src)
|
|
12
|
-
return transparent;
|
|
13
|
-
// Use the smallest width for the placeholder, to ensure it is the smallest filesize possible
|
|
14
|
-
const smallestWidth = widths.sort((a, b) => a - b)[0];
|
|
15
|
-
const prop = createSrcWithProperties(smallestWidth, aspect, src, false, {
|
|
16
|
-
crop
|
|
17
|
-
});
|
|
18
|
-
const finalSrc = `${baseUrl}/cdn-cgi/image/${prop}/${src}${modifiedDate ? `?timestamp=${modifiedDate}` : ''}`;
|
|
19
|
-
return finalSrc;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=getLQIP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getLQIP.js","sourceRoot":"","sources":["getLQIP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CACrB,GAAW,EACX,MAAgB,EAChB,MAAc,EACd,IAAI,GAAG,KAAK,EACZ,YAAoB,EACpB,OAAe;IAEf,MAAM,WAAW,GACf,oHAAoH,CAAC;IACvH,IAAI,CAAC,GAAG;QAAE,OAAO,WAAW,CAAC;IAE7B,6FAA6F;IAC7F,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEtD,MAAM,IAAI,GAAG,uBAAuB,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE;QACtE,IAAI;KACL,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,GAAG,OAAO,kBAAkB,IAAI,IAAI,GAAG,GACtD,YAAY,CAAC,CAAC,CAAC,cAAc,YAAY,EAAE,CAAC,CAAC,CAAC,EAChD,EAAE,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ProductImageSize } from '@jetshop/core/types';
|
|
2
|
-
/**
|
|
3
|
-
* This exists to handle the deprecated `ProductImageSize` field from the API
|
|
4
|
-
* Takes an array of sizes, and returns the url of the largest one
|
|
5
|
-
* @param sizes Sizes field returned from API
|
|
6
|
-
*/
|
|
7
|
-
export declare const getLargestSize: (sizes: string | ProductImageSize[]) => any;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This exists to handle the deprecated `ProductImageSize` field from the API
|
|
3
|
-
* Takes an array of sizes, and returns the url of the largest one
|
|
4
|
-
* @param sizes Sizes field returned from API
|
|
5
|
-
*/
|
|
6
|
-
export const getLargestSize = (sizes) => {
|
|
7
|
-
if (Array.isArray(sizes)) {
|
|
8
|
-
if (sizes.length === 0) {
|
|
9
|
-
throw new Error('Sizes must not be an empty array');
|
|
10
|
-
}
|
|
11
|
-
return sizes[sizes.length - 1].url;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return sizes.toString();
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=getLargestSize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getLargestSize.js","sourceRoot":"","sources":["getLargestSize.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAkC,EAAE,EAAE;IACnE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;QACD,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;KACpC;SAAM;QACL,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;KACzB;AACH,CAAC,CAAC"}
|