@vtex/ads-stories 0.4.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +44 -88
  3. package/dist/cdn/vtex-ads-stories.js +1313 -74
  4. package/dist/cdn/vtex-ads-stories.js.map +1 -1
  5. package/dist/cjs/index.cjs +3744 -513
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/index.d.cts +46 -15
  8. package/dist/cjs/react.cjs.map +1 -1
  9. package/dist/cjs/react.d.cts +51 -5
  10. package/dist/cjs/story-DAiAN9v-.d.cts +260 -0
  11. package/dist/esm/index.d.ts +46 -15
  12. package/dist/esm/index.js +3348 -217
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/react.d.ts +51 -5
  15. package/dist/esm/story-DAiAN9v-.d.ts +260 -0
  16. package/package.json +18 -4
  17. package/src/cdn.ts +7 -3
  18. package/src/commerce-events.ts +93 -0
  19. package/src/components/card/card.ts +79 -14
  20. package/src/components/carousel/carousel-skeleton.ts +113 -0
  21. package/src/components/carousel/carousel.ts +715 -0
  22. package/src/components/carousel/index.ts +22 -0
  23. package/src/components/events/events-controller.ts +222 -0
  24. package/src/components/events/index.ts +6 -0
  25. package/src/components/icons/assets/caret-left-bold.svg +1 -0
  26. package/src/components/icons/assets/caret-right-bold.svg +1 -0
  27. package/src/components/icons/assets/caret-up-bold.svg +1 -0
  28. package/src/components/icons/assets/minus.svg +1 -0
  29. package/src/components/icons/assets/plus.svg +1 -0
  30. package/src/components/icons/assets/trash.svg +1 -0
  31. package/src/components/icons/assets/warning-circle-fill.svg +1 -0
  32. package/src/components/icons/index.ts +14 -0
  33. package/src/components/media/index.ts +8 -1
  34. package/src/components/media/media.styles.ts +113 -0
  35. package/src/components/media/media.ts +124 -23
  36. package/src/components/media/video-controller.ts +127 -6
  37. package/src/components/player/index.ts +6 -2
  38. package/src/components/player/player.ts +824 -50
  39. package/src/components/product/cta.ts +56 -0
  40. package/src/components/product/index.ts +22 -0
  41. package/src/components/product/price.ts +86 -0
  42. package/src/components/product/product.styles.ts +426 -0
  43. package/src/components/product/product.ts +336 -0
  44. package/src/index.ts +17 -1
  45. package/src/locales/en.ts +39 -0
  46. package/src/locales/es.ts +40 -0
  47. package/src/locales/index.ts +36 -0
  48. package/src/locales/pt.ts +39 -0
  49. package/src/locales/types.ts +44 -0
  50. package/src/react.ts +55 -7
  51. package/src/story/index.ts +5 -1
  52. package/src/story/story.ts +679 -49
  53. package/src/tag-name.ts +1 -0
  54. package/src/types.ts +8 -12
  55. package/src/utils/fetch-story.ts +113 -0
  56. package/src/utils/hydrate-products.ts +112 -0
  57. package/src/utils/media-ready.ts +58 -0
  58. package/src/utils/safe-url.ts +36 -0
  59. package/src/utils/send-event.ts +71 -0
  60. package/src/utils/with-timeout.ts +43 -0
@@ -1,21 +1,52 @@
1
- import * as lit from 'lit';
2
- import { LitElement } from 'lit';
1
+ export { S as StoryHydration, a as StoryProductDetails, T as TAG_NAME, V as VtexAdsStoryCarouselElement, d as defineVtexAdsStoryCarousel } from './story-DAiAN9v-.cjs';
2
+ import 'lit';
3
+ import '@vtex/ads-core';
3
4
 
