gatsby-plugin-image 3.9.0-next.0 → 3.10.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/babel-helpers.js +3 -3
- package/dist/babel-plugin-parse-static-images.js +6 -6
- package/dist/components/gatsby-image.browser.js +10 -10
- package/dist/components/gatsby-image.server.js +9 -9
- package/dist/components/hooks.js +7 -7
- package/dist/components/intersection-observer.js +4 -4
- package/dist/components/layout-wrapper.js +10 -10
- package/dist/components/lazy-hydrate.js +10 -9
- package/dist/components/main-image.js +5 -5
- package/dist/components/picture.js +10 -10
- package/dist/components/placeholder.js +5 -5
- package/dist/components/static-image.server.js +6 -6
- package/dist/gatsby-image.js +1 -1
- package/dist/gatsby-image.js.map +1 -1
- package/dist/gatsby-image.module.js +1 -1
- package/dist/gatsby-image.module.js.map +1 -1
- package/dist/gatsby-node.js +5 -5
- package/dist/global.js +1 -1
- package/dist/image-utils.js +17 -17
- package/dist/index.browser-006c3456.js +1 -1
- package/dist/index.browser-006c3456.js.map +1 -1
- package/dist/index.browser-395cc902.js +1 -1
- package/dist/index.browser-395cc902.js.map +1 -1
- package/dist/index.js +12 -23
- package/dist/lazy-hydrate-6ff2d17c.js +1 -1
- package/dist/lazy-hydrate-6ff2d17c.js.map +1 -1
- package/dist/node-apis/image-processing.js +9 -9
- package/dist/node-apis/node-utils.js +2 -2
- package/dist/node-apis/parser.js +6 -6
- package/dist/node-apis/preprocess-source.js +10 -10
- package/dist/node-apis/watcher.js +3 -3
- package/dist/resolver-utils.js +27 -27
- package/dist/src/components/gatsby-image.browser.d.ts +32 -32
- package/dist/src/components/gatsby-image.server.d.ts +7 -7
- package/dist/src/components/hooks.d.ts +96 -96
- package/dist/src/components/intersection-observer.d.ts +2 -2
- package/dist/src/components/layout-wrapper.d.ts +9 -9
- package/dist/src/components/lazy-hydrate.d.ts +9 -9
- package/dist/src/components/main-image.d.ts +4 -4
- package/dist/src/components/picture.d.ts +23 -23
- package/dist/src/components/placeholder.d.ts +7 -7
- package/dist/src/components/static-image.d.ts +9 -9
- package/dist/src/components/static-image.server.d.ts +23 -23
- package/dist/src/gatsby-ssr.d.ts +2 -2
- package/dist/src/global.d.ts +5 -5
- package/dist/src/image-utils.d.ts +113 -113
- package/dist/src/index.browser.d.ts +7 -7
- package/dist/src/index.d.ts +8 -8
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.8.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-plugin-image@3.8.0/packages/gatsby-plugin-image) (2023-03-21)
|
|
7
|
+
|
|
8
|
+
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v5.8)
|
|
9
|
+
|
|
10
|
+
**Note:** Version bump only for package gatsby-plugin-image
|
|
11
|
+
|
|
6
12
|
## [3.7.0](https://github.com/gatsbyjs/gatsby/commits/gatsby-plugin-image@3.7.0/packages/gatsby-plugin-image) (2023-02-21)
|
|
7
13
|
|
|
8
14
|
[🧾 Release notes](https://www.gatsbyjs.com/docs/reference/release-notes/v5.7)
|
package/dist/babel-helpers.js
CHANGED
|
@@ -13,7 +13,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.hashOptions = exports.evaluateImageAttributes = exports.normalizeProps = exports.SHARP_ATTRIBUTES = void 0;
|
|
18
18
|
var murmurhash_1 = require("gatsby-core-utils/murmurhash");
|
|
19
19
|
var babel_jsx_utils_1 = require("babel-jsx-utils");
|
|
@@ -42,10 +42,10 @@ exports.SHARP_ATTRIBUTES = new Set([
|
|
|
42
42
|
function normalizeProps(props) {
|
|
43
43
|
var out = __assign({}, props);
|
|
44
44
|
if (out.layout) {
|
|
45
|
-
out.layout = (0, camelcase_1
|
|
45
|
+
out.layout = (0, camelcase_1.default)(out.layout);
|
|
46
46
|
}
|
|
47
47
|
if (out.placeholder) {
|
|
48
|
-
out.placeholder = (0, camelcase_1
|
|
48
|
+
out.placeholder = (0, camelcase_1.default)(out.placeholder);
|
|
49
49
|
if (out.placeholder === "tracedSvg") {
|
|
50
50
|
out.placeholder = "tracedSVG";
|
|
51
51
|
}
|
|
@@ -6,7 +6,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
6
6
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
8
|
};
|
|
9
|
-
exports
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
var babel_helpers_1 = require("./babel-helpers");
|
|
11
11
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
12
12
|
var path_1 = __importDefault(require("path"));
|
|
@@ -46,12 +46,12 @@ function attrs(_a) {
|
|
|
46
46
|
if (!cacheDir) {
|
|
47
47
|
console.warn("[gatsby-plugin-image] Couldn't find image data cache file");
|
|
48
48
|
}
|
|
49
|
-
var filename = path_1
|
|
49
|
+
var filename = path_1.default.join(cacheDir, "".concat(hash, ".json"));
|
|
50
50
|
var data;
|
|
51
51
|
// If there's no src prop there's no point in checking if it exists
|
|
52
52
|
if (!unresolvedProps.includes("src")) {
|
|
53
53
|
try {
|
|
54
|
-
data = fs_extra_1
|
|
54
|
+
data = fs_extra_1.default.readJSONSync(filename);
|
|
55
55
|
}
|
|
56
56
|
catch (e) {
|
|
57
57
|
// TODO add info about minimum Gatsby version once this is merged
|
|
@@ -76,9 +76,9 @@ function attrs(_a) {
|
|
|
76
76
|
var makeRequire = template.expression("require(\"".concat((0, gatsby_core_utils_1.slash)(filename), "\")"));
|
|
77
77
|
var newProp = t.jsxAttribute(t.jsxIdentifier("__imageData"), t.jsxExpressionContainer(makeRequire()));
|
|
78
78
|
nodePath.node.attributes.push(newProp);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
exports
|
|
83
|
+
exports.default = attrs;
|
|
84
84
|
var templateObject_1;
|
|
@@ -44,7 +44,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
44
44
|
}
|
|
45
45
|
return t;
|
|
46
46
|
};
|
|
47
|
-
exports
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.GatsbyImage = void 0;
|
|
49
49
|
var react_1 = require("react");
|
|
50
50
|
var hooks_1 = require("./hooks");
|
|
@@ -54,7 +54,7 @@ var imageCache = new Set();
|
|
|
54
54
|
var renderImageToStringPromise;
|
|
55
55
|
var renderImage;
|
|
56
56
|
var GatsbyImageHydrator = function GatsbyImageHydrator(_a) {
|
|
57
|
-
var _b = _a.as, as = _b === void 0 ? "div" : _b, image = _a.image, style = _a.style, backgroundColor = _a.backgroundColor, className = _a.className, preactClass = _a
|
|
57
|
+
var _b = _a.as, as = _b === void 0 ? "div" : _b, image = _a.image, style = _a.style, backgroundColor = _a.backgroundColor, className = _a.className, preactClass = _a.class, onStartLoad = _a.onStartLoad, onLoad = _a.onLoad, onError = _a.onError, props = __rest(_a, ["as", "image", "style", "backgroundColor", "className", "class", "onStartLoad", "onLoad", "onError"]);
|
|
58
58
|
var width = image.width, height = image.height, layout = image.layout;
|
|
59
59
|
var _c = (0, hooks_1.getWrapperProps)(width, height, layout), wStyle = _c.style, wClass = _c.className, wrapperProps = __rest(_c, ["style", "className"]);
|
|
60
60
|
var root = (0, react_1.useRef)();
|
|
@@ -71,7 +71,7 @@ var GatsbyImageHydrator = function GatsbyImageHydrator(_a) {
|
|
|
71
71
|
renderImage = renderImageToString;
|
|
72
72
|
return {
|
|
73
73
|
renderImageToString: renderImageToString,
|
|
74
|
-
swapPlaceholderImage: swapPlaceholderImage
|
|
74
|
+
swapPlaceholderImage: swapPlaceholderImage,
|
|
75
75
|
};
|
|
76
76
|
});
|
|
77
77
|
}
|
|
@@ -82,10 +82,10 @@ var GatsbyImageHydrator = function GatsbyImageHydrator(_a) {
|
|
|
82
82
|
if (ssrImage.complete) {
|
|
83
83
|
// Trigger onStartload and onLoad events
|
|
84
84
|
onStartLoad === null || onStartLoad === void 0 ? void 0 : onStartLoad({
|
|
85
|
-
wasCached: true
|
|
85
|
+
wasCached: true,
|
|
86
86
|
});
|
|
87
87
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
88
|
-
wasCached: true
|
|
88
|
+
wasCached: true,
|
|
89
89
|
});
|
|
90
90
|
// remove ssr key for state updates but add delay to not fight with native code snippt of gatsby-ssr
|
|
91
91
|
setTimeout(function () {
|
|
@@ -94,12 +94,12 @@ var GatsbyImageHydrator = function GatsbyImageHydrator(_a) {
|
|
|
94
94
|
}
|
|
95
95
|
else {
|
|
96
96
|
onStartLoad === null || onStartLoad === void 0 ? void 0 : onStartLoad({
|
|
97
|
-
wasCached: true
|
|
97
|
+
wasCached: true,
|
|
98
98
|
});
|
|
99
99
|
ssrImage.addEventListener("load", function onLoadListener() {
|
|
100
100
|
ssrImage.removeEventListener("load", onLoadListener);
|
|
101
101
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
102
|
-
wasCached: true
|
|
102
|
+
wasCached: true,
|
|
103
103
|
});
|
|
104
104
|
// remove ssr key for state updates but add delay to not fight with native code snippt of gatsby-ssr
|
|
105
105
|
setTimeout(function () {
|
|
@@ -145,16 +145,16 @@ var GatsbyImageHydrator = function GatsbyImageHydrator(_a) {
|
|
|
145
145
|
root.current.innerHTML = renderImage(__assign({ isLoading: imageCache.has(cacheKey), isLoaded: imageCache.has(cacheKey), image: image }, props));
|
|
146
146
|
// Trigger onStartload and onLoad events
|
|
147
147
|
onStartLoad === null || onStartLoad === void 0 ? void 0 : onStartLoad({
|
|
148
|
-
wasCached: true
|
|
148
|
+
wasCached: true,
|
|
149
149
|
});
|
|
150
150
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
151
|
-
wasCached: true
|
|
151
|
+
wasCached: true,
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
}, [image]);
|
|
155
155
|
// By keeping all props equal React will keep the component in the DOM
|
|
156
156
|
return (0, react_1.createElement)(as, __assign(__assign({}, wrapperProps), { style: __assign(__assign(__assign({}, wStyle), style), { backgroundColor: backgroundColor }), className: "".concat(wClass).concat(className ? " ".concat(className) : ""), ref: root, dangerouslySetInnerHTML: {
|
|
157
|
-
__html: sizer
|
|
157
|
+
__html: sizer,
|
|
158
158
|
}, suppressHydrationWarning: true }));
|
|
159
159
|
};
|
|
160
160
|
exports.GatsbyImage = (0, react_1.memo)(function GatsbyImage(props) {
|
|
@@ -49,7 +49,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
49
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
|
-
exports
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.propTypes = exports.altValidator = exports.GatsbyImage = void 0;
|
|
54
54
|
var react_1 = __importDefault(require("react"));
|
|
55
55
|
var hooks_1 = require("./hooks");
|
|
@@ -59,7 +59,7 @@ var layout_wrapper_1 = require("./layout-wrapper");
|
|
|
59
59
|
var prop_types_1 = __importDefault(require("prop-types"));
|
|
60
60
|
var removeNewLines = function (str) { return str.replace(/\n/g, ""); };
|
|
61
61
|
var GatsbyImage = function GatsbyImage(_a) {
|
|
62
|
-
var _b = _a.as, as = _b === void 0 ? "div" : _b, className = _a.className, preactClass = _a
|
|
62
|
+
var _b = _a.as, as = _b === void 0 ? "div" : _b, className = _a.className, preactClass = _a.class, style = _a.style, image = _a.image, _c = _a.loading, loading = _c === void 0 ? "lazy" : _c, imgClassName = _a.imgClassName, imgStyle = _a.imgStyle, backgroundColor = _a.backgroundColor, objectFit = _a.objectFit, objectPosition = _a.objectPosition, props = __rest(_a, ["as", "className", "class", "style", "image", "loading", "imgClassName", "imgStyle", "backgroundColor", "objectFit", "objectPosition"]);
|
|
63
63
|
if (!image) {
|
|
64
64
|
console.warn("[gatsby-plugin-image] Missing image prop");
|
|
65
65
|
return null;
|
|
@@ -72,7 +72,7 @@ var GatsbyImage = function GatsbyImage(_a) {
|
|
|
72
72
|
var _d = (0, hooks_1.getWrapperProps)(width, height, layout), wStyle = _d.style, wClass = _d.className, wrapperProps = __rest(_d, ["style", "className"]);
|
|
73
73
|
var cleanedImages = {
|
|
74
74
|
fallback: undefined,
|
|
75
|
-
sources: []
|
|
75
|
+
sources: [],
|
|
76
76
|
};
|
|
77
77
|
if (images.fallback) {
|
|
78
78
|
cleanedImages.fallback = __assign(__assign({}, images.fallback), { srcSet: images.fallback.srcSet
|
|
@@ -84,9 +84,9 @@ var GatsbyImage = function GatsbyImage(_a) {
|
|
|
84
84
|
return __assign(__assign({}, source), { srcSet: removeNewLines(source.srcSet) });
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
return react_1
|
|
88
|
-
react_1
|
|
89
|
-
react_1
|
|
87
|
+
return react_1.default.createElement(as, __assign(__assign({}, wrapperProps), { style: __assign(__assign(__assign({}, wStyle), style), { backgroundColor: backgroundColor }), className: "".concat(wClass).concat(className ? " ".concat(className) : "") }), react_1.default.createElement(layout_wrapper_1.LayoutWrapper, { layout: layout, width: width, height: height },
|
|
88
|
+
react_1.default.createElement(placeholder_1.Placeholder, __assign({}, (0, hooks_1.getPlaceholderProps)(placeholder, false, layout, width, height, placeholderBackgroundColor, objectFit, objectPosition))),
|
|
89
|
+
react_1.default.createElement(main_image_1.MainImage, __assign({ "data-gatsby-image-ssr": "", className: imgClassName }, props, (0, hooks_1.getMainProps)(loading === "eager", false, cleanedImages, loading, imgStyle)))));
|
|
90
90
|
};
|
|
91
91
|
exports.GatsbyImage = GatsbyImage;
|
|
92
92
|
var altValidator = function (props, propName, componentName) {
|
|
@@ -97,10 +97,10 @@ var altValidator = function (props, propName, componentName) {
|
|
|
97
97
|
if (!props.alt && props.alt !== "") {
|
|
98
98
|
return new Error("The \"alt\" prop is required in ".concat(componentName, ". If the image is purely presentational then pass an empty string: e.g. alt=\"\". Learn more: https://a11y-style-guide.com/style-guide/section-media.html"));
|
|
99
99
|
}
|
|
100
|
-
return prop_types_1
|
|
100
|
+
return prop_types_1.default.string.apply(prop_types_1.default, __spreadArray([props, propName, componentName], __read(rest), false));
|
|
101
101
|
};
|
|
102
102
|
exports.altValidator = altValidator;
|
|
103
103
|
exports.propTypes = {
|
|
104
|
-
image: prop_types_1
|
|
105
|
-
alt: exports.altValidator
|
|
104
|
+
image: prop_types_1.default.object.isRequired,
|
|
105
|
+
alt: exports.altValidator,
|
|
106
106
|
};
|
package/dist/components/hooks.js
CHANGED
|
@@ -46,7 +46,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
46
46
|
}
|
|
47
47
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
48
|
};
|
|
49
|
-
exports
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.withArtDirection = exports.getPlaceholderProps = exports.getMainProps = exports.getImageData = exports.getWrapperProps = exports.getSrcSet = exports.getSrc = exports.getImage = exports.gatsbyImageIsInstalled = exports.hasNativeLazyLoadSupport = void 0;
|
|
51
51
|
/* global GATSBY___IMAGE */
|
|
52
52
|
var image_utils_1 = require("../image-utils");
|
|
@@ -114,7 +114,7 @@ function getWrapperProps(width, height, layout) {
|
|
|
114
114
|
return {
|
|
115
115
|
className: className,
|
|
116
116
|
"data-gatsby-image-wrapper": "",
|
|
117
|
-
style: wrapperStyle
|
|
117
|
+
style: wrapperStyle,
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
exports.getWrapperProps = getWrapperProps;
|
|
@@ -132,13 +132,13 @@ function getImageData(_a) {
|
|
|
132
132
|
width: width,
|
|
133
133
|
height: height,
|
|
134
134
|
format: format,
|
|
135
|
-
src: urlBuilder({ baseUrl: baseUrl, width: width, height: height, options: options, format: format })
|
|
135
|
+
src: urlBuilder({ baseUrl: baseUrl, width: width, height: height, options: options, format: format }),
|
|
136
136
|
};
|
|
137
137
|
};
|
|
138
138
|
var sourceMetadata = {
|
|
139
139
|
width: sourceWidth,
|
|
140
140
|
height: sourceHeight,
|
|
141
|
-
format: "auto"
|
|
141
|
+
format: "auto",
|
|
142
142
|
};
|
|
143
143
|
var args = __assign(__assign({}, props), { pluginName: pluginName, generateImageSource: generateImageSource, filename: baseUrl, formats: formats, breakpoints: breakpoints, sourceMetadata: sourceMetadata });
|
|
144
144
|
return (0, image_utils_1.generateImageData)(args);
|
|
@@ -193,7 +193,7 @@ function getPlaceholderProps(placeholder, isLoaded, layout, width, height, backg
|
|
|
193
193
|
left: 0,
|
|
194
194
|
position: "absolute",
|
|
195
195
|
top: 0,
|
|
196
|
-
width: "100%"
|
|
196
|
+
width: "100%",
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
199
|
return result;
|
|
@@ -232,14 +232,14 @@ function withArtDirection(defaultImage, artDirected) {
|
|
|
232
232
|
return __assign(__assign({}, source), { media: media });
|
|
233
233
|
})), false), [{
|
|
234
234
|
media: media,
|
|
235
|
-
srcSet: image.images.fallback.srcSet
|
|
235
|
+
srcSet: image.images.fallback.srcSet,
|
|
236
236
|
}], false));
|
|
237
237
|
if (!output.placeholder) {
|
|
238
238
|
return;
|
|
239
239
|
}
|
|
240
240
|
output.placeholder.sources.push({
|
|
241
241
|
media: media,
|
|
242
|
-
srcSet: image.placeholder.fallback
|
|
242
|
+
srcSet: image.placeholder.fallback,
|
|
243
243
|
});
|
|
244
244
|
});
|
|
245
245
|
(_a = output.images.sources).push.apply(_a, __spreadArray([], __read(images.sources), false));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createIntersectionObserver = void 0;
|
|
4
4
|
var intersectionObserver;
|
|
5
5
|
var ioEntryMap = new WeakMap();
|
|
@@ -29,13 +29,13 @@ function createIntersectionObserver(callback) {
|
|
|
29
29
|
// Get the matching entry's callback and call it
|
|
30
30
|
(_a = ioEntryMap.get(entry.target)) === null || _a === void 0 ? void 0 : _a();
|
|
31
31
|
// We only need to call it once
|
|
32
|
-
ioEntryMap
|
|
32
|
+
ioEntryMap.delete(entry.target);
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
}, {
|
|
36
36
|
rootMargin: connectionType === "4g" && !(connection === null || connection === void 0 ? void 0 : connection.saveData)
|
|
37
37
|
? FAST_CONNECTION_THRESHOLD
|
|
38
|
-
: SLOW_CONNECTION_THRESHOLD
|
|
38
|
+
: SLOW_CONNECTION_THRESHOLD,
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
return function observe(element) {
|
|
@@ -44,7 +44,7 @@ function createIntersectionObserver(callback) {
|
|
|
44
44
|
intersectionObserver.observe(element);
|
|
45
45
|
return function unobserve() {
|
|
46
46
|
if (intersectionObserver && element) {
|
|
47
|
-
ioEntryMap
|
|
47
|
+
ioEntryMap.delete(element);
|
|
48
48
|
intersectionObserver.unobserve(element);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
@@ -51,12 +51,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
51
51
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
52
52
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
53
53
|
};
|
|
54
|
-
exports
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
55
|
exports.LayoutWrapper = exports.getSizer = void 0;
|
|
56
56
|
var react_1 = __importStar(require("react"));
|
|
57
57
|
var terser_macro_1 = __importDefault(require("../../macros/terser.macro"));
|
|
58
|
-
var NativeScriptLoading = function () { return (react_1
|
|
59
|
-
__html: (0, terser_macro_1
|
|
58
|
+
var NativeScriptLoading = function () { return (react_1.default.createElement("script", { type: "module", dangerouslySetInnerHTML: {
|
|
59
|
+
__html: (0, terser_macro_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\nconst hasNativeLazyLoadSupport = typeof HTMLImageElement !== \"undefined\" && \"loading\" in HTMLImageElement.prototype;\nif (hasNativeLazyLoadSupport) {\n const gatsbyImages = document.querySelectorAll('img[data-main-image]');\n for (let mainImage of gatsbyImages) {\n if (mainImage.dataset.src) {\n mainImage.setAttribute('src', mainImage.dataset.src)\n mainImage.removeAttribute('data-src')\n }\n if (mainImage.dataset.srcset) {\n mainImage.setAttribute('srcset', mainImage.dataset.srcset)\n mainImage.removeAttribute('data-srcset')\n }\n\n const sources = mainImage.parentNode.querySelectorAll('source[data-srcset]');\n for (let source of sources) {\n source.setAttribute('srcset', source.dataset.srcset)\n source.removeAttribute('data-srcset')\n }\n\n if (mainImage.complete) {\n mainImage.style.opacity = 1;\n\n // also hide the placeholder\n mainImage.parentNode.parentNode.querySelector('[data-placeholder-image]').style.opacity = 0;\n }\n }\n}\n"], ["\nconst hasNativeLazyLoadSupport = typeof HTMLImageElement !== \"undefined\" && \"loading\" in HTMLImageElement.prototype;\nif (hasNativeLazyLoadSupport) {\n const gatsbyImages = document.querySelectorAll('img[data-main-image]');\n for (let mainImage of gatsbyImages) {\n if (mainImage.dataset.src) {\n mainImage.setAttribute('src', mainImage.dataset.src)\n mainImage.removeAttribute('data-src')\n }\n if (mainImage.dataset.srcset) {\n mainImage.setAttribute('srcset', mainImage.dataset.srcset)\n mainImage.removeAttribute('data-srcset')\n }\n\n const sources = mainImage.parentNode.querySelectorAll('source[data-srcset]');\n for (let source of sources) {\n source.setAttribute('srcset', source.dataset.srcset)\n source.removeAttribute('data-srcset')\n }\n\n if (mainImage.complete) {\n mainImage.style.opacity = 1;\n\n // also hide the placeholder\n mainImage.parentNode.parentNode.querySelector('[data-placeholder-image]').style.opacity = 0;\n }\n }\n}\n"]))),
|
|
60
60
|
} })); };
|
|
61
61
|
function getSizer(layout, width, height) {
|
|
62
62
|
var sizer = "";
|
|
@@ -72,24 +72,24 @@ exports.getSizer = getSizer;
|
|
|
72
72
|
var Sizer = function Sizer(_a) {
|
|
73
73
|
var layout = _a.layout, width = _a.width, height = _a.height;
|
|
74
74
|
if (layout === "fullWidth") {
|
|
75
|
-
return (react_1
|
|
75
|
+
return (react_1.default.createElement("div", { "aria-hidden": true, style: { paddingTop: "".concat((height / width) * 100, "%") } }));
|
|
76
76
|
}
|
|
77
77
|
if (layout === "constrained") {
|
|
78
|
-
return (react_1
|
|
79
|
-
react_1
|
|
78
|
+
return (react_1.default.createElement("div", { style: { maxWidth: width, display: "block" } },
|
|
79
|
+
react_1.default.createElement("img", { alt: "", role: "presentation", "aria-hidden": "true", src: "data:image/svg+xml;charset=utf-8,%3Csvg%20height='".concat(height, "'%20width='").concat(width, "'%20xmlns='http://www.w3.org/2000/svg'%20version='1.1'%3E%3C/svg%3E"), style: {
|
|
80
80
|
maxWidth: "100%",
|
|
81
81
|
display: "block",
|
|
82
|
-
position: "static"
|
|
82
|
+
position: "static",
|
|
83
83
|
} })));
|
|
84
84
|
}
|
|
85
85
|
return null;
|
|
86
86
|
};
|
|
87
87
|
var LayoutWrapper = function LayoutWrapper(_a) {
|
|
88
88
|
var children = _a.children, props = __rest(_a, ["children"]);
|
|
89
|
-
return (react_1
|
|
90
|
-
react_1
|
|
89
|
+
return (react_1.default.createElement(react_1.Fragment, null,
|
|
90
|
+
react_1.default.createElement(Sizer, __assign({}, props)),
|
|
91
91
|
children,
|
|
92
|
-
SERVER ? react_1
|
|
92
|
+
SERVER ? react_1.default.createElement(NativeScriptLoading, null) : null));
|
|
93
93
|
};
|
|
94
94
|
exports.LayoutWrapper = LayoutWrapper;
|
|
95
95
|
var templateObject_1;
|
|
@@ -83,7 +83,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
83
83
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
84
84
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
85
85
|
};
|
|
86
|
-
exports
|
|
86
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87
87
|
exports.renderImageToString = exports.swapPlaceholderImage = void 0;
|
|
88
88
|
var react_1 = __importDefault(require("react"));
|
|
89
89
|
var server_1 = require("react-dom/server");
|
|
@@ -137,9 +137,10 @@ function startLoading(element, cacheKey, imageCache, onStartLoad, onLoad, onErro
|
|
|
137
137
|
// eslint-disable-next-line @babel/no-invalid-this
|
|
138
138
|
toggleLoaded(_this, placeholderImage);
|
|
139
139
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
140
|
-
wasCached: isCached
|
|
140
|
+
wasCached: isCached,
|
|
141
141
|
});
|
|
142
|
-
})
|
|
142
|
+
})
|
|
143
|
+
.catch(function (e) {
|
|
143
144
|
// eslint-disable-next-line @babel/no-invalid-this
|
|
144
145
|
toggleLoaded(_this, placeholderImage);
|
|
145
146
|
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
@@ -149,13 +150,13 @@ function startLoading(element, cacheKey, imageCache, onStartLoad, onLoad, onErro
|
|
|
149
150
|
// eslint-disable-next-line @babel/no-invalid-this
|
|
150
151
|
toggleLoaded(this, placeholderImage);
|
|
151
152
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
152
|
-
wasCached: isCached
|
|
153
|
+
wasCached: isCached,
|
|
153
154
|
});
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
mainImage.addEventListener("load", onImageLoaded);
|
|
157
158
|
onStartLoad === null || onStartLoad === void 0 ? void 0 : onStartLoad({
|
|
158
|
-
wasCached: isCached
|
|
159
|
+
wasCached: isCached,
|
|
159
160
|
});
|
|
160
161
|
Array.from(mainImage.parentElement.children).forEach(function (child) {
|
|
161
162
|
var src = child.getAttribute("data-src");
|
|
@@ -174,7 +175,7 @@ function startLoading(element, cacheKey, imageCache, onStartLoad, onLoad, onErro
|
|
|
174
175
|
// We check if the image is already completed and if so we trigger onload.
|
|
175
176
|
if (mainImage.complete) {
|
|
176
177
|
onImageLoaded.call(mainImage, {
|
|
177
|
-
currentTarget: mainImage
|
|
178
|
+
currentTarget: mainImage,
|
|
178
179
|
});
|
|
179
180
|
}
|
|
180
181
|
return function () {
|
|
@@ -211,8 +212,8 @@ function renderImageToString(_a) {
|
|
|
211
212
|
var image = _a.image, _b = _a.loading, loading = _b === void 0 ? "lazy" : _b, isLoading = _a.isLoading, isLoaded = _a.isLoaded, imgClassName = _a.imgClassName, _c = _a.imgStyle, imgStyle = _c === void 0 ? {} : _c, objectPosition = _a.objectPosition, backgroundColor = _a.backgroundColor, _d = _a.objectFit, objectFit = _d === void 0 ? "cover" : _d, props = __rest(_a, ["image", "loading", "isLoading", "isLoaded", "imgClassName", "imgStyle", "objectPosition", "backgroundColor", "objectFit"]);
|
|
212
213
|
var width = image.width, height = image.height, layout = image.layout, images = image.images, placeholder = image.placeholder, wrapperBackgroundColor = image.backgroundColor;
|
|
213
214
|
imgStyle = __assign({ objectFit: objectFit, objectPosition: objectPosition, backgroundColor: backgroundColor }, imgStyle);
|
|
214
|
-
return (0, server_1.renderToStaticMarkup)(react_1
|
|
215
|
-
react_1
|
|
216
|
-
react_1
|
|
215
|
+
return (0, server_1.renderToStaticMarkup)(react_1.default.createElement(layout_wrapper_1.LayoutWrapper, { layout: layout, width: width, height: height },
|
|
216
|
+
react_1.default.createElement(placeholder_1.Placeholder, __assign({}, (0, hooks_1.getPlaceholderProps)(placeholder, isLoaded, layout, width, height, wrapperBackgroundColor, objectFit, objectPosition))),
|
|
217
|
+
react_1.default.createElement(main_image_1.MainImage, __assign({}, props, { width: width, height: height, className: imgClassName }, (0, hooks_1.getMainProps)(isLoading, isLoaded, images, loading, imgStyle)))));
|
|
217
218
|
}
|
|
218
219
|
exports.renderImageToString = renderImageToString;
|
|
@@ -13,15 +13,15 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.MainImage = void 0;
|
|
18
18
|
var react_1 = __importDefault(require("react"));
|
|
19
19
|
var picture_1 = require("./picture");
|
|
20
20
|
var MainImage = function MainImage(props) {
|
|
21
|
-
return (react_1
|
|
22
|
-
react_1
|
|
23
|
-
react_1
|
|
24
|
-
react_1
|
|
21
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
22
|
+
react_1.default.createElement(picture_1.Picture, __assign({}, props)),
|
|
23
|
+
react_1.default.createElement("noscript", null,
|
|
24
|
+
react_1.default.createElement(picture_1.Picture, __assign({}, props, { shouldLoad: true })))));
|
|
25
25
|
};
|
|
26
26
|
exports.MainImage = MainImage;
|
|
27
27
|
exports.MainImage.displayName = "MainImage";
|
|
@@ -47,25 +47,25 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
47
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
49
|
};
|
|
50
|
-
exports
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
51
|
exports.Picture = void 0;
|
|
52
52
|
var react_1 = __importDefault(require("react"));
|
|
53
53
|
var PropTypes = __importStar(require("prop-types"));
|
|
54
54
|
var Image = function Image(_a) {
|
|
55
55
|
var src = _a.src, srcSet = _a.srcSet, loading = _a.loading, _b = _a.alt, alt = _b === void 0 ? "" : _b, shouldLoad = _a.shouldLoad, props = __rest(_a, ["src", "srcSet", "loading", "alt", "shouldLoad"]);
|
|
56
|
-
return (react_1
|
|
56
|
+
return (react_1.default.createElement("img", __assign({}, props, { decoding: "async", loading: loading, src: shouldLoad ? src : undefined, "data-src": !shouldLoad ? src : undefined, srcSet: shouldLoad ? srcSet : undefined, "data-srcset": !shouldLoad ? srcSet : undefined, alt: alt })));
|
|
57
57
|
};
|
|
58
58
|
var Picture = function Picture(_a) {
|
|
59
59
|
var fallback = _a.fallback, _b = _a.sources, sources = _b === void 0 ? [] : _b, _c = _a.shouldLoad, shouldLoad = _c === void 0 ? true : _c, props = __rest(_a, ["fallback", "sources", "shouldLoad"]);
|
|
60
60
|
var sizes = props.sizes || (fallback === null || fallback === void 0 ? void 0 : fallback.sizes);
|
|
61
|
-
var fallbackImage = (react_1
|
|
61
|
+
var fallbackImage = (react_1.default.createElement(Image, __assign({}, props, fallback, { sizes: sizes, shouldLoad: shouldLoad })));
|
|
62
62
|
if (!sources.length) {
|
|
63
63
|
return fallbackImage;
|
|
64
64
|
}
|
|
65
|
-
return (react_1
|
|
65
|
+
return (react_1.default.createElement("picture", null,
|
|
66
66
|
sources.map(function (_a) {
|
|
67
67
|
var media = _a.media, srcSet = _a.srcSet, type = _a.type;
|
|
68
|
-
return (react_1
|
|
68
|
+
return (react_1.default.createElement("source", { key: "".concat(media, "-").concat(type, "-").concat(srcSet), type: type, media: media, srcSet: shouldLoad ? srcSet : undefined, "data-srcset": !shouldLoad ? srcSet : undefined, sizes: sizes }));
|
|
69
69
|
}),
|
|
70
70
|
fallbackImage));
|
|
71
71
|
};
|
|
@@ -75,7 +75,7 @@ Image.propTypes = {
|
|
|
75
75
|
alt: PropTypes.string.isRequired,
|
|
76
76
|
sizes: PropTypes.string,
|
|
77
77
|
srcSet: PropTypes.string,
|
|
78
|
-
shouldLoad: PropTypes.bool
|
|
78
|
+
shouldLoad: PropTypes.bool,
|
|
79
79
|
};
|
|
80
80
|
exports.Picture.displayName = "Picture";
|
|
81
81
|
exports.Picture.propTypes = {
|
|
@@ -84,20 +84,20 @@ exports.Picture.propTypes = {
|
|
|
84
84
|
fallback: PropTypes.exact({
|
|
85
85
|
src: PropTypes.string.isRequired,
|
|
86
86
|
srcSet: PropTypes.string,
|
|
87
|
-
sizes: PropTypes.string
|
|
87
|
+
sizes: PropTypes.string,
|
|
88
88
|
}),
|
|
89
89
|
sources: PropTypes.arrayOf(PropTypes.oneOfType([
|
|
90
90
|
PropTypes.exact({
|
|
91
91
|
media: PropTypes.string.isRequired,
|
|
92
92
|
type: PropTypes.string,
|
|
93
93
|
sizes: PropTypes.string,
|
|
94
|
-
srcSet: PropTypes.string.isRequired
|
|
94
|
+
srcSet: PropTypes.string.isRequired,
|
|
95
95
|
}),
|
|
96
96
|
PropTypes.exact({
|
|
97
97
|
media: PropTypes.string,
|
|
98
98
|
type: PropTypes.string.isRequired,
|
|
99
99
|
sizes: PropTypes.string,
|
|
100
|
-
srcSet: PropTypes.string.isRequired
|
|
100
|
+
srcSet: PropTypes.string.isRequired,
|
|
101
101
|
}),
|
|
102
|
-
]))
|
|
102
|
+
])),
|
|
103
103
|
};
|
|
@@ -48,7 +48,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
48
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
49
|
};
|
|
50
50
|
var _a;
|
|
51
|
-
exports
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
52
|
exports.Placeholder = void 0;
|
|
53
53
|
var react_1 = __importDefault(require("react"));
|
|
54
54
|
var PropTypes = __importStar(require("prop-types"));
|
|
@@ -56,12 +56,12 @@ var picture_1 = require("./picture");
|
|
|
56
56
|
var Placeholder = function Placeholder(_a) {
|
|
57
57
|
var fallback = _a.fallback, props = __rest(_a, ["fallback"]);
|
|
58
58
|
if (fallback) {
|
|
59
|
-
return (react_1
|
|
60
|
-
src: fallback
|
|
59
|
+
return (react_1.default.createElement(picture_1.Picture, __assign({}, props, { fallback: {
|
|
60
|
+
src: fallback,
|
|
61
61
|
}, "aria-hidden": true, alt: "" })));
|
|
62
62
|
}
|
|
63
63
|
else {
|
|
64
|
-
return react_1
|
|
64
|
+
return react_1.default.createElement("div", __assign({}, props));
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
exports.Placeholder = Placeholder;
|
|
@@ -74,5 +74,5 @@ exports.Placeholder.propTypes = {
|
|
|
74
74
|
return null;
|
|
75
75
|
}
|
|
76
76
|
return new Error("Invalid prop `".concat(propName, "` supplied to `").concat(componentName, "`. Validation failed."));
|
|
77
|
-
}
|
|
77
|
+
},
|
|
78
78
|
};
|
|
@@ -49,7 +49,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
49
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
|
-
exports
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.StaticImage = exports.propTypes = exports._getStaticImage = void 0;
|
|
54
54
|
var react_1 = __importDefault(require("react"));
|
|
55
55
|
var gatsby_image_server_1 = require("./gatsby-image.server");
|
|
@@ -66,7 +66,7 @@ function _getStaticImage(GatsbyImage) {
|
|
|
66
66
|
console.warn(__error);
|
|
67
67
|
}
|
|
68
68
|
if (imageData) {
|
|
69
|
-
return react_1
|
|
69
|
+
return react_1.default.createElement(GatsbyImage, __assign({ image: imageData }, props));
|
|
70
70
|
}
|
|
71
71
|
console.warn("Image not loaded", src);
|
|
72
72
|
if (!__error && process.env.NODE_ENV === "development") {
|
|
@@ -88,15 +88,15 @@ var checkDimensionProps = function (props, propName) {
|
|
|
88
88
|
props[propName]) {
|
|
89
89
|
return new Error("\"".concat(propName, "\" ").concat(props[propName], " may not be passed when layout is fullWidth."));
|
|
90
90
|
}
|
|
91
|
-
return prop_types_1
|
|
91
|
+
return prop_types_1.default.number.apply(prop_types_1.default, __spreadArray([props, propName], __read(rest), false));
|
|
92
92
|
};
|
|
93
93
|
var validLayouts = new Set(["fixed", "fullWidth", "constrained"]);
|
|
94
94
|
exports.propTypes = {
|
|
95
|
-
src: prop_types_1
|
|
95
|
+
src: prop_types_1.default.string.isRequired,
|
|
96
96
|
alt: gatsby_image_server_1.altValidator,
|
|
97
97
|
width: checkDimensionProps,
|
|
98
98
|
height: checkDimensionProps,
|
|
99
|
-
sizes: prop_types_1
|
|
99
|
+
sizes: prop_types_1.default.string,
|
|
100
100
|
layout: function (props) {
|
|
101
101
|
if (props.layout === undefined) {
|
|
102
102
|
return undefined;
|
|
@@ -105,7 +105,7 @@ exports.propTypes = {
|
|
|
105
105
|
return undefined;
|
|
106
106
|
}
|
|
107
107
|
return new Error("Invalid value ".concat(props.layout, "\" provided for prop \"layout\". Defaulting to \"constrained\". Valid values are \"fixed\", \"fullWidth\" or \"constrained\"."));
|
|
108
|
-
}
|
|
108
|
+
},
|
|
109
109
|
};
|
|
110
110
|
StaticImage.displayName = "StaticImage";
|
|
111
111
|
StaticImage.propTypes = exports.propTypes;
|