@telefonica/mistica 12.5.0 → 12.7.0

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 (79) hide show
  1. package/dist/carousel.js +5 -3
  2. package/dist/dialog.d.ts +20 -5
  3. package/dist/dialog.js +39 -14
  4. package/dist/dialog.js.flow +24 -7
  5. package/dist/fixed-footer-layout.js +31 -9
  6. package/dist/generated/mistica-icons/icon-buy-data-light.js +5 -11
  7. package/dist/generated/mistica-icons/icon-buy-data-regular.js +1 -1
  8. package/dist/generated/mistica-icons/icon-eco-light.js +1 -1
  9. package/dist/generated/mistica-icons/icon-justice-regular.js +1 -1
  10. package/dist/generated/mistica-icons/icon-tokens-filled.d.ts +4 -0
  11. package/dist/generated/mistica-icons/icon-tokens-filled.js +109 -0
  12. package/dist/generated/mistica-icons/icon-tokens-filled.js.flow +6 -0
  13. package/dist/generated/mistica-icons/icon-tokens-light.d.ts +4 -0
  14. package/dist/generated/mistica-icons/icon-tokens-light.js +109 -0
  15. package/dist/generated/mistica-icons/icon-tokens-light.js.flow +6 -0
  16. package/dist/generated/mistica-icons/icon-tokens-regular.d.ts +4 -0
  17. package/dist/generated/mistica-icons/icon-tokens-regular.js +109 -0
  18. package/dist/generated/mistica-icons/icon-tokens-regular.js.flow +6 -0
  19. package/dist/hooks.d.ts +3 -0
  20. package/dist/hooks.js +16 -3
  21. package/dist/hooks.js.flow +3 -0
  22. package/dist/image.d.ts +2 -0
  23. package/dist/image.js +118 -80
  24. package/dist/image.js.flow +2 -0
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.js +28 -0
  27. package/dist/index.js.flow +4 -0
  28. package/dist/navigation-bar.js +7 -9
  29. package/dist/package-version.js +1 -1
  30. package/dist/skeletons.d.ts +5 -2
  31. package/dist/skeletons.js +50 -87
  32. package/dist/skeletons.js.flow +4 -4
  33. package/dist/skins/o2.js +1 -1
  34. package/dist/text-field-base.d.ts +0 -1
  35. package/dist/text-field-base.js +23 -5
  36. package/dist/text-field-base.js.flow +0 -1
  37. package/dist/text-field-components.d.ts +1 -0
  38. package/dist/text-field-components.js +7 -3
  39. package/dist/text-field-components.js.flow +1 -0
  40. package/dist/text-link.js +2 -1
  41. package/dist/theme.d.ts +2 -0
  42. package/dist/theme.js +2 -1
  43. package/dist/theme.js.flow +2 -0
  44. package/dist/tooltip.d.ts +2 -0
  45. package/dist/tooltip.js +234 -78
  46. package/dist/tooltip.js.flow +2 -0
  47. package/dist/touchable.d.ts +1 -0
  48. package/dist/touchable.js +6 -1
  49. package/dist/touchable.js.flow +1 -0
  50. package/dist/utils/aspect-ratio-support.d.ts +10 -0
  51. package/dist/utils/aspect-ratio-support.js +115 -1
  52. package/dist/utils/aspect-ratio-support.js.flow +14 -0
  53. package/dist/video.js +20 -79
  54. package/dist-es/carousel.js +5 -3
  55. package/dist-es/dialog.js +40 -15
  56. package/dist-es/fixed-footer-layout.js +32 -10
  57. package/dist-es/generated/mistica-icons/icon-buy-data-light.js +6 -12
  58. package/dist-es/generated/mistica-icons/icon-buy-data-regular.js +1 -1
  59. package/dist-es/generated/mistica-icons/icon-eco-light.js +1 -1
  60. package/dist-es/generated/mistica-icons/icon-justice-regular.js +1 -1
  61. package/dist-es/generated/mistica-icons/icon-tokens-filled.js +85 -0
  62. package/dist-es/generated/mistica-icons/icon-tokens-light.js +85 -0
  63. package/dist-es/generated/mistica-icons/icon-tokens-regular.js +85 -0
  64. package/dist-es/hooks.js +14 -2
  65. package/dist-es/image.js +115 -83
  66. package/dist-es/index.js +4 -0
  67. package/dist-es/navigation-bar.js +7 -9
  68. package/dist-es/package-version.js +1 -1
  69. package/dist-es/skeletons.js +50 -87
  70. package/dist-es/skins/o2.js +1 -1
  71. package/dist-es/text-field-base.js +25 -7
  72. package/dist-es/text-field-components.js +7 -3
  73. package/dist-es/text-link.js +3 -1
  74. package/dist-es/theme.js +2 -1
  75. package/dist-es/tooltip.js +234 -78
  76. package/dist-es/touchable.js +6 -1
  77. package/dist-es/utils/aspect-ratio-support.js +112 -0
  78. package/dist-es/video.js +21 -81
  79. package/package.json +2 -1
