@lumx/react 2.1.8 → 2.1.9-alpha-thumbnail
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/esm/_internal/List2.js.map +1 -1
- package/esm/_internal/Slider2.js +21 -2
- package/esm/_internal/Slider2.js.map +1 -1
- package/esm/_internal/Thumbnail2.js +63 -764
- package/esm/_internal/Thumbnail2.js.map +1 -1
- package/esm/_internal/avatar.js +0 -3
- package/esm/_internal/avatar.js.map +1 -1
- package/esm/_internal/comment-block.js +0 -3
- package/esm/_internal/comment-block.js.map +1 -1
- package/esm/_internal/image-block.js +0 -3
- package/esm/_internal/image-block.js.map +1 -1
- package/esm/_internal/link-preview.js +0 -3
- package/esm/_internal/link-preview.js.map +1 -1
- package/esm/_internal/mdi.js +2 -2
- package/esm/_internal/mdi.js.map +1 -1
- package/esm/_internal/mosaic.js +0 -3
- package/esm/_internal/mosaic.js.map +1 -1
- package/esm/_internal/post-block.js +0 -3
- package/esm/_internal/post-block.js.map +1 -1
- package/esm/_internal/slider.js +1 -2
- package/esm/_internal/slider.js.map +1 -1
- package/esm/_internal/thumbnail.js +0 -3
- package/esm/_internal/thumbnail.js.map +1 -1
- package/esm/_internal/user-block.js +0 -2
- package/esm/_internal/user-block.js.map +1 -1
- package/esm/index.js +2 -3
- package/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/thumbnail/Thumbnail.stories.tsx +343 -59
- package/src/components/thumbnail/Thumbnail.test.tsx +6 -6
- package/src/components/thumbnail/Thumbnail.tsx +37 -34
- package/src/components/thumbnail/useFocusPoint.ts +18 -10
- package/src/components/thumbnail/useImageLoad.ts +23 -22
- package/src/hooks/useOnResize.ts +6 -0
- package/src/stories/knobs/image.ts +35 -3
- package/types.d.ts +2 -0
- package/esm/_internal/clamp.js +0 -22
- package/esm/_internal/clamp.js.map +0 -1
|
@@ -1,752 +1,54 @@
|
|
|
1
|
-
import { d as _slicedToArray,
|
|
2
|
-
import {
|
|
3
|
-
import React, {
|
|
1
|
+
import { d as _slicedToArray, b as _objectWithoutProperties, _ as _objectSpread2, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
2
|
+
import { Size, Theme, AspectRatio } from './components.js';
|
|
3
|
+
import React, { useState, useEffect, forwardRef, useRef } from 'react';
|
|
4
4
|
import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
5
|
-
import { r as
|
|
6
|
-
import { W as WINDOW } from './constants.js';
|
|
5
|
+
import { r as mdiImageBroken } from './mdi.js';
|
|
7
6
|
import { m as mergeRefs } from './mergeRefs.js';
|
|
8
7
|
import { I as Icon } from './Icon2.js';
|
|
9
|
-
import { c as clamp } from './clamp.js';
|
|
10
|
-
import { isEqual } from 'lodash';
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var isInternetExplorer = function isInternetExplorer() {
|
|
18
|
-
var _WINDOW$navigator;
|
|
19
|
-
|
|
20
|
-
var userAgent = WINDOW === null || WINDOW === void 0 ? void 0 : (_WINDOW$navigator = WINDOW.navigator) === null || _WINDOW$navigator === void 0 ? void 0 : _WINDOW$navigator.userAgent;
|
|
21
|
-
|
|
22
|
-
if (!userAgent) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var msie = userAgent.indexOf('MSIE ');
|
|
27
|
-
var isIEVersion = !!userAgent.match(/Trident.*rv:11\./);
|
|
28
|
-
return msie > 0 || isIEVersion;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
var resizeObservers = [];
|
|
32
|
-
|
|
33
|
-
var hasActiveObservations = function () {
|
|
34
|
-
return resizeObservers.some(function (ro) { return ro.activeTargets.length > 0; });
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
var hasSkippedObservations = function () {
|
|
38
|
-
return resizeObservers.some(function (ro) { return ro.skippedTargets.length > 0; });
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
var msg = 'ResizeObserver loop completed with undelivered notifications.';
|
|
42
|
-
var deliverResizeLoopError = function () {
|
|
43
|
-
var event;
|
|
44
|
-
if (typeof ErrorEvent === 'function') {
|
|
45
|
-
event = new ErrorEvent('error', {
|
|
46
|
-
message: msg
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
event = document.createEvent('Event');
|
|
51
|
-
event.initEvent('error', false, false);
|
|
52
|
-
event.message = msg;
|
|
53
|
-
}
|
|
54
|
-
window.dispatchEvent(event);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
var ResizeObserverBoxOptions;
|
|
58
|
-
(function (ResizeObserverBoxOptions) {
|
|
59
|
-
ResizeObserverBoxOptions["BORDER_BOX"] = "border-box";
|
|
60
|
-
ResizeObserverBoxOptions["CONTENT_BOX"] = "content-box";
|
|
61
|
-
ResizeObserverBoxOptions["DEVICE_PIXEL_CONTENT_BOX"] = "device-pixel-content-box";
|
|
62
|
-
})(ResizeObserverBoxOptions || (ResizeObserverBoxOptions = {}));
|
|
63
|
-
|
|
64
|
-
var DOMRectReadOnly = (function () {
|
|
65
|
-
function DOMRectReadOnly(x, y, width, height) {
|
|
66
|
-
this.x = x;
|
|
67
|
-
this.y = y;
|
|
68
|
-
this.width = width;
|
|
69
|
-
this.height = height;
|
|
70
|
-
this.top = this.y;
|
|
71
|
-
this.left = this.x;
|
|
72
|
-
this.bottom = this.top + this.height;
|
|
73
|
-
this.right = this.left + this.width;
|
|
74
|
-
return Object.freeze(this);
|
|
75
|
-
}
|
|
76
|
-
DOMRectReadOnly.prototype.toJSON = function () {
|
|
77
|
-
var _a = this, x = _a.x, y = _a.y, top = _a.top, right = _a.right, bottom = _a.bottom, left = _a.left, width = _a.width, height = _a.height;
|
|
78
|
-
return { x: x, y: y, top: top, right: right, bottom: bottom, left: left, width: width, height: height };
|
|
79
|
-
};
|
|
80
|
-
DOMRectReadOnly.fromRect = function (rectangle) {
|
|
81
|
-
return new DOMRectReadOnly(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
|
82
|
-
};
|
|
83
|
-
return DOMRectReadOnly;
|
|
84
|
-
}());
|
|
85
|
-
|
|
86
|
-
var isSVG = function (target) { return target instanceof SVGElement && 'getBBox' in target; };
|
|
87
|
-
var isHidden = function (target) {
|
|
88
|
-
if (isSVG(target)) {
|
|
89
|
-
var _a = target.getBBox(), width = _a.width, height = _a.height;
|
|
90
|
-
return !width && !height;
|
|
91
|
-
}
|
|
92
|
-
var _b = target, offsetWidth = _b.offsetWidth, offsetHeight = _b.offsetHeight;
|
|
93
|
-
return !(offsetWidth || offsetHeight || target.getClientRects().length);
|
|
94
|
-
};
|
|
95
|
-
var isElement = function (obj) {
|
|
96
|
-
var _a, _b;
|
|
97
|
-
var scope = (_b = (_a = obj) === null || _a === void 0 ? void 0 : _a.ownerDocument) === null || _b === void 0 ? void 0 : _b.defaultView;
|
|
98
|
-
return !!(scope && obj instanceof scope.Element);
|
|
99
|
-
};
|
|
100
|
-
var isReplacedElement = function (target) {
|
|
101
|
-
switch (target.tagName) {
|
|
102
|
-
case 'INPUT':
|
|
103
|
-
if (target.type !== 'image') {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
case 'VIDEO':
|
|
107
|
-
case 'AUDIO':
|
|
108
|
-
case 'EMBED':
|
|
109
|
-
case 'OBJECT':
|
|
110
|
-
case 'CANVAS':
|
|
111
|
-
case 'IFRAME':
|
|
112
|
-
case 'IMG':
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
return false;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
var global = typeof window !== 'undefined' ? window : {};
|
|
119
|
-
|
|
120
|
-
var cache = new WeakMap();
|
|
121
|
-
var scrollRegexp = /auto|scroll/;
|
|
122
|
-
var verticalRegexp = /^tb|vertical/;
|
|
123
|
-
var IE = (/msie|trident/i).test(global.navigator && global.navigator.userAgent);
|
|
124
|
-
var parseDimension = function (pixel) { return parseFloat(pixel || '0'); };
|
|
125
|
-
var size = function (inlineSize, blockSize, switchSizes) {
|
|
126
|
-
if (inlineSize === void 0) { inlineSize = 0; }
|
|
127
|
-
if (blockSize === void 0) { blockSize = 0; }
|
|
128
|
-
if (switchSizes === void 0) { switchSizes = false; }
|
|
129
|
-
return Object.freeze({
|
|
130
|
-
inlineSize: (switchSizes ? blockSize : inlineSize) || 0,
|
|
131
|
-
blockSize: (switchSizes ? inlineSize : blockSize) || 0
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
var zeroBoxes = Object.freeze({
|
|
135
|
-
devicePixelContentBoxSize: size(),
|
|
136
|
-
borderBoxSize: size(),
|
|
137
|
-
contentBoxSize: size(),
|
|
138
|
-
contentRect: new DOMRectReadOnly(0, 0, 0, 0)
|
|
139
|
-
});
|
|
140
|
-
var calculateBoxSizes = function (target, forceRecalculation) {
|
|
141
|
-
if (forceRecalculation === void 0) { forceRecalculation = false; }
|
|
142
|
-
if (cache.has(target) && !forceRecalculation) {
|
|
143
|
-
return cache.get(target);
|
|
144
|
-
}
|
|
145
|
-
if (isHidden(target)) {
|
|
146
|
-
cache.set(target, zeroBoxes);
|
|
147
|
-
return zeroBoxes;
|
|
148
|
-
}
|
|
149
|
-
var cs = getComputedStyle(target);
|
|
150
|
-
var svg = isSVG(target) && target.ownerSVGElement && target.getBBox();
|
|
151
|
-
var removePadding = !IE && cs.boxSizing === 'border-box';
|
|
152
|
-
var switchSizes = verticalRegexp.test(cs.writingMode || '');
|
|
153
|
-
var canScrollVertically = !svg && scrollRegexp.test(cs.overflowY || '');
|
|
154
|
-
var canScrollHorizontally = !svg && scrollRegexp.test(cs.overflowX || '');
|
|
155
|
-
var paddingTop = svg ? 0 : parseDimension(cs.paddingTop);
|
|
156
|
-
var paddingRight = svg ? 0 : parseDimension(cs.paddingRight);
|
|
157
|
-
var paddingBottom = svg ? 0 : parseDimension(cs.paddingBottom);
|
|
158
|
-
var paddingLeft = svg ? 0 : parseDimension(cs.paddingLeft);
|
|
159
|
-
var borderTop = svg ? 0 : parseDimension(cs.borderTopWidth);
|
|
160
|
-
var borderRight = svg ? 0 : parseDimension(cs.borderRightWidth);
|
|
161
|
-
var borderBottom = svg ? 0 : parseDimension(cs.borderBottomWidth);
|
|
162
|
-
var borderLeft = svg ? 0 : parseDimension(cs.borderLeftWidth);
|
|
163
|
-
var horizontalPadding = paddingLeft + paddingRight;
|
|
164
|
-
var verticalPadding = paddingTop + paddingBottom;
|
|
165
|
-
var horizontalBorderArea = borderLeft + borderRight;
|
|
166
|
-
var verticalBorderArea = borderTop + borderBottom;
|
|
167
|
-
var horizontalScrollbarThickness = !canScrollHorizontally ? 0 : target.offsetHeight - verticalBorderArea - target.clientHeight;
|
|
168
|
-
var verticalScrollbarThickness = !canScrollVertically ? 0 : target.offsetWidth - horizontalBorderArea - target.clientWidth;
|
|
169
|
-
var widthReduction = removePadding ? horizontalPadding + horizontalBorderArea : 0;
|
|
170
|
-
var heightReduction = removePadding ? verticalPadding + verticalBorderArea : 0;
|
|
171
|
-
var contentWidth = svg ? svg.width : parseDimension(cs.width) - widthReduction - verticalScrollbarThickness;
|
|
172
|
-
var contentHeight = svg ? svg.height : parseDimension(cs.height) - heightReduction - horizontalScrollbarThickness;
|
|
173
|
-
var borderBoxWidth = contentWidth + horizontalPadding + verticalScrollbarThickness + horizontalBorderArea;
|
|
174
|
-
var borderBoxHeight = contentHeight + verticalPadding + horizontalScrollbarThickness + verticalBorderArea;
|
|
175
|
-
var boxes = Object.freeze({
|
|
176
|
-
devicePixelContentBoxSize: size(Math.round(contentWidth * devicePixelRatio), Math.round(contentHeight * devicePixelRatio), switchSizes),
|
|
177
|
-
borderBoxSize: size(borderBoxWidth, borderBoxHeight, switchSizes),
|
|
178
|
-
contentBoxSize: size(contentWidth, contentHeight, switchSizes),
|
|
179
|
-
contentRect: new DOMRectReadOnly(paddingLeft, paddingTop, contentWidth, contentHeight)
|
|
180
|
-
});
|
|
181
|
-
cache.set(target, boxes);
|
|
182
|
-
return boxes;
|
|
183
|
-
};
|
|
184
|
-
var calculateBoxSize = function (target, observedBox, forceRecalculation) {
|
|
185
|
-
var _a = calculateBoxSizes(target, forceRecalculation), borderBoxSize = _a.borderBoxSize, contentBoxSize = _a.contentBoxSize, devicePixelContentBoxSize = _a.devicePixelContentBoxSize;
|
|
186
|
-
switch (observedBox) {
|
|
187
|
-
case ResizeObserverBoxOptions.DEVICE_PIXEL_CONTENT_BOX:
|
|
188
|
-
return devicePixelContentBoxSize;
|
|
189
|
-
case ResizeObserverBoxOptions.BORDER_BOX:
|
|
190
|
-
return borderBoxSize;
|
|
191
|
-
default:
|
|
192
|
-
return contentBoxSize;
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
var ResizeObserverEntry = (function () {
|
|
197
|
-
function ResizeObserverEntry(target) {
|
|
198
|
-
var boxes = calculateBoxSizes(target);
|
|
199
|
-
this.target = target;
|
|
200
|
-
this.contentRect = boxes.contentRect;
|
|
201
|
-
this.borderBoxSize = [boxes.borderBoxSize];
|
|
202
|
-
this.contentBoxSize = [boxes.contentBoxSize];
|
|
203
|
-
this.devicePixelContentBoxSize = [boxes.devicePixelContentBoxSize];
|
|
204
|
-
}
|
|
205
|
-
return ResizeObserverEntry;
|
|
206
|
-
}());
|
|
207
|
-
|
|
208
|
-
var calculateDepthForNode = function (node) {
|
|
209
|
-
if (isHidden(node)) {
|
|
210
|
-
return Infinity;
|
|
211
|
-
}
|
|
212
|
-
var depth = 0;
|
|
213
|
-
var parent = node.parentNode;
|
|
214
|
-
while (parent) {
|
|
215
|
-
depth += 1;
|
|
216
|
-
parent = parent.parentNode;
|
|
217
|
-
}
|
|
218
|
-
return depth;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
var broadcastActiveObservations = function () {
|
|
222
|
-
var shallowestDepth = Infinity;
|
|
223
|
-
var callbacks = [];
|
|
224
|
-
resizeObservers.forEach(function processObserver(ro) {
|
|
225
|
-
if (ro.activeTargets.length === 0) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
var entries = [];
|
|
229
|
-
ro.activeTargets.forEach(function processTarget(ot) {
|
|
230
|
-
var entry = new ResizeObserverEntry(ot.target);
|
|
231
|
-
var targetDepth = calculateDepthForNode(ot.target);
|
|
232
|
-
entries.push(entry);
|
|
233
|
-
ot.lastReportedSize = calculateBoxSize(ot.target, ot.observedBox);
|
|
234
|
-
if (targetDepth < shallowestDepth) {
|
|
235
|
-
shallowestDepth = targetDepth;
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
callbacks.push(function resizeObserverCallback() {
|
|
239
|
-
ro.callback.call(ro.observer, entries, ro.observer);
|
|
240
|
-
});
|
|
241
|
-
ro.activeTargets.splice(0, ro.activeTargets.length);
|
|
242
|
-
});
|
|
243
|
-
for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
|
|
244
|
-
var callback = callbacks_1[_i];
|
|
245
|
-
callback();
|
|
246
|
-
}
|
|
247
|
-
return shallowestDepth;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
var gatherActiveObservationsAtDepth = function (depth) {
|
|
251
|
-
resizeObservers.forEach(function processObserver(ro) {
|
|
252
|
-
ro.activeTargets.splice(0, ro.activeTargets.length);
|
|
253
|
-
ro.skippedTargets.splice(0, ro.skippedTargets.length);
|
|
254
|
-
ro.observationTargets.forEach(function processTarget(ot) {
|
|
255
|
-
if (ot.isActive()) {
|
|
256
|
-
if (calculateDepthForNode(ot.target) > depth) {
|
|
257
|
-
ro.activeTargets.push(ot);
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
ro.skippedTargets.push(ot);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
var process = function () {
|
|
268
|
-
var depth = 0;
|
|
269
|
-
gatherActiveObservationsAtDepth(depth);
|
|
270
|
-
while (hasActiveObservations()) {
|
|
271
|
-
depth = broadcastActiveObservations();
|
|
272
|
-
gatherActiveObservationsAtDepth(depth);
|
|
273
|
-
}
|
|
274
|
-
if (hasSkippedObservations()) {
|
|
275
|
-
deliverResizeLoopError();
|
|
276
|
-
}
|
|
277
|
-
return depth > 0;
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
var trigger;
|
|
281
|
-
var callbacks = [];
|
|
282
|
-
var notify = function () { return callbacks.splice(0).forEach(function (cb) { return cb(); }); };
|
|
283
|
-
var queueMicroTask = function (callback) {
|
|
284
|
-
if (!trigger) {
|
|
285
|
-
var toggle_1 = 0;
|
|
286
|
-
var el_1 = document.createTextNode('');
|
|
287
|
-
var config = { characterData: true };
|
|
288
|
-
new MutationObserver(function () { return notify(); }).observe(el_1, config);
|
|
289
|
-
trigger = function () { el_1.textContent = "" + (toggle_1 ? toggle_1-- : toggle_1++); };
|
|
290
|
-
}
|
|
291
|
-
callbacks.push(callback);
|
|
292
|
-
trigger();
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
var queueResizeObserver = function (cb) {
|
|
296
|
-
queueMicroTask(function ResizeObserver() {
|
|
297
|
-
requestAnimationFrame(cb);
|
|
298
|
-
});
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
var watching = 0;
|
|
302
|
-
var isWatching = function () { return !!watching; };
|
|
303
|
-
var CATCH_PERIOD = 250;
|
|
304
|
-
var observerConfig = { attributes: true, characterData: true, childList: true, subtree: true };
|
|
305
|
-
var events = [
|
|
306
|
-
'resize',
|
|
307
|
-
'load',
|
|
308
|
-
'transitionend',
|
|
309
|
-
'animationend',
|
|
310
|
-
'animationstart',
|
|
311
|
-
'animationiteration',
|
|
312
|
-
'keyup',
|
|
313
|
-
'keydown',
|
|
314
|
-
'mouseup',
|
|
315
|
-
'mousedown',
|
|
316
|
-
'mouseover',
|
|
317
|
-
'mouseout',
|
|
318
|
-
'blur',
|
|
319
|
-
'focus'
|
|
320
|
-
];
|
|
321
|
-
var time = function (timeout) {
|
|
322
|
-
if (timeout === void 0) { timeout = 0; }
|
|
323
|
-
return Date.now() + timeout;
|
|
324
|
-
};
|
|
325
|
-
var scheduled = false;
|
|
326
|
-
var Scheduler = (function () {
|
|
327
|
-
function Scheduler() {
|
|
328
|
-
var _this = this;
|
|
329
|
-
this.stopped = true;
|
|
330
|
-
this.listener = function () { return _this.schedule(); };
|
|
331
|
-
}
|
|
332
|
-
Scheduler.prototype.run = function (timeout) {
|
|
333
|
-
var _this = this;
|
|
334
|
-
if (timeout === void 0) { timeout = CATCH_PERIOD; }
|
|
335
|
-
if (scheduled) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
scheduled = true;
|
|
339
|
-
var until = time(timeout);
|
|
340
|
-
queueResizeObserver(function () {
|
|
341
|
-
var elementsHaveResized = false;
|
|
342
|
-
try {
|
|
343
|
-
elementsHaveResized = process();
|
|
344
|
-
}
|
|
345
|
-
finally {
|
|
346
|
-
scheduled = false;
|
|
347
|
-
timeout = until - time();
|
|
348
|
-
if (!isWatching()) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
if (elementsHaveResized) {
|
|
352
|
-
_this.run(1000);
|
|
353
|
-
}
|
|
354
|
-
else if (timeout > 0) {
|
|
355
|
-
_this.run(timeout);
|
|
356
|
-
}
|
|
357
|
-
else {
|
|
358
|
-
_this.start();
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
};
|
|
363
|
-
Scheduler.prototype.schedule = function () {
|
|
364
|
-
this.stop();
|
|
365
|
-
this.run();
|
|
366
|
-
};
|
|
367
|
-
Scheduler.prototype.observe = function () {
|
|
368
|
-
var _this = this;
|
|
369
|
-
var cb = function () { return _this.observer && _this.observer.observe(document.body, observerConfig); };
|
|
370
|
-
document.body ? cb() : global.addEventListener('DOMContentLoaded', cb);
|
|
371
|
-
};
|
|
372
|
-
Scheduler.prototype.start = function () {
|
|
373
|
-
var _this = this;
|
|
374
|
-
if (this.stopped) {
|
|
375
|
-
this.stopped = false;
|
|
376
|
-
this.observer = new MutationObserver(this.listener);
|
|
377
|
-
this.observe();
|
|
378
|
-
events.forEach(function (name) { return global.addEventListener(name, _this.listener, true); });
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
Scheduler.prototype.stop = function () {
|
|
382
|
-
var _this = this;
|
|
383
|
-
if (!this.stopped) {
|
|
384
|
-
this.observer && this.observer.disconnect();
|
|
385
|
-
events.forEach(function (name) { return global.removeEventListener(name, _this.listener, true); });
|
|
386
|
-
this.stopped = true;
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
return Scheduler;
|
|
390
|
-
}());
|
|
391
|
-
var scheduler = new Scheduler();
|
|
392
|
-
var updateCount = function (n) {
|
|
393
|
-
!watching && n > 0 && scheduler.start();
|
|
394
|
-
watching += n;
|
|
395
|
-
!watching && scheduler.stop();
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
var skipNotifyOnElement = function (target) {
|
|
399
|
-
return !isSVG(target)
|
|
400
|
-
&& !isReplacedElement(target)
|
|
401
|
-
&& getComputedStyle(target).display === 'inline';
|
|
402
|
-
};
|
|
403
|
-
var ResizeObservation = (function () {
|
|
404
|
-
function ResizeObservation(target, observedBox) {
|
|
405
|
-
this.target = target;
|
|
406
|
-
this.observedBox = observedBox || ResizeObserverBoxOptions.CONTENT_BOX;
|
|
407
|
-
this.lastReportedSize = {
|
|
408
|
-
inlineSize: 0,
|
|
409
|
-
blockSize: 0
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
ResizeObservation.prototype.isActive = function () {
|
|
413
|
-
var size = calculateBoxSize(this.target, this.observedBox, true);
|
|
414
|
-
if (skipNotifyOnElement(this.target)) {
|
|
415
|
-
this.lastReportedSize = size;
|
|
416
|
-
}
|
|
417
|
-
if (this.lastReportedSize.inlineSize !== size.inlineSize
|
|
418
|
-
|| this.lastReportedSize.blockSize !== size.blockSize) {
|
|
419
|
-
return true;
|
|
420
|
-
}
|
|
421
|
-
return false;
|
|
422
|
-
};
|
|
423
|
-
return ResizeObservation;
|
|
424
|
-
}());
|
|
425
|
-
|
|
426
|
-
var ResizeObserverDetail = (function () {
|
|
427
|
-
function ResizeObserverDetail(resizeObserver, callback) {
|
|
428
|
-
this.activeTargets = [];
|
|
429
|
-
this.skippedTargets = [];
|
|
430
|
-
this.observationTargets = [];
|
|
431
|
-
this.observer = resizeObserver;
|
|
432
|
-
this.callback = callback;
|
|
433
|
-
}
|
|
434
|
-
return ResizeObserverDetail;
|
|
435
|
-
}());
|
|
436
|
-
|
|
437
|
-
var observerMap = new WeakMap();
|
|
438
|
-
var getObservationIndex = function (observationTargets, target) {
|
|
439
|
-
for (var i = 0; i < observationTargets.length; i += 1) {
|
|
440
|
-
if (observationTargets[i].target === target) {
|
|
441
|
-
return i;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
return -1;
|
|
445
|
-
};
|
|
446
|
-
var ResizeObserverController = (function () {
|
|
447
|
-
function ResizeObserverController() {
|
|
448
|
-
}
|
|
449
|
-
ResizeObserverController.connect = function (resizeObserver, callback) {
|
|
450
|
-
var detail = new ResizeObserverDetail(resizeObserver, callback);
|
|
451
|
-
observerMap.set(resizeObserver, detail);
|
|
452
|
-
};
|
|
453
|
-
ResizeObserverController.observe = function (resizeObserver, target, options) {
|
|
454
|
-
var detail = observerMap.get(resizeObserver);
|
|
455
|
-
var firstObservation = detail.observationTargets.length === 0;
|
|
456
|
-
if (getObservationIndex(detail.observationTargets, target) < 0) {
|
|
457
|
-
firstObservation && resizeObservers.push(detail);
|
|
458
|
-
detail.observationTargets.push(new ResizeObservation(target, options && options.box));
|
|
459
|
-
updateCount(1);
|
|
460
|
-
scheduler.schedule();
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
ResizeObserverController.unobserve = function (resizeObserver, target) {
|
|
464
|
-
var detail = observerMap.get(resizeObserver);
|
|
465
|
-
var index = getObservationIndex(detail.observationTargets, target);
|
|
466
|
-
var lastObservation = detail.observationTargets.length === 1;
|
|
467
|
-
if (index >= 0) {
|
|
468
|
-
lastObservation && resizeObservers.splice(resizeObservers.indexOf(detail), 1);
|
|
469
|
-
detail.observationTargets.splice(index, 1);
|
|
470
|
-
updateCount(-1);
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
ResizeObserverController.disconnect = function (resizeObserver) {
|
|
474
|
-
var _this = this;
|
|
475
|
-
var detail = observerMap.get(resizeObserver);
|
|
476
|
-
detail.observationTargets.slice().forEach(function (ot) { return _this.unobserve(resizeObserver, ot.target); });
|
|
477
|
-
detail.activeTargets.splice(0, detail.activeTargets.length);
|
|
478
|
-
};
|
|
479
|
-
return ResizeObserverController;
|
|
480
|
-
}());
|
|
481
|
-
|
|
482
|
-
var ResizeObserver = (function () {
|
|
483
|
-
function ResizeObserver(callback) {
|
|
484
|
-
if (arguments.length === 0) {
|
|
485
|
-
throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
486
|
-
}
|
|
487
|
-
if (typeof callback !== 'function') {
|
|
488
|
-
throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");
|
|
489
|
-
}
|
|
490
|
-
ResizeObserverController.connect(this, callback);
|
|
491
|
-
}
|
|
492
|
-
ResizeObserver.prototype.observe = function (target, options) {
|
|
493
|
-
if (arguments.length === 0) {
|
|
494
|
-
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
495
|
-
}
|
|
496
|
-
if (!isElement(target)) {
|
|
497
|
-
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
|
|
498
|
-
}
|
|
499
|
-
ResizeObserverController.observe(this, target, options);
|
|
500
|
-
};
|
|
501
|
-
ResizeObserver.prototype.unobserve = function (target) {
|
|
502
|
-
if (arguments.length === 0) {
|
|
503
|
-
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
|
|
504
|
-
}
|
|
505
|
-
if (!isElement(target)) {
|
|
506
|
-
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
|
|
507
|
-
}
|
|
508
|
-
ResizeObserverController.unobserve(this, target);
|
|
509
|
-
};
|
|
510
|
-
ResizeObserver.prototype.disconnect = function () {
|
|
511
|
-
ResizeObserverController.disconnect(this);
|
|
512
|
-
};
|
|
513
|
-
ResizeObserver.toString = function () {
|
|
514
|
-
return 'function ResizeObserver () { [polyfill code] }';
|
|
515
|
-
};
|
|
516
|
-
return ResizeObserver;
|
|
517
|
-
}());
|
|
518
|
-
|
|
519
|
-
var _ref;
|
|
520
|
-
var ResizeObserver$1 = ((_ref = WINDOW) === null || _ref === void 0 ? void 0 : _ref.ResizeObserver) || ResizeObserver;
|
|
521
|
-
function useOnResize(element, update) {
|
|
522
|
-
var observerRef = useRef(null);
|
|
523
|
-
var previousSize = useRef();
|
|
524
|
-
useEffect(function () {
|
|
525
|
-
if (!element || !update) {
|
|
526
|
-
return undefined;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
previousSize.current = undefined;
|
|
530
|
-
var observer = observerRef.current || new ResizeObserver$1(function (_ref2) {
|
|
531
|
-
var _previousSize$current, _previousSize$current2;
|
|
532
|
-
|
|
533
|
-
var _ref3 = _slicedToArray(_ref2, 1),
|
|
534
|
-
entry = _ref3[0];
|
|
535
|
-
|
|
536
|
-
var updateFunction = update.current;
|
|
537
|
-
|
|
538
|
-
if (!updateFunction) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
9
|
+
function getState(img, event) {
|
|
10
|
+
// Error event occurred or image loaded empty.
|
|
11
|
+
if ((event === null || event === void 0 ? void 0 : event.type) === 'error' || (img === null || img === void 0 ? void 0 : img.complete) && ((img === null || img === void 0 ? void 0 : img.naturalWidth) === 0 || (img === null || img === void 0 ? void 0 : img.naturalHeight) === 0)) {
|
|
12
|
+
return 'hasError';
|
|
13
|
+
} // Image is undefined or incomplete.
|
|
541
14
|
|
|
542
|
-
var _entry$contentRect = entry.contentRect,
|
|
543
|
-
width = _entry$contentRect.width,
|
|
544
|
-
height = _entry$contentRect.height;
|
|
545
15
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
16
|
+
if (!img || !img.complete) {
|
|
17
|
+
return 'isLoading';
|
|
18
|
+
} // Else loaded.
|
|
549
19
|
|
|
550
|
-
window.requestAnimationFrame(function () {
|
|
551
|
-
return updateFunction();
|
|
552
|
-
});
|
|
553
|
-
previousSize.current = entry.contentRect;
|
|
554
|
-
});
|
|
555
|
-
if (!observerRef.current) observerRef.current = observer;
|
|
556
|
-
observer.observe(element);
|
|
557
|
-
return function () {
|
|
558
|
-
observer.unobserve(element);
|
|
559
|
-
};
|
|
560
|
-
}, [element, update]);
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
var IMG_STYLES = {
|
|
564
|
-
bottom: 0,
|
|
565
|
-
left: 0,
|
|
566
|
-
position: 'absolute',
|
|
567
|
-
right: 0,
|
|
568
|
-
top: 0,
|
|
569
|
-
minHeight: '100%',
|
|
570
|
-
minWidth: '100%'
|
|
571
|
-
};
|
|
572
|
-
var WRAPPER_STYLES = {
|
|
573
|
-
overflow: 'hidden',
|
|
574
|
-
position: 'relative'
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
function calculateSizes(imageElement, parentElement, aspectRatio) {
|
|
578
|
-
if (!imageElement || !parentElement || !aspectRatio || aspectRatio === AspectRatio.original) return undefined;
|
|
579
|
-
|
|
580
|
-
var _ref = imageElement || {
|
|
581
|
-
naturalWidth: 0,
|
|
582
|
-
naturalHeight: 0
|
|
583
|
-
},
|
|
584
|
-
imgWidth = _ref.naturalWidth,
|
|
585
|
-
imgHeight = _ref.naturalHeight;
|
|
586
|
-
|
|
587
|
-
var _ref2 = (parentElement === null || parentElement === void 0 ? void 0 : parentElement.getBoundingClientRect()) || {
|
|
588
|
-
width: 0,
|
|
589
|
-
height: 0
|
|
590
|
-
},
|
|
591
|
-
containerWidth = _ref2.width,
|
|
592
|
-
containerHeight = _ref2.height;
|
|
593
|
-
|
|
594
|
-
return {
|
|
595
|
-
imgWidth: imgWidth,
|
|
596
|
-
imgHeight: imgHeight,
|
|
597
|
-
containerWidth: containerWidth,
|
|
598
|
-
containerHeight: containerHeight,
|
|
599
|
-
aspectRatio: aspectRatio
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
var parseFocusPoint = function parseFocusPoint() {
|
|
604
|
-
var point = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
605
|
-
return {
|
|
606
|
-
x: point.x ? clamp(point.x, -1, 1) : 0,
|
|
607
|
-
y: point.y ? clamp(point.y, -1, 1) : 0
|
|
608
|
-
};
|
|
609
|
-
};
|
|
610
|
-
|
|
611
|
-
function calculateImageShift(containerToImageSizeRatio, containerSize, imageSize, focusSize, toMinus) {
|
|
612
|
-
var containerCenter = Math.floor(containerSize / 2); // Container center in px
|
|
613
|
-
|
|
614
|
-
var focusFactor = (focusSize + 1) / 2; // Focus point of resize image in px
|
|
615
|
-
|
|
616
|
-
var scaledImage = Math.floor(imageSize / containerToImageSizeRatio); // Can't use width() as images may be display:none
|
|
617
|
-
|
|
618
|
-
var focus = Math.floor(focusFactor * scaledImage);
|
|
619
|
-
|
|
620
|
-
if (toMinus) {
|
|
621
|
-
focus = scaledImage - focus;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
var focusOffset = focus - containerCenter; // Calculate difference between focus point and center
|
|
625
|
-
|
|
626
|
-
var remainder = scaledImage - focus; // Reduce offset if necessary so image remains filled
|
|
627
20
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
if (remainder < containerRemainder) {
|
|
631
|
-
focusOffset -= containerRemainder - remainder;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
if (focusOffset < 0) {
|
|
635
|
-
focusOffset = 0;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
return focusOffset * -100 / containerSize;
|
|
21
|
+
return 'isLoaded';
|
|
639
22
|
}
|
|
640
23
|
|
|
641
|
-
function
|
|
642
|
-
if (!sizes.imgWidth || !sizes.imgHeight || !sizes.containerWidth || !sizes.containerHeight) {
|
|
643
|
-
return undefined;
|
|
644
|
-
} // Which is over by more?
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
var widthRatio = sizes.imgWidth / sizes.containerWidth;
|
|
648
|
-
var heightRatio = sizes.imgHeight / sizes.containerHeight;
|
|
649
|
-
|
|
650
|
-
var image = _objectSpread2({}, IMG_STYLES); // Minimize image while still filling space
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
if (sizes.imgWidth > sizes.containerWidth && sizes.imgHeight > sizes.containerHeight) {
|
|
654
|
-
image[widthRatio > heightRatio ? 'maxHeight' : 'maxWidth'] = '100%';
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
if (widthRatio > heightRatio) {
|
|
658
|
-
image.left = "".concat(calculateImageShift(heightRatio, sizes.containerWidth, sizes.imgWidth, point.x), "%");
|
|
659
|
-
} else if (widthRatio < heightRatio) {
|
|
660
|
-
image.top = "".concat(calculateImageShift(widthRatio, sizes.containerHeight, sizes.imgHeight, point.y, true), "%");
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
return {
|
|
664
|
-
image: image,
|
|
665
|
-
wrapper: WRAPPER_STYLES
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* Hook that calculate CSS style to shift the image in it's container according to the focus point.
|
|
670
|
-
*/
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
var useFocusPoint = function useFocusPoint(options) {
|
|
674
|
-
var image = options.image,
|
|
675
|
-
aspectRatio = options.aspectRatio,
|
|
676
|
-
focusPoint = options.focusPoint,
|
|
677
|
-
imgRef = options.imgRef,
|
|
678
|
-
loadingState = options.loadingState,
|
|
679
|
-
wrapper = options.wrapper;
|
|
680
|
-
var point = parseFocusPoint(focusPoint);
|
|
681
|
-
var previousPoint = useRef();
|
|
682
|
-
var previousSizes = useRef({});
|
|
683
|
-
|
|
684
|
-
var _useState = useState(),
|
|
685
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
686
|
-
style = _useState2[0],
|
|
687
|
-
setStyle = _useState2[1]; // Update style.
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
var updateRef = useRef(null);
|
|
691
|
-
var update = useMemo(function () {
|
|
692
|
-
var updateFunction = function updateFunction() {
|
|
693
|
-
var sizes = calculateSizes(imgRef === null || imgRef === void 0 ? void 0 : imgRef.current, wrapper, aspectRatio);
|
|
694
|
-
|
|
695
|
-
if (!sizes || isEqual(sizes, previousSizes.current) && isEqual(point, previousPoint.current)) {
|
|
696
|
-
// Nothing changed.
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
setStyle(calculateImageStyle(sizes, point));
|
|
701
|
-
previousPoint.current = point;
|
|
702
|
-
previousSizes.current = sizes;
|
|
703
|
-
};
|
|
704
|
-
|
|
705
|
-
updateRef.current = updateFunction;
|
|
706
|
-
return updateFunction;
|
|
707
|
-
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
708
|
-
[].concat(_toConsumableArray(Object.values(point)), [imgRef, wrapper, aspectRatio])); // Update on image loaded.
|
|
709
|
-
|
|
710
|
-
useLayoutEffect(update, [image, update, loadingState]); // Update on parent resize.
|
|
711
|
-
|
|
712
|
-
useOnResize(wrapper, updateRef);
|
|
713
|
-
return style;
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
function useImageLoad(imgRef) {
|
|
24
|
+
function useImageLoad(imageURL, imgRef) {
|
|
717
25
|
var _imgRef$current;
|
|
718
26
|
|
|
719
|
-
var _useState = useState(
|
|
27
|
+
var _useState = useState(getState(imgRef === null || imgRef === void 0 ? void 0 : imgRef.current)),
|
|
720
28
|
_useState2 = _slicedToArray(_useState, 2),
|
|
721
29
|
state = _useState2[0],
|
|
722
|
-
setState = _useState2[1];
|
|
723
|
-
|
|
724
|
-
var update = useCallback(function (event) {
|
|
725
|
-
var img = imgRef === null || imgRef === void 0 ? void 0 : imgRef.current;
|
|
30
|
+
setState = _useState2[1]; // Update state when changing image URL or DOM reference.
|
|
726
31
|
|
|
727
|
-
if (!img || !img.complete) {
|
|
728
|
-
setState('isLoading');
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
32
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
33
|
+
useEffect(function () {
|
|
34
|
+
setState(getState(imgRef === null || imgRef === void 0 ? void 0 : imgRef.current));
|
|
35
|
+
}, [imageURL, imgRef]); // Listen to `load` and `error` event on image
|
|
736
36
|
|
|
737
|
-
setState('isLoaded');
|
|
738
|
-
}, [imgRef]);
|
|
739
37
|
useEffect(function () {
|
|
740
38
|
var img = imgRef === null || imgRef === void 0 ? void 0 : imgRef.current;
|
|
741
39
|
if (!img) return undefined;
|
|
742
|
-
|
|
40
|
+
|
|
41
|
+
var update = function update(event) {
|
|
42
|
+
return setState(getState(img, event));
|
|
43
|
+
};
|
|
44
|
+
|
|
743
45
|
img.addEventListener('load', update);
|
|
744
46
|
img.addEventListener('error', update);
|
|
745
47
|
return function () {
|
|
746
48
|
img.removeEventListener('load', update);
|
|
747
49
|
img.removeEventListener('error', update);
|
|
748
50
|
};
|
|
749
|
-
}, [
|
|
51
|
+
}, [imgRef, imgRef === null || imgRef === void 0 ? void 0 : (_imgRef$current = imgRef.current) === null || _imgRef$current === void 0 ? void 0 : _imgRef$current.src]);
|
|
750
52
|
return state;
|
|
751
53
|
}
|
|
752
54
|
|
|
@@ -764,10 +66,17 @@ var CLASSNAME = getRootClassName(COMPONENT_NAME);
|
|
|
764
66
|
*/
|
|
765
67
|
|
|
766
68
|
var DEFAULT_PROPS = {
|
|
767
|
-
fallback:
|
|
69
|
+
fallback: mdiImageBroken,
|
|
768
70
|
loading: 'lazy',
|
|
769
71
|
theme: Theme.light
|
|
770
72
|
};
|
|
73
|
+
|
|
74
|
+
function getObjectPosition(aspectRatio, focusPoint) {
|
|
75
|
+
if (aspectRatio === AspectRatio.original || !(focusPoint === null || focusPoint === void 0 ? void 0 : focusPoint.y) && !(focusPoint === null || focusPoint === void 0 ? void 0 : focusPoint.x)) return undefined;
|
|
76
|
+
var x = (((focusPoint === null || focusPoint === void 0 ? void 0 : focusPoint.x) || 0) + 1) / 2 * 100;
|
|
77
|
+
var y = (((focusPoint === null || focusPoint === void 0 ? void 0 : focusPoint.y) || 0) - 1) / 2 * 100;
|
|
78
|
+
return "".concat(x, "% ").concat(y, "%");
|
|
79
|
+
}
|
|
771
80
|
/**
|
|
772
81
|
* Thumbnail component.
|
|
773
82
|
*
|
|
@@ -776,12 +85,12 @@ var DEFAULT_PROPS = {
|
|
|
776
85
|
* @return React element.
|
|
777
86
|
*/
|
|
778
87
|
|
|
779
|
-
var Thumbnail = forwardRef(function (props, ref) {
|
|
780
|
-
var _wrapper$getBoundingC;
|
|
781
88
|
|
|
89
|
+
var Thumbnail = forwardRef(function (props, ref) {
|
|
782
90
|
var align = props.align,
|
|
783
91
|
alt = props.alt,
|
|
784
|
-
aspectRatio = props.aspectRatio,
|
|
92
|
+
_props$aspectRatio = props.aspectRatio,
|
|
93
|
+
aspectRatio = _props$aspectRatio === void 0 ? AspectRatio.original : _props$aspectRatio,
|
|
785
94
|
badge = props.badge,
|
|
786
95
|
className = props.className,
|
|
787
96
|
crossOrigin = props.crossOrigin,
|
|
@@ -791,25 +100,22 @@ var Thumbnail = forwardRef(function (props, ref) {
|
|
|
791
100
|
image = props.image,
|
|
792
101
|
imgProps = props.imgProps,
|
|
793
102
|
propImgRef = props.imgRef,
|
|
103
|
+
isLoadingProp = props.isLoading,
|
|
794
104
|
loading = props.loading,
|
|
795
105
|
size = props.size,
|
|
796
106
|
theme = props.theme,
|
|
797
107
|
variant = props.variant,
|
|
798
108
|
linkProps = props.linkProps,
|
|
799
109
|
linkAs = props.linkAs,
|
|
800
|
-
|
|
110
|
+
_props$showSkeletonLo = props.showSkeletonLoading,
|
|
111
|
+
showSkeletonLoading = _props$showSkeletonLo === void 0 ? true : _props$showSkeletonLo,
|
|
112
|
+
forwardedProps = _objectWithoutProperties(props, ["align", "alt", "aspectRatio", "badge", "className", "crossOrigin", "fallback", "fillHeight", "focusPoint", "image", "imgProps", "imgRef", "isLoading", "loading", "size", "theme", "variant", "linkProps", "linkAs", "showSkeletonLoading"]);
|
|
801
113
|
|
|
802
114
|
var imgRef = useRef(null); // Image loading state.
|
|
803
115
|
|
|
804
|
-
var loadingState = useImageLoad(imgRef);
|
|
116
|
+
var loadingState = useImageLoad(image, imgRef);
|
|
117
|
+
var isLoading = isLoadingProp || loadingState === 'isLoading';
|
|
805
118
|
var hasError = loadingState === 'hasError';
|
|
806
|
-
var isLoading = loadingState === 'isLoading';
|
|
807
|
-
|
|
808
|
-
var _useState = useState(),
|
|
809
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
810
|
-
wrapper = _useState2[0],
|
|
811
|
-
setWrapper = _useState2[1];
|
|
812
|
-
|
|
813
119
|
var isLink = Boolean((linkProps === null || linkProps === void 0 ? void 0 : linkProps.href) || linkAs);
|
|
814
120
|
var isButton = !!forwardedProps.onClick;
|
|
815
121
|
var isClickable = isButton || isLink;
|
|
@@ -822,19 +128,10 @@ var Thumbnail = forwardRef(function (props, ref) {
|
|
|
822
128
|
Object.assign(wrapperProps, linkProps);
|
|
823
129
|
} else if (isButton) {
|
|
824
130
|
Wrapper = 'button';
|
|
825
|
-
}
|
|
826
|
-
|
|
131
|
+
}
|
|
827
132
|
|
|
828
|
-
var style = useFocusPoint({
|
|
829
|
-
image: image,
|
|
830
|
-
focusPoint: focusPoint,
|
|
831
|
-
aspectRatio: aspectRatio,
|
|
832
|
-
imgRef: imgRef,
|
|
833
|
-
loadingState: loadingState,
|
|
834
|
-
wrapper: wrapper
|
|
835
|
-
});
|
|
836
133
|
return React.createElement(Wrapper, _extends({}, wrapperProps, {
|
|
837
|
-
ref:
|
|
134
|
+
ref: ref,
|
|
838
135
|
className: classnames(linkProps === null || linkProps === void 0 ? void 0 : linkProps.className, className, handleBasicClasses({
|
|
839
136
|
align: align,
|
|
840
137
|
aspectRatio: aspectRatio,
|
|
@@ -843,32 +140,34 @@ var Thumbnail = forwardRef(function (props, ref) {
|
|
|
843
140
|
theme: theme,
|
|
844
141
|
variant: variant,
|
|
845
142
|
isClickable: isClickable,
|
|
143
|
+
hasError: hasError,
|
|
144
|
+
isLoading: showSkeletonLoading && isLoading,
|
|
846
145
|
hasBadge: !!badge
|
|
847
|
-
}),
|
|
146
|
+
}), fillHeight && "".concat(CLASSNAME, "--fill-height"))
|
|
848
147
|
}), React.createElement("div", {
|
|
849
|
-
className: "".concat(CLASSNAME, "__background")
|
|
850
|
-
style: _objectSpread2({}, style === null || style === void 0 ? void 0 : style.wrapper, {
|
|
851
|
-
// Remove from layout if image not loaded correctly (use fallback)
|
|
852
|
-
display: hasError ? 'none' : undefined,
|
|
853
|
-
// Hide while loading.
|
|
854
|
-
visibility: isLoading ? 'hidden' : undefined
|
|
855
|
-
})
|
|
148
|
+
className: "".concat(CLASSNAME, "__background")
|
|
856
149
|
}, React.createElement("img", _extends({}, imgProps, {
|
|
857
|
-
style: _objectSpread2({}, imgProps === null || imgProps === void 0 ? void 0 : imgProps.style, {
|
|
150
|
+
style: _objectSpread2({}, imgProps === null || imgProps === void 0 ? void 0 : imgProps.style, {
|
|
151
|
+
//
|
|
152
|
+
//display: hasError && (!imgProps?.width || !imgProps?.height) ? 'none' : undefined,
|
|
153
|
+
// Hide while loading.
|
|
154
|
+
visibility: hasError || hasError && isLoading ? 'hidden' : undefined,
|
|
155
|
+
// Focus point.
|
|
156
|
+
objectPosition: getObjectPosition(aspectRatio, focusPoint)
|
|
157
|
+
}),
|
|
858
158
|
ref: mergeRefs(imgRef, propImgRef),
|
|
859
|
-
className: (
|
|
860
|
-
crossOrigin: crossOrigin
|
|
159
|
+
className: classnames("".concat(CLASSNAME, "__image"), isLoading && "".concat(CLASSNAME, "__image--is-loading")),
|
|
160
|
+
crossOrigin: crossOrigin,
|
|
861
161
|
src: image,
|
|
862
162
|
alt: alt,
|
|
863
163
|
loading: loading
|
|
864
|
-
}))
|
|
865
|
-
className: "".concat(CLASSNAME, "__fallback")
|
|
164
|
+
})), !isLoading && hasError && React.createElement("div", {
|
|
165
|
+
className: "".concat(CLASSNAME, "__fallback")
|
|
166
|
+
}, typeof fallback === 'string' ? React.createElement(Icon, {
|
|
866
167
|
icon: fallback,
|
|
867
|
-
size:
|
|
168
|
+
size: Size.xxs,
|
|
868
169
|
theme: theme
|
|
869
|
-
}) : React.
|
|
870
|
-
className: "".concat(CLASSNAME, "__fallback")
|
|
871
|
-
}, fallback)), badge && React.cloneElement(badge, {
|
|
170
|
+
}) : fallback)), badge && React.cloneElement(badge, {
|
|
872
171
|
className: classnames("".concat(CLASSNAME, "__badge"), badge.props.className)
|
|
873
172
|
}));
|
|
874
173
|
});
|