@vtex/ads-stories 0.5.0 → 0.8.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 (49) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +29 -297
  3. package/dist/cdn/vtex-ads-stories.js +438 -113
  4. package/dist/cdn/vtex-ads-stories.js.map +1 -1
  5. package/dist/cjs/index.cjs +932 -189
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/index.d.cts +42 -196
  8. package/dist/cjs/react.cjs.map +1 -1
  9. package/dist/cjs/react.d.cts +13 -3
  10. package/dist/cjs/story-Ba9J0rbL.d.cts +276 -0
  11. package/dist/esm/index.d.ts +42 -196
  12. package/dist/esm/index.js +956 -212
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/react.d.ts +13 -3
  15. package/dist/esm/story-Ba9J0rbL.d.ts +276 -0
  16. package/package.json +1 -1
  17. package/src/commerce-events.ts +93 -0
  18. package/src/components/card/card.ts +16 -3
  19. package/src/components/carousel/carousel-skeleton.ts +113 -0
  20. package/src/components/carousel/carousel.ts +53 -8
  21. package/src/components/carousel/index.ts +7 -0
  22. package/src/components/events/events-controller.ts +23 -13
  23. package/src/components/icons/assets/minus.svg +1 -0
  24. package/src/components/icons/assets/plus.svg +1 -0
  25. package/src/components/icons/assets/trash.svg +1 -0
  26. package/src/components/icons/assets/warning-circle-fill.svg +1 -0
  27. package/src/components/icons/index.ts +8 -0
  28. package/src/components/media/index.ts +7 -1
  29. package/src/components/media/media.styles.ts +113 -0
  30. package/src/components/media/media.ts +108 -11
  31. package/src/components/media/video-controller.ts +80 -6
  32. package/src/components/player/player.ts +42 -17
  33. package/src/components/product/cta.ts +3 -3
  34. package/src/components/product/index.ts +2 -0
  35. package/src/components/product/product.styles.ts +63 -6
  36. package/src/components/product/product.ts +130 -29
  37. package/src/index.ts +8 -0
  38. package/src/locales/en.ts +13 -3
  39. package/src/locales/es.ts +13 -3
  40. package/src/locales/index.ts +6 -0
  41. package/src/locales/pt.ts +13 -3
  42. package/src/locales/types.ts +22 -2
  43. package/src/react.ts +12 -2
  44. package/src/story/story.ts +218 -20
  45. package/src/utils/hydrate-products.ts +30 -6
  46. package/src/utils/media-ready.ts +58 -0
  47. package/src/utils/safe-url.ts +36 -0
  48. package/src/utils/send-event.ts +1 -1
  49. package/src/utils/http-url.ts +0 -12
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ ADD_TO_CART_EVENT: () => ADD_TO_CART_EVENT,
24
+ REMOVE_FROM_CART_EVENT: () => REMOVE_FROM_CART_EVENT,
23
25
  TAG_NAME: () => TAG_NAME,
24
26
  VtexAdsStoryCarouselElement: () => VtexAdsStoryCarouselElement,
25
27
  defineVtexAdsStoryCarousel: () => defineVtexAdsStoryCarousel
@@ -244,7 +246,7 @@ Object.defineProperties(EventShim.prototype, {
244
246
  stopPropagation: enumerableProperty,
245
247
  isTrusted: enumerableProperty
246
248
  });
