@lumx/react 2.1.9-alpha-thumbnail → 2.1.9

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.
Files changed (61) hide show
  1. package/esm/_internal/Avatar2.js +1 -5
  2. package/esm/_internal/Avatar2.js.map +1 -1
  3. package/esm/_internal/DragHandle.js +1 -1
  4. package/esm/_internal/DragHandle.js.map +1 -1
  5. package/esm/_internal/Flag2.js +1 -3
  6. package/esm/_internal/Flag2.js.map +1 -1
  7. package/esm/_internal/Icon2.js +9 -1
  8. package/esm/_internal/Icon2.js.map +1 -1
  9. package/esm/_internal/List2.js.map +1 -1
  10. package/esm/_internal/Message2.js +2 -2
  11. package/esm/_internal/Message2.js.map +1 -1
  12. package/esm/_internal/Slider2.js +2 -21
  13. package/esm/_internal/Slider2.js.map +1 -1
  14. package/esm/_internal/Thumbnail2.js +787 -81
  15. package/esm/_internal/Thumbnail2.js.map +1 -1
  16. package/esm/_internal/UserBlock.js +14 -45
  17. package/esm/_internal/UserBlock.js.map +1 -1
  18. package/esm/_internal/avatar.js +3 -0
  19. package/esm/_internal/avatar.js.map +1 -1
  20. package/esm/_internal/clamp.js +22 -0
  21. package/esm/_internal/clamp.js.map +1 -0
  22. package/esm/_internal/comment-block.js +3 -0
  23. package/esm/_internal/comment-block.js.map +1 -1
  24. package/esm/_internal/image-block.js +3 -0
  25. package/esm/_internal/image-block.js.map +1 -1
  26. package/esm/_internal/link-preview.js +3 -0
  27. package/esm/_internal/link-preview.js.map +1 -1
  28. package/esm/_internal/mdi.js +2 -2
  29. package/esm/_internal/mdi.js.map +1 -1
  30. package/esm/_internal/mosaic.js +3 -0
  31. package/esm/_internal/mosaic.js.map +1 -1
  32. package/esm/_internal/post-block.js +3 -0
  33. package/esm/_internal/post-block.js.map +1 -1
  34. package/esm/_internal/slider.js +2 -1
  35. package/esm/_internal/slider.js.map +1 -1
  36. package/esm/_internal/thumbnail.js +3 -0
  37. package/esm/_internal/thumbnail.js.map +1 -1
  38. package/esm/_internal/user-block.js +2 -1
  39. package/esm/_internal/user-block.js.map +1 -1
  40. package/esm/index.js +3 -2
  41. package/esm/index.js.map +1 -1
  42. package/package.json +4 -4
  43. package/src/components/avatar/Avatar.tsx +0 -8
  44. package/src/components/drag-handle/DragHandle.tsx +5 -1
  45. package/src/components/flag/Flag.test.tsx +1 -2
  46. package/src/components/flag/Flag.tsx +2 -10
  47. package/src/components/flag/__snapshots__/Flag.test.tsx.snap +0 -15
  48. package/src/components/icon/Icon.tsx +10 -1
  49. package/src/components/message/Message.tsx +2 -2
  50. package/src/components/thumbnail/Thumbnail.stories.tsx +42 -347
  51. package/src/components/thumbnail/Thumbnail.test.tsx +2 -20
  52. package/src/components/thumbnail/Thumbnail.tsx +45 -73
  53. package/src/components/thumbnail/__snapshots__/Thumbnail.test.tsx.snap +6 -53
  54. package/src/components/thumbnail/useFocusPoint.ts +10 -18
  55. package/src/components/thumbnail/useImageLoad.ts +22 -23
  56. package/src/components/user-block/UserBlock.stories.tsx +4 -30
  57. package/src/components/user-block/UserBlock.tsx +16 -41
  58. package/src/components/user-block/__snapshots__/UserBlock.test.tsx.snap +145 -244
  59. package/src/hooks/useOnResize.ts +0 -6
  60. package/src/stories/knobs/image.ts +3 -35
  61. package/types.d.ts +0 -14
