@vtex/ads-stories 0.5.0 → 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.
- package/CHANGELOG.md +27 -0
- package/README.md +29 -297
- package/dist/cdn/vtex-ads-stories.js +438 -113
- package/dist/cdn/vtex-ads-stories.js.map +1 -1
- package/dist/cjs/index.cjs +909 -186
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +42 -196
- package/dist/cjs/react.cjs.map +1 -1
- package/dist/cjs/react.d.cts +7 -1
- package/dist/cjs/story-DAiAN9v-.d.cts +260 -0
- package/dist/esm/index.d.ts +42 -196
- package/dist/esm/index.js +933 -209
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react.d.ts +7 -1
- package/dist/esm/story-DAiAN9v-.d.ts +260 -0
- package/package.json +1 -1
- package/src/commerce-events.ts +93 -0
- package/src/components/card/card.ts +16 -3
- package/src/components/carousel/carousel-skeleton.ts +113 -0
- package/src/components/carousel/carousel.ts +53 -8
- package/src/components/carousel/index.ts +7 -0
- package/src/components/events/events-controller.ts +23 -13
- package/src/components/icons/assets/minus.svg +1 -0
- package/src/components/icons/assets/plus.svg +1 -0
- package/src/components/icons/assets/trash.svg +1 -0
- package/src/components/icons/assets/warning-circle-fill.svg +1 -0
- package/src/components/icons/index.ts +8 -0
- package/src/components/media/index.ts +7 -1
- package/src/components/media/media.styles.ts +113 -0
- package/src/components/media/media.ts +108 -11
- package/src/components/media/video-controller.ts +80 -6
- package/src/components/player/player.ts +42 -17
- package/src/components/product/cta.ts +3 -3
- package/src/components/product/index.ts +2 -0
- package/src/components/product/product.styles.ts +63 -6
- package/src/components/product/product.ts +130 -29
- package/src/index.ts +8 -0
- package/src/locales/en.ts +13 -3
- package/src/locales/es.ts +13 -3
- package/src/locales/pt.ts +13 -3
- package/src/locales/types.ts +22 -2
- package/src/react.ts +6 -0
- package/src/story/story.ts +188 -16
- package/src/utils/hydrate-products.ts +30 -6
- package/src/utils/media-ready.ts +58 -0
- package/src/utils/safe-url.ts +36 -0
- package/src/utils/send-event.ts +1 -1
- package/src/utils/http-url.ts +0 -12
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/story/story.ts
|
|
2
|
-
import { css as
|
|
2
|
+
import { css as css7, html as html8, LitElement, nothing as nothing5 } from "lit";
|
|
3
3
|
|
|
4
4
|
// src/components/card/card.ts
|
|
5
|
-
import { css as
|
|
5
|
+
import { css as css3, html as html4, nothing as nothing3 } from "lit";
|
|
6
6
|
import { ref as ref2 } from "lit/directives/ref.js";
|
|
7
7
|
|
|
8
8
|
// src/components/icons/index.ts
|
|
@@ -28,30 +28,46 @@ var collapse_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256
|
|
|
28
28
|
// raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/expand.svg
|
|
29
29
|
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';
|
|
30
30
|
|
|
31
|
+
// raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/minus.svg
|
|
32
|
+
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>';
|
|
33
|
+
|
|
31
34
|
// raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/pause-fill.svg
|
|
32
35
|
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';
|
|
33
36
|
|
|
34
37
|
// raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/play-fill.svg
|
|
35
38
|
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';
|
|
36
39
|
|
|
40
|
+
// raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/plus.svg
|
|
41
|
+
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>';
|
|
42
|
+
|
|
37
43
|
// raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/speaker-x-fill.svg
|
|
38
44
|
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';
|
|
39
45
|
|
|
40
46
|
// raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/speaker-high-fill.svg
|
|
41
47
|
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';
|
|
42
48
|
|
|
49
|
+
// raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/trash.svg
|
|
50
|
+
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>';
|
|
51
|
+
|
|
52
|
+
// raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/warning-circle-fill.svg
|
|
53
|
+
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';
|
|
54
|
+
|
|
43
55
|
// src/components/icons/index.ts
|
|
44
56
|
var icons = {
|
|
45
57
|
caretUp: caret_up_bold_default,
|
|
46
58
|
close: close_default,
|
|
47
59
|
collapse: collapse_default,
|
|
48
60
|
expand: expand_default,
|
|
61
|
+
minus: minus_default,
|
|
49
62
|
next: caret_right_bold_default,
|
|
50
63
|
pause: pause_fill_default,
|
|
51
64
|
play: play_fill_default,
|
|
65
|
+
plus: plus_default,
|
|
52
66
|
previous: caret_left_bold_default,
|
|
53
67
|
soundOff: speaker_x_fill_default,
|
|
54
|
-
soundOn: speaker_high_fill_default
|
|
68
|
+
soundOn: speaker_high_fill_default,
|
|
69
|
+
trash: trash_default,
|
|
70
|
+
warning: warning_circle_fill_default
|
|
55
71
|
};
|
|
56
72
|
var markup = Object.fromEntries(
|
|
57
73
|
Object.entries(icons).map(([name, svg]) => [
|
|
@@ -70,7 +86,138 @@ function icon(name) {
|
|
|
70
86
|
import { html, nothing } from "lit";
|
|
71
87
|
import { ref } from "lit/directives/ref.js";
|
|
72
88
|
|
|
73
|
-
// src/
|
|
89
|
+
// src/locales/en.ts
|
|
90
|
+
var en = {
|
|
91
|
+
watch: "Watch video",
|
|
92
|
+
show: "Show video",
|
|
93
|
+
carousel: "Videos",
|
|
94
|
+
carouselRole: "carousel",
|
|
95
|
+
previous: "Previous video",
|
|
96
|
+
next: "Next video",
|
|
97
|
+
player: "Video",
|
|
98
|
+
expand: "Expand video",
|
|
99
|
+
collapse: "Collapse video",
|
|
100
|
+
close: "Close video",
|
|
101
|
+
play: "Play video",
|
|
102
|
+
pause: "Pause video",
|
|
103
|
+
soundOn: "Turn sound on",
|
|
104
|
+
soundOff: "Turn sound off",
|
|
105
|
+
addToCart: "Add to cart",
|
|
106
|
+
cartQuantity: "Quantity in cart",
|
|
107
|
+
decreaseQuantity: "Decrease quantity",
|
|
108
|
+
removeFromCart: "Remove from cart",
|
|
109
|
+
increaseQuantity: "Increase quantity",
|
|
110
|
+
unavailable: "Product unavailable",
|
|
111
|
+
soldOut: "Sold out",
|
|
112
|
+
viewProduct: "View product",
|
|
113
|
+
videoUnavailable: "Video unavailable",
|
|
114
|
+
videoFailed: "Couldn't load the video",
|
|
115
|
+
retry: "Try again",
|
|
116
|
+
videoLoading: "Loading video",
|
|
117
|
+
product: (name, price, listPrice, soldOut) => {
|
|
118
|
+
let text = name;
|
|
119
|
+
if (price && listPrice) text = `${name}, was ${listPrice}, now ${price}`;
|
|
120
|
+
else if (price) text = `${name}, ${price}`;
|
|
121
|
+
return soldOut ? `${text}, ${soldOut}` : text;
|
|
122
|
+
},
|
|
123
|
+
position: (label, index, count) => count > 1 ? `${label} ${index + 1} of ${count}` : label
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// src/locales/es.ts
|
|
127
|
+
var es = {
|
|
128
|
+
watch: "Ver video",
|
|
129
|
+
show: "Mostrar video",
|
|
130
|
+
carousel: "Videos",
|
|
131
|
+
carouselRole: "carrusel",
|
|
132
|
+
previous: "Video anterior",
|
|
133
|
+
next: "Video siguiente",
|
|
134
|
+
player: "Video",
|
|
135
|
+
expand: "Ampliar video",
|
|
136
|
+
collapse: "Reducir video",
|
|
137
|
+
close: "Cerrar video",
|
|
138
|
+
play: "Reproducir video",
|
|
139
|
+
pause: "Pausar video",
|
|
140
|
+
soundOn: "Activar sonido",
|
|
141
|
+
soundOff: "Desactivar sonido",
|
|
142
|
+
addToCart: "Agregar al carrito",
|
|
143
|
+
cartQuantity: "Cantidad en el carrito",
|
|
144
|
+
decreaseQuantity: "Disminuir cantidad",
|
|
145
|
+
removeFromCart: "Quitar del carrito",
|
|
146
|
+
increaseQuantity: "Aumentar cantidad",
|
|
147
|
+
unavailable: "Producto no disponible",
|
|
148
|
+
soldOut: "Agotado",
|
|
149
|
+
viewProduct: "Ver producto",
|
|
150
|
+
videoUnavailable: "Video no disponible",
|
|
151
|
+
videoFailed: "No se pudo cargar el video",
|
|
152
|
+
retry: "Intentar de nuevo",
|
|
153
|
+
videoLoading: "Cargando video",
|
|
154
|
+
product: (name, price, listPrice, soldOut) => {
|
|
155
|
+
let text = name;
|
|
156
|
+
if (price && listPrice)
|
|
157
|
+
text = `${name}, antes ${listPrice}, ahora ${price}`;
|
|
158
|
+
else if (price) text = `${name}, ${price}`;
|
|
159
|
+
return soldOut ? `${text}, ${soldOut}` : text;
|
|
160
|
+
},
|
|
161
|
+
position: (label, index, count) => count > 1 ? `${label} ${index + 1} de ${count}` : label
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/locales/pt.ts
|
|
165
|
+
var pt = {
|
|
166
|
+
watch: "Assistir v\xEDdeo",
|
|
167
|
+
show: "Mostrar v\xEDdeo",
|
|
168
|
+
carousel: "V\xEDdeos",
|
|
169
|
+
carouselRole: "carrossel",
|
|
170
|
+
previous: "V\xEDdeo anterior",
|
|
171
|
+
next: "Pr\xF3ximo v\xEDdeo",
|
|
172
|
+
player: "V\xEDdeo",
|
|
173
|
+
expand: "Expandir v\xEDdeo",
|
|
174
|
+
collapse: "Reduzir v\xEDdeo",
|
|
175
|
+
close: "Fechar v\xEDdeo",
|
|
176
|
+
play: "Reproduzir v\xEDdeo",
|
|
177
|
+
pause: "Pausar v\xEDdeo",
|
|
178
|
+
soundOn: "Ativar som",
|
|
179
|
+
soundOff: "Desativar som",
|
|
180
|
+
addToCart: "Adicionar ao carrinho",
|
|
181
|
+
cartQuantity: "Quantidade no carrinho",
|
|
182
|
+
decreaseQuantity: "Diminuir quantidade",
|
|
183
|
+
removeFromCart: "Remover do carrinho",
|
|
184
|
+
increaseQuantity: "Aumentar quantidade",
|
|
185
|
+
unavailable: "Produto indispon\xEDvel",
|
|
186
|
+
soldOut: "Esgotado",
|
|
187
|
+
viewProduct: "Ver produto",
|
|
188
|
+
videoUnavailable: "V\xEDdeo indispon\xEDvel",
|
|
189
|
+
videoFailed: "N\xE3o foi poss\xEDvel carregar o v\xEDdeo",
|
|
190
|
+
retry: "Tentar de novo",
|
|
191
|
+
videoLoading: "Carregando v\xEDdeo",
|
|
192
|
+
product: (name, price, listPrice, soldOut) => {
|
|
193
|
+
let text = name;
|
|
194
|
+
if (price && listPrice) text = `${name}, de ${listPrice} por ${price}`;
|
|
195
|
+
else if (price) text = `${name}, ${price}`;
|
|
196
|
+
return soldOut ? `${text}, ${soldOut}` : text;
|
|
197
|
+
},
|
|
198
|
+
position: (label, index, count) => count > 1 ? `${label} ${index + 1} de ${count}` : label
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/locales/index.ts
|
|
202
|
+
var BY_LANGUAGE = /* @__PURE__ */ new Map([
|
|
203
|
+
["pt", pt],
|
|
204
|
+
["es", es],
|
|
205
|
+
["en", en]
|
|
206
|
+
]);
|
|
207
|
+
function labelsFor(locale, overrides = {}) {
|
|
208
|
+
var _a, _b, _c;
|
|
209
|
+
const language = locale.split("-")[0].toLowerCase();
|
|
210
|
+
const labels = (_a = BY_LANGUAGE.get(language)) != null ? _a : pt;
|
|
211
|
+
const addToCart = (_b = overrides.addToCart) == null ? void 0 : _b.trim();
|
|
212
|
+
const viewProduct = (_c = overrides.viewProduct) == null ? void 0 : _c.trim();
|
|
213
|
+
return {
|
|
214
|
+
...labels,
|
|
215
|
+
...addToCart && { addToCart },
|
|
216
|
+
...viewProduct && { viewProduct }
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/utils/safe-url.ts
|
|
74
221
|
function httpUrl(value) {
|
|
75
222
|
if (!value) return null;
|
|
76
223
|
try {
|
|
@@ -80,18 +227,82 @@ function httpUrl(value) {
|
|
|
80
227
|
return null;
|
|
81
228
|
}
|
|
82
229
|
}
|
|
230
|
+
var STORE_BASE = "https://store.invalid";
|
|
231
|
+
function storePath(value) {
|
|
232
|
+
try {
|
|
233
|
+
const url = new URL(value, STORE_BASE);
|
|
234
|
+
if (url.origin !== STORE_BASE || url.pathname.startsWith("//")) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
238
|
+
} catch (e) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function destinationUrl(value) {
|
|
243
|
+
if (!value) return null;
|
|
244
|
+
return value.startsWith("/") ? storePath(value) : httpUrl(value);
|
|
245
|
+
}
|
|
83
246
|
|
|
84
247
|
// src/components/media/media.ts
|
|
248
|
+
var REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
|
|
85
249
|
function prefersReducedMotion() {
|
|
86
250
|
var _a, _b;
|
|
87
|
-
return (_b = (_a = globalThis.matchMedia) == null ? void 0 : _a.call(globalThis,
|
|
251
|
+
return (_b = (_a = globalThis.matchMedia) == null ? void 0 : _a.call(globalThis, REDUCED_MOTION).matches) != null ? _b : false;
|
|
88
252
|
}
|
|
89
253
|
function hasVideo(story, video) {
|
|
90
|
-
return !video.failed && httpUrl(story.media_url) !== null;
|
|
254
|
+
return !video.failed && !video.retrying && httpUrl(story.media_url) !== null;
|
|
91
255
|
}
|
|
92
|
-
function
|
|
256
|
+
function renderFailed(labels, onRetry) {
|
|
257
|
+
const retry = (event) => {
|
|
258
|
+
event.stopPropagation();
|
|
259
|
+
onRetry == null ? void 0 : onRetry();
|
|
260
|
+
};
|
|
261
|
+
return html`
|
|
262
|
+
<div class="media-status" ?data-retry=${!!onRetry}>
|
|
263
|
+
<span class="media-status-text">
|
|
264
|
+
${icon("warning")}
|
|
265
|
+
${onRetry ? labels.videoFailed : labels.videoUnavailable}
|
|
266
|
+
</span>
|
|
267
|
+
${onRetry ? html`
|
|
268
|
+
<button type="button" class="media-retry" @click=${retry}>
|
|
269
|
+
${labels.retry}
|
|
270
|
+
</button>
|
|
271
|
+
` : nothing}
|
|
272
|
+
</div>
|
|
273
|
+
`;
|
|
274
|
+
}
|
|
275
|
+
function renderVideoLoading(labels) {
|
|
276
|
+
return html`
|
|
277
|
+
<div class="media-status">
|
|
278
|
+
<span class="media-status-text">
|
|
279
|
+
<span class="media-spinner" aria-hidden="true"></span>
|
|
280
|
+
${labels.videoLoading}
|
|
281
|
+
</span>
|
|
282
|
+
</div>
|
|
283
|
+
`;
|
|
284
|
+
}
|
|
285
|
+
function renderStatus(video, labels, onRetry) {
|
|
286
|
+
if (video.failed) return renderFailed(labels, onRetry);
|
|
287
|
+
if (video.retrying) return renderVideoLoading(labels);
|
|
288
|
+
return nothing;
|
|
289
|
+
}
|
|
290
|
+
function renderNotice(video, { labels = pt, onRetry, announce = true }) {
|
|
291
|
+
return html`
|
|
292
|
+
<div
|
|
293
|
+
class="media-notice"
|
|
294
|
+
role=${announce ? "status" : nothing}
|
|
295
|
+
aria-hidden=${announce ? nothing : "true"}
|
|
296
|
+
>
|
|
297
|
+
${renderStatus(video, labels, onRetry)}
|
|
298
|
+
</div>
|
|
299
|
+
`;
|
|
300
|
+
}
|
|
301
|
+
function renderMedia(story, video, options = {}) {
|
|
302
|
+
const { withVideo = true, loop = true, onEnded, autoplay = true } = options;
|
|
93
303
|
const posterUrl = httpUrl(story.poster_url);
|
|
94
304
|
const mediaUrl = withVideo ? httpUrl(story.media_url) : null;
|
|
305
|
+
const preload = autoplay ? "metadata" : "auto";
|
|
95
306
|
return html`
|
|
96
307
|
${posterUrl ? html`<img class="poster" alt="" src=${posterUrl} />` : nothing}
|
|
97
308
|
${mediaUrl && !video.failed ? html`
|
|
@@ -100,22 +311,138 @@ function renderMedia(story, video, { withVideo = true, loop = true, onEnded } =
|
|
|
100
311
|
muted
|
|
101
312
|
playsinline
|
|
102
313
|
?loop=${loop}
|
|
103
|
-
preload
|
|
314
|
+
preload=${preload}
|
|
104
315
|
.muted=${true}
|
|
105
|
-
?autoplay=${!prefersReducedMotion()}
|
|
316
|
+
?autoplay=${autoplay && !prefersReducedMotion()}
|
|
106
317
|
poster=${posterUrl != null ? posterUrl : nothing}
|
|
107
318
|
src=${mediaUrl}
|
|
108
319
|
${ref(video.ref)}
|
|
109
320
|
@play=${video.sync}
|
|
110
321
|
@pause=${video.sync}
|
|
111
322
|
@volumechange=${video.sync}
|
|
323
|
+
@loadeddata=${video.loaded}
|
|
112
324
|
@error=${video.fail}
|
|
113
325
|
@ended=${onEnded}
|
|
114
326
|
></video>
|
|
115
327
|
` : nothing}
|
|
328
|
+
${mediaUrl ? renderNotice(video, options) : nothing}
|
|
116
329
|
`;
|
|
117
330
|
}
|
|
118
331
|
|
|
332
|
+
// src/components/media/media.styles.ts
|
|
333
|
+
import { css } from "lit";
|
|
334
|
+
var mediaStyles = css`
|
|
335
|
+
/* The live region the notice shows in, over the cover. Empty until the
|
|
336
|
+
video can't load or is loading again. Clicks go through to the card. */
|
|
337
|
+
.media-notice {
|
|
338
|
+
position: absolute;
|
|
339
|
+
inset: 0;
|
|
340
|
+
pointer-events: none;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* The notice: a dimmed layer with the text in the middle. */
|
|
344
|
+
.media-status {
|
|
345
|
+
position: absolute;
|
|
346
|
+
inset: 0;
|
|
347
|
+
display: flex;
|
|
348
|
+
flex-direction: column;
|
|
349
|
+
gap: 12px;
|
|
350
|
+
align-items: center;
|
|
351
|
+
justify-content: center;
|
|
352
|
+
box-sizing: border-box;
|
|
353
|
+
padding: 16px;
|
|
354
|
+
background: rgba(0, 0, 0, 0.45);
|
|
355
|
+
color: #fff;
|
|
356
|
+
text-align: center;
|
|
357
|
+
pointer-events: none;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
.media-status > * {
|
|
361
|
+
animation: media-status-in 0.4s ease-out both;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.media-status-text {
|
|
365
|
+
display: flex;
|
|
366
|
+
flex-direction: column;
|
|
367
|
+
gap: 8px;
|
|
368
|
+
align-items: center;
|
|
369
|
+
max-width: 100%;
|
|
370
|
+
font-size: 14px;
|
|
371
|
+
font-weight: 600;
|
|
372
|
+
line-height: 1.3;
|
|
373
|
+
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
.media-status-text .icon {
|
|
377
|
+
width: 18px;
|
|
378
|
+
height: 18px;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
.media-status[data-retry] .media-status-text .icon {
|
|
382
|
+
width: 24px;
|
|
383
|
+
height: 24px;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.media-retry {
|
|
387
|
+
min-height: 36px;
|
|
388
|
+
padding: 0 16px;
|
|
389
|
+
border: 0;
|
|
390
|
+
border-radius: var(--_button-radius);
|
|
391
|
+
background: rgba(255, 255, 255, 0.15);
|
|
392
|
+
backdrop-filter: blur(4px);
|
|
393
|
+
box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.42);
|
|
394
|
+
color: #fff;
|
|
395
|
+
font: inherit;
|
|
396
|
+
font-size: 14px;
|
|
397
|
+
font-weight: 600;
|
|
398
|
+
cursor: pointer;
|
|
399
|
+
pointer-events: auto;
|
|
400
|
+
animation-delay: 0.06s;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.media-retry:focus-visible {
|
|
404
|
+
outline: 2px solid #fff;
|
|
405
|
+
outline-offset: 2px;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
@media (hover: hover) and (pointer: fine) {
|
|
409
|
+
.media-retry:hover {
|
|
410
|
+
background: rgba(255, 255, 255, 0.25);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/* It spins with reduced motion too: a still ring wouldn't read as
|
|
415
|
+
loading. */
|
|
416
|
+
.media-spinner {
|
|
417
|
+
width: 24px;
|
|
418
|
+
height: 24px;
|
|
419
|
+
box-sizing: border-box;
|
|
420
|
+
border: 2px solid rgba(255, 255, 255, 0.35);
|
|
421
|
+
border-top-color: #fff;
|
|
422
|
+
border-radius: 50%;
|
|
423
|
+
animation: media-spin 0.8s linear infinite;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
@keyframes media-status-in {
|
|
427
|
+
from {
|
|
428
|
+
opacity: 0;
|
|
429
|
+
transform: translateY(4px);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
@keyframes media-spin {
|
|
434
|
+
to {
|
|
435
|
+
transform: rotate(360deg);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
@media (prefers-reduced-motion: reduce) {
|
|
440
|
+
.media-status > :not(.media-spinner) {
|
|
441
|
+
animation: none;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
`;
|
|
445
|
+
|
|
119
446
|
// src/components/media/video-controller.ts
|
|
120
447
|
import { createRef } from "lit/directives/ref.js";
|
|
121
448
|
function playVideo(video) {
|
|
@@ -130,8 +457,7 @@ var VideoController = class {
|
|
|
130
457
|
this.paused = true;
|
|
131
458
|
// The video always starts muted: that is what browsers allow to autoplay.
|
|
132
459
|
this.muted = true;
|
|
133
|
-
|
|
134
|
-
this.failed = false;
|
|
460
|
+
this.status = "playable";
|
|
135
461
|
/** Listener for the video's play, pause and volumechange events. */
|
|
136
462
|
this.sync = () => {
|
|
137
463
|
const video = this.ref.value;
|
|
@@ -140,22 +466,78 @@ var VideoController = class {
|
|
|
140
466
|
this.muted = video.muted;
|
|
141
467
|
this.host.requestUpdate();
|
|
142
468
|
};
|
|
469
|
+
/** Listener for the video's loadeddata event. */
|
|
470
|
+
this.loaded = () => {
|
|
471
|
+
this.settleReady(true);
|
|
472
|
+
if (!this.retrying) return;
|
|
473
|
+
this.status = "playable";
|
|
474
|
+
this.host.requestUpdate();
|
|
475
|
+
};
|
|
143
476
|
/** Listener for the video's error event. */
|
|
144
477
|
this.fail = () => {
|
|
145
|
-
this.
|
|
478
|
+
this.status = "failed";
|
|
479
|
+
this.settleReady(false);
|
|
146
480
|
this.host.requestUpdate();
|
|
147
481
|
};
|
|
482
|
+
this.waitForReady();
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Resolves true once the video's first frame has loaded, or false if it
|
|
486
|
+
* fails. A new one for each new <video> (see reset).
|
|
487
|
+
*/
|
|
488
|
+
get ready() {
|
|
489
|
+
return this.readyState;
|
|
490
|
+
}
|
|
491
|
+
/** The video could not load: the cover shows with a notice over it. */
|
|
492
|
+
get failed() {
|
|
493
|
+
return this.status === "failed";
|
|
494
|
+
}
|
|
495
|
+
/** A failed video is loading again (see retry), until it loads or fails. */
|
|
496
|
+
get retrying() {
|
|
497
|
+
return this.status === "retrying";
|
|
148
498
|
}
|
|
149
499
|
/** The rendered <video> is on the page and playing. */
|
|
150
500
|
get playing() {
|
|
151
501
|
const video = this.ref.value;
|
|
152
502
|
return !!video && video.isConnected && !video.paused;
|
|
153
503
|
}
|
|
154
|
-
/**
|
|
504
|
+
/**
|
|
505
|
+
* For a new <video>, such as each time the player opens. A retry still
|
|
506
|
+
* loading resolves false.
|
|
507
|
+
*/
|
|
155
508
|
reset() {
|
|
509
|
+
this.cancelRetry();
|
|
156
510
|
this.paused = true;
|
|
157
511
|
this.muted = true;
|
|
158
|
-
this.
|
|
512
|
+
this.status = "playable";
|
|
513
|
+
this.waitForReady();
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* For the next Story's <video>: neither failed nor loading again (a retry
|
|
517
|
+
* still loading resolves false). Unlike reset, it keeps the playback and
|
|
518
|
+
* sound state.
|
|
519
|
+
*/
|
|
520
|
+
clearFailure() {
|
|
521
|
+
if (this.retrying) {
|
|
522
|
+
this.cancelRetry();
|
|
523
|
+
this.waitForReady();
|
|
524
|
+
}
|
|
525
|
+
this.status = "playable";
|
|
526
|
+
this.host.requestUpdate();
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Loads a failed video again: renderMedia renders a new <video> with a
|
|
530
|
+
* notice that it is loading, until it loads or fails. Resolves as `ready`
|
|
531
|
+
* does: false too if the video is replaced first (see reset and
|
|
532
|
+
* clearFailure), and at once for a video that didn't fail.
|
|
533
|
+
*/
|
|
534
|
+
retry() {
|
|
535
|
+
if (this.retrying) return this.ready;
|
|
536
|
+
if (!this.failed) return Promise.resolve(false);
|
|
537
|
+
this.reset();
|
|
538
|
+
this.status = "retrying";
|
|
539
|
+
this.host.requestUpdate();
|
|
540
|
+
return this.ready;
|
|
159
541
|
}
|
|
160
542
|
play() {
|
|
161
543
|
const video = this.ref.value;
|
|
@@ -215,6 +597,13 @@ var VideoController = class {
|
|
|
215
597
|
const video = this.ref.value;
|
|
216
598
|
if (video) video.muted = !video.muted;
|
|
217
599
|
}
|
|
600
|
+
// The video loading again is replaced: its retry resolves false.
|
|
601
|
+
cancelRetry() {
|
|
602
|
+
if (this.retrying) this.settleReady(false);
|
|
603
|
+
}
|
|
604
|
+
waitForReady() {
|
|
605
|
+
this.readyState = new Promise((settle) => this.settleReady = settle);
|
|
606
|
+
}
|
|
218
607
|
};
|
|
219
608
|
|
|
220
609
|
// src/components/product/product.ts
|
|
@@ -266,33 +655,31 @@ function priceFormatter(locale, currency) {
|
|
|
266
655
|
|
|
267
656
|
// src/components/product/product.ts
|
|
268
657
|
function toCardProduct(story, format, labels, fetched) {
|
|
269
|
-
var _a, _b, _c, _d;
|
|
658
|
+
var _a, _b, _c, _d, _e, _f;
|
|
270
659
|
const product = story.product;
|
|
271
660
|
const name = (_a = product == null ? void 0 : product.product_name) == null ? void 0 : _a.trim();
|
|
272
661
|
if (!product || !name) return void 0;
|
|
273
662
|
const base = {
|
|
274
663
|
name,
|
|
275
664
|
imageUrl: (_b = httpUrl(product.image_url)) != null ? _b : void 0,
|
|
276
|
-
url: (_c =
|
|
665
|
+
url: (_c = destinationUrl(story.destination_url)) != null ? _c : void 0,
|
|
666
|
+
sku: ((_d = product.product_sku) == null ? void 0 : _d.trim()) || void 0,
|
|
667
|
+
seller: ((_e = product.seller_id) == null ? void 0 : _e.trim()) || void 0
|
|
277
668
|
};
|
|
278
669
|
if (fetched === "loading") {
|
|
279
670
|
return { ...base, label: labels.product(name), isLoading: true };
|
|
280
671
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
label: labels.product(name, labels.soldOut),
|
|
285
|
-
soldOut: labels.soldOut
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
const amounts = (_d = fetched == null ? void 0 : fetched.price) != null ? _d : readProductPrice(product.product_metadata);
|
|
672
|
+
const soldOut = (fetched == null ? void 0 : fetched.available) === false ? labels.soldOut : void 0;
|
|
673
|
+
const shown = (amounts2) => soldOut && (amounts2 == null ? void 0 : amounts2.price) === 0 ? void 0 : amounts2;
|
|
674
|
+
const amounts = (_f = shown(fetched == null ? void 0 : fetched.price)) != null ? _f : shown(readProductPrice(product.product_metadata));
|
|
289
675
|
const price = amounts && format(amounts.price);
|
|
290
676
|
const listPrice = (amounts == null ? void 0 : amounts.listPrice) === void 0 ? void 0 : format(amounts.listPrice);
|
|
291
677
|
return {
|
|
292
678
|
...base,
|
|
293
679
|
price,
|
|
294
680
|
listPrice,
|
|
295
|
-
|
|
681
|
+
soldOut,
|
|
682
|
+
label: labels.product(name, price, listPrice, soldOut)
|
|
296
683
|
};
|
|
297
684
|
}
|
|
298
685
|
var priceSkeleton = html2`
|
|
@@ -309,10 +696,9 @@ var addToCartSkeleton = html2`
|
|
|
309
696
|
`;
|
|
310
697
|
function renderPrice({ isLoading, soldOut, price, listPrice }) {
|
|
311
698
|
if (isLoading) return priceSkeleton;
|
|
312
|
-
if (
|
|
313
|
-
return html2`<span class="product-price product-sold-out">${soldOut}</span
|
|
699
|
+
if (!price) {
|
|
700
|
+
return soldOut ? html2`<span class="product-price product-sold-out">${soldOut}</span>` : nothing2;
|
|
314
701
|
}
|
|
315
|
-
if (!price) return nothing2;
|
|
316
702
|
return html2`
|
|
317
703
|
<span class="product-price">
|
|
318
704
|
<span>${price}</span>
|
|
@@ -341,7 +727,48 @@ function renderProduct(product, onSelect) {
|
|
|
341
727
|
</button>
|
|
342
728
|
`;
|
|
343
729
|
}
|
|
344
|
-
|
|
730
|
+
var STEPPER_ADD_CLASS = "product-stepper-add";
|
|
731
|
+
var ADD_TO_CART_CLASS = "product-add-to-cart";
|
|
732
|
+
function focusCartAction(root, action) {
|
|
733
|
+
var _a;
|
|
734
|
+
const className = action === "stepper" ? STEPPER_ADD_CLASS : ADD_TO_CART_CLASS;
|
|
735
|
+
(_a = root.querySelector(`.${className}`)) == null ? void 0 : _a.focus();
|
|
736
|
+
}
|
|
737
|
+
function renderStepper(quantity, {
|
|
738
|
+
labels,
|
|
739
|
+
onAddToCart,
|
|
740
|
+
onRemoveFromCart
|
|
741
|
+
}) {
|
|
742
|
+
const last = quantity === 1;
|
|
743
|
+
return html2`
|
|
744
|
+
<div
|
|
745
|
+
class="product-action product-stepper"
|
|
746
|
+
role="group"
|
|
747
|
+
aria-label=${labels.cartQuantity}
|
|
748
|
+
>
|
|
749
|
+
<button
|
|
750
|
+
type="button"
|
|
751
|
+
class="product-stepper-button product-stepper-remove"
|
|
752
|
+
aria-label=${last ? labels.removeFromCart : labels.decreaseQuantity}
|
|
753
|
+
@click=${onRemoveFromCart}
|
|
754
|
+
>
|
|
755
|
+
${icon(last ? "trash" : "minus")}
|
|
756
|
+
</button>
|
|
757
|
+
<span class="product-quantity">${quantity}</span>
|
|
758
|
+
<button
|
|
759
|
+
type="button"
|
|
760
|
+
class="product-stepper-button ${STEPPER_ADD_CLASS}"
|
|
761
|
+
aria-label=${labels.increaseQuantity}
|
|
762
|
+
@click=${onAddToCart}
|
|
763
|
+
>
|
|
764
|
+
${icon("plus")}
|
|
765
|
+
</button>
|
|
766
|
+
</div>
|
|
767
|
+
`;
|
|
768
|
+
}
|
|
769
|
+
function renderAddToCart({ isLoading, soldOut, sku }, options) {
|
|
770
|
+
const { labels, onAddToCart, cartQuantity = 0 } = options;
|
|
771
|
+
if (!sku || !onAddToCart) return nothing2;
|
|
345
772
|
if (isLoading) return addToCartSkeleton;
|
|
346
773
|
if (soldOut) {
|
|
347
774
|
return html2`
|
|
@@ -350,12 +777,25 @@ function renderAddToCart({ isLoading, soldOut }, { labels }) {
|
|
|
350
777
|
</button>
|
|
351
778
|
`;
|
|
352
779
|
}
|
|
780
|
+
if (cartQuantity > 0) return renderStepper(cartQuantity, options);
|
|
353
781
|
return html2`
|
|
354
|
-
<button
|
|
782
|
+
<button
|
|
783
|
+
type="button"
|
|
784
|
+
class="product-action ${ADD_TO_CART_CLASS}"
|
|
785
|
+
@click=${onAddToCart}
|
|
786
|
+
>
|
|
355
787
|
${labels.addToCart}
|
|
356
788
|
</button>
|
|
357
789
|
`;
|
|
358
790
|
}
|
|
791
|
+
function renderCartStatus({ sku }, { labels, cartQuantity = 0, onAddToCart }) {
|
|
792
|
+
if (!sku || !onAddToCart) return nothing2;
|
|
793
|
+
return html2`
|
|
794
|
+
<span class="product-cart-status" role="status">
|
|
795
|
+
${cartQuantity > 0 ? `${labels.cartQuantity}: ${cartQuantity}` : ""}
|
|
796
|
+
</span>
|
|
797
|
+
`;
|
|
798
|
+
}
|
|
359
799
|
function renderExpandableProduct(product, options) {
|
|
360
800
|
const { open } = options;
|
|
361
801
|
return html2`
|
|
@@ -373,6 +813,7 @@ function renderExpandableProduct(product, options) {
|
|
|
373
813
|
</button>
|
|
374
814
|
<div id=${options.panelId} class="product-panel" ?inert=${!open}>
|
|
375
815
|
<div class="product-actions">
|
|
816
|
+
${renderCartStatus(product, options)}
|
|
376
817
|
${renderAddToCart(product, options)}
|
|
377
818
|
${product.url ? html2`
|
|
378
819
|
<a
|
|
@@ -396,7 +837,7 @@ function toCardCta(story) {
|
|
|
396
837
|
var _a;
|
|
397
838
|
if (story.product) return void 0;
|
|
398
839
|
const label = (_a = story.call_to_action) == null ? void 0 : _a.trim();
|
|
399
|
-
const url =
|
|
840
|
+
const url = destinationUrl(story.destination_url);
|
|
400
841
|
return label && url ? { label, url } : void 0;
|
|
401
842
|
}
|
|
402
843
|
function renderCta(cta, onSelect) {
|
|
@@ -419,8 +860,8 @@ function renderCta(cta, onSelect) {
|
|
|
419
860
|
}
|
|
420
861
|
|
|
421
862
|
// src/components/product/product.styles.ts
|
|
422
|
-
import { css } from "lit";
|
|
423
|
-
var productStyles =
|
|
863
|
+
import { css as css2 } from "lit";
|
|
864
|
+
var productStyles = css2`
|
|
424
865
|
/* A glass pill at the bottom of the card, above its button: the product or
|
|
425
866
|
the call to action. */
|
|
426
867
|
.card-product,
|
|
@@ -434,9 +875,9 @@ var productStyles = css`
|
|
|
434
875
|
gap: 8px;
|
|
435
876
|
align-items: center;
|
|
436
877
|
box-sizing: border-box;
|
|
437
|
-
padding:
|
|
878
|
+
padding: var(--_pill-inset);
|
|
438
879
|
border: 0;
|
|
439
|
-
border-radius:
|
|
880
|
+
border-radius: var(--_pill-radius);
|
|
440
881
|
background: rgba(255, 255, 255, 0.15);
|
|
441
882
|
backdrop-filter: blur(5px);
|
|
442
883
|
color: #fff;
|
|
@@ -531,7 +972,7 @@ var productStyles = css`
|
|
|
531
972
|
align-items: center;
|
|
532
973
|
box-sizing: border-box;
|
|
533
974
|
width: 100%;
|
|
534
|
-
padding:
|
|
975
|
+
padding: var(--_pill-inset);
|
|
535
976
|
border: 0;
|
|
536
977
|
border-radius: inherit;
|
|
537
978
|
background: transparent;
|
|
@@ -594,7 +1035,7 @@ var productStyles = css`
|
|
|
594
1035
|
height: 48px;
|
|
595
1036
|
padding: 0 16px;
|
|
596
1037
|
border: 1px solid var(--vtex-ads-story-color-accent, #1b75a8);
|
|
597
|
-
border-radius:
|
|
1038
|
+
border-radius: var(--_button-radius);
|
|
598
1039
|
font: inherit;
|
|
599
1040
|
font-size: 14px;
|
|
600
1041
|
font-weight: 700;
|
|
@@ -621,6 +1062,62 @@ var productStyles = css`
|
|
|
621
1062
|
);
|
|
622
1063
|
}
|
|
623
1064
|
|
|
1065
|
+
/* In the cart: the add to cart button's pill, with minus and plus at its
|
|
1066
|
+
ends and the quantity between them. */
|
|
1067
|
+
.product-stepper {
|
|
1068
|
+
justify-content: space-between;
|
|
1069
|
+
padding: 0;
|
|
1070
|
+
background: var(--vtex-ads-story-color-accent, #1b75a8);
|
|
1071
|
+
color: var(--vtex-ads-story-color-accent-contrast, #fff);
|
|
1072
|
+
cursor: auto;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
.product-stepper-button {
|
|
1076
|
+
display: grid;
|
|
1077
|
+
flex: none;
|
|
1078
|
+
place-items: center;
|
|
1079
|
+
width: 46px;
|
|
1080
|
+
height: 46px;
|
|
1081
|
+
padding: 0;
|
|
1082
|
+
border: 0;
|
|
1083
|
+
border-radius: var(--_button-radius);
|
|
1084
|
+
background: transparent;
|
|
1085
|
+
color: inherit;
|
|
1086
|
+
cursor: pointer;
|
|
1087
|
+
transition: background-color 0.2s ease;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
.product-stepper-button .icon {
|
|
1091
|
+
width: 18px;
|
|
1092
|
+
height: 18px;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
.product-stepper-button:hover {
|
|
1096
|
+
background: rgba(0, 0, 0, 0.15);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
.product-stepper-button:focus-visible {
|
|
1100
|
+
outline: 2px solid var(--vtex-ads-story-color-accent-contrast, #fff);
|
|
1101
|
+
outline-offset: -4px;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
.product-quantity {
|
|
1105
|
+
flex: 1;
|
|
1106
|
+
min-width: 0;
|
|
1107
|
+
font-size: 16px;
|
|
1108
|
+
text-align: center;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
.product-cart-status {
|
|
1112
|
+
position: absolute;
|
|
1113
|
+
width: 1px;
|
|
1114
|
+
height: 1px;
|
|
1115
|
+
margin: -1px;
|
|
1116
|
+
overflow: hidden;
|
|
1117
|
+
clip-path: inset(50%);
|
|
1118
|
+
white-space: nowrap;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
624
1121
|
/* Sold out: add to cart, disabled and grayed. */
|
|
625
1122
|
.product-unavailable {
|
|
626
1123
|
border-color: transparent;
|
|
@@ -710,11 +1207,12 @@ var productStyles = css`
|
|
|
710
1207
|
}
|
|
711
1208
|
}
|
|
712
1209
|
|
|
1210
|
+
/* Its corners follow the pill's, one inset in from them: 8px by default. */
|
|
713
1211
|
.product-image {
|
|
714
1212
|
flex: none;
|
|
715
1213
|
width: 60px;
|
|
716
1214
|
height: 60px;
|
|
717
|
-
border-radius:
|
|
1215
|
+
border-radius: max(0px, var(--_pill-radius) - var(--_pill-inset));
|
|
718
1216
|
background: #fff;
|
|
719
1217
|
object-fit: contain;
|
|
720
1218
|
}
|
|
@@ -778,7 +1276,7 @@ var productStyles = css`
|
|
|
778
1276
|
.product-add-to-cart-loading {
|
|
779
1277
|
display: block;
|
|
780
1278
|
height: 48px;
|
|
781
|
-
border-radius:
|
|
1279
|
+
border-radius: var(--_button-radius);
|
|
782
1280
|
}
|
|
783
1281
|
|
|
784
1282
|
@media (prefers-reduced-motion: reduce) {
|
|
@@ -789,7 +1287,7 @@ var productStyles = css`
|
|
|
789
1287
|
`;
|
|
790
1288
|
|
|
791
1289
|
// src/components/card/card.ts
|
|
792
|
-
var cardStyles =
|
|
1290
|
+
var cardStyles = css3`
|
|
793
1291
|
/* 9:16 at the height its container gives it (--card-height, default
|
|
794
1292
|
500px). */
|
|
795
1293
|
.card {
|
|
@@ -922,7 +1420,12 @@ function renderCard(story, video, options) {
|
|
|
922
1420
|
return (_a2 = options.onPress) == null ? void 0 : _a2.call(options);
|
|
923
1421
|
}, capture: true }}
|
|
924
1422
|
>
|
|
925
|
-
${renderMedia(story, video, {
|
|
1423
|
+
${renderMedia(story, video, {
|
|
1424
|
+
withVideo,
|
|
1425
|
+
autoplay: options.autoplay,
|
|
1426
|
+
labels: options.labels,
|
|
1427
|
+
announce: false
|
|
1428
|
+
})}
|
|
926
1429
|
<button
|
|
927
1430
|
type="button"
|
|
928
1431
|
class="card-open"
|
|
@@ -930,7 +1433,7 @@ function renderCard(story, video, options) {
|
|
|
930
1433
|
aria-label=${options.label}
|
|
931
1434
|
@click=${options.onSelect}
|
|
932
1435
|
>
|
|
933
|
-
|
|
1436
|
+
${withVideo && video.failed ? nothing3 : html4`<span class="play" aria-hidden="true">${icon("play")}</span>`}
|
|
934
1437
|
</button>
|
|
935
1438
|
${withVideo && hasVideo(story, video) && !video.paused ? renderSoundButton(video, options) : nothing3}
|
|
936
1439
|
${options.product ? renderProduct(
|
|
@@ -944,19 +1447,30 @@ function renderCard(story, video, options) {
|
|
|
944
1447
|
|
|
945
1448
|
// src/components/carousel/carousel.ts
|
|
946
1449
|
import {
|
|
947
|
-
css as
|
|
1450
|
+
css as css4,
|
|
948
1451
|
html as html5
|
|
949
1452
|
} from "lit";
|
|
950
1453
|
import { repeat } from "lit/directives/repeat.js";
|
|
951
1454
|
import { styleMap } from "lit/directives/style-map.js";
|
|
952
|
-
var STAGE_HEIGHT =
|
|
953
|
-
var SOLO_PADDING =
|
|
1455
|
+
var STAGE_HEIGHT = css4`500px`;
|
|
1456
|
+
var SOLO_PADDING = css4`24px`;
|
|
954
1457
|
var AUTO_ADVANCE_MS = 5e3;
|
|
1458
|
+
var MIN_SLIDE_DURATION_MS = 2e3;
|
|
1459
|
+
var MAX_SLIDE_DURATION_MS = 12e4;
|
|
1460
|
+
var toSlideDuration = (ms) => {
|
|
1461
|
+
if (ms === void 0 || !Number.isFinite(ms) || ms < 0) {
|
|
1462
|
+
return AUTO_ADVANCE_MS;
|
|
1463
|
+
}
|
|
1464
|
+
if (ms === 0) {
|
|
1465
|
+
return 0;
|
|
1466
|
+
}
|
|
1467
|
+
return Math.min(Math.max(ms, MIN_SLIDE_DURATION_MS), MAX_SLIDE_DURATION_MS);
|
|
1468
|
+
};
|
|
955
1469
|
var SWIPE_DISTANCE = 40;
|
|
956
|
-
var NARROW_SCREEN =
|
|
1470
|
+
var NARROW_SCREEN = css4`(max-width: 576px)`;
|
|
957
1471
|
var VISIBLE_SIDE = 2;
|
|
958
1472
|
var RENDERED_SIDE = VISIBLE_SIDE + 3;
|
|
959
|
-
var carouselStyles =
|
|
1473
|
+
var carouselStyles = css4`
|
|
960
1474
|
.carousel {
|
|
961
1475
|
position: relative;
|
|
962
1476
|
box-sizing: border-box;
|
|
@@ -1134,9 +1648,12 @@ var CarouselController = class {
|
|
|
1134
1648
|
this.distance = 1;
|
|
1135
1649
|
this.count = 0;
|
|
1136
1650
|
this.narrow = false;
|
|
1651
|
+
this.reducedMotion = false;
|
|
1137
1652
|
this.connected = false;
|
|
1138
1653
|
this.hovered = false;
|
|
1139
1654
|
this.focused = false;
|
|
1655
|
+
/** The interval the running timer was started with. */
|
|
1656
|
+
this.timerMs = 0;
|
|
1140
1657
|
/** The rendered cards, as their cardRef reported them. */
|
|
1141
1658
|
this.cards = /* @__PURE__ */ new Map();
|
|
1142
1659
|
/** The rendered cards' focus targets, as their focusRef reported them. */
|
|
@@ -1235,11 +1752,12 @@ var CarouselController = class {
|
|
|
1235
1752
|
}
|
|
1236
1753
|
}
|
|
1237
1754
|
hostConnected() {
|
|
1238
|
-
var _a, _b, _c, _d;
|
|
1755
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1239
1756
|
this.connected = true;
|
|
1240
1757
|
this.media = (_a = globalThis.matchMedia) == null ? void 0 : _a.call(globalThis, NARROW_SCREEN.toString());
|
|
1241
1758
|
(_b = this.media) == null ? void 0 : _b.addEventListener("change", this.onMediaChange);
|
|
1242
1759
|
this.narrow = (_d = (_c = this.media) == null ? void 0 : _c.matches) != null ? _d : false;
|
|
1760
|
+
this.reducedMotion = (_g = (_f = (_e = this.options).reducedMotion) == null ? void 0 : _f.call(_e)) != null ? _g : false;
|
|
1243
1761
|
this.syncTimer();
|
|
1244
1762
|
}
|
|
1245
1763
|
hostDisconnected() {
|
|
@@ -1250,8 +1768,8 @@ var CarouselController = class {
|
|
|
1250
1768
|
this.endSwipe();
|
|
1251
1769
|
this.syncTimer();
|
|
1252
1770
|
}
|
|
1253
|
-
// Whatever the host changed (the player opening, new Stories
|
|
1254
|
-
// stop the automatic advance.
|
|
1771
|
+
// Whatever the host changed (the player opening, new Stories, the slide
|
|
1772
|
+
// duration) may start, stop or restart the automatic advance.
|
|
1255
1773
|
hostUpdated() {
|
|
1256
1774
|
this.syncTimer();
|
|
1257
1775
|
}
|
|
@@ -1280,13 +1798,20 @@ var CarouselController = class {
|
|
|
1280
1798
|
(_d = (_c = this.options).onStep) == null ? void 0 : _d.call(_c, from, this.activeKey);
|
|
1281
1799
|
this.restartTimer();
|
|
1282
1800
|
}
|
|
1801
|
+
get slideDuration() {
|
|
1802
|
+
var _a, _b;
|
|
1803
|
+
return toSlideDuration((_b = (_a = this.options).slideDuration) == null ? void 0 : _b.call(_a));
|
|
1804
|
+
}
|
|
1283
1805
|
get shouldAdvance() {
|
|
1284
1806
|
var _a, _b;
|
|
1285
|
-
return this.connected && this.count > 1 && !this.hovered && !this.focused && !((_b = (_a = this.options).locked) == null ? void 0 : _b.call(_a));
|
|
1807
|
+
return this.slideDuration > 0 && !this.reducedMotion && this.connected && this.count > 1 && !this.hovered && !this.focused && !((_b = (_a = this.options).locked) == null ? void 0 : _b.call(_a));
|
|
1286
1808
|
}
|
|
1287
1809
|
syncTimer() {
|
|
1810
|
+
const ms = this.slideDuration;
|
|
1811
|
+
if (this.timer && this.timerMs !== ms) this.stopTimer();
|
|
1288
1812
|
if (this.shouldAdvance && !this.timer) {
|
|
1289
|
-
this.
|
|
1813
|
+
this.timerMs = ms;
|
|
1814
|
+
this.timer = setInterval(() => this.step(1), ms);
|
|
1290
1815
|
} else if (!this.shouldAdvance && this.timer) {
|
|
1291
1816
|
this.stopTimer();
|
|
1292
1817
|
}
|
|
@@ -1294,6 +1819,7 @@ var CarouselController = class {
|
|
|
1294
1819
|
stopTimer() {
|
|
1295
1820
|
clearInterval(this.timer);
|
|
1296
1821
|
this.timer = void 0;
|
|
1822
|
+
this.timerMs = 0;
|
|
1297
1823
|
}
|
|
1298
1824
|
restartTimer() {
|
|
1299
1825
|
this.stopTimer();
|
|
@@ -1448,6 +1974,107 @@ var CarouselController = class {
|
|
|
1448
1974
|
}
|
|
1449
1975
|
};
|
|
1450
1976
|
|
|
1977
|
+
// src/components/carousel/carousel-skeleton.ts
|
|
1978
|
+
import { css as css5, html as html6 } from "lit";
|
|
1979
|
+
import { styleMap as styleMap2 } from "lit/directives/style-map.js";
|
|
1980
|
+
var carouselSkeletonStyles = css5`
|
|
1981
|
+
.root {
|
|
1982
|
+
position: relative;
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
.root[data-requesting] {
|
|
1986
|
+
height: ${STAGE_HEIGHT};
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
.root[data-loading] .carousel {
|
|
1990
|
+
visibility: hidden;
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
.skeleton {
|
|
1994
|
+
position: absolute;
|
|
1995
|
+
inset: 0;
|
|
1996
|
+
z-index: 2;
|
|
1997
|
+
box-sizing: border-box;
|
|
1998
|
+
overflow: hidden;
|
|
1999
|
+
pointer-events: none;
|
|
2000
|
+
transition:
|
|
2001
|
+
opacity 0.3s ease,
|
|
2002
|
+
visibility 0s;
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
.skeleton[data-done] {
|
|
2006
|
+
opacity: 0;
|
|
2007
|
+
visibility: hidden;
|
|
2008
|
+
transition:
|
|
2009
|
+
opacity 0.3s ease,
|
|
2010
|
+
visibility 0s 0.3s;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
.skeleton-slide {
|
|
2014
|
+
position: absolute;
|
|
2015
|
+
top: 0;
|
|
2016
|
+
left: 50%;
|
|
2017
|
+
width: calc(${STAGE_HEIGHT} * 9 / 16);
|
|
2018
|
+
height: 100%;
|
|
2019
|
+
margin-left: calc(${STAGE_HEIGHT} * 9 / -32);
|
|
2020
|
+
transform: translateX(calc(var(--place) * (100% + 8px))) scale(0.9);
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
.skeleton-slide[data-active] {
|
|
2024
|
+
transform: none;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
.skeleton-card {
|
|
2028
|
+
width: 100%;
|
|
2029
|
+
height: 100%;
|
|
2030
|
+
border-radius: var(--vtex-ads-story-radius, 20px);
|
|
2031
|
+
background: #ececec;
|
|
2032
|
+
animation: skeleton-pulse 1.2s ease-in-out infinite alternate;
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
.skeleton[data-done] .skeleton-card {
|
|
2036
|
+
animation: none;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
@keyframes skeleton-pulse {
|
|
2040
|
+
to {
|
|
2041
|
+
background-color: #f6f6f6;
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2046
|
+
.skeleton,
|
|
2047
|
+
.skeleton[data-done] {
|
|
2048
|
+
transition: none;
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
.skeleton-card {
|
|
2052
|
+
animation: none;
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
`;
|
|
2056
|
+
function renderCarouselSkeleton({ done }) {
|
|
2057
|
+
const places = Array.from(
|
|
2058
|
+
{ length: VISIBLE_SIDE * 2 + 1 },
|
|
2059
|
+
(_, i) => i - VISIBLE_SIDE
|
|
2060
|
+
);
|
|
2061
|
+
return html6`
|
|
2062
|
+
<div class="skeleton" aria-hidden="true" ?data-done=${done}>
|
|
2063
|
+
${places.map(
|
|
2064
|
+
(place) => html6`
|
|
2065
|
+
<div
|
|
2066
|
+
class="skeleton-slide"
|
|
2067
|
+
?data-active=${place === 0}
|
|
2068
|
+
style=${styleMap2({ "--place": String(place) })}
|
|
2069
|
+
>
|
|
2070
|
+
<div class="skeleton-card"></div>
|
|
2071
|
+
</div>
|
|
2072
|
+
`
|
|
2073
|
+
)}
|
|
2074
|
+
</div>
|
|
2075
|
+
`;
|
|
2076
|
+
}
|
|
2077
|
+
|
|
1451
2078
|
// src/tag-name.ts
|
|
1452
2079
|
var TAG_NAME = "vtex-ads-story-carousel";
|
|
1453
2080
|
|
|
@@ -1503,6 +2130,7 @@ var StoryEventsController = class {
|
|
|
1503
2130
|
click: /* @__PURE__ */ new Set()
|
|
1504
2131
|
};
|
|
1505
2132
|
this.pendingImpressions = [];
|
|
2133
|
+
this.connected = false;
|
|
1506
2134
|
this.watched = /* @__PURE__ */ new Map();
|
|
1507
2135
|
this.onIntersect = (entries) => {
|
|
1508
2136
|
for (const entry of entries) {
|
|
@@ -1525,6 +2153,7 @@ var StoryEventsController = class {
|
|
|
1525
2153
|
}
|
|
1526
2154
|
hostConnected() {
|
|
1527
2155
|
var _a;
|
|
2156
|
+
this.connected = true;
|
|
1528
2157
|
if (typeof IntersectionObserver === "function") {
|
|
1529
2158
|
this.observer = new IntersectionObserver(this.onIntersect, {
|
|
1530
2159
|
threshold: VIEW_THRESHOLD
|
|
@@ -1534,10 +2163,15 @@ var StoryEventsController = class {
|
|
|
1534
2163
|
"visibilitychange",
|
|
1535
2164
|
this.onVisibilityChange
|
|
1536
2165
|
);
|
|
1537
|
-
this.host.updateComplete.then(() =>
|
|
2166
|
+
this.host.updateComplete.then(() => {
|
|
2167
|
+
if (!this.connected) return;
|
|
2168
|
+
this.sendImpressions();
|
|
2169
|
+
this.syncViewTargets();
|
|
2170
|
+
});
|
|
1538
2171
|
}
|
|
1539
2172
|
hostDisconnected() {
|
|
1540
2173
|
var _a, _b;
|
|
2174
|
+
this.connected = false;
|
|
1541
2175
|
(_a = globalThis.document) == null ? void 0 : _a.removeEventListener(
|
|
1542
2176
|
"visibilitychange",
|
|
1543
2177
|
this.onVisibilityChange
|
|
@@ -1546,24 +2180,26 @@ var StoryEventsController = class {
|
|
|
1546
2180
|
this.observer = void 0;
|
|
1547
2181
|
for (const watched of this.watched.values()) clearTimeout(watched.timer);
|
|
1548
2182
|
this.watched.clear();
|
|
1549
|
-
this.pendingImpressions = [];
|
|
1550
2183
|
}
|
|
1551
2184
|
hostUpdated() {
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
this.pendingImpressions = [];
|
|
1555
|
-
for (const story of stories) this.send("impression", story);
|
|
1556
|
-
}
|
|
2185
|
+
if (!this.connected) return;
|
|
2186
|
+
this.sendImpressions();
|
|
1557
2187
|
this.syncViewTargets();
|
|
1558
2188
|
}
|
|
1559
2189
|
/**
|
|
1560
|
-
* The Stories the host
|
|
1561
|
-
* render is done,
|
|
1562
|
-
* has
|
|
2190
|
+
* The Stories the host shows next: their impressions go out once that
|
|
2191
|
+
* render is done, on the page, with a session (or after the first render
|
|
2192
|
+
* that has both). Replaces Stories passed before and not sent yet.
|
|
1563
2193
|
*/
|
|
1564
2194
|
impress(stories) {
|
|
1565
2195
|
this.pendingImpressions = stories;
|
|
1566
2196
|
}
|
|
2197
|
+
sendImpressions() {
|
|
2198
|
+
const stories = this.pendingImpressions;
|
|
2199
|
+
if (!stories.length || !this.options.identity().sessionId) return;
|
|
2200
|
+
this.pendingImpressions = [];
|
|
2201
|
+
for (const story of stories) this.send("impression", story);
|
|
2202
|
+
}
|
|
1567
2203
|
/** A touch on the Story: its click goes out, the first time only. */
|
|
1568
2204
|
click(story) {
|
|
1569
2205
|
this.send("click", story);
|
|
@@ -1630,13 +2266,13 @@ var StoryEventsController = class {
|
|
|
1630
2266
|
};
|
|
1631
2267
|
|
|
1632
2268
|
// src/components/player/player.ts
|
|
1633
|
-
import { css as
|
|
2269
|
+
import { css as css6, html as html7, nothing as nothing4 } from "lit";
|
|
1634
2270
|
import { createRef as createRef2, ref as ref3 } from "lit/directives/ref.js";
|
|
1635
2271
|
import { repeat as repeat2 } from "lit/directives/repeat.js";
|
|
1636
|
-
import { styleMap as
|
|
2272
|
+
import { styleMap as styleMap3 } from "lit/directives/style-map.js";
|
|
1637
2273
|
var NEAR_GAP = 72;
|
|
1638
2274
|
var FAR_GAP = 48;
|
|
1639
|
-
var playerStyles =
|
|
2275
|
+
var playerStyles = css6`
|
|
1640
2276
|
.player {
|
|
1641
2277
|
position: fixed;
|
|
1642
2278
|
inset: auto 16px 16px auto;
|
|
@@ -1849,7 +2485,7 @@ var playerStyles = css4`
|
|
|
1849
2485
|
padding: 0;
|
|
1850
2486
|
overflow: hidden;
|
|
1851
2487
|
border: 0;
|
|
1852
|
-
border-radius: 16px;
|
|
2488
|
+
border-radius: var(--vtex-ads-story-radius, 16px);
|
|
1853
2489
|
background: #111;
|
|
1854
2490
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
|
|
1855
2491
|
cursor: pointer;
|
|
@@ -2177,6 +2813,18 @@ var PlayerController = class {
|
|
|
2177
2813
|
this.productOpen = !this.productOpen;
|
|
2178
2814
|
this.host.requestUpdate();
|
|
2179
2815
|
};
|
|
2816
|
+
/**
|
|
2817
|
+
* Loads the failed video again and, once it loads, plays it with the sound
|
|
2818
|
+
* on (muted if the browser blocks it). Not if the player closed or stepped
|
|
2819
|
+
* meanwhile, even back to the same Story: the retry then resolves false.
|
|
2820
|
+
*/
|
|
2821
|
+
this.retryVideo = () => {
|
|
2822
|
+
var _a;
|
|
2823
|
+
(_a = this.dialog.value) == null ? void 0 : _a.focus();
|
|
2824
|
+
void this.video.retry().then((loaded) => {
|
|
2825
|
+
if (loaded) this.video.playWithSound();
|
|
2826
|
+
});
|
|
2827
|
+
};
|
|
2180
2828
|
/**
|
|
2181
2829
|
* A click on the video: closes the product panel when it is open, plays or
|
|
2182
2830
|
* pauses the video otherwise.
|
|
@@ -2200,7 +2848,8 @@ var PlayerController = class {
|
|
|
2200
2848
|
this.close();
|
|
2201
2849
|
}
|
|
2202
2850
|
/**
|
|
2203
|
-
* Opens the mini player, plays the video
|
|
2851
|
+
* Opens the mini player, plays the video with the sound on (muted if the
|
|
2852
|
+
* browser blocks it) and focuses the close button.
|
|
2204
2853
|
* With `productOpen`, the product panel shows open (the shopper chose the
|
|
2205
2854
|
* product).
|
|
2206
2855
|
*/
|
|
@@ -2220,7 +2869,7 @@ var PlayerController = class {
|
|
|
2220
2869
|
const dialog = this.dialog.value;
|
|
2221
2870
|
if (!this.isOpen || !dialog) return;
|
|
2222
2871
|
this.show(dialog);
|
|
2223
|
-
this.video.
|
|
2872
|
+
this.video.playWithSound();
|
|
2224
2873
|
(_a = this.closeButton.value) == null ? void 0 : _a.focus();
|
|
2225
2874
|
}
|
|
2226
2875
|
/** Hides the player now; the host removes it on its next update. */
|
|
@@ -2242,7 +2891,7 @@ var PlayerController = class {
|
|
|
2242
2891
|
async showNext(delta = 0) {
|
|
2243
2892
|
if (!this.isOpen) return;
|
|
2244
2893
|
const withSound = !this.video.muted;
|
|
2245
|
-
this.video.
|
|
2894
|
+
this.video.clearFailure();
|
|
2246
2895
|
this.productOpen = false;
|
|
2247
2896
|
this.host.requestUpdate();
|
|
2248
2897
|
await this.host.updateComplete;
|
|
@@ -2344,21 +2993,27 @@ var PlayerController = class {
|
|
|
2344
2993
|
* its actions, or the call to action of a link destination. Clicks on them
|
|
2345
2994
|
* don't reach the video.
|
|
2346
2995
|
*/
|
|
2347
|
-
renderDestination({
|
|
2996
|
+
renderDestination({
|
|
2997
|
+
product,
|
|
2998
|
+
cta,
|
|
2999
|
+
labels,
|
|
3000
|
+
productActions
|
|
3001
|
+
}) {
|
|
2348
3002
|
let content;
|
|
2349
3003
|
if (product) {
|
|
2350
3004
|
content = renderExpandableProduct(product, {
|
|
3005
|
+
...productActions,
|
|
3006
|
+
labels,
|
|
2351
3007
|
open: this.productOpen,
|
|
2352
3008
|
onToggle: this.toggleProduct,
|
|
2353
|
-
panelId: "player-product-panel"
|
|
2354
|
-
labels
|
|
3009
|
+
panelId: "player-product-panel"
|
|
2355
3010
|
});
|
|
2356
3011
|
} else if (cta) {
|
|
2357
3012
|
content = renderCta(cta);
|
|
2358
3013
|
} else {
|
|
2359
3014
|
return nothing4;
|
|
2360
3015
|
}
|
|
2361
|
-
return
|
|
3016
|
+
return html7`
|
|
2362
3017
|
<div
|
|
2363
3018
|
class="player-destination"
|
|
2364
3019
|
@click=${(event) => event.stopPropagation()}
|
|
@@ -2377,7 +3032,7 @@ var PlayerController = class {
|
|
|
2377
3032
|
event.stopPropagation();
|
|
2378
3033
|
video.toggleMuted();
|
|
2379
3034
|
};
|
|
2380
|
-
return
|
|
3035
|
+
return html7`
|
|
2381
3036
|
<button
|
|
2382
3037
|
type="button"
|
|
2383
3038
|
class="play player-toggle"
|
|
@@ -2406,7 +3061,7 @@ var PlayerController = class {
|
|
|
2406
3061
|
var _a;
|
|
2407
3062
|
return (_a = options.onStep) == null ? void 0 : _a.call(options, delta);
|
|
2408
3063
|
};
|
|
2409
|
-
return
|
|
3064
|
+
return html7`
|
|
2410
3065
|
<div class="player-controls player-nav">
|
|
2411
3066
|
<button
|
|
2412
3067
|
type="button"
|
|
@@ -2436,12 +3091,12 @@ var PlayerController = class {
|
|
|
2436
3091
|
({ offset, story, label }) => {
|
|
2437
3092
|
const poster = httpUrl(story.poster_url);
|
|
2438
3093
|
const side = Math.sign(offset);
|
|
2439
|
-
return
|
|
3094
|
+
return html7`
|
|
2440
3095
|
<button
|
|
2441
3096
|
type="button"
|
|
2442
3097
|
class="player-neighbor"
|
|
2443
3098
|
aria-label=${label != null ? label : labels.show}
|
|
2444
|
-
style=${
|
|
3099
|
+
style=${styleMap3({
|
|
2445
3100
|
"--side": String(side),
|
|
2446
3101
|
"--beyond": String(offset - side)
|
|
2447
3102
|
})}
|
|
@@ -2451,7 +3106,7 @@ var PlayerController = class {
|
|
|
2451
3106
|
return (_a = options.onStep) == null ? void 0 : _a.call(options, offset);
|
|
2452
3107
|
}}
|
|
2453
3108
|
>
|
|
2454
|
-
${poster ?
|
|
3109
|
+
${poster ? html7`<img alt="" src=${poster} />` : nothing4}
|
|
2455
3110
|
</button>
|
|
2456
3111
|
`;
|
|
2457
3112
|
}
|
|
@@ -2460,7 +3115,7 @@ var PlayerController = class {
|
|
|
2460
3115
|
/** Expand or collapse, and close: above the video, or at the top right. */
|
|
2461
3116
|
renderWindowControls(labels) {
|
|
2462
3117
|
const { options, expanded } = this;
|
|
2463
|
-
return
|
|
3118
|
+
return html7`
|
|
2464
3119
|
<div class="player-controls">
|
|
2465
3120
|
<button
|
|
2466
3121
|
type="button"
|
|
@@ -2490,14 +3145,16 @@ var PlayerController = class {
|
|
|
2490
3145
|
*/
|
|
2491
3146
|
renderVideo(story, advances, destination) {
|
|
2492
3147
|
const { video, options } = this;
|
|
2493
|
-
return
|
|
3148
|
+
return html7`
|
|
2494
3149
|
<div class="card" ${ref3(this.stageCardRef)} @click=${this.onVideoClick}>
|
|
2495
3150
|
${renderMedia(story, video, {
|
|
2496
3151
|
loop: !advances,
|
|
2497
3152
|
onEnded: advances ? () => {
|
|
2498
3153
|
var _a;
|
|
2499
3154
|
return (_a = options.onStep) == null ? void 0 : _a.call(options, 1);
|
|
2500
|
-
} : void 0
|
|
3155
|
+
} : void 0,
|
|
3156
|
+
labels: destination.labels,
|
|
3157
|
+
onRetry: this.retryVideo
|
|
2501
3158
|
})}
|
|
2502
3159
|
${hasVideo(story, video) ? this.renderVideoControls(destination.labels) : nothing4}
|
|
2503
3160
|
${this.renderDestination(destination)}
|
|
@@ -2528,26 +3185,25 @@ var PlayerController = class {
|
|
|
2528
3185
|
* The expanded view also shows the `neighbors` beside it.
|
|
2529
3186
|
*/
|
|
2530
3187
|
render(story, {
|
|
2531
|
-
labels,
|
|
2532
3188
|
navigation = false,
|
|
2533
3189
|
neighbors = [],
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
onPress
|
|
3190
|
+
onPress,
|
|
3191
|
+
...destination
|
|
2537
3192
|
}) {
|
|
3193
|
+
const { labels } = destination;
|
|
2538
3194
|
if (!this.isOpen) return nothing4;
|
|
2539
3195
|
const { video, expanded } = this;
|
|
2540
3196
|
const shownNeighbors = this.track(story, neighbors);
|
|
2541
3197
|
const pair = this.pairDirection !== 0;
|
|
2542
3198
|
this.navigation = navigation;
|
|
2543
|
-
return
|
|
3199
|
+
return html7`
|
|
2544
3200
|
<dialog
|
|
2545
3201
|
class="player"
|
|
2546
3202
|
popover="manual"
|
|
2547
3203
|
aria-label=${labels.player}
|
|
2548
3204
|
?data-expanded=${expanded}
|
|
2549
3205
|
?data-pair=${pair}
|
|
2550
|
-
style=${
|
|
3206
|
+
style=${styleMap3({
|
|
2551
3207
|
"--pair-dir": pair ? String(this.pairDirection) : void 0
|
|
2552
3208
|
})}
|
|
2553
3209
|
?data-switched=${this.switched}
|
|
@@ -2573,11 +3229,7 @@ var PlayerController = class {
|
|
|
2573
3229
|
}}
|
|
2574
3230
|
>
|
|
2575
3231
|
${navigation ? this.renderNavigation(labels) : nothing4}
|
|
2576
|
-
${this.renderVideo(story, navigation && expanded,
|
|
2577
|
-
product,
|
|
2578
|
-
cta,
|
|
2579
|
-
labels
|
|
2580
|
-
})}
|
|
3232
|
+
${this.renderVideo(story, navigation && expanded, destination)}
|
|
2581
3233
|
<span class="player-dim" aria-hidden="true" ${ref3(this.dim)}></span>
|
|
2582
3234
|
</div>
|
|
2583
3235
|
</div>
|
|
@@ -2628,6 +3280,12 @@ var intelligentSearchHydration = {
|
|
|
2628
3280
|
price: intelligentSearchPrice,
|
|
2629
3281
|
available: intelligentSearchAvailability
|
|
2630
3282
|
};
|
|
3283
|
+
function toShownPrice(value) {
|
|
3284
|
+
const isAmount = (amount) => typeof amount === "number" && Number.isFinite(amount) && amount >= 0;
|
|
3285
|
+
if (!isAmount(value == null ? void 0 : value.price)) return void 0;
|
|
3286
|
+
const { price, listPrice } = value;
|
|
3287
|
+
return isAmount(listPrice) && listPrice > price ? { price, listPrice } : { price };
|
|
3288
|
+
}
|
|
2631
3289
|
async function hydrateStoryProducts(placement, stories, hydration, identity, { signal, timeout } = {}) {
|
|
2632
3290
|
var _a, _b;
|
|
2633
3291
|
const products = /* @__PURE__ */ new Map();
|
|
@@ -2642,12 +3300,19 @@ async function hydrateStoryProducts(placement, stories, hydration, identity, { s
|
|
|
2642
3300
|
);
|
|
2643
3301
|
for (const { story, product, offer } of (_a = hydrated.stories[placement]) != null ? _a : []) {
|
|
2644
3302
|
if (!product || !offer) continue;
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
3303
|
+
try {
|
|
3304
|
+
const price = toShownPrice(hydration.price(product, offer));
|
|
3305
|
+
const available = (_b = hydration.available) == null ? void 0 : _b.call(hydration, product, offer);
|
|
3306
|
+
products.set(story.ad_id, {
|
|
3307
|
+
...price && { price },
|
|
3308
|
+
...available !== void 0 && { available }
|
|
3309
|
+
});
|
|
3310
|
+
} catch (error) {
|
|
3311
|
+
console.error(
|
|
3312
|
+
`[${TAG_NAME}] Product details failed for ad ${story.ad_id}`,
|
|
3313
|
+
error
|
|
3314
|
+
);
|
|
3315
|
+
}
|
|
2651
3316
|
}
|
|
2652
3317
|
} catch (error) {
|
|
2653
3318
|
if (!limit.signal.aborted) {
|
|
@@ -2710,105 +3375,57 @@ async function fetchStories({
|
|
|
2710
3375
|
}
|
|
2711
3376
|
}
|
|
2712
3377
|
|
|
2713
|
-
// src/
|
|
2714
|
-
var
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
player: "Video",
|
|
2749
|
-
expand: "Ampliar video",
|
|
2750
|
-
collapse: "Reducir video",
|
|
2751
|
-
close: "Cerrar video",
|
|
2752
|
-
play: "Reproducir video",
|
|
2753
|
-
pause: "Pausar video",
|
|
2754
|
-
soundOn: "Activar sonido",
|
|
2755
|
-
soundOff: "Desactivar sonido",
|
|
2756
|
-
addToCart: "Agregar al carrito",
|
|
2757
|
-
unavailable: "Producto no disponible",
|
|
2758
|
-
soldOut: "Agotado",
|
|
2759
|
-
viewProduct: "Ver producto",
|
|
2760
|
-
product: (name, price, listPrice) => {
|
|
2761
|
-
if (price && listPrice)
|
|
2762
|
-
return `${name}, antes ${listPrice}, ahora ${price}`;
|
|
2763
|
-
return price ? `${name}, ${price}` : name;
|
|
2764
|
-
},
|
|
2765
|
-
position: (label, index, count) => count > 1 ? `${label} ${index + 1} de ${count}` : label
|
|
2766
|
-
};
|
|
2767
|
-
|
|
2768
|
-
// src/locales/pt.ts
|
|
2769
|
-
var pt = {
|
|
2770
|
-
watch: "Assistir v\xEDdeo",
|
|
2771
|
-
show: "Mostrar v\xEDdeo",
|
|
2772
|
-
carousel: "V\xEDdeos",
|
|
2773
|
-
carouselRole: "carrossel",
|
|
2774
|
-
previous: "V\xEDdeo anterior",
|
|
2775
|
-
next: "Pr\xF3ximo v\xEDdeo",
|
|
2776
|
-
player: "V\xEDdeo",
|
|
2777
|
-
expand: "Expandir v\xEDdeo",
|
|
2778
|
-
collapse: "Reduzir v\xEDdeo",
|
|
2779
|
-
close: "Fechar v\xEDdeo",
|
|
2780
|
-
play: "Reproduzir v\xEDdeo",
|
|
2781
|
-
pause: "Pausar v\xEDdeo",
|
|
2782
|
-
soundOn: "Ativar som",
|
|
2783
|
-
soundOff: "Desativar som",
|
|
2784
|
-
addToCart: "Adicionar ao carrinho",
|
|
2785
|
-
unavailable: "Produto indispon\xEDvel",
|
|
2786
|
-
soldOut: "Esgotado",
|
|
2787
|
-
viewProduct: "Ver produto",
|
|
2788
|
-
product: (name, price, listPrice) => {
|
|
2789
|
-
if (price && listPrice) return `${name}, de ${listPrice} por ${price}`;
|
|
2790
|
-
return price ? `${name}, ${price}` : name;
|
|
2791
|
-
},
|
|
2792
|
-
position: (label, index, count) => count > 1 ? `${label} ${index + 1} de ${count}` : label
|
|
2793
|
-
};
|
|
3378
|
+
// src/utils/media-ready.ts
|
|
3379
|
+
var MEDIA_TIMEOUT = 3e3;
|
|
3380
|
+
function decodeImage(url) {
|
|
3381
|
+
if (typeof Image === "undefined") return Promise.resolve(true);
|
|
3382
|
+
const image = new Image();
|
|
3383
|
+
image.src = url;
|
|
3384
|
+
if (!image.decode) return Promise.resolve(true);
|
|
3385
|
+
return image.decode().then(
|
|
3386
|
+
() => true,
|
|
3387
|
+
() => false
|
|
3388
|
+
);
|
|
3389
|
+
}
|
|
3390
|
+
function firstReady(checks, signal) {
|
|
3391
|
+
if (!checks.length) return Promise.resolve();
|
|
3392
|
+
const limit = withTimeout(void 0, MEDIA_TIMEOUT, signal);
|
|
3393
|
+
return new Promise((resolve) => {
|
|
3394
|
+
const done = () => {
|
|
3395
|
+
limit.clear();
|
|
3396
|
+
resolve();
|
|
3397
|
+
};
|
|
3398
|
+
if (limit.signal.aborted) return done();
|
|
3399
|
+
limit.signal.addEventListener("abort", done, { once: true });
|
|
3400
|
+
let failed = 0;
|
|
3401
|
+
for (const check of checks) {
|
|
3402
|
+
check.then(
|
|
3403
|
+
(ready) => {
|
|
3404
|
+
if (ready || ++failed === checks.length) done();
|
|
3405
|
+
},
|
|
3406
|
+
() => {
|
|
3407
|
+
if (++failed === checks.length) done();
|
|
3408
|
+
}
|
|
3409
|
+
);
|
|
3410
|
+
}
|
|
3411
|
+
});
|
|
3412
|
+
}
|
|
2794
3413
|
|
|
2795
|
-
// src/
|
|
2796
|
-
var
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
...viewProduct && { viewProduct }
|
|
2811
|
-
};
|
|
3414
|
+
// src/commerce-events.ts
|
|
3415
|
+
var ADD_TO_CART_EVENT = "vtex-ads-story:add-to-cart";
|
|
3416
|
+
var REMOVE_FROM_CART_EVENT = "vtex-ads-story:remove-from-cart";
|
|
3417
|
+
function cartEvent(type, { sku, seller }, quantity) {
|
|
3418
|
+
return new CustomEvent(type, {
|
|
3419
|
+
detail: { sku, ...seller && { seller }, quantity },
|
|
3420
|
+
bubbles: true,
|
|
3421
|
+
composed: true
|
|
3422
|
+
});
|
|
3423
|
+
}
|
|
3424
|
+
function addToCartEvent(item, quantity = 1) {
|
|
3425
|
+
return cartEvent(ADD_TO_CART_EVENT, item, quantity);
|
|
3426
|
+
}
|
|
3427
|
+
function removeFromCartEvent(item, quantity = 1) {
|
|
3428
|
+
return cartEvent(REMOVE_FROM_CART_EVENT, item, quantity);
|
|
2812
3429
|
}
|
|
2813
3430
|
|
|
2814
3431
|
// src/story/story.ts
|
|
@@ -2833,9 +3450,17 @@ var channelConverter = {
|
|
|
2833
3450
|
var hydrationConverter = {
|
|
2834
3451
|
fromAttribute: (value) => value === "none" ? "none" : void 0
|
|
2835
3452
|
};
|
|
3453
|
+
var cartKey = ({ sku, seller }) => JSON.stringify([sku, seller != null ? seller : ""]);
|
|
2836
3454
|
var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
2837
3455
|
constructor() {
|
|
2838
3456
|
super();
|
|
3457
|
+
/**
|
|
3458
|
+
* How many of each SKU, from each seller (see cartKey), were added since
|
|
3459
|
+
* the player opened, for its stepper. It doesn't read the store's cart: it
|
|
3460
|
+
* counts the add and remove events sent, and starts over each time the
|
|
3461
|
+
* player opens, as the cart may have changed meanwhile.
|
|
3462
|
+
*/
|
|
3463
|
+
this.cartQuantities = /* @__PURE__ */ new Map();
|
|
2839
3464
|
/**
|
|
2840
3465
|
* One per rendered card, by its key (see Slide): a Story can show in more
|
|
2841
3466
|
* than one card, each with its own video.
|
|
@@ -2857,7 +3482,9 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
2857
3482
|
}
|
|
2858
3483
|
},
|
|
2859
3484
|
// The player shows the highlighted Story: the highlight stays on it.
|
|
2860
|
-
locked: () => this.player.isOpen
|
|
3485
|
+
locked: () => this.player.isOpen || this.mediaLoading,
|
|
3486
|
+
slideDuration: () => this.slideDuration,
|
|
3487
|
+
reducedMotion: prefersReducedMotion
|
|
2861
3488
|
});
|
|
2862
3489
|
this.player = new PlayerController(this, {
|
|
2863
3490
|
onStep: (delta) => this.stepInPlayer(delta),
|
|
@@ -2879,6 +3506,7 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
2879
3506
|
),
|
|
2880
3507
|
labels: this.labels,
|
|
2881
3508
|
withVideo: active || this.inactiveAutoplay && !hidden,
|
|
3509
|
+
autoplay: !this.mediaLoading,
|
|
2882
3510
|
product: this.productOf(story),
|
|
2883
3511
|
onSelect: active ? () => this.openPlayer() : () => this.carousel.step(offset),
|
|
2884
3512
|
// On a card without the highlight, the product moves it, as the card.
|
|
@@ -2893,6 +3521,8 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
2893
3521
|
});
|
|
2894
3522
|
this.inactiveAutoplay = false;
|
|
2895
3523
|
this.stories = [];
|
|
3524
|
+
this.requesting = false;
|
|
3525
|
+
this.mediaLoading = false;
|
|
2896
3526
|
}
|
|
2897
3527
|
// Lit keeps the card's DOM when the element is moved (removed and appended
|
|
2898
3528
|
// again), but the browser pauses a removed video and doesn't autoplay it
|
|
@@ -2908,9 +3538,10 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
2908
3538
|
}
|
|
2909
3539
|
// A request still pending when the element leaves the page is cancelled.
|
|
2910
3540
|
disconnectedCallback() {
|
|
2911
|
-
var _a;
|
|
3541
|
+
var _a, _b;
|
|
2912
3542
|
super.disconnectedCallback();
|
|
2913
3543
|
(_a = this.request) == null ? void 0 : _a.abort();
|
|
3544
|
+
(_b = this.mediaWait) == null ? void 0 : _b.abort();
|
|
2914
3545
|
}
|
|
2915
3546
|
willUpdate(changed) {
|
|
2916
3547
|
if (REQUEST_PROPERTIES.some((name) => changed.has(name))) {
|
|
@@ -2939,16 +3570,21 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
2939
3570
|
const request = new AbortController();
|
|
2940
3571
|
this.request = request;
|
|
2941
3572
|
this.player.close();
|
|
3573
|
+
this.requesting = false;
|
|
2942
3574
|
this.showStories([]);
|
|
2943
3575
|
if (!this.isConnected) {
|
|
2944
3576
|
request.abort();
|
|
2945
3577
|
return;
|
|
2946
3578
|
}
|
|
3579
|
+
this.requesting = Boolean(
|
|
3580
|
+
this.publisherId && this.sessionId && this.placement
|
|
3581
|
+
);
|
|
2947
3582
|
const stories = await fetchStories(this, {
|
|
2948
3583
|
signal: request.signal,
|
|
2949
3584
|
timeout: this.timeout
|
|
2950
3585
|
});
|
|
2951
3586
|
if (request.signal.aborted) return;
|
|
3587
|
+
this.requesting = false;
|
|
2952
3588
|
const hydration = this.activeHydration;
|
|
2953
3589
|
if (!hydration || !stories.some((story) => story.product)) {
|
|
2954
3590
|
this.request = void 0;
|
|
@@ -2982,7 +3618,34 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
2982
3618
|
this.afterRender = void 0;
|
|
2983
3619
|
this.carousel.reset(stories.length);
|
|
2984
3620
|
this.stories = stories;
|
|
3621
|
+
void this.waitForFirstMedia(stories);
|
|
3622
|
+
}
|
|
3623
|
+
/**
|
|
3624
|
+
* Shows the cards once the first Story's cover or video is ready: whichever
|
|
3625
|
+
* loads first, or once both failed. Only then are the Stories impressed
|
|
3626
|
+
* and do their videos play, from the start.
|
|
3627
|
+
*/
|
|
3628
|
+
async waitForFirstMedia(stories) {
|
|
3629
|
+
var _a, _b, _c;
|
|
3630
|
+
(_a = this.mediaWait) == null ? void 0 : _a.abort();
|
|
3631
|
+
const wait = new AbortController();
|
|
3632
|
+
this.mediaWait = wait;
|
|
3633
|
+
const cover = httpUrl((_b = stories[0]) == null ? void 0 : _b.poster_url);
|
|
3634
|
+
const video = httpUrl((_c = stories[0]) == null ? void 0 : _c.media_url);
|
|
3635
|
+
const checks = [];
|
|
3636
|
+
if (cover) checks.push(decodeImage(cover));
|
|
3637
|
+
if (video) checks.push(this.videoFor(this.carousel.activeKey).ready);
|
|
3638
|
+
this.mediaLoading = checks.length > 0;
|
|
3639
|
+
await firstReady(checks, wait.signal);
|
|
3640
|
+
if (this.mediaWait !== wait) return;
|
|
3641
|
+
this.mediaWait = void 0;
|
|
3642
|
+
this.mediaLoading = false;
|
|
2985
3643
|
this.events.impress(stories);
|
|
3644
|
+
this.afterRender = () => {
|
|
3645
|
+
if (!this.isConnected) return;
|
|
3646
|
+
for (const cardVideo of this.cardVideos.values()) cardVideo.resume();
|
|
3647
|
+
};
|
|
3648
|
+
this.requestUpdate();
|
|
2986
3649
|
}
|
|
2987
3650
|
/**
|
|
2988
3651
|
* Where each Story is being watched: the cards on screen (not the hidden
|
|
@@ -2993,6 +3656,7 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
2993
3656
|
*viewTargets() {
|
|
2994
3657
|
var _a;
|
|
2995
3658
|
const { stories } = this;
|
|
3659
|
+
if (this.mediaLoading) return;
|
|
2996
3660
|
if (!this.player.isExpanded) {
|
|
2997
3661
|
for (const [card, { key, index }] of this.carousel.visibleCards()) {
|
|
2998
3662
|
const story = stories[index];
|
|
@@ -3050,6 +3714,7 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
3050
3714
|
openPlayer({ productOpen = false } = {}) {
|
|
3051
3715
|
var _a;
|
|
3052
3716
|
if (this.player.isOpen) return;
|
|
3717
|
+
this.cartQuantities.clear();
|
|
3053
3718
|
(_a = this.activeVideo) == null ? void 0 : _a.pause();
|
|
3054
3719
|
void this.player.open({ productOpen });
|
|
3055
3720
|
}
|
|
@@ -3103,7 +3768,23 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
3103
3768
|
const { stories } = this;
|
|
3104
3769
|
const index = this.carousel.active;
|
|
3105
3770
|
const active = stories[index];
|
|
3106
|
-
if (!active) return nothing5;
|
|
3771
|
+
if (!active && !this.requesting) return nothing5;
|
|
3772
|
+
const loading = this.requesting || this.mediaLoading;
|
|
3773
|
+
return html8`
|
|
3774
|
+
<div
|
|
3775
|
+
class="root"
|
|
3776
|
+
?data-loading=${loading}
|
|
3777
|
+
?data-requesting=${this.requesting}
|
|
3778
|
+
>
|
|
3779
|
+
${active ? this.carousel.render(stories, this.renderSlide, this.labels) : nothing5}
|
|
3780
|
+
${renderCarouselSkeleton({ done: !loading })}
|
|
3781
|
+
</div>
|
|
3782
|
+
${active ? this.renderPlayer(active) : nothing5}
|
|
3783
|
+
`;
|
|
3784
|
+
}
|
|
3785
|
+
renderPlayer(active) {
|
|
3786
|
+
const { stories } = this;
|
|
3787
|
+
const index = this.carousel.active;
|
|
3107
3788
|
const neighbors = neighborOffsets(stories.length, index).map((offset) => {
|
|
3108
3789
|
const neighbor = (index + offset + stories.length) % stories.length;
|
|
3109
3790
|
return {
|
|
@@ -3112,19 +3793,52 @@ var VtexAdsStoryCarouselElement = class extends LitElement {
|
|
|
3112
3793
|
label: this.labels.position(this.labels.show, neighbor, stories.length)
|
|
3113
3794
|
};
|
|
3114
3795
|
});
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
${this.carousel.render(stories, this.renderSlide, this.labels)}
|
|
3118
|
-
</div>
|
|
3119
|
-
${this.player.render(active, {
|
|
3796
|
+
const product = this.productOf(active);
|
|
3797
|
+
return this.player.render(active, {
|
|
3120
3798
|
labels: this.labels,
|
|
3121
3799
|
navigation: stories.length > 1,
|
|
3122
3800
|
neighbors,
|
|
3123
|
-
product
|
|
3801
|
+
product,
|
|
3124
3802
|
cta: toCardCta(active),
|
|
3803
|
+
productActions: this.cartActionsFor(product),
|
|
3125
3804
|
onPress: () => this.events.click(active)
|
|
3126
|
-
})
|
|
3127
|
-
|
|
3805
|
+
});
|
|
3806
|
+
}
|
|
3807
|
+
cartActionsFor(product) {
|
|
3808
|
+
const sku = product == null ? void 0 : product.sku;
|
|
3809
|
+
if (!sku) return void 0;
|
|
3810
|
+
const item = { sku, seller: product.seller };
|
|
3811
|
+
return {
|
|
3812
|
+
cartQuantity: this.cartQuantities.get(cartKey(item)),
|
|
3813
|
+
onAddToCart: () => this.changeCart(item, 1),
|
|
3814
|
+
onRemoveFromCart: () => this.changeCart(item, -1)
|
|
3815
|
+
};
|
|
3816
|
+
}
|
|
3817
|
+
/**
|
|
3818
|
+
* Adds one of `item` to the stepper's count, or removes one, and tells the
|
|
3819
|
+
* store, which changes its cart: the element has none. When add to cart
|
|
3820
|
+
* and the stepper swap places, the focus moves to the one now shown.
|
|
3821
|
+
*/
|
|
3822
|
+
changeCart(item, delta) {
|
|
3823
|
+
var _a;
|
|
3824
|
+
const key = cartKey(item);
|
|
3825
|
+
const before = (_a = this.cartQuantities.get(key)) != null ? _a : 0;
|
|
3826
|
+
const after = Math.max(0, before + delta);
|
|
3827
|
+
if (after === before) return;
|
|
3828
|
+
if (after > 0) this.cartQuantities.set(key, after);
|
|
3829
|
+
else this.cartQuantities.delete(key);
|
|
3830
|
+
this.requestUpdate();
|
|
3831
|
+
this.dispatchEvent(
|
|
3832
|
+
delta > 0 ? addToCartEvent(item) : removeFromCartEvent(item)
|
|
3833
|
+
);
|
|
3834
|
+
let swapped;
|
|
3835
|
+
if (before === 0) swapped = "stepper";
|
|
3836
|
+
else if (after === 0) swapped = "add";
|
|
3837
|
+
if (!swapped) return;
|
|
3838
|
+
const action = swapped;
|
|
3839
|
+
this.updateComplete.then(
|
|
3840
|
+
() => this.shadowRoot && focusCartAction(this.shadowRoot, action)
|
|
3841
|
+
);
|
|
3128
3842
|
}
|
|
3129
3843
|
};
|
|
3130
3844
|
VtexAdsStoryCarouselElement.properties = {
|
|
@@ -3141,25 +3855,33 @@ VtexAdsStoryCarouselElement.properties = {
|
|
|
3141
3855
|
labelViewProduct: { attribute: "label-view-product" },
|
|
3142
3856
|
hydration: { converter: hydrationConverter },
|
|
3143
3857
|
hydrationTimeout: { type: Number, attribute: "hydration-timeout" },
|
|
3858
|
+
slideDuration: { type: Number, attribute: "slide-duration" },
|
|
3144
3859
|
inactiveAutoplay: {
|
|
3145
3860
|
type: Boolean,
|
|
3146
3861
|
attribute: "inactive-autoplay",
|
|
3147
3862
|
converter: booleanConverter
|
|
3148
3863
|
},
|
|
3149
3864
|
stories: { state: true },
|
|
3150
|
-
products: { state: true }
|
|
3865
|
+
products: { state: true },
|
|
3866
|
+
requesting: { state: true },
|
|
3867
|
+
mediaLoading: { state: true }
|
|
3151
3868
|
};
|
|
3152
3869
|
VtexAdsStoryCarouselElement.styles = [
|
|
3153
|
-
|
|
3870
|
+
css7`
|
|
3154
3871
|
:host {
|
|
3155
3872
|
display: block;
|
|
3156
3873
|
font-family: var(--vtex-ads-story-font-family, inherit);
|
|
3157
3874
|
color: var(--vtex-ads-story-color-text, inherit);
|
|
3875
|
+
--_pill-radius: var(--vtex-ads-story-radius, 16px);
|
|
3876
|
+
--_pill-inset: 8px;
|
|
3877
|
+
--_button-radius: var(--vtex-ads-story-radius, 999px);
|
|
3158
3878
|
}
|
|
3159
3879
|
`,
|
|
3160
3880
|
cardStyles,
|
|
3881
|
+
mediaStyles,
|
|
3161
3882
|
productStyles,
|
|
3162
3883
|
carouselStyles,
|
|
3884
|
+
carouselSkeletonStyles,
|
|
3163
3885
|
playerStyles
|
|
3164
3886
|
];
|
|
3165
3887
|
function defineVtexAdsStoryCarousel() {
|
|
@@ -3168,6 +3890,8 @@ function defineVtexAdsStoryCarousel() {
|
|
|
3168
3890
|
customElements.define(TAG_NAME, VtexAdsStoryCarouselElement);
|
|
3169
3891
|
}
|
|
3170
3892
|
export {
|
|
3893
|
+
ADD_TO_CART_EVENT,
|
|
3894
|
+
REMOVE_FROM_CART_EVENT,
|
|
3171
3895
|
TAG_NAME,
|
|
3172
3896
|
VtexAdsStoryCarouselElement,
|
|
3173
3897
|
defineVtexAdsStoryCarousel
|