247
- var CustomEventShim = (_b = class CustomEvent extends EventShim {
249
+ var CustomEventShim = (_b = class CustomEvent2 extends EventShim {
248
250
  constructor(type, options = {}) {
249
251
  var _a13;
250
252
  super(type, options);
@@ -1487,30 +1489,46 @@ var collapse_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256
1487
1489
  // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/expand.svg
1488
1490
  var expand_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M216,48V88a8,8,0,0,1-16,0V56H168a8,8,0,0,1,0-16h40A8,8,0,0,1,216,48ZM88,200H56V168a8,8,0,0,0-16,0v40a8,8,0,0,0,8,8H88a8,8,0,0,0,0-16Zm120-40a8,8,0,0,0-8,8v32H168a8,8,0,0,0,0,16h40a8,8,0,0,0,8-8V168A8,8,0,0,0,208,160ZM88,40H48a8,8,0,0,0-8,8V88a8,8,0,0,0,16,0V56H88a8,8,0,0,0,0-16Z"/></svg>\n';
1489
1491
 
1492
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/minus.svg
1493
+ var minus_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M224,128a8,8,0,0,1-8,8H40a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128Z"/></svg>';
1494
+
1490
1495
  // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/pause-fill.svg
1491
1496
  var pause_fill_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M216,48V208a16,16,0,0,1-16,16H160a16,16,0,0,1-16-16V48a16,16,0,0,1,16-16h40A16,16,0,0,1,216,48ZM96,32H56A16,16,0,0,0,40,48V208a16,16,0,0,0,16,16H96a16,16,0,0,0,16-16V48A16,16,0,0,0,96,32Z"/></svg>\n';
1492
1497
 
1493
1498
  // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/play-fill.svg
1494
1499
  var play_fill_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M240,128a15.74,15.74,0,0,1-7.6,13.51L88.32,229.65a16,16,0,0,1-16.2.3A15.86,15.86,0,0,1,64,216.13V39.87a15.86,15.86,0,0,1,8.12-13.82,16,16,0,0,1,16.2.3L232.4,114.49A15.74,15.74,0,0,1,240,128Z"/></svg>\n';
1495
1500
 
1501
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/plus.svg
1502
+ var plus_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M224,128a8,8,0,0,1-8,8H136v80a8,8,0,0,1-16,0V136H40a8,8,0,0,1,0-16h80V40a8,8,0,0,1,16,0v80h80A8,8,0,0,1,224,128Z"/></svg>';
1503
+
1496
1504
  // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/speaker-x-fill.svg
1497
1505
  var speaker_x_fill_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M245.66,146.34a8,8,0,0,1-11.32,11.32L216,139.31l-18.34,18.35a8,8,0,0,1-11.32-11.32L204.69,128l-18.35-18.34a8,8,0,0,1,11.32-11.32L216,116.69l18.34-18.35a8,8,0,0,1,11.32,11.32L227.31,128ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm97.15-54.15a8,8,0,0,0-10-.16l-65.57,51A4,4,0,0,0,80,79.84v96.32a4,4,0,0,0,1.55,3.15l65.57,51a8,8,0,0,0,9,.56,8.29,8.29,0,0,0,3.91-7.18V32.25A8.27,8.27,0,0,0,157.12,25.85Z"/></svg>\n';
1498
1506
 
1499
1507
  // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/speaker-high-fill.svg
1500
1508
  var speaker_high_fill_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm126.77,20.84a8,8,0,0,0-.72,11.3,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88A8,8,0,0,0,186.74,100.84Zm40.89-26.17a8,8,0,1,0-11.92,10.66,64,64,0,0,1,0,85.34,8,8,0,1,0,11.92,10.66,80,80,0,0,0,0-106.66Z"/></svg>\n';
1501
1509
 
1510
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/trash.svg
1511
+ var trash_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M216,48H176V40a24,24,0,0,0-24-24H104A24,24,0,0,0,80,40v8H40a8,8,0,0,0,0,16h8V208a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V64h8a8,8,0,0,0,0-16ZM96,40a8,8,0,0,1,8-8h48a8,8,0,0,1,8,8v8H96Zm96,168H64V64H192ZM112,104v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Zm48,0v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Z"/></svg>';
1512
+
1513
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/warning-circle-fill.svg
1514
+ var warning_circle_fill_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm-8,56a8,8,0,0,1,16,0v56a8,8,0,0,1-16,0Zm8,104a12,12,0,1,1,12-12A12,12,0,0,1,128,184Z"/></svg>\n';
1515
+
1502
1516
  // src/components/icons/index.ts
1503
1517
  var icons = {
1504
1518
  caretUp: caret_up_bold_default,
1505
1519
  close: close_default,
1506
1520
  collapse: collapse_default,
1507
1521
  expand: expand_default,
1522
+ minus: minus_default,
1508
1523
  next: caret_right_bold_default,
1509
1524
  pause: pause_fill_default,
1510
1525
  play: play_fill_default,
1526
+ plus: plus_default,
1511
1527
  previous: caret_left_bold_default,
1512
1528
  soundOff: speaker_x_fill_default,
1513
- soundOn: speaker_high_fill_default
1529
+ soundOn: speaker_high_fill_default,
1530
+ trash: trash_default,
1531
+ warning: warning_circle_fill_default
1514
1532
  };
1515
1533
  var markup = Object.fromEntries(
1516
1534
  Object.entries(icons).map(([name, svg]) => [
@@ -1525,7 +1543,142 @@ function icon(name) {
1525
1543
  return o7(markup[name]);
1526
1544
  }
1527
1545
 
1528
- // src/utils/http-url.ts
1546
+ // src/locales/en.ts
1547
+ var en = {
1548
+ watch: "Watch video",
1549
+ show: "Show video",
1550
+ carousel: "Videos",
1551
+ carouselRole: "carousel",
1552
+ previous: "Previous video",
1553
+ next: "Next video",
1554
+ player: "Video",
1555
+ expand: "Expand video",
1556
+ collapse: "Collapse video",
1557
+ close: "Close video",
1558
+ play: "Play video",
1559
+ pause: "Pause video",
1560
+ soundOn: "Turn sound on",
1561
+ soundOff: "Turn sound off",
1562
+ addToCart: "Add to cart",
1563
+ cartQuantity: "Quantity in cart",
1564
+ decreaseQuantity: "Decrease quantity",
1565
+ removeFromCart: "Remove from cart",
1566
+ increaseQuantity: "Increase quantity",
1567
+ unavailable: "Product unavailable",
1568
+ soldOut: "Sold out",
1569
+ viewProduct: "View product",
1570
+ videoUnavailable: "Video unavailable",
1571
+ videoFailed: "Couldn't load the video",
1572
+ retry: "Try again",
1573
+ videoLoading: "Loading video",
1574
+ product: (name, price, listPrice, soldOut) => {
1575
+ let text = name;
1576
+ if (price && listPrice) text = `${name}, was ${listPrice}, now ${price}`;
1577
+ else if (price) text = `${name}, ${price}`;
1578
+ return soldOut ? `${text}, ${soldOut}` : text;
1579
+ },
1580
+ position: (label, index, count) => count > 1 ? `${label} ${index + 1} of ${count}` : label
1581
+ };
1582
+
1583
+ // src/locales/es.ts
1584
+ var es = {
1585
+ watch: "Ver video",
1586
+ show: "Mostrar video",
1587
+ carousel: "Videos",
1588
+ carouselRole: "carrusel",
1589
+ previous: "Video anterior",
1590
+ next: "Video siguiente",
1591
+ player: "Video",
1592
+ expand: "Ampliar video",
1593
+ collapse: "Reducir video",
1594
+ close: "Cerrar video",
1595
+ play: "Reproducir video",
1596
+ pause: "Pausar video",
1597
+ soundOn: "Activar sonido",
1598
+ soundOff: "Desactivar sonido",
1599
+ addToCart: "Agregar al carrito",
1600
+ cartQuantity: "Cantidad en el carrito",
1601
+ decreaseQuantity: "Disminuir cantidad",
1602
+ removeFromCart: "Quitar del carrito",
1603
+ increaseQuantity: "Aumentar cantidad",
1604
+ unavailable: "Producto no disponible",
1605
+ soldOut: "Agotado",
1606
+ viewProduct: "Ver producto",
1607
+ videoUnavailable: "Video no disponible",
1608
+ videoFailed: "No se pudo cargar el video",
1609
+ retry: "Intentar de nuevo",
1610
+ videoLoading: "Cargando video",
1611
+ product: (name, price, listPrice, soldOut) => {
1612
+ let text = name;
1613
+ if (price && listPrice)
1614
+ text = `${name}, antes ${listPrice}, ahora ${price}`;
1615
+ else if (price) text = `${name}, ${price}`;
1616
+ return soldOut ? `${text}, ${soldOut}` : text;
1617
+ },
1618
+ position: (label, index, count) => count > 1 ? `${label} ${index + 1} de ${count}` : label
1619
+ };
1620
+
1621
+ // src/locales/pt.ts
1622
+ var pt = {
1623
+ watch: "Assistir v\xEDdeo",
1624
+ show: "Mostrar v\xEDdeo",
1625
+ carousel: "V\xEDdeos",
1626
+ carouselRole: "carrossel",
1627
+ previous: "V\xEDdeo anterior",
1628
+ next: "Pr\xF3ximo v\xEDdeo",
1629
+ player: "V\xEDdeo",
1630
+ expand: "Expandir v\xEDdeo",
1631
+ collapse: "Reduzir v\xEDdeo",
1632
+ close: "Fechar v\xEDdeo",
1633
+ play: "Reproduzir v\xEDdeo",
1634
+ pause: "Pausar v\xEDdeo",
1635
+ soundOn: "Ativar som",
1636
+ soundOff: "Desativar som",
1637
+ addToCart: "Adicionar ao carrinho",
1638
+ cartQuantity: "Quantidade no carrinho",
1639
+ decreaseQuantity: "Diminuir quantidade",
1640
+ removeFromCart: "Remover do carrinho",
1641
+ increaseQuantity: "Aumentar quantidade",
1642
+ unavailable: "Produto indispon\xEDvel",
1643
+ soldOut: "Esgotado",
1644
+ viewProduct: "Ver produto",
1645
+ videoUnavailable: "V\xEDdeo indispon\xEDvel",
1646
+ videoFailed: "N\xE3o foi poss\xEDvel carregar o v\xEDdeo",
1647
+ retry: "Tentar de novo",
1648
+ videoLoading: "Carregando v\xEDdeo",
1649
+ product: (name, price, listPrice, soldOut) => {
1650
+ let text = name;
1651
+ if (price && listPrice) text = `${name}, de ${listPrice} por ${price}`;
1652
+ else if (price) text = `${name}, ${price}`;
1653
+ return soldOut ? `${text}, ${soldOut}` : text;
1654
+ },
1655
+ position: (label, index, count) => count > 1 ? `${label} ${index + 1} de ${count}` : label
1656
+ };
1657
+
1658
+ // src/locales/index.ts
1659
+ var BY_LANGUAGE = /* @__PURE__ */ new Map([
1660
+ ["pt", pt],
1661
+ ["es", es],
1662
+ ["en", en]
1663
+ ]);
1664
+ function labelsFor(locale, overrides = {}) {
1665
+ var _a13, _b3, _c, _d, _e;
1666
+ const language = locale.split("-")[0].toLowerCase();
1667
+ const labels = (_a13 = BY_LANGUAGE.get(language)) != null ? _a13 : pt;
1668
+ const addToCart = (_b3 = overrides.addToCart) == null ? void 0 : _b3.trim();
1669
+ const viewProduct = (_c = overrides.viewProduct) == null ? void 0 : _c.trim();
1670
+ const unavailable = (_d = overrides.unavailable) == null ? void 0 : _d.trim();
1671
+ const soldOut = (_e = overrides.soldOut) == null ? void 0 : _e.trim();
1672
+ return {
1673
+ ...labels,
1674
+ ...addToCart && { addToCart },
1675
+ ...viewProduct && { viewProduct },
1676
+ ...unavailable && { unavailable },
1677
+ ...soldOut && { soldOut }
1678
+ };
1679
+ }
1680
+
1681
+ // src/utils/safe-url.ts
1529
1682
  function httpUrl(value) {
1530
1683
  if (!value) return null;
1531
1684
  try {
@@ -1535,18 +1688,82 @@ function httpUrl(value) {
1535
1688
  return null;
1536
1689
  }
1537
1690
  }
1691
+ var STORE_BASE = "https://store.invalid";
1692
+ function storePath(value) {
1693
+ try {
1694
+ const url = new URL(value, STORE_BASE);
1695
+ if (url.origin !== STORE_BASE || url.pathname.startsWith("//")) {
1696
+ return null;
1697
+ }
1698
+ return `${url.pathname}${url.search}${url.hash}`;
1699
+ } catch (e6) {
1700
+ return null;
1701
+ }
1702
+ }
1703
+ function destinationUrl(value) {
1704
+ if (!value) return null;
1705
+ return value.startsWith("/") ? storePath(value) : httpUrl(value);
1706
+ }
1538
1707
 
1539
1708
  // src/components/media/media.ts
1709
+ var REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
1540
1710
  function prefersReducedMotion() {
1541
1711
  var _a13, _b3;
1542
- return (_b3 = (_a13 = globalThis.matchMedia) == null ? void 0 : _a13.call(globalThis, "(prefers-reduced-motion: reduce)").matches) != null ? _b3 : false;
1712
+ return (_b3 = (_a13 = globalThis.matchMedia) == null ? void 0 : _a13.call(globalThis, REDUCED_MOTION).matches) != null ? _b3 : false;
1543
1713
  }
1544
1714
  function hasVideo(story, video) {
1545
- return !video.failed && httpUrl(story.media_url) !== null;
1715
+ return !video.failed && !video.retrying && httpUrl(story.media_url) !== null;
1716
+ }
1717
+ function renderFailed(labels, onRetry) {
1718
+ const retry = (event) => {
1719
+ event.stopPropagation();
1720
+ onRetry == null ? void 0 : onRetry();
1721
+ };
1722
+ return T`
1723
+ <div class="media-status" ?data-retry=${!!onRetry}>
1724
+ <span class="media-status-text">
1725
+ ${icon("warning")}
1726
+ ${onRetry ? labels.videoFailed : labels.videoUnavailable}
1727
+ </span>
1728
+ ${onRetry ? T`
1729
+ <button type="button" class="media-retry" @click=${retry}>
1730
+ ${labels.retry}
1731
+ </button>
1732
+ ` : A}
1733
+ </div>
1734
+ `;
1546
1735
  }
1547
- function renderMedia(story, video, { withVideo = true, loop = true, onEnded } = {}) {
1736
+ function renderVideoLoading(labels) {
1737
+ return T`
1738
+ <div class="media-status">
1739
+ <span class="media-status-text">
1740
+ <span class="media-spinner" aria-hidden="true"></span>
1741
+ ${labels.videoLoading}
1742
+ </span>
1743
+ </div>
1744
+ `;
1745
+ }
1746
+ function renderStatus(video, labels, onRetry) {
1747
+ if (video.failed) return renderFailed(labels, onRetry);
1748
+ if (video.retrying) return renderVideoLoading(labels);
1749
+ return A;
1750
+ }
1751
+ function renderNotice(video, { labels = pt, onRetry, announce = true }) {
1752
+ return T`
1753
+ <div
1754
+ class="media-notice"
1755
+ role=${announce ? "status" : A}
1756
+ aria-hidden=${announce ? A : "true"}
1757
+ >
1758
+ ${renderStatus(video, labels, onRetry)}
1759
+ </div>
1760
+ `;
1761
+ }
1762
+ function renderMedia(story, video, options = {}) {
1763
+ const { withVideo = true, loop = true, onEnded, autoplay = true } = options;
1548
1764
  const posterUrl = httpUrl(story.poster_url);
1549
1765
  const mediaUrl = withVideo ? httpUrl(story.media_url) : null;
1766
+ const preload = autoplay ? "metadata" : "auto";
1550
1767
  return T`
1551
1768
  ${posterUrl ? T`<img class="poster" alt="" src=${posterUrl} />` : A}
1552
1769
  ${mediaUrl && !video.failed ? T`
@@ -1555,22 +1772,137 @@ function renderMedia(story, video, { withVideo = true, loop = true, onEnded } =
1555
1772
  muted
1556
1773
  playsinline
1557
1774
  ?loop=${loop}
1558
- preload="metadata"
1775
+ preload=${preload}
1559
1776
  .muted=${true}
1560
- ?autoplay=${!prefersReducedMotion()}
1777
+ ?autoplay=${autoplay && !prefersReducedMotion()}
1561
1778
  poster=${posterUrl != null ? posterUrl : A}
1562
1779
  src=${mediaUrl}
1563
1780
  ${n5(video.ref)}
1564
1781
  @play=${video.sync}
1565
1782
  @pause=${video.sync}
1566
1783
  @volumechange=${video.sync}
1784
+ @loadeddata=${video.loaded}
1567
1785
  @error=${video.fail}
1568
1786
  @ended=${onEnded}
1569
1787
  ></video>
1570
1788
  ` : A}
1789
+ ${mediaUrl ? renderNotice(video, options) : A}
1571
1790
  `;
1572
1791
  }
1573
1792
 
1793
+ // src/components/media/media.styles.ts
1794
+ var mediaStyles = i`
1795
+ /* The live region the notice shows in, over the cover. Empty until the
1796
+ video can't load or is loading again. Clicks go through to the card. */
1797
+ .media-notice {
1798
+ position: absolute;
1799
+ inset: 0;
1800
+ pointer-events: none;
1801
+ }
1802
+
1803
+ /* The notice: a dimmed layer with the text in the middle. */
1804
+ .media-status {
1805
+ position: absolute;
1806
+ inset: 0;
1807
+ display: flex;
1808
+ flex-direction: column;
1809
+ gap: 12px;
1810
+ align-items: center;
1811
+ justify-content: center;
1812
+ box-sizing: border-box;
1813
+ padding: 16px;
1814
+ background: rgba(0, 0, 0, 0.45);
1815
+ color: #fff;
1816
+ text-align: center;
1817
+ pointer-events: none;
1818
+ }
1819
+
1820
+ .media-status > * {
1821
+ animation: media-status-in 0.4s ease-out both;
1822
+ }
1823
+
1824
+ .media-status-text {
1825
+ display: flex;
1826
+ flex-direction: column;
1827
+ gap: 8px;
1828
+ align-items: center;
1829
+ max-width: 100%;
1830
+ font-size: 14px;
1831
+ font-weight: 600;
1832
+ line-height: 1.3;
1833
+ text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
1834
+ }
1835
+
1836
+ .media-status-text .icon {
1837
+ width: 18px;
1838
+ height: 18px;
1839
+ }
1840
+
1841
+ .media-status[data-retry] .media-status-text .icon {
1842
+ width: 24px;
1843
+ height: 24px;
1844
+ }
1845
+
1846
+ .media-retry {
1847
+ min-height: 36px;
1848
+ padding: 0 16px;
1849
+ border: 0;
1850
+ border-radius: var(--_button-radius);
1851
+ background: rgba(255, 255, 255, 0.15);
1852
+ backdrop-filter: blur(4px);
1853
+ box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.42);
1854
+ color: #fff;
1855
+ font: inherit;
1856
+ font-size: 14px;
1857
+ font-weight: 600;
1858
+ cursor: pointer;
1859
+ pointer-events: auto;
1860
+ animation-delay: 0.06s;
1861
+ }
1862
+
1863
+ .media-retry:focus-visible {
1864
+ outline: 2px solid #fff;
1865
+ outline-offset: 2px;
1866
+ }
1867
+
1868
+ @media (hover: hover) and (pointer: fine) {
1869
+ .media-retry:hover {
1870
+ background: rgba(255, 255, 255, 0.25);
1871
+ }
1872
+ }
1873
+
1874
+ /* It spins with reduced motion too: a still ring wouldn't read as
1875
+ loading. */
1876
+ .media-spinner {
1877
+ width: 24px;
1878
+ height: 24px;
1879
+ box-sizing: border-box;
1880
+ border: 2px solid rgba(255, 255, 255, 0.35);
1881
+ border-top-color: #fff;
1882
+ border-radius: 50%;
1883
+ animation: media-spin 0.8s linear infinite;
1884
+ }
1885
+
1886
+ @keyframes media-status-in {
1887
+ from {
1888
+ opacity: 0;
1889
+ transform: translateY(4px);
1890
+ }
1891
+ }
1892
+
1893
+ @keyframes media-spin {
1894
+ to {
1895
+ transform: rotate(360deg);
1896
+ }
1897
+ }
1898
+
1899
+ @media (prefers-reduced-motion: reduce) {
1900
+ .media-status > :not(.media-spinner) {
1901
+ animation: none;
1902
+ }
1903
+ }
1904
+ `;
1905
+
1574
1906
  // src/components/media/video-controller.ts
1575
1907
  function playVideo(video) {
1576
1908
  var _a13;
@@ -1584,8 +1916,7 @@ var VideoController = class {
1584
1916
  this.paused = true;
1585
1917
  // The video always starts muted: that is what browsers allow to autoplay.
1586
1918
  this.muted = true;
1587
- /** The video could not load: only the cover is shown. */
1588
- this.failed = false;
1919
+ this.status = "playable";
1589
1920
  /** Listener for the video's play, pause and volumechange events. */
1590
1921
  this.sync = () => {
1591
1922
  const video = this.ref.value;
@@ -1594,22 +1925,78 @@ var VideoController = class {
1594
1925
  this.muted = video.muted;
1595
1926
  this.host.requestUpdate();
1596
1927
  };
1928
+ /** Listener for the video's loadeddata event. */
1929
+ this.loaded = () => {
1930
+ this.settleReady(true);
1931
+ if (!this.retrying) return;
1932
+ this.status = "playable";
1933
+ this.host.requestUpdate();
1934
+ };
1597
1935
  /** Listener for the video's error event. */
1598
1936
  this.fail = () => {
1599
- this.failed = true;
1937
+ this.status = "failed";
1938
+ this.settleReady(false);
1600
1939
  this.host.requestUpdate();
1601
1940
  };
1941
+ this.waitForReady();
1942
+ }
1943
+ /**
1944
+ * Resolves true once the video's first frame has loaded, or false if it
1945
+ * fails. A new one for each new <video> (see reset).
1946
+ */
1947
+ get ready() {
1948
+ return this.readyState;
1949
+ }
1950
+ /** The video could not load: the cover shows with a notice over it. */
1951
+ get failed() {
1952
+ return this.status === "failed";
1953
+ }
1954
+ /** A failed video is loading again (see retry), until it loads or fails. */
1955
+ get retrying() {
1956
+ return this.status === "retrying";
1602
1957
  }
1603
1958
  /** The rendered <video> is on the page and playing. */
1604
1959
  get playing() {
1605
1960
  const video = this.ref.value;
1606
1961
  return !!video && video.isConnected && !video.paused;
1607
1962
  }
1608
- /** For a new <video>, such as each time the player opens. */
1963
+ /**
1964
+ * For a new <video>, such as each time the player opens. A retry still
1965
+ * loading resolves false.
1966
+ */
1609
1967
  reset() {
1968
+ this.cancelRetry();
1610
1969
  this.paused = true;
1611
1970
  this.muted = true;
1612
- this.failed = false;
1971
+ this.status = "playable";
1972
+ this.waitForReady();
1973
+ }
1974
+ /**
1975
+ * For the next Story's <video>: neither failed nor loading again (a retry
1976
+ * still loading resolves false). Unlike reset, it keeps the playback and
1977
+ * sound state.
1978
+ */
1979
+ clearFailure() {
1980
+ if (this.retrying) {
1981
+ this.cancelRetry();
1982
+ this.waitForReady();
1983
+ }
1984
+ this.status = "playable";
1985
+ this.host.requestUpdate();
1986
+ }
1987
+ /**
1988
+ * Loads a failed video again: renderMedia renders a new <video> with a
1989
+ * notice that it is loading, until it loads or fails. Resolves as `ready`
1990
+ * does: false too if the video is replaced first (see reset and
1991
+ * clearFailure), and at once for a video that didn't fail.
1992
+ */
1993
+ retry() {
1994
+ if (this.retrying) return this.ready;
1995
+ if (!this.failed) return Promise.resolve(false);
1996
+ this.reset();
1997
+ this.status = "retrying";
1998
+ this.host.requestUpdate();
1999
+ return this.ready;
1613
2000
  }
1614
2001
  play() {
1615
2002
  const video = this.ref.value;
@@ -1669,6 +2056,13 @@ var VideoController = class {
1669
2056
  const video = this.ref.value;
1670
2057
  if (video) video.muted = !video.muted;
1671
2058
  }
2059
+ // The video loading again is replaced: its retry resolves false.
2060
+ cancelRetry() {
2061
+ if (this.retrying) this.settleReady(false);
2062
+ }
2063
+ waitForReady() {
2064
+ this.readyState = new Promise((settle) => this.settleReady = settle);
2065
+ }
1672
2066
  };
1673
2067
 
1674
2068
  // src/components/product/price.ts
@@ -1717,33 +2111,31 @@ function priceFormatter(locale, currency) {
1717
2111
 
1718
2112
  // src/components/product/product.ts
1719
2113
  function toCardProduct(story, format, labels, fetched) {
1720
- var _a13, _b3, _c, _d;
2114
+ var _a13, _b3, _c, _d, _e, _f;
1721
2115
  const product = story.product;
1722
2116
  const name = (_a13 = product == null ? void 0 : product.product_name) == null ? void 0 : _a13.trim();
1723
2117
  if (!product || !name) return void 0;
1724
2118
  const base = {
1725
2119
  name,
1726
2120
  imageUrl: (_b3 = httpUrl(product.image_url)) != null ? _b3 : void 0,
1727
- url: (_c = httpUrl(story.destination_url)) != null ? _c : void 0
2121
+ url: (_c = destinationUrl(story.destination_url)) != null ? _c : void 0,
2122
+ sku: ((_d = product.product_sku) == null ? void 0 : _d.trim()) || void 0,
2123
+ seller: ((_e = product.seller_id) == null ? void 0 : _e.trim()) || void 0
1728
2124
  };
1729
2125
  if (fetched === "loading") {
1730
2126
  return { ...base, label: labels.product(name), isLoading: true };
1731
2127
  }
1732
- if ((fetched == null ? void 0 : fetched.available) === false) {
1733
- return {
1734
- ...base,
1735
- label: labels.product(name, labels.soldOut),
1736
- soldOut: labels.soldOut
1737
- };
1738
- }
1739
- const amounts = (_d = fetched == null ? void 0 : fetched.price) != null ? _d : readProductPrice(product.product_metadata);
2128
+ const soldOut = (fetched == null ? void 0 : fetched.available) === false ? labels.soldOut : void 0;
2129
+ const shown = (amounts2) => soldOut && (amounts2 == null ? void 0 : amounts2.price) === 0 ? void 0 : amounts2;
2130
+ const amounts = (_f = shown(fetched == null ? void 0 : fetched.price)) != null ? _f : shown(readProductPrice(product.product_metadata));
1740
2131
  const price = amounts && format(amounts.price);
1741
2132
  const listPrice = (amounts == null ? void 0 : amounts.listPrice) === void 0 ? void 0 : format(amounts.listPrice);
1742
2133
  return {
1743
2134
  ...base,
1744
2135
  price,
1745
2136
  listPrice,
1746
- label: labels.product(name, price, listPrice)
2137
+ soldOut,
2138
+ label: labels.product(name, price, listPrice, soldOut)
1747
2139
  };
1748
2140
  }
1749
2141
  var priceSkeleton = T`
@@ -1760,10 +2152,9 @@ var addToCartSkeleton = T`
1760
2152
  `;
1761
2153
  function renderPrice({ isLoading, soldOut, price, listPrice }) {
1762
2154
  if (isLoading) return priceSkeleton;
1763
- if (soldOut) {
1764
- return T`<span class="product-price product-sold-out">${soldOut}</span>`;
2155
+ if (!price) {
2156
+ return soldOut ? T`<span class="product-price product-sold-out">${soldOut}</span>` : A;
1765
2157
  }
1766
- if (!price) return A;
1767
2158
  return T`
1768
2159
  <span class="product-price">
1769
2160
  <span>${price}</span>
@@ -1792,7 +2183,48 @@ function renderProduct(product, onSelect) {
1792
2183
  </button>
1793
2184
  `;
1794
2185
  }
1795
- function renderAddToCart({ isLoading, soldOut }, { labels }) {
2186
+ var STEPPER_ADD_CLASS = "product-stepper-add";
2187
+ var ADD_TO_CART_CLASS = "product-add-to-cart";
2188
+ function focusCartAction(root, action) {
2189
+ var _a13;
2190
+ const className = action === "stepper" ? STEPPER_ADD_CLASS : ADD_TO_CART_CLASS;
2191
+ (_a13 = root.querySelector(`.${className}`)) == null ? void 0 : _a13.focus();
2192
+ }
2193
+ function renderStepper(quantity, {
2194
+ labels,
2195
+ onAddToCart,
2196
+ onRemoveFromCart
2197
+ }) {
2198
+ const last = quantity === 1;
2199
+ return T`
2200
+ <div
2201
+ class="product-action product-stepper"
2202
+ role="group"
2203
+ aria-label=${labels.cartQuantity}
2204
+ >
2205
+ <button
2206
+ type="button"
2207
+ class="product-stepper-button product-stepper-remove"
2208
+ aria-label=${last ? labels.removeFromCart : labels.decreaseQuantity}
2209
+ @click=${onRemoveFromCart}
2210
+ >
2211
+ ${icon(last ? "trash" : "minus")}
2212
+ </button>
2213
+ <span class="product-quantity">${quantity}</span>
2214
+ <button
2215
+ type="button"
2216
+ class="product-stepper-button ${STEPPER_ADD_CLASS}"
2217
+ aria-label=${labels.increaseQuantity}
2218
+ @click=${onAddToCart}
2219
+ >
2220
+ ${icon("plus")}
2221
+ </button>
2222
+ </div>
2223
+ `;
2224
+ }
2225
+ function renderAddToCart({ isLoading, soldOut, sku }, options) {
2226
+ const { labels, onAddToCart, cartQuantity = 0 } = options;
2227
+ if (!sku || !onAddToCart) return A;
1796
2228
  if (isLoading) return addToCartSkeleton;
1797
2229
  if (soldOut) {
1798
2230
  return T`
@@ -1801,12 +2233,25 @@ function renderAddToCart({ isLoading, soldOut }, { labels }) {
1801
2233
  </button>
1802
2234
  `;
1803
2235
  }
2236
+ if (cartQuantity > 0) return renderStepper(cartQuantity, options);
1804
2237
  return T`
1805
- <button type="button" class="product-action product-add-to-cart">
2238
+ <button
2239
+ type="button"
2240
+ class="product-action ${ADD_TO_CART_CLASS}"
2241
+ @click=${onAddToCart}
2242
+ >
1806
2243
  ${labels.addToCart}
1807
2244
  </button>
1808
2245
  `;
1809
2246
  }
2247
+ function renderCartStatus({ sku }, { labels, cartQuantity = 0, onAddToCart }) {
2248
+ if (!sku || !onAddToCart) return A;
2249
+ return T`
2250
+ <span class="product-cart-status" role="status">
2251
+ ${cartQuantity > 0 ? `${labels.cartQuantity}: ${cartQuantity}` : ""}
2252
+ </span>
2253
+ `;
2254
+ }
1810
2255
  function renderExpandableProduct(product, options) {
1811
2256
  const { open } = options;
1812
2257
  return T`
@@ -1824,6 +2269,7 @@ function renderExpandableProduct(product, options) {
1824
2269
  </button>
1825
2270
  <div id=${options.panelId} class="product-panel" ?inert=${!open}>
1826
2271
  <div class="product-actions">
2272
+ ${renderCartStatus(product, options)}
1827
2273
  ${renderAddToCart(product, options)}
1828
2274
  ${product.url ? T`
1829
2275
  <a
@@ -1846,7 +2292,7 @@ function toCardCta(story) {
1846
2292
  var _a13;
1847
2293
  if (story.product) return void 0;
1848
2294
  const label = (_a13 = story.call_to_action) == null ? void 0 : _a13.trim();
1849
- const url = httpUrl(story.destination_url);
2295
+ const url = destinationUrl(story.destination_url);
1850
2296
  return label && url ? { label, url } : void 0;
1851
2297
  }
1852
2298
  function renderCta(cta, onSelect) {
@@ -1883,9 +2329,9 @@ var productStyles = i`
1883
2329
  gap: 8px;
1884
2330
  align-items: center;
1885
2331
  box-sizing: border-box;
1886
- padding: 8px;
2332
+ padding: var(--_pill-inset);
1887
2333
  border: 0;
1888
- border-radius: 16px;
2334
+ border-radius: var(--_pill-radius);
1889
2335
  background: rgba(255, 255, 255, 0.15);
1890
2336
  backdrop-filter: blur(5px);
1891
2337
  color: #fff;
@@ -1980,7 +2426,7 @@ var productStyles = i`
1980
2426
  align-items: center;
1981
2427
  box-sizing: border-box;
1982
2428
  width: 100%;
1983
- padding: 8px;
2429
+ padding: var(--_pill-inset);
1984
2430
  border: 0;
1985
2431
  border-radius: inherit;
1986
2432
  background: transparent;
@@ -2043,7 +2489,7 @@ var productStyles = i`
2043
2489
  height: 48px;
2044
2490
  padding: 0 16px;
2045
2491
  border: 1px solid var(--vtex-ads-story-color-accent, #1b75a8);
2046
- border-radius: 50px;
2492
+ border-radius: var(--_button-radius);
2047
2493
  font: inherit;
2048
2494
  font-size: 14px;
2049
2495
  font-weight: 700;
@@ -2070,6 +2516,62 @@ var productStyles = i`
2070
2516
  );
2071
2517
  }
2072
2518
 
2519
+ /* In the cart: the add to cart button's pill, with minus and plus at its
2520
+ ends and the quantity between them. */
2521
+ .product-stepper {
2522
+ justify-content: space-between;
2523
+ padding: 0;
2524
+ background: var(--vtex-ads-story-color-accent, #1b75a8);
2525
+ color: var(--vtex-ads-story-color-accent-contrast, #fff);
2526
+ cursor: auto;
2527
+ }
2528
+
2529
+ .product-stepper-button {
2530
+ display: grid;
2531
+ flex: none;
2532
+ place-items: center;
2533
+ width: 46px;
2534
+ height: 46px;
2535
+ padding: 0;
2536
+ border: 0;
2537
+ border-radius: var(--_button-radius);
2538
+ background: transparent;
2539
+ color: inherit;
2540
+ cursor: pointer;
2541
+ transition: background-color 0.2s ease;
2542
+ }
2543
+
2544
+ .product-stepper-button .icon {
2545
+ width: 18px;
2546
+ height: 18px;
2547
+ }
2548
+
2549
+ .product-stepper-button:hover {
2550
+ background: rgba(0, 0, 0, 0.15);
2551
+ }
2552
+
2553
+ .product-stepper-button:focus-visible {
2554
+ outline: 2px solid var(--vtex-ads-story-color-accent-contrast, #fff);
2555
+ outline-offset: -4px;
2556
+ }
2557
+
2558
+ .product-quantity {
2559
+ flex: 1;
2560
+ min-width: 0;
2561
+ font-size: 16px;
2562
+ text-align: center;
2563
+ }
2564
+
2565
+ .product-cart-status {
2566
+ position: absolute;
2567
+ width: 1px;
2568
+ height: 1px;
2569
+ margin: -1px;
2570
+ overflow: hidden;
2571
+ clip-path: inset(50%);
2572
+ white-space: nowrap;
2573
+ }
2574
+
2073
2575
  /* Sold out: add to cart, disabled and grayed. */
2074
2576
  .product-unavailable {
2075
2577
  border-color: transparent;
@@ -2159,11 +2661,12 @@ var productStyles = i`
2159
2661
  }
2160
2662
  }
2161
2663
 
2664
+ /* Its corners follow the pill's, one inset in from them: 8px by default. */
2162
2665
  .product-image {
2163
2666
  flex: none;
2164
2667
  width: 60px;
2165
2668
  height: 60px;
2166
- border-radius: 8px;
2669
+ border-radius: max(0px, var(--_pill-radius) - var(--_pill-inset));
2167
2670
  background: #fff;
2168
2671
  object-fit: contain;
2169
2672
  }
@@ -2227,7 +2730,7 @@ var productStyles = i`
2227
2730
  .product-add-to-cart-loading {
2228
2731
  display: block;
2229
2732
  height: 48px;
2230
- border-radius: 50px;
2733
+ border-radius: var(--_button-radius);
2231
2734
  }
2232
2735
 
2233
2736
  @media (prefers-reduced-motion: reduce) {
@@ -2371,7 +2874,12 @@ function renderCard(story, video, options) {
2371
2874
  return (_a14 = options.onPress) == null ? void 0 : _a14.call(options);
2372
2875
  }, capture: true }}
2373
2876
  >
2374
- ${renderMedia(story, video, { withVideo })}
2877
+ ${renderMedia(story, video, {
2878
+ withVideo,
2879
+ autoplay: options.autoplay,
2880
+ labels: options.labels,
2881
+ announce: false
2882
+ })}
2375
2883
  <button
2376
2884
  type="button"
2377
2885
  class="card-open"
@@ -2379,7 +2887,7 @@ function renderCard(story, video, options) {
2379
2887
  aria-label=${options.label}
2380
2888
  @click=${options.onSelect}
2381
2889
  >
2382
- <span class="play" aria-hidden="true">${icon("play")}</span>
2890
+ ${withVideo && video.failed ? A : T`<span class="play" aria-hidden="true">${icon("play")}</span>`}
2383
2891
  </button>
2384
2892
  ${withVideo && hasVideo(story, video) && !video.paused ? renderSoundButton(video, options) : A}
2385
2893
  ${options.product ? renderProduct(
@@ -2479,6 +2987,17 @@ var o8 = e3(class extends i5 {
2479
2987
  var STAGE_HEIGHT = i`500px`;
2480
2988
  var SOLO_PADDING = i`24px`;
2481
2989
  var AUTO_ADVANCE_MS = 5e3;
2990
+ var MIN_SLIDE_DURATION_MS = 2e3;
2991
+ var MAX_SLIDE_DURATION_MS = 12e4;
2992
+ var toSlideDuration = (ms) => {
2993
+ if (ms === void 0 || !Number.isFinite(ms) || ms < 0) {
2994
+ return AUTO_ADVANCE_MS;
2995
+ }
2996
+ if (ms === 0) {
2997
+ return 0;
2998
+ }
2999
+ return Math.min(Math.max(ms, MIN_SLIDE_DURATION_MS), MAX_SLIDE_DURATION_MS);
3000
+ };
2482
3001
  var SWIPE_DISTANCE = 40;
2483
3002
  var NARROW_SCREEN = i`(max-width: 576px)`;
2484
3003
  var VISIBLE_SIDE = 2;
@@ -2661,9 +3180,12 @@ var CarouselController = class {
2661
3180
  this.distance = 1;
2662
3181
  this.count = 0;
2663
3182
  this.narrow = false;
3183
+ this.reducedMotion = false;
2664
3184
  this.connected = false;
2665
3185
  this.hovered = false;
2666
3186
  this.focused = false;
3187
+ /** The interval the running timer was started with. */
3188
+ this.timerMs = 0;
2667
3189
  /** The rendered cards, as their cardRef reported them. */
2668
3190
  this.cards = /* @__PURE__ */ new Map();
2669
3191
  /** The rendered cards' focus targets, as their focusRef reported them. */
@@ -2762,11 +3284,12 @@ var CarouselController = class {
2762
3284
  }
2763
3285
  }
2764
3286
  hostConnected() {
2765
- var _a13, _b3, _c, _d;
3287
+ var _a13, _b3, _c, _d, _e, _f, _g;
2766
3288
  this.connected = true;
2767
3289
  this.media = (_a13 = globalThis.matchMedia) == null ? void 0 : _a13.call(globalThis, NARROW_SCREEN.toString());
2768
3290
  (_b3 = this.media) == null ? void 0 : _b3.addEventListener("change", this.onMediaChange);
2769
3291
  this.narrow = (_d = (_c = this.media) == null ? void 0 : _c.matches) != null ? _d : false;
3292
+ this.reducedMotion = (_g = (_f = (_e = this.options).reducedMotion) == null ? void 0 : _f.call(_e)) != null ? _g : false;
2770
3293
  this.syncTimer();
2771
3294
  }
2772
3295
  hostDisconnected() {
@@ -2777,8 +3300,8 @@ var CarouselController = class {
2777
3300
  this.endSwipe();
2778
3301
  this.syncTimer();
2779
3302
  }
2780
- // Whatever the host changed (the player opening, new Stories) may start or
2781
- // stop the automatic advance.
3303
+ // Whatever the host changed (the player opening, new Stories, the slide
3304
+ // duration) may start, stop or restart the automatic advance.
2782
3305
  hostUpdated() {
2783
3306
  this.syncTimer();
2784
3307
  }
@@ -2807,13 +3330,20 @@ var CarouselController = class {
2807
3330
  (_d = (_c = this.options).onStep) == null ? void 0 : _d.call(_c, from, this.activeKey);
2808
3331
  this.restartTimer();
2809
3332
  }
3333
+ get slideDuration() {
3334
+ var _a13, _b3;
3335
+ return toSlideDuration((_b3 = (_a13 = this.options).slideDuration) == null ? void 0 : _b3.call(_a13));
3336
+ }
2810
3337
  get shouldAdvance() {
2811
3338
  var _a13, _b3;
2812
- return this.connected && this.count > 1 && !this.hovered && !this.focused && !((_b3 = (_a13 = this.options).locked) == null ? void 0 : _b3.call(_a13));
3339
+ return this.slideDuration > 0 && !this.reducedMotion && this.connected && this.count > 1 && !this.hovered && !this.focused && !((_b3 = (_a13 = this.options).locked) == null ? void 0 : _b3.call(_a13));
2813
3340
  }
2814
3341
  syncTimer() {
3342
+ const ms = this.slideDuration;
3343
+ if (this.timer && this.timerMs !== ms) this.stopTimer();
2815
3344
  if (this.shouldAdvance && !this.timer) {
2816
- this.timer = setInterval(() => this.step(1), AUTO_ADVANCE_MS);
3345
+ this.timerMs = ms;
3346
+ this.timer = setInterval(() => this.step(1), ms);
2817
3347
  } else if (!this.shouldAdvance && this.timer) {
2818
3348
  this.stopTimer();
2819
3349
  }
@@ -2821,6 +3351,7 @@ var CarouselController = class {
2821
3351
  stopTimer() {
2822
3352
  clearInterval(this.timer);
2823
3353
  this.timer = void 0;
3354
+ this.timerMs = 0;
2824
3355
  }
2825
3356
  restartTimer() {
2826
3357
  this.stopTimer();
@@ -2975,6 +3506,105 @@ var CarouselController = class {
2975
3506
  }
2976
3507
  };
2977
3508
 
3509
+ // src/components/carousel/carousel-skeleton.ts
3510
+ var carouselSkeletonStyles = i`
3511
+ .root {
3512
+ position: relative;
3513
+ }
3514
+
3515
+ .root[data-requesting] {
3516
+ height: ${STAGE_HEIGHT};
3517
+ }
3518
+
3519
+ .root[data-loading] .carousel {
3520
+ visibility: hidden;
3521
+ }
3522
+
3523
+ .skeleton {
3524
+ position: absolute;
3525
+ inset: 0;
3526
+ z-index: 2;
3527
+ box-sizing: border-box;
3528
+ overflow: hidden;
3529
+ pointer-events: none;
3530
+ transition:
3531
+ opacity 0.3s ease,
3532
+ visibility 0s;
3533
+ }
3534
+
3535
+ .skeleton[data-done] {
3536
+ opacity: 0;
3537
+ visibility: hidden;
3538
+ transition:
3539
+ opacity 0.3s ease,
3540
+ visibility 0s 0.3s;
3541
+ }
3542
+
3543
+ .skeleton-slide {
3544
+ position: absolute;
3545
+ top: 0;
3546
+ left: 50%;
3547
+ width: calc(${STAGE_HEIGHT} * 9 / 16);
3548
+ height: 100%;
3549
+ margin-left: calc(${STAGE_HEIGHT} * 9 / -32);
3550
+ transform: translateX(calc(var(--place) * (100% + 8px))) scale(0.9);
3551
+ }
3552
+
3553
+ .skeleton-slide[data-active] {
3554
+ transform: none;
3555
+ }
3556
+
3557
+ .skeleton-card {
3558
+ width: 100%;
3559
+ height: 100%;
3560
+ border-radius: var(--vtex-ads-story-radius, 20px);
3561
+ background: #ececec;
3562
+ animation: skeleton-pulse 1.2s ease-in-out infinite alternate;
3563
+ }
3564
+
3565
+ .skeleton[data-done] .skeleton-card {
3566
+ animation: none;
3567
+ }
3568
+
3569
+ @keyframes skeleton-pulse {
3570
+ to {
3571
+ background-color: #f6f6f6;
3572
+ }
3573
+ }
3574
+
3575
+ @media (prefers-reduced-motion: reduce) {
3576
+ .skeleton,
3577
+ .skeleton[data-done] {
3578
+ transition: none;
3579
+ }
3580
+
3581
+ .skeleton-card {
3582
+ animation: none;
3583
+ }
3584
+ }
3585
+ `;
3586
+ function renderCarouselSkeleton({ done }) {
3587
+ const places = Array.from(
3588
+ { length: VISIBLE_SIDE * 2 + 1 },
3589
+ (_2, i7) => i7 - VISIBLE_SIDE
3590
+ );
3591
+ return T`
3592
+ <div class="skeleton" aria-hidden="true" ?data-done=${done}>
3593
+ ${places.map(
3594
+ (place) => T`
3595
+ <div
3596
+ class="skeleton-slide"
3597
+ ?data-active=${place === 0}
3598
+ style=${o8({ "--place": String(place) })}
3599
+ >
3600
+ <div class="skeleton-card"></div>
3601
+ </div>
3602
+ `
3603
+ )}
3604
+ </div>
3605
+ `;
3606
+ }
3607
+
2978
3608
  // src/tag-name.ts
2979
3609
  var TAG_NAME = "vtex-ads-story-carousel";
2980
3610
 
@@ -3030,6 +3660,7 @@ var StoryEventsController = class {
3030
3660
  click: /* @__PURE__ */ new Set()
3031
3661
  };
3032
3662
  this.pendingImpressions = [];
3663
+ this.connected = false;
3033
3664
  this.watched = /* @__PURE__ */ new Map();
3034
3665
  this.onIntersect = (entries) => {
3035
3666
  for (const entry of entries) {
@@ -3052,6 +3683,7 @@ var StoryEventsController = class {
3052
3683
  }
3053
3684
  hostConnected() {
3054
3685
  var _a13;
3686
+ this.connected = true;
3055
3687
  if (typeof IntersectionObserver === "function") {
3056
3688
  this.observer = new IntersectionObserver(this.onIntersect, {
3057
3689
  threshold: VIEW_THRESHOLD
@@ -3061,10 +3693,15 @@ var StoryEventsController = class {
3061
3693
  "visibilitychange",
3062
3694
  this.onVisibilityChange
3063
3695
  );
3064
- this.host.updateComplete.then(() => this.syncViewTargets());
3696
+ this.host.updateComplete.then(() => {
3697
+ if (!this.connected) return;
3698
+ this.sendImpressions();
3699
+ this.syncViewTargets();
3700
+ });
3065
3701
  }
3066
3702
  hostDisconnected() {
3067
3703
  var _a13, _b3;
3704
+ this.connected = false;
3068
3705
  (_a13 = globalThis.document) == null ? void 0 : _a13.removeEventListener(
3069
3706
  "visibilitychange",
3070
3707
  this.onVisibilityChange
@@ -3073,24 +3710,26 @@ var StoryEventsController = class {
3073
3710
  this.observer = void 0;
3074
3711
  for (const watched of this.watched.values()) clearTimeout(watched.timer);
3075
3712
  this.watched.clear();
3076
- this.pendingImpressions = [];
3077
3713
  }
3078
3714
  hostUpdated() {
3079
- const stories = this.pendingImpressions;
3080
- if (stories.length && this.options.identity().sessionId) {
3081
- this.pendingImpressions = [];
3082
- for (const story of stories) this.send("impression", story);
3083
- }
3715
+ if (!this.connected) return;
3716
+ this.sendImpressions();
3084
3717
  this.syncViewTargets();
3085
3718
  }
3086
3719
  /**
3087
- * The Stories the host renders next: their impressions go out once that
3088
- * render is done, or, without a session yet, after the first render that
3089
- * has one. Replaces Stories passed before and not sent yet.
3720
+ * The Stories the host shows next: their impressions go out once that
3721
+ * render is done, on the page, with a session (or after the first render
3722
+ * that has both). Replaces Stories passed before and not sent yet.
3090
3723
  */
3091
3724
  impress(stories) {
3092
3725
  this.pendingImpressions = stories;
3093
3726
  }
3727
+ sendImpressions() {
3728
+ const stories = this.pendingImpressions;
3729
+ if (!stories.length || !this.options.identity().sessionId) return;
3730
+ this.pendingImpressions = [];
3731
+ for (const story of stories) this.send("impression", story);
3732
+ }
3094
3733
  /** A touch on the Story: its click goes out, the first time only. */
3095
3734
  click(story) {
3096
3735
  this.send("click", story);
@@ -3372,7 +4011,7 @@ var playerStyles = i`
3372
4011
  padding: 0;
3373
4012
  overflow: hidden;
3374
4013
  border: 0;
3375
- border-radius: 16px;
4014
+ border-radius: var(--vtex-ads-story-radius, 16px);
3376
4015
  background: #111;
3377
4016
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
3378
4017
  cursor: pointer;
@@ -3700,6 +4339,18 @@ var PlayerController = class {
3700
4339
  this.productOpen = !this.productOpen;
3701
4340
  this.host.requestUpdate();
3702
4341
  };
4342
+ /**
4343
+ * Loads the failed video again and, once it loads, plays it with the sound
4344
+ * on (muted if the browser blocks it). Not if the player closed or stepped
4345
+ * meanwhile, even back to the same Story: the retry then resolves false.
4346
+ */
4347
+ this.retryVideo = () => {
4348
+ var _a13;
4349
+ (_a13 = this.dialog.value) == null ? void 0 : _a13.focus();
4350
+ void this.video.retry().then((loaded) => {
4351
+ if (loaded) this.video.playWithSound();
4352
+ });
4353
+ };
3703
4354
  /**
3704
4355
  * A click on the video: closes the product panel when it is open, plays or
3705
4356
  * pauses the video otherwise.
@@ -3723,7 +4374,8 @@ var PlayerController = class {
3723
4374
  this.close();
3724
4375
  }
3725
4376
  /**
3726
- * Opens the mini player, plays the video and focuses the close button.
4377
+ * Opens the mini player, plays the video with the sound on (muted if the
4378
+ * browser blocks it) and focuses the close button.
3727
4379
  * With `productOpen`, the product panel shows open (the shopper chose the
3728
4380
  * product).
3729
4381
  */
@@ -3743,7 +4395,7 @@ var PlayerController = class {
3743
4395
  const dialog = this.dialog.value;
3744
4396
  if (!this.isOpen || !dialog) return;
3745
4397
  this.show(dialog);
3746
- this.video.play();
4398
+ this.video.playWithSound();
3747
4399
  (_a13 = this.closeButton.value) == null ? void 0 : _a13.focus();
3748
4400
  }
3749
4401
  /** Hides the player now; the host removes it on its next update. */
@@ -3765,7 +4417,7 @@ var PlayerController = class {
3765
4417
  async showNext(delta = 0) {
3766
4418
  if (!this.isOpen) return;
3767
4419
  const withSound = !this.video.muted;
3768
- this.video.failed = false;
4420
+ this.video.clearFailure();
3769
4421
  this.productOpen = false;
3770
4422
  this.host.requestUpdate();
3771
4423
  await this.host.updateComplete;
@@ -3867,14 +4519,20 @@ var PlayerController = class {
3867
4519
  * its actions, or the call to action of a link destination. Clicks on them
3868
4520
  * don't reach the video.
3869
4521
  */
3870
- renderDestination({ product, cta, labels }) {
4522
+ renderDestination({
4523
+ product,
4524
+ cta,
4525
+ labels,
4526
+ productActions
4527
+ }) {
3871
4528
  let content;
3872
4529
  if (product) {
3873
4530
  content = renderExpandableProduct(product, {
4531
+ ...productActions,
4532
+ labels,
3874
4533
  open: this.productOpen,
3875
4534
  onToggle: this.toggleProduct,
3876
- panelId: "player-product-panel",
3877
- labels
4535
+ panelId: "player-product-panel"
3878
4536
  });
3879
4537
  } else if (cta) {
3880
4538
  content = renderCta(cta);
@@ -4020,7 +4678,9 @@ var PlayerController = class {
4020
4678
  onEnded: advances ? () => {
4021
4679
  var _a13;
4022
4680
  return (_a13 = options.onStep) == null ? void 0 : _a13.call(options, 1);
4023
- } : void 0
4681
+ } : void 0,
4682
+ labels: destination.labels,
4683
+ onRetry: this.retryVideo
4024
4684
  })}
4025
4685
  ${hasVideo(story, video) ? this.renderVideoControls(destination.labels) : A}
4026
4686
  ${this.renderDestination(destination)}
@@ -4051,13 +4711,12 @@ var PlayerController = class {
4051
4711
  * The expanded view also shows the `neighbors` beside it.
4052
4712
  */
4053
4713
  render(story, {
4054
- labels,
4055
4714
  navigation = false,
4056
4715
  neighbors = [],
4057
- product,
4058
- cta,
4059
- onPress
4716
+ onPress,
4717
+ ...destination
4060
4718
  }) {
4719
+ const { labels } = destination;
4061
4720
  if (!this.isOpen) return A;
4062
4721
  const { video, expanded } = this;
4063
4722
  const shownNeighbors = this.track(story, neighbors);
@@ -4096,11 +4755,7 @@ var PlayerController = class {
4096
4755
  }}
4097
4756
  >
4098
4757
  ${navigation ? this.renderNavigation(labels) : A}
4099
- ${this.renderVideo(story, navigation && expanded, {
4100
- product,
4101
- cta,
4102
- labels
4103
- })}
4758
+ ${this.renderVideo(story, navigation && expanded, destination)}
4104
4759
  <span class="player-dim" aria-hidden="true" ${n5(this.dim)}></span>
4105
4760
  </div>
4106
4761
  </div>
@@ -4145,6 +4800,12 @@ var intelligentSearchHydration = {
4145
4800
  price: import_ads_core.intelligentSearchPrice,
4146
4801
  available: import_ads_core.intelligentSearchAvailability
4147
4802
  };
4803
+ function toShownPrice(value) {
4804
+ const isAmount = (amount) => typeof amount === "number" && Number.isFinite(amount) && amount >= 0;
4805
+ if (!isAmount(value == null ? void 0 : value.price)) return void 0;
4806
+ const { price, listPrice } = value;
4807
+ return isAmount(listPrice) && listPrice > price ? { price, listPrice } : { price };
4808
+ }
4148
4809
  async function hydrateStoryProducts(placement, stories, hydration, identity, { signal, timeout } = {}) {
4149
4810
  var _a13, _b3;
4150
4811
  const products = /* @__PURE__ */ new Map();
@@ -4159,12 +4820,19 @@ async function hydrateStoryProducts(placement, stories, hydration, identity, { s
4159
4820
  );
4160
4821
  for (const { story, product, offer } of (_a13 = hydrated.stories[placement]) != null ? _a13 : []) {
4161
4822
  if (!product || !offer) continue;
4162
- const price = hydration.price(product, offer);
4163
- const available = (_b3 = hydration.available) == null ? void 0 : _b3.call(hydration, product, offer);
4164
- products.set(story.ad_id, {
4165
- ...price && { price },
4166
- ...available !== void 0 && { available }
4167
- });
4823
+ try {
4824
+ const price = toShownPrice(hydration.price(product, offer));
4825
+ const available = (_b3 = hydration.available) == null ? void 0 : _b3.call(hydration, product, offer);
4826
+ products.set(story.ad_id, {
4827
+ ...price && { price },
4828
+ ...available !== void 0 && { available }
4829
+ });
4830
+ } catch (error) {
4831
+ console.error(
4832
+ `[${TAG_NAME}] Product details failed for ad ${story.ad_id}`,
4833
+ error
4834
+ );
4835
+ }
4168
4836
  }
4169
4837
  } catch (error) {
4170
4838
  if (!limit.signal.aborted) {
@@ -4227,105 +4895,57 @@ async function fetchStories({
4227
4895
  }
4228
4896
  }
4229
4897
 
4230
- // src/locales/en.ts
4231
- var en = {
4232
- watch: "Watch video",
4233
- show: "Show video",
4234
- carousel: "Videos",
4235
- carouselRole: "carousel",
4236
- previous: "Previous video",
4237
- next: "Next video",
4238
- player: "Video",
4239
- expand: "Expand video",
4240
- collapse: "Collapse video",
4241
- close: "Close video",
4242
- play: "Play video",
4243
- pause: "Pause video",
4244
- soundOn: "Turn sound on",
4245
- soundOff: "Turn sound off",
4246
- addToCart: "Add to cart",
4247
- unavailable: "Product unavailable",
4248
- soldOut: "Sold out",
4249
- viewProduct: "View product",
4250
- product: (name, price, listPrice) => {
4251
- if (price && listPrice) return `${name}, was ${listPrice}, now ${price}`;
4252
- return price ? `${name}, ${price}` : name;
4253
- },
4254
- position: (label, index, count) => count > 1 ? `${label} ${index + 1} of ${count}` : label
4255
- };
4256
-
4257
- // src/locales/es.ts
4258
- var es = {
4259
- watch: "Ver video",
4260
- show: "Mostrar video",
4261
- carousel: "Videos",
4262
- carouselRole: "carrusel",
4263
- previous: "Video anterior",
4264
- next: "Video siguiente",
4265
- player: "Video",
4266
- expand: "Ampliar video",
4267
- collapse: "Reducir video",
4268
- close: "Cerrar video",
4269
- play: "Reproducir video",
4270
- pause: "Pausar video",
4271
- soundOn: "Activar sonido",
4272
- soundOff: "Desactivar sonido",
4273
- addToCart: "Agregar al carrito",
4274
- unavailable: "Producto no disponible",
4275
- soldOut: "Agotado",
4276
- viewProduct: "Ver producto",
4277
- product: (name, price, listPrice) => {
4278
- if (price && listPrice)
4279
- return `${name}, antes ${listPrice}, ahora ${price}`;
4280
- return price ? `${name}, ${price}` : name;
4281
- },
4282
- position: (label, index, count) => count > 1 ? `${label} ${index + 1} de ${count}` : label
4283
- };
4284
-
4285
- // src/locales/pt.ts
4286
- var pt = {
4287
- watch: "Assistir v\xEDdeo",
4288
- show: "Mostrar v\xEDdeo",
4289
- carousel: "V\xEDdeos",
4290
- carouselRole: "carrossel",
4291
- previous: "V\xEDdeo anterior",
4292
- next: "Pr\xF3ximo v\xEDdeo",
4293
- player: "V\xEDdeo",
4294
- expand: "Expandir v\xEDdeo",
4295
- collapse: "Reduzir v\xEDdeo",
4296
- close: "Fechar v\xEDdeo",
4297
- play: "Reproduzir v\xEDdeo",
4298
- pause: "Pausar v\xEDdeo",
4299
- soundOn: "Ativar som",
4300
- soundOff: "Desativar som",
4301
- addToCart: "Adicionar ao carrinho",
4302
- unavailable: "Produto indispon\xEDvel",
4303
- soldOut: "Esgotado",
4304
- viewProduct: "Ver produto",
4305
- product: (name, price, listPrice) => {
4306
- if (price && listPrice) return `${name}, de ${listPrice} por ${price}`;
4307
- return price ? `${name}, ${price}` : name;
4308
- },
4309
- position: (label, index, count) => count > 1 ? `${label} ${index + 1} de ${count}` : label
4310
- };
4898
+ // src/utils/media-ready.ts
4899
+ var MEDIA_TIMEOUT = 3e3;
4900
+ function decodeImage(url) {
4901
+ if (typeof Image === "undefined") return Promise.resolve(true);
4902
+ const image = new Image();
4903
+ image.src = url;
4904
+ if (!image.decode) return Promise.resolve(true);
4905
+ return image.decode().then(
4906
+ () => true,
4907
+ () => false
4908
+ );
4909
+ }
4910
+ function firstReady(checks, signal) {
4911
+ if (!checks.length) return Promise.resolve();
4912
+ const limit = withTimeout(void 0, MEDIA_TIMEOUT, signal);
4913
+ return new Promise((resolve) => {
4914
+ const done = () => {
4915
+ limit.clear();
4916
+ resolve();
4917
+ };
4918
+ if (limit.signal.aborted) return done();
4919
+ limit.signal.addEventListener("abort", done, { once: true });
4920
+ let failed = 0;
4921
+ for (const check of checks) {
4922
+ check.then(
4923
+ (ready) => {
4924
+ if (ready || ++failed === checks.length) done();
4925
+ },
4926
+ () => {
4927
+ if (++failed === checks.length) done();
4928
+ }
4929
+ );
4930
+ }
4931
+ });
4932
+ }
4311
4933
 
4312
- // src/locales/index.ts
4313
- var BY_LANGUAGE = /* @__PURE__ */ new Map([
4314
- ["pt", pt],
4315
- ["es", es],
4316
- ["en", en]
4317
- ]);
4318
- function labelsFor(locale, overrides = {}) {
4319
- var _a13, _b3, _c;
4320
- const language = locale.split("-")[0].toLowerCase();
4321
- const labels = (_a13 = BY_LANGUAGE.get(language)) != null ? _a13 : pt;
4322
- const addToCart = (_b3 = overrides.addToCart) == null ? void 0 : _b3.trim();
4323
- const viewProduct = (_c = overrides.viewProduct) == null ? void 0 : _c.trim();
4324
- return {
4325
- ...labels,
4326
- ...addToCart && { addToCart },
4327
- ...viewProduct && { viewProduct }
4328
- };
4934
+ // src/commerce-events.ts
4935
+ var ADD_TO_CART_EVENT = "vtex-ads-story:add-to-cart";
4936
+ var REMOVE_FROM_CART_EVENT = "vtex-ads-story:remove-from-cart";
4937
+ function cartEvent(type, { sku, seller }, quantity) {
4938
+ return new CustomEvent(type, {
4939
+ detail: { sku, ...seller && { seller }, quantity },
4940
+ bubbles: true,
4941
+ composed: true
4942
+ });
4943
+ }
4944
+ function addToCartEvent(item, quantity = 1) {
4945
+ return cartEvent(ADD_TO_CART_EVENT, item, quantity);
4946
+ }
4947
+ function removeFromCartEvent(item, quantity = 1) {
4948
+ return cartEvent(REMOVE_FROM_CART_EVENT, item, quantity);
4329
4949
  }
4330
4950
 
4331
4951
  // src/story/story.ts
@@ -4350,9 +4970,17 @@ var channelConverter = {
4350
4970
  var hydrationConverter = {
4351
4971
  fromAttribute: (value) => value === "none" ? "none" : void 0
4352
4972
  };
4973
+ var cartKey = ({ sku, seller }) => JSON.stringify([sku, seller != null ? seller : ""]);
4353
4974
  var VtexAdsStoryCarouselElement = class extends i3 {
4354
4975
  constructor() {
4355
4976
  super();
4977
+ /**
4978
+ * How many of each SKU, from each seller (see cartKey), were added since
4979
+ * the player opened, for its stepper. It doesn't read the store's cart: it
4980
+ * counts the add and remove events sent, and starts over each time the
4981
+ * player opens, as the cart may have changed meanwhile.
4982
+ */
4983
+ this.cartQuantities = /* @__PURE__ */ new Map();
4356
4984
  /**
4357
4985
  * One per rendered card, by its key (see Slide): a Story can show in more
4358
4986
  * than one card, each with its own video.
@@ -4374,7 +5002,9 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4374
5002
  }
4375
5003
  },
4376
5004
  // The player shows the highlighted Story: the highlight stays on it.
4377
- locked: () => this.player.isOpen
5005
+ locked: () => this.player.isOpen || this.mediaLoading,
5006
+ slideDuration: () => this.slideDuration,
5007
+ reducedMotion: prefersReducedMotion
4378
5008
  });
4379
5009
  this.player = new PlayerController(this, {
4380
5010
  onStep: (delta) => this.stepInPlayer(delta),
@@ -4396,6 +5026,7 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4396
5026
  ),
4397
5027
  labels: this.labels,
4398
5028
  withVideo: active || this.inactiveAutoplay && !hidden,
5029
+ autoplay: !this.mediaLoading,
4399
5030
  product: this.productOf(story),
4400
5031
  onSelect: active ? () => this.openPlayer() : () => this.carousel.step(offset),
4401
5032
  // On a card without the highlight, the product moves it, as the card.
@@ -4410,6 +5041,8 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4410
5041
  });
4411
5042
  this.inactiveAutoplay = false;
4412
5043
  this.stories = [];
5044
+ this.requesting = false;
5045
+ this.mediaLoading = false;
4413
5046
  }
4414
5047
  // Lit keeps the card's DOM when the element is moved (removed and appended
4415
5048
  // again), but the browser pauses a removed video and doesn't autoplay it
@@ -4425,9 +5058,10 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4425
5058
  }
4426
5059
  // A request still pending when the element leaves the page is cancelled.
4427
5060
  disconnectedCallback() {
4428
- var _a13;
5061
+ var _a13, _b3;
4429
5062
  super.disconnectedCallback();
4430
5063
  (_a13 = this.request) == null ? void 0 : _a13.abort();
5064
+ (_b3 = this.mediaWait) == null ? void 0 : _b3.abort();
4431
5065
  }
4432
5066
  willUpdate(changed) {
4433
5067
  if (REQUEST_PROPERTIES.some((name) => changed.has(name))) {
@@ -4456,16 +5090,21 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4456
5090
  const request = new AbortController();
4457
5091
  this.request = request;
4458
5092
  this.player.close();
5093
+ this.requesting = false;
4459
5094
  this.showStories([]);
4460
5095
  if (!this.isConnected) {
4461
5096
  request.abort();
4462
5097
  return;
4463
5098
  }
5099
+ this.requesting = Boolean(
5100
+ this.publisherId && this.sessionId && this.placement
5101
+ );
4464
5102
  const stories = await fetchStories(this, {
4465
5103
  signal: request.signal,
4466
5104
  timeout: this.timeout
4467
5105
  });
4468
5106
  if (request.signal.aborted) return;
5107
+ this.requesting = false;
4469
5108
  const hydration = this.activeHydration;
4470
5109
  if (!hydration || !stories.some((story) => story.product)) {
4471
5110
  this.request = void 0;
@@ -4499,7 +5138,34 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4499
5138
  this.afterRender = void 0;
4500
5139
  this.carousel.reset(stories.length);
4501
5140
  this.stories = stories;
5141
+ void this.waitForFirstMedia(stories);
5142
+ }
5143
+ /**
5144
+ * Shows the cards once the first Story's cover or video is ready: whichever
5145
+ * loads first, or once both failed. Only then are the Stories impressed
5146
+ * and do their videos play, from the start.
5147
+ */
5148
+ async waitForFirstMedia(stories) {
5149
+ var _a13, _b3, _c;
5150
+ (_a13 = this.mediaWait) == null ? void 0 : _a13.abort();
5151
+ const wait = new AbortController();
5152
+ this.mediaWait = wait;
5153
+ const cover = httpUrl((_b3 = stories[0]) == null ? void 0 : _b3.poster_url);
5154
+ const video = httpUrl((_c = stories[0]) == null ? void 0 : _c.media_url);
5155
+ const checks = [];
5156
+ if (cover) checks.push(decodeImage(cover));
5157
+ if (video) checks.push(this.videoFor(this.carousel.activeKey).ready);
5158
+ this.mediaLoading = checks.length > 0;
5159
+ await firstReady(checks, wait.signal);
5160
+ if (this.mediaWait !== wait) return;
5161
+ this.mediaWait = void 0;
5162
+ this.mediaLoading = false;
4502
5163
  this.events.impress(stories);
5164
+ this.afterRender = () => {
5165
+ if (!this.isConnected) return;
5166
+ for (const cardVideo of this.cardVideos.values()) cardVideo.resume();
5167
+ };
5168
+ this.requestUpdate();
4503
5169
  }
4504
5170
  /**
4505
5171
  * Where each Story is being watched: the cards on screen (not the hidden
@@ -4510,6 +5176,7 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4510
5176
  *viewTargets() {
4511
5177
  var _a13;
4512
5178
  const { stories } = this;
5179
+ if (this.mediaLoading) return;
4513
5180
  if (!this.player.isExpanded) {
4514
5181
  for (const [card, { key, index }] of this.carousel.visibleCards()) {
4515
5182
  const story = stories[index];
@@ -4567,6 +5234,7 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4567
5234
  openPlayer({ productOpen = false } = {}) {
4568
5235
  var _a13;
4569
5236
  if (this.player.isOpen) return;
5237
+ this.cartQuantities.clear();
4570
5238
  (_a13 = this.activeVideo) == null ? void 0 : _a13.pause();
4571
5239
  void this.player.open({ productOpen });
4572
5240
  }
@@ -4589,14 +5257,28 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4589
5257
  }
4590
5258
  get labels() {
4591
5259
  var _a13;
4592
- const { locale, labelAddToCart = "", labelViewProduct = "" } = this;
4593
- const key = JSON.stringify([locale, labelAddToCart, labelViewProduct]);
5260
+ const {
5261
+ locale,
5262
+ labelAddToCart = "",
5263
+ labelViewProduct = "",
5264
+ labelUnavailable = "",
5265
+ labelSoldOut = ""
5266
+ } = this;
5267
+ const key = JSON.stringify([
5268
+ locale,
5269
+ labelAddToCart,
5270
+ labelViewProduct,
5271
+ labelUnavailable,
5272
+ labelSoldOut
5273
+ ]);
4594
5274
  if (((_a13 = this.labelSet) == null ? void 0 : _a13.key) !== key) {
4595
5275
  this.labelSet = {
4596
5276
  key,
4597
5277
  labels: labelsFor(locale, {
4598
5278
  addToCart: labelAddToCart,
4599
- viewProduct: labelViewProduct
5279
+ viewProduct: labelViewProduct,
5280
+ unavailable: labelUnavailable,
5281
+ soldOut: labelSoldOut
4600
5282
  })
4601
5283
  };
4602
5284
  }
@@ -4620,7 +5302,23 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4620
5302
  const { stories } = this;
4621
5303
  const index = this.carousel.active;
4622
5304
  const active = stories[index];
4623
- if (!active) return A;
5305
+ if (!active && !this.requesting) return A;
5306
+ const loading = this.requesting || this.mediaLoading;
5307
+ return T`
5308
+ <div
5309
+ class="root"
5310
+ ?data-loading=${loading}
5311
+ ?data-requesting=${this.requesting}
5312
+ >
5313
+ ${active ? this.carousel.render(stories, this.renderSlide, this.labels) : A}
5314
+ ${renderCarouselSkeleton({ done: !loading })}
5315
+ </div>
5316
+ ${active ? this.renderPlayer(active) : A}
5317
+ `;
5318
+ }
5319
+ renderPlayer(active) {
5320
+ const { stories } = this;
5321
+ const index = this.carousel.active;
4624
5322
  const neighbors = neighborOffsets(stories.length, index).map((offset) => {
4625
5323
  const neighbor = (index + offset + stories.length) % stories.length;
4626
5324
  return {
@@ -4629,19 +5327,52 @@ var VtexAdsStoryCarouselElement = class extends i3 {
4629
5327
  label: this.labels.position(this.labels.show, neighbor, stories.length)
4630
5328
  };
4631
5329
  });
4632
- return T`
4633
- <div class="root">
4634
- ${this.carousel.render(stories, this.renderSlide, this.labels)}
4635
- </div>
4636
- ${this.player.render(active, {
5330
+ const product = this.productOf(active);
5331
+ return this.player.render(active, {
4637
5332
  labels: this.labels,
4638
5333
  navigation: stories.length > 1,
4639
5334
  neighbors,
4640
- product: this.productOf(active),
5335
+ product,
4641
5336
  cta: toCardCta(active),
5337
+ productActions: this.cartActionsFor(product),
4642
5338
  onPress: () => this.events.click(active)
4643
- })}
4644
- `;
5339
+ });
5340
+ }
5341
+ cartActionsFor(product) {
5342
+ const sku = product == null ? void 0 : product.sku;
5343
+ if (!sku) return void 0;
5344
+ const item = { sku, seller: product.seller };
5345
+ return {
5346
+ cartQuantity: this.cartQuantities.get(cartKey(item)),
5347
+ onAddToCart: () => this.changeCart(item, 1),
5348
+ onRemoveFromCart: () => this.changeCart(item, -1)
5349
+ };
5350
+ }
5351
+ /**
5352
+ * Adds one of `item` to the stepper's count, or removes one, and tells the
5353
+ * store, which changes its cart: the element has none. When add to cart
5354
+ * and the stepper swap places, the focus moves to the one now shown.
5355
+ */
5356
+ changeCart(item, delta) {
5357
+ var _a13;
5358
+ const key = cartKey(item);
5359
+ const before = (_a13 = this.cartQuantities.get(key)) != null ? _a13 : 0;
5360
+ const after = Math.max(0, before + delta);
5361
+ if (after === before) return;
5362
+ if (after > 0) this.cartQuantities.set(key, after);
5363
+ else this.cartQuantities.delete(key);
5364
+ this.requestUpdate();
5365
+ this.dispatchEvent(
5366
+ delta > 0 ? addToCartEvent(item) : removeFromCartEvent(item)
5367
+ );
5368
+ let swapped;
5369
+ if (before === 0) swapped = "stepper";
5370
+ else if (after === 0) swapped = "add";
5371
+ if (!swapped) return;
5372
+ const action = swapped;
5373
+ this.updateComplete.then(
5374
+ () => this.shadowRoot && focusCartAction(this.shadowRoot, action)
5375
+ );
4645
5376
  }
4646
5377
  };
4647
5378
  VtexAdsStoryCarouselElement.properties = {
@@ -4656,15 +5387,20 @@ VtexAdsStoryCarouselElement.properties = {
4656
5387
  currency: {},
4657
5388
  labelAddToCart: { attribute: "label-add-to-cart" },
4658
5389
  labelViewProduct: { attribute: "label-view-product" },
5390
+ labelUnavailable: { attribute: "label-unavailable" },
5391
+ labelSoldOut: { attribute: "label-sold-out" },
4659
5392
  hydration: { converter: hydrationConverter },
4660
5393
  hydrationTimeout: { type: Number, attribute: "hydration-timeout" },
5394
+ slideDuration: { type: Number, attribute: "slide-duration" },
4661
5395
  inactiveAutoplay: {
4662
5396
  type: Boolean,
4663
5397
  attribute: "inactive-autoplay",
4664
5398
  converter: booleanConverter
4665
5399
  },
4666
5400
  stories: { state: true },
4667
- products: { state: true }
5401
+ products: { state: true },
5402
+ requesting: { state: true },
5403
+ mediaLoading: { state: true }
4668
5404
  };
4669
5405
  VtexAdsStoryCarouselElement.styles = [
4670
5406
  i`
@@ -4672,11 +5408,16 @@ VtexAdsStoryCarouselElement.styles = [
4672
5408
  display: block;
4673
5409
  font-family: var(--vtex-ads-story-font-family, inherit);
4674
5410
  color: var(--vtex-ads-story-color-text, inherit);
5411
+ --_pill-radius: var(--vtex-ads-story-radius, 16px);
5412
+ --_pill-inset: 8px;
5413
+ --_button-radius: var(--vtex-ads-story-radius, 999px);
4675
5414
  }
4676
5415
  `,
4677
5416
  cardStyles,
5417
+ mediaStyles,
4678
5418
  productStyles,
4679
5419
  carouselStyles,
5420
+ carouselSkeletonStyles,
4680
5421
  playerStyles
4681
5422
  ];
4682
5423
  function defineVtexAdsStoryCarousel() {
@@ -4686,6 +5427,8 @@ function defineVtexAdsStoryCarousel() {
4686
5427
  }
4687
5428
  // Annotate the CommonJS export names for ESM import in node:
4688
5429
  0 && (module.exports = {
5430
+ ADD_TO_CART_EVENT,
5431
+ REMOVE_FROM_CART_EVENT,
4689
5432
  TAG_NAME,
4690
5433
  VtexAdsStoryCarouselElement,
4691
5434
  defineVtexAdsStoryCarousel