gatsby-plugin-image 2.14.0-next.4 → 2.15.0-next.1
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 +4 -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 +6 -14
- 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-574ee440.js +0 -3
- package/dist/index.browser-574ee440.js.map +0 -1
- package/dist/index.browser-aa9e39e5.js +0 -2
- package/dist/index.browser-aa9e39e5.js.map +0 -1
- package/dist/index.browser-fafd25d1.js +0 -2
- package/dist/index.browser-fafd25d1.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-065459ce.js +0 -2
- package/dist/lazy-hydrate-065459ce.js.map +0 -1
- package/dist/lazy-hydrate-71e049f8.js +0 -2
- package/dist/lazy-hydrate-71e049f8.js.map +0 -1
- package/dist/lazy-hydrate-8b7352ac.js +0 -2
- package/dist/lazy-hydrate-8b7352ac.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;
|
|
@@ -188,27 +117,6 @@ function getWrapperProps(width, height, layout) {
|
|
|
188
117
|
};
|
|
189
118
|
}
|
|
190
119
|
exports.getWrapperProps = getWrapperProps;
|
|
191
|
-
function applyPolyfill(ref) {
|
|
192
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
-
return __generator(this, function (_a) {
|
|
194
|
-
switch (_a.label) {
|
|
195
|
-
case 0:
|
|
196
|
-
if (!!("objectFitPolyfill" in window)) return [3 /*break*/, 2];
|
|
197
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(
|
|
198
|
-
// @ts-ignore typescript can't find the module for some reason ¯\_(ツ)_/¯
|
|
199
|
-
/* webpackChunkName: "gatsby-plugin-image-objectfit-polyfill" */ "objectFitPolyfill")); })];
|
|
200
|
-
case 1:
|
|
201
|
-
_a.sent();
|
|
202
|
-
_a.label = 2;
|
|
203
|
-
case 2:
|
|
204
|
-
;
|
|
205
|
-
window.objectFitPolyfill(ref.current);
|
|
206
|
-
return [2 /*return*/];
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
exports.applyPolyfill = applyPolyfill;
|
|
212
120
|
/**
|
|
213
121
|
* Use this hook to generate gatsby-plugin-image data in the browser.
|
|
214
122
|
*/
|
|
@@ -235,42 +143,13 @@ function getImageData(_a) {
|
|
|
235
143
|
return (0, image_utils_1.generateImageData)(args);
|
|
236
144
|
}
|
|
237
145
|
exports.getImageData = getImageData;
|
|
238
|
-
function getMainProps(isLoading, isLoaded, images, loading,
|
|
239
|
-
var _a, _b;
|
|
146
|
+
function getMainProps(isLoading, isLoaded, images, loading, style) {
|
|
240
147
|
if (style === void 0) { style = {}; }
|
|
241
|
-
var onLoad = function (e) {
|
|
242
|
-
if (isLoaded) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
storeImageloaded(cacheKey);
|
|
246
|
-
var target = e.currentTarget;
|
|
247
|
-
var img = new Image();
|
|
248
|
-
img.src = target.currentSrc;
|
|
249
|
-
if (img.decode) {
|
|
250
|
-
// Decode the image through javascript to support our transition
|
|
251
|
-
img
|
|
252
|
-
.decode()["catch"](function () {
|
|
253
|
-
// ignore error, we just go forward
|
|
254
|
-
})
|
|
255
|
-
.then(function () {
|
|
256
|
-
toggleLoaded(true);
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
toggleLoaded(true);
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
// Polyfill "object-fit" if unsupported (mostly IE)
|
|
264
|
-
if ((ref === null || ref === void 0 ? void 0 : ref.current) && !("objectFit" in document.documentElement.style)) {
|
|
265
|
-
ref.current.dataset.objectFit = (_a = style.objectFit) !== null && _a !== void 0 ? _a : "cover";
|
|
266
|
-
ref.current.dataset.objectPosition = "".concat((_b = style.objectPosition) !== null && _b !== void 0 ? _b : "50% 50%");
|
|
267
|
-
applyPolyfill(ref);
|
|
268
|
-
}
|
|
269
148
|
// fallback when it's not configured in gatsby-config.
|
|
270
149
|
if (!gatsbyImageIsInstalled()) {
|
|
271
150
|
style = __assign({ height: "100%", left: 0, position: "absolute", top: 0, transform: "translateZ(0)", transition: "opacity 250ms linear", width: "100%", willChange: "opacity" }, style);
|
|
272
151
|
}
|
|
273
|
-
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 }) });
|
|
274
153
|
return result;
|
|
275
154
|
}
|
|
276
155
|
exports.getMainProps = getMainProps;
|
|
@@ -319,46 +198,6 @@ function getPlaceholderProps(placeholder, isLoaded, layout, width, height, backg
|
|
|
319
198
|
return result;
|
|
320
199
|
}
|
|
321
200
|
exports.getPlaceholderProps = getPlaceholderProps;
|
|
322
|
-
function useImageLoaded(cacheKey, loading, ref) {
|
|
323
|
-
var _a = __read((0, react_1.useState)(false), 2), isLoaded = _a[0], toggleLoaded = _a[1];
|
|
324
|
-
var _b = __read((0, react_1.useState)(loading === "eager"), 2), isLoading = _b[0], toggleIsLoading = _b[1];
|
|
325
|
-
var rAF = typeof window !== "undefined" && "requestAnimationFrame" in window
|
|
326
|
-
? requestAnimationFrame
|
|
327
|
-
: function (cb) {
|
|
328
|
-
return setTimeout(cb, 16);
|
|
329
|
-
};
|
|
330
|
-
var cRAF = typeof window !== "undefined" && "cancelAnimationFrame" in window
|
|
331
|
-
? cancelAnimationFrame
|
|
332
|
-
: clearTimeout;
|
|
333
|
-
(0, react_1.useEffect)(function () {
|
|
334
|
-
var interval;
|
|
335
|
-
// @see https://stackoverflow.com/questions/44074747/componentdidmount-called-before-ref-callback/50019873#50019873
|
|
336
|
-
function toggleIfRefExists() {
|
|
337
|
-
if (ref.current) {
|
|
338
|
-
if (loading === "eager" && ref.current.complete) {
|
|
339
|
-
storeImageloaded(cacheKey);
|
|
340
|
-
toggleLoaded(true);
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
toggleIsLoading(true);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
interval = rAF(toggleIfRefExists);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
toggleIfRefExists();
|
|
351
|
-
return function () {
|
|
352
|
-
cRAF(interval);
|
|
353
|
-
};
|
|
354
|
-
}, []);
|
|
355
|
-
return {
|
|
356
|
-
isLoading: isLoading,
|
|
357
|
-
isLoaded: isLoaded,
|
|
358
|
-
toggleLoaded: toggleLoaded
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
exports.useImageLoaded = useImageLoaded;
|
|
362
201
|
/**
|
|
363
202
|
* Generate a Gatsby image data object with multiple, art-directed images that display at different
|
|
364
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
|
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
3
|
-
/// <reference path="../global.d.ts" />
|
|
4
2
|
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
5
3
|
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
6
4
|
return cooked;
|
|
@@ -61,7 +59,7 @@ var NativeScriptLoading = function () { return (react_1["default"].createElement
|
|
|
61
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 }\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 }\n}\n"])))
|
|
62
60
|
} })); };
|
|
63
61
|
function getSizer(layout, width, height) {
|
|
64
|
-
var sizer =
|
|
62
|
+
var sizer = "";
|
|
65
63
|
if (layout === "fullWidth") {
|
|
66
64
|
sizer = "<div aria-hidden=\"true\" style=\"padding-top: ".concat((height / width) * 100, "%;\"></div>");
|
|
67
65
|
}
|
|
@@ -91,8 +89,7 @@ var LayoutWrapper = function LayoutWrapper(_a) {
|
|
|
91
89
|
return (react_1["default"].createElement(react_1.Fragment, null,
|
|
92
90
|
react_1["default"].createElement(Sizer, __assign({}, props)),
|
|
93
91
|
children,
|
|
94
|
-
|
|
95
|
-
SERVER && react_1["default"].createElement(NativeScriptLoading, null)));
|
|
92
|
+
SERVER ? react_1["default"].createElement(NativeScriptLoading, null) : null));
|
|
96
93
|
};
|
|
97
94
|
exports.LayoutWrapper = LayoutWrapper;
|
|
98
95
|
var templateObject_1;
|