@vtex/ads-stories 0.3.0 → 0.4.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/dist/esm/index.js CHANGED
@@ -7,11 +7,28 @@ var collapse_default = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256
7
7
  // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/expand.svg
8
8
  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';
9
9
 
10
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/pause-fill.svg
11
+ 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';
12
+
10
13
  // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/play-fill.svg
11
14
  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';
12
15
 
16
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/speaker-x-fill.svg
17
+ 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';
18
+
19
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/speaker-high-fill.svg
20
+ 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';
21
+
13
22
  // src/components/icons/index.ts
14
- var icons = { close: close_default, collapse: collapse_default, expand: expand_default, play: play_fill_default };
23
+ var icons = {
24
+ close: close_default,
25
+ collapse: collapse_default,
26
+ expand: expand_default,
27
+ pause: pause_fill_default,
28
+ play: play_fill_default,
29
+ soundOff: speaker_x_fill_default,
30
+ soundOn: speaker_high_fill_default
31
+ };
15
32
  function createIcon(name) {
16
33
  const template = document.createElement("template");
17
34
  template.innerHTML = icons[name];
@@ -34,11 +51,29 @@ var cardStyles = `
34
51
  background: #000;
35
52
  }
36
53
 
37
- .card[role="button"] {
54
+ /* The card's button covers it. The focus ring goes on the card, since the
55
+ card's overflow would clip the button's own. */
56
+ .card-open {
57
+ position: absolute;
58
+ inset: 0;
59
+ width: 100%;
60
+ height: 100%;
61
+ padding: 0;
62
+ border: 0;
63
+ background: transparent;
38
64
  cursor: pointer;
39
65
  }
40
66
 
41
- .poster {
67
+ .card-open:focus-visible {
68
+ outline: none;
69
+ }
70
+
71
+ .card:has(> .card-open:focus-visible) {
72
+ outline: auto;
73
+ }
74
+
75
+ .poster,
76
+ .video {
42
77
  position: absolute;
43
78
  inset: 0;
44
79
  width: 100%;
@@ -74,6 +109,29 @@ var cardStyles = `
74
109
  color: #fff;
75
110
  }
76
111
 
112
+ /* Sound on/off, at the top right of the card (as in the prototype). */
113
+ .card-sound {
114
+ position: absolute;
115
+ top: 22px;
116
+ right: 12px;
117
+ z-index: 1;
118
+ display: grid;
119
+ width: 28px;
120
+ height: 28px;
121
+ place-items: center;
122
+ padding: 0;
123
+ border: 0;
124
+ background: transparent;
125
+ color: #fff;
126
+ cursor: pointer;
127
+ filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
128
+ }
129
+
130
+ .card-sound .icon {
131
+ width: 20px;
132
+ height: 20px;
133
+ }
134
+
77
135
  /* With a mouse, the play button shows only on hover or keyboard focus.
78
136
  Touch screens have no hover, so it stays visible there. */
79
137
  @media (hover: hover) and (pointer: fine) {
@@ -83,45 +141,89 @@ var cardStyles = `
83
141
  }
84
142
 
85
143
  .card:hover .play,
86
- .card:focus-visible .play {
144
+ .card-open:focus-visible .play {
87
145
  opacity: 1;
88
146
  transform: translate(-50%, -50%);
89
147
  }
90
148
  }
91
149
  `;
92
- function isHttpUrl(value) {
150
+ function httpUrl(value) {
151
+ if (!value) return null;
93
152
  try {
94
153
  const { protocol } = new URL(value);
95
- return protocol === "https:" || protocol === "http:";
154
+ return protocol === "https:" || protocol === "http:" ? value : null;
96
155
  } catch (e) {
97
- return false;
156
+ return null;
157
+ }
158
+ }
159
+ function prefersReducedMotion() {
160
+ var _a2, _b;
161
+ return (_b = (_a2 = globalThis.matchMedia) == null ? void 0 : _a2.call(globalThis, "(prefers-reduced-motion: reduce)").matches) != null ? _b : false;
162
+ }
163
+ function playVideo(video) {
164
+ var _a2;
165
+ (_a2 = video.play()) == null ? void 0 : _a2.catch(() => void 0);
166
+ }
167
+ function createVideo(src, poster) {
168
+ const video = document.createElement("video");
169
+ video.className = "video";
170
+ video.muted = true;
171
+ video.setAttribute("muted", "");
172
+ video.setAttribute("playsinline", "");
173
+ video.loop = true;
174
+ video.preload = "metadata";
175
+ video.autoplay = !prefersReducedMotion();
176
+ if (poster) video.poster = poster;
177
+ video.src = src;
178
+ video.addEventListener("error", () => video.remove());
179
+ return video;
180
+ }
181
+ function createSoundButton(video, options) {
182
+ const button = document.createElement("button");
183
+ button.type = "button";
184
+ button.className = "card-sound";
185
+ function sync() {
186
+ button.setAttribute(
187
+ "aria-label",
188
+ video.muted ? options.soundOnLabel : options.soundOffLabel
189
+ );
190
+ button.replaceChildren(createIcon(video.muted ? "soundOff" : "soundOn"));
98
191
  }
192
+ video.addEventListener("volumechange", sync);
193
+ video.addEventListener("error", () => button.remove());
194
+ button.addEventListener("click", () => {
195
+ video.muted = !video.muted;
196
+ });
197
+ sync();
198
+ return button;
99
199
  }
100
200
  function createCard(story, options) {
101
201
  const card = document.createElement("div");
102
202
  card.className = "card";
103
- if (story.poster_url && isHttpUrl(story.poster_url)) {
203
+ const posterUrl = httpUrl(story.poster_url);
204
+ if (posterUrl) {
104
205
  const poster = document.createElement("img");
105
206
  poster.className = "poster";
106
207
  poster.alt = "";
107
- poster.src = story.poster_url;
208
+ poster.src = posterUrl;
108
209
  card.append(poster);
109
210
  }
211
+ const mediaUrl = httpUrl(story.media_url);
212
+ const video = mediaUrl ? createVideo(mediaUrl, posterUrl) : null;
213
+ if (video) card.append(video);
110
214
  if (options) {
111
- card.setAttribute("role", "button");
112
- card.setAttribute("aria-label", options.label);
113
- card.tabIndex = 0;
215
+ const open = document.createElement("button");
216
+ open.type = "button";
217
+ open.className = "card-open";
218
+ open.setAttribute("aria-label", options.label);
114
219
  const play = document.createElement("span");
115
220
  play.className = "play";
116
221
  play.setAttribute("aria-hidden", "true");
117
222
  play.append(createIcon("play"));
118
- card.append(play);
119
- card.addEventListener("click", options.onSelect);
120
- card.addEventListener("keydown", (event) => {
121
- if (event.key !== "Enter" && event.key !== " ") return;
122
- event.preventDefault();
123
- options.onSelect();
124
- });
223
+ open.append(play);
224
+ open.addEventListener("click", options.onSelect);
225
+ card.append(open);
226
+ if (video) card.append(createSoundButton(video, options));
125
227
  }
126
228
  return card;
127
229
  }
@@ -172,6 +274,46 @@ var playerStyles = `
172
274
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
173
275
  }
174
276
 
277
+ .player .card:has(.video) {
278
+ cursor: pointer;
279
+ }
280
+
281
+ /* Play/pause reuses the card's glass .play button, as a real button. */
282
+ .player-toggle {
283
+ padding: 0;
284
+ border: 0;
285
+ color: #fff;
286
+ font: inherit;
287
+ cursor: pointer;
288
+ }
289
+
290
+ .player[data-paused] .player-toggle,
291
+ .player-toggle:focus-visible {
292
+ opacity: 1;
293
+ transform: translate(-50%, -50%);
294
+ }
295
+
296
+ /* On touch, tapping the video pauses it; the button shows while paused. */
297
+ @media (hover: none) {
298
+ .player:not([data-paused]) .player-toggle {
299
+ opacity: 0;
300
+ }
301
+ }
302
+
303
+ .player-sound {
304
+ position: absolute;
305
+ top: 12px;
306
+ right: 12px;
307
+ z-index: 1;
308
+ border-color: transparent;
309
+ background: rgba(0, 0, 0, 0.3);
310
+ }
311
+
312
+ .player-sound .icon {
313
+ width: 20px;
314
+ height: 20px;
315
+ }
316
+
175
317
  /* Above the card: on narrow screens the expanded card can cover them. */
176
318
  .player-controls {
177
319
  position: absolute;
@@ -256,8 +398,12 @@ var playerStyles = `
256
398
  border-radius: 0;
257
399
  }
258
400
 
401
+ /* Below the sound button, at the top right of the video. Placed in the
402
+ video frame, not the screen: the frame is centered, so on screens
403
+ taller than 9:16 its top is below the screen's. */
259
404
  .player[data-expanded] .player-controls {
260
- top: 12px;
405
+ position: absolute;
406
+ top: 60px;
261
407
  right: 12px;
262
408
  }
263
409
  }
@@ -290,6 +436,57 @@ function showPlayer(player) {
290
436
  if (supportsPopover(player)) player.showPopover();
291
437
  else player.show();
292
438
  }
439
+ function playPlayer(player) {
440
+ const video = player.querySelector("video");
441
+ if (video) playVideo(video);
442
+ }
443
+ function addVideoControls(player, card, video, options) {
444
+ const toggle = document.createElement("button");
445
+ toggle.type = "button";
446
+ toggle.className = "play player-toggle";
447
+ const sound = createButton("player-sound", "", "soundOff");
448
+ function syncPlayback() {
449
+ player.toggleAttribute("data-paused", video.paused);
450
+ toggle.setAttribute(
451
+ "aria-label",
452
+ video.paused ? options.playLabel : options.pauseLabel
453
+ );
454
+ toggle.replaceChildren(createIcon(video.paused ? "play" : "pause"));
455
+ }
456
+ function syncSound() {
457
+ sound.setAttribute(
458
+ "aria-label",
459
+ video.muted ? options.soundOnLabel : options.soundOffLabel
460
+ );
461
+ sound.replaceChildren(createIcon(video.muted ? "soundOff" : "soundOn"));
462
+ }
463
+ function togglePlayback() {
464
+ if (video.paused) playVideo(video);
465
+ else video.pause();
466
+ }
467
+ video.addEventListener("play", syncPlayback);
468
+ video.addEventListener("pause", syncPlayback);
469
+ video.addEventListener("volumechange", syncSound);
470
+ video.addEventListener("error", () => {
471
+ toggle.remove();
472
+ sound.remove();
473
+ delete player.dataset.paused;
474
+ });
475
+ toggle.addEventListener("click", (event) => {
476
+ event.stopPropagation();
477
+ togglePlayback();
478
+ });
479
+ sound.addEventListener("click", (event) => {
480
+ event.stopPropagation();
481
+ video.muted = !video.muted;
482
+ });
483
+ card.addEventListener("click", () => {
484
+ if (video.isConnected) togglePlayback();
485
+ });
486
+ syncPlayback();
487
+ syncSound();
488
+ card.append(toggle, sound);
489
+ }
293
490
  function createPlayer(story, options) {
294
491
  const player = document.createElement("dialog");
295
492
  player.className = "player";
@@ -329,7 +526,10 @@ function createPlayer(story, options) {
329
526
  event.preventDefault();
330
527
  options.onClose();
331
528
  });
332
- frame.append(controls, createCard(story));
529
+ const card = createCard(story);
530
+ const video = card.querySelector("video");
531
+ if (video) addVideoControls(player, card, video, options);
532
+ frame.append(controls, card);
333
533
  player.append(frame);
334
534
  return player;
335
535
  }
