@lumx/react 2.1.8-alpha.0 → 2.1.9-alpha-thumbnail3

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