gatsby-plugin-image 2.19.0-next.2 → 2.19.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.
Files changed (32) hide show
  1. package/dist/babel-helpers.js +66 -66
  2. package/dist/babel-plugin-parse-static-images.js +80 -80
  3. package/dist/components/gatsby-image.browser.js +173 -173
  4. package/dist/components/gatsby-image.server.js +106 -106
  5. package/dist/components/hooks.js +250 -250
  6. package/dist/components/intersection-observer.js +53 -53
  7. package/dist/components/layout-wrapper.js +95 -95
  8. package/dist/components/lazy-hydrate.js +218 -218
  9. package/dist/components/main-image.js +28 -28
  10. package/dist/components/picture.js +103 -103
  11. package/dist/components/placeholder.js +78 -78
  12. package/dist/components/static-image.server.js +111 -111
  13. package/dist/gatsby-node.js +58 -58
  14. package/dist/global.js +2 -2
  15. package/dist/image-utils.js +442 -442
  16. package/dist/index.js +32 -32
  17. package/dist/node-apis/image-processing.js +276 -276
  18. package/dist/node-apis/node-utils.js +11 -11
  19. package/dist/node-apis/parser.js +98 -98
  20. package/dist/node-apis/preprocess-source.js +117 -117
  21. package/dist/node-apis/watcher.js +129 -129
  22. package/dist/resolver-utils.js +120 -120
  23. package/dist/src/babel-helpers.d.ts +6 -6
  24. package/dist/src/babel-plugin-parse-static-images.d.ts +10 -10
  25. package/dist/src/gatsby-node.d.ts +5 -5
  26. package/dist/src/node-apis/image-processing.d.ts +29 -29
  27. package/dist/src/node-apis/node-utils.d.ts +1 -1
  28. package/dist/src/node-apis/parser.d.ts +11 -11
  29. package/dist/src/node-apis/preprocess-source.d.ts +2 -2
  30. package/dist/src/node-apis/watcher.d.ts +12 -12
  31. package/dist/src/resolver-utils.d.ts +21 -21
  32. package/package.json +5 -5