@@ -1,57 +1,775 @@
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';
1
+ import { d as _slicedToArray, e as _toConsumableArray, _ as _objectSpread2, b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
2
+ import { AspectRatio, Size, Theme } from './components.js';
3
+ import React, { useRef, useEffect, useState, useMemo, useLayoutEffect, useCallback, forwardRef } from 'react';
4
4
  import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
5
- import { r as mdiImageBroken } from './mdi.js';
5
+ import { r as mdiImageBrokenVariant } from './mdi.js';
6
+ import { W as WINDOW } from './constants.js';
6
7
  import { m as mergeRefs } from './mergeRefs.js';
7
8
  import { I as Icon } from './Icon2.js';
9
+ import { c as clamp } from './clamp.js';
10
+ import { isEqual } from 'lodash';
8
11
 
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.
12
+ /**
13
+ * Check if browser is IE
14
+ * @return Browser is IE or not
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
+ }
541
+
542
+ var _entry$contentRect = entry.contentRect,
543
+ width = _entry$contentRect.width,
544
+ height = _entry$contentRect.height;
545
+
546
+ if (((_previousSize$current = previousSize.current) === null || _previousSize$current === void 0 ? void 0 : _previousSize$current.width) === width && ((_previousSize$current2 = previousSize.current) === null || _previousSize$current2 === void 0 ? void 0 : _previousSize$current2.height) === height) {
547
+ return;
548
+ }
14
549
 
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;
15
579
 
16
- if (!img || !img.complete) {
17
- return 'isLoading';
18
- } // Else loaded.
580
+ var _ref = imageElement || {
581
+ naturalWidth: 0,
582
+ naturalHeight: 0
583
+ },
584
+ imgWidth = _ref.naturalWidth,
585
+ imgHeight = _ref.naturalHeight;
19
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;
20
593
 
21
- return 'isLoaded';
594
+ return {
595
+ imgWidth: imgWidth,
596
+ imgHeight: imgHeight,
597
+ containerWidth: containerWidth,
598
+ containerHeight: containerHeight,
599
+ aspectRatio: aspectRatio
600
+ };
22
601
  }
23
602
 
24
- function useImageLoad(imageURL, imgRef) {
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
+
628
+ var containerRemainder = containerSize - containerCenter;
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;
639
+ }
640
+
641
+ function calculateImageStyle(sizes, point) {
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) {
25
717
  var _imgRef$current;
26
718
 
27
- var _useState = useState(getState(imgRef === null || imgRef === void 0 ? void 0 : imgRef.current)),
719
+ var _useState = useState('isLoading'),
28
720
  _useState2 = _slicedToArray(_useState, 2),
29
721
  state = _useState2[0],
30
- setState = _useState2[1]; // Update state when changing image URL or DOM reference.
722
+ setState = _useState2[1];
31
723
 
724
+ var update = useCallback(function (event) {
725
+ var img = imgRef === null || imgRef === void 0 ? void 0 : imgRef.current;
32
726
 
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
727
+ if (!img || !img.complete) {
728
+ setState('isLoading');
729
+ return;
730
+ }
731
+
732
+ if ((event === null || event === void 0 ? void 0 : event.type) === 'error' || img.complete && (img === null || img === void 0 ? void 0 : img.naturalWidth) === 0) {
733
+ setState('hasError');
734
+ return;
735
+ }
36
736
 
737
+ setState('isLoaded');
738
+ }, [imgRef]);
37
739
  useEffect(function () {
38
740
  var img = imgRef === null || imgRef === void 0 ? void 0 : imgRef.current;
39
741
  if (!img) return undefined;
40
-
41
- var update = function update(event) {
42
- return setState(getState(img, event));
43
- };
44
-
742
+ update();
45
743
  img.addEventListener('load', update);
46
744
  img.addEventListener('error', update);
47
745
  return function () {
48
746
  img.removeEventListener('load', update);
49
747
  img.removeEventListener('error', update);
50
748
  };
51
- }, [imgRef, imgRef === null || imgRef === void 0 ? void 0 : (_imgRef$current = imgRef.current) === null || _imgRef$current === void 0 ? void 0 : _imgRef$current.src]);
749
+ }, [update, imgRef, imgRef === null || imgRef === void 0 ? void 0 : (_imgRef$current = imgRef.current) === null || _imgRef$current === void 0 ? void 0 : _imgRef$current.src]);
52
750
  return state;
53
751
  }
54
752
 
753
+ var useClickable = function useClickable(_ref) {
754
+ var onClick = _ref.onClick,
755
+ _onKeyPress = _ref.onKeyPress;
756
+ return useMemo(function () {
757
+ if (!onClick) return undefined;
758
+ return {
759
+ role: 'button',
760
+ tabIndex: 0,
761
+ onClick: onClick,
762
+ onKeyPress: function onKeyPress(event) {
763
+ _onKeyPress === null || _onKeyPress === void 0 ? void 0 : _onKeyPress(event);
764
+
765
+ if (event.key === 'Enter' || event.key === ' ') {
766
+ onClick === null || onClick === void 0 ? void 0 : onClick();
767
+ }
768
+ }
769
+ };
770
+ }, [onClick, _onKeyPress]);
771
+ };
772
+
55
773
  /**
56
774
  * Component display name.
57
775
  */
@@ -66,17 +784,10 @@ var CLASSNAME = getRootClassName(COMPONENT_NAME);
66
784
  */
67
785
 
68
786
  var DEFAULT_PROPS = {
69
- fallback: mdiImageBroken,
787
+ fallback: mdiImageBrokenVariant,
70
788
  loading: 'lazy',
71
789
  theme: Theme.light
72
790
  };
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
- }
80
791
  /**
81
792
  * Thumbnail component.
82
793
  *
@@ -85,12 +796,12 @@ function getObjectPosition(aspectRatio, focusPoint) {
85
796
  * @return React element.
86
797
  */
