@vtex/ads-stories 0.2.0 → 0.3.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
@@ -1,3 +1,339 @@
1
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/close.svg
2
+ var close_default = '<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';
3
+
4
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/collapse.svg
5
+ var collapse_default = '<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';
6
+
7
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/expand.svg
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
+
10
+ // raw:/workspace/source/ads-js/packages/ads-stories/src/components/icons/assets/play-fill.svg
11
+ 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
+
13
+ // src/components/icons/index.ts
14
+ var icons = { close: close_default, collapse: collapse_default, expand: expand_default, play: play_fill_default };
15
+ function createIcon(name) {
16
+ const template = document.createElement("template");
17
+ template.innerHTML = icons[name];
18
+ const svg = template.content.firstElementChild;
19
+ svg.classList.add("icon");
20
+ svg.setAttribute("aria-hidden", "true");
21
+ svg.setAttribute("focusable", "false");
22
+ return svg;
23
+ }
24
+
25
+ // src/components/card/card.ts
26
+ var cardStyles = `
27
+ .card {
28
+ position: relative;
29
+ box-sizing: border-box;
30
+ width: calc(500px * 9 / 16);
31
+ height: 500px;
32
+ overflow: hidden;
33
+ border-radius: var(--vtex-ads-story-radius, 20px);
34
+ background: #000;
35
+ }
36
+
37
+ .card[role="button"] {
38
+ cursor: pointer;
39
+ }
40
+
41
+ .poster {
42
+ position: absolute;
43
+ inset: 0;
44
+ width: 100%;
45
+ height: 100%;
46
+ object-fit: cover;
47
+ }
48
+
49
+ .play {
50
+ position: absolute;
51
+ top: 50%;
52
+ left: 50%;
53
+ display: grid;
54
+ width: 66px;
55
+ height: 66px;
56
+ place-items: center;
57
+ border-radius: 50%;
58
+ background:
59
+ linear-gradient(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.06)),
60
+ rgba(255, 255, 255, 0.15);
61
+ backdrop-filter: blur(2px);
62
+ box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.42);
63
+ transform: translate(-50%, -50%);
64
+ transition:
65
+ opacity 0.3s ease,
66
+ transform 0.3s ease;
67
+ }
68
+
69
+ /* The icon's triangle is 18px tall and already sits slightly right of its
70
+ box, so it looks centered in the circle. */
71
+ .play .icon {
72
+ width: 22px;
73
+ height: 22px;
74
+ color: #fff;
75
+ }
76
+
77
+ /* With a mouse, the play button shows only on hover or keyboard focus.
78
+ Touch screens have no hover, so it stays visible there. */
79
+ @media (hover: hover) and (pointer: fine) {
80
+ .play {
81
+ opacity: 0;
82
+ transform: translate(-50%, -50%) scale(0.9);
83
+ }
84
+
85
+ .card:hover .play,
86
+ .card:focus-visible .play {
87
+ opacity: 1;
88
+ transform: translate(-50%, -50%);
89
+ }
90
+ }
91
+ `;
92
+ function isHttpUrl(value) {
93
+ try {
94
+ const { protocol } = new URL(value);
95
+ return protocol === "https:" || protocol === "http:";
96
+ } catch (e) {
97
+ return false;
98
+ }
99
+ }
100
+ function createCard(story, options) {
101
+ const card = document.createElement("div");
102
+ card.className = "card";
103
+ if (story.poster_url && isHttpUrl(story.poster_url)) {
104
+ const poster = document.createElement("img");
105
+ poster.className = "poster";
106
+ poster.alt = "";
107
+ poster.src = story.poster_url;
108
+ card.append(poster);
109
+ }
110
+ if (options) {
111
+ card.setAttribute("role", "button");
112
+ card.setAttribute("aria-label", options.label);
113
+ card.tabIndex = 0;
114
+ const play = document.createElement("span");
115
+ play.className = "play";
116
+ play.setAttribute("aria-hidden", "true");
117
+ 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
+ });
125
+ }
126
+ return card;
127
+ }
128
+
129
+ // src/components/player/player.ts
130
+ var playerStyles = `
131
+ .player {
132
+ position: fixed;
133
+ inset: auto 16px 16px auto;
134
+ z-index: 2147483000;
135
+ box-sizing: border-box;
136
+ width: calc(min(587px, 100vh - 80px) * 9 / 16);
137
+ height: min(587px, 100vh - 80px);
138
+ margin: 0;
139
+ padding: 0;
140
+ overflow: visible;
141
+ border: 0;
142
+ background: transparent;
143
+ color: inherit;
144
+ font: inherit;
145
+ animation: player-in 0.25s ease;
146
+ }
147
+
148
+ /* A <dialog> shown as a popover has no open attribute, which the browser
149
+ hides by default. */
150
+ .player:popover-open {
151
+ display: block;
152
+ }
153
+
154
+ /* Switching modes shows the dialog again; only the first opening fades in. */
155
+ .player[data-switched] {
156
+ animation: none;
157
+ }
158
+
159
+ .player::backdrop {
160
+ background: transparent;
161
+ }
162
+
163
+ .player-frame {
164
+ position: relative;
165
+ width: 100%;
166
+ height: 100%;
167
+ }
168
+
169
+ .player .card {
170
+ width: 100%;
171
+ height: 100%;
172
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
173
+ }
174
+
175
+ /* Above the card: on narrow screens the expanded card can cover them. */
176
+ .player-controls {
177
+ position: absolute;
178
+ right: 0;
179
+ bottom: calc(100% + 8px);
180
+ z-index: 1;
181
+ display: flex;
182
+ gap: 8px;
183
+ }
184
+
185
+ .player-button {
186
+ display: grid;
187
+ width: 36px;
188
+ height: 36px;
189
+ place-items: center;
190
+ padding: 0;
191
+ border: 1px solid rgba(133, 133, 133, 0.3);
192
+ border-radius: 50%;
193
+ background: rgba(0, 0, 0, 0.32);
194
+ backdrop-filter: blur(5px);
195
+ color: #fff;
196
+ cursor: pointer;
197
+ transition: background-color 0.2s;
198
+ }
199
+
200
+ .player-button:hover {
201
+ background: rgba(0, 0, 0, 0.55);
202
+ }
203
+
204
+ .player-button .icon {
205
+ width: 18px;
206
+ height: 18px;
207
+ }
208
+
209
+ .player[data-expanded] {
210
+ inset: 0;
211
+ display: grid;
212
+ width: 100%;
213
+ max-width: none;
214
+ height: 100%;
215
+ max-height: none;
216
+ place-items: center;
217
+ background: rgba(0, 0, 0, 0.85);
218
+ animation: none;
219
+ }
220
+
221
+ .player[data-expanded] .player-frame {
222
+ width: calc(min(78vh, 720px) * 9 / 16);
223
+ height: min(78vh, 720px);
224
+ }
225
+
226
+ .player[data-expanded] .player-controls {
227
+ position: fixed;
228
+ top: 24px;
229
+ right: 24px;
230
+ bottom: auto;
231
+ }
232
+
233
+ .player[data-expanded] .player-button {
234
+ width: 40px;
235
+ height: 40px;
236
+ }
237
+
238
+ @media (max-width: 576px) {
239
+ .player {
240
+ right: 12px;
241
+ width: 220px;
242
+ height: 391px;
243
+ }
244
+
245
+ .player[data-expanded] {
246
+ background: #000;
247
+ }
248
+
249
+ /* The video stays 9:16 and centered; the rest of the screen is black. */
250
+ .player[data-expanded] .player-frame {
251
+ width: min(100vw, 100vh * 9 / 16);
252
+ height: min(100vh, 100vw * 16 / 9);
253
+ }
254
+
255
+ .player[data-expanded] .card {
256
+ border-radius: 0;
257
+ }
258
+
259
+ .player[data-expanded] .player-controls {
260
+ top: 12px;
261
+ right: 12px;
262
+ }
263
+ }
264
+
265
+ @keyframes player-in {
266
+ from {
267
+ opacity: 0;
268
+ transform: translateY(8px);
269
+ }
270
+ }
271
+
272
+ @media (prefers-reduced-motion: reduce) {
273
+ .player {
274
+ animation: none;
275
+ }
276
+ }
277
+ `;
278
+ function createButton(className, label, icon) {
279
+ const button = document.createElement("button");
280
+ button.type = "button";
281
+ button.className = `player-button ${className}`;
282
+ button.setAttribute("aria-label", label);
283
+ button.append(createIcon(icon));
284
+ return button;
285
+ }
286
+ function supportsPopover(player) {
287
+ return typeof player.showPopover === "function";
288
+ }
289
+ function showPlayer(player) {
290
+ if (supportsPopover(player)) player.showPopover();
291
+ else player.show();
292
+ }
293
+ function createPlayer(story, options) {
294
+ const player = document.createElement("dialog");
295
+ player.className = "player";
296
+ player.setAttribute("popover", "manual");
297
+ player.setAttribute("aria-label", options.label);
298
+ const frame = document.createElement("div");
299
+ frame.className = "player-frame";
300
+ const controls = document.createElement("div");
301
+ controls.className = "player-controls";
302
+ const expand = createButton("player-expand", options.expandLabel, "expand");
303
+ const close = createButton("player-close", options.closeLabel, "close");
304
+ controls.append(expand, close);
305
+ let expanded = false;
306
+ function hide() {
307
+ if (!expanded && supportsPopover(player)) player.hidePopover();
308
+ else player.close();
309
+ }
310
+ expand.addEventListener("click", () => {
311
+ hide();
312
+ expanded = !expanded;
313
+ player.toggleAttribute("data-expanded", expanded);
314
+ player.dataset.switched = "";
315
+ expand.setAttribute(
316
+ "aria-label",
317
+ expanded ? options.collapseLabel : options.expandLabel
318
+ );
319
+ expand.replaceChildren(createIcon(expanded ? "collapse" : "expand"));
320
+ if (expanded) player.showModal();
321
+ else showPlayer(player);
322
+ expand.focus();
323
+ });
324
+ close.addEventListener("click", options.onClose);
325
+ player.addEventListener("click", (event) => {
326
+ if (expanded && event.target === player) options.onClose();
327
+ });
328
+ player.addEventListener("cancel", (event) => {
329
+ event.preventDefault();
330
+ options.onClose();
331
+ });
332
+ frame.append(controls, createCard(story));
333
+ player.append(frame);
334
+ return player;
335
+ }
336
+
1
337
  // src/story/story.ts
