gatsby-plugin-image 2.9.0 → 2.10.0-next.2
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/babel-helpers.js +66 -66
- package/dist/babel-plugin-parse-static-images.js +80 -80
- package/dist/components/gatsby-image.browser.js +247 -247
- package/dist/components/gatsby-image.server.js +112 -112
- package/dist/components/hooks.js +399 -399
- package/dist/components/intersection-observer.js +55 -55
- package/dist/components/layout-wrapper.js +94 -94
- package/dist/components/lazy-hydrate.js +75 -75
- package/dist/components/main-image.js +43 -43
- package/dist/components/picture.js +96 -96
- package/dist/components/placeholder.js +74 -74
- package/dist/components/static-image.server.js +111 -111
- package/dist/gatsby-node.js +54 -54
- package/dist/image-utils.js +449 -449
- package/dist/index.js +27 -27
- package/dist/node-apis/image-processing.js +278 -278
- package/dist/node-apis/node-utils.js +11 -11
- package/dist/node-apis/parser.js +98 -98
- package/dist/node-apis/preprocess-source.js +118 -118
- package/dist/node-apis/watcher.js +129 -129
- package/dist/resolver-utils.js +119 -119
- package/dist/src/babel-helpers.d.ts +6 -6
- package/dist/src/babel-plugin-parse-static-images.d.ts +10 -10
- package/dist/src/gatsby-node.d.ts +5 -5
- package/dist/src/node-apis/image-processing.d.ts +30 -30
- package/dist/src/node-apis/node-utils.d.ts +1 -1
- package/dist/src/node-apis/parser.d.ts +11 -11
- package/dist/src/node-apis/preprocess-source.d.ts +2 -2
- package/dist/src/node-apis/watcher.d.ts +12 -12
- package/dist/src/resolver-utils.d.ts +21 -21
- package/package.json +4 -4
package/dist/components/hooks.js
CHANGED
|
@@ -1,399 +1,399 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
-
if (mod && mod.__esModule) return mod;
|
|
27
|
-
var result = {};
|
|
28
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
-
__setModuleDefault(result, mod);
|
|
30
|
-
return result;
|
|
31
|
-
};
|
|
32
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
33
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
42
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
-
function step(op) {
|
|
46
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
-
while (_) try {
|
|
48
|
-
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;
|
|
49
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
-
switch (op[0]) {
|
|
51
|
-
case 0: case 1: t = op; break;
|
|
52
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
-
default:
|
|
56
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
-
if (t[2]) _.ops.pop();
|
|
61
|
-
_.trys.pop(); continue;
|
|
62
|
-
}
|
|
63
|
-
op = body.call(thisArg, _);
|
|
64
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
69
|
-
var t = {};
|
|
70
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
71
|
-
t[p] = s[p];
|
|
72
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
73
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
74
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
75
|
-
t[p[i]] = s[p[i]];
|
|
76
|
-
}
|
|
77
|
-
return t;
|
|
78
|
-
};
|
|
79
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
80
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
81
|
-
if (!m) return o;
|
|
82
|
-
var i = m.call(o), r, ar = [], e;
|
|
83
|
-
try {
|
|
84
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
85
|
-
}
|
|
86
|
-
catch (error) { e = { error: error }; }
|
|
87
|
-
finally {
|
|
88
|
-
try {
|
|
89
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
90
|
-
}
|
|
91
|
-
finally { if (e) throw e.error; }
|
|
92
|
-
}
|
|
93
|
-
return ar;
|
|
94
|
-
};
|
|
95
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
96
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
97
|
-
if (ar || !(i in from)) {
|
|
98
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
99
|
-
ar[i] = from[i];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
103
|
-
};
|
|
104
|
-
exports.__esModule = true;
|
|
105
|
-
exports.withArtDirection = exports.useImageLoaded = exports.getPlaceholderProps = exports.getMainProps = exports.getImageData = exports.applyPolyfill = exports.getWrapperProps = exports.getSrcSet = exports.getSrc = exports.getImage = exports.hasImageLoaded = exports.storeImageloaded = exports.gatsbyImageIsInstalled = exports.hasNativeLazyLoadSupport = void 0;
|
|
106
|
-
/* eslint-disable no-unused-expressions */
|
|
107
|
-
var react_1 = require("react");
|
|
108
|
-
var image_utils_1 = require("../image-utils");
|
|
109
|
-
var imageCache = new Set();
|
|
110
|
-
// Native lazy-loading support: https://addyosmani.com/blog/lazy-loading/
|
|
111
|
-
var hasNativeLazyLoadSupport = function () {
|
|
112
|
-
return typeof HTMLImageElement !== "undefined" &&
|
|
113
|
-
"loading" in HTMLImageElement.prototype;
|
|
114
|
-
};
|
|
115
|
-
exports.hasNativeLazyLoadSupport = hasNativeLazyLoadSupport;
|
|
116
|
-
function gatsbyImageIsInstalled() {
|
|
117
|
-
return typeof GATSBY___IMAGE !== "undefined" && GATSBY___IMAGE;
|
|
118
|
-
}
|
|
119
|
-
exports.gatsbyImageIsInstalled = gatsbyImageIsInstalled;
|
|
120
|
-
function storeImageloaded(cacheKey) {
|
|
121
|
-
if (cacheKey) {
|
|
122
|
-
imageCache.add(cacheKey);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
exports.storeImageloaded = storeImageloaded;
|
|
126
|
-
function hasImageLoaded(cacheKey) {
|
|
127
|
-
return imageCache.has(cacheKey);
|
|
128
|
-
}
|
|
129
|
-
exports.hasImageLoaded = hasImageLoaded;
|
|
130
|
-
var isGatsbyImageData = function (
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
|
-
node) { var _a, _b;
|
|
133
|
-
// 🦆 check for a deep prop to be sure this is a valid gatsbyImageData object
|
|
134
|
-
return Boolean((_b = (_a = node === null || node === void 0 ? void 0 : node.images) === null || _a === void 0 ? void 0 : _a.fallback) === null || _b === void 0 ? void 0 : _b.src); };
|
|
135
|
-
var isGatsbyImageDataParent = function (
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
-
node) { return Boolean(node === null || node === void 0 ? void 0 : node.gatsbyImageData); };
|
|
138
|
-
var getImage = function (node) {
|
|
139
|
-
var _a;
|
|
140
|
-
if (isGatsbyImageData(node)) {
|
|
141
|
-
return node;
|
|
142
|
-
}
|
|
143
|
-
if (isGatsbyImageDataParent(node)) {
|
|
144
|
-
return node.gatsbyImageData;
|
|
145
|
-
}
|
|
146
|
-
return (_a = node === null || node === void 0 ? void 0 : node.childImageSharp) === null || _a === void 0 ? void 0 : _a.gatsbyImageData;
|
|
147
|
-
};
|
|
148
|
-
exports.getImage = getImage;
|
|
149
|
-
var getSrc = function (node) { var _a, _b, _c; return (_c = (_b = (_a = (0, exports.getImage)(node)) === null || _a === void 0 ? void 0 : _a.images) === null || _b === void 0 ? void 0 : _b.fallback) === null || _c === void 0 ? void 0 : _c.src; };
|
|
150
|
-
exports.getSrc = getSrc;
|
|
151
|
-
var getSrcSet = function (node) { var _a, _b, _c; return (_c = (_b = (_a = (0, exports.getImage)(node)) === null || _a === void 0 ? void 0 : _a.images) === null || _b === void 0 ? void 0 : _b.fallback) === null || _c === void 0 ? void 0 : _c.srcSet; };
|
|
152
|
-
exports.getSrcSet = getSrcSet;
|
|
153
|
-
function getWrapperProps(width, height, layout) {
|
|
154
|
-
var wrapperStyle = {};
|
|
155
|
-
var className = "gatsby-image-wrapper";
|
|
156
|
-
// If the plugin isn't installed we need to apply the styles inline
|
|
157
|
-
if (!gatsbyImageIsInstalled()) {
|
|
158
|
-
wrapperStyle.position = "relative";
|
|
159
|
-
wrapperStyle.overflow = "hidden";
|
|
160
|
-
}
|
|
161
|
-
if (layout === "fixed") {
|
|
162
|
-
wrapperStyle.width = width;
|
|
163
|
-
wrapperStyle.height = height;
|
|
164
|
-
}
|
|
165
|
-
else if (layout === "constrained") {
|
|
166
|
-
if (!gatsbyImageIsInstalled()) {
|
|
167
|
-
wrapperStyle.display = "inline-block";
|
|
168
|
-
wrapperStyle.verticalAlign = "top";
|
|
169
|
-
}
|
|
170
|
-
className = "gatsby-image-wrapper gatsby-image-wrapper-constrained";
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
className: className,
|
|
174
|
-
"data-gatsby-image-wrapper": "",
|
|
175
|
-
style: wrapperStyle
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
exports.getWrapperProps = getWrapperProps;
|
|
179
|
-
function applyPolyfill(ref) {
|
|
180
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
-
return __generator(this, function (_a) {
|
|
182
|
-
switch (_a.label) {
|
|
183
|
-
case 0:
|
|
184
|
-
if (!!("objectFitPolyfill" in window)) return [3 /*break*/, 2];
|
|
185
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(
|
|
186
|
-
// @ts-ignore typescript can't find the module for some reason ¯\_(ツ)_/¯
|
|
187
|
-
/* webpackChunkName: "gatsby-plugin-image-objectfit-polyfill" */ "objectFitPolyfill")); })];
|
|
188
|
-
case 1:
|
|
189
|
-
_a.sent();
|
|
190
|
-
_a.label = 2;
|
|
191
|
-
case 2:
|
|
192
|
-
;
|
|
193
|
-
window.objectFitPolyfill(ref.current);
|
|
194
|
-
return [2 /*return*/];
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
exports.applyPolyfill = applyPolyfill;
|
|
200
|
-
/**
|
|
201
|
-
* Use this hook to generate gatsby-plugin-image data in the browser.
|
|
202
|
-
*/
|
|
203
|
-
function getImageData(_a) {
|
|
204
|
-
var baseUrl = _a.baseUrl, urlBuilder = _a.urlBuilder, sourceWidth = _a.sourceWidth, sourceHeight = _a.sourceHeight, _b = _a.pluginName, pluginName = _b === void 0 ? "getImageData" : _b, _c = _a.formats, formats = _c === void 0 ? ["auto"] : _c, breakpoints = _a.breakpoints, options = _a.options, props = __rest(_a, ["baseUrl", "urlBuilder", "sourceWidth", "sourceHeight", "pluginName", "formats", "breakpoints", "options"]);
|
|
205
|
-
if (!(breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.length) &&
|
|
206
|
-
(props.layout === "fullWidth" || props.layout === "FULL_WIDTH")) {
|
|
207
|
-
breakpoints = image_utils_1.EVERY_BREAKPOINT;
|
|
208
|
-
}
|
|
209
|
-
var generateImageSource = function (baseUrl, width, height, format) {
|
|
210
|
-
return {
|
|
211
|
-
width: width,
|
|
212
|
-
height: height,
|
|
213
|
-
format: format,
|
|
214
|
-
src: urlBuilder({ baseUrl: baseUrl, width: width, height: height, options: options, format: format })
|
|
215
|
-
};
|
|
216
|
-
};
|
|
217
|
-
var sourceMetadata = {
|
|
218
|
-
width: sourceWidth,
|
|
219
|
-
height: sourceHeight,
|
|
220
|
-
format: "auto"
|
|
221
|
-
};
|
|
222
|
-
var args = __assign(__assign({}, props), { pluginName: pluginName, generateImageSource: generateImageSource, filename: baseUrl, formats: formats, breakpoints: breakpoints, sourceMetadata: sourceMetadata });
|
|
223
|
-
return (0, image_utils_1.generateImageData)(args);
|
|
224
|
-
}
|
|
225
|
-
exports.getImageData = getImageData;
|
|
226
|
-
function getMainProps(isLoading, isLoaded, images, loading, toggleLoaded, cacheKey, ref, style) {
|
|
227
|
-
var _a, _b;
|
|
228
|
-
if (style === void 0) { style = {}; }
|
|
229
|
-
var onLoad = function (e) {
|
|
230
|
-
if (isLoaded) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
storeImageloaded(cacheKey);
|
|
234
|
-
var target = e.currentTarget;
|
|
235
|
-
var img = new Image();
|
|
236
|
-
img.src = target.currentSrc;
|
|
237
|
-
if (img.decode) {
|
|
238
|
-
// Decode the image through javascript to support our transition
|
|
239
|
-
img
|
|
240
|
-
.decode()["catch"](function () {
|
|
241
|
-
// ignore error, we just go forward
|
|
242
|
-
})
|
|
243
|
-
.then(function () {
|
|
244
|
-
toggleLoaded(true);
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
toggleLoaded(true);
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
// Polyfill "object-fit" if unsupported (mostly IE)
|
|
252
|
-
if ((ref === null || ref === void 0 ? void 0 : ref.current) && !("objectFit" in document.documentElement.style)) {
|
|
253
|
-
ref.current.dataset.objectFit = (_a = style.objectFit) !== null && _a !== void 0 ? _a : "cover";
|
|
254
|
-
ref.current.dataset.objectPosition = "".concat((_b = style.objectPosition) !== null && _b !== void 0 ? _b : "50% 50%");
|
|
255
|
-
applyPolyfill(ref);
|
|
256
|
-
}
|
|
257
|
-
// fallback when it's not configured in gatsby-config.
|
|
258
|
-
if (!gatsbyImageIsInstalled()) {
|
|
259
|
-
style = __assign({ height: "100%", left: 0, position: "absolute", top: 0, transform: "translateZ(0)", transition: "opacity 250ms linear", width: "100%", willChange: "opacity" }, style);
|
|
260
|
-
}
|
|
261
|
-
var result = __assign(__assign({}, images), { loading: loading, shouldLoad: isLoading, "data-main-image": "", style: __assign(__assign({}, style), { opacity: isLoaded ? 1 : 0 }), onLoad: onLoad, ref: ref });
|
|
262
|
-
return result;
|
|
263
|
-
}
|
|
264
|
-
exports.getMainProps = getMainProps;
|
|
265
|
-
function getPlaceholderProps(placeholder, isLoaded, layout, width, height, backgroundColor, objectFit, objectPosition) {
|
|
266
|
-
var wrapperStyle = {};
|
|
267
|
-
if (backgroundColor) {
|
|
268
|
-
wrapperStyle.backgroundColor = backgroundColor;
|
|
269
|
-
if (layout === "fixed") {
|
|
270
|
-
wrapperStyle.width = width;
|
|
271
|
-
wrapperStyle.height = height;
|
|
272
|
-
wrapperStyle.backgroundColor = backgroundColor;
|
|
273
|
-
wrapperStyle.position = "relative";
|
|
274
|
-
}
|
|
275
|
-
else if (layout === "constrained") {
|
|
276
|
-
wrapperStyle.position = "absolute";
|
|
277
|
-
wrapperStyle.top = 0;
|
|
278
|
-
wrapperStyle.left = 0;
|
|
279
|
-
wrapperStyle.bottom = 0;
|
|
280
|
-
wrapperStyle.right = 0;
|
|
281
|
-
}
|
|
282
|
-
else if (layout === "fullWidth") {
|
|
283
|
-
wrapperStyle.position = "absolute";
|
|
284
|
-
wrapperStyle.top = 0;
|
|
285
|
-
wrapperStyle.left = 0;
|
|
286
|
-
wrapperStyle.bottom = 0;
|
|
287
|
-
wrapperStyle.right = 0;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
if (objectFit) {
|
|
291
|
-
wrapperStyle.objectFit = objectFit;
|
|
292
|
-
}
|
|
293
|
-
if (objectPosition) {
|
|
294
|
-
wrapperStyle.objectPosition = objectPosition;
|
|
295
|
-
}
|
|
296
|
-
var result = __assign(__assign({}, placeholder), { "aria-hidden": true, "data-placeholder-image": "", style: __assign({ opacity: isLoaded ? 0 : 1, transition: "opacity 500ms linear" }, wrapperStyle) });
|
|
297
|
-
// fallback when it's not configured in gatsby-config.
|
|
298
|
-
if (!gatsbyImageIsInstalled()) {
|
|
299
|
-
result.style = {
|
|
300
|
-
height: "100%",
|
|
301
|
-
left: 0,
|
|
302
|
-
position: "absolute",
|
|
303
|
-
top: 0,
|
|
304
|
-
width: "100%"
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
return result;
|
|
308
|
-
}
|
|
309
|
-
exports.getPlaceholderProps = getPlaceholderProps;
|
|
310
|
-
function useImageLoaded(cacheKey, loading, ref) {
|
|
311
|
-
var _a = __read((0, react_1.useState)(false), 2), isLoaded = _a[0], toggleLoaded = _a[1];
|
|
312
|
-
var _b = __read((0, react_1.useState)(loading === "eager"), 2), isLoading = _b[0], toggleIsLoading = _b[1];
|
|
313
|
-
var rAF = typeof window !== "undefined" && "requestAnimationFrame" in window
|
|
314
|
-
? requestAnimationFrame
|
|
315
|
-
: function (cb) {
|
|
316
|
-
return setTimeout(cb, 16);
|
|
317
|
-
};
|
|
318
|
-
var cRAF = typeof window !== "undefined" && "cancelAnimationFrame" in window
|
|
319
|
-
? cancelAnimationFrame
|
|
320
|
-
: clearTimeout;
|
|
321
|
-
(0, react_1.useEffect)(function () {
|
|
322
|
-
var interval;
|
|
323
|
-
// @see https://stackoverflow.com/questions/44074747/componentdidmount-called-before-ref-callback/50019873#50019873
|
|
324
|
-
function toggleIfRefExists() {
|
|
325
|
-
if (ref.current) {
|
|
326
|
-
if (loading === "eager" && ref.current.complete) {
|
|
327
|
-
storeImageloaded(cacheKey);
|
|
328
|
-
toggleLoaded(true);
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
toggleIsLoading(true);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
interval = rAF(toggleIfRefExists);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
toggleIfRefExists();
|
|
339
|
-
return function () {
|
|
340
|
-
cRAF(interval);
|
|
341
|
-
};
|
|
342
|
-
}, []);
|
|
343
|
-
return {
|
|
344
|
-
isLoading: isLoading,
|
|
345
|
-
isLoaded: isLoaded,
|
|
346
|
-
toggleLoaded: toggleLoaded
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
exports.useImageLoaded = useImageLoaded;
|
|
350
|
-
/**
|
|
351
|
-
* Generate a Gatsby image data object with multiple, art-directed images that display at different
|
|
352
|
-
* resolutions.
|
|
353
|
-
*
|
|
354
|
-
* @param defaultImage The image displayed when no media query matches.
|
|
355
|
-
* It is also used for all other settings applied to the image, such as width, height and layout.
|
|
356
|
-
* You should pass a className to the component with media queries to adjust the size of the container,
|
|
357
|
-
* as this cannot be adjusted automatically.
|
|
358
|
-
* @param artDirected Array of objects which each contains a `media` string which is a media query
|
|
359
|
-
* such as `(min-width: 320px)`, and the image object to use when that query matches.
|
|
360
|
-
*/
|
|
361
|
-
function withArtDirection(defaultImage, artDirected) {
|
|
362
|
-
var _a, _b;
|
|
363
|
-
var _c;
|
|
364
|
-
var images = defaultImage.images, placeholder = defaultImage.placeholder, props = __rest(defaultImage, ["images", "placeholder"]);
|
|
365
|
-
var output = __assign(__assign({}, props), { images: __assign(__assign({}, images), { sources: [] }), placeholder: placeholder && __assign(__assign({}, placeholder), { sources: [] }) });
|
|
366
|
-
artDirected.forEach(function (_a) {
|
|
367
|
-
var _b;
|
|
368
|
-
var media = _a.media, image = _a.image;
|
|
369
|
-
if (!media) {
|
|
370
|
-
if (process.env.NODE_ENV === "development") {
|
|
371
|
-
console.warn("[gatsby-plugin-image] All art-directed images passed to must have a value set for `media`. Skipping.");
|
|
372
|
-
}
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
if (image.layout !== defaultImage.layout &&
|
|
376
|
-
process.env.NODE_ENV === "development") {
|
|
377
|
-
console.warn("[gatsby-plugin-image] Mismatched image layout: expected \"".concat(defaultImage.layout, "\" but received \"").concat(image.layout, "\". All art-directed images use the same layout as the default image"));
|
|
378
|
-
}
|
|
379
|
-
(_b = output.images.sources).push.apply(_b, __spreadArray(__spreadArray([], __read(image.images.sources.map(function (source) {
|
|
380
|
-
return __assign(__assign({}, source), { media: media });
|
|
381
|
-
})), false), [{
|
|
382
|
-
media: media,
|
|
383
|
-
srcSet: image.images.fallback.srcSet
|
|
384
|
-
}], false));
|
|
385
|
-
if (!output.placeholder) {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
output.placeholder.sources.push({
|
|
389
|
-
media: media,
|
|
390
|
-
srcSet: image.placeholder.fallback
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
(_a = output.images.sources).push.apply(_a, __spreadArray([], __read(images.sources), false));
|
|
394
|
-
if (placeholder === null || placeholder === void 0 ? void 0 : placeholder.sources) {
|
|
395
|
-
(_c = output.placeholder) === null || _c === void 0 ? void 0 : (_b = _c.sources).push.apply(_b, __spreadArray([], __read(placeholder.sources), false));
|
|
396
|
-
}
|
|
397
|
-
return output;
|
|
398
|
-
}
|
|
399
|
-
exports.withArtDirection = withArtDirection;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
33
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
42
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
+
function step(op) {
|
|
46
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
+
while (_) try {
|
|
48
|
+
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;
|
|
49
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
+
switch (op[0]) {
|
|
51
|
+
case 0: case 1: t = op; break;
|
|
52
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
+
default:
|
|
56
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
+
if (t[2]) _.ops.pop();
|
|
61
|
+
_.trys.pop(); continue;
|
|
62
|
+
}
|
|
63
|
+
op = body.call(thisArg, _);
|
|
64
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
69
|
+
var t = {};
|
|
70
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
71
|
+
t[p] = s[p];
|
|
72
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
73
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
74
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
75
|
+
t[p[i]] = s[p[i]];
|
|
76
|
+
}
|
|
77
|
+
return t;
|
|
78
|
+
};
|
|
79
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
80
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
81
|
+
if (!m) return o;
|
|
82
|
+
var i = m.call(o), r, ar = [], e;
|
|
83
|
+
try {
|
|
84
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
85
|
+
}
|
|
86
|
+
catch (error) { e = { error: error }; }
|
|
87
|
+
finally {
|
|
88
|
+
try {
|
|
89
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
90
|
+
}
|
|
91
|
+
finally { if (e) throw e.error; }
|
|
92
|
+
}
|
|
93
|
+
return ar;
|
|
94
|
+
};
|
|
95
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
96
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
97
|
+
if (ar || !(i in from)) {
|
|
98
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
99
|
+
ar[i] = from[i];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
103
|
+
};
|
|
104
|
+
exports.__esModule = true;
|
|
105
|
+
exports.withArtDirection = exports.useImageLoaded = exports.getPlaceholderProps = exports.getMainProps = exports.getImageData = exports.applyPolyfill = exports.getWrapperProps = exports.getSrcSet = exports.getSrc = exports.getImage = exports.hasImageLoaded = exports.storeImageloaded = exports.gatsbyImageIsInstalled = exports.hasNativeLazyLoadSupport = void 0;
|
|
106
|
+
/* eslint-disable no-unused-expressions */
|
|
107
|
+
var react_1 = require("react");
|
|
108
|
+
var image_utils_1 = require("../image-utils");
|
|
109
|
+
var imageCache = new Set();
|
|
110
|
+
// Native lazy-loading support: https://addyosmani.com/blog/lazy-loading/
|
|
111
|
+
var hasNativeLazyLoadSupport = function () {
|
|
112
|
+
return typeof HTMLImageElement !== "undefined" &&
|
|
113
|
+
"loading" in HTMLImageElement.prototype;
|
|
114
|
+
};
|
|
115
|
+
exports.hasNativeLazyLoadSupport = hasNativeLazyLoadSupport;
|
|
116
|
+
function gatsbyImageIsInstalled() {
|
|
117
|
+
return typeof GATSBY___IMAGE !== "undefined" && GATSBY___IMAGE;
|
|
118
|
+
}
|
|
119
|
+
exports.gatsbyImageIsInstalled = gatsbyImageIsInstalled;
|
|
120
|
+
function storeImageloaded(cacheKey) {
|
|
121
|
+
if (cacheKey) {
|
|
122
|
+
imageCache.add(cacheKey);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.storeImageloaded = storeImageloaded;
|
|
126
|
+
function hasImageLoaded(cacheKey) {
|
|
127
|
+
return imageCache.has(cacheKey);
|
|
128
|
+
}
|
|
129
|
+
exports.hasImageLoaded = hasImageLoaded;
|
|
130
|
+
var isGatsbyImageData = function (
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
|
+
node) { var _a, _b;
|
|
133
|
+
// 🦆 check for a deep prop to be sure this is a valid gatsbyImageData object
|
|
134
|
+
return Boolean((_b = (_a = node === null || node === void 0 ? void 0 : node.images) === null || _a === void 0 ? void 0 : _a.fallback) === null || _b === void 0 ? void 0 : _b.src); };
|
|
135
|
+
var isGatsbyImageDataParent = function (
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
+
node) { return Boolean(node === null || node === void 0 ? void 0 : node.gatsbyImageData); };
|
|
138
|
+
var getImage = function (node) {
|
|
139
|
+
var _a;
|
|
140
|
+
if (isGatsbyImageData(node)) {
|
|
141
|
+
return node;
|
|
142
|
+
}
|
|
143
|
+
if (isGatsbyImageDataParent(node)) {
|
|
144
|
+
return node.gatsbyImageData;
|
|
145
|
+
}
|
|
146
|
+
return (_a = node === null || node === void 0 ? void 0 : node.childImageSharp) === null || _a === void 0 ? void 0 : _a.gatsbyImageData;
|
|
147
|
+
};
|
|
148
|
+
exports.getImage = getImage;
|
|
149
|
+
var getSrc = function (node) { var _a, _b, _c; return (_c = (_b = (_a = (0, exports.getImage)(node)) === null || _a === void 0 ? void 0 : _a.images) === null || _b === void 0 ? void 0 : _b.fallback) === null || _c === void 0 ? void 0 : _c.src; };
|
|
150
|
+
exports.getSrc = getSrc;
|
|
151
|
+
var getSrcSet = function (node) { var _a, _b, _c; return (_c = (_b = (_a = (0, exports.getImage)(node)) === null || _a === void 0 ? void 0 : _a.images) === null || _b === void 0 ? void 0 : _b.fallback) === null || _c === void 0 ? void 0 : _c.srcSet; };
|
|
152
|
+
exports.getSrcSet = getSrcSet;
|
|
153
|
+
function getWrapperProps(width, height, layout) {
|
|
154
|
+
var wrapperStyle = {};
|
|
155
|
+
var className = "gatsby-image-wrapper";
|
|
156
|
+
// If the plugin isn't installed we need to apply the styles inline
|
|
157
|
+
if (!gatsbyImageIsInstalled()) {
|
|
158
|
+
wrapperStyle.position = "relative";
|
|
159
|
+
wrapperStyle.overflow = "hidden";
|
|
160
|
+
}
|
|
161
|
+
if (layout === "fixed") {
|
|
162
|
+
wrapperStyle.width = width;
|
|
163
|
+
wrapperStyle.height = height;
|
|
164
|
+
}
|
|
165
|
+
else if (layout === "constrained") {
|
|
166
|
+
if (!gatsbyImageIsInstalled()) {
|
|
167
|
+
wrapperStyle.display = "inline-block";
|
|
168
|
+
wrapperStyle.verticalAlign = "top";
|
|
169
|
+
}
|
|
170
|
+
className = "gatsby-image-wrapper gatsby-image-wrapper-constrained";
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
className: className,
|
|
174
|
+
"data-gatsby-image-wrapper": "",
|
|
175
|
+
style: wrapperStyle
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
exports.getWrapperProps = getWrapperProps;
|
|
179
|
+
function applyPolyfill(ref) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
+
return __generator(this, function (_a) {
|
|
182
|
+
switch (_a.label) {
|
|
183
|
+
case 0:
|
|
184
|
+
if (!!("objectFitPolyfill" in window)) return [3 /*break*/, 2];
|
|
185
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(
|
|
186
|
+
// @ts-ignore typescript can't find the module for some reason ¯\_(ツ)_/¯
|
|
187
|
+
/* webpackChunkName: "gatsby-plugin-image-objectfit-polyfill" */ "objectFitPolyfill")); })];
|
|
188
|
+
case 1:
|
|
189
|
+
_a.sent();
|
|
190
|
+
_a.label = 2;
|
|
191
|
+
case 2:
|
|
192
|
+
;
|
|
193
|
+
window.objectFitPolyfill(ref.current);
|
|
194
|
+
return [2 /*return*/];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
exports.applyPolyfill = applyPolyfill;
|
|
200
|
+
/**
|
|
201
|
+
* Use this hook to generate gatsby-plugin-image data in the browser.
|
|
202
|
+
*/
|
|
203
|
+
function getImageData(_a) {
|
|
204
|
+
var baseUrl = _a.baseUrl, urlBuilder = _a.urlBuilder, sourceWidth = _a.sourceWidth, sourceHeight = _a.sourceHeight, _b = _a.pluginName, pluginName = _b === void 0 ? "getImageData" : _b, _c = _a.formats, formats = _c === void 0 ? ["auto"] : _c, breakpoints = _a.breakpoints, options = _a.options, props = __rest(_a, ["baseUrl", "urlBuilder", "sourceWidth", "sourceHeight", "pluginName", "formats", "breakpoints", "options"]);
|
|
205
|
+
if (!(breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.length) &&
|
|
206
|
+
(props.layout === "fullWidth" || props.layout === "FULL_WIDTH")) {
|
|
207
|
+
breakpoints = image_utils_1.EVERY_BREAKPOINT;
|
|
208
|
+
}
|
|
209
|
+
var generateImageSource = function (baseUrl, width, height, format) {
|
|
210
|
+
return {
|
|
211
|
+
width: width,
|
|
212
|
+
height: height,
|
|
213
|
+
format: format,
|
|
214
|
+
src: urlBuilder({ baseUrl: baseUrl, width: width, height: height, options: options, format: format })
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
var sourceMetadata = {
|
|
218
|
+
width: sourceWidth,
|
|
219
|
+
height: sourceHeight,
|
|
220
|
+
format: "auto"
|
|
221
|
+
};
|
|
222
|
+
var args = __assign(__assign({}, props), { pluginName: pluginName, generateImageSource: generateImageSource, filename: baseUrl, formats: formats, breakpoints: breakpoints, sourceMetadata: sourceMetadata });
|
|
223
|
+
return (0, image_utils_1.generateImageData)(args);
|
|
224
|
+
}
|
|
225
|
+
exports.getImageData = getImageData;
|
|
226
|
+
function getMainProps(isLoading, isLoaded, images, loading, toggleLoaded, cacheKey, ref, style) {
|
|
227
|
+
var _a, _b;
|
|
228
|
+
if (style === void 0) { style = {}; }
|
|
229
|
+
var onLoad = function (e) {
|
|
230
|
+
if (isLoaded) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
storeImageloaded(cacheKey);
|
|
234
|
+
var target = e.currentTarget;
|
|
235
|
+
var img = new Image();
|
|
236
|
+
img.src = target.currentSrc;
|
|
237
|
+
if (img.decode) {
|
|
238
|
+
// Decode the image through javascript to support our transition
|
|
239
|
+
img
|
|
240
|
+
.decode()["catch"](function () {
|
|
241
|
+
// ignore error, we just go forward
|
|
242
|
+
})
|
|
243
|
+
.then(function () {
|
|
244
|
+
toggleLoaded(true);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
toggleLoaded(true);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
// Polyfill "object-fit" if unsupported (mostly IE)
|
|
252
|
+
if ((ref === null || ref === void 0 ? void 0 : ref.current) && !("objectFit" in document.documentElement.style)) {
|
|
253
|
+
ref.current.dataset.objectFit = (_a = style.objectFit) !== null && _a !== void 0 ? _a : "cover";
|
|
254
|
+
ref.current.dataset.objectPosition = "".concat((_b = style.objectPosition) !== null && _b !== void 0 ? _b : "50% 50%");
|
|
255
|
+
applyPolyfill(ref);
|
|
256
|
+
}
|
|
257
|
+
// fallback when it's not configured in gatsby-config.
|
|
258
|
+
if (!gatsbyImageIsInstalled()) {
|
|
259
|
+
style = __assign({ height: "100%", left: 0, position: "absolute", top: 0, transform: "translateZ(0)", transition: "opacity 250ms linear", width: "100%", willChange: "opacity" }, style);
|
|
260
|
+
}
|
|
261
|
+
var result = __assign(__assign({}, images), { loading: loading, shouldLoad: isLoading, "data-main-image": "", style: __assign(__assign({}, style), { opacity: isLoaded ? 1 : 0 }), onLoad: onLoad, ref: ref });
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
exports.getMainProps = getMainProps;
|
|
265
|
+
function getPlaceholderProps(placeholder, isLoaded, layout, width, height, backgroundColor, objectFit, objectPosition) {
|
|
266
|
+
var wrapperStyle = {};
|
|
267
|
+
if (backgroundColor) {
|
|
268
|
+
wrapperStyle.backgroundColor = backgroundColor;
|
|
269
|
+
if (layout === "fixed") {
|
|
270
|
+
wrapperStyle.width = width;
|
|
271
|
+
wrapperStyle.height = height;
|
|
272
|
+
wrapperStyle.backgroundColor = backgroundColor;
|
|
273
|
+
wrapperStyle.position = "relative";
|
|
274
|
+
}
|
|
275
|
+
else if (layout === "constrained") {
|
|
276
|
+
wrapperStyle.position = "absolute";
|
|
277
|
+
wrapperStyle.top = 0;
|
|
278
|
+
wrapperStyle.left = 0;
|
|
279
|
+
wrapperStyle.bottom = 0;
|
|
280
|
+
wrapperStyle.right = 0;
|
|
281
|
+
}
|
|
282
|
+
else if (layout === "fullWidth") {
|
|
283
|
+
wrapperStyle.position = "absolute";
|
|
284
|
+
wrapperStyle.top = 0;
|
|
285
|
+
wrapperStyle.left = 0;
|
|
286
|
+
wrapperStyle.bottom = 0;
|
|
287
|
+
wrapperStyle.right = 0;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (objectFit) {
|
|
291
|
+
wrapperStyle.objectFit = objectFit;
|
|
292
|
+
}
|
|
293
|
+
if (objectPosition) {
|
|
294
|
+
wrapperStyle.objectPosition = objectPosition;
|
|
295
|
+
}
|
|
296
|
+
var result = __assign(__assign({}, placeholder), { "aria-hidden": true, "data-placeholder-image": "", style: __assign({ opacity: isLoaded ? 0 : 1, transition: "opacity 500ms linear" }, wrapperStyle) });
|
|
297
|
+
// fallback when it's not configured in gatsby-config.
|
|
298
|
+
if (!gatsbyImageIsInstalled()) {
|
|
299
|
+
result.style = {
|
|
300
|
+
height: "100%",
|
|
301
|
+
left: 0,
|
|
302
|
+
position: "absolute",
|
|
303
|
+
top: 0,
|
|
304
|
+
width: "100%"
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
exports.getPlaceholderProps = getPlaceholderProps;
|
|
310
|
+
function useImageLoaded(cacheKey, loading, ref) {
|
|
311
|
+
var _a = __read((0, react_1.useState)(false), 2), isLoaded = _a[0], toggleLoaded = _a[1];
|
|
312
|
+
var _b = __read((0, react_1.useState)(loading === "eager"), 2), isLoading = _b[0], toggleIsLoading = _b[1];
|
|
313
|
+
var rAF = typeof window !== "undefined" && "requestAnimationFrame" in window
|
|
314
|
+
? requestAnimationFrame
|
|
315
|
+
: function (cb) {
|
|
316
|
+
return setTimeout(cb, 16);
|
|
317
|
+
};
|
|
318
|
+
var cRAF = typeof window !== "undefined" && "cancelAnimationFrame" in window
|
|
319
|
+
? cancelAnimationFrame
|
|
320
|
+
: clearTimeout;
|
|
321
|
+
(0, react_1.useEffect)(function () {
|
|
322
|
+
var interval;
|
|
323
|
+
// @see https://stackoverflow.com/questions/44074747/componentdidmount-called-before-ref-callback/50019873#50019873
|
|
324
|
+
function toggleIfRefExists() {
|
|
325
|
+
if (ref.current) {
|
|
326
|
+
if (loading === "eager" && ref.current.complete) {
|
|
327
|
+
storeImageloaded(cacheKey);
|
|
328
|
+
toggleLoaded(true);
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
toggleIsLoading(true);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
interval = rAF(toggleIfRefExists);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
toggleIfRefExists();
|
|
339
|
+
return function () {
|
|
340
|
+
cRAF(interval);
|
|
341
|
+
};
|
|
342
|
+
}, []);
|
|
343
|
+
return {
|
|
344
|
+
isLoading: isLoading,
|
|
345
|
+
isLoaded: isLoaded,
|
|
346
|
+
toggleLoaded: toggleLoaded
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
exports.useImageLoaded = useImageLoaded;
|
|
350
|
+
/**
|
|
351
|
+
* Generate a Gatsby image data object with multiple, art-directed images that display at different
|
|
352
|
+
* resolutions.
|
|
353
|
+
*
|
|
354
|
+
* @param defaultImage The image displayed when no media query matches.
|
|
355
|
+
* It is also used for all other settings applied to the image, such as width, height and layout.
|
|
356
|
+
* You should pass a className to the component with media queries to adjust the size of the container,
|
|
357
|
+
* as this cannot be adjusted automatically.
|
|
358
|
+
* @param artDirected Array of objects which each contains a `media` string which is a media query
|
|
359
|
+
* such as `(min-width: 320px)`, and the image object to use when that query matches.
|
|
360
|
+
*/
|
|
361
|
+
function withArtDirection(defaultImage, artDirected) {
|
|
362
|
+
var _a, _b;
|
|
363
|
+
var _c;
|
|
364
|
+
var images = defaultImage.images, placeholder = defaultImage.placeholder, props = __rest(defaultImage, ["images", "placeholder"]);
|
|
365
|
+
var output = __assign(__assign({}, props), { images: __assign(__assign({}, images), { sources: [] }), placeholder: placeholder && __assign(__assign({}, placeholder), { sources: [] }) });
|
|
366
|
+
artDirected.forEach(function (_a) {
|
|
367
|
+
var _b;
|
|
368
|
+
var media = _a.media, image = _a.image;
|
|
369
|
+
if (!media) {
|
|
370
|
+
if (process.env.NODE_ENV === "development") {
|
|
371
|
+
console.warn("[gatsby-plugin-image] All art-directed images passed to must have a value set for `media`. Skipping.");
|
|
372
|
+
}
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (image.layout !== defaultImage.layout &&
|
|
376
|
+
process.env.NODE_ENV === "development") {
|
|
377
|
+
console.warn("[gatsby-plugin-image] Mismatched image layout: expected \"".concat(defaultImage.layout, "\" but received \"").concat(image.layout, "\". All art-directed images use the same layout as the default image"));
|
|
378
|
+
}
|
|
379
|
+
(_b = output.images.sources).push.apply(_b, __spreadArray(__spreadArray([], __read(image.images.sources.map(function (source) {
|
|
380
|
+
return __assign(__assign({}, source), { media: media });
|
|
381
|
+
})), false), [{
|
|
382
|
+
media: media,
|
|
383
|
+
srcSet: image.images.fallback.srcSet
|
|
384
|
+
}], false));
|
|
385
|
+
if (!output.placeholder) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
output.placeholder.sources.push({
|
|
389
|
+
media: media,
|
|
390
|
+
srcSet: image.placeholder.fallback
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
(_a = output.images.sources).push.apply(_a, __spreadArray([], __read(images.sources), false));
|
|
394
|
+
if (placeholder === null || placeholder === void 0 ? void 0 : placeholder.sources) {
|
|
395
|
+
(_c = output.placeholder) === null || _c === void 0 ? void 0 : (_b = _c.sources).push.apply(_b, __spreadArray([], __read(placeholder.sources), false));
|
|
396
|
+
}
|
|
397
|
+
return output;
|
|
398
|
+
}
|
|
399
|
+
exports.withArtDirection = withArtDirection;
|