87
798
 
88
-
89
799
  var Thumbnail = forwardRef(function (props, ref) {
800
+ var _wrapper$getBoundingC;
801
+
90
802
  var align = props.align,
91
803
  alt = props.alt,
92
- _props$aspectRatio = props.aspectRatio,
93
- aspectRatio = _props$aspectRatio === void 0 ? AspectRatio.original : _props$aspectRatio,
804
+ aspectRatio = props.aspectRatio,
94
805
  badge = props.badge,
95
806
  className = props.className,
96
807
  crossOrigin = props.crossOrigin,
@@ -100,74 +811,69 @@ var Thumbnail = forwardRef(function (props, ref) {
100
811
  image = props.image,
101
812
  imgProps = props.imgProps,
102
813
  propImgRef = props.imgRef,
103
- isLoadingProp = props.isLoading,
104
814
  loading = props.loading,
105
815
  size = props.size,
106
816
  theme = props.theme,
107
817
  variant = props.variant,
108
- linkProps = props.linkProps,
109
- linkAs = props.linkAs,
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"]);
818
+ forwardedProps = _objectWithoutProperties(props, ["align", "alt", "aspectRatio", "badge", "className", "crossOrigin", "fallback", "fillHeight", "focusPoint", "image", "imgProps", "imgRef", "loading", "size", "theme", "variant"]);
113
819
 
114
820
  var imgRef = useRef(null); // Image loading state.
115
821
 
116
- var loadingState = useImageLoad(image, imgRef);
117
- var isLoading = isLoadingProp || loadingState === 'isLoading';
822
+ var loadingState = useImageLoad(imgRef);
118
823
  var hasError = loadingState === 'hasError';
119
- var isLink = Boolean((linkProps === null || linkProps === void 0 ? void 0 : linkProps.href) || linkAs);
120
- var isButton = !!forwardedProps.onClick;
121
- var isClickable = isButton || isLink;
122
- var Wrapper = 'div';
123
-
124
- var wrapperProps = _objectSpread2({}, forwardedProps);
125
-
126
- if (isLink) {
127
- Wrapper = linkAs || 'a';
128
- Object.assign(wrapperProps, linkProps);
129
- } else if (isButton) {
130
- Wrapper = 'button';
131
- }
824
+ var isLoading = loadingState === 'isLoading';
825
+
826
+ var _useState = useState(),
827
+ _useState2 = _slicedToArray(_useState, 2),
828
+ wrapper = _useState2[0],
829
+ setWrapper = _useState2[1];
132
830
 
133
- return React.createElement(Wrapper, _extends({}, wrapperProps, {
134
- ref: ref,
135
- className: classnames(linkProps === null || linkProps === void 0 ? void 0 : linkProps.className, className, handleBasicClasses({
831
+ var wrapperProps = _objectSpread2({}, forwardedProps, {
832
+ ref: mergeRefs(setWrapper, ref),
833
+ className: classnames(className, handleBasicClasses({
136
834
  align: align,
137
835
  aspectRatio: aspectRatio,
138
836
  prefix: CLASSNAME,
139
837
  size: size,
140
838
  theme: theme,
141
839
  variant: variant,
142
- isClickable: isClickable,
143
- hasError: hasError,
144
- isLoading: showSkeletonLoading && isLoading,
145
840
  hasBadge: !!badge
146
- }), fillHeight && "".concat(CLASSNAME, "--fill-height"))
147
- }), React.createElement("div", {
148
- className: "".concat(CLASSNAME, "__background")
149
- }, React.createElement("img", _extends({}, imgProps, {
150
- style: _objectSpread2({}, imgProps === null || imgProps === void 0 ? void 0 : imgProps.style, {
151
- //
152
- //display: hasError && (!imgProps?.width || !imgProps?.height) ? 'none' : undefined,
841
+ }), isLoading && (wrapper === null || wrapper === void 0 ? void 0 : (_wrapper$getBoundingC = wrapper.getBoundingClientRect()) === null || _wrapper$getBoundingC === void 0 ? void 0 : _wrapper$getBoundingC.height) && 'lumx-color-background-dark-L6', fillHeight && "".concat(CLASSNAME, "--fill-height"))
842
+ }, useClickable(props)); // Update img style according to focus point and aspect ratio.
843
+
844
+
845
+ var style = useFocusPoint({
846
+ image: image,
847
+ focusPoint: focusPoint,
848
+ aspectRatio: aspectRatio,
849
+ imgRef: imgRef,
850
+ loadingState: loadingState,
851
+ wrapper: wrapper
852
+ });
853
+ return React.createElement("div", wrapperProps, React.createElement("div", {
854
+ className: "".concat(CLASSNAME, "__background"),
855
+ style: _objectSpread2({}, style === null || style === void 0 ? void 0 : style.wrapper, {
856
+ // Remove from layout if image not loaded correctly (use fallback)
857
+ display: hasError ? 'none' : undefined,
153
858
  // Hide while loading.
154
- visibility: hasError || hasError && isLoading ? 'hidden' : undefined,
155
- // Focus point.
156
- objectPosition: getObjectPosition(aspectRatio, focusPoint)
157
- }),
859
+ visibility: isLoading ? 'hidden' : undefined
860
+ })
861
+ }, React.createElement("img", _extends({}, imgProps, {
862
+ style: _objectSpread2({}, imgProps === null || imgProps === void 0 ? void 0 : imgProps.style, {}, style === null || style === void 0 ? void 0 : style.image),
158
863
  ref: mergeRefs(imgRef, propImgRef),
159
- className: classnames("".concat(CLASSNAME, "__image"), isLoading && "".concat(CLASSNAME, "__image--is-loading")),
160
- crossOrigin: crossOrigin,
864
+ className: (style === null || style === void 0 ? void 0 : style.image) ? "".concat(CLASSNAME, "__focused-image") : "".concat(CLASSNAME, "__image"),
865
+ crossOrigin: crossOrigin && !isInternetExplorer() ? crossOrigin : undefined,
161
866
  src: image,
162
867
  alt: alt,
163
868
  loading: loading
164
- })), !isLoading && hasError && React.createElement("div", {
165
- className: "".concat(CLASSNAME, "__fallback")
166
- }, typeof fallback === 'string' ? React.createElement(Icon, {
869
+ }))), hasError && (typeof fallback === 'string' ? React.createElement(Icon, {
870
+ className: "".concat(CLASSNAME, "__fallback"),
167
871
  icon: fallback,
168
- size: Size.xxs,
872
+ size: size || Size.m,
169
873
  theme: theme
170
- }) : fallback)), badge && React.cloneElement(badge, {
874
+ }) : React.createElement("div", {
875
+ className: "".concat(CLASSNAME, "__fallback")
876
+ }, fallback)), badge && React.cloneElement(badge, {
171
877
  className: classnames("".concat(CLASSNAME, "__badge"), badge.props.className)
172
878
  }));
173
879
  });