2
338
  var TAG_NAME = "vtex-ads-story";
3
339
  var _a;
@@ -8,44 +344,73 @@ var styles = `
8
344
  font-family: var(--vtex-ads-story-font-family, inherit);
9
345
  color: var(--vtex-ads-story-color-text, inherit);
10
346
  }
347
+ ${cardStyles}
348
+ ${playerStyles}
11
349
  `;
12
- var DEFAULT_NAME = "world";
350
+ var PLACEHOLDER_STORY = {
351
+ ad_id: "placeholder",
352
+ poster_url: "https://dummyimage.com/1080x1920/e31c57/fff"
353
+ };
354
+ var LABELS = {
355
+ watch: "Assistir v\xEDdeo",
356
+ player: "V\xEDdeo",
357
+ expand: "Expandir v\xEDdeo",
358
+ collapse: "Reduzir v\xEDdeo",
359
+ close: "Fechar v\xEDdeo"
360
+ };
13
361
  var VtexAdsStoryElement = class extends BaseElement {
14
- static get observedAttributes() {
15
- return ["name"];
16
- }
17
- get name() {
18
- var _a2, _b;
19
- return (_b = (_a2 = this.getAttribute("name")) == null ? void 0 : _a2.trim()) != null ? _b : "";
20
- }
21
- set name(value) {
22
- this.setAttribute("name", value);
362
+ constructor() {
363
+ super(...arguments);
364
+ this.player = null;
365
+ this.onKeyDown = (event) => {
366
+ if (event.key === "Escape") this.closePlayer();
367
+ };
23
368
  }
24
369
  render() {
25
370
  var _a2;
26
- const container = (_a2 = this.shadowRoot) == null ? void 0 : _a2.querySelector("[part='root']");
371
+ const container = (_a2 = this.shadowRoot) == null ? void 0 : _a2.querySelector(".root");
27
372
  if (!container) return;
28
- container.textContent = `Hello ${this.name || DEFAULT_NAME}!`;
373
+ container.replaceChildren(
374
+ createCard(PLACEHOLDER_STORY, {
375
+ label: LABELS.watch,
376
+ onSelect: () => this.openPlayer()
377
+ })
378
+ );
379
+ }
380
+ openPlayer() {
381
+ var _a2;
382
+ if (this.player || !this.shadowRoot) return;
383
+ this.player = createPlayer(PLACEHOLDER_STORY, {
384
+ label: LABELS.player,
385
+ expandLabel: LABELS.expand,
386
+ collapseLabel: LABELS.collapse,
387
+ closeLabel: LABELS.close,
388
+ onClose: () => this.closePlayer()
389
+ });
390
+ this.shadowRoot.append(this.player);
391
+ showPlayer(this.player);
392
+ document.addEventListener("keydown", this.onKeyDown);
393
+ (_a2 = this.player.querySelector(".player-close")) == null ? void 0 : _a2.focus();
394
+ }
395
+ closePlayer({ restoreFocus = true } = {}) {
396
+ var _a2, _b;
397
+ if (!this.player) return;
398
+ document.removeEventListener("keydown", this.onKeyDown);
399
+ this.player.remove();
400
+ this.player = null;
401
+ if (restoreFocus) {
402
+ (_b = (_a2 = this.shadowRoot) == null ? void 0 : _a2.querySelector(".root .card")) == null ? void 0 : _b.focus();
403
+ }
29
404
  }
30
405
  connectedCallback() {
31
406
  if (!this.shadowRoot) {
32
407
  const root = this.attachShadow({ mode: "open" });
33
- root.innerHTML = `<style>${styles}</style><div part="root"></div>`;
408
+ root.innerHTML = `<style>${styles}</style><div class="root"></div>`;
34
409
  }
35
- this.upgradeProperty("name");
36
410
  this.render();
37
411
  }
38
- // A property set before the element is defined (e.g. while the CDN script
39
- // loads) becomes an own property that shadows the class getter/setter.
40
- // Remove it and set it again so it goes through the setter.
41
- upgradeProperty(prop) {
42
- if (!Object.prototype.hasOwnProperty.call(this, prop)) return;
43
- const value = this[prop];
44
- Reflect.deleteProperty(this, prop);
45
- this[prop] = value;
46
- }
47
- attributeChangedCallback() {
48
- this.render();
412
+ disconnectedCallback() {
413
+ this.closePlayer({ restoreFocus: false });
49
414
  }
50
415
  };
51
416
  function defineVtexAdsStories() {
@@ -58,4 +423,5 @@ export {
58
423
  VtexAdsStoryElement,
59
424
  defineVtexAdsStories
60
425
  };
426
+ /*! Icons from Phosphor Icons (https://phosphoricons.com), MIT License, Copyright (c) 2023 Phosphor Icons */
61
427
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/story/story.ts"],"sourcesContent":["export 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`;\n\nconst DEFAULT_NAME = \"world\";\n\nexport class VtexAdsStoryElement extends BaseElement {\n static get observedAttributes() {\n return [\"name\"];\n }\n\n get name(): string {\n return this.getAttribute(\"name\")?.trim() ?? \"\";\n }\n\n set name(value: string) {\n this.setAttribute(\"name\", value);\n }\n\n private render() {\n const container = this.shadowRoot?.querySelector(\"[part='root']\");\n if (!container) return;\n\n // textContent keeps the name as plain text (no HTML injection).\n container.textContent = `Hello ${this.name || DEFAULT_NAME}!`;\n }\n\n connectedCallback() {\n if (!this.shadowRoot) {\n const root = this.attachShadow({ mode: \"open\" });\n root.innerHTML = `<style>${styles}</style><div part=\"root\"></div>`;\n }\n\n this.upgradeProperty(\"name\");\n this.render();\n }\n\n // A property set before the element is defined (e.g. while the CDN script\n // loads) becomes an own property that shadows the class getter/setter.\n // Remove it and set it again so it goes through the setter.\n private upgradeProperty(prop: \"name\") {\n if (!Object.prototype.hasOwnProperty.call(this, prop)) return;\n\n const value = this[prop];\n Reflect.deleteProperty(this, prop);\n this[prop] = value;\n }\n\n attributeChangedCallback() {\n this.render();\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":";AAAO,IAAM,WAAW;AAAxB;AAGA,IAAM,eAAkC,gBAAW,gBAAX,YAA0B;AAElE,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQf,IAAM,eAAe;AAEd,IAAM,sBAAN,cAAkC,YAAY;AAAA,EACnD,WAAW,qBAAqB;AAC9B,WAAO,CAAC,MAAM;AAAA,EAChB;AAAA,EAEA,IAAI,OAAe;AApBrB,QAAAA,KAAA;AAqBI,YAAO,MAAAA,MAAA,KAAK,aAAa,MAAM,MAAxB,gBAAAA,IAA2B,WAA3B,YAAqC;AAAA,EAC9C;AAAA,EAEA,IAAI,KAAK,OAAe;AACtB,SAAK,aAAa,QAAQ,KAAK;AAAA,EACjC;AAAA,EAEQ,SAAS;AA5BnB,QAAAA;AA6BI,UAAM,aAAYA,MAAA,KAAK,eAAL,gBAAAA,IAAiB,cAAc;AACjD,QAAI,CAAC,UAAW;AAGhB,cAAU,cAAc,SAAS,KAAK,QAAQ,YAAY;AAAA,EAC5D;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,gBAAgB,MAAM;AAC3B,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKQ,gBAAgB,MAAc;AACpC,QAAI,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,IAAI,EAAG;AAEvD,UAAM,QAAQ,KAAK,IAAI;AACvB,YAAQ,eAAe,MAAM,IAAI;AACjC,SAAK,IAAI,IAAI;AAAA,EACf;AAAA,EAEA,2BAA2B;AACzB,SAAK,OAAO;AAAA,EACd;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/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;AA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;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,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"]}
@@ -11,10 +11,7 @@ import { VtexAdsStoryElement } from './index.js';
11
11
  * or add "@vtex/ads-stories/react" to `compilerOptions.types` in tsconfig.
12
12
  */
13
13
 
14
- type VtexAdsStoryProps = DetailedHTMLProps<HTMLAttributes<VtexAdsStoryElement>, VtexAdsStoryElement> & {
15
- /** Name shown in the greeting; falls back to "world" when empty. */
16
- name?: string;
17
- };
14
+ type VtexAdsStoryProps = DetailedHTMLProps<HTMLAttributes<VtexAdsStoryElement>, VtexAdsStoryElement>;
18
15
  declare module "react" {
19
16
  namespace JSX {
20
17
  interface IntrinsicElements {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtex/ads-stories",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "description": "VTEX Ads Stories web component",
6
6
  "main": "dist/cjs/index.cjs",
7
7
  "module": "dist/esm/index.js",
@@ -38,6 +38,7 @@
38
38
  "dist",
39
39
  "src",
40
40
  "!src/**/*.test.ts",
41
+ "!src/**/*.mock.ts",
41
42
  "README.md",
42
43
  "CHANGELOG.md"
43
44
  ],
@@ -0,0 +1,124 @@
1
+ import { createIcon } from "../icons";
2
+ import type { StoryAd } from "../../types";
3
+
4
+ export const cardStyles = `
5
+ .card {
6
+ position: relative;
7
+ box-sizing: border-box;
8
+ width: calc(500px * 9 / 16);
9
+ height: 500px;
10
+ overflow: hidden;
11
+ border-radius: var(--vtex-ads-story-radius, 20px);
12
+ background: #000;
13
+ }
14
+
15
+ .card[role="button"] {
16
+ cursor: pointer;
17
+ }
18
+
19
+ .poster {
20
+ position: absolute;
21
+ inset: 0;
22
+ width: 100%;
23
+ height: 100%;
24
+ object-fit: cover;
25
+ }
26
+
27
+ .play {
28
+ position: absolute;
29
+ top: 50%;
30
+ left: 50%;
31
+ display: grid;
32
+ width: 66px;
33
+ height: 66px;
34
+ place-items: center;
35
+ border-radius: 50%;
36
+ background:
37
+ linear-gradient(rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.06)),
38
+ rgba(255, 255, 255, 0.15);
39
+ backdrop-filter: blur(2px);
40
+ box-shadow: inset 0 0 3px rgba(255, 255, 255, 0.42);
41
+ transform: translate(-50%, -50%);
42
+ transition:
43
+ opacity 0.3s ease,
44
+ transform 0.3s ease;
45
+ }
46
+
47
+ /* The icon's triangle is 18px tall and already sits slightly right of its
48
+ box, so it looks centered in the circle. */
49
+ .play .icon {
50
+ width: 22px;
51
+ height: 22px;
52
+ color: #fff;
53
+ }
54
+
55
+ /* With a mouse, the play button shows only on hover or keyboard focus.
56
+ Touch screens have no hover, so it stays visible there. */
57
+ @media (hover: hover) and (pointer: fine) {
58
+ .play {
59
+ opacity: 0;
60
+ transform: translate(-50%, -50%) scale(0.9);
61
+ }
62
+
63
+ .card:hover .play,
64
+ .card:focus-visible .play {
65
+ opacity: 1;
66
+ transform: translate(-50%, -50%);
67
+ }
68
+ }
69
+ `;
70
+
71
+ export interface CardOptions {
72
+ /** Accessible name of the card. */
73
+ label: string;
74
+ /** Called on click, Enter or Space. */
75
+ onSelect: () => void;
76
+ }
77
+
78
+ // Only absolute http(s) URLs reach the DOM.
79
+ function isHttpUrl(value: string) {
80
+ try {
81
+ const { protocol } = new URL(value);
82
+ return protocol === "https:" || protocol === "http:";
83
+ } catch {
84
+ return false;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * A 9:16 card with the Story cover. With options, the card is a button with
90
+ * a play icon in the middle.
91
+ */
92
+ export function createCard(story: StoryAd, options?: CardOptions) {
93
+ const card = document.createElement("div");
94
+ card.className = "card";
95
+
96
+ if (story.poster_url && isHttpUrl(story.poster_url)) {
97
+ const poster = document.createElement("img");
98
+ poster.className = "poster";
99
+ poster.alt = "";
100
+ poster.src = story.poster_url;
101
+ card.append(poster);
102
+ }
103
+
104
+ if (options) {
105
+ card.setAttribute("role", "button");
106
+ card.setAttribute("aria-label", options.label);
107
+ card.tabIndex = 0;
108
+
109
+ const play = document.createElement("span");
110
+ play.className = "play";
111
+ play.setAttribute("aria-hidden", "true");
112
+ play.append(createIcon("play"));
113
+ card.append(play);
114
+
115
+ card.addEventListener("click", options.onSelect);
116
+ card.addEventListener("keydown", (event) => {
117
+ if (event.key !== "Enter" && event.key !== " ") return;
118
+ event.preventDefault();
119
+ options.onSelect();
120
+ });
121
+ }
122
+
123
+ return card;
124
+ }
@@ -0,0 +1,2 @@
1
+ export { createCard, cardStyles } from "./card";
2
+ export type { CardOptions } from "./card";
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Phosphor Icons
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ <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>