@vio-live/web-sdk 0.23.1 → 0.24.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.
@@ -1,4 +1,4 @@
1
- import { Vio, __decorateClass, primaryImageUrl, displayPrice, getGlobalCurrency, ensureVippsButton, formatPrice, nexiReturnPaymentId, readNexiPending, kustomReturnOutcome, KUSTOM_RETURN_QUERY_KEYS, ADYEN_RETURN_METHOD, adyenReturnParams, ADYEN_RETURN_QUERY_KEYS, adyenReturnOutcome, AdyenOriginError, normalizeSlotId, autoSlotDisplayName, autoSlotId, normalizeScope } from './chunk-BRJMT7P4.js';
1
+ import { Vio, __decorateClass, primaryImageUrl, displayPrice, toCampaignId, getGlobalCurrency, ensureVippsButton, formatPrice, nexiReturnPaymentId, readNexiPending, kustomReturnOutcome, KUSTOM_RETURN_QUERY_KEYS, ADYEN_RETURN_METHOD, adyenReturnParams, ADYEN_RETURN_QUERY_KEYS, adyenReturnOutcome, AdyenOriginError, normalizeSlotId, autoSlotDisplayName, autoSlotId, normalizeScope, campaignCandidates } from './chunk-AXJKB2CW.js';
2
2
  import { LitElement, css, html } from 'lit';
3
3
  import { property, state, query } from 'lit/decorators.js';
4
4
 
@@ -171,6 +171,8 @@ var SCOPE_ATTR = "vio-scope";
171
171
  var SCOPE_NAME_ATTR = "vio-scope-name";
172
172
  var SCOPE_DATA_ATTR = "data-vio-scope";
173
173
  var SCOPE_NAME_DATA_ATTR = "data-vio-scope-name";