@@ -102,19 +102,27 @@ function _unsupportedIterableToArray(o, minLen) {
102
102
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
103
103
  import * as React from "react";
104
104
  import classnames from "classnames";
105
+ import { CSSTransition } from "react-transition-group";
105
106
  import { useAriaId, useScreenSize } from "./hooks";
106
107
  import { Portal } from "./portal";
107
108
  import Overlay from "./overlay";
109
+ import { Text2 } from "./text";
108
110
  import * as key from "./utils/key-codes";
109
111
  import { createUseStyles } from "./jss";
112
+ import Stack from "./stack";
110
113
  var defaultPositionDesktop = "bottom";
111
114
  var defaultPositionMobile = "top";
112
115
  var arrowSize = 12;
113
- var distanceToTarget = 8 + arrowSize;
116
+ var distanceToTarget = 4 + arrowSize;
114
117
  var marginLeftRightMobile = 16;
115
118
  var defaultWidthDesktop = 340;
116
119
  var arrowWrapperWidth = arrowSize * 2;
117
120
  var arrowWrapperHeight = arrowSize;
121
+ var transitionDurationMs = 500;
122
+ var animationMovement = 12;
123
+ var animationTiming = "cubic-bezier(0.215, 0.61, 0.355, 1)";
124
+ var defaultShowTooltipDelayMs = 500;
125
+ var noOp = function() {};
118
126
  var useStyles = createUseStyles(function(theme) {
119
127
  var shadowAlpha = theme.isDarkMode ? 1 : 0.2;
120
128
  return {
@@ -126,7 +134,7 @@ var useStyles = createUseStyles(function(theme) {
126
134
  top: 0,
127
135
  left: "50%",
128
136
  transform: "translate(-50%, -50%) rotate(45deg)",
129
- border: "1px solid ".concat(theme.colors.divider),
137
+ border: "1px solid ".concat(theme.colors.border),
130
138
  borderRadius: 2
131
139
  },
132
140
  arrowTop: {
@@ -175,42 +183,142 @@ var useStyles = createUseStyles(function(theme) {
175
183
  left: 16,
176
184
  width: "auto",
177
185
  boxShadow: "0 2px 4px 0 rgba(0, 0, 0, ".concat(shadowAlpha, ")"),
178
- padding: 16,
186
+ padding: 8,
179
187
  backgroundColor: theme.colors.backgroundContainer,
180
- zIndex: 12,
181
- border: "1px solid ".concat(theme.colors.divider),
188
+ zIndex: 50,
189
+ border: "1px solid ".concat(theme.colors.border),
182
190
  borderRadius: 8
191
+ }
192
+ };
193
+ });
194
+ var useAnimationStyles = createUseStyles(function() {
195
+ return {
196
+ enter: {
197
+ transform: function(param) {
198
+ var position = param.position;
199
+ if (position === "bottom") {
200
+ return "translateY(".concat(animationMovement, "px)");
201
+ }
202
+ if (position === "top") {
203
+ return "translateY(calc(-100% - ".concat(animationMovement, "px))");
204
+ }
205
+ if (position === "right") {
206
+ return "translateX(".concat(animationMovement, "px) translateY(-50%)");
207
+ }
208
+ if (position === "left") {
209
+ return "translateX(-".concat(animationMovement, "px) translateY(-50%)");
210
+ }
211
+ return "translateY(-".concat(animationMovement, "px)");
212
+ }
213
+ },
214
+ enterActive: {
215
+ animationName: function(param) {
216
+ var position = param.position;
217
+ if (position === "top") return "$fadeInTop";
218
+ if (position === "bottom") return "$fadeInBottom";
219
+ return "$fadeInX";
220
+ },
221
+ animationFillMode: "both",
222
+ animationDuration: "".concat(transitionDurationMs, "ms"),
223
+ animationTimingFunction: animationTiming
224
+ },
225
+ enterDone: {
226
+ transform: function(param) {
227
+ var position = param.position;
228
+ if (position === "top") return "translateY(-100%)";
229
+ if (position === "bottom") return "translateY(0)";
230
+ return "translateY(-50%)";
231
+ }
232
+ },
233
+ exit: {
234
+ transform: function(param) {
235
+ var position = param.position;
236
+ if (position === "bottom") {
237
+ return "translateY(0)";
238
+ }
239
+ if (position === "top") {
240
+ return "translateY(-100%)";
241
+ }
242
+ if (position === "right") {
243
+ return "translateX(0px) translateY(-50%)";
244
+ }
245
+ if (position === "left") {
246
+ return "translateX(0px) translateY(-50%)";
247
+ }
248
+ return "translateY(0px)";
249
+ },
250
+ opacity: 1,
251
+ transition: "opacity 0.3s ".concat(animationTiming)
252
+ },
253
+ exitActive: {
254
+ animation: "$fadeOut 0.3s ".concat(animationTiming, " both")
255
+ },
256
+ "@keyframes fadeInBottom": {
257
+ from: {
258
+ opacity: 0
259
+ },
260
+ "40%": {
261
+ opacity: 1
262
+ },
263
+ to: {
264
+ opacity: 1,
265
+ transform: "translateY(0)"
266
+ }
183
267
  },
184
- title: {
185
- margin: 0,
186
- marginBottom: 12,
187
- color: theme.colors.textPrimary,
188
- lineHeight: 1.42857142,
189
- fontSize: 14
268
+ "@keyframes fadeInTop": {
269
+ from: {
270
+ opacity: 0
271
+ },
272
+ "40%": {
273
+ opacity: 1
274
+ },
275
+ to: {
276
+ opacity: 1,
277
+ transform: "translateY(-100%)"
278
+ }
190
279
  },
191
- description: {
192
- margin: 0,
193
- color: theme.colors.textPrimary,
194
- lineHeight: 1.42857142,
195
- fontSize: 14
280
+ "@keyframes fadeInX": {
281
+ from: {
282
+ opacity: 0
283
+ },
284
+ "40%": {
285
+ opacity: 1
286
+ },
287
+ to: {
288
+ opacity: 1,
289
+ transform: "translateX(0) translateY(-50%)"
290
+ }
291
+ },
292
+ "@keyframes fadeOut": {
293
+ from: {
294
+ opacity: 1
295
+ },
296
+ to: {
297
+ opacity: 0
298
+ }
196
299
  }
197
300
  };
198
301
  });
199
302
  var getWidthDesktop = function(customWidth) {
200
303
  return customWidth ? customWidth : defaultWidthDesktop;
201
304
  };
202
- var EVENT_THROTTLE_TIME = process.env.NODE_ENV === "test" ? 0 : 200;
203
305
  var Tooltip = function(_param) {
204
- var children = _param.children, description = _param.description, target = _param.target, title = _param.title, targetLabel = _param.targetLabel, rest = _objectWithoutProperties(_param, [
306
+ var children = _param.children, extra = _param.extra, description = _param.description, target = _param.target, title = _param.title, targetLabel = _param.targetLabel, _delay = _param.delay, delay = _delay === void 0 ? true : _delay, rest = _objectWithoutProperties(_param, [
205
307
  "children",
308
+ "extra",
206
309
  "description",
207
310
  "target",
208
311
  "title",
209
- "targetLabel"
312
+ "targetLabel",
313
+ "delay"
210
314
  ]);
211
315
  var ref = _slicedToArray(React.useState(false), 2), isVisible = ref[0], setIsVisible = ref[1];
212
316
  var isTabletOrSmaller = useScreenSize().isTabletOrSmaller;
213
317
  var ariaId = useAriaId();
318
+ var isPointerOver = React.useRef(false);
319
+ var closeTooltipTimeoutId = React.useRef(null);
320
+ var showTooltipTimeoutId = React.useRef(null);
321
+ var targetRef = React.useRef(null);
214
322
  var targetBoundingClientRect = React.useRef({
215
323
  top: 0,
216
324
  right: 0,
@@ -219,10 +327,16 @@ var Tooltip = function(_param) {
219
327
  width: 0,
220
328
  height: 0
221
329
  });
222
- // This property is needed because safari is making a mess with the events (it has problems
223
- // when the overlay layer appears and disappears). This way we ensure that events don't get handled twice
224
- var lastChangeTime = React.useRef(0);
330
+ var getPosition = function() {
331
+ var position = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultPositionDesktop;
332
+ return isTabletOrSmaller && (position === "left" || position === "right") ? defaultPositionMobile : position;
333
+ };
334
+ var position1 = getPosition(rest.position);
225
335
  var classes = useStyles();
336
+ var animationClasses = useAnimationStyles({
337
+ position: position1
338
+ });
339
+ var isTouchableDevice = typeof window !== "undefined" ? window.matchMedia("(pointer: coarse)").matches : false;
226
340
  var closeTooltip = function() {
227
341
  if (isVisible) {
228
342
  setIsVisible(false);
@@ -235,23 +349,16 @@ var Tooltip = function(_param) {
235
349
  };
236
350
  });
237
351
  var handleClickOutside = function() {
238
- if (Date.now() - lastChangeTime.current < EVENT_THROTTLE_TIME) {
239
- return;
240
- }
241
- lastChangeTime.current = Date.now();
242
352
  setIsVisible(false);
243
353
  };
244
- var toggleVisibility = function(e) {
245
- if (Date.now() - lastChangeTime.current < EVENT_THROTTLE_TIME) {
246
- return;
247
- }
248
- lastChangeTime.current = Date.now();
249
- targetBoundingClientRect.current = e.currentTarget.getBoundingClientRect();
354
+ var toggleVisibility = function() {
355
+ if (!targetRef.current) return;
356
+ targetBoundingClientRect.current = targetRef.current.getBoundingClientRect();
250
357
  setIsVisible(!isVisible);
251
358
  };
252
- var handleFocus = function(e) {
359
+ var handleFocus = function() {
253
360
  if (!isVisible) {
254
- toggleVisibility(e);
361
+ toggleVisibility();
255
362
  }
256
363
  };
257
364
  var handleKeyDown = function(event) {
@@ -260,22 +367,19 @@ var Tooltip = function(_param) {
260
367
  }
261
368
  };
262
369
  var getContainerPosition = function(position, width) {
370
+ if (typeof window === "undefined") {
371
+ return {};
372
+ }
263
373
  var containerPos = {
264
374
  right: {
265
375
  left: targetBoundingClientRect.current.right + distanceToTarget,
266
- top: window.pageYOffset + targetBoundingClientRect.current.top + targetBoundingClientRect.current.height / 2,
267
- transform: "translateY(-50%)",
268
- WebKitTransform: "translateY(-50%)"
376
+ top: window.pageYOffset + targetBoundingClientRect.current.top + targetBoundingClientRect.current.height / 2
269
377
  },
270
378
  left: {
271
379
  left: targetBoundingClientRect.current.left - width - distanceToTarget,
272
- top: window.pageYOffset + targetBoundingClientRect.current.top + targetBoundingClientRect.current.height / 2,
273
- transform: "translateY(-50%)",
274
- WebKitTransform: "translateY(-50%)"
380
+ top: window.pageYOffset + targetBoundingClientRect.current.top + targetBoundingClientRect.current.height / 2
275
381
  },
276
382
  top: {
277
- transform: "translateY(-100%)",
278
- WebKitTransform: "translateY(-100%)",
279
383
  top: window.pageYOffset + targetBoundingClientRect.current.top - distanceToTarget,
280
384
  left: isTabletOrSmaller ? marginLeftRightMobile : window.pageXOffset + targetBoundingClientRect.current.left + targetBoundingClientRect.current.width / 2 - width / 2
281
385
  },
@@ -286,10 +390,6 @@ var Tooltip = function(_param) {
286
390
  };
287
391
  return containerPos[position];
288
392
  };
289
- var getPosition = function() {
290
- var position = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultPositionDesktop;
291
- return isTabletOrSmaller && (position === "left" || position === "right") ? defaultPositionMobile : position;
292
- };
293
393
  var getCustomStylesForMobile = function() {
294
394
  return isTabletOrSmaller ? {
295
395
  left: targetBoundingClientRect.current.left + targetBoundingClientRect.current.width / 2 - marginLeftRightMobile
@@ -298,7 +398,6 @@ var Tooltip = function(_param) {
298
398
  var getWidth = function() {
299
399
  return isTabletOrSmaller ? window.innerWidth - marginLeftRightMobile * 2 : getWidthDesktop(rest.width);
300
400
  };
301
- var position1 = getPosition(rest.position);
302
401
  var width1 = getWidth();
303
402
  var classNameByPosition = {
304
403
  top: classes.arrowTop,
@@ -309,8 +408,38 @@ var Tooltip = function(_param) {
309
408
  return /*#__PURE__*/ _jsxs(_Fragment, {
310
409
  children: [
311
410
  /*#__PURE__*/ _jsx("div", {
411
+ ref: targetRef,
312
412
  className: classes.wrapper,
313
- onPointerDown: toggleVisibility,
413
+ onPointerOver: function() {
414
+ if (closeTooltipTimeoutId.current) {
415
+ clearTimeout(closeTooltipTimeoutId.current);
416
+ closeTooltipTimeoutId.current = null;
417
+ }
418
+ if (isPointerOver.current) return;
419
+ isPointerOver.current = true;
420
+ if (delay) {
421
+ showTooltipTimeoutId.current = setTimeout(function() {
422
+ showTooltipTimeoutId.current = null;
423
+ toggleVisibility();
424
+ }, defaultShowTooltipDelayMs);
425
+ } else {
426
+ toggleVisibility();
427
+ }
428
+ },
429
+ onPointerLeave: isTouchableDevice ? noOp : function() {
430
+ if (showTooltipTimeoutId.current) {
431
+ clearTimeout(showTooltipTimeoutId.current);
432
+ showTooltipTimeoutId.current = null;
433
+ isPointerOver.current = false;
434
+ return;
435
+ }
436
+ closeTooltipTimeoutId.current = setTimeout(function() {
437
+ if (!isPointerOver.current) return;
438
+ closeTooltipTimeoutId.current = null;
439
+ isPointerOver.current = false;
440
+ toggleVisibility();
441
+ }, 100);
442
+ },
314
443
  onFocus: handleFocus,
315
444
  onKeyDown: handleKeyDown,
316
445
  "touch-action": "auto" // Prop needed for Pointer Events Polyfill to work properly
@@ -322,40 +451,67 @@ var Tooltip = function(_param) {
322
451
  "aria-label": targetLabel,
323
452
  children: target
324
453
  }),
325
- isVisible && /*#__PURE__*/ _jsxs(Portal, {
454
+ /*#__PURE__*/ _jsxs(Portal, {
326
455
  children: [
327
- /*#__PURE__*/ _jsx(Overlay, {
456
+ isVisible && isTouchableDevice && /*#__PURE__*/ _jsx(Overlay, {
328
457
  onPress: handleClickOutside
329
458
  }),
330
- /*#__PURE__*/ _jsxs("div", {
331
- role: "tooltip",
332
- id: ariaId,
333
- className: classes.container,
334
- style: _objectSpread({
335
- width: width1
336
- }, getContainerPosition(position1, width1)),
337
- children: [
338
- /*#__PURE__*/ _jsx("div", {
339
- className: classnames(classes.arrowWrapper, classNameByPosition[position1]),
340
- style: getCustomStylesForMobile(),
341
- children: /*#__PURE__*/ _jsx("div", {
342
- className: classes.arrow
343
- })
344
- }),
345
- (title || description) && /*#__PURE__*/ _jsxs(_Fragment, {
346
- children: [
347
- title && /*#__PURE__*/ _jsx("p", {
348
- className: classes.title,
349
- children: title
350
- }),
351
- description && /*#__PURE__*/ _jsx("p", {
352
- className: classes.description,
353
- children: description
459
+ /*#__PURE__*/ _jsx(CSSTransition, {
460
+ in: isVisible,
461
+ timeout: transitionDurationMs,
462
+ classNames: {
463
+ enter: animationClasses.enter,
464
+ enterActive: animationClasses.enterActive,
465
+ enterDone: animationClasses.enterDone,
466
+ exit: animationClasses.exit,
467
+ exitActive: animationClasses.exitActive
468
+ },
469
+ unmountOnExit: true,
470
+ children: /*#__PURE__*/ _jsxs("div", {
471
+ role: "tooltip",
472
+ id: ariaId,
473
+ className: classes.container,
474
+ style: _objectSpread({
475
+ width: width1
476
+ }, getContainerPosition(position1, width1)),
477
+ onPointerOver: function() {
478
+ if (closeTooltipTimeoutId.current) {
479
+ clearTimeout(closeTooltipTimeoutId.current);
480
+ closeTooltipTimeoutId.current = null;
481
+ }
482
+ },
483
+ onPointerLeave: isTouchableDevice ? noOp : function() {
484
+ closeTooltipTimeoutId.current = setTimeout(function() {
485
+ if (!isPointerOver.current) return;
486
+ closeTooltipTimeoutId.current = null;
487
+ isPointerOver.current = false;
488
+ toggleVisibility();
489
+ }, 100);
490
+ },
491
+ children: [
492
+ /*#__PURE__*/ _jsx("div", {
493
+ className: classnames(classes.arrowWrapper, classNameByPosition[position1]),
494
+ style: getCustomStylesForMobile(),
495
+ children: /*#__PURE__*/ _jsx("div", {
496
+ className: classes.arrow
354
497
  })
355
- ]
356
- }),
357
- children
358
- ]
498
+ }),
499
+ (title || description) && /*#__PURE__*/ _jsxs(Stack, {
500
+ space: 4,
501
+ children: [
502
+ title && /*#__PURE__*/ _jsx(Text2, {
503
+ medium: true,
504
+ children: title
505
+ }),
506
+ description && /*#__PURE__*/ _jsx(Text2, {
507
+ regular: true,
508
+ children: description
509
+ })
510
+ ]
511
+ }),
512
+ extra || children
513
+ ]
514
+ })
359
515
  })
360
516
  ]
361
517
  })
@@ -205,7 +205,12 @@ var Touchable = /*#__PURE__*/ React.forwardRef(function(props, ref) {
205
205
  }));
206
206
  }
207
207
  if (props.onPress) {
208
- return /*#__PURE__*/ _jsx("button", _objectSpread({}, commonProps, {
208
+ var _as;
209
+ var elementType = (_as = props.as) !== null && _as !== void 0 ? _as : "button";
210
+ var _role;
211
+ var role = (_role = commonProps.role) !== null && _role !== void 0 ? _role : props.as === "a" ? "button" : undefined;
212
+ return /*#__PURE__*/ React.createElement(elementType, _objectSpread({}, commonProps, {
213
+ role: role,
209
214
  // this "form" attribute is useful when the form's submit button
210
215
  // is located outside the <form> element, for example if you use
211
216
  // a ButtonFixedFooter layout inside a form with the submit
@@ -6,6 +6,19 @@ function _arrayLikeToArray(arr, len) {
6
6
  function _arrayWithHoles(arr) {
7
7
  if (Array.isArray(arr)) return arr;
8
8
  }
9
+ function _defineProperty(obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+ return obj;
21
+ }
9
22
  function _iterableToArrayLimit(arr, i) {
10
23
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
24
  if (_i == null) return;
@@ -33,6 +46,21 @@ function _iterableToArrayLimit(arr, i) {
33
46
  function _nonIterableRest() {
34
47
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
48
  }
49
+ function _objectSpread(target) {
50
+ for(var i = 1; i < arguments.length; i++){
51
+ var source = arguments[i] != null ? arguments[i] : {};
52
+ var ownKeys = Object.keys(source);
53
+ if (typeof Object.getOwnPropertySymbols === "function") {
54
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
55
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
56
+ }));
57
+ }
58
+ ownKeys.forEach(function(key) {
59
+ _defineProperty(target, key, source[key]);
60
+ });
61
+ }
62
+ return target;
63
+ }
36
64
  function _slicedToArray(arr, i) {
37
65
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
38
66
  }
@@ -47,6 +75,7 @@ function _unsupportedIterableToArray(o, minLen) {
47
75
  import { jsx as _jsx } from "react/jsx-runtime";
48
76
  import * as React from "react";
49
77
  import { useIsomorphicLayoutEffect } from "../hooks";
78
+ import { createUseStyles } from "../jss";
50
79
  var AspectRatioSupport = /*#__PURE__*/ React.createContext(true);
51
80
  export var AspectRatioSupportProvider = function(param) {
52
81
  var children = param.children;
@@ -70,3 +99,86 @@ export var AspectRatioSupportProvider = function(param) {
70
99
  export var useSupportsAspectRatio = function() {
71
100
  return React.useContext(AspectRatioSupport);
72
101
  };
102
+ var useAspectRatioStyles = createUseStyles(function() {
103
+ return {
104
+ container: {
105
+ "@supports (aspect-ratio: 1 / 1)": {
106
+ aspectRatio: function(param) {
107
+ var aspectRatio = param.aspectRatio;
108
+ return aspectRatio !== null && aspectRatio !== void 0 ? aspectRatio : "unset";
109
+ }
110
+ },
111
+ "$wrapper &": {
112
+ position: function(param) {
113
+ var aspectRatio = param.aspectRatio;
114
+ return aspectRatio ? "absolute" : "static";
115
+ },
116
+ width: "100%",
117
+ height: "100%",
118
+ top: 0,
119
+ left: 0
120
+ }
121
+ },
122
+ wrapper: {
123
+ overflow: "hidden",
124
+ maxWidth: "100%",
125
+ maxHeight: "100%",
126
+ position: "relative",
127
+ paddingTop: function(param) {
128
+ var aspectRatio = param.aspectRatio, width = param.width;
129
+ if (!aspectRatio) {
130
+ return 0;
131
+ }
132
+ if (width && typeof width === "string" && width.endsWith("%")) {
133
+ return "".concat(Number(width.replace("%", "")) / aspectRatio, "%");
134
+ }
135
+ return "".concat(100 / aspectRatio, "%");
136
+ }
137
+ }
138
+ };
139
+ });
140
+ export var AspectRatioElement = function(props) {
141
+ var supportsAspectRatio = useSupportsAspectRatio();
142
+ // if width or height are numeric, we can calculate the other with the ratio without css.
143
+ // if aspect ratio is 0, we use the original image proportions
144
+ var withCssAspectRatio = typeof props.width !== "number" && typeof props.height !== "number" && props.aspectRatio !== 0;
145
+ var classes = useAspectRatioStyles({
146
+ aspectRatio: withCssAspectRatio ? props.aspectRatio : undefined,
147
+ width: props.width
148
+ });
149
+ var width = props.width;
150
+ var height = props.height;
151
+ if (props.width !== undefined && props.height !== undefined) {
152
+ width = props.width;
153
+ height = props.height;
154
+ } else if (typeof props.width === "number") {
155
+ height = props.aspectRatio !== 0 ? props.width / props.aspectRatio : undefined;
156
+ } else if (typeof props.height === "number") {
157
+ width = props.aspectRatio !== 0 ? props.height * props.aspectRatio : undefined;
158
+ } else {
159
+ width = props.width || "100%";
160
+ }
161
+ var needsWrapper = withCssAspectRatio && !supportsAspectRatio;
162
+ var _as;
163
+ var container = /*#__PURE__*/ React.createElement((_as = props.as) !== null && _as !== void 0 ? _as : "div", {
164
+ className: props.className ? "".concat(props.className, " ").concat(classes.container) : classes.container,
165
+ style: _objectSpread({}, needsWrapper ? _objectSpread({}, props.style, {
166
+ width: "100%"
167
+ }) : _objectSpread({}, props.style, {
168
+ width: width,
169
+ height: height
170
+ }))
171
+ }, props.children);
172
+ if (needsWrapper) {
173
+ return /*#__PURE__*/ _jsx("div", {
174
+ style: {
175
+ width: width,
176
+ height: height
177
+ },
178
+ className: classes.wrapper,
179
+ children: container
180
+ });
181
+ } else {
182
+ return container;
183
+ }
184
+ };