@action-x/ad-sdk 0.1.12 → 0.1.13

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/index.js CHANGED
@@ -13,18 +13,18 @@ class q {
13
13
  */
14
14
  off(e, t) {
15
15
  if (!this.events[e]) return;
16
- const i = this.events[e].indexOf(t);
17
- i > -1 && this.events[e].splice(i, 1);
16
+ const n = this.events[e].indexOf(t);
17
+ n > -1 && this.events[e].splice(n, 1);
18
18
  }
19
19
  /**
20
20
  * Emit an event
21
21
  */
22
22
  emit(e, ...t) {
23
- this.events[e] && this.events[e].forEach((i) => {
23
+ this.events[e] && this.events[e].forEach((n) => {
24
24
  try {
25
- i(...t);
26
- } catch (n) {
27
- console.error(`[EventEmitter] Error in event handler for "${e}":`, n);
25
+ n(...t);
26
+ } catch (s) {
27
+ console.error(`[EventEmitter] Error in event handler for "${e}":`, s);
28
28
  }
29
29
  });
30
30
  }
@@ -42,10 +42,10 @@ class q {
42
42
  return ((t = this.events[e]) == null ? void 0 : t.length) || 0;
43
43
  }
44
44
  }
45
- function m(o) {
46
- return o.replace(/<[^>]+>/g, " ").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&nbsp;/g, " ").replace(/\s{2,}/g, " ").trim();
45
+ function m(r) {
46
+ return r.replace(/<[^>]+>/g, " ").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&nbsp;/g, " ").replace(/\s{2,}/g, " ").trim();
47
47
  }
48
- class v {
48
+ class I {
49
49
  static getClickUrl(e) {
50
50
  return e.tracking.clickUrl || e.tracking.click_url || "#";
51
51
  }
@@ -63,30 +63,30 @@ class v {
63
63
  * @returns HTML string
64
64
  */
65
65
  static renderActionCard(e, t = {}) {
66
- var f;
67
- const { variant: i = "horizontal", includeWrapper: n = !0 } = t, s = e.adapted, r = this.getClickUrl(e), a = this.getImpressionUrl(e), c = (f = s.image) != null && f.url ? `<div class="ax-ad-image-wrap">
66
+ var h;
67
+ const { variant: n = "horizontal", includeWrapper: s = !0 } = t, i = e.adapted, o = this.getClickUrl(e), a = this.getImpressionUrl(e), c = (h = i.image) != null && h.url ? `<div class="ax-ad-image-wrap">
68
68
  <img
69
- src="${s.image.url}"
70
- alt="${s.title}"
69
+ src="${i.image.url}"
70
+ alt="${i.title}"
71
71
  class="ax-ad-image"
72
72
  loading="lazy"
73
73
  />
74
- </div>` : "", d = (s.brand || "").trim(), l = d && d.toLowerCase() !== "unknown" ? `<span class="ax-ad-brand">${s.brand}</span>` : "", u = `
74
+ </div>` : "", u = (i.brand || "").trim(), l = u && u.toLowerCase() !== "unknown" ? `<span class="ax-ad-brand">${i.brand}</span>` : "", d = `
75
75
  ${c}
76
76
  <div class="ax-ad-content">
77
77
  ${l}
78
- <h3 class="ax-ad-title">${s.title}</h3>
79
- ${s.body ? `<p class="ax-ad-body">${m(s.body)}</p>` : ""}
78
+ <h3 class="ax-ad-title">${i.title}</h3>
79
+ ${i.body ? `<p class="ax-ad-body">${m(i.body)}</p>` : ""}
80
80
  </div>
81
- `, h = n ? `<a
82
- href="${r}"
83
- class="ax-ad-card ax-ad-card-${i} ax-ad-card-link"
81
+ `, f = s ? `<a
82
+ href="${o}"
83
+ class="ax-ad-card ax-ad-card-${n} ax-ad-card-link"
84
84
  target="_blank"
85
85
  rel="sponsored noopener noreferrer"
86
86
  data-ad-id="${e.original.id}"
87
87
  data-impression-url="${a}"
88
- >` : "", p = n ? "</a>" : "";
89
- return h + u + p;
88
+ >` : "", g = s ? "</a>" : "";
89
+ return f + d + g;
90
90
  }
91
91
  /**
92
92
  * Render Suffix ad as HTML string
@@ -95,19 +95,19 @@ class v {
95
95
  * @returns HTML string
96
96
  */
97
97
  static renderSuffixAd(e) {
98
- const t = e.adapted, i = this.getClickUrl(e), n = this.getImpressionUrl(e);
98
+ const t = e.adapted, n = this.getClickUrl(e), s = this.getImpressionUrl(e);
99
99
  return `
100
100
  <div class="ax-ad-suffix" data-ad-id="${e.original.id}">
101
101
  <div class="ax-ad-suffix-content">
102
102
  ${t.title ? `<h4 class="ax-ad-suffix-title">${t.title}</h4>` : ""}
103
103
  ${t.body ? `<p class="ax-ad-suffix-body">${m(t.body)}</p>` : ""}
104
104
  <a
105
- href="${i}"
105
+ href="${n}"
106
106
  class="ax-ad-suffix-link"
107
107
  target="_blank"
108
108
  rel="sponsored noopener noreferrer"
109
109
  data-ad-id="${e.original.id}"
110
- data-impression-url="${n}"
110
+ data-impression-url="${s}"
111
111
  >
112
112
  ${this.getCtaText(e)}
113
113
  </a>
@@ -122,19 +122,19 @@ class v {
122
122
  * @returns HTML string
123
123
  */
124
124
  static renderSponsoredSource(e) {
125
- var s;
126
- const t = e.adapted, i = this.getClickUrl(e), n = this.getImpressionUrl(e);
125
+ var i;
126
+ const t = e.adapted, n = this.getClickUrl(e), s = this.getImpressionUrl(e);
127
127
  return `
128
128
  <div class="ax-ad-source" data-ad-id="${e.original.id}">
129
129
  <a
130
- href="${i}"
130
+ href="${n}"
131
131
  class="ax-ad-source-link"
132
132
  target="_blank"
133
133
  rel="sponsored noopener noreferrer"
134
134
  data-ad-id="${e.original.id}"
135
- data-impression-url="${n}"
135
+ data-impression-url="${s}"
136
136
  >
137
- ${(s = t.image) != null && s.url ? `<img src="${t.image.url}" alt="" class="ax-ad-source-icon" />` : ""}
137
+ ${(i = t.image) != null && i.url ? `<img src="${t.image.url}" alt="" class="ax-ad-source-icon" />` : ""}
138
138
  <div class="ax-ad-source-info">
139
139
  <span class="ax-ad-source-name">${t.title}</span>
140
140
  ${t.body ? `<span class="ax-ad-source-desc">${m(t.body)}</span>` : ""}
@@ -151,19 +151,19 @@ class v {
151
151
  * @returns HTML string
152
152
  */
153
153
  static renderLeadGenAd(e) {
154
- const t = e.adapted, i = this.getClickUrl(e), n = this.getImpressionUrl(e);
154
+ const t = e.adapted, n = this.getClickUrl(e), s = this.getImpressionUrl(e);
155
155
  return `
156
156
  <div class="ax-ad-leadgen" data-ad-id="${e.original.id}">
157
157
  <div class="ax-ad-leadgen-content">
158
158
  ${t.title ? `<h3 class="ax-ad-leadgen-title">${t.title}</h3>` : ""}
159
159
  ${t.body ? `<p class="ax-ad-leadgen-body">${m(t.body)}</p>` : ""}
160
160
  <a
161
- href="${i}"
161
+ href="${n}"
162
162
  class="ax-ad-leadgen-cta"
163
163
  target="_blank"
164
164
  rel="sponsored noopener noreferrer"
165
165
  data-ad-id="${e.original.id}"
166
- data-impression-url="${n}"
166
+ data-impression-url="${s}"
167
167
  >
168
168
  ${this.getCtaText(e)}
169
169
  </a>
@@ -178,25 +178,25 @@ class v {
178
178
  * @param renderFn - Render function to use
179
179
  * @returns HTML string with all ads
180
180
  */
181
- static renderAds(e, t = v.renderActionCard.bind(v)) {
181
+ static renderAds(e, t = I.renderActionCard.bind(I)) {
182
182
  return e.map(t).join(`
183
183
  `);
184
184
  }
185
185
  }
186
- const L = "ad_session_id";
186
+ const P = "ad_session_id";
187
187
  function K() {
188
188
  if (typeof window < "u") {
189
- const o = window.__AD_CONFIG__;
190
- if (o != null && o.apiKey)
191
- return o.apiKey;
189
+ const r = window.__AD_CONFIG__;
190
+ if (r != null && r.apiKey)
191
+ return r.apiKey;
192
192
  }
193
193
  }
194
- function R() {
195
- var o;
196
- return typeof window < "u" ? !!((o = window.__AD_CONFIG__) != null && o.debug) : !1;
194
+ function B() {
195
+ var r;
196
+ return typeof window < "u" ? !!((r = window.__AD_CONFIG__) != null && r.debug) : !1;
197
197
  }
198
- function U(o) {
199
- if (o) return o;
198
+ function $(r) {
199
+ if (r) return r;
200
200
  if (typeof window < "u") {
201
201
  const e = window.__AD_CONFIG__;
202
202
  if (e != null && e.apiBaseUrl)
@@ -204,9 +204,9 @@ function U(o) {
204
204
  }
205
205
  return "/api/v1";
206
206
  }
207
- class V {
207
+ class M {
208
208
  constructor(e = {}) {
209
- this.memoryCache = /* @__PURE__ */ new Map(), this.sessionKey = e.sessionKey || L, this.storage = e.storage || "sessionStorage", (typeof window > "u" || typeof window.sessionStorage > "u") && (this.storage = "memory");
209
+ this.memoryCache = /* @__PURE__ */ new Map(), this.sessionKey = e.sessionKey || P, this.storage = e.storage || "sessionStorage", (typeof window > "u" || typeof window.sessionStorage > "u") && (this.storage = "memory");
210
210
  }
211
211
  /**
212
212
  * 获取 Session ID
@@ -240,8 +240,8 @@ class V {
240
240
  this.storage === "sessionStorage" ? sessionStorage.removeItem(this.sessionKey) : this.memoryCache.delete(this.sessionKey);
241
241
  }
242
242
  }
243
- const N = new V(), w = () => N.getSessionId();
244
- class x {
243
+ const R = new M(), w = () => R.getSessionId();
244
+ class A {
245
245
  constructor(e = {}) {
246
246
  this.explicitBaseUrl = e.baseUrl, this.timeout = e.timeout || 1e4, this.retryAttempts = e.retryAttempts ?? 2, this.retryDelay = e.retryDelay || 1e3, this.debug = e.debug || !1;
247
247
  }
@@ -250,7 +250,7 @@ class x {
250
250
  */
251
251
  async trackImpression(e) {
252
252
  return this.sendRequest(
253
- `${U(this.explicitBaseUrl)}/ads/impression`,
253
+ `${$(this.explicitBaseUrl)}/ads/impression`,
254
254
  e,
255
255
  "impression"
256
256
  );
@@ -260,7 +260,7 @@ class x {
260
260
  */
261
261
  async trackClick(e) {
262
262
  return this.sendRequest(
263
- `${U(this.explicitBaseUrl)}/ads/click`,
263
+ `${$(this.explicitBaseUrl)}/ads/click`,
264
264
  e,
265
265
  "click"
266
266
  );
@@ -269,32 +269,32 @@ class x {
269
269
  * 通用请求发送方法(带重试)
270
270
  * 自动添加 X-API-Key header
271
271
  */
272
- async sendRequest(e, t, i) {
273
- let n = null;
274
- for (let s = 0; s <= this.retryAttempts; s++) {
275
- const r = this.debug || R();
272
+ async sendRequest(e, t, n) {
273
+ let s = null;
274
+ for (let i = 0; i <= this.retryAttempts; i++) {
275
+ const o = this.debug || B();
276
276
  try {
277
- r && (console.log(`[Analytics] Request URL (${i}):`, e), console.log(`[Analytics] Sending ${i} event (attempt ${s + 1}):`, t));
278
- const a = new AbortController(), c = setTimeout(() => a.abort(), this.timeout), d = {
277
+ o && (console.log(`[Analytics] Request URL (${n}):`, e), console.log(`[Analytics] Sending ${n} event (attempt ${i + 1}):`, t));
278
+ const a = new AbortController(), c = setTimeout(() => a.abort(), this.timeout), u = {
279
279
  "Content-Type": "application/json"
280
280
  }, l = K();
281
- l && (d["X-API-Key"] = l, r && console.log(`[Analytics] Adding X-API-Key header for ${i} event`));
282
- const u = await fetch(e, {
281
+ l && (u["X-API-Key"] = l, o && console.log(`[Analytics] Adding X-API-Key header for ${n} event`));
282
+ const d = await fetch(e, {
283
283
  method: "POST",
284
- headers: d,
284
+ headers: u,
285
285
  body: JSON.stringify(t),
286
286
  keepalive: !0,
287
287
  signal: a.signal
288
288
  });
289
- if (clearTimeout(c), !u.ok)
290
- throw new Error(`HTTP ${u.status}: ${u.statusText}`);
291
- const h = await u.json();
292
- return r && console.log(`[Analytics] ${i} event tracked successfully:`, h), h;
289
+ if (clearTimeout(c), !d.ok)
290
+ throw new Error(`HTTP ${d.status}: ${d.statusText}`);
291
+ const f = await d.json();
292
+ return o && console.log(`[Analytics] ${n} event tracked successfully:`, f), f;
293
293
  } catch (a) {
294
- n = a, r && console.warn(`[Analytics] ${i} tracking failed (attempt ${s + 1}):`, a), s < this.retryAttempts && await this.delay(this.retryDelay * (s + 1));
294
+ s = a, o && console.warn(`[Analytics] ${n} tracking failed (attempt ${i + 1}):`, a), i < this.retryAttempts && await this.delay(this.retryDelay * (i + 1));
295
295
  }
296
296
  }
297
- return console.error(`[Analytics] ${i} tracking failed after ${this.retryAttempts + 1} attempts:`, n), null;
297
+ return console.error(`[Analytics] ${n} tracking failed after ${this.retryAttempts + 1} attempts:`, s), null;
298
298
  }
299
299
  /**
300
300
  * 延迟辅助方法
@@ -303,32 +303,32 @@ class x {
303
303
  return new Promise((t) => setTimeout(t, e));
304
304
  }
305
305
  }
306
- const P = new x(), T = (o, e) => e != null && e.baseUrl ? new x({ baseUrl: e.baseUrl }).trackImpression(o) : P.trackImpression(o), O = (o, e) => e != null && e.baseUrl ? new x({ baseUrl: e.baseUrl }).trackClick(o) : P.trackClick(o);
307
- function J(o, e) {
308
- return `vt_${o}_${e}`;
306
+ const T = new A(), b = (r, e) => e != null && e.baseUrl ? new A({ baseUrl: e.baseUrl }).trackImpression(r) : T.trackImpression(r), O = (r, e) => e != null && e.baseUrl ? new A({ baseUrl: e.baseUrl }).trackClick(r) : T.trackClick(r);
307
+ function z(r, e) {
308
+ return `vt_${r}_${e}`;
309
309
  }
310
- async function X(o) {
311
- return Promise.all(o.map((e) => T(e)));
310
+ async function W(r) {
311
+ return Promise.all(r.map((e) => b(e)));
312
312
  }
313
- async function Z(o) {
314
- return Promise.all(o.map((e) => O(e)));
313
+ async function J(r) {
314
+ return Promise.all(r.map((e) => O(e)));
315
315
  }
316
- function Y(o) {
317
- const e = new x(o);
316
+ function X(r) {
317
+ const e = new A(r);
318
318
  return {
319
319
  trackImpression: (t) => e.trackImpression(t),
320
320
  trackClick: (t) => e.trackClick(t)
321
321
  };
322
322
  }
323
- function ee(o = {}) {
324
- const e = new V(o);
323
+ function Z(r = {}) {
324
+ const e = new M(r);
325
325
  return {
326
326
  getSessionId: () => e.getSessionId(),
327
327
  regenerateSessionId: () => e.regenerateSessionId(),
328
328
  clearSessionId: () => e.clearSessionId()
329
329
  };
330
330
  }
331
- const $ = class $ {
331
+ const U = class U {
332
332
  static isDebugEnabled() {
333
333
  var e;
334
334
  return typeof window < "u" ? !!((e = window.__AD_CONFIG__) != null && e.debug) : !1;
@@ -342,111 +342,111 @@ const $ = class $ {
342
342
  /**
343
343
  * Render Action Card ad into container
344
344
  */
345
- static renderActionCard(e, t, i = {}) {
346
- t.innerHTML = v.renderActionCard(e, i);
347
- const n = t.querySelector(".ax-ad-card-link");
348
- return n && n.addEventListener("click", (s) => {
349
- s.preventDefault(), this.handleClick(e, i);
350
- }), this.trackImpression(e, t, i), t;
345
+ static renderActionCard(e, t, n = {}) {
346
+ t.innerHTML = I.renderActionCard(e, n);
347
+ const s = t.querySelector(".ax-ad-card-link");
348
+ return s && s.addEventListener("click", (i) => {
349
+ i.preventDefault(), this.handleClick(e, n);
350
+ }), this.trackImpression(e, t, n), t;
351
351
  }
352
352
  /**
353
353
  * Render Suffix ad into container
354
354
  */
355
- static renderSuffixAd(e, t, i = {}) {
356
- const n = i.variant || "block";
357
- t.innerHTML = this.generateSuffixAdHTML(e, n);
358
- const s = t.querySelector(".ax-ad-suffix-link");
359
- return s && s.addEventListener("click", (r) => {
360
- r.preventDefault(), this.handleClick(e, i);
361
- }), this.trackImpression(e, t, i), t;
355
+ static renderSuffixAd(e, t, n = {}) {
356
+ const s = n.variant || "block";
357
+ t.innerHTML = this.generateSuffixAdHTML(e, s);
358
+ const i = t.querySelector(".ax-ad-suffix-link");
359
+ return i && i.addEventListener("click", (o) => {
360
+ o.preventDefault(), this.handleClick(e, n);
361
+ }), this.trackImpression(e, t, n), t;
362
362
  }
363
363
  /**
364
364
  * Render Sponsored Source ad into container
365
365
  */
366
- static renderSponsoredSource(e, t, i = {}) {
367
- const n = i.variant || "card";
368
- t.innerHTML = this.generateSponsoredSourceHTML(e, n);
369
- const s = t.querySelector(".ax-ad-source-link");
370
- return s && s.addEventListener("click", (r) => {
371
- r.preventDefault(), this.handleClick(e, i);
372
- }), this.trackImpression(e, t, i), t;
366
+ static renderSponsoredSource(e, t, n = {}) {
367
+ const s = n.variant || "card";
368
+ t.innerHTML = this.generateSponsoredSourceHTML(e, s);
369
+ const i = t.querySelector(".ax-ad-source-link");
370
+ return i && i.addEventListener("click", (o) => {
371
+ o.preventDefault(), this.handleClick(e, n);
372
+ }), this.trackImpression(e, t, n), t;
373
373
  }
374
374
  /**
375
375
  * Render Lead Gen ad into container
376
376
  */
377
- static renderLeadGenAd(e, t, i = {}) {
378
- t.innerHTML = v.renderLeadGenAd(e);
379
- const n = t.querySelector(".ax-ad-leadgen-cta");
380
- return n && n.addEventListener("click", (s) => {
381
- s.preventDefault(), this.handleClick(e, i);
382
- }), this.trackImpression(e, t, i), t;
377
+ static renderLeadGenAd(e, t, n = {}) {
378
+ t.innerHTML = I.renderLeadGenAd(e);
379
+ const s = t.querySelector(".ax-ad-leadgen-cta");
380
+ return s && s.addEventListener("click", (i) => {
381
+ i.preventDefault(), this.handleClick(e, n);
382
+ }), this.trackImpression(e, t, n), t;
383
383
  }
384
384
  /**
385
385
  * Render multiple ads into container
386
386
  */
387
- static renderAds(e, t, i = this.renderActionCard.bind(this), n) {
387
+ static renderAds(e, t, n = this.renderActionCard.bind(this), s) {
388
388
  t.innerHTML = "";
389
- const s = document.createElement("div");
390
- return s.className = "ax-ads-container", e.forEach((r) => {
389
+ const i = document.createElement("div");
390
+ return i.className = "ax-ads-container", e.forEach((o) => {
391
391
  const a = document.createElement("div");
392
- a.className = "ax-ad-wrapper", i.call(this, r, a, n), s.appendChild(a);
393
- }), t.appendChild(s), t;
392
+ a.className = "ax-ad-wrapper", n.call(this, o, a, s), i.appendChild(a);
393
+ }), t.appendChild(i), t;
394
394
  }
395
395
  /**
396
396
  * Handle ad click
397
397
  * Directly opens click_url in a new window.
398
398
  */
399
399
  static handleClick(e, t) {
400
- const { onClick: i } = t, n = this.getClickUrl(e);
401
- if (!n) {
400
+ const { onClick: n } = t, s = this.getClickUrl(e);
401
+ if (!s) {
402
402
  console.warn("[DOMRenderer] Missing click url for ad:", e.original.id);
403
403
  return;
404
404
  }
405
- i && i(e), this.isDebugEnabled() && console.log("[DOMRenderer] Redirect URL:", n), window.open(n, "_blank", "noopener,noreferrer");
405
+ n && n(e), this.isDebugEnabled() && console.log("[DOMRenderer] Redirect URL:", s), window.open(s, "_blank", "noopener,noreferrer");
406
406
  }
407
407
  /**
408
408
  * Track ad impression using IntersectionObserver (50% visible + 1000ms delay)
409
409
  * Falls back to immediate tracking if IntersectionObserver is unavailable.
410
410
  */
411
- static trackImpression(e, t, i) {
412
- const { analytics: n, onImpression: s } = i, r = n ? `${n.requestId}:${n.slotId}:${e.original.id}:${this.getViewToken(e) || ""}` : `no-analytics:${e.original.id}:${this.getViewToken(e) || ""}`;
413
- if (this.trackedImpressionKeys.has(r))
411
+ static trackImpression(e, t, n) {
412
+ const { analytics: s, onImpression: i } = n, o = s ? `${s.requestId}:${s.slotId}:${e.original.id}:${this.getViewToken(e) || ""}` : `no-analytics:${e.original.id}:${this.getViewToken(e) || ""}`;
413
+ if (this.trackedImpressionKeys.has(o))
414
414
  return;
415
415
  let a = !1;
416
416
  const c = () => {
417
- a || this.trackedImpressionKeys.has(r) || (a = !0, this.trackedImpressionKeys.add(r), d());
418
- }, d = () => {
419
- n ? T({
420
- requestId: n.requestId,
417
+ a || this.trackedImpressionKeys.has(o) || (a = !0, this.trackedImpressionKeys.add(o), u());
418
+ }, u = () => {
419
+ s ? b({
420
+ requestId: s.requestId,
421
421
  adId: e.original.id,
422
- slotId: n.slotId,
423
- position: n.position,
424
- totalAds: n.totalAds,
422
+ slotId: s.slotId,
423
+ position: s.position,
424
+ totalAds: s.totalAds,
425
425
  sessionId: w(),
426
426
  adTitle: e.adapted.title,
427
427
  format: e.original.type,
428
428
  source: "internal",
429
429
  viewToken: this.getViewToken(e),
430
- userId: n.userId
431
- }, { baseUrl: n.apiBaseUrl }).then(() => {
432
- s && s(e);
430
+ userId: s.userId
431
+ }, { baseUrl: s.apiBaseUrl }).then(() => {
432
+ i && i(e);
433
433
  }).catch((l) => {
434
434
  console.error("[DOMRenderer] Analytics impression tracking failed:", l);
435
- }) : s && s(e);
435
+ }) : i && i(e);
436
436
  };
437
437
  if (typeof IntersectionObserver < "u") {
438
- let l = !1, u = null;
439
- const h = new IntersectionObserver(
440
- (f) => {
441
- f.forEach((k) => {
442
- l = k.isIntersecting && k.intersectionRatio >= 0.5, l ? u || (u = setTimeout(() => {
443
- u = null, l && (c(), h.disconnect());
444
- }, 1e3)) : u && (clearTimeout(u), u = null);
438
+ let l = !1, d = null;
439
+ const f = new IntersectionObserver(
440
+ (h) => {
441
+ h.forEach((v) => {
442
+ l = v.isIntersecting && v.intersectionRatio >= 0.5, l ? d || (d = setTimeout(() => {
443
+ d = null, l && (c(), f.disconnect());
444
+ }, 1e3)) : d && (clearTimeout(d), d = null);
445
445
  });
446
446
  },
447
447
  { threshold: 0.5 }
448
- ), p = t.querySelector(`[data-ad-id="${e.original.id}"]`) || t;
449
- h.observe(p);
448
+ ), g = t.querySelector(`[data-ad-id="${e.original.id}"]`) || t;
449
+ f.observe(g);
450
450
  } else
451
451
  c();
452
452
  }
@@ -454,22 +454,22 @@ const $ = class $ {
454
454
  * Generate HTML for Suffix Ad variants
455
455
  */
456
456
  static generateSuffixAdHTML(e, t) {
457
- const i = e.adapted.title || "", n = m(e.adapted.body || "");
457
+ const n = e.adapted.title || "", s = m(e.adapted.body || "");
458
458
  return t === "inline" ? `
459
459
  <span class="ax-ad-suffix-link ax-ad-variant-inline" data-ad-id="${e.original.id}">
460
- ${i}
460
+ ${n}
461
461
  <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="display:inline;vertical-align:middle;margin-left:4px">
462
462
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
463
463
  </svg>
464
464
  </span>
465
465
  ` : t === "minimal" ? `
466
466
  <span class="ax-ad-suffix-link ax-ad-variant-minimal" data-ad-id="${e.original.id}">
467
- ${i}
467
+ ${n}
468
468
  </span>
469
469
  ` : `
470
470
  <div class="ax-ad-suffix ax-ad-variant-block" data-ad-id="${e.original.id}">
471
471
  <div class="ax-ad-suffix-content">
472
- <p class="ax-ad-suffix-title">${i}</p>
472
+ <p class="ax-ad-suffix-title">${n}</p>
473
473
  <div style="display:flex;align-items:center;gap:8px;flex-shrink:0">
474
474
  <span class="ax-ad-sponsored-badge">Sponsored</span>
475
475
  <svg width="16" height="16" fill="none" stroke="#d1d5db" viewBox="0 0 24 24">
@@ -477,7 +477,7 @@ const $ = class $ {
477
477
  </svg>
478
478
  </div>
479
479
  </div>
480
- ${n ? `<p class="ax-ad-suffix-body">${n}</p>` : ""}
480
+ ${s ? `<p class="ax-ad-suffix-body">${s}</p>` : ""}
481
481
  </div>
482
482
  `;
483
483
  }
@@ -485,13 +485,13 @@ const $ = class $ {
485
485
  * Generate HTML for Sponsored Source Ad variants
486
486
  */
487
487
  static generateSponsoredSourceHTML(e, t) {
488
- var r;
489
- const i = e.adapted.title || "", n = m(e.adapted.body || ""), s = ((r = e.adapted.image) == null ? void 0 : r.url) || "";
488
+ var o;
489
+ const n = e.adapted.title || "", s = m(e.adapted.body || ""), i = ((o = e.adapted.image) == null ? void 0 : o.url) || "";
490
490
  return t === "list-item" ? `
491
491
  <div class="ax-ad-source ax-ad-variant-list-item" data-ad-id="${e.original.id}">
492
- ${s ? `<img src="${s}" alt="${i}" loading="lazy" />` : ""}
492
+ ${i ? `<img src="${i}" alt="${n}" loading="lazy" />` : ""}
493
493
  <div class="ax-ad-source-info">
494
- <span class="ax-ad-source-name">${i}</span>
494
+ <span class="ax-ad-source-name">${n}</span>
495
495
  <span class="ax-ad-sponsored-badge" style="font-size:9px">Ad</span>
496
496
  </div>
497
497
  <svg width="12" height="12" fill="none" stroke="#d1d5db" viewBox="0 0 24 24" style="flex-shrink:0">
@@ -501,20 +501,20 @@ const $ = class $ {
501
501
  ` : t === "minimal" ? `
502
502
  <div data-ad-id="${e.original.id}" style="display:inline-flex">
503
503
  <a class="ax-ad-source-link ax-ad-variant-minimal">
504
- ${s ? `<img src="${s}" alt="${i}" loading="lazy" style="width:16px;height:16px;border-radius:2px;object-fit:cover" />` : ""}
505
- <span>${i}</span>
504
+ ${i ? `<img src="${i}" alt="${n}" loading="lazy" style="width:16px;height:16px;border-radius:2px;object-fit:cover" />` : ""}
505
+ <span>${n}</span>
506
506
  <span class="ax-ad-sponsored-badge" style="font-size:9px">Ad</span>
507
507
  </a>
508
508
  </div>
509
509
  ` : `
510
510
  <div class="ax-ad-source ax-ad-variant-card" data-ad-id="${e.original.id}">
511
- ${s ? `<img src="${s}" alt="${i}" loading="lazy" style="width:48px;height:48px;border-radius:6px;object-fit:cover;flex-shrink:0" />` : ""}
511
+ ${i ? `<img src="${i}" alt="${n}" loading="lazy" style="width:48px;height:48px;border-radius:6px;object-fit:cover;flex-shrink:0" />` : ""}
512
512
  <div class="ax-ad-source-info">
513
513
  <div style="display:flex;align-items:center;gap:8px;margin-bottom:4px">
514
- <span class="ax-ad-source-name">${i}</span>
514
+ <span class="ax-ad-source-name">${n}</span>
515
515
  <span class="ax-ad-sponsored-badge">Sponsored</span>
516
516
  </div>
517
- ${n ? `<p class="ax-ad-source-desc">${n}</p>` : ""}
517
+ ${s ? `<p class="ax-ad-source-desc">${s}</p>` : ""}
518
518
  </div>
519
519
  <svg width="16" height="16" fill="none" stroke="#d1d5db" viewBox="0 0 24 24" style="flex-shrink:0">
520
520
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
@@ -523,9 +523,9 @@ const $ = class $ {
523
523
  `;
524
524
  }
525
525
  };
526
- $.trackedImpressionKeys = /* @__PURE__ */ new Set();
527
- let y = $;
528
- class I {
526
+ U.trackedImpressionKeys = /* @__PURE__ */ new Set();
527
+ let y = U;
528
+ class S {
529
529
  constructor() {
530
530
  this.cachedStaticInfo = null, this.cacheTimestamp = 0, this.CACHE_TTL = 36e5;
531
531
  }
@@ -540,13 +540,13 @@ class I {
540
540
  name: "Unknown App",
541
541
  publisher: { id: "unknown" }
542
542
  };
543
- const e = this.inferBundle(), t = this.inferAppName(), i = this.inferAppVersion(), n = this.inferPublisherId();
543
+ const e = this.inferBundle(), t = this.inferAppName(), n = this.inferAppVersion(), s = this.inferPublisherId();
544
544
  return {
545
545
  bundle: e,
546
- ver: i,
546
+ ver: n,
547
547
  name: t,
548
548
  publisher: {
549
- id: n,
549
+ id: s,
550
550
  domain: window.location.hostname
551
551
  }
552
552
  };
@@ -564,15 +564,15 @@ class I {
564
564
  * 自动推断应用名称
565
565
  */
566
566
  inferAppName() {
567
- var n, s;
567
+ var s, i;
568
568
  if (typeof document > "u") return "Unknown App";
569
569
  const e = document.title;
570
570
  if (e && e !== "Loading..." && e.length < 100)
571
571
  return e;
572
- const t = (n = document.querySelector('meta[property="og:title"]')) == null ? void 0 : n.getAttribute("content");
572
+ const t = (s = document.querySelector('meta[property="og:title"]')) == null ? void 0 : s.getAttribute("content");
573
573
  if (t) return t;
574
- const i = (s = document.querySelector('meta[name="application-name"]')) == null ? void 0 : s.getAttribute("content");
575
- return i || "Unknown App";
574
+ const n = (i = document.querySelector('meta[name="application-name"]')) == null ? void 0 : i.getAttribute("content");
575
+ return n || "Unknown App";
576
576
  }
577
577
  /**
578
578
  * 自动推断应用版本
@@ -587,12 +587,12 @@ class I {
587
587
  // 从manifest.json读取
588
588
  ];
589
589
  for (const t of e) {
590
- const i = document.querySelector(t);
591
- if (i) {
590
+ const n = document.querySelector(t);
591
+ if (n) {
592
592
  if (t.includes("manifest"))
593
593
  return "1.0.0";
594
- const n = i.getAttribute("content");
595
- if (n) return n;
594
+ const s = n.getAttribute("content");
595
+ if (s) return s;
596
596
  }
597
597
  }
598
598
  return "1.0.0";
@@ -601,18 +601,18 @@ class I {
601
601
  * 自动推断publisher ID
602
602
  */
603
603
  inferPublisherId() {
604
- var i, n;
604
+ var n, s;
605
605
  if (typeof document > "u") return "unknown";
606
- const e = (i = document.querySelector('meta[name="publisher-id"]')) == null ? void 0 : i.getAttribute("content");
606
+ const e = (n = document.querySelector('meta[name="publisher-id"]')) == null ? void 0 : n.getAttribute("content");
607
607
  if (e) return e;
608
- const t = (n = window.location) == null ? void 0 : n.hostname;
608
+ const t = (s = window.location) == null ? void 0 : s.hostname;
609
609
  return t ? t.replace(/\./g, "_") : "unknown";
610
610
  }
611
611
  /**
612
612
  * Get singleton instance
613
613
  */
614
614
  static getInstance() {
615
- return this.instance || (this.instance = new I()), this.instance;
615
+ return this.instance || (this.instance = new S()), this.instance;
616
616
  }
617
617
  /**
618
618
  * Collect all available client information
@@ -622,7 +622,7 @@ class I {
622
622
  collect(e) {
623
623
  const t = Date.now();
624
624
  (!this.cachedStaticInfo || t - this.cacheTimestamp > this.CACHE_TTL) && (this.cachedStaticInfo = this.collectStaticInfo(), this.cacheTimestamp = t);
625
- const i = this.collectDynamicInfo();
625
+ const n = this.collectDynamicInfo();
626
626
  return {
627
627
  device: {
628
628
  ua: this.cachedStaticInfo.ua,
@@ -632,8 +632,8 @@ class I {
632
632
  model: this.cachedStaticInfo.model,
633
633
  make: this.cachedStaticInfo.make,
634
634
  language: this.cachedStaticInfo.language,
635
- connectiontype: i.connectiontype ?? 0,
636
- bandwidth: i.bandwidth,
635
+ connectiontype: n.connectiontype ?? 0,
636
+ bandwidth: n.bandwidth,
637
637
  ...(e == null ? void 0 : e.device) || {}
638
638
  // App overrides
639
639
  },
@@ -663,11 +663,11 @@ class I {
663
663
  collectStaticInfo() {
664
664
  if (typeof navigator > "u")
665
665
  return this.getFallbackInfo();
666
- const e = navigator.userAgent, t = this.detectOS(e), i = this.detectOSVersion(e);
666
+ const e = navigator.userAgent, t = this.detectOS(e), n = this.detectOSVersion(e);
667
667
  return {
668
668
  ua: e,
669
669
  os: t,
670
- osv: i,
670
+ osv: n,
671
671
  devicetype: this.detectDeviceType(e),
672
672
  model: this.detectModel(e),
673
673
  make: this.detectMake(e),
@@ -731,14 +731,14 @@ class I {
731
731
  const t = e.match(/OS (\d+)_(\d+)_?(\d+)?/);
732
732
  if (t)
733
733
  return `${t[1]}.${t[2]}${t[3] ? "." + t[3] : ""}`;
734
- const i = e.match(/Android (\d+)\.(\d+)/);
735
- if (i)
736
- return `${i[1]}.${i[2]}`;
737
- const n = e.match(/Windows NT (\d+\.\d+)/);
734
+ const n = e.match(/Android (\d+)\.(\d+)/);
738
735
  if (n)
739
- return n[1];
740
- const s = e.match(/Mac OS X (\d+[._]\d+)/);
741
- return s ? s[1].replace("_", ".") : "Unknown";
736
+ return `${n[1]}.${n[2]}`;
737
+ const s = e.match(/Windows NT (\d+\.\d+)/);
738
+ if (s)
739
+ return s[1];
740
+ const i = e.match(/Mac OS X (\d+[._]\d+)/);
741
+ return i ? i[1].replace("_", ".") : "Unknown";
742
742
  }
743
743
  /**
744
744
  * Detect Device Type (OpenRTB standard)
@@ -760,16 +760,16 @@ class I {
760
760
  const t = e.match(/iPhone(?:;\s*[^\)]*)?\s*(\d+,\d)?/);
761
761
  if (t) return `iPhone${t[1] || ""}`;
762
762
  if (/iPad/.test(e)) return "iPad";
763
- const i = e.match(/Samsung-.*(SM-\w+)/);
764
- if (i) return i[1];
763
+ const n = e.match(/Samsung-.*(SM-\w+)/);
764
+ if (n) return n[1];
765
765
  if (/Pixel/.test(e)) return "Google Pixel";
766
- const n = e.match(/(BARC-|HUAWEI-)?([A-Z]{2}\-\w{4})/);
767
- if (n) return n[2];
768
- const s = e.match(/(MI|Redmi|POCO)\s([\w\s]+)/);
769
- if (s) return s[1] + " " + s[2];
766
+ const s = e.match(/(BARC-|HUAWEI-)?([A-Z]{2}\-\w{4})/);
767
+ if (s) return s[2];
768
+ const i = e.match(/(MI|Redmi|POCO)\s([\w\s]+)/);
769
+ if (i) return i[1] + " " + i[2];
770
770
  if (/OnePlus/.test(e)) {
771
- const r = e.match(/OnePlus\s([A-Z\d]+)/);
772
- return r ? "OnePlus " + r[1] : "OnePlus";
771
+ const o = e.match(/OnePlus\s([A-Z\d]+)/);
772
+ return o ? "OnePlus " + o[1] : "OnePlus";
773
773
  }
774
774
  }
775
775
  /**
@@ -834,7 +834,7 @@ class I {
834
834
  */
835
835
  inferCountry(e, t) {
836
836
  if (!e && !t) return;
837
- const i = {
837
+ const n = {
838
838
  "Asia/Shanghai": "CN",
839
839
  "Asia/Hong_Kong": "HK",
840
840
  "Asia/Taipei": "TW",
@@ -879,12 +879,12 @@ class I {
879
879
  "Australia/Sydney": "AU",
880
880
  "Pacific/Auckland": "NZ"
881
881
  };
882
- if (t && i[t])
883
- return i[t];
882
+ if (t && n[t])
883
+ return n[t];
884
884
  if (e) {
885
- const n = e.split("-")[1];
886
- if (n)
887
- return n.toUpperCase();
885
+ const s = e.split("-")[1];
886
+ if (s)
887
+ return s.toUpperCase();
888
888
  }
889
889
  }
890
890
  /**
@@ -915,141 +915,141 @@ class I {
915
915
  this.cachedStaticInfo = null, this.cacheTimestamp = 0;
916
916
  }
917
917
  }
918
- const C = () => I.getInstance();
919
- function b(o) {
920
- return C().collect(o);
918
+ const C = () => S.getInstance();
919
+ function k(r) {
920
+ return C().collect(r);
921
921
  }
922
- function te() {
923
- return b().device;
922
+ function Y() {
923
+ return k().device;
924
924
  }
925
- function H() {
926
- return b().user;
925
+ function N() {
926
+ return k().user;
927
927
  }
928
- function ie() {
929
- return b().app;
928
+ function Q() {
929
+ return k().app;
930
930
  }
931
- function ne() {
932
- return b().geo;
931
+ function ee() {
932
+ return k().geo;
933
933
  }
934
- function D() {
935
- return H().id;
934
+ function H() {
935
+ return N().id;
936
936
  }
937
- function se() {
937
+ function te() {
938
938
  C().clearCache();
939
939
  }
940
- function re(o) {
941
- const e = b(o);
940
+ function ne(r) {
941
+ const e = k(r);
942
942
  return JSON.stringify(e, null, 2);
943
943
  }
944
- function oe() {
944
+ function se() {
945
945
  var t;
946
- const o = b();
946
+ const r = k();
947
947
  return [
948
- o.device.os,
949
- o.device.osv,
950
- o.app.name,
951
- o.user.id.slice(0, 8) + "...",
952
- ((t = o.geo) == null ? void 0 : t.country) || "Unknown"
948
+ r.device.os,
949
+ r.device.osv,
950
+ r.app.name,
951
+ r.user.id.slice(0, 8) + "...",
952
+ ((t = r.geo) == null ? void 0 : t.country) || "Unknown"
953
953
  ].join(" / ");
954
954
  }
955
- function B() {
955
+ function L() {
956
956
  if (typeof crypto > "u" || !crypto.subtle)
957
957
  throw new Error("Web Crypto API not supported");
958
958
  }
959
- async function G(o, e) {
960
- B();
961
- const t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(e)), i = await crypto.subtle.importKey("raw", t, "AES-GCM", !1, ["encrypt"]), n = crypto.getRandomValues(new Uint8Array(12)), s = await crypto.subtle.encrypt(
962
- { name: "AES-GCM", iv: n },
963
- i,
964
- new TextEncoder().encode(o)
965
- ), r = new Uint8Array(n.length + s.byteLength);
966
- return r.set(n), r.set(new Uint8Array(s), n.length), btoa(String.fromCharCode(...r));
967
- }
968
- async function F(o, e) {
969
- B();
970
- const t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(e)), i = await crypto.subtle.importKey("raw", t, "AES-GCM", !1, ["decrypt"]), n = Uint8Array.from(atob(o), (c) => c.charCodeAt(0)), s = n.slice(0, 12), r = n.slice(12), a = await crypto.subtle.decrypt(
959
+ async function G(r, e) {
960
+ L();
961
+ const t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(e)), n = await crypto.subtle.importKey("raw", t, "AES-GCM", !1, ["encrypt"]), s = crypto.getRandomValues(new Uint8Array(12)), i = await crypto.subtle.encrypt(
971
962
  { name: "AES-GCM", iv: s },
972
- i,
973
- r
963
+ n,
964
+ new TextEncoder().encode(r)
965
+ ), o = new Uint8Array(s.length + i.byteLength);
966
+ return o.set(s), o.set(new Uint8Array(i), s.length), btoa(String.fromCharCode(...o));
967
+ }
968
+ async function F(r, e) {
969
+ L();
970
+ const t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(e)), n = await crypto.subtle.importKey("raw", t, "AES-GCM", !1, ["decrypt"]), s = Uint8Array.from(atob(r), (c) => c.charCodeAt(0)), i = s.slice(0, 12), o = s.slice(12), a = await crypto.subtle.decrypt(
971
+ { name: "AES-GCM", iv: i },
972
+ n,
973
+ o
974
974
  );
975
975
  return new TextDecoder().decode(a);
976
976
  }
977
- function z() {
978
- var o;
979
- return typeof window < "u" ? !!((o = window.__AD_CONFIG__) != null && o.debug) : !1;
977
+ function D() {
978
+ var r;
979
+ return typeof window < "u" ? !!((r = window.__AD_CONFIG__) != null && r.debug) : !1;
980
980
  }
981
- function ae(o) {
981
+ function ie(r) {
982
982
  var e, t;
983
983
  return {
984
- id: o.original.id,
985
- type: o.original.type,
986
- score: o.original.score,
984
+ id: r.original.id,
985
+ type: r.original.type,
986
+ score: r.original.score,
987
987
  source: "internal",
988
988
  // Default source
989
989
  content: {
990
- title: o.adapted.title,
991
- body: o.adapted.body,
992
- image: (e = o.adapted.image) == null ? void 0 : e.url,
993
- cta_text: o.adapted.ctaText,
994
- price: (t = o.adapted.price) == null ? void 0 : t.display,
995
- rating: o.adapted.rating,
996
- brand: o.adapted.brand
990
+ title: r.adapted.title,
991
+ body: r.adapted.body,
992
+ image: (e = r.adapted.image) == null ? void 0 : e.url,
993
+ cta_text: r.adapted.ctaText,
994
+ price: (t = r.adapted.price) == null ? void 0 : t.display,
995
+ rating: r.adapted.rating,
996
+ brand: r.adapted.brand
997
997
  },
998
998
  tracking: {
999
- click_url: o.tracking.clickUrl || o.tracking.click_url || "",
1000
- impression_url: o.tracking.impressionUrl || o.tracking.impression_url || ""
999
+ click_url: r.tracking.clickUrl || r.tracking.click_url || "",
1000
+ impression_url: r.tracking.impressionUrl || r.tracking.impression_url || ""
1001
1001
  },
1002
1002
  metadata: {
1003
- viewToken: o.tracking.viewToken || o.tracking.view_token,
1004
- styling: o.adapted.styling
1003
+ viewToken: r.tracking.viewToken || r.tracking.view_token,
1004
+ styling: r.adapted.styling
1005
1005
  }
1006
1006
  };
1007
1007
  }
1008
- async function j(o, e = {}) {
1009
- const t = e.apiBaseUrl || "/api/v1", i = z(), s = C().collect(), r = {
1010
- ...o,
1011
- clientInfo: s
1008
+ async function V(r, e = {}) {
1009
+ const t = e.apiBaseUrl || "/api/v1", n = D(), i = C().collect(), o = {
1010
+ ...r,
1011
+ clientInfo: i
1012
1012
  }, a = {
1013
1013
  "Content-Type": "application/json"
1014
1014
  };
1015
1015
  e.apiKey && (a["X-API-Key"] = e.apiKey);
1016
1016
  let c;
1017
- if (e.apiKey && !i)
1017
+ if (e.apiKey && !n)
1018
1018
  try {
1019
- c = { encryptedPayload: await G(JSON.stringify(r), e.apiKey) };
1020
- } catch (h) {
1021
- i && console.warn("[fetchAds] Encryption failed, using plaintext:", h), c = r;
1019
+ c = { encryptedPayload: await G(JSON.stringify(o), e.apiKey) };
1020
+ } catch (f) {
1021
+ n && console.warn("[fetchAds] Encryption failed, using plaintext:", f), c = o;
1022
1022
  }
1023
1023
  else
1024
- c = r;
1025
- i && (console.log("[fetchAds] Request URL:", `${t}/ads/request`), console.log("[fetchAds] Request body:", c));
1026
- const d = await fetch(`${t}/ads/request`, {
1024
+ c = o;
1025
+ n && (console.log("[fetchAds] Request URL:", `${t}/ads/request`), console.log("[fetchAds] Request body:", c));
1026
+ const u = await fetch(`${t}/ads/request`, {
1027
1027
  method: "POST",
1028
1028
  headers: a,
1029
1029
  body: JSON.stringify(c)
1030
1030
  });
1031
- if (!d.ok)
1032
- throw new Error(`Ad request failed: ${d.status} ${d.statusText}`);
1033
- const l = await d.json();
1031
+ if (!u.ok)
1032
+ throw new Error(`Ad request failed: ${u.status} ${u.statusText}`);
1033
+ const l = await u.json();
1034
1034
  if (!l.success)
1035
1035
  throw new Error(l.error || "Ad request failed");
1036
- let u = l.data;
1036
+ let d = l.data;
1037
1037
  if (l.data.encryptedPayload && e.apiKey) {
1038
- const h = await F(l.data.encryptedPayload, e.apiKey);
1039
- u = JSON.parse(h);
1038
+ const f = await F(l.data.encryptedPayload, e.apiKey);
1039
+ d = JSON.parse(f);
1040
1040
  }
1041
- return i && console.log("[fetchAds] Response:", u), u;
1041
+ return n && console.log("[fetchAds] Response:", d), d;
1042
1042
  }
1043
- const W = { width: 400, height: 200 }, S = {
1043
+ const j = { width: 400, height: 200 }, x = {
1044
1044
  variant: "horizontal",
1045
1045
  count: 1,
1046
1046
  preferences: {}
1047
1047
  };
1048
- function M(o = {}) {
1048
+ function _(r = {}) {
1049
1049
  const e = {
1050
- variant: o.variant ?? S.variant,
1051
- count: o.count ?? S.count,
1052
- preferences: { ...S.preferences, ...o.preferences }
1050
+ variant: r.variant ?? x.variant,
1051
+ count: r.count ?? x.count,
1052
+ preferences: { ...x.preferences, ...r.preferences }
1053
1053
  };
1054
1054
  return [
1055
1055
  {
@@ -1057,16 +1057,16 @@ function M(o = {}) {
1057
1057
  slotName: "Action Card",
1058
1058
  format: "action_card",
1059
1059
  variant: e.variant,
1060
- size: W,
1060
+ size: j,
1061
1061
  count: e.count,
1062
1062
  preferences: e.preferences,
1063
1063
  placement: { position: "below_fold", context: "post_response" }
1064
1064
  }
1065
1065
  ];
1066
1066
  }
1067
- const g = class g {
1067
+ const p = class p {
1068
1068
  constructor(e) {
1069
- this.slots = {}, this.isLoading = !1, this.currentRequestId = null, this.adsAnalyticsMap = /* @__PURE__ */ new Map(), this.config = e, this.enabled = e.enabled !== !1, this.eventBus = new q(), this.slots_config = M(e.cardOption), typeof window < "u" && (window.__AD_CONFIG__ = {
1069
+ this.slots = {}, this.isLoading = !1, this.currentRequestId = null, this.adsAnalyticsMap = /* @__PURE__ */ new Map(), this.config = e, this.enabled = e.enabled !== !1, this.eventBus = new q(), this.slots_config = _(e.cardOption), typeof window < "u" && (window.__AD_CONFIG__ = {
1070
1070
  ...window.__AD_CONFIG__ || {},
1071
1071
  apiKey: e.apiKey,
1072
1072
  apiBaseUrl: e.apiBaseUrl,
@@ -1080,17 +1080,17 @@ const g = class g {
1080
1080
  async requestAds(e) {
1081
1081
  const t = "conversationContext" in e ? e : { conversationContext: e };
1082
1082
  this.currentUserId = this.resolveUserId(t.userContext);
1083
- const i = this.buildRequestKey(t), n = g.inFlightRequests.get(i);
1084
- if (n)
1085
- return this.config.debug && console.log("[AdManager] Reusing in-flight request for identical context"), n;
1083
+ const n = this.buildRequestKey(t), s = p.inFlightRequests.get(n);
1084
+ if (s)
1085
+ return this.config.debug && console.log("[AdManager] Reusing in-flight request for identical context"), s;
1086
1086
  if (!this.enabled)
1087
1087
  throw this.config.debug && console.warn("[AdManager] Ads are disabled, skipping request"), new Error("Ads are disabled");
1088
1088
  if (this.isLoading)
1089
1089
  throw this.config.debug && console.warn("[AdManager] Request already in progress"), new Error("Request already in progress");
1090
1090
  this.isLoading = !0, this.eventBus.emit("adsLoading"), this.config.debug && console.log("[AdManager] Starting ad request...");
1091
- const s = (async () => {
1091
+ const i = (async () => {
1092
1092
  try {
1093
- const r = await j(
1093
+ const o = await V(
1094
1094
  {
1095
1095
  conversationContext: t.conversationContext,
1096
1096
  userContext: t.userContext ? {
@@ -1105,11 +1105,11 @@ const g = class g {
1105
1105
  apiKey: this.config.apiKey
1106
1106
  }
1107
1107
  );
1108
- this.currentRequestId = r.requestId, this.adsAnalyticsMap.clear(), r.slots.forEach((c) => {
1109
- c.ads.forEach((d, l) => {
1110
- const u = d.original.id;
1111
- this.adsAnalyticsMap.set(u, {
1112
- requestId: r.requestId,
1108
+ this.currentRequestId = o.requestId, this.adsAnalyticsMap.clear(), o.slots.forEach((c) => {
1109
+ c.ads.forEach((u, l) => {
1110
+ const d = u.original.id;
1111
+ this.adsAnalyticsMap.set(d, {
1112
+ requestId: o.requestId,
1113
1113
  slotId: c.slotId,
1114
1114
  position: l,
1115
1115
  totalAds: c.ads.length,
@@ -1119,20 +1119,20 @@ const g = class g {
1119
1119
  });
1120
1120
  });
1121
1121
  const a = {};
1122
- return r.slots.forEach((c) => {
1122
+ return o.slots.forEach((c) => {
1123
1123
  a[c.slotId] = c;
1124
1124
  }), this.slots = a, this.eventBus.emit("adsUpdated", this.slots), this.config.debug && console.log("[AdManager] Ads received:", {
1125
1125
  slotCount: Object.keys(this.slots).length,
1126
1126
  slots: Object.keys(this.slots)
1127
- }), r;
1128
- } catch (r) {
1129
- const a = r;
1127
+ }), o;
1128
+ } catch (o) {
1129
+ const a = o;
1130
1130
  throw this.eventBus.emit("adsError", a), a;
1131
1131
  } finally {
1132
- this.isLoading = !1, g.inFlightRequests.delete(i);
1132
+ this.isLoading = !1, p.inFlightRequests.delete(n);
1133
1133
  }
1134
1134
  })();
1135
- return g.inFlightRequests.set(i, s), s;
1135
+ return p.inFlightRequests.set(n, i), i;
1136
1136
  }
1137
1137
  buildRequestKey(e) {
1138
1138
  return JSON.stringify({
@@ -1147,30 +1147,30 @@ const g = class g {
1147
1147
  if (e != null && e.userId)
1148
1148
  return e.userId;
1149
1149
  try {
1150
- return D();
1150
+ return H();
1151
1151
  } catch {
1152
1152
  return;
1153
1153
  }
1154
1154
  }
1155
- render(e, t, i = {}) {
1156
- const n = typeof e != "string", s = n ? g.DEFAULT_SLOT_ID : e, r = n ? e : t, a = (n ? t : i) || {};
1157
- if (!r)
1155
+ render(e, t, n = {}) {
1156
+ const s = typeof e != "string", i = s ? p.DEFAULT_SLOT_ID : e, o = s ? e : t, a = (s ? t : n) || {};
1157
+ if (!o)
1158
1158
  return this.config.debug && console.warn("[AdManager] Render container is required"), null;
1159
- const c = this.slots[s];
1159
+ const c = this.slots[i];
1160
1160
  if (!c || !c.ads || c.ads.length === 0)
1161
- return this.config.debug && console.warn("[AdManager] No ads in slot:", s), null;
1162
- const d = a.adIndex ?? 0, l = c.ads[d];
1161
+ return this.config.debug && console.warn("[AdManager] No ads in slot:", i), null;
1162
+ const u = a.adIndex ?? 0, l = c.ads[u];
1163
1163
  if (!l)
1164
- return this.config.debug && console.warn(`[AdManager] Ad at index ${d} not found in slot:`, s), null;
1165
- const u = this.adsAnalyticsMap.get(l.original.id), h = this.slots_config.find((k) => k.slotId === s), p = (h == null ? void 0 : h.format) || "action_card";
1166
- r.innerHTML = "";
1167
- const f = {
1168
- analytics: u,
1164
+ return this.config.debug && console.warn(`[AdManager] Ad at index ${u} not found in slot:`, i), null;
1165
+ const d = this.adsAnalyticsMap.get(l.original.id), f = this.slots_config.find((v) => v.slotId === i), g = (f == null ? void 0 : f.format) || "action_card";
1166
+ o.innerHTML = "";
1167
+ const h = {
1168
+ analytics: d,
1169
1169
  variant: a.variant,
1170
1170
  onClick: a.onClick,
1171
1171
  onImpression: a.onImpression
1172
1172
  };
1173
- return p === "suffix" ? y.renderSuffixAd(l, r, f) : p === "source" ? y.renderSponsoredSource(l, r, f) : p === "lead_gen" ? y.renderLeadGenAd(l, r, f) : y.renderActionCard(l, r, f);
1173
+ return g === "suffix" ? y.renderSuffixAd(l, o, h) : g === "source" ? y.renderSponsoredSource(l, o, h) : g === "lead_gen" ? y.renderLeadGenAd(l, o, h) : y.renderActionCard(l, o, h);
1174
1174
  }
1175
1175
  /**
1176
1176
  * Get ad slots data
@@ -1182,9 +1182,9 @@ const g = class g {
1182
1182
  * Check if a slot has ads
1183
1183
  */
1184
1184
  hasAds(e) {
1185
- var i;
1185
+ var n;
1186
1186
  const t = this.slots[e];
1187
- return (t == null ? void 0 : t.status) === "filled" && ((i = t.ads) == null ? void 0 : i.length) > 0;
1187
+ return (t == null ? void 0 : t.status) === "filled" && ((n = t.ads) == null ? void 0 : n.length) > 0;
1188
1188
  }
1189
1189
  /**
1190
1190
  * Get ads for a specific slot
@@ -1209,7 +1209,7 @@ const g = class g {
1209
1209
  * Update configuration
1210
1210
  */
1211
1211
  updateConfig(e) {
1212
- this.config = { ...this.config, ...e }, e.cardOption !== void 0 && (this.slots_config = M(this.config.cardOption)), this.config.debug && console.log("[AdManager] Config updated:", e);
1212
+ this.config = { ...this.config, ...e }, e.cardOption !== void 0 && (this.slots_config = _(this.config.cardOption)), this.config.debug && console.log("[AdManager] Config updated:", e);
1213
1213
  }
1214
1214
  /**
1215
1215
  * Clear all slot data
@@ -1252,52 +1252,52 @@ const g = class g {
1252
1252
  */
1253
1253
  getAdsAnalytics(e) {
1254
1254
  const t = /* @__PURE__ */ new Map();
1255
- return e.forEach((i) => {
1256
- const n = this.adsAnalyticsMap.get(i);
1257
- n && t.set(i, n);
1255
+ return e.forEach((n) => {
1256
+ const s = this.adsAnalyticsMap.get(n);
1257
+ s && t.set(n, s);
1258
1258
  }), t;
1259
1259
  }
1260
1260
  /**
1261
1261
  * Track ad click using Analytics API
1262
1262
  */
1263
- async trackAdClick(e, t, i) {
1264
- const n = this.adsAnalyticsMap.get(e);
1265
- if (!n || !this.currentRequestId)
1263
+ async trackAdClick(e, t, n) {
1264
+ const s = this.adsAnalyticsMap.get(e);
1265
+ if (!s || !this.currentRequestId)
1266
1266
  return this.config.debug && console.warn("[AdManager] No analytics info for ad:", e), null;
1267
- const s = w(), r = await O({
1267
+ const i = w(), o = await O({
1268
1268
  requestId: this.currentRequestId,
1269
1269
  adId: e,
1270
1270
  destinationUrl: t,
1271
- sessionId: s,
1272
- slotId: n.slotId,
1273
- adTitle: i == null ? void 0 : i.title,
1274
- format: i == null ? void 0 : i.format,
1275
- source: i == null ? void 0 : i.source,
1276
- userId: n.userId ?? this.currentUserId
1277
- }, { baseUrl: n.apiBaseUrl });
1278
- return r && (this.eventBus.emit("adClicked", e, n.slotId), this.config.debug && console.log("[AdManager] Click tracked via Analytics API:", r.eventId)), r;
1271
+ sessionId: i,
1272
+ slotId: s.slotId,
1273
+ adTitle: n == null ? void 0 : n.title,
1274
+ format: n == null ? void 0 : n.format,
1275
+ source: n == null ? void 0 : n.source,
1276
+ userId: s.userId ?? this.currentUserId
1277
+ }, { baseUrl: s.apiBaseUrl });
1278
+ return o && (this.eventBus.emit("adClicked", e, s.slotId), this.config.debug && console.log("[AdManager] Click tracked via Analytics API:", o.eventId)), o;
1279
1279
  }
1280
1280
  /**
1281
1281
  * Track ad impression using Analytics API
1282
1282
  */
1283
1283
  async trackAdImpressionAPI(e, t) {
1284
- const i = this.adsAnalyticsMap.get(e);
1285
- if (!i || !this.currentRequestId)
1284
+ const n = this.adsAnalyticsMap.get(e);
1285
+ if (!n || !this.currentRequestId)
1286
1286
  return this.config.debug && console.warn("[AdManager] No analytics info for ad:", e), null;
1287
- const n = w(), s = await T({
1287
+ const s = w(), i = await b({
1288
1288
  requestId: this.currentRequestId,
1289
1289
  adId: e,
1290
- slotId: i.slotId,
1291
- position: i.position,
1292
- totalAds: i.totalAds,
1293
- sessionId: n,
1290
+ slotId: n.slotId,
1291
+ position: n.position,
1292
+ totalAds: n.totalAds,
1293
+ sessionId: s,
1294
1294
  adTitle: t == null ? void 0 : t.title,
1295
1295
  format: t == null ? void 0 : t.format,
1296
1296
  source: t == null ? void 0 : t.source,
1297
1297
  viewToken: t == null ? void 0 : t.viewToken,
1298
- userId: i.userId ?? this.currentUserId
1299
- }, { baseUrl: i.apiBaseUrl });
1300
- return s && (this.eventBus.emit("adImpression", e, i.slotId), this.config.debug && console.log("[AdManager] Impression tracked via Analytics API:", s.eventId)), s;
1298
+ userId: n.userId ?? this.currentUserId
1299
+ }, { baseUrl: n.apiBaseUrl });
1300
+ return i && (this.eventBus.emit("adImpression", e, n.slotId), this.config.debug && console.log("[AdManager] Impression tracked via Analytics API:", i.eventId)), i;
1301
1301
  }
1302
1302
  /**
1303
1303
  * Destroy the manager and clean up
@@ -1306,297 +1306,37 @@ const g = class g {
1306
1306
  this.removeAllListeners(), this.clearSlots(), this.config.debug && console.log("[AdManager] Destroyed");
1307
1307
  }
1308
1308
  };
1309
- g.DEFAULT_SLOT_ID = "action_card", g.inFlightRequests = /* @__PURE__ */ new Map();
1310
- let _ = g;
1311
- function E() {
1312
- if (typeof window < "u") {
1313
- const o = window.__AD_CONFIG__;
1314
- if (o != null && o.apiKey)
1315
- return o.apiKey;
1316
- }
1317
- }
1318
- class Q {
1319
- constructor(e = {}, t = "/api/v1") {
1320
- var i, n;
1321
- this.observers = /* @__PURE__ */ new Map(), this.metrics = /* @__PURE__ */ new Map(), this.timers = /* @__PURE__ */ new Map(), this.batchTimers = /* @__PURE__ */ new Map(), this.eventQueue = /* @__PURE__ */ new Map(), this.isTracking = /* @__PURE__ */ new Map(), this.config = {
1322
- minVisiblePercentage: e.minVisiblePercentage ?? 50,
1323
- minViewableDuration: e.minViewableDuration ?? 1e3,
1324
- maxTrackingDuration: e.maxTrackingDuration ?? 6e4,
1325
- batchConfig: {
1326
- maxBatchSize: ((i = e.batchConfig) == null ? void 0 : i.maxBatchSize) ?? 5,
1327
- maxBatchWaitMs: ((n = e.batchConfig) == null ? void 0 : n.maxBatchWaitMs) ?? 1e4
1328
- },
1329
- debug: e.debug ?? !1
1330
- }, this.baseUrl = t;
1331
- }
1332
- /**
1333
- * Start tracking viewability for an ad element
1334
- */
1335
- startTracking(e, t, i, n, s) {
1336
- if (this.isTracking.get(e)) {
1337
- this.log(`[ViewabilityTracker] Already tracking ${e}, skipping`);
1338
- return;
1339
- }
1340
- this.log(`[ViewabilityTracker] Starting tracking for ${e}`);
1341
- const r = {
1342
- visiblePercentage: 0,
1343
- maxVisiblePercentage: 0,
1344
- totalVisibleTimeMs: 0,
1345
- currentVisibleTimeMs: 0,
1346
- isViewable: !1,
1347
- viewableAt: null,
1348
- enteredViewportAt: null,
1349
- enterCount: 0
1350
- };
1351
- this.metrics.set(e, r), this.isTracking.set(e, !0), this.eventQueue.set(e, []);
1352
- const a = new IntersectionObserver(
1353
- (d) => this.handleIntersection(e, d[0], i, n, s),
1354
- {
1355
- threshold: this.createThresholds()
1356
- }
1357
- );
1358
- a.observe(t), this.observers.set(e, a), this.startMonitoring(e, i, n, s);
1359
- const c = setTimeout(() => {
1360
- this.endTracking(e, i, n, s);
1361
- }, this.config.maxTrackingDuration);
1362
- this.timers.set(e, c);
1363
- }
1364
- /**
1365
- * Stop tracking an ad element
1366
- */
1367
- stopTracking(e) {
1368
- this.log(`[ViewabilityTracker] Manual stop tracking for ${e}`), this.cleanup(e);
1369
- }
1370
- /**
1371
- * Get current metrics for an ad
1372
- */
1373
- getMetrics(e) {
1374
- return this.metrics.get(e);
1375
- }
1376
- /**
1377
- * Handle IntersectionObserver callback
1378
- * Event-driven: Only process when state actually changes
1379
- */
1380
- handleIntersection(e, t, i, n, s) {
1381
- const r = this.metrics.get(e);
1382
- if (!r || !this.isTracking.get(e)) return;
1383
- const a = r.isViewable, c = Math.round(t.intersectionRatio * 100);
1384
- r.visiblePercentage = c, r.maxVisiblePercentage = Math.max(r.maxVisiblePercentage, c);
1385
- const d = Date.now(), l = c >= this.config.minVisiblePercentage;
1386
- if (l && !r.enteredViewportAt && (r.enteredViewportAt = d, r.enterCount++, this.log(`[ViewabilityTracker] ${e} entered viewport at ${d}`), this.queueEvent(e, {
1387
- adId: e,
1388
- sessionId: i,
1389
- requestId: n,
1390
- viewToken: s,
1391
- eventType: "enter_viewport",
1392
- visiblePercentage: c,
1393
- maxVisiblePercentage: r.maxVisiblePercentage,
1394
- totalVisibleTimeMs: r.totalVisibleTimeMs,
1395
- isViewable: !1,
1396
- timestamp: d
1397
- })), !l && r.enteredViewportAt) {
1398
- const u = d - r.enteredViewportAt;
1399
- r.totalVisibleTimeMs += u, r.enteredViewportAt = null, r.currentVisibleTimeMs = 0, this.log(`[ViewabilityTracker] ${e} exited viewport, total visible: ${r.totalVisibleTimeMs}ms`), this.queueEvent(e, {
1400
- adId: e,
1401
- sessionId: i,
1402
- requestId: n,
1403
- viewToken: s,
1404
- eventType: "exit_viewport",
1405
- visiblePercentage: c,
1406
- maxVisiblePercentage: r.maxVisiblePercentage,
1407
- totalVisibleTimeMs: r.totalVisibleTimeMs,
1408
- isViewable: r.isViewable,
1409
- timestamp: d
1410
- });
1411
- }
1412
- r.isViewable !== a && r.isViewable && this.log(`[ViewabilityTracker] ${e} became VIEWABLE!`), this.metrics.set(e, r);
1413
- }
1414
- /**
1415
- * Start monitoring loop for tracking duration
1416
- * Runs every 100ms to track continuous visible time
1417
- */
1418
- startMonitoring(e, t, i, n) {
1419
- const r = setInterval(() => {
1420
- const a = this.metrics.get(e);
1421
- if (!a || !this.isTracking.get(e)) {
1422
- clearInterval(r);
1423
- return;
1424
- }
1425
- const c = Date.now(), d = a.isViewable;
1426
- if (a.enteredViewportAt) {
1427
- const l = c - a.enteredViewportAt;
1428
- a.currentVisibleTimeMs = l, l >= this.config.minViewableDuration && a.visiblePercentage >= this.config.minVisiblePercentage && (a.isViewable = !0, d || (a.viewableAt = a.enteredViewportAt, this.log(`[ViewabilityTracker] ${e} BECAME VIEWABLE at ${a.viewableAt}`), this.queueEvent(e, {
1429
- adId: e,
1430
- sessionId: t,
1431
- requestId: i,
1432
- viewToken: n,
1433
- eventType: "become_viewable",
1434
- visiblePercentage: a.visiblePercentage,
1435
- maxVisiblePercentage: a.maxVisiblePercentage,
1436
- totalVisibleTimeMs: a.totalVisibleTimeMs,
1437
- isViewable: !0,
1438
- timestamp: c
1439
- })));
1440
- }
1441
- a.enteredViewportAt && (a.totalVisibleTimeMs += 100), this.metrics.set(e, a);
1442
- }, 100);
1443
- this.timers.set(`${e}_monitoring`, r);
1444
- }
1445
- /**
1446
- * Queue an event to be sent (batched)
1447
- */
1448
- queueEvent(e, t) {
1449
- var s, r;
1450
- const i = this.eventQueue.get(e);
1451
- if (!i) {
1452
- this.log(`[ViewabilityTracker] No queue found for ${e}, skipping event`);
1453
- return;
1454
- }
1455
- i.push(t), this.log(`[ViewabilityTracker] Queued ${t.eventType} for ${e} (queue size: ${i.length})`);
1456
- const n = ((s = this.config.batchConfig) == null ? void 0 : s.maxBatchSize) ?? 5;
1457
- if (i.length >= n)
1458
- this.flushQueue(e);
1459
- else {
1460
- const a = this.batchTimers.get(e);
1461
- a && clearTimeout(a);
1462
- const c = ((r = this.config.batchConfig) == null ? void 0 : r.maxBatchWaitMs) ?? 1e4, d = setTimeout(() => {
1463
- this.flushQueue(e);
1464
- }, c);
1465
- this.batchTimers.set(e, d);
1466
- }
1467
- }
1468
- /**
1469
- * Flush the event queue and send to server
1470
- */
1471
- async flushQueue(e) {
1472
- const t = this.eventQueue.get(e);
1473
- if (!t || t.length === 0) return;
1474
- const i = [...t];
1475
- t.length = 0, this.log(`[ViewabilityTracker] Flushing ${i.length} events for ${e}`);
1476
- try {
1477
- const n = {
1478
- "Content-Type": "application/json"
1479
- }, s = E();
1480
- s && (n["x-api-key"] = s), await fetch(`${this.baseUrl}/ads/viewability/batch`, {
1481
- method: "POST",
1482
- headers: n,
1483
- body: JSON.stringify({ events: i })
1484
- }), this.log(`[ViewabilityTracker] Successfully sent ${i.length} events for ${e}`);
1485
- } catch (n) {
1486
- this.log(`[ViewabilityTracker] Failed to send events for ${e}:`, n), t.unshift(...i);
1487
- }
1488
- }
1489
- /**
1490
- * End tracking and send final metrics
1491
- */
1492
- endTracking(e, t, i, n) {
1493
- const s = this.metrics.get(e);
1494
- if (!s) return;
1495
- this.log(`[ViewabilityTracker] Ending tracking for ${e}`), this.flushQueue(e);
1496
- const r = Date.now();
1497
- this.queueEvent(e, {
1498
- adId: e,
1499
- sessionId: t,
1500
- requestId: i,
1501
- viewToken: n,
1502
- eventType: "end_tracking",
1503
- visiblePercentage: s.visiblePercentage,
1504
- maxVisiblePercentage: s.maxVisiblePercentage,
1505
- totalVisibleTimeMs: s.totalVisibleTimeMs,
1506
- isViewable: s.isViewable,
1507
- timestamp: r
1508
- }), this.flushQueue(e), this.cleanup(e);
1509
- }
1510
- /**
1511
- * Cleanup resources for an ad
1512
- */
1513
- cleanup(e) {
1514
- const t = this.observers.get(e);
1515
- t && (t.disconnect(), this.observers.delete(e));
1516
- const i = this.timers.get(e);
1517
- i && (clearTimeout(i), this.timers.delete(e));
1518
- const n = this.timers.get(`${e}_monitoring`);
1519
- n && (clearInterval(n), this.timers.delete(`${e}_monitoring`));
1520
- const s = this.batchTimers.get(e);
1521
- s && (clearTimeout(s), this.batchTimers.delete(e)), this.flushQueue(e), this.isTracking.delete(e), this.metrics.delete(e), this.eventQueue.delete(e);
1522
- }
1523
- /**
1524
- * Create thresholds for IntersectionObserver
1525
- */
1526
- createThresholds() {
1527
- return [0, 0.25, 0.5, 0.75, 0.9, 1];
1528
- }
1529
- /**
1530
- * Stop all tracking
1531
- */
1532
- stopAll() {
1533
- const e = Array.from(this.isTracking.keys());
1534
- for (const t of e)
1535
- this.cleanup(t);
1536
- }
1537
- /**
1538
- * Debug logging
1539
- */
1540
- log(...e) {
1541
- this.config.debug && console.log(...e);
1542
- }
1543
- /**
1544
- * Send any pending events before page unload
1545
- */
1546
- setupBeforeUnload() {
1547
- typeof window < "u" && window.addEventListener("beforeunload", () => {
1548
- for (const e of this.eventQueue.keys()) {
1549
- const t = this.eventQueue.get(e);
1550
- if (t && t.length > 0) {
1551
- const i = {
1552
- "Content-Type": "application/json"
1553
- }, n = E();
1554
- n && (i["x-api-key"] = n), fetch(`${this.baseUrl}/ads/viewability/batch`, {
1555
- method: "POST",
1556
- headers: i,
1557
- keepalive: !0,
1558
- body: JSON.stringify({ events: t })
1559
- });
1560
- }
1561
- }
1562
- });
1563
- }
1564
- }
1565
- let A = null;
1566
- function ce(o, e) {
1567
- return A || (A = new Q(o, e), A.setupBeforeUnload()), A;
1568
- }
1569
- const le = "0.1.0";
1309
+ p.DEFAULT_SLOT_ID = "action_card", p.inFlightRequests = /* @__PURE__ */ new Map();
1310
+ let E = p;
1311
+ const re = "0.1.0";
1570
1312
  export {
1571
- _ as AdManager,
1572
- x as AnalyticsSender,
1573
- I as ClientInfoCollector,
1313
+ E as AdManager,
1314
+ A as AnalyticsSender,
1315
+ S as ClientInfoCollector,
1574
1316
  y as DOMRenderer,
1575
- v as HTMLRenderer,
1576
- le as SDK_VERSION,
1577
- V as SessionManager,
1578
- Q as ViewabilityTracker,
1579
- ae as adaptAdToKoahAd,
1580
- se as clearClientInfoCache,
1581
- Y as createAnalytics,
1582
- ee as createSession,
1317
+ I as HTMLRenderer,
1318
+ re as SDK_VERSION,
1319
+ M as SessionManager,
1320
+ ie as adaptAdToKoahAd,
1321
+ te as clearClientInfoCache,
1322
+ X as createAnalytics,
1323
+ Z as createSession,
1583
1324
  F as decryptAES,
1584
1325
  G as encryptAES,
1585
- j as fetchAds,
1586
- J as generateViewToken,
1587
- ie as getAppInfo,
1588
- b as getClientInfo,
1326
+ V as fetchAds,
1327
+ z as generateViewToken,
1328
+ Q as getAppInfo,
1329
+ k as getClientInfo,
1589
1330
  C as getClientInfoCollector,
1590
- re as getClientInfoJSON,
1591
- oe as getClientInfoSummary,
1592
- te as getDeviceInfo,
1593
- ne as getGeoInfo,
1331
+ ne as getClientInfoJSON,
1332
+ se as getClientInfoSummary,
1333
+ Y as getDeviceInfo,
1334
+ ee as getGeoInfo,
1594
1335
  w as getSessionId,
1595
- D as getUserId,
1596
- H as getUserInfo,
1597
- ce as getViewabilityTracker,
1336
+ H as getUserId,
1337
+ N as getUserInfo,
1598
1338
  O as trackAdClick,
1599
- T as trackAdImpression,
1600
- Z as trackClicksBatch,
1601
- X as trackImpressionsBatch
1339
+ b as trackAdImpression,
1340
+ J as trackClicksBatch,
1341
+ W as trackImpressionsBatch
1602
1342
  };