174
+ var CAMPAIGN_ATTR = "vio-campaign";
175
+ var CAMPAIGN_DATA_ATTR = "data-vio-campaign";
174
176
  var liveAutoIds = (() => {
175
177
  const g = globalThis;
176
178
  return g.__VIO_LIVE_SLOT_IDS__ ?? (g.__VIO_LIVE_SLOT_IDS__ = /* @__PURE__ */ new Map());
@@ -192,6 +194,14 @@ var SlotRegistration = class {
192
194
  get effective() {
193
195
  return this.identity?.id ?? "";
194
196
  }
197
+ /** The element's own page campaign (`vio-campaign` / ancestor `data-vio-campaign`); undefined → `Vio.init`'s applies. */
198
+ get campaignId() {
199
+ return this.identity?.campaignId;
200
+ }
201
+ /** The element's page-campaign candidates in order (own, ancestor) — the hint for `Vio.attribution` / `campaignForSlot`. */
202
+ get campaignHint() {
203
+ return this.identity?.campaignCandidates ?? [];
204
+ }
195
205
  /** On connect: read the scope from the DOM, then register. */
196
206
  connect(attrs) {
197
207
  this.connected = true;
@@ -216,7 +226,7 @@ var SlotRegistration = class {
216
226
  this.unregister();
217
227
  if (!next) return;
218
228
  try {
219
- this.release = typeof Vio.registerSlot === "function" ? Vio.registerSlot(next.id, next.displayName) : null;
229
+ this.release = typeof Vio.registerSlot !== "function" ? null : next.campaignId !== void 0 ? Vio.registerSlot(next.id, next.displayName, next.campaignId) : Vio.registerSlot(next.id, next.displayName);
220
230
  this.identity = next;
221
231
  } catch {
222
232
  this.release = null;
@@ -227,13 +237,20 @@ var SlotRegistration = class {
227
237
  resolve(attrs) {
228
238
  const explicit = normalizeSlotId(attrs.vioSlot);
229
239
  const name = typeof attrs.vioSlotName === "string" && attrs.vioSlotName.trim() ? attrs.vioSlotName.trim() : void 0;
240
+ const campaignCandidates2 = campaignCandidatesOf(this.host, attrs);
241
+ const campaignId = campaignCandidates2[0];
230
242
  if (explicit) {
231
243
  this.releaseAuto();
232
- return { id: explicit, displayName: name };
244
+ return { id: explicit, displayName: name, campaignId, campaignCandidates: campaignCandidates2 };
233
245
  }
234
246
  if (!this.connected) return null;
235
247
  const auto = this.claimAuto();
236
- return { id: auto.id, displayName: name ?? autoSlotDisplayName(this.kind, auto.number - 1, this.scopeName) };
248
+ return {
249
+ id: auto.id,
250
+ displayName: name ?? autoSlotDisplayName(this.kind, auto.number - 1, this.scopeName),
251
+ campaignId,
252
+ campaignCandidates: campaignCandidates2
253
+ };
237
254
  }
238
255
  /** Unregister whatever is registered and free the auto number. */
239
256
  clear() {
@@ -275,7 +292,12 @@ var SlotRegistration = class {
275
292
  };
276
293
  function sameIdentity(a, b) {
277
294
  if (!a || !b) return a === b;
278
- return a.id === b.id && a.displayName === b.displayName;
295
+ return a.id === b.id && a.displayName === b.displayName && a.campaignId === b.campaignId;
296
+ }
297
+ function campaignCandidatesOf(el, attrs) {
298
+ const own = attrs && attrs.vioCampaign !== void 0 && attrs.vioCampaign !== null ? attrs.vioCampaign : el.vioCampaign !== void 0 ? el.vioCampaign : el.getAttribute(CAMPAIGN_ATTR);
299
+ const ancestor = closestAcrossShadow(el, `[${CAMPAIGN_DATA_ATTR}]`)?.getAttribute(CAMPAIGN_DATA_ATTR);
300
+ return campaignCandidates([own, ancestor]);
279
301
  }
280
302
  function scopeOf(el, attrs) {
281
303
  const own = attrs && typeof attrs.vioScope === "string" ? attrs.vioScope : typeof el.vioScope === "string" ? el.vioScope ?? "" : el.getAttribute(SCOPE_ATTR) ?? "";
@@ -314,6 +336,7 @@ var VioProduct = class extends LitElement {
314
336
  this.vioSlotName = "";
315
337
  this.vioScope = "";
316
338
  this.vioScopeName = "";
339
+ this.vioCampaign = "";
317
340
  this.vioContentId = "";
318
341
  this.vioContentTitle = "";
319
342
  this.slotRegistration = new SlotRegistration(this, "card");
@@ -330,9 +353,13 @@ var VioProduct = class extends LitElement {
330
353
  get effectiveSlot() {
331
354
  return this.slotRegistration.effective;
332
355
  }
356
+ /** The element's own page campaign (`vio-campaign` / ancestor), if any; `Vio.init`'s applies otherwise. */
357
+ get effectiveCampaignId() {
358
+ return this.slotRegistration.campaignId;
359
+ }
333
360
  /** The slot campaign's sponsor as the string the attributes use ('' when unknown). */
334
361
  sponsorFromAttribution() {
335
- const id = typeof Vio.attribution === "function" ? Vio.attribution(this.effectiveSlot).sponsorId : void 0;
362
+ const id = typeof Vio.attribution === "function" ? Vio.attribution(this.effectiveSlot, { campaignId: this.slotRegistration.campaignHint }).sponsorId : void 0;
336
363
  return id !== void 0 ? String(id) : "";
337
364
  }
338
365
  slotAttributes() {
@@ -340,7 +367,8 @@ var VioProduct = class extends LitElement {
340
367
  vioSlot: this.vioSlot,
341
368
  vioSlotName: this.vioSlotName,
342
369
  vioScope: this.vioScope,
343
- vioScopeName: this.vioScopeName
370
+ vioScopeName: this.vioScopeName,
371
+ vioCampaign: this.vioCampaign
344
372
  };
345
373
  }
346
374
  /**
@@ -349,7 +377,10 @@ var VioProduct = class extends LitElement {
349
377
  * set `vio-content-id` / `vio-content-title` on this card.
350
378
  */
351
379
  attribution() {
352
- const base = typeof Vio.attribution === "function" ? Vio.attribution(this.effectiveSlot, { sponsorId: this.sponsorId || void 0 }) : { slot: this.effectiveSlot || void 0 };
380
+ const base = typeof Vio.attribution === "function" ? Vio.attribution(this.effectiveSlot, {
381
+ sponsorId: this.sponsorId || void 0,
382
+ campaignId: this.slotRegistration.campaignHint
383
+ }) : { slot: this.effectiveSlot || void 0 };
353
384
  return {
354
385
  ...base,
355
386
  ...this.vioContentId ? { contentId: this.vioContentId } : {},
@@ -479,7 +510,7 @@ var VioProduct = class extends LitElement {
479
510
  }
480
511
  updated(changed) {
481
512
  if (changed.has("productId") || changed.has("sponsorId")) this.updateInCart();
482
- if (changed.has("vioSlot") || changed.has("vioSlotName") || changed.has("vioScope") || changed.has("vioScopeName")) {
513
+ if (changed.has("vioSlot") || changed.has("vioSlotName") || changed.has("vioScope") || changed.has("vioScopeName") || changed.has("vioCampaign")) {
483
514
  this.slotRegistration.sync(this.slotAttributes());
484
515
  }
485
516
  }
@@ -635,6 +666,9 @@ __decorateClass([
635
666
  __decorateClass([
636
667
  property({ type: String, attribute: "vio-scope-name" })
637
668
  ], VioProduct.prototype, "vioScopeName", 2);
669
+ __decorateClass([
670
+ property({ type: String, attribute: "vio-campaign" })
671
+ ], VioProduct.prototype, "vioCampaign", 2);
638
672
  __decorateClass([
639
673
  property({ type: String, attribute: "vio-content-id" })
640
674
  ], VioProduct.prototype, "vioContentId", 2);
@@ -679,6 +713,7 @@ var VioProductCarousel = class extends LitElement {
679
713
  this.vioSlotName = "";
680
714
  this.vioScope = "";
681
715
  this.vioScopeName = "";
716
+ this.vioCampaign = "";
682
717
  this.vioContentId = "";
683
718
  this.vioContentTitle = "";
684
719
  this.slotRegistration = new SlotRegistration(this, "carousel");
@@ -697,17 +732,25 @@ var VioProductCarousel = class extends LitElement {
697
732
  get effectiveSlot() {
698
733
  return this.slotRegistration.effective;
699
734
  }
735
+ /** The element's own page campaign (`vio-campaign` / ancestor), if any; `Vio.init`'s applies otherwise. */
736
+ get effectiveCampaignId() {
737
+ return this.slotRegistration.campaignId;
738
+ }
700
739
  slotAttributes() {
701
740
  return {
702
741
  vioSlot: this.vioSlot,
703
742
  vioSlotName: this.vioSlotName,
704
743
  vioScope: this.vioScope,
705
- vioScopeName: this.vioScopeName
744
+ vioScopeName: this.vioScopeName,
745
+ vioCampaign: this.vioCampaign
706
746
  };
707
747
  }
708
748
  /** Attribution every analytics event of this carousel carries (`Vio.attribution` + the content overrides). */
709
749
  attribution() {
710
- const base = typeof Vio.attribution === "function" ? Vio.attribution(this.effectiveSlot, { sponsorId: this.sponsorId > 0 ? this.sponsorId : void 0 }) : { slot: this.effectiveSlot || void 0 };
750
+ const base = typeof Vio.attribution === "function" ? Vio.attribution(this.effectiveSlot, {
751
+ sponsorId: this.sponsorId > 0 ? this.sponsorId : void 0,
752
+ campaignId: this.slotRegistration.campaignHint
753
+ }) : { slot: this.effectiveSlot || void 0 };
711
754
  return {
712
755
  ...base,
713
756
  ...this.vioContentId ? { contentId: this.vioContentId } : {},
@@ -874,10 +917,10 @@ var VioProductCarousel = class extends LitElement {
874
917
  super.disconnectedCallback();
875
918
  }
876
919
  updated(changed) {
877
- if (changed.has("vioSlot") || changed.has("vioSlotName") || changed.has("vioScope") || changed.has("vioScopeName")) {
920
+ if (changed.has("vioSlot") || changed.has("vioSlotName") || changed.has("vioScope") || changed.has("vioScopeName") || changed.has("vioCampaign")) {
878
921
  this.slotRegistration.sync(this.slotAttributes());
879
922
  }
880
- const propChanged = changed.has("productRefs") || changed.has("productIds") || changed.has("commerceKey") || changed.has("sponsorId") || changed.has("vioSlot");
923
+ const propChanged = changed.has("productRefs") || changed.has("productIds") || changed.has("commerceKey") || changed.has("sponsorId") || changed.has("vioSlot") || changed.has("vioCampaign");
881
924
  if (propChanged && (this.productRefs.trim() || this.productIds.trim())) {
882
925
  void this.autoFetch();
883
926
  }
@@ -889,7 +932,7 @@ var VioProductCarousel = class extends LitElement {
889
932
  */
890
933
  effectiveSponsorId() {
891
934
  if (this.sponsorId > 0) return this.sponsorId;
892
- const fromSlot = typeof Vio.campaignForSlot === "function" ? Number(Vio.campaignForSlot(this.effectiveSlot || null)?.primarySponsor?.id) : NaN;
935
+ const fromSlot = typeof Vio.campaignForSlot === "function" ? Number(Vio.campaignForSlot(this.effectiveSlot || null, { campaignId: this.slotRegistration.campaignHint })?.primarySponsor?.id) : NaN;
893
936
  return Number.isFinite(fromSlot) && fromSlot > 0 ? fromSlot : 0;
894
937
  }
895
938
  async autoFetch() {
@@ -1038,6 +1081,7 @@ var VioProductCarousel = class extends LitElement {
1038
1081
  image-url=${img}
1039
1082
  ?has-variants=${(p.variants?.length ?? 0) > 1}
1040
1083
  .vioSlot=${this.effectiveSlot}
1084
+ .vioCampaign=${this.effectiveCampaignId !== void 0 ? String(this.effectiveCampaignId) : ""}
1041
1085
  .vioContentId=${this.vioContentId}
1042
1086
  .vioContentTitle=${this.vioContentTitle}
1043
1087
  ></vio-product>
@@ -1121,6 +1165,9 @@ __decorateClass([
1121
1165
  __decorateClass([
1122
1166
  property({ type: String, attribute: "vio-scope-name" })
1123
1167
  ], VioProductCarousel.prototype, "vioScopeName", 2);
1168
+ __decorateClass([
1169
+ property({ type: String, attribute: "vio-campaign" })
1170
+ ], VioProductCarousel.prototype, "vioCampaign", 2);
1124
1171
  __decorateClass([
1125
1172
  property({ type: String, attribute: "vio-content-id" })
1126
1173
  ], VioProductCarousel.prototype, "vioContentId", 2);
@@ -1369,6 +1416,7 @@ var VioProductDetail = class extends LitElement {
1369
1416
  this.vioSlotName = "";
1370
1417
  this.vioScope = "";
1371
1418
  this.vioScopeName = "";
1419
+ this.vioCampaign = "";
1372
1420
  this.vioContentId = "";
1373
1421
  this.vioContentTitle = "";
1374
1422
  this.slotRegistration = new SlotRegistration(this, "detail");
@@ -1376,6 +1424,7 @@ var VioProductDetail = class extends LitElement {
1376
1424
  this.eventSlot = "";
1377
1425
  this.eventContentId = "";
1378
1426
  this.eventContentTitle = "";
1427
+ this.eventCampaignId = void 0;
1379
1428
  this.eventProductId = "";
1380
1429
  this.product = null;
1381
1430
  this.sellerName = null;
@@ -1410,11 +1459,16 @@ var VioProductDetail = class extends LitElement {
1410
1459
  const slot = typeof ev.detail.slot === "string" ? ev.detail.slot.trim() : "";
1411
1460
  let sponsorIdNum = parseInt(ev.detail.sponsorId, 10);
1412
1461
  if (Number.isNaN(sponsorIdNum) || sponsorIdNum <= 0) {
1413
- const fromSlot = typeof Vio.campaignForSlot === "function" ? Number(Vio.campaignForSlot(slot || this.effectiveSlot || null)?.primarySponsor?.id) : NaN;
1462
+ const fromSlot = typeof Vio.campaignForSlot === "function" ? Number(
1463
+ Vio.campaignForSlot(slot || this.effectiveSlot || null, {
1464
+ campaignId: [ev.detail.campaignId, ...this.slotRegistration.campaignHint]
1465
+ })?.primarySponsor?.id
1466
+ ) : NaN;
1414
1467
  if (!Number.isFinite(fromSlot) || fromSlot <= 0) return;
1415
1468
  sponsorIdNum = fromSlot;
1416
1469
  }
1417
1470
  this.eventSlot = slot;
1471
+ this.eventCampaignId = toCampaignId(ev.detail.campaignId);
1418
1472
  this.eventProductId = String(ev.detail.productId);
1419
1473
  this.eventContentId = ev.detail.contentId !== void 0 && ev.detail.contentId !== null ? String(ev.detail.contentId).trim() : "";
1420
1474
  this.eventContentTitle = typeof ev.detail.contentTitle === "string" ? ev.detail.contentTitle.trim() : "";
@@ -1433,21 +1487,34 @@ var VioProductDetail = class extends LitElement {
1433
1487
  get effectiveSlot() {
1434
1488
  return this.slotRegistration.effective;
1435
1489
  }
1490
+ /** The element's own page campaign (`vio-campaign` / ancestor), if any; `Vio.init`'s applies otherwise. */
1491
+ get effectiveCampaignId() {
1492
+ return this.slotRegistration.campaignId;
1493
+ }
1436
1494
  /** The slot the open product is attributed to: the opening card's, else this element's. */
1437
1495
  get activeSlot() {
1438
1496
  return this.fromCard && this.eventSlot || this.effectiveSlot;
1439
1497
  }
1498
+ /** The page-campaign candidates of the open product: the opening card's, then this element's own and its ancestor's. */
1499
+ get activeCampaignHint() {
1500
+ const own = this.slotRegistration.campaignHint;
1501
+ return this.fromCard && this.eventCampaignId !== void 0 ? [this.eventCampaignId, ...own] : own;
1502
+ }
1440
1503
  slotAttributes() {
1441
1504
  return {
1442
1505
  vioSlot: this.vioSlot,
1443
1506
  vioSlotName: this.vioSlotName,
1444
1507
  vioScope: this.vioScope,
1445
- vioScopeName: this.vioScopeName
1508
+ vioScopeName: this.vioScopeName,
1509
+ vioCampaign: this.vioCampaign
1446
1510
  };
1447
1511
  }
1448
1512
  /** Attribution every event of the open product carries (`Vio.attribution` of the opening card's slot, else this element's). */
1449
1513
  attribution() {
1450
- const base = typeof Vio.attribution === "function" ? Vio.attribution(this.activeSlot, { sponsorId: this.sponsorId > 0 ? this.sponsorId : void 0 }) : { slot: this.activeSlot || void 0 };
1514
+ const base = typeof Vio.attribution === "function" ? Vio.attribution(this.activeSlot, {
1515
+ sponsorId: this.sponsorId > 0 ? this.sponsorId : void 0,
1516
+ campaignId: this.activeCampaignHint
1517
+ }) : { slot: this.activeSlot || void 0 };
1451
1518
  const contentId = this.fromCard && this.eventContentId || this.vioContentId;
1452
1519
  const contentTitle = this.fromCard && this.eventContentTitle || this.vioContentTitle;
1453
1520
  return {
@@ -1914,7 +1981,7 @@ var VioProductDetail = class extends LitElement {
1914
1981
  }
1915
1982
  updated(changed) {
1916
1983
  if (changed.has("open")) this.dialogFocus.update(this.open);
1917
- if (changed.has("vioSlot") || changed.has("vioSlotName") || changed.has("vioScope") || changed.has("vioScopeName")) {
1984
+ if (changed.has("vioSlot") || changed.has("vioSlotName") || changed.has("vioScope") || changed.has("vioScopeName") || changed.has("vioCampaign")) {
1918
1985
  this.slotRegistration.sync(this.slotAttributes());
1919
1986
  }
1920
1987
  }
@@ -1928,6 +1995,7 @@ var VioProductDetail = class extends LitElement {
1928
1995
  this.eventSlot = "";
1929
1996
  this.eventContentId = "";
1930
1997
  this.eventContentTitle = "";
1998
+ this.eventCampaignId = void 0;
1931
1999
  this.eventProductId = "";
1932
2000
  this.product = null;
1933
2001
  this.sellerName = null;
@@ -2028,7 +2096,7 @@ var VioProductDetail = class extends LitElement {
2028
2096
  }
2029
2097
  /** Which buy buttons to render — backend-configured per sponsor. */
2030
2098
  async loadAvailablePaymentMethods() {
2031
- const spId = this.sponsorId || (typeof Vio.campaignForSlot === "function" ? Number(Vio.campaignForSlot(this.activeSlot || null)?.primarySponsor?.id) : 0) || globalThis.__VIO_SPONSOR_ID__;
2099
+ const spId = this.sponsorId || (typeof Vio.campaignForSlot === "function" ? Number(Vio.campaignForSlot(this.activeSlot || null, { campaignId: this.activeCampaignHint })?.primarySponsor?.id) : 0) || globalThis.__VIO_SPONSOR_ID__;
2032
2100
  if (!spId) return;
2033
2101
  try {
2034
2102
  const methods = await Vio.checkout.getAvailablePaymentMethods(spId);
@@ -2734,6 +2802,9 @@ __decorateClass([
2734
2802
  __decorateClass([
2735
2803
  property({ type: String, attribute: "vio-scope-name" })
2736
2804
  ], VioProductDetail.prototype, "vioScopeName", 2);
2805
+ __decorateClass([
2806
+ property({ type: String, attribute: "vio-campaign" })
2807
+ ], VioProductDetail.prototype, "vioCampaign", 2);
2737
2808
  __decorateClass([
2738
2809
  property({ type: String, attribute: "vio-content-id" })
2739
2810
  ], VioProductDetail.prototype, "vioContentId", 2);
@@ -7034,5 +7105,5 @@ function registerVioElements() {
7034
7105
  }
7035
7106
 
7036
7107
  export { VioCart, VioCheckout, VioProduct, VioProductCarousel, VioProductDetail, VioTokens, applyVioTheme, registerVioElements };
7037
- //# sourceMappingURL=chunk-UVDOKFGD.js.map
7038
- //# sourceMappingURL=chunk-UVDOKFGD.js.map
7108
+ //# sourceMappingURL=chunk-N6U65DWG.js.map
7109
+ //# sourceMappingURL=chunk-N6U65DWG.js.map