@vtex/ads-stories 0.4.1 → 0.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 (60) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +44 -88
  3. package/dist/cdn/vtex-ads-stories.js +1313 -74
  4. package/dist/cdn/vtex-ads-stories.js.map +1 -1
  5. package/dist/cjs/index.cjs +3744 -513
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/index.d.cts +46 -15
  8. package/dist/cjs/react.cjs.map +1 -1
  9. package/dist/cjs/react.d.cts +51 -5
  10. package/dist/cjs/story-DAiAN9v-.d.cts +260 -0
  11. package/dist/esm/index.d.ts +46 -15
  12. package/dist/esm/index.js +3348 -217
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/react.d.ts +51 -5
  15. package/dist/esm/story-DAiAN9v-.d.ts +260 -0
  16. package/package.json +18 -4
  17. package/src/cdn.ts +7 -3
  18. package/src/commerce-events.ts +93 -0
  19. package/src/components/card/card.ts +79 -14
  20. package/src/components/carousel/carousel-skeleton.ts +113 -0
  21. package/src/components/carousel/carousel.ts +715 -0
  22. package/src/components/carousel/index.ts +22 -0
  23. package/src/components/events/events-controller.ts +222 -0
  24. package/src/components/events/index.ts +6 -0
  25. package/src/components/icons/assets/caret-left-bold.svg +1 -0
  26. package/src/components/icons/assets/caret-right-bold.svg +1 -0
  27. package/src/components/icons/assets/caret-up-bold.svg +1 -0
  28. package/src/components/icons/assets/minus.svg +1 -0
  29. package/src/components/icons/assets/plus.svg +1 -0
  30. package/src/components/icons/assets/trash.svg +1 -0
  31. package/src/components/icons/assets/warning-circle-fill.svg +1 -0
  32. package/src/components/icons/index.ts +14 -0
  33. package/src/components/media/index.ts +8 -1
  34. package/src/components/media/media.styles.ts +113 -0
  35. package/src/components/media/media.ts +124 -23
  36. package/src/components/media/video-controller.ts +127 -6
  37. package/src/components/player/index.ts +6 -2
  38. package/src/components/player/player.ts +824 -50
  39. package/src/components/product/cta.ts +56 -0
  40. package/src/components/product/index.ts +22 -0
  41. package/src/components/product/price.ts +86 -0
  42. package/src/components/product/product.styles.ts +426 -0
  43. package/src/components/product/product.ts +336 -0
  44. package/src/index.ts +17 -1
  45. package/src/locales/en.ts +39 -0
  46. package/src/locales/es.ts +40 -0
  47. package/src/locales/index.ts +36 -0
  48. package/src/locales/pt.ts +39 -0
  49. package/src/locales/types.ts +44 -0
  50. package/src/react.ts +55 -7
  51. package/src/story/index.ts +5 -1
  52. package/src/story/story.ts +679 -49
  53. package/src/tag-name.ts +1 -0
  54. package/src/types.ts +8 -12
  55. package/src/utils/fetch-story.ts +113 -0
  56. package/src/utils/hydrate-products.ts +112 -0
  57. package/src/utils/media-ready.ts +58 -0
  58. package/src/utils/safe-url.ts +36 -0
  59. package/src/utils/send-event.ts +71 -0
  60. package/src/utils/with-timeout.ts +43 -0
@@ -0,0 +1,113 @@
1
+ import { css, html } from "lit";
2
+ import { styleMap } from "lit/directives/style-map.js";
3
+ import { STAGE_HEIGHT, VISIBLE_SIDE } from "./carousel";
4
+
5
+ /**
6
+ * While the covers and product photos load, the carousel is hidden under a
7
+ * skeleton of the same layout, which then fades out. The skeleton's slides
8
+ * have their own class, so they never count as the carousel's.
9
+ */
10
+ export const carouselSkeletonStyles = css`
11
+ .root {
12
+ position: relative;
13
+ }
14
+
15
+ .root[data-requesting] {
16
+ height: ${STAGE_HEIGHT};
17
+ }
18
+
19
+ .root[data-loading] .carousel {
20
+ visibility: hidden;
21
+ }
22
+
23
+ .skeleton {
24
+ position: absolute;
25
+ inset: 0;
26
+ z-index: 2;
27
+ box-sizing: border-box;
28
+ overflow: hidden;
29
+ pointer-events: none;
30
+ transition:
31
+ opacity 0.3s ease,
32
+ visibility 0s;
33
+ }
34
+
35
+ .skeleton[data-done] {
36
+ opacity: 0;
37
+ visibility: hidden;
38
+ transition:
39
+ opacity 0.3s ease,
40
+ visibility 0s 0.3s;
41
+ }
42
+
43
+ .skeleton-slide {
44
+ position: absolute;
45
+ top: 0;
46
+ left: 50%;
47
+ width: calc(${STAGE_HEIGHT} * 9 / 16);
48
+ height: 100%;
49
+ margin-left: calc(${STAGE_HEIGHT} * 9 / -32);
50
+ transform: translateX(calc(var(--place) * (100% + 8px))) scale(0.9);
51
+ }
52
+
53
+ .skeleton-slide[data-active] {
54
+ transform: none;
55
+ }
56
+
57
+ .skeleton-card {
58
+ width: 100%;
59
+ height: 100%;
60
+ border-radius: var(--vtex-ads-story-radius, 20px);
61
+ background: #ececec;
62
+ animation: skeleton-pulse 1.2s ease-in-out infinite alternate;
63
+ }
64
+
65
+ .skeleton[data-done] .skeleton-card {
66
+ animation: none;
67
+ }
68
+
69
+ @keyframes skeleton-pulse {
70
+ to {
71
+ background-color: #f6f6f6;
72
+ }
73
+ }
74
+
75
+ @media (prefers-reduced-motion: reduce) {
76
+ .skeleton,
77
+ .skeleton[data-done] {
78
+ transition: none;
79
+ }
80
+
81
+ .skeleton-card {
82
+ animation: none;
83
+ }
84
+ }
85
+ `;
86
+
87
+ /**
88
+ * Placeholder for the carousel while it loads.
89
+ * Decorative, so hidden from assistive technology. With `done`, it fades out
90
+ * and stays out of sight.
91
+ */
92
+ export function renderCarouselSkeleton({ done }: { done: boolean }) {
93
+ const places = Array.from(
94
+ { length: VISIBLE_SIDE * 2 + 1 },
95
+ (_, i) => i - VISIBLE_SIDE,
96
+ );
97
+
98
+ return html`
99
+ <div class="skeleton" aria-hidden="true" ?data-done=${done}>
100
+ ${places.map(
101
+ (place) => html`
102
+ <div
103
+ class="skeleton-slide"
104
+ ?data-active=${place === 0}
105
+ style=${styleMap({ "--place": String(place) })}
106
+ >
107
+ <div class="skeleton-card"></div>
108
+ </div>
109
+ `,
110
+ )}
111
+ </div>
112
+ `;
113
+ }