@@ -1,250 +1,250 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- var __read = (this && this.__read) || function (o, n) {
25
- var m = typeof Symbol === "function" && o[Symbol.iterator];
26
- if (!m) return o;
27
- var i = m.call(o), r, ar = [], e;
28
- try {
29
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
- }
31
- catch (error) { e = { error: error }; }
32
- finally {
33
- try {
34
- if (r && !r.done && (m = i["return"])) m.call(i);
35
- }
36
- finally { if (e) throw e.error; }
37
- }
38
- return ar;
39
- };
40
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
- if (ar || !(i in from)) {
43
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
- ar[i] = from[i];
45
- }
46
- }
47
- return to.concat(ar || Array.prototype.slice.call(from));
48
- };
49
- exports.__esModule = true;
50
- exports.withArtDirection = exports.getPlaceholderProps = exports.getMainProps = exports.getImageData = exports.getWrapperProps = exports.getSrcSet = exports.getSrc = exports.getImage = exports.gatsbyImageIsInstalled = exports.hasNativeLazyLoadSupport = void 0;
51
- /* global GATSBY___IMAGE */
52
- var image_utils_1 = require("../image-utils");
53
- // Native lazy-loading support: https://addyosmani.com/blog/lazy-loading/
54
- var hasNativeLazyLoadSupport = function () {
55
- return typeof HTMLImageElement !== "undefined" &&
56
- "loading" in HTMLImageElement.prototype;
57
- };
58
- exports.hasNativeLazyLoadSupport = hasNativeLazyLoadSupport;
59
- function gatsbyImageIsInstalled() {
60
- return typeof GATSBY___IMAGE !== "undefined" && GATSBY___IMAGE;
61
- }
62
- exports.gatsbyImageIsInstalled = gatsbyImageIsInstalled;
63
- var isGatsbyImageData = function (
64
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- node) { var _a, _b;
66
- // 🦆 check for a deep prop to be sure this is a valid gatsbyImageData object
67
- return Boolean((_b = (_a = node === null || node === void 0 ? void 0 : node.images) === null || _a === void 0 ? void 0 : _a.fallback) === null || _b === void 0 ? void 0 : _b.src); };
68
- var isGatsbyImageDataParent = function (
69
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
- node) { return Boolean(node === null || node === void 0 ? void 0 : node.gatsbyImageData); };
71
- var isGatsbyImageParent = function (
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- node) { return Boolean(node === null || node === void 0 ? void 0 : node.gatsbyImage); };
74
- var getImage = function (node) {
75
- var _a;
76
- if (isGatsbyImageData(node)) {
77
- return node;
78
- }
79
- // gatsbyImageData GraphQL field
80
- if (isGatsbyImageDataParent(node)) {
81
- return node.gatsbyImageData;
82
- }
83
- // gatsbyImage GraphQL field for Gatsby's Image CDN service
84
- if (isGatsbyImageParent(node)) {
85
- return node.gatsbyImage;
86
- }
87
- return (_a = node === null || node === void 0 ? void 0 : node.childImageSharp) === null || _a === void 0 ? void 0 : _a.gatsbyImageData;
88
- };
89
- exports.getImage = getImage;
90
- var getSrc = function (node) { var _a, _b, _c; return (_c = (_b = (_a = (0, exports.getImage)(node)) === null || _a === void 0 ? void 0 : _a.images) === null || _b === void 0 ? void 0 : _b.fallback) === null || _c === void 0 ? void 0 : _c.src; };
91
- exports.getSrc = getSrc;
92
- var getSrcSet = function (node) { var _a, _b, _c; return (_c = (_b = (_a = (0, exports.getImage)(node)) === null || _a === void 0 ? void 0 : _a.images) === null || _b === void 0 ? void 0 : _b.fallback) === null || _c === void 0 ? void 0 : _c.srcSet; };
93
- exports.getSrcSet = getSrcSet;
94
- function getWrapperProps(width, height, layout) {
95
- var wrapperStyle = {};
96
- var className = "gatsby-image-wrapper";
97
- // If the plugin isn't installed we need to apply the styles inline
98
- if (!gatsbyImageIsInstalled()) {
99
- wrapperStyle.position = "relative";
100
- wrapperStyle.overflow = "hidden";
101
- }
102
- if (layout === "fixed") {
103
- wrapperStyle.width = width;
104
- wrapperStyle.height = height;
105
- }
106
- else if (layout === "constrained") {
107
- if (!gatsbyImageIsInstalled()) {
108
- wrapperStyle.display = "inline-block";
109
- wrapperStyle.verticalAlign = "top";
110
- }
111
- className = "gatsby-image-wrapper gatsby-image-wrapper-constrained";
112
- }
113
- return {
114
- className: className,
115
- "data-gatsby-image-wrapper": "",
116
- style: wrapperStyle
117
- };
118
- }
119
- exports.getWrapperProps = getWrapperProps;
120
- /**
121
- * Use this hook to generate gatsby-plugin-image data in the browser.
122
- */
123
- function getImageData(_a) {
124
- var baseUrl = _a.baseUrl, urlBuilder = _a.urlBuilder, sourceWidth = _a.sourceWidth, sourceHeight = _a.sourceHeight, _b = _a.pluginName, pluginName = _b === void 0 ? "getImageData" : _b, _c = _a.formats, formats = _c === void 0 ? ["auto"] : _c, breakpoints = _a.breakpoints, options = _a.options, props = __rest(_a, ["baseUrl", "urlBuilder", "sourceWidth", "sourceHeight", "pluginName", "formats", "breakpoints", "options"]);
125
- if (!(breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.length) &&
126
- (props.layout === "fullWidth" || props.layout === "FULL_WIDTH")) {
127
- breakpoints = image_utils_1.EVERY_BREAKPOINT;
128
- }
129
- var generateImageSource = function (baseUrl, width, height, format) {
130
- return {
131
- width: width,
132
- height: height,
133
- format: format,
134
- src: urlBuilder({ baseUrl: baseUrl, width: width, height: height, options: options, format: format })
135
- };
136
- };
137
- var sourceMetadata = {
138
- width: sourceWidth,
139
- height: sourceHeight,
140
- format: "auto"
141
- };
142
- var args = __assign(__assign({}, props), { pluginName: pluginName, generateImageSource: generateImageSource, filename: baseUrl, formats: formats, breakpoints: breakpoints, sourceMetadata: sourceMetadata });
143
- return (0, image_utils_1.generateImageData)(args);
144
- }
145
- exports.getImageData = getImageData;
146
- function getMainProps(isLoading, isLoaded, images, loading, style) {
147
- if (style === void 0) { style = {}; }
148
- // fallback when it's not configured in gatsby-config.
149
- if (!gatsbyImageIsInstalled()) {
150
- style = __assign({ height: "100%", left: 0, position: "absolute", top: 0, transform: "translateZ(0)", transition: "opacity 250ms linear", width: "100%", willChange: "opacity" }, style);
151
- }
152
- var result = __assign(__assign({}, images), { loading: loading, shouldLoad: isLoading, "data-main-image": "", style: __assign(__assign({}, style), { opacity: isLoaded ? 1 : 0 }) });
153
- return result;
154
- }
155
- exports.getMainProps = getMainProps;
156
- function getPlaceholderProps(placeholder, isLoaded, layout, width, height, backgroundColor, objectFit, objectPosition) {
157
- var wrapperStyle = {};
158
- if (backgroundColor) {
159
- wrapperStyle.backgroundColor = backgroundColor;
160
- if (layout === "fixed") {
161
- wrapperStyle.width = width;
162
- wrapperStyle.height = height;
163
- wrapperStyle.backgroundColor = backgroundColor;
164
- wrapperStyle.position = "relative";
165
- }
166
- else if (layout === "constrained") {
167
- wrapperStyle.position = "absolute";
168
- wrapperStyle.top = 0;
169
- wrapperStyle.left = 0;
170
- wrapperStyle.bottom = 0;
171
- wrapperStyle.right = 0;
172
- }
173
- else if (layout === "fullWidth") {
174
- wrapperStyle.position = "absolute";
175
- wrapperStyle.top = 0;
176
- wrapperStyle.left = 0;
177
- wrapperStyle.bottom = 0;
178
- wrapperStyle.right = 0;
179
- }
180
- }
181
- if (objectFit) {
182
- wrapperStyle.objectFit = objectFit;
183
- }
184
- if (objectPosition) {
185
- wrapperStyle.objectPosition = objectPosition;
186
- }
187
- var result = __assign(__assign({}, placeholder), { "aria-hidden": true, "data-placeholder-image": "", style: __assign({ opacity: isLoaded ? 0 : 1, transition: "opacity 500ms linear" }, wrapperStyle) });
188
- // fallback when it's not configured in gatsby-config.
189
- if (!gatsbyImageIsInstalled()) {
190
- result.style = {
191
- height: "100%",
192
- left: 0,
193
- position: "absolute",
194
- top: 0,
195
- width: "100%"
196
- };
197
- }
198
- return result;
199
- }
200
- exports.getPlaceholderProps = getPlaceholderProps;
201
- /**
202
- * Generate a Gatsby image data object with multiple, art-directed images that display at different
203
- * resolutions.
204
- *
205
- * @param defaultImage The image displayed when no media query matches.
206
- * It is also used for all other settings applied to the image, such as width, height and layout.
207
- * You should pass a className to the component with media queries to adjust the size of the container,
208
- * as this cannot be adjusted automatically.
209
- * @param artDirected Array of objects which each contains a `media` string which is a media query
210
- * such as `(min-width: 320px)`, and the image object to use when that query matches.
211
- */
212
- function withArtDirection(defaultImage, artDirected) {
213
- var _a, _b;
214
- var _c;
215
- var images = defaultImage.images, placeholder = defaultImage.placeholder, props = __rest(defaultImage, ["images", "placeholder"]);
216
- var output = __assign(__assign({}, props), { images: __assign(__assign({}, images), { sources: [] }), placeholder: placeholder && __assign(__assign({}, placeholder), { sources: [] }) });
217
- artDirected.forEach(function (_a) {
218
- var _b;
219
- var media = _a.media, image = _a.image;
220
- if (!media) {
221
- if (process.env.NODE_ENV === "development") {
222
- console.warn("[gatsby-plugin-image] All art-directed images passed to must have a value set for `media`. Skipping.");
223
- }
224
- return;
225
- }
226
- if (image.layout !== defaultImage.layout &&
227
- process.env.NODE_ENV === "development") {
228
- console.warn("[gatsby-plugin-image] Mismatched image layout: expected \"".concat(defaultImage.layout, "\" but received \"").concat(image.layout, "\". All art-directed images use the same layout as the default image"));
229
- }
230
- (_b = output.images.sources).push.apply(_b, __spreadArray(__spreadArray([], __read(image.images.sources.map(function (source) {
231
- return __assign(__assign({}, source), { media: media });
232
- })), false), [{
233
- media: media,
234
- srcSet: image.images.fallback.srcSet
235
- }], false));
236
- if (!output.placeholder) {
237
- return;
238
- }
239
- output.placeholder.sources.push({
240
- media: media,
241
- srcSet: image.placeholder.fallback
242
- });
243
- });
244
- (_a = output.images.sources).push.apply(_a, __spreadArray([], __read(images.sources), false));
245
- if (placeholder === null || placeholder === void 0 ? void 0 : placeholder.sources) {
246
- (_c = output.placeholder) === null || _c === void 0 ? void 0 : (_b = _c.sources).push.apply(_b, __spreadArray([], __read(placeholder.sources), false));
247
- }
248
- return output;
249
- }
250
- exports.withArtDirection = withArtDirection;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __read = (this && this.__read) || function (o, n) {
25
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
26
+ if (!m) return o;
27
+ var i = m.call(o), r, ar = [], e;
28
+ try {
29
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
+ }
31
+ catch (error) { e = { error: error }; }
32
+ finally {
33
+ try {
34
+ if (r && !r.done && (m = i["return"])) m.call(i);
35
+ }
36
+ finally { if (e) throw e.error; }
37
+ }
38
+ return ar;
39
+ };
40
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
+ if (ar || !(i in from)) {
43
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
+ ar[i] = from[i];
45
+ }
46
+ }
47
+ return to.concat(ar || Array.prototype.slice.call(from));
48
+ };
49
+ exports.__esModule = true;
50
+ exports.withArtDirection = exports.getPlaceholderProps = exports.getMainProps = exports.getImageData = exports.getWrapperProps = exports.getSrcSet = exports.getSrc = exports.getImage = exports.gatsbyImageIsInstalled = exports.hasNativeLazyLoadSupport = void 0;
51
+ /* global GATSBY___IMAGE */
52
+ var image_utils_1 = require("../image-utils");
53
+ // Native lazy-loading support: https://addyosmani.com/blog/lazy-loading/
54
+ var hasNativeLazyLoadSupport = function () {
55
+ return typeof HTMLImageElement !== "undefined" &&
56
+ "loading" in HTMLImageElement.prototype;
57
+ };
58
+ exports.hasNativeLazyLoadSupport = hasNativeLazyLoadSupport;
59
+ function gatsbyImageIsInstalled() {
60
+ return typeof GATSBY___IMAGE !== "undefined" && GATSBY___IMAGE;
61
+ }
62
+ exports.gatsbyImageIsInstalled = gatsbyImageIsInstalled;
63
+ var isGatsbyImageData = function (
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ node) { var _a, _b;
66
+ // 🦆 check for a deep prop to be sure this is a valid gatsbyImageData object
67
+ return Boolean((_b = (_a = node === null || node === void 0 ? void 0 : node.images) === null || _a === void 0 ? void 0 : _a.fallback) === null || _b === void 0 ? void 0 : _b.src); };
68
+ var isGatsbyImageDataParent = function (
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ node) { return Boolean(node === null || node === void 0 ? void 0 : node.gatsbyImageData); };
71
+ var isGatsbyImageParent = function (
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ node) { return Boolean(node === null || node === void 0 ? void 0 : node.gatsbyImage); };
74
+ var getImage = function (node) {
75
+ var _a;
76
+ if (isGatsbyImageData(node)) {
77
+ return node;
78
+ }
79
+ // gatsbyImageData GraphQL field
80
+ if (isGatsbyImageDataParent(node)) {
81
+ return node.gatsbyImageData;
82
+ }
83
+ // gatsbyImage GraphQL field for Gatsby's Image CDN service
84
+ if (isGatsbyImageParent(node)) {
85
+ return node.gatsbyImage;
86
+ }
87
+ return (_a = node === null || node === void 0 ? void 0 : node.childImageSharp) === null || _a === void 0 ? void 0 : _a.gatsbyImageData;
88
+ };
89
+ exports.getImage = getImage;
90
+ var getSrc = function (node) { var _a, _b, _c; return (_c = (_b = (_a = (0, exports.getImage)(node)) === null || _a === void 0 ? void 0 : _a.images) === null || _b === void 0 ? void 0 : _b.fallback) === null || _c === void 0 ? void 0 : _c.src; };
91
+ exports.getSrc = getSrc;
92
+ var getSrcSet = function (node) { var _a, _b, _c; return (_c = (_b = (_a = (0, exports.getImage)(node)) === null || _a === void 0 ? void 0 : _a.images) === null || _b === void 0 ? void 0 : _b.fallback) === null || _c === void 0 ? void 0 : _c.srcSet; };
93
+ exports.getSrcSet = getSrcSet;
94
+ function getWrapperProps(width, height, layout) {
95
+ var wrapperStyle = {};
96
+ var className = "gatsby-image-wrapper";
97
+ // If the plugin isn't installed we need to apply the styles inline
98
+ if (!gatsbyImageIsInstalled()) {
99
+ wrapperStyle.position = "relative";
100
+ wrapperStyle.overflow = "hidden";
101
+ }
102
+ if (layout === "fixed") {
103
+ wrapperStyle.width = width;
104
+ wrapperStyle.height = height;
105
+ }
106
+ else if (layout === "constrained") {
107
+ if (!gatsbyImageIsInstalled()) {
108
+ wrapperStyle.display = "inline-block";
109
+ wrapperStyle.verticalAlign = "top";
110
+ }
111
+ className = "gatsby-image-wrapper gatsby-image-wrapper-constrained";
112
+ }
113
+ return {
114
+ className: className,
115
+ "data-gatsby-image-wrapper": "",
116
+ style: wrapperStyle
117
+ };
118
+ }
119
+ exports.getWrapperProps = getWrapperProps;
120
+ /**
121
+ * Use this hook to generate gatsby-plugin-image data in the browser.
122
+ */
123
+ function getImageData(_a) {
124
+ var baseUrl = _a.baseUrl, urlBuilder = _a.urlBuilder, sourceWidth = _a.sourceWidth, sourceHeight = _a.sourceHeight, _b = _a.pluginName, pluginName = _b === void 0 ? "getImageData" : _b, _c = _a.formats, formats = _c === void 0 ? ["auto"] : _c, breakpoints = _a.breakpoints, options = _a.options, props = __rest(_a, ["baseUrl", "urlBuilder", "sourceWidth", "sourceHeight", "pluginName", "formats", "breakpoints", "options"]);
125
+ if (!(breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.length) &&
126
+ (props.layout === "fullWidth" || props.layout === "FULL_WIDTH")) {
127
+ breakpoints = image_utils_1.EVERY_BREAKPOINT;
128
+ }
129
+ var generateImageSource = function (baseUrl, width, height, format) {
130
+ return {
131
+ width: width,
132
+ height: height,
133
+ format: format,
134
+ src: urlBuilder({ baseUrl: baseUrl, width: width, height: height, options: options, format: format })
135
+ };
136
+ };
137
+ var sourceMetadata = {
138
+ width: sourceWidth,
139
+ height: sourceHeight,
140
+ format: "auto"
141
+ };
142
+ var args = __assign(__assign({}, props), { pluginName: pluginName, generateImageSource: generateImageSource, filename: baseUrl, formats: formats, breakpoints: breakpoints, sourceMetadata: sourceMetadata });
143
+ return (0, image_utils_1.generateImageData)(args);
144
+ }
145
+ exports.getImageData = getImageData;
146
+ function getMainProps(isLoading, isLoaded, images, loading, style) {
147
+ if (style === void 0) { style = {}; }
148
+ // fallback when it's not configured in gatsby-config.
149
+ if (!gatsbyImageIsInstalled()) {
150
+ style = __assign({ height: "100%", left: 0, position: "absolute", top: 0, transform: "translateZ(0)", transition: "opacity 250ms linear", width: "100%", willChange: "opacity" }, style);
151
+ }
152
+ var result = __assign(__assign({}, images), { loading: loading, shouldLoad: isLoading, "data-main-image": "", style: __assign(__assign({}, style), { opacity: isLoaded ? 1 : 0 }) });
153
+ return result;
154
+ }
155
+ exports.getMainProps = getMainProps;
156
+ function getPlaceholderProps(placeholder, isLoaded, layout, width, height, backgroundColor, objectFit, objectPosition) {
157
+ var wrapperStyle = {};
158
+ if (backgroundColor) {
159
+ wrapperStyle.backgroundColor = backgroundColor;
160
+ if (layout === "fixed") {
161
+ wrapperStyle.width = width;
162
+ wrapperStyle.height = height;
163
+ wrapperStyle.backgroundColor = backgroundColor;
164
+ wrapperStyle.position = "relative";
165
+ }
166
+ else if (layout === "constrained") {
167
+ wrapperStyle.position = "absolute";
168
+ wrapperStyle.top = 0;
169
+ wrapperStyle.left = 0;
170
+ wrapperStyle.bottom = 0;
171
+ wrapperStyle.right = 0;
172
+ }
173
+ else if (layout === "fullWidth") {
174
+ wrapperStyle.position = "absolute";
175
+ wrapperStyle.top = 0;
176
+ wrapperStyle.left = 0;
177
+ wrapperStyle.bottom = 0;
178
+ wrapperStyle.right = 0;
179
+ }
180
+ }
181
+ if (objectFit) {
182
+ wrapperStyle.objectFit = objectFit;
183
+ }
184
+ if (objectPosition) {
185
+ wrapperStyle.objectPosition = objectPosition;
186
+ }
187
+ var result = __assign(__assign({}, placeholder), { "aria-hidden": true, "data-placeholder-image": "", style: __assign({ opacity: isLoaded ? 0 : 1, transition: "opacity 500ms linear" }, wrapperStyle) });
188
+ // fallback when it's not configured in gatsby-config.
189
+ if (!gatsbyImageIsInstalled()) {
190
+ result.style = {
191
+ height: "100%",
192
+ left: 0,
193
+ position: "absolute",
194
+ top: 0,
195
+ width: "100%"
196
+ };
197
+ }
198
+ return result;
199
+ }
200
+ exports.getPlaceholderProps = getPlaceholderProps;
201
+ /**
202
+ * Generate a Gatsby image data object with multiple, art-directed images that display at different
203
+ * resolutions.
204
+ *
205
+ * @param defaultImage The image displayed when no media query matches.
206
+ * It is also used for all other settings applied to the image, such as width, height and layout.
207
+ * You should pass a className to the component with media queries to adjust the size of the container,
208
+ * as this cannot be adjusted automatically.
209
+ * @param artDirected Array of objects which each contains a `media` string which is a media query
210
+ * such as `(min-width: 320px)`, and the image object to use when that query matches.
211
+ */
212
+ function withArtDirection(defaultImage, artDirected) {
213
+ var _a, _b;
214
+ var _c;
215
+ var images = defaultImage.images, placeholder = defaultImage.placeholder, props = __rest(defaultImage, ["images", "placeholder"]);
216
+ var output = __assign(__assign({}, props), { images: __assign(__assign({}, images), { sources: [] }), placeholder: placeholder && __assign(__assign({}, placeholder), { sources: [] }) });
217
+ artDirected.forEach(function (_a) {
218
+ var _b;
219
+ var media = _a.media, image = _a.image;
220
+ if (!media) {
221
+ if (process.env.NODE_ENV === "development") {
222
+ console.warn("[gatsby-plugin-image] All art-directed images passed to must have a value set for `media`. Skipping.");
223
+ }
224
+ return;
225
+ }
226
+ if (image.layout !== defaultImage.layout &&
227
+ process.env.NODE_ENV === "development") {
228
+ console.warn("[gatsby-plugin-image] Mismatched image layout: expected \"".concat(defaultImage.layout, "\" but received \"").concat(image.layout, "\". All art-directed images use the same layout as the default image"));
229
+ }
230
+ (_b = output.images.sources).push.apply(_b, __spreadArray(__spreadArray([], __read(image.images.sources.map(function (source) {
231
+ return __assign(__assign({}, source), { media: media });
232
+ })), false), [{
233
+ media: media,
234
+ srcSet: image.images.fallback.srcSet
235
+ }], false));
236
+ if (!output.placeholder) {
237
+ return;
238
+ }
239
+ output.placeholder.sources.push({
240
+ media: media,
241
+ srcSet: image.placeholder.fallback
242
+ });
243
+ });
244
+ (_a = output.images.sources).push.apply(_a, __spreadArray([], __read(images.sources), false));
245
+ if (placeholder === null || placeholder === void 0 ? void 0 : placeholder.sources) {
246
+ (_c = output.placeholder) === null || _c === void 0 ? void 0 : (_b = _c.sources).push.apply(_b, __spreadArray([], __read(placeholder.sources), false));
247
+ }
248
+ return output;
249
+ }
250
+ exports.withArtDirection = withArtDirection;
@@ -1,53 +1,53 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.createIntersectionObserver = void 0;
4
- var intersectionObserver;
5
- var ioEntryMap = new WeakMap();
6
- /* eslint-disable @typescript-eslint/no-explicit-any */
7
- var connection = navigator.connection ||
8
- navigator.mozConnection ||
9
- navigator.webkitConnection;
10
- /* eslint-enable @typescript-eslint/no-explicit-any */
11
- // These match the thresholds used in Chrome's native lazy loading
12
- // @see https://web.dev/browser-level-image-lazy-loading/#distance-from-viewport-thresholds
13
- var FAST_CONNECTION_THRESHOLD = "1250px";
14
- var SLOW_CONNECTION_THRESHOLD = "2500px";
15
- function createIntersectionObserver(callback) {
16
- var connectionType = connection === null || connection === void 0 ? void 0 : connection.effectiveType;
17
- // if we don't support intersectionObserver we don't lazy load (Sorry IE 11).
18
- if (!("IntersectionObserver" in window)) {
19
- return function observe() {
20
- callback();
21
- return function unobserve() { };
22
- };
23
- }
24
- if (!intersectionObserver) {
25
- intersectionObserver = new IntersectionObserver(function (entries) {
26
- entries.forEach(function (entry) {
27
- var _a;
28
- if (entry.isIntersecting) {
29
- // Get the matching entry's callback and call it
30
- (_a = ioEntryMap.get(entry.target)) === null || _a === void 0 ? void 0 : _a();
31
- // We only need to call it once
32
- ioEntryMap["delete"](entry.target);
33
- }
34
- });
35
- }, {
36
- rootMargin: connectionType === "4g" && !(connection === null || connection === void 0 ? void 0 : connection.saveData)
37
- ? FAST_CONNECTION_THRESHOLD
38
- : SLOW_CONNECTION_THRESHOLD
39
- });
40
- }
41
- return function observe(element) {
42
- // Store a reference to the callback mapped to the element being watched
43
- ioEntryMap.set(element, callback);
44
- intersectionObserver.observe(element);
45
- return function unobserve() {
46
- if (intersectionObserver && element) {
47
- ioEntryMap["delete"](element);
48
- intersectionObserver.unobserve(element);
49
- }
50
- };
51
- };
52
- }
53
- exports.createIntersectionObserver = createIntersectionObserver;
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.createIntersectionObserver = void 0;
4
+ var intersectionObserver;
5
+ var ioEntryMap = new WeakMap();
6
+ /* eslint-disable @typescript-eslint/no-explicit-any */
7
+ var connection = navigator.connection ||
8
+ navigator.mozConnection ||
9
+ navigator.webkitConnection;
10
+ /* eslint-enable @typescript-eslint/no-explicit-any */
11
+ // These match the thresholds used in Chrome's native lazy loading
12
+ // @see https://web.dev/browser-level-image-lazy-loading/#distance-from-viewport-thresholds
13
+ var FAST_CONNECTION_THRESHOLD = "1250px";
14
+ var SLOW_CONNECTION_THRESHOLD = "2500px";
15
+ function createIntersectionObserver(callback) {
16
+ var connectionType = connection === null || connection === void 0 ? void 0 : connection.effectiveType;
17
+ // if we don't support intersectionObserver we don't lazy load (Sorry IE 11).
18
+ if (!("IntersectionObserver" in window)) {
19
+ return function observe() {
20
+ callback();
21
+ return function unobserve() { };
22
+ };
23
+ }
24
+ if (!intersectionObserver) {
25
+ intersectionObserver = new IntersectionObserver(function (entries) {
26
+ entries.forEach(function (entry) {
27
+ var _a;
28
+ if (entry.isIntersecting) {
29
+ // Get the matching entry's callback and call it
30
+ (_a = ioEntryMap.get(entry.target)) === null || _a === void 0 ? void 0 : _a();
31
+ // We only need to call it once
32
+ ioEntryMap["delete"](entry.target);
33
+ }
34
+ });
35
+ }, {
36
+ rootMargin: connectionType === "4g" && !(connection === null || connection === void 0 ? void 0 : connection.saveData)
37
+ ? FAST_CONNECTION_THRESHOLD
38
+ : SLOW_CONNECTION_THRESHOLD
39
+ });
40
+ }
41
+ return function observe(element) {
42
+ // Store a reference to the callback mapped to the element being watched
43
+ ioEntryMap.set(element, callback);
44
+ intersectionObserver.observe(element);
45
+ return function unobserve() {
46
+ if (intersectionObserver && element) {
47
+ ioEntryMap["delete"](element);
48
+ intersectionObserver.unobserve(element);
49
+ }
50
+ };
51
+ };
52
+ }
53
+ exports.createIntersectionObserver = createIntersectionObserver;