gatsby-plugin-image 2.14.0-next.3 → 2.15.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/dist/components/gatsby-image.browser.js +98 -197
- package/dist/components/gatsby-image.server.js +6 -12
- package/dist/components/hooks.js +12 -165
- package/dist/components/intersection-observer.js +6 -8
- package/dist/components/layout-wrapper.js +2 -5
- package/dist/components/lazy-hydrate.js +176 -37
- package/dist/components/main-image.js +7 -26
- package/dist/components/picture.js +10 -7
- package/dist/gatsby-image.browser.js +1 -1
- package/dist/gatsby-image.browser.modern.js +1 -1
- 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 +1 -3
- package/dist/global.js +2 -0
- package/dist/image-utils.js +1 -8
- package/dist/index.browser-bd6b0c0c.js +2 -0
- package/dist/index.browser-bd6b0c0c.js.map +1 -0
- package/dist/index.browser-cdba1a30.js +2 -0
- package/dist/index.browser-cdba1a30.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/lazy-hydrate-21b90201.js +2 -0
- package/dist/lazy-hydrate-21b90201.js.map +1 -0
- package/dist/lazy-hydrate-2ea962de.js +2 -0
- package/dist/lazy-hydrate-2ea962de.js.map +1 -0
- package/dist/src/components/gatsby-image.browser.d.ts +9 -7
- package/dist/src/components/gatsby-image.browser.d.ts.map +1 -1
- package/dist/src/components/gatsby-image.server.d.ts +3 -7
- package/dist/src/components/gatsby-image.server.d.ts.map +1 -1
- package/dist/src/components/hooks.d.ts +10 -15
- package/dist/src/components/hooks.d.ts.map +1 -1
- package/dist/src/components/intersection-observer.d.ts +1 -2
- package/dist/src/components/intersection-observer.d.ts.map +1 -1
- package/dist/src/components/layout-wrapper.d.ts +0 -1
- package/dist/src/components/layout-wrapper.d.ts.map +1 -1
- package/dist/src/components/lazy-hydrate.d.ts +4 -6
- package/dist/src/components/lazy-hydrate.d.ts.map +1 -1
- package/dist/src/components/main-image.d.ts +1 -8
- package/dist/src/components/main-image.d.ts.map +1 -1
- package/dist/src/components/picture.d.ts +1 -6
- package/dist/src/components/picture.d.ts.map +1 -1
- package/dist/src/gatsby-node.d.ts +1 -1
- package/dist/src/gatsby-ssr.d.ts.map +1 -1
- package/dist/src/global.d.ts +6 -0
- package/dist/src/global.d.ts.map +1 -0
- package/dist/src/image-utils.d.ts +1 -1
- package/dist/src/image-utils.d.ts.map +1 -1
- package/dist/src/index.browser.d.ts +1 -1
- package/dist/src/index.browser.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/resolver-utils.d.ts +3 -3
- package/gatsby-ssr.js +1 -1
- package/package.json +7 -8
- package/dist/gatsby-image.browser.module.js +0 -2
- package/dist/gatsby-image.browser.module.js.map +0 -1
- package/dist/index.browser-4e524ce6.js +0 -2
- package/dist/index.browser-4e524ce6.js.map +0 -1
- package/dist/index.browser-53efc75d.js +0 -2
- package/dist/index.browser-53efc75d.js.map +0 -1
- package/dist/index.browser-80ad8918.js +0 -3
- package/dist/index.browser-80ad8918.js.map +0 -1
- package/dist/intersection-observer-1b2d7fcb.js +0 -2
- package/dist/intersection-observer-1b2d7fcb.js.map +0 -1
- package/dist/intersection-observer-3d807f12.js +0 -2
- package/dist/intersection-observer-3d807f12.js.map +0 -1
- package/dist/intersection-observer-6b794dd8.js +0 -2
- package/dist/intersection-observer-6b794dd8.js.map +0 -1
- package/dist/lazy-hydrate-1b726509.js +0 -2
- package/dist/lazy-hydrate-1b726509.js.map +0 -1
- package/dist/lazy-hydrate-2d1e8cb4.js +0 -2
- package/dist/lazy-hydrate-2d1e8cb4.js.map +0 -1
- package/dist/lazy-hydrate-b920df6f.js +0 -2
- package/dist/lazy-hydrate-b920df6f.js.map +0 -1
- package/dist/src/components/later-hydrator.d.ts +0 -3
- package/dist/src/components/later-hydrator.d.ts.map +0 -1
- package/gatsby-browser.js +0 -6
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __assign = (this && this.__assign) || function () {
|
|
18
3
|
__assign = Object.assign || function(t) {
|
|
19
4
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -61,188 +46,115 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
61
46
|
};
|
|
62
47
|
exports.__esModule = true;
|
|
63
48
|
exports.GatsbyImage = void 0;
|
|
64
|
-
|
|
65
|
-
/* eslint-disable no-unused-expressions */
|
|
66
|
-
var react_1 = __importStar(require("react"));
|
|
49
|
+
var react_1 = require("react");
|
|
67
50
|
var hooks_1 = require("./hooks");
|
|
68
51
|
var layout_wrapper_1 = require("./layout-wrapper");
|
|
69
52
|
var gatsby_image_server_1 = require("./gatsby-image.server");
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
var reactDomClient_2 = require("react-dom");
|
|
83
|
-
reactRender = function (Component, el) {
|
|
84
|
-
reactDomClient_2.render(Component, el);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
var GatsbyImageHydrator = /** @class */ (function (_super) {
|
|
88
|
-
__extends(GatsbyImageHydrator, _super);
|
|
89
|
-
function GatsbyImageHydrator(props) {
|
|
90
|
-
var _this_1 = _super.call(this, props) || this;
|
|
91
|
-
_this_1.root = (0, react_1.createRef)();
|
|
92
|
-
_this_1.hydrated = { current: false };
|
|
93
|
-
_this_1.forceRender = {
|
|
94
|
-
// In dev we use render not hydrate, to avoid hydration warnings
|
|
95
|
-
current: process.env.NODE_ENV === "development"
|
|
96
|
-
};
|
|
97
|
-
_this_1.lazyHydrator = null;
|
|
98
|
-
_this_1.ref = (0, react_1.createRef)();
|
|
99
|
-
_this_1.reactRootRef = (0, react_1.createRef)();
|
|
100
|
-
_this_1.state = {
|
|
101
|
-
isLoading: (0, hooks_1.hasNativeLazyLoadSupport)(),
|
|
102
|
-
isLoaded: false
|
|
103
|
-
};
|
|
104
|
-
return _this_1;
|
|
53
|
+
var imageCache = new Set();
|
|
54
|
+
var renderImageToStringPromise;
|
|
55
|
+
var renderImage;
|
|
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["class"], onStartLoad = _a.onStartLoad, onLoad = _a.onLoad, onError = _a.onError, props = __rest(_a, ["as", "image", "style", "backgroundColor", "className", "class", "onStartLoad", "onLoad", "onError"]);
|
|
58
|
+
var width = image.width, height = image.height, layout = image.layout;
|
|
59
|
+
var _c = (0, hooks_1.getWrapperProps)(width, height, layout), wStyle = _c.style, wClass = _c.className, wrapperProps = __rest(_c, ["style", "className"]);
|
|
60
|
+
var root = (0, react_1.useRef)();
|
|
61
|
+
var cacheKey = (0, react_1.useMemo)(function () { return JSON.stringify(image.images); }, [image.images]);
|
|
62
|
+
// Preact uses class instead of className so we need to check for both
|
|
63
|
+
if (preactClass) {
|
|
64
|
+
className = preactClass;
|
|
105
65
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
66
|
+
var sizer = (0, layout_wrapper_1.getSizer)(layout, width, height);
|
|
67
|
+
(0, react_1.useEffect)(function () {
|
|
68
|
+
if (!renderImageToStringPromise) {
|
|
69
|
+
renderImageToStringPromise = Promise.resolve().then(function () { return __importStar(require("./lazy-hydrate")); }).then(function (_a) {
|
|
70
|
+
var renderImageToString = _a.renderImageToString, swapPlaceholderImage = _a.swapPlaceholderImage;
|
|
71
|
+
renderImage = renderImageToString;
|
|
72
|
+
return {
|
|
73
|
+
renderImageToString: renderImageToString,
|
|
74
|
+
swapPlaceholderImage: swapPlaceholderImage
|
|
75
|
+
};
|
|
76
|
+
});
|
|
113
77
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (_this_1.root.current) {
|
|
137
|
-
var cacheKey = JSON.stringify(_this_1.props.image.images);
|
|
138
|
-
(_b = (_a = _this_1.props).onStartLoad) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
139
|
-
wasCached: useCache && (0, hooks_1.hasImageLoaded)(cacheKey)
|
|
78
|
+
// The plugin image component is a bit special where if it's server-side rendered, we add extra script tags to support lazy-loading without
|
|
79
|
+
// In this case we stop hydration but fire the correct events.
|
|
80
|
+
var ssrImage = root.current.querySelector("[data-gatsby-image-ssr]");
|
|
81
|
+
if (ssrImage && (0, hooks_1.hasNativeLazyLoadSupport)()) {
|
|
82
|
+
if (ssrImage.complete) {
|
|
83
|
+
// Trigger onStartload and onLoad events
|
|
84
|
+
onStartLoad === null || onStartLoad === void 0 ? void 0 : onStartLoad({
|
|
85
|
+
wasCached: true
|
|
86
|
+
});
|
|
87
|
+
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
88
|
+
wasCached: true
|
|
89
|
+
});
|
|
90
|
+
// remove ssr key for state updates but add delay to not fight with native code snippt of gatsby-ssr
|
|
91
|
+
setTimeout(function () {
|
|
92
|
+
ssrImage.removeAttribute("data-gatsby-image-ssr");
|
|
93
|
+
}, 0);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
document.addEventListener("load", function onLoadListener() {
|
|
97
|
+
document.removeEventListener("load", onLoadListener);
|
|
98
|
+
onStartLoad === null || onStartLoad === void 0 ? void 0 : onStartLoad({
|
|
99
|
+
wasCached: true
|
|
140
100
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
isLoaded: useCache && (0, hooks_1.hasImageLoaded)(cacheKey)
|
|
101
|
+
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
102
|
+
wasCached: true
|
|
144
103
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
104
|
+
// remove ssr key for state updates but add delay to not fight with native code snippt of gatsby-ssr
|
|
105
|
+
setTimeout(function () {
|
|
106
|
+
ssrImage.removeAttribute("data-gatsby-image-ssr");
|
|
107
|
+
}, 0);
|
|
108
|
+
});
|
|
149
109
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
GatsbyImageHydrator.prototype.shouldComponentUpdate = function (nextProps, nextState) {
|
|
153
|
-
var _this_1 = this;
|
|
154
|
-
var hasChanged = false;
|
|
155
|
-
if (!this.state.isLoading && nextState.isLoading && !nextState.isLoaded) {
|
|
156
|
-
// Props have changed between SSR and hydration, so we need to force render instead of hydrate
|
|
157
|
-
this.forceRender.current = true;
|
|
110
|
+
imageCache.add(cacheKey);
|
|
111
|
+
return;
|
|
158
112
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// reset state, we'll rely on intersection observer to reload
|
|
162
|
-
if (this.unobserveRef) {
|
|
163
|
-
// unregister intersectionObserver
|
|
164
|
-
this.unobserveRef();
|
|
165
|
-
// // on unmount, make sure we cleanup
|
|
166
|
-
if (this.hydrated.current && this.lazyHydrator) {
|
|
167
|
-
this.reactRootRef.current = reactRender(null, this.root.current, this.reactRootRef.current);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
this.setState({
|
|
171
|
-
isLoading: false,
|
|
172
|
-
isLoaded: false
|
|
173
|
-
}, function () {
|
|
174
|
-
_this_1._setupIntersectionObserver(false);
|
|
175
|
-
});
|
|
176
|
-
hasChanged = true;
|
|
113
|
+
if (renderImage && imageCache.has(cacheKey)) {
|
|
114
|
+
return;
|
|
177
115
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if ((0, hooks_1.hasNativeLazyLoadSupport)() &&
|
|
190
|
-
ssrElement_1 &&
|
|
191
|
-
(0, hooks_1.gatsbyImageIsInstalled)()) {
|
|
192
|
-
(_b = (_a = this.props).onStartLoad) === null || _b === void 0 ? void 0 : _b.call(_a, { wasCached: false });
|
|
193
|
-
// When the image is already loaded before we have hydrated, we trigger onLoad and cache the item
|
|
194
|
-
if (ssrElement_1.complete) {
|
|
195
|
-
(_d = (_c = this.props).onLoad) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
196
|
-
(0, hooks_1.storeImageloaded)(cacheKey_1);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
// We need the current class context (this) inside our named onLoad function
|
|
200
|
-
// The named function is necessary to easily remove the listener afterward.
|
|
201
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
202
|
-
var _this_2 = this;
|
|
203
|
-
// add an onLoad to the image
|
|
204
|
-
ssrElement_1.addEventListener("load", function onLoad() {
|
|
205
|
-
var _a, _b;
|
|
206
|
-
ssrElement_1.removeEventListener("load", onLoad);
|
|
207
|
-
(_b = (_a = _this_2.props).onLoad) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
208
|
-
(0, hooks_1.storeImageloaded)(cacheKey_1);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return;
|
|
116
|
+
var animationFrame;
|
|
117
|
+
var cleanupCallback;
|
|
118
|
+
renderImageToStringPromise.then(function (_a) {
|
|
119
|
+
var renderImageToString = _a.renderImageToString, swapPlaceholderImage = _a.swapPlaceholderImage;
|
|
120
|
+
root.current.innerHTML = renderImageToString(__assign({ isLoading: true, isLoaded: imageCache.has(cacheKey), image: image }, props));
|
|
121
|
+
if (!imageCache.has(cacheKey)) {
|
|
122
|
+
animationFrame = requestAnimationFrame(function () {
|
|
123
|
+
if (root.current) {
|
|
124
|
+
cleanupCallback = swapPlaceholderImage(root.current, cacheKey, imageCache, style, onStartLoad, onLoad, onError);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
212
127
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// Cleanup when onmount happens
|
|
219
|
-
if (this.unobserveRef) {
|
|
220
|
-
// unregister intersectionObserver
|
|
221
|
-
this.unobserveRef();
|
|
222
|
-
// on unmount, make sure we cleanup
|
|
223
|
-
if (this.hydrated.current && this.lazyHydrator) {
|
|
224
|
-
this.lazyHydrator();
|
|
128
|
+
});
|
|
129
|
+
// eslint-disable-next-line consistent-return
|
|
130
|
+
return function () {
|
|
131
|
+
if (animationFrame) {
|
|
132
|
+
cancelAnimationFrame(animationFrame);
|
|
225
133
|
}
|
|
134
|
+
if (cleanupCallback) {
|
|
135
|
+
cleanupCallback();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}, [image]);
|
|
139
|
+
// useLayoutEffect is ran before React commits to the DOM. This allows us to make sure our HTML is using our cached image version
|
|
140
|
+
(0, react_1.useLayoutEffect)(function () {
|
|
141
|
+
if (imageCache.has(cacheKey) && renderImage) {
|
|
142
|
+
root.current.innerHTML = renderImage(__assign({ isLoading: imageCache.has(cacheKey), isLoaded: imageCache.has(cacheKey), image: image }, props));
|
|
143
|
+
// Trigger onStartload and onLoad events
|
|
144
|
+
onStartLoad === null || onStartLoad === void 0 ? void 0 : onStartLoad({
|
|
145
|
+
wasCached: true
|
|
146
|
+
});
|
|
147
|
+
onLoad === null || onLoad === void 0 ? void 0 : onLoad({
|
|
148
|
+
wasCached: true
|
|
149
|
+
});
|
|
226
150
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
// preact class
|
|
235
|
-
if (this.props["class"]) {
|
|
236
|
-
className = this.props["class"];
|
|
237
|
-
}
|
|
238
|
-
var sizer = (0, layout_wrapper_1.getSizer)(layout, width, height);
|
|
239
|
-
return (react_1["default"].createElement(Type, __assign({}, wrapperProps, { style: __assign(__assign(__assign({}, wStyle), this.props.style), { backgroundColor: this.props.backgroundColor }), className: "".concat(wClass).concat(className ? " ".concat(className) : ""), ref: this.root, dangerouslySetInnerHTML: {
|
|
240
|
-
__html: sizer
|
|
241
|
-
}, suppressHydrationWarning: true })));
|
|
242
|
-
};
|
|
243
|
-
return GatsbyImageHydrator;
|
|
244
|
-
}(react_1.Component));
|
|
245
|
-
var GatsbyImage = function GatsbyImage(props) {
|
|
151
|
+
}, [image]);
|
|
152
|
+
// By keeping all props equal React will keep the component in the DOM
|
|
153
|
+
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: {
|
|
154
|
+
__html: sizer
|
|
155
|
+
}, suppressHydrationWarning: true }));
|
|
156
|
+
};
|
|
157
|
+
exports.GatsbyImage = (0, react_1.memo)(function GatsbyImage(props) {
|
|
246
158
|
if (!props.image) {
|
|
247
159
|
if (process.env.NODE_ENV === "development") {
|
|
248
160
|
console.warn("[gatsby-plugin-image] Missing image prop");
|
|
@@ -252,18 +164,7 @@ var GatsbyImage = function GatsbyImage(props) {
|
|
|
252
164
|
if (!(0, hooks_1.gatsbyImageIsInstalled)() && process.env.NODE_ENV === "development") {
|
|
253
165
|
console.warn("[gatsby-plugin-image] You're missing out on some cool performance features. Please add \"gatsby-plugin-image\" to your gatsby-config.js");
|
|
254
166
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
var propsKey = JSON.stringify([
|
|
258
|
-
width,
|
|
259
|
-
height,
|
|
260
|
-
layout,
|
|
261
|
-
className,
|
|
262
|
-
classSafe,
|
|
263
|
-
backgroundColor,
|
|
264
|
-
]);
|
|
265
|
-
return react_1["default"].createElement(GatsbyImageHydrator, __assign({ key: propsKey }, props));
|
|
266
|
-
};
|
|
267
|
-
exports.GatsbyImage = GatsbyImage;
|
|
167
|
+
return (0, react_1.createElement)(GatsbyImageHydrator, props);
|
|
168
|
+
});
|
|
268
169
|
exports.GatsbyImage.propTypes = gatsby_image_server_1.propTypes;
|
|
269
170
|
exports.GatsbyImage.displayName = "GatsbyImage";
|
|
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
exports.__esModule = true;
|
|
53
|
-
exports.propTypes = exports.altValidator = exports.GatsbyImage =
|
|
53
|
+
exports.propTypes = exports.altValidator = exports.GatsbyImage = void 0;
|
|
54
54
|
var react_1 = __importDefault(require("react"));
|
|
55
55
|
var hooks_1 = require("./hooks");
|
|
56
56
|
var placeholder_1 = require("./placeholder");
|
|
@@ -58,13 +58,8 @@ var main_image_1 = require("./main-image");
|
|
|
58
58
|
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
|
-
var GatsbyImageHydrator = function GatsbyImageHydrator(_a) {
|
|
62
|
-
var _b = _a.as, Type = _b === void 0 ? "div" : _b, children = _a.children, props = __rest(_a, ["as", "children"]);
|
|
63
|
-
return react_1["default"].createElement(Type, __assign({}, props), children);
|
|
64
|
-
};
|
|
65
|
-
exports.GatsbyImageHydrator = GatsbyImageHydrator;
|
|
66
61
|
var GatsbyImage = function GatsbyImage(_a) {
|
|
67
|
-
var
|
|
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"]);
|
|
68
63
|
if (!image) {
|
|
69
64
|
console.warn("[gatsby-plugin-image] Missing image prop");
|
|
70
65
|
return null;
|
|
@@ -74,7 +69,7 @@ var GatsbyImage = function GatsbyImage(_a) {
|
|
|
74
69
|
}
|
|
75
70
|
imgStyle = __assign({ objectFit: objectFit, objectPosition: objectPosition, backgroundColor: backgroundColor }, imgStyle);
|
|
76
71
|
var width = image.width, height = image.height, layout = image.layout, images = image.images, placeholder = image.placeholder, placeholderBackgroundColor = image.backgroundColor;
|
|
77
|
-
var
|
|
72
|
+
var _d = (0, hooks_1.getWrapperProps)(width, height, layout), wStyle = _d.style, wClass = _d.className, wrapperProps = __rest(_d, ["style", "className"]);
|
|
78
73
|
var cleanedImages = {
|
|
79
74
|
fallback: undefined,
|
|
80
75
|
sources: []
|
|
@@ -89,10 +84,9 @@ var GatsbyImage = function GatsbyImage(_a) {
|
|
|
89
84
|
return __assign(__assign({}, source), { srcSet: removeNewLines(source.srcSet) });
|
|
90
85
|
});
|
|
91
86
|
}
|
|
92
|
-
return
|
|
93
|
-
react_1["default"].createElement(
|
|
94
|
-
|
|
95
|
-
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, undefined, undefined, undefined, imgStyle))))));
|
|
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)))));
|
|
96
90
|
};
|
|
97
91
|
exports.GatsbyImage = GatsbyImage;
|
|
98
92
|
var altValidator = function (props, propName, componentName) {
|
package/dist/components/hooks.js
CHANGED
|
@@ -10,65 +10,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
-
function step(op) {
|
|
50
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
-
while (_) try {
|
|
52
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
-
switch (op[0]) {
|
|
55
|
-
case 0: case 1: t = op; break;
|
|
56
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
-
default:
|
|
60
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
-
if (t[2]) _.ops.pop();
|
|
65
|
-
_.trys.pop(); continue;
|
|
66
|
-
}
|
|
67
|
-
op = body.call(thisArg, _);
|
|
68
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
13
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
73
14
|
var t = {};
|
|
74
15
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -106,11 +47,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
106
47
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
107
48
|
};
|
|
108
49
|
exports.__esModule = true;
|
|
109
|
-
exports.withArtDirection = exports.
|
|
110
|
-
/*
|
|
111
|
-
var react_1 = require("react");
|
|
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 */
|
|
112
52
|
var image_utils_1 = require("../image-utils");
|
|
113
|
-
var imageCache = new Set();
|
|
114
53
|
// Native lazy-loading support: https://addyosmani.com/blog/lazy-loading/
|
|
115
54
|
var hasNativeLazyLoadSupport = function () {
|
|
116
55
|
return typeof HTMLImageElement !== "undefined" &&
|
|
@@ -121,16 +60,6 @@ function gatsbyImageIsInstalled() {
|
|
|
121
60
|
return typeof GATSBY___IMAGE !== "undefined" && GATSBY___IMAGE;
|
|
122
61
|
}
|
|
123
62
|
exports.gatsbyImageIsInstalled = gatsbyImageIsInstalled;
|
|
124
|
-
function storeImageloaded(cacheKey) {
|
|
125
|
-
if (cacheKey) {
|
|
126
|
-
imageCache.add(cacheKey);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.storeImageloaded = storeImageloaded;
|
|
130
|
-
function hasImageLoaded(cacheKey) {
|
|
131
|
-
return imageCache.has(cacheKey);
|
|
132
|
-
}
|
|
133
|
-
exports.hasImageLoaded = hasImageLoaded;
|
|
134
63
|
var isGatsbyImageData = function (
|
|
135
64
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
136
65
|
node) { var _a, _b;
|
|
@@ -139,14 +68,22 @@ return Boolean((_b = (_a = node === null || node === void 0 ? void 0 : node.imag
|
|
|
139
68
|
var isGatsbyImageDataParent = function (
|
|
140
69
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
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); };
|
|
142
74
|
var getImage = function (node) {
|
|
143
75
|
var _a;
|
|
144
76
|
if (isGatsbyImageData(node)) {
|
|
145
77
|
return node;
|
|
146
78
|
}
|
|
79
|
+
// gatsbyImageData GraphQL field
|
|
147
80
|
if (isGatsbyImageDataParent(node)) {
|
|
148
81
|
return node.gatsbyImageData;
|
|
149
82
|
}
|
|
83
|
+
// gatsbyImage GraphQL field for Gatsby's Image CDN service
|
|
84
|
+
if (isGatsbyImageParent(node)) {
|
|
85
|
+
return node.gatsbyImage;
|
|
86
|
+
}
|
|
150
87
|
return (_a = node === null || node === void 0 ? void 0 : node.childImageSharp) === null || _a === void 0 ? void 0 : _a.gatsbyImageData;
|
|
151
88
|
};
|
|
152
89
|
exports.getImage = getImage;
|
|
@@ -180,27 +117,6 @@ function getWrapperProps(width, height, layout) {
|
|
|
180
117
|
};
|
|
181
118
|
}
|
|
182
119
|
exports.getWrapperProps = getWrapperProps;
|
|
183
|
-
function applyPolyfill(ref) {
|
|
184
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
return __generator(this, function (_a) {
|
|
186
|
-
switch (_a.label) {
|
|
187
|
-
case 0:
|
|
188
|
-
if (!!("objectFitPolyfill" in window)) return [3 /*break*/, 2];
|
|
189
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(
|
|
190
|
-
// @ts-ignore typescript can't find the module for some reason ¯\_(ツ)_/¯
|
|
191
|
-
/* webpackChunkName: "gatsby-plugin-image-objectfit-polyfill" */ "objectFitPolyfill")); })];
|
|
192
|
-
case 1:
|
|
193
|
-
_a.sent();
|
|
194
|
-
_a.label = 2;
|
|
195
|
-
case 2:
|
|
196
|
-
;
|
|
197
|
-
window.objectFitPolyfill(ref.current);
|
|
198
|
-
return [2 /*return*/];
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
exports.applyPolyfill = applyPolyfill;
|
|
204
120
|
/**
|
|
205
121
|
* Use this hook to generate gatsby-plugin-image data in the browser.
|
|
206
122
|
*/
|
|
@@ -227,42 +143,13 @@ function getImageData(_a) {
|
|
|
227
143
|
return (0, image_utils_1.generateImageData)(args);
|
|
228
144
|
}
|
|
229
145
|
exports.getImageData = getImageData;
|
|
230
|
-
function getMainProps(isLoading, isLoaded, images, loading,
|
|
231
|
-
var _a, _b;
|
|
146
|
+
function getMainProps(isLoading, isLoaded, images, loading, style) {
|
|
232
147
|
if (style === void 0) { style = {}; }
|
|
233
|
-
var onLoad = function (e) {
|
|
234
|
-
if (isLoaded) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
storeImageloaded(cacheKey);
|
|
238
|
-
var target = e.currentTarget;
|
|
239
|
-
var img = new Image();
|
|
240
|
-
img.src = target.currentSrc;
|
|
241
|
-
if (img.decode) {
|
|
242
|
-
// Decode the image through javascript to support our transition
|
|
243
|
-
img
|
|
244
|
-
.decode()["catch"](function () {
|
|
245
|
-
// ignore error, we just go forward
|
|
246
|
-
})
|
|
247
|
-
.then(function () {
|
|
248
|
-
toggleLoaded(true);
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
toggleLoaded(true);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
// Polyfill "object-fit" if unsupported (mostly IE)
|
|
256
|
-
if ((ref === null || ref === void 0 ? void 0 : ref.current) && !("objectFit" in document.documentElement.style)) {
|
|
257
|
-
ref.current.dataset.objectFit = (_a = style.objectFit) !== null && _a !== void 0 ? _a : "cover";
|
|
258
|
-
ref.current.dataset.objectPosition = "".concat((_b = style.objectPosition) !== null && _b !== void 0 ? _b : "50% 50%");
|
|
259
|
-
applyPolyfill(ref);
|
|
260
|
-
}
|
|
261
148
|
// fallback when it's not configured in gatsby-config.
|
|
262
149
|
if (!gatsbyImageIsInstalled()) {
|
|
263
150
|
style = __assign({ height: "100%", left: 0, position: "absolute", top: 0, transform: "translateZ(0)", transition: "opacity 250ms linear", width: "100%", willChange: "opacity" }, style);
|
|
264
151
|
}
|
|
265
|
-
var result = __assign(__assign({}, images), { loading: loading, shouldLoad: isLoading, "data-main-image": "", style: __assign(__assign({}, style), { opacity: isLoaded ? 1 : 0 })
|
|
152
|
+
var result = __assign(__assign({}, images), { loading: loading, shouldLoad: isLoading, "data-main-image": "", style: __assign(__assign({}, style), { opacity: isLoaded ? 1 : 0 }) });
|
|
266
153
|
return result;
|
|
267
154
|
}
|
|
268
155
|
exports.getMainProps = getMainProps;
|
|
@@ -311,46 +198,6 @@ function getPlaceholderProps(placeholder, isLoaded, layout, width, height, backg
|
|
|
311
198
|
return result;
|
|
312
199
|
}
|
|
313
200
|
exports.getPlaceholderProps = getPlaceholderProps;
|
|
314
|
-
function useImageLoaded(cacheKey, loading, ref) {
|
|
315
|
-
var _a = __read((0, react_1.useState)(false), 2), isLoaded = _a[0], toggleLoaded = _a[1];
|
|
316
|
-
var _b = __read((0, react_1.useState)(loading === "eager"), 2), isLoading = _b[0], toggleIsLoading = _b[1];
|
|
317
|
-
var rAF = typeof window !== "undefined" && "requestAnimationFrame" in window
|
|
318
|
-
? requestAnimationFrame
|
|
319
|
-
: function (cb) {
|
|
320
|
-
return setTimeout(cb, 16);
|
|
321
|
-
};
|
|
322
|
-
var cRAF = typeof window !== "undefined" && "cancelAnimationFrame" in window
|
|
323
|
-
? cancelAnimationFrame
|
|
324
|
-
: clearTimeout;
|
|
325
|
-
(0, react_1.useEffect)(function () {
|
|
326
|
-
var interval;
|
|
327
|
-
// @see https://stackoverflow.com/questions/44074747/componentdidmount-called-before-ref-callback/50019873#50019873
|
|
328
|
-
function toggleIfRefExists() {
|
|
329
|
-
if (ref.current) {
|
|
330
|
-
if (loading === "eager" && ref.current.complete) {
|
|
331
|
-
storeImageloaded(cacheKey);
|
|
332
|
-
toggleLoaded(true);
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
toggleIsLoading(true);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
interval = rAF(toggleIfRefExists);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
toggleIfRefExists();
|
|
343
|
-
return function () {
|
|
344
|
-
cRAF(interval);
|
|
345
|
-
};
|
|
346
|
-
}, []);
|
|
347
|
-
return {
|
|
348
|
-
isLoading: isLoading,
|
|
349
|
-
isLoaded: isLoaded,
|
|
350
|
-
toggleLoaded: toggleLoaded
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
exports.useImageLoaded = useImageLoaded;
|
|
354
201
|
/**
|
|
355
202
|
* Generate a Gatsby image data object with multiple, art-directed images that display at different
|
|
356
203
|
* resolutions.
|
|
@@ -39,15 +39,13 @@ function createIntersectionObserver(callback) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
return function observe(element) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
intersectionObserver.observe(element.current);
|
|
46
|
-
}
|
|
42
|
+
// Store a reference to the callback mapped to the element being watched
|
|
43
|
+
ioEntryMap.set(element, callback);
|
|
44
|
+
intersectionObserver.observe(element);
|
|
47
45
|
return function unobserve() {
|
|
48
|
-
if (intersectionObserver && element
|
|
49
|
-
ioEntryMap["delete"](element
|
|
50
|
-
intersectionObserver.unobserve(element
|
|
46
|
+
if (intersectionObserver && element) {
|
|
47
|
+
ioEntryMap["delete"](element);
|
|
48
|
+
intersectionObserver.unobserve(element);
|
|
51
49
|
}
|
|
52
50
|
};
|
|
53
51
|
};
|