4
- declare const TAG_NAME = "vtex-ads-story";
5
- declare class VtexAdsStoryElement extends LitElement {
6
- static readonly styles: lit.CSSResult[];
7
- private readonly cardVideo;
8
- private readonly player;
9
- connectedCallback(): void;
10
- private openPlayer;
11
- private closePlayer;
12
- protected render(): lit.TemplateResult<1>;
5
+ /**
6
+ * The commerce events the element hands to the store: it has no cart of its
7
+ * own. They bubble and cross shadow roots, so the store can listen on the
8
+ * element, the document or any ancestor.
9
+ */
10
+ /**
11
+ * Add to cart, or the stepper's plus, was clicked in the player. No default
12
+ * action.
13
+ */
14
+ declare const ADD_TO_CART_EVENT = "vtex-ads-story:add-to-cart";
15
+ /**
16
+ * The stepper's minus, or its trash with one left, was clicked in the
17
+ * player. No default action.
18
+ */
19
+ declare const REMOVE_FROM_CART_EVENT = "vtex-ads-story:remove-from-cart";
20
+ interface StoryCartEventDetail {
21
+ /** The Story product's SKU, from the ad API (`product.product_sku`). */
22
+ sku: string;
23
+ /**
24
+ * The product's seller, from the ad API (`product.seller_id`). Missing
25
+ * when the ad API doesn't send one.
26
+ */
27
+ seller?: string;
28
+ /** How many to add (or, removing, to remove). Always 1 for now. */
29
+ quantity: number;
13
30
  }
31
+ /** The detail of the add to cart event: `quantity` is how many to add. */
32
+ type StoryAddToCartDetail = StoryCartEventDetail;
33
+ /** The detail of remove from cart: `quantity` is how many to remove. */
34
+ type StoryRemoveFromCartDetail = StoryCartEventDetail;
35
+ type StoryAddToCartEvent = CustomEvent<StoryAddToCartDetail>;
36
+ type StoryRemoveFromCartEvent = CustomEvent<StoryRemoveFromCartDetail>;
14
37
  declare global {
15
- interface HTMLElementTagNameMap {
16
- "vtex-ads-story": VtexAdsStoryElement;
38
+ interface HTMLElementEventMap {
39
+ [ADD_TO_CART_EVENT]: StoryAddToCartEvent;
40
+ [REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
41
+ }
42
+ interface DocumentEventMap {
43
+ [ADD_TO_CART_EVENT]: StoryAddToCartEvent;
44
+ [REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
45
+ }
46
+ interface WindowEventMap {
47
+ [ADD_TO_CART_EVENT]: StoryAddToCartEvent;
48
+ [REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
17
49
  }
18
50
  }
19
- declare function defineVtexAdsStories(): void;
20
51
 
21
- export { TAG_NAME, VtexAdsStoryElement, defineVtexAdsStories };
52
+ export { ADD_TO_CART_EVENT, REMOVE_FROM_CART_EVENT, type StoryAddToCartDetail, type StoryAddToCartEvent, type StoryRemoveFromCartDetail, type StoryRemoveFromCartEvent };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react.ts"],"sourcesContent":["/**\n * React JSX types for <vtex-ads-story>. Types only: the JS output is empty.\n *\n * Opt in once per project, so non-React projects never need @types/react:\n *\n * import type {} from \"@vtex/ads-stories/react\";\n *\n * or add \"@vtex/ads-stories/react\" to `compilerOptions.types` in tsconfig.\n */\nimport type { DetailedHTMLProps, HTMLAttributes } from \"react\";\nimport type { VtexAdsStoryElement } from \"./story\";\n\nexport type VtexAdsStoryProps = DetailedHTMLProps<\n HTMLAttributes<VtexAdsStoryElement>,\n VtexAdsStoryElement\n>;\n\ndeclare module \"react\" {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n \"vtex-ads-story\": VtexAdsStoryProps;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/react.ts"],"sourcesContent":["/**\n * React JSX types for <vtex-ads-story-carousel>. Types only: the JS output\n * is empty.\n *\n * Opt in once per project, so non-React projects never need @types/react:\n *\n * import type {} from \"@vtex/ads-stories/react\";\n *\n * or add \"@vtex/ads-stories/react\" to `compilerOptions.types` in tsconfig.\n */\nimport type { DetailedHTMLProps, HTMLAttributes } from \"react\";\nimport type { Channel } from \"@vtex/ads-core\";\nimport type { TAG_NAME, VtexAdsStoryCarouselElement } from \"./story\";\n\n/**\n * The element's own attributes. The required ones match the README: without\n * them, the element requests nothing and renders nothing.\n */\nexport interface VtexAdsStoryCarouselAttributes {\n /** The publisher the ads are requested for. */\n \"publisher-id\": string;\n /** The store's session, also used to deduplicate events. */\n \"session-id\": string;\n /** The Story placement configured for the publisher. */\n placement: string;\n \"user-id\"?: string;\n \"account-name\"?: string;\n /** `site` or `app`. */\n channel?: Channel;\n /** Time limit for the ad request, in milliseconds (default 2000). */\n timeout?: number;\n /** How many Stories to ask for: the carousel positions (default 8). */\n quantity?: number;\n /** Currency of the prices, ISO 4217 (\"BRL\"). Default BRL. */\n currency?: string;\n /** The add to cart button's text. Default in the element's language. */\n \"label-add-to-cart\"?: string;\n /** The view product button's text. Default in the element's language. */\n \"label-view-product\"?: string;\n /**\n * \"none\": no product request. To set a strategy, assign the element's\n * `hydration` property. Missing: Intelligent Search with `account-name`.\n */\n hydration?: \"none\";\n /** Time limit for the product request, in milliseconds (default 5000). */\n \"hydration-timeout\"?: number;\n /**\n * With more than one Story, the cards without the highlight also play\n * their video, muted. Off by default.\n */\n \"inactive-autoplay\"?: boolean;\n /**\n * With more than one Story, how long each one stays highlighted, in\n * milliseconds (default 5000). 0: no automatic advance. Never advances on\n * its own for people who prefer reduced motion.\n */\n \"slide-duration\"?: number;\n}\n\nexport type VtexAdsStoryCarouselProps = DetailedHTMLProps<\n HTMLAttributes<VtexAdsStoryCarouselElement>,\n VtexAdsStoryCarouselElement\n> &\n VtexAdsStoryCarouselAttributes;\n\ndeclare module \"react\" {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n [TAG_NAME]: VtexAdsStoryCarouselProps;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,9 +1,11 @@
1
1
  import { DetailedHTMLProps, HTMLAttributes } from 'react';
2
- import { VtexAdsStoryElement } from './index.cjs';
2
+ import { Channel } from '@vtex/ads-core';
3
+ import { T as TAG_NAME, V as VtexAdsStoryCarouselElement } from './story-DAiAN9v-.cjs';
3
4
  import 'lit';
4
5
 
5
6
  /**
6
- * React JSX types for <vtex-ads-story>. Types only: the JS output is empty.
7
+ * React JSX types for <vtex-ads-story-carousel>. Types only: the JS output
8
+ * is empty.
7
9
  *
8
10
  * Opt in once per project, so non-React projects never need @types/react:
9
11
  *
@@ -12,13 +14,57 @@ import 'lit';
12
14
  * or add "@vtex/ads-stories/react" to `compilerOptions.types` in tsconfig.
13
15
  */
14
16
 
15
- type VtexAdsStoryProps = DetailedHTMLProps<HTMLAttributes<VtexAdsStoryElement>, VtexAdsStoryElement>;
17
+ /**
18
+ * The element's own attributes. The required ones match the README: without
19
+ * them, the element requests nothing and renders nothing.
20
+ */
21
+ interface VtexAdsStoryCarouselAttributes {
22
+ /** The publisher the ads are requested for. */
23
+ "publisher-id": string;
24
+ /** The store's session, also used to deduplicate events. */
25
+ "session-id": string;
26
+ /** The Story placement configured for the publisher. */
27
+ placement: string;
28
+ "user-id"?: string;
29
+ "account-name"?: string;
30
+ /** `site` or `app`. */
31
+ channel?: Channel;
32
+ /** Time limit for the ad request, in milliseconds (default 2000). */
33
+ timeout?: number;
34
+ /** How many Stories to ask for: the carousel positions (default 8). */
35
+ quantity?: number;
36
+ /** Currency of the prices, ISO 4217 ("BRL"). Default BRL. */
37
+ currency?: string;
38
+ /** The add to cart button's text. Default in the element's language. */
39
+ "label-add-to-cart"?: string;
40
+ /** The view product button's text. Default in the element's language. */
41
+ "label-view-product"?: string;
42
+ /**
43
+ * "none": no product request. To set a strategy, assign the element's
44
+ * `hydration` property. Missing: Intelligent Search with `account-name`.
45
+ */
46
+ hydration?: "none";
47
+ /** Time limit for the product request, in milliseconds (default 5000). */
48
+ "hydration-timeout"?: number;
49
+ /**
50
+ * With more than one Story, the cards without the highlight also play
51
+ * their video, muted. Off by default.
52
+ */
53
+ "inactive-autoplay"?: boolean;
54
+ /**
55
+ * With more than one Story, how long each one stays highlighted, in
56
+ * milliseconds (default 5000). 0: no automatic advance. Never advances on
57
+ * its own for people who prefer reduced motion.
58
+ */
59
+ "slide-duration"?: number;
60
+ }
61
+ type VtexAdsStoryCarouselProps = DetailedHTMLProps<HTMLAttributes<VtexAdsStoryCarouselElement>, VtexAdsStoryCarouselElement> & VtexAdsStoryCarouselAttributes;
16
62
  declare module "react" {
17
63
  namespace JSX {
18
64
  interface IntrinsicElements {
19
- "vtex-ads-story": VtexAdsStoryProps;
65
+ [TAG_NAME]: VtexAdsStoryCarouselProps;
20
66
  }
21
67
  }
22
68
  }
23
69
 
24
- export type { VtexAdsStoryProps };
70
+ export type { VtexAdsStoryCarouselAttributes, VtexAdsStoryCarouselProps };
@@ -0,0 +1,260 @@
1
+ import * as lit from 'lit';
2
+ import { LitElement, PropertyValues, nothing } from 'lit';
3
+ import { ProductFetcher, Offer, ProductPrice, Channel } from '@vtex/ads-core';
4
+
5
+ /**
6
+ * Where the element gets its products' details: a fetcher and a matcher, as
7
+ * in `@vtex/ads-core`, and a reader for the price of a fetched product.
8
+ */
9
+ interface StoryHydration<TProduct extends object = object> {
10
+ fetcher: ProductFetcher<TProduct>;
11
+ matcher(product: TProduct, offer: Offer): boolean;
12
+ price(product: TProduct, offer: Offer): ProductPrice | undefined;
13
+ /** Whether the product can be bought. Without it, it isn't checked. */
14
+ available?(product: TProduct, offer: Offer): boolean | undefined;
15
+ }
16
+ interface StoryProductDetails {
17
+ price?: ProductPrice;
18
+ /** Missing when the strategy doesn't say. */
19
+ available?: boolean;
20
+ }
21
+
22
+ declare const TAG_NAME = "vtex-ads-story-carousel";
23
+
24
+ declare class VtexAdsStoryCarouselElement extends LitElement {
25
+ static readonly properties: {
26
+ publisherId: {
27
+ attribute: string;
28
+ };
29
+ sessionId: {
30
+ attribute: string;
31
+ };
32
+ placement: {};
33
+ userId: {
34
+ attribute: string;
35
+ };
36
+ accountName: {
37
+ attribute: string;
38
+ };
39
+ channel: {
40
+ converter: {
41
+ fromAttribute: (value: string | null) => Channel | undefined;
42
+ };
43
+ };
44
+ timeout: {
45
+ type: NumberConstructor;
46
+ };
47
+ quantity: {
48
+ type: NumberConstructor;
49
+ };
50
+ currency: {};
51
+ labelAddToCart: {
52
+ attribute: string;
53
+ };
54
+ labelViewProduct: {
55
+ attribute: string;
56
+ };
57
+ hydration: {
58
+ converter: {
59
+ fromAttribute: (value: string | null) => "none" | undefined;
60
+ };
61
+ };
62
+ hydrationTimeout: {
63
+ type: NumberConstructor;
64
+ attribute: string;
65
+ };
66
+ slideDuration: {
67
+ type: NumberConstructor;
68
+ attribute: string;
69
+ };
70
+ inactiveAutoplay: {
71
+ type: BooleanConstructor;
72
+ attribute: string;
73
+ converter: {
74
+ fromAttribute: (value: string | null) => boolean;
75
+ };
76
+ };
77
+ stories: {
78
+ state: boolean;
79
+ };
80
+ products: {
81
+ state: boolean;
82
+ };
83
+ requesting: {
84
+ state: boolean;
85
+ };
86
+ mediaLoading: {
87
+ state: boolean;
88
+ };
89
+ };
90
+ /** Required. The publisher the ads are requested for. */
91
+ publisherId?: string;
92
+ /** Required. The store's session, also used to deduplicate events. */
93
+ sessionId?: string;
94
+ /** Required. The Story placement configured for the publisher. */
95
+ placement?: string;
96
+ userId?: string;
97
+ accountName?: string;
98
+ /** `site` or `app`. Any other attribute value is ignored. */
99
+ channel?: Channel;
100
+ /**
101
+ * Time limit for the ad request, in milliseconds (default 2000). Without a
102
+ * Story by then, the element renders nothing. A change applies to the next
103
+ * request; it doesn't request again.
104
+ */
105
+ timeout?: number;
106
+ /**
107
+ * How many Stories to ask for: the carousel positions (default 8). Missing,
108
+ * below 1 or not a number: the default.
109
+ */
110
+ quantity?: number;
111
+ /**
112
+ * Currency of the prices, as an ISO 4217 code ("BRL", "ARS"). Missing or
113
+ * invalid: BRL.
114
+ */
115
+ currency?: string;
116
+ /**
117
+ * The add to cart button's text. Missing or blank: the default in the
118
+ * element's language ("Adicionar ao carrinho").
119
+ */
120
+ labelAddToCart?: string;
121
+ /**
122
+ * The view product button's text. Missing or blank: the default in the
123
+ * element's language ("Ver produto").
124
+ */
125
+ labelViewProduct?: string;
126
+ /**
127
+ * Where the products' details (for now, their prices) come from. A
128
+ * strategy (fetcher, matcher and price reader) is set as a property; the
129
+ * attribute takes only "none", for no product request. Missing:
130
+ * Intelligent Search when `account-name` is set, no product request
131
+ * otherwise.
132
+ */
133
+ hydration?: StoryHydration | "none";
134
+ /**
135
+ * Time limit for the product request, in milliseconds (default 5000).
136
+ * Without the prices by then, the cards show the ad server's.
137
+ */
138
+ hydrationTimeout?: number;
139
+ /**
140
+ * With more than one Story, whether the cards without the highlight also
141
+ * play their video, muted. Off by default: they show only their cover, and
142
+ * only the highlighted card plays.
143
+ */
144
+ inactiveAutoplay: boolean;
145
+ /**
146
+ * With more than one Story, how long each one stays highlighted before the
147
+ * next, in milliseconds (default 5000). Zero: the highlight moves only by
148
+ * hand. A change starts the time over; it doesn't request again.
149
+ */
150
+ slideDuration?: number;
151
+ /** The Stories shown: none while loading, on error or with none. */
152
+ private stories;
153
+ /**
154
+ * The fetched products, by Story `ad_id`, or `"loading"` while the product
155
+ * request runs. Undefined without a product request.
156
+ */
157
+ private products?;
158
+ /**
159
+ * The ad request is pending (and has what it needs to go out): a skeleton
160
+ * stands in for the carousel until the Stories arrive.
161
+ */
162
+ private requesting;
163
+ /**
164
+ * The first Story's media is still loading: a skeleton covers the cards
165
+ * until its cover or its video is ready (or MEDIA_TIMEOUT passes), so the
166
+ * first card doesn't show up piece by piece. Meanwhile, the cards load
167
+ * underneath, their videos without playing, and no event goes out.
168
+ */
169
+ private mediaLoading;
170
+ /**
171
+ * Cancels the wait for the media in progress: when other Stories replace
172
+ * its Stories, or the element leaves the page.
173
+ */
174
+ private mediaWait?;
175
+ /**
176
+ * Cancels the request in progress. Kept, already aborted, when leaving the
177
+ * page cancelled it, so connecting again requests once more.
178
+ */
179
+ private request?;
180
+ static readonly styles: lit.CSSResult[];
181
+ /**
182
+ * How many of each SKU, from each seller (see cartKey), were added since
183
+ * the player opened, for its stepper. It doesn't read the store's cart: it
184
+ * counts the add and remove events sent, and starts over each time the
185
+ * player opens, as the cart may have changed meanwhile.
186
+ */
187
+ private readonly cartQuantities;
188
+ /**
189
+ * One per rendered card, by its key (see Slide): a Story can show in more
190
+ * than one card, each with its own video.
191
+ */
192
+ private readonly cardVideos;
193
+ /** The sound was on when the highlight moved: the new card turns it on. */
194
+ private soundPending;
195
+ /**
196
+ * What to do once the next render is on screen, when the new highlighted
197
+ * card's video exists (see leaveHighlight and onLayoutChange). A step
198
+ * taken before then replaces it.
199
+ */
200
+ private afterRender?;
201
+ private readonly carousel;
202
+ private readonly player;
203
+ private readonly events;
204
+ constructor();
205
+ connectedCallback(): void;
206
+ disconnectedCallback(): void;
207
+ protected willUpdate(changed: PropertyValues<this>): void;
208
+ protected updated(): void;
209
+ private get activeHydration();
210
+ /**
211
+ * Requests the Story and shows it, then hydrates its products. Until the
212
+ * Story arrives, and when there is none (see fetchStories), the element
213
+ * renders nothing.
214
+ */
215
+ private loadStory;
216
+ private showStories;
217
+ /**
218
+ * Shows the cards once the first Story's cover or video is ready: whichever
219
+ * loads first, or once both failed. Only then are the Stories impressed
220
+ * and do their videos play, from the start.
221
+ */
222
+ private waitForFirstMedia;
223
+ /**
224
+ * Where each Story is being watched: the cards on screen (not the hidden
225
+ * ones kept for the slide in) and the open player's video, while their
226
+ * video plays. A card showing only its cover doesn't count. Behind the
227
+ * expanded player, a modal over the page, the cards are covered.
228
+ */
229
+ private viewTargets;
230
+ private videoFor;
231
+ private get activeVideo();
232
+ private leaveHighlight;
233
+ private stepInPlayer;
234
+ private openPlayer;
235
+ private closePlayer;
236
+ private formatter?;
237
+ private get locale();
238
+ private labelSet?;
239
+ private get labels();
240
+ private get formatPrice();
241
+ private productOf;
242
+ private readonly renderSlide;
243
+ protected render(): typeof nothing | lit.TemplateResult<1>;
244
+ private renderPlayer;
245
+ private cartActionsFor;
246
+ /**
247
+ * Adds one of `item` to the stepper's count, or removes one, and tells the
248
+ * store, which changes its cart: the element has none. When add to cart
249
+ * and the stepper swap places, the focus moves to the one now shown.
250
+ */
251
+ private changeCart;
252
+ }
253
+ declare global {
254
+ interface HTMLElementTagNameMap {
255
+ [TAG_NAME]: VtexAdsStoryCarouselElement;
256
+ }
257
+ }
258
+ declare function defineVtexAdsStoryCarousel(): void;
259
+
260
+ export { type StoryHydration as S, TAG_NAME as T, VtexAdsStoryCarouselElement as V, type StoryProductDetails as a, defineVtexAdsStoryCarousel as d };
@@ -1,21 +1,52 @@
1
- import * as lit from 'lit';
2
- import { LitElement } from 'lit';
1
+ export { S as StoryHydration, a as StoryProductDetails, T as TAG_NAME, V as VtexAdsStoryCarouselElement, d as defineVtexAdsStoryCarousel } from './story-DAiAN9v-.js';
2
+ import 'lit';
3
+ import '@vtex/ads-core';
3
4
 
4
- declare const TAG_NAME = "vtex-ads-story";
5
- declare class VtexAdsStoryElement extends LitElement {
6
- static readonly styles: lit.CSSResult[];
7
- private readonly cardVideo;
8
- private readonly player;
9
- connectedCallback(): void;
10
- private openPlayer;
11
- private closePlayer;
12
- protected render(): lit.TemplateResult<1>;
5
+ /**
6
+ * The commerce events the element hands to the store: it has no cart of its
7
+ * own. They bubble and cross shadow roots, so the store can listen on the
8
+ * element, the document or any ancestor.
9
+ */
10
+ /**
11
+ * Add to cart, or the stepper's plus, was clicked in the player. No default
12
+ * action.
13
+ */
14
+ declare const ADD_TO_CART_EVENT = "vtex-ads-story:add-to-cart";
15
+ /**
16
+ * The stepper's minus, or its trash with one left, was clicked in the
17
+ * player. No default action.
18
+ */
19
+ declare const REMOVE_FROM_CART_EVENT = "vtex-ads-story:remove-from-cart";
20
+ interface StoryCartEventDetail {
21
+ /** The Story product's SKU, from the ad API (`product.product_sku`). */
22
+ sku: string;
23
+ /**
24
+ * The product's seller, from the ad API (`product.seller_id`). Missing
25
+ * when the ad API doesn't send one.
26
+ */
27
+ seller?: string;
28
+ /** How many to add (or, removing, to remove). Always 1 for now. */
29
+ quantity: number;
13
30
  }
31
+ /** The detail of the add to cart event: `quantity` is how many to add. */
32
+ type StoryAddToCartDetail = StoryCartEventDetail;
33
+ /** The detail of remove from cart: `quantity` is how many to remove. */
34
+ type StoryRemoveFromCartDetail = StoryCartEventDetail;
35
+ type StoryAddToCartEvent = CustomEvent<StoryAddToCartDetail>;
36
+ type StoryRemoveFromCartEvent = CustomEvent<StoryRemoveFromCartDetail>;
14
37
  declare global {
15
- interface HTMLElementTagNameMap {
16
- "vtex-ads-story": VtexAdsStoryElement;
38
+ interface HTMLElementEventMap {
39
+ [ADD_TO_CART_EVENT]: StoryAddToCartEvent;
40
+ [REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
41
+ }
42
+ interface DocumentEventMap {
43
+ [ADD_TO_CART_EVENT]: StoryAddToCartEvent;
44
+ [REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
45
+ }
46
+ interface WindowEventMap {
47
+ [ADD_TO_CART_EVENT]: StoryAddToCartEvent;
48
+ [REMOVE_FROM_CART_EVENT]: StoryRemoveFromCartEvent;
17
49
  }
18
50
  }
19
- declare function defineVtexAdsStories(): void;
20
51
 
21
- export { TAG_NAME, VtexAdsStoryElement, defineVtexAdsStories };
52
+ export { ADD_TO_CART_EVENT, REMOVE_FROM_CART_EVENT, type StoryAddToCartDetail, type StoryAddToCartEvent, type StoryRemoveFromCartDetail, type StoryRemoveFromCartEvent };