@@ -348,15 +548,19 @@ var styles = `
348
548
  ${playerStyles}
349
549
  `;
350
550
  var PLACEHOLDER_STORY = {
351
- ad_id: "placeholder",
352
- poster_url: "https://dummyimage.com/1080x1920/e31c57/fff"
551
+ poster_url: "https://dummyimage.com/1080x1920/e31c57/fff",
552
+ media_url: "https://samplelib.com/mp4/sample-10s-vp9.mp4"
353
553
  };
354
554
  var LABELS = {
355
555
  watch: "Assistir v\xEDdeo",
356
556
  player: "V\xEDdeo",
357
557
  expand: "Expandir v\xEDdeo",
358
558
  collapse: "Reduzir v\xEDdeo",
359
- close: "Fechar v\xEDdeo"
559
+ close: "Fechar v\xEDdeo",
560
+ play: "Reproduzir v\xEDdeo",
561
+ pause: "Pausar v\xEDdeo",
562
+ soundOn: "Ativar som",
563
+ soundOff: "Desativar som"
360
564
  };
361
565
  var VtexAdsStoryElement = class extends BaseElement {
362
566
  constructor() {
@@ -373,34 +577,51 @@ var VtexAdsStoryElement = class extends BaseElement {
373
577
  container.replaceChildren(
374
578
  createCard(PLACEHOLDER_STORY, {
375
579
  label: LABELS.watch,
580
+ soundOnLabel: LABELS.soundOn,
581
+ soundOffLabel: LABELS.soundOff,
376
582
  onSelect: () => this.openPlayer()
377
583
  })
378
584
  );
379
585
  }
380
- openPlayer() {
586
+ cardVideo() {
381
587
  var _a2;
588
+ return (_a2 = this.shadowRoot) == null ? void 0 : _a2.querySelector(
589
+ ".root .card video"
590
+ );
591
+ }
592
+ openPlayer() {
593
+ var _a2, _b;
382
594
  if (this.player || !this.shadowRoot) return;
383
595
  this.player = createPlayer(PLACEHOLDER_STORY, {
384
596
  label: LABELS.player,
385
597
  expandLabel: LABELS.expand,
386
598
  collapseLabel: LABELS.collapse,
387
599
  closeLabel: LABELS.close,
600
+ playLabel: LABELS.play,
601
+ pauseLabel: LABELS.pause,
602
+ soundOnLabel: LABELS.soundOn,
603
+ soundOffLabel: LABELS.soundOff,
388
604
  onClose: () => this.closePlayer()
389
605
  });
390
606
  this.shadowRoot.append(this.player);
391
607
  showPlayer(this.player);
608
+ (_a2 = this.cardVideo()) == null ? void 0 : _a2.pause();
609
+ playPlayer(this.player);
392
610
  document.addEventListener("keydown", this.onKeyDown);
393
- (_a2 = this.player.querySelector(".player-close")) == null ? void 0 : _a2.focus();
611
+ (_b = this.player.querySelector(".player-close")) == null ? void 0 : _b.focus();
394
612
  }
395
- closePlayer({ restoreFocus = true } = {}) {
613
+ // `removed`: the element is leaving the page, so there is no card to give
614
+ // focus back to or to resume playing (it would play out of sight).
615
+ closePlayer({ removed = false } = {}) {
396
616
  var _a2, _b;
397
617
  if (!this.player) return;
398
618
  document.removeEventListener("keydown", this.onKeyDown);
399
619
  this.player.remove();
400
620
  this.player = null;
401
- if (restoreFocus) {
402
- (_b = (_a2 = this.shadowRoot) == null ? void 0 : _a2.querySelector(".root .card")) == null ? void 0 : _b.focus();
403
- }
621
+ if (removed) return;
622
+ const video = this.cardVideo();
623
+ if (video == null ? void 0 : video.autoplay) playVideo(video);
624
+ (_b = (_a2 = this.shadowRoot) == null ? void 0 : _a2.querySelector(".root .card-open")) == null ? void 0 : _b.focus();
404
625
  }
405
626
  connectedCallback() {
406
627
  if (!this.shadowRoot) {
@@ -410,7 +631,7 @@ var VtexAdsStoryElement = class extends BaseElement {
410
631
  this.render();
411
632
  }
412
633
  disconnectedCallback() {
413
- this.closePlayer({ restoreFocus: false });
634
+ this.closePlayer({ removed: true });
414
635
  }
415
636
  };
416
637
  function defineVtexAdsStories() {
@@ -1 +1 @@
1
- {"version":3,"sources":["raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/close.svg","raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/collapse.svg","raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/expand.svg","raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/play-fill.svg","../../src/components/icons/index.ts","../../src/components/card/card.ts","../../src/components/player/player.ts","../../src/story/story.ts"],"sourcesContent":["<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" fill=\"currentColor\"><path d=\"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z\"/></svg>\n","<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" fill=\"currentColor\"><path d=\"M152,96V48a8,8,0,0,1,16,0V88h40a8,8,0,0,1,0,16H160A8,8,0,0,1,152,96ZM96,152H48a8,8,0,0,0,0,16H88v40a8,8,0,0,0,16,0V160A8,8,0,0,0,96,152Zm112,0H160a8,8,0,0,0-8,8v48a8,8,0,0,0,16,0V168h40a8,8,0,0,0,0-16ZM96,40a8,8,0,0,0-8,8V88H48a8,8,0,0,0,0,16H96a8,8,0,0,0,8-8V48A8,8,0,0,0,96,40Z\"/></svg>\n","<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","<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","/*! Icons from Phosphor Icons (https://phosphoricons.com), MIT License, Copyright (c) 2023 Phosphor Icons */\n\n// SVG files as downloaded from Phosphor: regular weight, or the weight in the\n// file name. They are bundled as text: `?raw` is handled by Vite in dev and\n// tests, and by the raw plugin in tsup.config.ts.\nimport close from \"./assets/close.svg?raw\";\nimport collapse from \"./assets/collapse.svg?raw\";\nimport expand from \"./assets/expand.svg?raw\";\nimport play from \"./assets/play-fill.svg?raw\";\n\nexport const icons = { close, collapse, expand, play };\n\nexport type IconName = keyof typeof icons;\n\n/** Renders a bundled icon. It is decorative: name the control around it. */\nexport function createIcon(name: IconName) {\n const template = document.createElement(\"template\");\n template.innerHTML = icons[name];\n\n const svg = template.content.firstElementChild as SVGSVGElement;\n svg.classList.add(\"icon\");\n svg.setAttribute(\"aria-hidden\", \"true\");\n svg.setAttribute(\"focusable\", \"false\");\n return svg;\n}\n","import { createIcon } from \"../icons\";\nimport type { StoryAd } from \"../../types\";\n\nexport const cardStyles = `\n .card {\n position: relative;\n box-sizing: border-box;\n width: calc(500px * 9 / 16);\n height: 500px;\n overflow: hidden;\n border-radius: var(--vtex-ads-story-radius, 20px);\n background: #000;\n }\n\n .card[role=\"button\"] {\n cursor: pointer;\n }\n\n .poster {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n object-fit: cover;\n }\n\n .play {\n position: absolute;\n top: 50%;\n left: 50%;\n display: grid;\n width: 66px;\n height: 66px;\n place-items: center;\n border-radius: 50%;\n background:\n linear-gradient(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.06)),\n rgba(255, 255, 255, 0.15);\n backdrop-filter: blur(2px);\n box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.42);\n transform: translate(-50%, -50%);\n transition:\n opacity 0.3s ease,\n transform 0.3s ease;\n }\n\n /* The icon's triangle is 18px tall and already sits slightly right of its\n box, so it looks centered in the circle. */\n .play .icon {\n width: 22px;\n height: 22px;\n color: #fff;\n }\n\n /* With a mouse, the play button shows only on hover or keyboard focus.\n Touch screens have no hover, so it stays visible there. */\n @media (hover: hover) and (pointer: fine) {\n .play {\n opacity: 0;\n transform: translate(-50%, -50%) scale(0.9);\n }\n\n .card:hover .play,\n .card:focus-visible .play {\n opacity: 1;\n transform: translate(-50%, -50%);\n }\n }\n`;\n\nexport interface CardOptions {\n /** Accessible name of the card. */\n label: string;\n /** Called on click, Enter or Space. */\n onSelect: () => void;\n}\n\n// Only absolute http(s) URLs reach the DOM.\nfunction isHttpUrl(value: string) {\n try {\n const { protocol } = new URL(value);\n return protocol === \"https:\" || protocol === \"http:\";\n } catch {\n return false;\n }\n}\n\n/**\n * A 9:16 card with the Story cover. With options, the card is a button with\n * a play icon in the middle.\n */\nexport function createCard(story: StoryAd, options?: CardOptions) {\n const card = document.createElement(\"div\");\n card.className = \"card\";\n\n if (story.poster_url && isHttpUrl(story.poster_url)) {\n const poster = document.createElement(\"img\");\n poster.className = \"poster\";\n poster.alt = \"\";\n poster.src = story.poster_url;\n card.append(poster);\n }\n\n if (options) {\n card.setAttribute(\"role\", \"button\");\n card.setAttribute(\"aria-label\", options.label);\n card.tabIndex = 0;\n\n const play = document.createElement(\"span\");\n play.className = \"play\";\n play.setAttribute(\"aria-hidden\", \"true\");\n play.append(createIcon(\"play\"));\n card.append(play);\n\n card.addEventListener(\"click\", options.onSelect);\n card.addEventListener(\"keydown\", (event) => {\n if (event.key !== \"Enter\" && event.key !== \" \") return;\n event.preventDefault();\n options.onSelect();\n });\n }\n\n return card;\n}\n","import { createCard } from \"../card\";\nimport { createIcon, type IconName } from \"../icons\";\nimport type { StoryAd } from \"../../types\";\n\n// The player is a <dialog> shown in the top layer, so no store z-index,\n// overflow or transform can hide or move it.\n//\n// Mini: a manual popover (non-modal, the page stays usable), with the card at\n// the bottom right and the controls above it. Without popover support it is a\n// non-modal dialog, fixed with a high z-index.\n// Expanded: a modal dialog (showModal), so the browser makes the page behind\n// it inert. The card is centered over a dark backdrop, with the controls at\n// the top right of the screen. On narrow screens it fills the screen.\nexport const playerStyles = `\n .player {\n position: fixed;\n inset: auto 16px 16px auto;\n z-index: 2147483000;\n box-sizing: border-box;\n width: calc(min(587px, 100vh - 80px) * 9 / 16);\n height: min(587px, 100vh - 80px);\n margin: 0;\n padding: 0;\n overflow: visible;\n border: 0;\n background: transparent;\n color: inherit;\n font: inherit;\n animation: player-in 0.25s ease;\n }\n\n /* A <dialog> shown as a popover has no open attribute, which the browser\n hides by default. */\n .player:popover-open {\n display: block;\n }\n\n /* Switching modes shows the dialog again; only the first opening fades in. */\n .player[data-switched] {\n animation: none;\n }\n\n .player::backdrop {\n background: transparent;\n }\n\n .player-frame {\n position: relative;\n width: 100%;\n height: 100%;\n }\n\n .player .card {\n width: 100%;\n height: 100%;\n box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);\n }\n\n /* Above the card: on narrow screens the expanded card can cover them. */\n .player-controls {\n position: absolute;\n right: 0;\n bottom: calc(100% + 8px);\n z-index: 1;\n display: flex;\n gap: 8px;\n }\n\n .player-button {\n display: grid;\n width: 36px;\n height: 36px;\n place-items: center;\n padding: 0;\n border: 1px solid rgba(133, 133, 133, 0.3);\n border-radius: 50%;\n background: rgba(0, 0, 0, 0.32);\n backdrop-filter: blur(5px);\n color: #fff;\n cursor: pointer;\n transition: background-color 0.2s;\n }\n\n .player-button:hover {\n background: rgba(0, 0, 0, 0.55);\n }\n\n .player-button .icon {\n width: 18px;\n height: 18px;\n }\n\n .player[data-expanded] {\n inset: 0;\n display: grid;\n width: 100%;\n max-width: none;\n height: 100%;\n max-height: none;\n place-items: center;\n background: rgba(0, 0, 0, 0.85);\n animation: none;\n }\n\n .player[data-expanded] .player-frame {\n width: calc(min(78vh, 720px) * 9 / 16);\n height: min(78vh, 720px);\n }\n\n .player[data-expanded] .player-controls {\n position: fixed;\n top: 24px;\n right: 24px;\n bottom: auto;\n }\n\n .player[data-expanded] .player-button {\n width: 40px;\n height: 40px;\n }\n\n @media (max-width: 576px) {\n .player {\n right: 12px;\n width: 220px;\n height: 391px;\n }\n\n .player[data-expanded] {\n background: #000;\n }\n\n /* The video stays 9:16 and centered; the rest of the screen is black. */\n .player[data-expanded] .player-frame {\n width: min(100vw, 100vh * 9 / 16);\n height: min(100vh, 100vw * 16 / 9);\n }\n\n .player[data-expanded] .card {\n border-radius: 0;\n }\n\n .player[data-expanded] .player-controls {\n top: 12px;\n right: 12px;\n }\n }\n\n @keyframes player-in {\n from {\n opacity: 0;\n transform: translateY(8px);\n }\n }\n\n @media (prefers-reduced-motion: reduce) {\n .player {\n animation: none;\n }\n }\n`;\n\nexport interface PlayerOptions {\n /** Accessible name of the player. */\n label: string;\n /** Accessible names of the buttons. */\n expandLabel: string;\n collapseLabel: string;\n closeLabel: string;\n onClose: () => void;\n}\n\nfunction createButton(className: string, label: string, icon: IconName) {\n const button = document.createElement(\"button\");\n button.type = \"button\";\n button.className = `player-button ${className}`;\n button.setAttribute(\"aria-label\", label);\n button.append(createIcon(icon));\n return button;\n}\n\nfunction supportsPopover(player: HTMLDialogElement) {\n return typeof player.showPopover === \"function\";\n}\n\n/** Shows the player as the mini player. It must already be in the page. */\nexport function showPlayer(player: HTMLDialogElement) {\n if (supportsPopover(player)) player.showPopover();\n else player.show();\n}\n\n/**\n * The Story player. It opens as the mini player (see showPlayer); expand\n * switches to the expanded view, a modal dialog, and back. Clicking the\n * backdrop of the expanded view or pressing Escape in it closes the player.\n */\nexport function createPlayer(story: StoryAd, options: PlayerOptions) {\n const player = document.createElement(\"dialog\");\n player.className = \"player\";\n player.setAttribute(\"popover\", \"manual\");\n player.setAttribute(\"aria-label\", options.label);\n\n const frame = document.createElement(\"div\");\n frame.className = \"player-frame\";\n\n const controls = document.createElement(\"div\");\n controls.className = \"player-controls\";\n\n const expand = createButton(\"player-expand\", options.expandLabel, \"expand\");\n const close = createButton(\"player-close\", options.closeLabel, \"close\");\n controls.append(expand, close);\n\n let expanded = false;\n\n // A dialog can't be shown as a popover and as a modal at the same time, so\n // switching modes hides it first, the same way it was shown.\n function hide() {\n if (!expanded && supportsPopover(player)) player.hidePopover();\n else player.close();\n }\n\n expand.addEventListener(\"click\", () => {\n hide();\n expanded = !expanded;\n player.toggleAttribute(\"data-expanded\", expanded);\n player.dataset.switched = \"\";\n expand.setAttribute(\n \"aria-label\",\n expanded ? options.collapseLabel : options.expandLabel,\n );\n expand.replaceChildren(createIcon(expanded ? \"collapse\" : \"expand\"));\n\n if (expanded) player.showModal();\n else showPlayer(player);\n expand.focus();\n });\n\n close.addEventListener(\"click\", options.onClose);\n\n // Clicks on the backdrop of the expanded view reach the dialog itself.\n player.addEventListener(\"click\", (event) => {\n if (expanded && event.target === player) options.onClose();\n });\n\n // Escape on a modal dialog would only hide it: close the player instead.\n player.addEventListener(\"cancel\", (event) => {\n event.preventDefault();\n options.onClose();\n });\n\n frame.append(controls, createCard(story));\n player.append(frame);\n return player;\n}\n","import { cardStyles, createCard } from \"../components/card\";\nimport { createPlayer, playerStyles, showPlayer } from \"../components/player\";\nimport type { StoryAd } from \"../types\";\n\nexport const TAG_NAME = \"vtex-ads-story\";\n\n// Keeps the module importable where HTMLElement doesn't exist (SSR, Node).\nconst BaseElement: typeof HTMLElement = globalThis.HTMLElement ?? Object;\n\nconst styles = `\n :host {\n display: block;\n font-family: var(--vtex-ads-story-font-family, inherit);\n color: var(--vtex-ads-story-color-text, inherit);\n }\n ${cardStyles}\n ${playerStyles}\n`;\n\n// Temporary: rendered until the element reads Stories from the ad API.\nconst PLACEHOLDER_STORY: StoryAd = {\n ad_id: \"placeholder\",\n poster_url: \"https://dummyimage.com/1080x1920/e31c57/fff\",\n};\n\n// Temporary: fixed texts until the store can set them by attribute.\nconst LABELS = {\n watch: \"Assistir vídeo\",\n player: \"Vídeo\",\n expand: \"Expandir vídeo\",\n collapse: \"Reduzir vídeo\",\n close: \"Fechar vídeo\",\n};\n\nexport class VtexAdsStoryElement extends BaseElement {\n private player: HTMLDialogElement | null = null;\n\n private readonly onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") this.closePlayer();\n };\n\n private render() {\n const container = this.shadowRoot?.querySelector(\".root\");\n if (!container) return;\n\n container.replaceChildren(\n createCard(PLACEHOLDER_STORY, {\n label: LABELS.watch,\n onSelect: () => this.openPlayer(),\n }),\n );\n }\n\n private openPlayer() {\n if (this.player || !this.shadowRoot) return;\n\n this.player = createPlayer(PLACEHOLDER_STORY, {\n label: LABELS.player,\n expandLabel: LABELS.expand,\n collapseLabel: LABELS.collapse,\n closeLabel: LABELS.close,\n onClose: () => this.closePlayer(),\n });\n this.shadowRoot.append(this.player);\n showPlayer(this.player);\n document.addEventListener(\"keydown\", this.onKeyDown);\n\n this.player.querySelector<HTMLElement>(\".player-close\")?.focus();\n }\n\n private closePlayer({ restoreFocus = true } = {}) {\n if (!this.player) return;\n\n document.removeEventListener(\"keydown\", this.onKeyDown);\n this.player.remove();\n this.player = null;\n\n if (restoreFocus) {\n this.shadowRoot?.querySelector<HTMLElement>(\".root .card\")?.focus();\n }\n }\n\n connectedCallback() {\n if (!this.shadowRoot) {\n const root = this.attachShadow({ mode: \"open\" });\n root.innerHTML = `<style>${styles}</style><div class=\"root\"></div>`;\n }\n\n this.render();\n }\n\n disconnectedCallback() {\n this.closePlayer({ restoreFocus: false });\n }\n}\n\n// Types `document.createElement(\"vtex-ads-story\")` and `querySelector` results\n// as VtexAdsStoryElement in any TypeScript project, no framework needed.\ndeclare global {\n interface HTMLElementTagNameMap {\n \"vtex-ads-story\": VtexAdsStoryElement;\n }\n}\n\nexport function defineVtexAdsStories() {\n if (typeof customElements === \"undefined\") return;\n if (customElements.get(TAG_NAME)) return;\n\n customElements.define(TAG_NAME, VtexAdsStoryElement);\n}\n"],"mappings":";AAAA;;;ACAA;;;ACAA;;;ACAA;;;ACUO,IAAM,QAAQ,EAAE,sBAAO,4BAAU,wBAAQ,wBAAK;AAK9C,SAAS,WAAW,MAAgB;AACzC,QAAM,WAAW,SAAS,cAAc,UAAU;AAClD,WAAS,YAAY,MAAM,IAAI;AAE/B,QAAM,MAAM,SAAS,QAAQ;AAC7B,MAAI,UAAU,IAAI,MAAM;AACxB,MAAI,aAAa,eAAe,MAAM;AACtC,MAAI,aAAa,aAAa,OAAO;AACrC,SAAO;AACT;;;ACrBO,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2E1B,SAAS,UAAU,OAAe;AAChC,MAAI;AACF,UAAM,EAAE,SAAS,IAAI,IAAI,IAAI,KAAK;AAClC,WAAO,aAAa,YAAY,aAAa;AAAA,EAC/C,SAAQ;AACN,WAAO;AAAA,EACT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AAuB;AACrB,SAAK,YAAY,EAAE,cAAc,MAAM,CAAC;AAAA,EAC1C;AACF;AAUO,SAAS,uBAAuB;AACrC,MAAI,OAAO,mBAAmB,YAAa;AAC3C,MAAI,eAAe,IAAI,QAAQ,EAAG;AAElC,iBAAe,OAAO,UAAU,mBAAmB;AACrD;","names":["_a"]}
1
+ {"version":3,"sources":["raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/close.svg","raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/collapse.svg","raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/expand.svg","raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/pause-fill.svg","raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/play-fill.svg","raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/speaker-x-fill.svg","raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/speaker-high-fill.svg","../../src/components/icons/index.ts","../../src/components/card/card.ts","../../src/components/player/player.ts","../../src/story/story.ts"],"sourcesContent":["<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" fill=\"currentColor\"><path d=\"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z\"/></svg>\n","<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" fill=\"currentColor\"><path d=\"M152,96V48a8,8,0,0,1,16,0V88h40a8,8,0,0,1,0,16H160A8,8,0,0,1,152,96ZM96,152H48a8,8,0,0,0,0,16H88v40a8,8,0,0,0,16,0V160A8,8,0,0,0,96,152Zm112,0H160a8,8,0,0,0-8,8v48a8,8,0,0,0,16,0V168h40a8,8,0,0,0,0-16ZM96,40a8,8,0,0,0-8,8V88H48a8,8,0,0,0,0,16H96a8,8,0,0,0,8-8V48A8,8,0,0,0,96,40Z\"/></svg>\n","<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","<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","<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","<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","<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","/*! Icons from Phosphor Icons (https://phosphoricons.com), MIT License, Copyright (c) 2023 Phosphor Icons */\n\n// SVG files as downloaded from Phosphor: regular weight, or the weight in the\n// file name. They are bundled as text: `?raw` is handled by Vite in dev and\n// tests, and by the raw plugin in tsup.config.ts.\nimport close from \"./assets/close.svg?raw\";\nimport collapse from \"./assets/collapse.svg?raw\";\nimport expand from \"./assets/expand.svg?raw\";\nimport pause from \"./assets/pause-fill.svg?raw\";\nimport play from \"./assets/play-fill.svg?raw\";\nimport soundOff from \"./assets/speaker-x-fill.svg?raw\";\nimport soundOn from \"./assets/speaker-high-fill.svg?raw\";\n\nexport const icons = {\n close,\n collapse,\n expand,\n pause,\n play,\n soundOff,\n soundOn,\n};\n\nexport type IconName = keyof typeof icons;\n\n/** Renders a bundled icon. It is decorative: name the control around it. */\nexport function createIcon(name: IconName) {\n const template = document.createElement(\"template\");\n template.innerHTML = icons[name];\n\n const svg = template.content.firstElementChild as SVGSVGElement;\n svg.classList.add(\"icon\");\n svg.setAttribute(\"aria-hidden\", \"true\");\n svg.setAttribute(\"focusable\", \"false\");\n return svg;\n}\n","import { createIcon } from \"../icons\";\nimport type { StoryMedia } from \"../../types\";\n\nexport const cardStyles = `\n .card {\n position: relative;\n box-sizing: border-box;\n width: calc(500px * 9 / 16);\n height: 500px;\n overflow: hidden;\n border-radius: var(--vtex-ads-story-radius, 20px);\n background: #000;\n }\n\n /* The card's button covers it. The focus ring goes on the card, since the\n card's overflow would clip the button's own. */\n .card-open {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n padding: 0;\n border: 0;\n background: transparent;\n cursor: pointer;\n }\n\n .card-open:focus-visible {\n outline: none;\n }\n\n .card:has(> .card-open:focus-visible) {\n outline: auto;\n }\n\n .poster,\n .video {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n object-fit: cover;\n }\n\n .play {\n position: absolute;\n top: 50%;\n left: 50%;\n display: grid;\n width: 66px;\n height: 66px;\n place-items: center;\n border-radius: 50%;\n background:\n linear-gradient(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.06)),\n rgba(255, 255, 255, 0.15);\n backdrop-filter: blur(2px);\n box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.42);\n transform: translate(-50%, -50%);\n transition:\n opacity 0.3s ease,\n transform 0.3s ease;\n }\n\n /* The icon's triangle is 18px tall and already sits slightly right of its\n box, so it looks centered in the circle. */\n .play .icon {\n width: 22px;\n height: 22px;\n color: #fff;\n }\n\n /* Sound on/off, at the top right of the card (as in the prototype). */\n .card-sound {\n position: absolute;\n top: 22px;\n right: 12px;\n z-index: 1;\n display: grid;\n width: 28px;\n height: 28px;\n place-items: center;\n padding: 0;\n border: 0;\n background: transparent;\n color: #fff;\n cursor: pointer;\n filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));\n }\n\n .card-sound .icon {\n width: 20px;\n height: 20px;\n }\n\n /* With a mouse, the play button shows only on hover or keyboard focus.\n Touch screens have no hover, so it stays visible there. */\n @media (hover: hover) and (pointer: fine) {\n .play {\n opacity: 0;\n transform: translate(-50%, -50%) scale(0.9);\n }\n\n .card:hover .play,\n .card-open:focus-visible .play {\n opacity: 1;\n transform: translate(-50%, -50%);\n }\n }\n`;\n\nexport interface CardOptions {\n /** Accessible name of the card. */\n label: string;\n /** Called on click, Enter or Space. */\n onSelect: () => void;\n /** Accessible names of the sound button, shown when the card has a video. */\n soundOnLabel: string;\n soundOffLabel: string;\n}\n\n// Only absolute http(s) URLs reach the DOM. Relative and protocol-relative\n// ones (\"/a.jpg\", \"//host/a.jpg\") don't parse without a base, so they're out.\nfunction httpUrl(value: string | undefined) {\n if (!value) return null;\n try {\n const { protocol } = new URL(value);\n return protocol === \"https:\" || protocol === \"http:\" ? value : null;\n } catch {\n return null;\n }\n}\n\nfunction prefersReducedMotion() {\n return (\n globalThis.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches ?? false\n );\n}\n\n/**\n * Plays a video. A blocked play is ignored: the cover or the paused state\n * stays.\n */\nexport function playVideo(video: HTMLVideoElement) {\n video.play()?.catch(() => undefined);\n}\n\nfunction createVideo(src: string, poster: string | null) {\n const video = document.createElement(\"video\");\n video.className = \"video\";\n // Muted and inline is what browsers, iOS included, allow to autoplay.\n video.muted = true;\n video.setAttribute(\"muted\", \"\");\n video.setAttribute(\"playsinline\", \"\");\n video.loop = true;\n video.preload = \"metadata\";\n // No autoplay for people who asked for reduced motion.\n video.autoplay = !prefersReducedMotion();\n if (poster) video.poster = poster;\n video.src = src;\n\n // If the video can't load, the cover underneath stays.\n video.addEventListener(\"error\", () => video.remove());\n return video;\n}\n\n/** Sound on/off for the card's video, which starts muted. */\nfunction createSoundButton(video: HTMLVideoElement, options: CardOptions) {\n const button = document.createElement(\"button\");\n button.type = \"button\";\n button.className = \"card-sound\";\n\n function sync() {\n button.setAttribute(\n \"aria-label\",\n video.muted ? options.soundOnLabel : options.soundOffLabel,\n );\n button.replaceChildren(createIcon(video.muted ? \"soundOff\" : \"soundOn\"));\n }\n\n video.addEventListener(\"volumechange\", sync);\n // Without the video, the cover stays and there is no sound to control.\n video.addEventListener(\"error\", () => button.remove());\n button.addEventListener(\"click\", () => {\n video.muted = !video.muted;\n });\n\n sync();\n return button;\n}\n\n/**\n * A 9:16 card with the Story cover and, with a media_url, the video looping\n * muted over it. With options, a button with a play icon in the middle covers\n * the card, and a card with a video gets a sound button. The sound button is\n * beside the card's button, not inside it: a button can't contain another.\n */\nexport function createCard(story: StoryMedia, options?: CardOptions) {\n const card = document.createElement(\"div\");\n card.className = \"card\";\n\n const posterUrl = httpUrl(story.poster_url);\n if (posterUrl) {\n const poster = document.createElement(\"img\");\n poster.className = \"poster\";\n poster.alt = \"\";\n poster.src = posterUrl;\n card.append(poster);\n }\n\n const mediaUrl = httpUrl(story.media_url);\n const video = mediaUrl ? createVideo(mediaUrl, posterUrl) : null;\n if (video) card.append(video);\n\n if (options) {\n const open = document.createElement(\"button\");\n open.type = \"button\";\n open.className = \"card-open\";\n open.setAttribute(\"aria-label\", options.label);\n\n const play = document.createElement(\"span\");\n play.className = \"play\";\n play.setAttribute(\"aria-hidden\", \"true\");\n play.append(createIcon(\"play\"));\n open.append(play);\n open.addEventListener(\"click\", options.onSelect);\n\n card.append(open);\n if (video) card.append(createSoundButton(video, options));\n }\n\n return card;\n}\n","import { createCard, playVideo } from \"../card\";\nimport { createIcon, type IconName } from \"../icons\";\nimport type { StoryMedia } from \"../../types\";\n\n// The player is a <dialog> shown in the top layer, so no store z-index,\n// overflow or transform can hide or move it.\n//\n// Mini: a manual popover (non-modal, the page stays usable), with the card at\n// the bottom right and the controls above it. Without popover support it is a\n// non-modal dialog, fixed with a high z-index.\n// Expanded: a modal dialog (showModal), so the browser makes the page behind\n// it inert. The card is centered over a dark backdrop, with the controls at\n// the top right of the screen. On narrow screens it fills the screen.\nexport const playerStyles = `\n .player {\n position: fixed;\n inset: auto 16px 16px auto;\n z-index: 2147483000;\n box-sizing: border-box;\n width: calc(min(587px, 100vh - 80px) * 9 / 16);\n height: min(587px, 100vh - 80px);\n margin: 0;\n padding: 0;\n overflow: visible;\n border: 0;\n background: transparent;\n color: inherit;\n font: inherit;\n animation: player-in 0.25s ease;\n }\n\n /* A <dialog> shown as a popover has no open attribute, which the browser\n hides by default. */\n .player:popover-open {\n display: block;\n }\n\n /* Switching modes shows the dialog again; only the first opening fades in. */\n .player[data-switched] {\n animation: none;\n }\n\n .player::backdrop {\n background: transparent;\n }\n\n .player-frame {\n position: relative;\n width: 100%;\n height: 100%;\n }\n\n .player .card {\n width: 100%;\n height: 100%;\n box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);\n }\n\n .player .card:has(.video) {\n cursor: pointer;\n }\n\n /* Play/pause reuses the card's glass .play button, as a real button. */\n .player-toggle {\n padding: 0;\n border: 0;\n color: #fff;\n font: inherit;\n cursor: pointer;\n }\n\n .player[data-paused] .player-toggle,\n .player-toggle:focus-visible {\n opacity: 1;\n transform: translate(-50%, -50%);\n }\n\n /* On touch, tapping the video pauses it; the button shows while paused. */\n @media (hover: none) {\n .player:not([data-paused]) .player-toggle {\n opacity: 0;\n }\n }\n\n .player-sound {\n position: absolute;\n top: 12px;\n right: 12px;\n z-index: 1;\n border-color: transparent;\n background: rgba(0, 0, 0, 0.3);\n }\n\n .player-sound .icon {\n width: 20px;\n height: 20px;\n }\n\n /* Above the card: on narrow screens the expanded card can cover them. */\n .player-controls {\n position: absolute;\n right: 0;\n bottom: calc(100% + 8px);\n z-index: 1;\n display: flex;\n gap: 8px;\n }\n\n .player-button {\n display: grid;\n width: 36px;\n height: 36px;\n place-items: center;\n padding: 0;\n border: 1px solid rgba(133, 133, 133, 0.3);\n border-radius: 50%;\n background: rgba(0, 0, 0, 0.32);\n backdrop-filter: blur(5px);\n color: #fff;\n cursor: pointer;\n transition: background-color 0.2s;\n }\n\n .player-button:hover {\n background: rgba(0, 0, 0, 0.55);\n }\n\n .player-button .icon {\n width: 18px;\n height: 18px;\n }\n\n .player[data-expanded] {\n inset: 0;\n display: grid;\n width: 100%;\n max-width: none;\n height: 100%;\n max-height: none;\n place-items: center;\n background: rgba(0, 0, 0, 0.85);\n animation: none;\n }\n\n .player[data-expanded] .player-frame {\n width: calc(min(78vh, 720px) * 9 / 16);\n height: min(78vh, 720px);\n }\n\n .player[data-expanded] .player-controls {\n position: fixed;\n top: 24px;\n right: 24px;\n bottom: auto;\n }\n\n .player[data-expanded] .player-button {\n width: 40px;\n height: 40px;\n }\n\n @media (max-width: 576px) {\n .player {\n right: 12px;\n width: 220px;\n height: 391px;\n }\n\n .player[data-expanded] {\n background: #000;\n }\n\n /* The video stays 9:16 and centered; the rest of the screen is black. */\n .player[data-expanded] .player-frame {\n width: min(100vw, 100vh * 9 / 16);\n height: min(100vh, 100vw * 16 / 9);\n }\n\n .player[data-expanded] .card {\n border-radius: 0;\n }\n\n /* Below the sound button, at the top right of the video. Placed in the\n video frame, not the screen: the frame is centered, so on screens\n taller than 9:16 its top is below the screen's. */\n .player[data-expanded] .player-controls {\n position: absolute;\n top: 60px;\n right: 12px;\n }\n }\n\n @keyframes player-in {\n from {\n opacity: 0;\n transform: translateY(8px);\n }\n }\n\n @media (prefers-reduced-motion: reduce) {\n .player {\n animation: none;\n }\n }\n`;\n\nexport interface PlayerOptions {\n /** Accessible name of the player. */\n label: string;\n /** Accessible names of the buttons. */\n expandLabel: string;\n collapseLabel: string;\n closeLabel: string;\n playLabel: string;\n pauseLabel: string;\n soundOnLabel: string;\n soundOffLabel: string;\n onClose: () => void;\n}\n\nfunction createButton(className: string, label: string, icon: IconName) {\n const button = document.createElement(\"button\");\n button.type = \"button\";\n button.className = `player-button ${className}`;\n button.setAttribute(\"aria-label\", label);\n button.append(createIcon(icon));\n return button;\n}\n\nfunction supportsPopover(player: HTMLDialogElement) {\n return typeof player.showPopover === \"function\";\n}\n\n/** Shows the player as the mini player. It must already be in the page. */\nexport function showPlayer(player: HTMLDialogElement) {\n if (supportsPopover(player)) player.showPopover();\n else player.show();\n}\n\n/** Plays the player's video, if it has one. */\nexport function playPlayer(player: HTMLDialogElement) {\n const video = player.querySelector(\"video\");\n if (video) playVideo(video);\n}\n\n/**\n * Play/pause in the middle of the video and sound on/off at its top right.\n * Clicking the video also plays or pauses it. The buttons follow the video's\n * own events, so a blocked autoplay shows as paused.\n */\nfunction addVideoControls(\n player: HTMLDialogElement,\n card: HTMLElement,\n video: HTMLVideoElement,\n options: PlayerOptions,\n) {\n // Not a .player-button: it keeps the card's larger glass look.\n const toggle = document.createElement(\"button\");\n toggle.type = \"button\";\n toggle.className = \"play player-toggle\";\n const sound = createButton(\"player-sound\", \"\", \"soundOff\");\n\n function syncPlayback() {\n player.toggleAttribute(\"data-paused\", video.paused);\n toggle.setAttribute(\n \"aria-label\",\n video.paused ? options.playLabel : options.pauseLabel,\n );\n toggle.replaceChildren(createIcon(video.paused ? \"play\" : \"pause\"));\n }\n\n function syncSound() {\n sound.setAttribute(\n \"aria-label\",\n video.muted ? options.soundOnLabel : options.soundOffLabel,\n );\n sound.replaceChildren(createIcon(video.muted ? \"soundOff\" : \"soundOn\"));\n }\n\n function togglePlayback() {\n if (video.paused) playVideo(video);\n else video.pause();\n }\n\n video.addEventListener(\"play\", syncPlayback);\n video.addEventListener(\"pause\", syncPlayback);\n video.addEventListener(\"volumechange\", syncSound);\n // Without the video, the cover stays and there is nothing to control.\n video.addEventListener(\"error\", () => {\n toggle.remove();\n sound.remove();\n delete player.dataset.paused;\n });\n\n toggle.addEventListener(\"click\", (event) => {\n event.stopPropagation();\n togglePlayback();\n });\n sound.addEventListener(\"click\", (event) => {\n event.stopPropagation();\n video.muted = !video.muted;\n });\n card.addEventListener(\"click\", () => {\n if (video.isConnected) togglePlayback();\n });\n\n syncPlayback();\n syncSound();\n card.append(toggle, sound);\n}\n\n/**\n * The Story player. It opens as the mini player (see showPlayer); expand\n * switches to the expanded view, a modal dialog, and back. Clicking the\n * backdrop of the expanded view or pressing Escape in it closes the player.\n * The video starts muted (see playPlayer).\n */\nexport function createPlayer(story: StoryMedia, options: PlayerOptions) {\n const player = document.createElement(\"dialog\");\n player.className = \"player\";\n player.setAttribute(\"popover\", \"manual\");\n player.setAttribute(\"aria-label\", options.label);\n\n const frame = document.createElement(\"div\");\n frame.className = \"player-frame\";\n\n const controls = document.createElement(\"div\");\n controls.className = \"player-controls\";\n\n const expand = createButton(\"player-expand\", options.expandLabel, \"expand\");\n const close = createButton(\"player-close\", options.closeLabel, \"close\");\n controls.append(expand, close);\n\n let expanded = false;\n\n // A dialog can't be shown as a popover and as a modal at the same time, so\n // switching modes hides it first, the same way it was shown.\n function hide() {\n if (!expanded && supportsPopover(player)) player.hidePopover();\n else player.close();\n }\n\n expand.addEventListener(\"click\", () => {\n hide();\n expanded = !expanded;\n player.toggleAttribute(\"data-expanded\", expanded);\n player.dataset.switched = \"\";\n expand.setAttribute(\n \"aria-label\",\n expanded ? options.collapseLabel : options.expandLabel,\n );\n expand.replaceChildren(createIcon(expanded ? \"collapse\" : \"expand\"));\n\n if (expanded) player.showModal();\n else showPlayer(player);\n expand.focus();\n });\n\n close.addEventListener(\"click\", options.onClose);\n\n // Clicks on the backdrop of the expanded view reach the dialog itself.\n player.addEventListener(\"click\", (event) => {\n if (expanded && event.target === player) options.onClose();\n });\n\n // Escape on a modal dialog would only hide it: close the player instead.\n player.addEventListener(\"cancel\", (event) => {\n event.preventDefault();\n options.onClose();\n });\n\n const card = createCard(story);\n const video = card.querySelector(\"video\");\n if (video) addVideoControls(player, card, video, options);\n\n frame.append(controls, card);\n player.append(frame);\n return player;\n}\n","import { cardStyles, createCard, playVideo } from \"../components/card\";\nimport {\n createPlayer,\n playerStyles,\n playPlayer,\n showPlayer,\n} from \"../components/player\";\nimport type { StoryMedia } from \"../types\";\n\nexport const TAG_NAME = \"vtex-ads-story\";\n\n// Keeps the module importable where HTMLElement doesn't exist (SSR, Node).\nconst BaseElement: typeof HTMLElement = globalThis.HTMLElement ?? Object;\n\nconst styles = `\n :host {\n display: block;\n font-family: var(--vtex-ads-story-font-family, inherit);\n color: var(--vtex-ads-story-color-text, inherit);\n }\n ${cardStyles}\n ${playerStyles}\n`;\n\n// Temporary: rendered until the element reads Stories from the ad API.\nconst PLACEHOLDER_STORY: StoryMedia = {\n poster_url: \"https://dummyimage.com/1080x1920/e31c57/fff\",\n media_url: \"https://samplelib.com/mp4/sample-10s-vp9.mp4\",\n};\n\n// Temporary: fixed texts until the store can set them by attribute.\nconst LABELS = {\n watch: \"Assistir vídeo\",\n player: \"Vídeo\",\n expand: \"Expandir vídeo\",\n collapse: \"Reduzir vídeo\",\n close: \"Fechar vídeo\",\n play: \"Reproduzir vídeo\",\n pause: \"Pausar vídeo\",\n soundOn: \"Ativar som\",\n soundOff: \"Desativar som\",\n};\n\nexport class VtexAdsStoryElement extends BaseElement {\n private player: HTMLDialogElement | null = null;\n\n private readonly onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") this.closePlayer();\n };\n\n private render() {\n const container = this.shadowRoot?.querySelector(\".root\");\n if (!container) return;\n\n container.replaceChildren(\n createCard(PLACEHOLDER_STORY, {\n label: LABELS.watch,\n soundOnLabel: LABELS.soundOn,\n soundOffLabel: LABELS.soundOff,\n onSelect: () => this.openPlayer(),\n }),\n );\n }\n\n private cardVideo() {\n return this.shadowRoot?.querySelector<HTMLVideoElement>(\n \".root .card video\",\n );\n }\n\n private openPlayer() {\n if (this.player || !this.shadowRoot) return;\n\n this.player = createPlayer(PLACEHOLDER_STORY, {\n label: LABELS.player,\n expandLabel: LABELS.expand,\n collapseLabel: LABELS.collapse,\n closeLabel: LABELS.close,\n playLabel: LABELS.play,\n pauseLabel: LABELS.pause,\n soundOnLabel: LABELS.soundOn,\n soundOffLabel: LABELS.soundOff,\n onClose: () => this.closePlayer(),\n });\n this.shadowRoot.append(this.player);\n showPlayer(this.player);\n // While the player is open, the card behind it stops on its cover.\n this.cardVideo()?.pause();\n playPlayer(this.player);\n document.addEventListener(\"keydown\", this.onKeyDown);\n\n this.player.querySelector<HTMLElement>(\".player-close\")?.focus();\n }\n\n // `removed`: the element is leaving the page, so there is no card to give\n // focus back to or to resume playing (it would play out of sight).\n private closePlayer({ removed = false } = {}) {\n if (!this.player) return;\n\n document.removeEventListener(\"keydown\", this.onKeyDown);\n this.player.remove();\n this.player = null;\n if (removed) return;\n\n const video = this.cardVideo();\n if (video?.autoplay) playVideo(video);\n\n this.shadowRoot?.querySelector<HTMLElement>(\".root .card-open\")?.focus();\n }\n\n connectedCallback() {\n if (!this.shadowRoot) {\n const root = this.attachShadow({ mode: \"open\" });\n root.innerHTML = `<style>${styles}</style><div class=\"root\"></div>`;\n }\n\n this.render();\n }\n\n disconnectedCallback() {\n this.closePlayer({ removed: true });\n }\n}\n\n// Types `document.createElement(\"vtex-ads-story\")` and `querySelector` results\n// as VtexAdsStoryElement in any TypeScript project, no framework needed.\ndeclare global {\n interface HTMLElementTagNameMap {\n \"vtex-ads-story\": VtexAdsStoryElement;\n }\n}\n\nexport function defineVtexAdsStories() {\n if (typeof customElements === \"undefined\") return;\n if (customElements.get(TAG_NAME)) return;\n\n customElements.define(TAG_NAME, VtexAdsStoryElement);\n}\n"],"mappings":";AAAA;;;ACAA;;;ACAA;;;ACAA;;;ACAA;;;ACAA;;;ACAA;;;ACaO,IAAM,QAAQ;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKO,SAAS,WAAW,MAAgB;AACzC,QAAM,WAAW,SAAS,cAAc,UAAU;AAClD,WAAS,YAAY,MAAM,IAAI;AAE/B,QAAM,MAAM,SAAS,QAAQ;AAC7B,MAAI,UAAU,IAAI,MAAM;AACxB,MAAI,aAAa,eAAe,MAAM;AACtC,MAAI,aAAa,aAAa,OAAO;AACrC,SAAO;AACT;;;AChCO,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AK,SAAS;AACd,QAAI,QAAS;AAEb,UAAM,QAAQ,KAAK,UAAU;AAC7B,QAAI,+BAAO,SAAU,WAAU,KAAK;AAEpC,WAAAA,MAAA,KAAK,eAAL,gBAAAA,IAAiB,cAA2B,wBAA5C,mBAAiE;AAAA,EACnE;AAAA,EAEA,oBAAoB;AAClB,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAC/C,WAAK,YAAY,UAAU,MAAM;AAAA,IACnC;AAEA,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,uBAAuB;AACrB,SAAK,YAAY,EAAE,SAAS,KAAK,CAAC;AAAA,EACpC;AACF;AAUO,SAAS,uBAAuB;AACrC,MAAI,OAAO,mBAAmB,YAAa;AAC3C,MAAI,eAAe,IAAI,QAAQ,EAAG;AAElC,iBAAe,OAAO,UAAU,mBAAmB;AACrD;","names":["_a","_a"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtex/ads-stories",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "description": "VTEX Ads Stories web component",
6
6
  "main": "dist/cjs/index.cjs",
7
7
  "module": "dist/esm/index.js",