@royaloperahouse/harmonic 0.12.0-e → 0.12.0-f

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.
@@ -3476,6 +3476,11 @@ var RotatorButtons = function RotatorButtons(_ref) {
3476
3476
  onClickFullscreen();
3477
3477
  }
3478
3478
  };
3479
+ var onFullscreenKeyDownHandler = function onFullscreenKeyDownHandler(e) {
3480
+ if (e.key === 'Enter') {
3481
+ onClickFullscreenHandler();
3482
+ }
3483
+ };
3479
3484
  var renderPrevIcon = function renderPrevIcon() {
3480
3485
  return /*#__PURE__*/React__default.createElement(Icon, {
3481
3486
  iconName: "CarouselArrow",
@@ -3518,6 +3523,7 @@ var RotatorButtons = function RotatorButtons(_ref) {
3518
3523
  "data-testid": "iconnextnoavailable"
3519
3524
  }, renderNextIcon())), showFullscreen && (/*#__PURE__*/React__default.createElement(FullscreenIconWrapper, {
3520
3525
  onClick: onClickFullscreenHandler,
3526
+ onKeyDown: onFullscreenKeyDownHandler,
3521
3527
  tabIndex: 0,
3522
3528
  "data-testid": "iconfullscreen",
3523
3529
  className: "carousel-icon-wrapper-fullscreen",
@@ -11362,7 +11368,7 @@ var SelectComponent$1 = function SelectComponent(_ref) {
11362
11368
  };
11363
11369
 
11364
11370
  var _templateObject$1h, _templateObject2$_;
11365
- var Wrapper$8 = /*#__PURE__*/styled__default.figure(_templateObject$1h || (_templateObject$1h = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n flex-direction: column;\n height: 100%;\n width: fit-content;\n\n ", " {\n height: calc(100% - 34px);\n @supports not (aspect-ratio: ", ") {\n width: ", ";\n }\n\n @media ", " {\n height: calc(100% - 30px);\n @supports not (aspect-ratio: ", ") {\n width: ", ";\n }\n }\n }\n"])), StyledImageAspectRatioWrapper, function (_ref) {
11371
+ var Wrapper$8 = /*#__PURE__*/styled__default.figure(_templateObject$1h || (_templateObject$1h = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: inline-flex;\n flex-direction: column;\n align-items: center;\n margin: 0;\n\n ", " {\n height: calc(100% - 34px);\n @supports not (aspect-ratio: ", ") {\n width: ", ";\n }\n\n @media ", " {\n height: calc(100% - 30px);\n @supports not (aspect-ratio: ", ") {\n width: ", ";\n }\n }\n }\n"])), StyledImageAspectRatioWrapper, function (_ref) {
11366
11372
  var _ref$aspectRatio = _ref.aspectRatio,
11367
11373
  aspectRatio = _ref$aspectRatio === void 0 ? exports.AspectRatio['1:1'] : _ref$aspectRatio;
11368
11374
  return aspectRatio;
@@ -11381,38 +11387,82 @@ var Wrapper$8 = /*#__PURE__*/styled__default.figure(_templateObject$1h || (_temp
11381
11387
  height = _ref4.height;
11382
11388
  return "calc(calc(" + height + "px - 30px) * " + AspectRatioWidth[aspectRatio] + ")";
11383
11389
  });
11384
- var CaptionWrapper = /*#__PURE__*/styled__default(Caption)(_templateObject2$_ || (_templateObject2$_ = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: 12px;\n height: 22px;\n font-feature-settings: var(--font-feature-settings-body);\n text-transform: var(--text-transform-body);\n word-break: var(--word-break-body);\n font-style: italic;\n\n @media ", " {\n height: 18px;\n }\n"])), devices.mobile);
11390
+ var CaptionWrapper = /*#__PURE__*/styled__default(Caption)(_templateObject2$_ || (_templateObject2$_ = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n && {\n margin-top: 12px;\n max-width: var(--caption-max-width, 100%);\n width: 100%;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n overflow-wrap: normal;\n }\n height: 22px;\n font-feature-settings: var(--font-feature-settings-body);\n text-transform: var(--text-transform-body);\n word-break: var(--word-break-body);\n\n @media ", " {\n height: 18px;\n }\n"])), devices.mobile);
11385
11391
 
11386
11392
  var ImageWithCaption = function ImageWithCaption(_ref) {
11387
11393
  var caption = _ref.caption,
11394
+ altText = _ref.altText,
11388
11395
  children = _ref.children,
11389
11396
  aspectRatio = _ref.aspectRatio;
11390
11397
  var wrapperRef = React.useRef(null);
11398
+ var imgRef = React.useRef(null);
11391
11399
  var _useState = React.useState(0),
11392
11400
  height = _useState[0],
11393
11401
  setHeight = _useState[1];
11402
+ var updateWrapperHeight = React__default.useCallback(function () {
11403
+ var _wrapperRef$current;
11404
+ setHeight((wrapperRef == null || (_wrapperRef$current = wrapperRef.current) == null ? void 0 : _wrapperRef$current.offsetHeight) || 0);
11405
+ }, []);
11406
+ var updateCaptionWidth = React__default.useCallback(function () {
11407
+ var img = imgRef.current;
11408
+ var wrapper = wrapperRef.current;
11409
+ if (img && wrapper) {
11410
+ var w = img.getBoundingClientRect().width;
11411
+ wrapper.style.setProperty('--caption-max-width', Math.round(w) + "px");
11412
+ }
11413
+ }, []);
11394
11414
  React.useEffect(function () {
11395
- var setWrapperHeight = function setWrapperHeight() {
11396
- var _wrapperRef$current;
11397
- return setHeight((wrapperRef == null || (_wrapperRef$current = wrapperRef.current) == null ? void 0 : _wrapperRef$current.offsetHeight) || 0);
11398
- };
11399
- setWrapperHeight(); // Initial height calculation
11400
- window.addEventListener('resize', setWrapperHeight);
11415
+ updateWrapperHeight();
11416
+ updateCaptionWidth();
11417
+ window.addEventListener('resize', updateWrapperHeight);
11418
+ window.addEventListener('resize', updateCaptionWidth);
11419
+ var imageResizeObserver = null;
11420
+ if (typeof ResizeObserver !== 'undefined' && imgRef.current) {
11421
+ imageResizeObserver = new ResizeObserver(updateCaptionWidth);
11422
+ imageResizeObserver.observe(imgRef.current);
11423
+ }
11401
11424
  return function () {
11402
- return window.removeEventListener('resize', setWrapperHeight);
11425
+ window.removeEventListener('resize', updateWrapperHeight);
11426
+ window.removeEventListener('resize', updateCaptionWidth);
11427
+ if (imageResizeObserver && imgRef.current) imageResizeObserver.unobserve(imgRef.current);
11403
11428
  };
11404
- }, []);
11429
+ }, [updateWrapperHeight, updateCaptionWidth]);
11430
+ var clonedChildren = React__default.Children.map(children, function (child) {
11431
+ if (! /*#__PURE__*/React__default.isValidElement(child)) return child;
11432
+ var childElement = child;
11433
+ var originalRef = child.ref;
11434
+ var newProps = {
11435
+ alt: altText,
11436
+ tabIndex: 0,
11437
+ onKeyDown: function onKeyDown(e) {
11438
+ if (e.key === 'Enter' || e.key === ' ') {
11439
+ var _imgRef$current;
11440
+ e.preventDefault();
11441
+ (_imgRef$current = imgRef.current) == null || _imgRef$current.click();
11442
+ }
11443
+ var originalOnKeyDownHandler = childElement.props.onKeyDown;
11444
+ if (originalOnKeyDownHandler) originalOnKeyDownHandler(e);
11445
+ },
11446
+ ref: function ref(node) {
11447
+ imgRef.current = node;
11448
+ if (node) updateCaptionWidth();
11449
+ if (!originalRef) return;
11450
+ if (typeof originalRef === 'function') {
11451
+ originalRef(node);
11452
+ } else {
11453
+ originalRef.current = node;
11454
+ }
11455
+ }
11456
+ };
11457
+ return /*#__PURE__*/React__default.cloneElement(childElement, newProps);
11458
+ });
11405
11459
  return /*#__PURE__*/React__default.createElement(Wrapper$8, {
11406
11460
  aspectRatio: aspectRatio,
11407
11461
  ref: wrapperRef,
11408
11462
  height: height
11409
11463
  }, /*#__PURE__*/React__default.createElement(ImageAspectRatioWrapper, {
11410
11464
  aspectRatio: aspectRatio
11411
- }, React__default.Children.map(children, function (child) {
11412
- return /*#__PURE__*/React__default.isValidElement(child) ? /*#__PURE__*/React__default.cloneElement(child, {
11413
- alt: child.props.alt || 'Visual representation'
11414
- }) : child;
11415
- })), caption && /*#__PURE__*/React__default.createElement(CaptionWrapper, {
11465
+ }, clonedChildren), caption && /*#__PURE__*/React__default.createElement(CaptionWrapper, {
11416
11466
  tag: "figcaption"
11417
11467
  }, caption));
11418
11468
  };