@active-reach/web-sdk 1.43.5 → 1.44.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 (32) hide show
  1. package/dist/aegis.min.js +1 -1
  2. package/dist/aegis.min.js.map +1 -1
  3. package/dist/chat/AegisChat.d.ts.map +1 -1
  4. package/dist/inapp/AegisInAppManager.d.ts +42 -0
  5. package/dist/inapp/AegisInAppManager.d.ts.map +1 -1
  6. package/dist/inapp/font.d.ts +118 -11
  7. package/dist/inapp/font.d.ts.map +1 -1
  8. package/dist/inapp/page-url-rules.d.ts +32 -0
  9. package/dist/inapp/page-url-rules.d.ts.map +1 -0
  10. package/dist/inapp/renderPreview.d.ts.map +1 -1
  11. package/dist/inapp/renderers/card-template.d.ts +11 -5
  12. package/dist/inapp/renderers/card-template.d.ts.map +1 -1
  13. package/dist/inapp/renderers/carousel-cards.d.ts.map +1 -1
  14. package/dist/inapp/renderers/coachmark-tour.d.ts.map +1 -1
  15. package/dist/inapp/renderers/games.d.ts.map +1 -1
  16. package/dist/inapp/renderers/hero.d.ts +0 -16
  17. package/dist/inapp/renderers/hero.d.ts.map +1 -1
  18. package/dist/inapp/renderers/product-recommendation.d.ts.map +1 -1
  19. package/dist/inapp/renderers/progress-bar.d.ts.map +1 -1
  20. package/dist/inapp/renderers/reviews.d.ts +1 -1
  21. package/dist/inapp/renderers/reviews.d.ts.map +1 -1
  22. package/dist/inapp/renderers/sticky-bar.d.ts.map +1 -1
  23. package/dist/inapp/renderers/stories.d.ts.map +1 -1
  24. package/dist/inapp/renderers/video.d.ts.map +1 -1
  25. package/dist/index.js +417 -101
  26. package/dist/index.js.map +1 -1
  27. package/dist/integrations/react.d.ts.map +1 -1
  28. package/dist/runtime/AegisMessageRuntime.d.ts +6 -0
  29. package/dist/runtime/AegisMessageRuntime.d.ts.map +1 -1
  30. package/dist/triggers/IntentRuleEvaluator.d.ts.map +1 -1
  31. package/dist/widgets/AegisWidgetManager.d.ts.map +1 -1
  32. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -360,15 +360,221 @@ function lucideSvg(name, opts = {}) {
360
360
  }).join("");
361
361
  return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="${escapeAttr(color)}" stroke-width="${strokeWidth}" stroke-linecap="round" stroke-linejoin="round"${cls} ${a11y}>${children}</svg>`;
362
362
  }
363
- const IN_APP_FONT_STACK = "'Urbanist', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif";
364
- function ensureInAppFont() {
365
- if (typeof document === "undefined") return;
366
- if (document.getElementById("aegis-inapp-font-urbanist")) return;
367
- const link = document.createElement("link");
368
- link.id = "aegis-inapp-font-urbanist";
369
- link.rel = "stylesheet";
370
- link.href = "https://fonts.googleapis.com/css2?family=Urbanist:wght@400;500;600;700;800&display=swap";
371
- document.head.appendChild(link);
363
+ const keywords = ["inherit", "system", "serif", "mono"];
364
+ const system_stacks = { "system": "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif", "serif": "Georgia, 'Times New Roman', serif", "mono": "ui-monospace, 'SF Mono', Menlo, monospace" };
365
+ const aliases = { "system-ui": "system", "-apple-system": "system", "georgia": "serif", "times new roman": "serif", "sf mono": "mono", "ui-monospace": "mono", "menlo": "mono", "monospace": "mono" };
366
+ const role_weights = { "body": [400, 500], "display": [600, 700] };
367
+ const google = [{ "name": "Urbanist", "category": "sans-serif", "fallback": { "local": "Arial", "size_adjust": "99.04%", "ascent_override": "95.93%", "descent_override": "25.24%", "line_gap_override": "0.00%" } }, { "name": "Inter", "category": "sans-serif", "fallback": { "local": "Arial", "size_adjust": "107.12%", "ascent_override": "90.44%", "descent_override": "22.52%", "line_gap_override": "0.00%" } }, { "name": "Poppins", "category": "sans-serif", "fallback": { "local": "Arial", "size_adjust": "112.16%", "ascent_override": "93.62%", "descent_override": "31.21%", "line_gap_override": "8.92%" } }, { "name": "DM Sans", "category": "sans-serif", "fallback": { "local": "Arial", "size_adjust": "104.53%", "ascent_override": "94.90%", "descent_override": "29.66%", "line_gap_override": "0.00%" } }, { "name": "Nunito", "category": "sans-serif", "fallback": { "local": "Arial", "size_adjust": "101.39%", "ascent_override": "99.71%", "descent_override": "34.82%", "line_gap_override": "0.00%" } }, { "name": "Montserrat", "category": "sans-serif", "fallback": { "local": "Arial", "size_adjust": "112.83%", "ascent_override": "85.79%", "descent_override": "22.25%", "line_gap_override": "0.00%" } }, { "name": "Roboto", "category": "sans-serif", "fallback": { "local": "Arial", "size_adjust": "99.78%", "ascent_override": "92.98%", "descent_override": "24.47%", "line_gap_override": "0.00%" } }, { "name": "Outfit", "category": "sans-serif", "fallback": { "local": "Arial", "size_adjust": "99.82%", "ascent_override": "100.18%", "descent_override": "26.05%", "line_gap_override": "0.00%" } }, { "name": "Playfair Display", "category": "serif", "fallback": { "local": "Times New Roman", "size_adjust": "111.26%", "ascent_override": "97.25%", "descent_override": "22.56%", "line_gap_override": "0.00%" } }, { "name": "Lora", "category": "serif", "fallback": { "local": "Times New Roman", "size_adjust": "115.20%", "ascent_override": "87.33%", "descent_override": "23.78%", "line_gap_override": "0.00%" } }];
368
+ const FONT_ALLOWLIST = {
369
+ keywords,
370
+ system_stacks,
371
+ aliases,
372
+ role_weights,
373
+ google
374
+ };
375
+ const BODY_FONT_STACK = "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif";
376
+ const SERIF_STACK = "Georgia, 'Times New Roman', serif";
377
+ const AEGIS_BODY_FONT_VAR = "--aegis-font-body";
378
+ const AEGIS_DISPLAY_FONT_VAR = "--aegis-font-display";
379
+ const ACS_DISPLAY_FONT_VAR = "--acs-font-display";
380
+ const ACS_BODY_FONT_VAR = "--acs-font-body";
381
+ const GOOGLE_FONTS = FONT_ALLOWLIST.google;
382
+ const KEYWORDS = FONT_ALLOWLIST.keywords;
383
+ const SYSTEM_STACKS = FONT_ALLOWLIST.system_stacks;
384
+ const ALIASES = FONT_ALLOWLIST.aliases;
385
+ const ROLE_WEIGHTS = FONT_ALLOWLIST.role_weights;
386
+ function fontFamilyCss(role) {
387
+ return `font-family:var(${role === "display" ? AEGIS_DISPLAY_FONT_VAR : AEGIS_BODY_FONT_VAR});`;
388
+ }
389
+ function findGoogleFont(value) {
390
+ const v = value.trim().toLowerCase();
391
+ return GOOGLE_FONTS.find((f) => f.name.toLowerCase() === v);
392
+ }
393
+ function normalizeFontValue(value) {
394
+ var _a;
395
+ if (typeof value !== "string") return null;
396
+ const first = value.split(",")[0].trim().replace(/^['"]|['"]$/g, "").trim();
397
+ if (!first) return null;
398
+ const v = first.toLowerCase();
399
+ if (KEYWORDS.includes(v)) return v;
400
+ if (ALIASES[v]) return ALIASES[v];
401
+ return ((_a = findGoogleFont(first)) == null ? void 0 : _a.name) ?? null;
402
+ }
403
+ function fallbackFamily(f) {
404
+ return `${f.name} Aegis Fallback`;
405
+ }
406
+ function fontValueToCss(value, host = "third_party") {
407
+ const canonical = normalizeFontValue(value);
408
+ if (!canonical) return null;
409
+ if (canonical === "inherit") return { css: "initial" };
410
+ if (SYSTEM_STACKS[canonical]) return { css: SYSTEM_STACKS[canonical] };
411
+ const f = findGoogleFont(canonical);
412
+ if (!f) return null;
413
+ const stack = f.category === "serif" ? SERIF_STACK : BODY_FONT_STACK;
414
+ if (host === "acs") return { css: `var(${acsFaceVar(f)}), ${stack}` };
415
+ return { css: `'${f.name}', '${fallbackFamily(f)}', ${stack}`, font: f };
416
+ }
417
+ function acsFaceVar(f) {
418
+ return `--acs-face-${f.name.toLowerCase().replace(/ /g, "-")}`;
419
+ }
420
+ function readRootVar(name) {
421
+ if (typeof document === "undefined" || typeof getComputedStyle !== "function") return "";
422
+ try {
423
+ return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
424
+ } catch {
425
+ return "";
426
+ }
427
+ }
428
+ function detectFontHost(read = readRootVar) {
429
+ return read(ACS_BODY_FONT_VAR) ? "acs" : "third_party";
430
+ }
431
+ function resolveRootFonts(brand, read = readRootVar) {
432
+ const host = detectFontHost(read);
433
+ if (host === "acs") {
434
+ return {
435
+ host,
436
+ body: `var(${ACS_BODY_FONT_VAR})`,
437
+ display: read(ACS_DISPLAY_FONT_VAR) ? `var(${ACS_DISPLAY_FONT_VAR})` : `var(${ACS_BODY_FONT_VAR})`,
438
+ load: []
439
+ };
440
+ }
441
+ const load = [];
442
+ const pick = (role) => {
443
+ const served = fontValueToCss(role === "display" ? brand == null ? void 0 : brand.display : brand == null ? void 0 : brand.body);
444
+ if (!served) return null;
445
+ if (served.font) load.push({ font: served.font, role });
446
+ return served.css;
447
+ };
448
+ const body = pick("body");
449
+ const display = pick("display");
450
+ return { host, body, display, load };
451
+ }
452
+ const LINK_ID = "aegis-inapp-fonts";
453
+ const FALLBACK_STYLE_ID = "aegis-inapp-font-fallbacks";
454
+ const PRECONNECT_ORIGINS = ["https://fonts.googleapis.com", "https://fonts.gstatic.com"];
455
+ const requested = /* @__PURE__ */ new Map();
456
+ function googleFontsHref(families) {
457
+ const parts = [...families.keys()].sort((a, b) => a.localeCompare(b)).map((name) => {
458
+ const weights = [...families.get(name) ?? []].sort((a, b) => a - b);
459
+ return `family=${name.replace(/ /g, "+")}:wght@${weights.join(";")}`;
460
+ });
461
+ return `https://fonts.googleapis.com/css2?${parts.join("&")}&display=swap`;
462
+ }
463
+ function fallbackFaceCss(fonts) {
464
+ return fonts.map(
465
+ (f) => `@font-face{font-family:'${fallbackFamily(f)}';src:local('${f.fallback.local}');size-adjust:${f.fallback.size_adjust};ascent-override:${f.fallback.ascent_override};descent-override:${f.fallback.descent_override};line-gap-override:${f.fallback.line_gap_override};}`
466
+ ).join("\n");
467
+ }
468
+ function ensurePreconnect() {
469
+ for (const origin of PRECONNECT_ORIGINS) {
470
+ if (document.head.querySelector(`link[rel="preconnect"][href="${origin}"]`)) continue;
471
+ const l = document.createElement("link");
472
+ l.rel = "preconnect";
473
+ l.href = origin;
474
+ if (origin.includes("gstatic")) l.crossOrigin = "anonymous";
475
+ document.head.appendChild(l);
476
+ }
477
+ }
478
+ function loadFonts(loads, read = readRootVar) {
479
+ if (typeof document === "undefined" || loads.length === 0) return;
480
+ if (detectFontHost(read) === "acs") return;
481
+ let grew = false;
482
+ for (const { font, role } of loads) {
483
+ const known = findGoogleFont(font.name);
484
+ if (!known) continue;
485
+ const set = requested.get(known.name) ?? /* @__PURE__ */ new Set();
486
+ for (const w of ROLE_WEIGHTS[role]) {
487
+ if (!set.has(w)) {
488
+ set.add(w);
489
+ grew = true;
490
+ }
491
+ }
492
+ requested.set(known.name, set);
493
+ }
494
+ if (!grew) return;
495
+ ensurePreconnect();
496
+ let style = document.getElementById(FALLBACK_STYLE_ID);
497
+ if (!style) {
498
+ style = document.createElement("style");
499
+ style.id = FALLBACK_STYLE_ID;
500
+ document.head.appendChild(style);
501
+ }
502
+ style.textContent = fallbackFaceCss(
503
+ [...requested.keys()].map((n) => findGoogleFont(n)).filter((f) => !!f)
504
+ );
505
+ let link = document.getElementById(LINK_ID);
506
+ if (!link) {
507
+ link = document.createElement("link");
508
+ link.id = LINK_ID;
509
+ link.rel = "stylesheet";
510
+ document.head.appendChild(link);
511
+ }
512
+ link.href = googleFontsHref(requested);
513
+ }
514
+ function applyRootFonts(brand, read = readRootVar) {
515
+ const r = resolveRootFonts(brand, read);
516
+ if (typeof document === "undefined") return r;
517
+ const root = document.documentElement.style;
518
+ if (r.body) root.setProperty(AEGIS_BODY_FONT_VAR, r.body);
519
+ else root.removeProperty(AEGIS_BODY_FONT_VAR);
520
+ if (r.display) root.setProperty(AEGIS_DISPLAY_FONT_VAR, r.display);
521
+ else root.removeProperty(AEGIS_DISPLAY_FONT_VAR);
522
+ loadFonts(r.load, read);
523
+ return r;
524
+ }
525
+ function campaignFontFamily(campaign) {
526
+ var _a;
527
+ const style = (_a = campaign == null ? void 0 : campaign.interactive_config) == null ? void 0 : _a.style;
528
+ if (style && typeof style === "object") {
529
+ const ff = style.fontFamily;
530
+ if (typeof ff === "string" && ff.trim()) return ff;
531
+ }
532
+ return void 0;
533
+ }
534
+ function campaignFontVarsCss(value, read = readRootVar) {
535
+ const served = fontValueToCss(value, detectFontHost(read));
536
+ if (!served) return "";
537
+ if (served.font) {
538
+ loadFonts(
539
+ [
540
+ { font: served.font, role: "body" },
541
+ { font: served.font, role: "display" }
542
+ ],
543
+ read
544
+ );
545
+ }
546
+ return `${AEGIS_BODY_FONT_VAR}:${served.css};${AEGIS_DISPLAY_FONT_VAR}:${served.css};`;
547
+ }
548
+ const CAMPAIGN_SHEET_ID = "aegis-campaign-fonts";
549
+ const SAFE_ID = /^[A-Za-z0-9_-]{1,128}$/;
550
+ function registerCampaignFonts(campaigns, read = readRootVar) {
551
+ const rules = [];
552
+ for (const c of campaigns) {
553
+ const id = typeof c.id === "string" ? c.id : "";
554
+ if (!SAFE_ID.test(id)) continue;
555
+ const decl = campaignFontVarsCss(campaignFontFamily(c), read);
556
+ if (decl) rules.push(`[data-campaign-id="${id}"]{${decl}}`);
557
+ }
558
+ const css = rules.join("\n");
559
+ if (typeof document === "undefined") return css;
560
+ let sheet = document.getElementById(CAMPAIGN_SHEET_ID);
561
+ if (!css) {
562
+ sheet == null ? void 0 : sheet.remove();
563
+ return css;
564
+ }
565
+ if (!sheet) {
566
+ sheet = document.createElement("style");
567
+ sheet.id = CAMPAIGN_SHEET_ID;
568
+ document.head.appendChild(sheet);
569
+ }
570
+ sheet.textContent = css;
571
+ return css;
572
+ }
573
+ function applyCampaignFonts(campaigns, read = readRootVar) {
574
+ var _a;
575
+ const brand = ((_a = campaigns.find((c) => c.brand_typography)) == null ? void 0 : _a.brand_typography) ?? null;
576
+ applyRootFonts(brand, read);
577
+ registerCampaignFonts(campaigns, read);
372
578
  }
373
579
  function npsBandFromScore(score) {
374
580
  if (score <= 6) return "detractor";
@@ -449,16 +655,8 @@ const WEIGHT = {
449
655
  const ICON_PX = { sm: 22, md: 30, lg: 40 };
450
656
  const TEXT_PX = { sm: 11.5, md: 13, lg: 15 };
451
657
  const RAIL_TILE_FLEX = "flex:0 0 clamp(150px, 15vw, 220px); scroll-snap-align:start;";
452
- function sanitizeFontFamily(v) {
453
- return v.replace(/[^a-zA-Z0-9 ,"'-]/g, "").slice(0, 120);
454
- }
455
658
  function resolveCardFont(ff) {
456
- if (ff === "inherit") return "";
457
- if (ff && ff.trim()) return sanitizeFontFamily(ff);
458
- return IN_APP_FONT_STACK;
459
- }
460
- function ensureCardFontLoaded(resolvedFont) {
461
- if (/urbanist/i.test(resolvedFont)) ensureInAppFont();
659
+ return `${campaignFontVarsCss(ff)}${fontFamilyCss("body")}`;
462
660
  }
463
661
  function interpolateTokens(s, ctx) {
464
662
  if (!s || s.indexOf("{") === -1) return s;
@@ -1549,8 +1747,8 @@ function renderCardFromTemplate(card, opts) {
1549
1747
  const muted = fg === "#ffffff" ? "rgba(255,255,255,0.72)" : "#6b7280";
1550
1748
  const tile = document.createElement("div");
1551
1749
  tile.setAttribute("data-aegis-reaction-anchor", "");
1552
- const cardFont = resolveCardFont(frame.fontFamily);
1553
- ensureCardFontLoaded(cardFont);
1750
+ const cardFont = resolveCardFont(campaignFontFamily(campaign) ?? frame.fontFamily);
1751
+ const displayFont = fontFamilyCss("display");
1554
1752
  const radius = frame.radius !== void 0 ? `${parseInt(String(frame.radius), 10) || 12}px` : "12px";
1555
1753
  const fLayout = frame.layout;
1556
1754
  const dir = fLayout === "row" ? "row" : "column";
@@ -1559,7 +1757,7 @@ function renderCardFromTemplate(card, opts) {
1559
1757
  tile.style.cssText = `
1560
1758
  box-sizing:border-box; display:flex; flex-direction:${dir}; ${fLayout === "row" ? "align-items:center;" : ""} gap:${tileGap}px; position:relative;
1561
1759
  color:${fg};
1562
- ${cardFont ? `font-family:${cardFont};` : ""}
1760
+ ${cardFont}
1563
1761
  background:${frame.bg ? sanitizeColor(frame.bg) : "#ffffff"};
1564
1762
  border:1px solid ${frame.border ? sanitizeColor(frame.border) : "transparent"};
1565
1763
  border-radius:${radius}; padding:8px;
@@ -1619,7 +1817,10 @@ function renderCardFromTemplate(card, opts) {
1619
1817
  }
1620
1818
  case "price": {
1621
1819
  const node = paintPrice(card, el2, accent, ctx);
1622
- if (node) container.appendChild(node);
1820
+ if (node) {
1821
+ node.style.cssText += `${displayFont}font-variant-numeric:tabular-nums;`;
1822
+ container.appendChild(node);
1823
+ }
1623
1824
  break;
1624
1825
  }
1625
1826
  case "title": {
@@ -1627,7 +1828,7 @@ function renderCardFromTemplate(card, opts) {
1627
1828
  const t = document.createElement("div");
1628
1829
  t.textContent = card.title;
1629
1830
  const lines = el2.lines && el2.lines > 0 ? el2.lines : 2;
1630
- t.style.cssText = `font-size:12.5px;font-weight:600;line-height:1.3;text-align:${el2.align ?? "left"};color:${el2.color ? sanitizeColor(el2.color) : fg};display:-webkit-box;-webkit-line-clamp:${lines};-webkit-box-orient:vertical;overflow:hidden;`;
1831
+ t.style.cssText = `${displayFont}font-size:12.5px;font-weight:600;line-height:1.3;text-align:${el2.align ?? "left"};color:${el2.color ? sanitizeColor(el2.color) : fg};display:-webkit-box;-webkit-line-clamp:${lines};-webkit-box-orient:vertical;overflow:hidden;`;
1631
1832
  container.appendChild(t);
1632
1833
  break;
1633
1834
  }
@@ -1798,7 +1999,6 @@ function renderCarouselCards(ctx) {
1798
1999
  const loop = ic.loop !== false;
1799
2000
  const layout = ic.rec_layout || "row";
1800
2001
  addAnimationStyles();
1801
- ensureInAppFont();
1802
2002
  const bg = "#ffffff";
1803
2003
  const fg = "#0f172a";
1804
2004
  const accent = sanitizeColor(campaign.background_color || "#4169e1");
@@ -1809,7 +2009,7 @@ function renderCarouselCards(ctx) {
1809
2009
  position: fixed; left: 0; right: 0; bottom: 0;
1810
2010
  z-index: 99999; padding: 12px 12px 20px;
1811
2011
  background: rgba(0,0,0,0.12); backdrop-filter: blur(8px);
1812
- font-family: ${IN_APP_FONT_STACK};
2012
+ ${fontFamilyCss("body")}
1813
2013
  animation: aegisSlideInFromBottom 0.3s ease-out;
1814
2014
  `;
1815
2015
  const card = document.createElement("div");
@@ -1993,7 +2193,7 @@ function renderStickyBar(ctx) {
1993
2193
  position: fixed; ${positionCss}
1994
2194
  background: ${bg}; color: ${fg};
1995
2195
  padding: 10px 14px; z-index: 999998;
1996
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
2196
+ ${fontFamilyCss("body")}
1997
2197
  display: flex; align-items: center; gap: 12px; justify-content: center;
1998
2198
  box-shadow: 0 ${position === "top" ? "2px" : "-2px"} 8px rgba(0,0,0,0.08);
1999
2199
  `;
@@ -2081,14 +2281,14 @@ function buildProgressBar(ctx, inline) {
2081
2281
  bar.style.cssText = inline ? `
2082
2282
  background: ${bg}; color: ${fg};
2083
2283
  padding: 10px 14px;
2084
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
2284
+ ${fontFamilyCss("body")}
2085
2285
  ` : `
2086
2286
  position: fixed; left: 12px; right: 12px; bottom: 12px;
2087
2287
  max-width: 540px; margin: 0 auto;
2088
2288
  background: ${bg}; color: ${fg}; border-radius: 12px;
2089
2289
  padding: 10px 14px; z-index: 999997;
2090
2290
  box-shadow: 0 8px 20px rgba(0,0,0,0.08);
2091
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
2291
+ ${fontFamilyCss("body")}
2092
2292
  animation: aegisSlideInFromBottom 0.3s ease-out;
2093
2293
  `;
2094
2294
  const label = document.createElement("div");
@@ -2357,7 +2557,7 @@ function renderCoachmarkTour(ctx) {
2357
2557
  padding: 12px 14px; border-radius: 12px;
2358
2558
  max-width: 260px;
2359
2559
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
2360
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
2560
+ ${fontFamilyCss("body")}
2361
2561
  animation: aegisFadeIn 0.2s ease;
2362
2562
  `;
2363
2563
  const titleEl = document.createElement("div");
@@ -2467,7 +2667,6 @@ function renderProductRecommendation(ctx) {
2467
2667
  const layout = ic.rec_layout || "grid";
2468
2668
  const template = resolveGlobalTemplate(ic);
2469
2669
  addAnimationStyles();
2470
- ensureInAppFont();
2471
2670
  const bg = "#ffffff";
2472
2671
  const fg = "#0f172a";
2473
2672
  const accent = sanitizeColor(campaign.background_color || "#4169e1");
@@ -2486,7 +2685,7 @@ function renderProductRecommendation(ctx) {
2486
2685
  max-width: 560px; width: 100%; max-height: 80vh; overflow-y: auto;
2487
2686
  border-radius: 20px 20px 0 0;
2488
2687
  padding: 18px 16px 22px;
2489
- font-family: ${IN_APP_FONT_STACK};
2688
+ ${fontFamilyCss("body")}
2490
2689
  animation: aegisSlideInFromBottom 0.3s ease-out;
2491
2690
  box-shadow: 0 -12px 30px rgba(0,0,0,0.12);
2492
2691
  `;
@@ -2566,12 +2765,11 @@ function renderProductRecommendationInline(ctx, target) {
2566
2765
  const fg = "#0f172a";
2567
2766
  const accent = sanitizeColor(campaign.background_color || "#4169e1");
2568
2767
  addAnimationStyles();
2569
- ensureInAppFont();
2570
2768
  const section = document.createElement("section");
2571
2769
  section.className = "aegis-in-app-product-rec-inline";
2572
2770
  section.setAttribute("data-campaign-id", campaign.id);
2573
2771
  section.style.cssText = `
2574
- font-family: ${IN_APP_FONT_STACK};
2772
+ ${fontFamilyCss("body")}
2575
2773
  color: ${fg};
2576
2774
  `;
2577
2775
  if (campaign.title) {
@@ -2727,14 +2925,14 @@ function renderLauncherBar(ctx, cfg, target) {
2727
2925
  padding: 14px 18px 16px 20px; scroll-padding-left: 20px;
2728
2926
  background: ${surfaceBg}; backdrop-filter: blur(8px);
2729
2927
  box-shadow: 0 -4px 16px rgba(0,0,0,0.08); scrollbar-width: none;
2730
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
2928
+ ${fontFamilyCss("body")}
2731
2929
  animation: aegisSlideInFromBottom 0.3s ease-out;
2732
2930
  ` : `
2733
2931
  display: flex; gap: 16px; align-items: flex-start; overflow-x: auto;
2734
2932
  padding: 12px 18px 12px 18px; scroll-padding-left: 18px;
2735
2933
  background: ${surfaceBg}; ${cfg.branded ? "border-radius: 16px;" : ""}
2736
2934
  scrollbar-width: none;
2737
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
2935
+ ${fontFamilyCss("body")}
2738
2936
  `;
2739
2937
  cfg.groups.forEach((g, i) => bar.appendChild(buildGroupBubble(ctx, cfg, g, i, labelColor)));
2740
2938
  if (floating) {
@@ -2855,7 +3053,7 @@ function openViewer(ctx, cfg, startGroupIndex, startFrameIndex = 0) {
2855
3053
  overlay.style.cssText = `
2856
3054
  position: fixed; inset: 0; z-index: 100000; background: #000;
2857
3055
  display: flex; align-items: center; justify-content: center;
2858
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
3056
+ ${fontFamilyCss("body")}
2859
3057
  animation: aegisFadeIn 0.25s ease;
2860
3058
  `;
2861
3059
  const stage = document.createElement("div");
@@ -2985,7 +3183,7 @@ function openViewer(ctx, cfg, startGroupIndex, startFrameIndex = 0) {
2985
3183
  if (f.title) {
2986
3184
  const t = document.createElement("div");
2987
3185
  t.textContent = f.title;
2988
- t.style.cssText = "font-family: 'Urbanist', system-ui, sans-serif; font-size: 21px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; margin-bottom: 6px; text-shadow: 0 1px 8px rgba(0,0,0,0.4);";
3186
+ t.style.cssText = `${fontFamilyCss("display")} font-size: 21px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; margin-bottom: 6px; text-shadow: 0 1px 8px rgba(0,0,0,0.4);`;
2989
3187
  copy.appendChild(t);
2990
3188
  }
2991
3189
  if (f.body) {
@@ -3151,7 +3349,7 @@ function openGameModal(ctx, className, maxWidth = 360) {
3151
3349
  const overlay = document.createElement("div");
3152
3350
  overlay.className = className;
3153
3351
  overlay.setAttribute("data-campaign-id", campaign.id);
3154
- overlay.style.cssText = 'position:fixed;inset:0;z-index:100000;background:rgba(15,23,42,0.55);backdrop-filter:blur(4px);display:flex;align-items:center;justify-content:center;padding:16px;font-family:"Urbanist",system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;animation:aegisFadeIn 0.25s ease;';
3352
+ overlay.style.cssText = `position:fixed;inset:0;z-index:100000;background:rgba(15,23,42,0.55);backdrop-filter:blur(4px);display:flex;align-items:center;justify-content:center;padding:16px;${fontFamilyCss("body")}animation:aegisFadeIn 0.25s ease;`;
3155
3353
  const card = document.createElement("div");
3156
3354
  card.style.cssText = `position:relative;width:100%;max-width:${maxWidth}px;max-height:88vh;overflow-y:auto;background:${bg};color:${fg};border-radius:20px;padding:24px 20px 20px;box-shadow:0 16px 48px rgba(0,0,0,0.22);animation:aegisScaleIn 0.3s ease;text-align:center;`;
3157
3355
  let removed = false;
@@ -3176,7 +3374,7 @@ function openGameModal(ctx, className, maxWidth = 360) {
3176
3374
  if (campaign.title) {
3177
3375
  const t = document.createElement("div");
3178
3376
  t.textContent = campaign.title;
3179
- t.style.cssText = "font-family:'Urbanist',system-ui,sans-serif;font-size:18px;font-weight:800;letter-spacing:-0.01em;margin:2px 24px 4px;line-height:1.25;";
3377
+ t.style.cssText = `${fontFamilyCss("display")}font-size:18px;font-weight:800;letter-spacing:-0.01em;margin:2px 24px 4px;line-height:1.25;`;
3180
3378
  card.appendChild(t);
3181
3379
  }
3182
3380
  if (campaign.body) {
@@ -3918,7 +4116,7 @@ function caption(ctx, accent, onCard) {
3918
4116
  if (campaign.title) {
3919
4117
  const t = document.createElement("div");
3920
4118
  t.textContent = campaign.title;
3921
- t.style.cssText = `font-family:'Urbanist',system-ui,sans-serif;font-size:17px;font-weight:800;letter-spacing:-0.01em;line-height:1.2;${onCard ? "text-shadow:0 1px 8px rgba(0,0,0,0.4);" : ""}`;
4119
+ t.style.cssText = `${fontFamilyCss("display")}font-size:17px;font-weight:800;letter-spacing:-0.01em;line-height:1.2;${onCard ? "text-shadow:0 1px 8px rgba(0,0,0,0.4);" : ""}`;
3922
4120
  box.appendChild(t);
3923
4121
  }
3924
4122
  if (campaign.body) {
@@ -3964,7 +4162,7 @@ function renderVideo(ctx) {
3964
4162
  const overlay = document.createElement("div");
3965
4163
  overlay.className = "aegis-in-app-video-overlay";
3966
4164
  overlay.setAttribute("data-campaign-id", campaign.id);
3967
- overlay.style.cssText = 'position:fixed;inset:0;z-index:100000;background:rgba(15,23,42,0.6);backdrop-filter:blur(4px);display:flex;align-items:center;justify-content:center;padding:16px;font-family:"Urbanist",system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;animation:aegisFadeIn 0.25s ease;';
4165
+ overlay.style.cssText = `position:fixed;inset:0;z-index:100000;background:rgba(15,23,42,0.6);backdrop-filter:blur(4px);display:flex;align-items:center;justify-content:center;padding:16px;${fontFamilyCss("body")}animation:aegisFadeIn 0.25s ease;`;
3968
4166
  const card = document.createElement("div");
3969
4167
  card.style.cssText = `position:relative;width:100%;max-width:${o.aspect === "9:16" ? 320 : 460}px;background:#fff;border-radius:18px;overflow:hidden;box-shadow:0 16px 48px rgba(0,0,0,0.28);animation:aegisScaleIn 0.3s ease;`;
3970
4168
  const media = buildVideo(ctx, o.aspect, o.autoplay, o.loop);
@@ -4009,7 +4207,7 @@ function renderVideoInline(ctx, target) {
4009
4207
  const banner = document.createElement("div");
4010
4208
  banner.className = "aegis-in-app-video-banner";
4011
4209
  banner.setAttribute("data-campaign-id", ctx.campaign.id);
4012
- banner.style.cssText = 'width:100%;font-family:"Urbanist",system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;';
4210
+ banner.style.cssText = `width:100%;${fontFamilyCss("body")}`;
4013
4211
  const media = buildVideo(ctx, o.aspect, o.autoplay, o.loop);
4014
4212
  if (o.overlayCaption) {
4015
4213
  const c = caption(ctx, o.accent, true);
@@ -4071,7 +4269,7 @@ function renderHeroInline(ctx, target) {
4071
4269
  if (variant === "announcement_bar") {
4072
4270
  const c = cards[0];
4073
4271
  const bar = document.createElement("div");
4074
- bar.style.cssText = `display:flex;align-items:center;justify-content:center;gap:10px;background:${accent};color:#fff;padding:8px 14px;font:600 13px/1.3 Inter,system-ui,sans-serif;text-align:center;`;
4272
+ bar.style.cssText = `display:flex;align-items:center;justify-content:center;gap:10px;background:${accent};color:#fff;padding:8px 14px;font-weight:600;font-size:13px;line-height:1.3;${fontFamilyCss("body")}text-align:center;`;
4075
4273
  bar.textContent = [cardHeadline(c), cardSub(c)].filter(Boolean).join(" · ");
4076
4274
  const url = sanitizeUrl(cardUrl(c));
4077
4275
  if (url && cardCta(c)) {
@@ -4149,14 +4347,14 @@ function renderHeroInline(ctx, target) {
4149
4347
  if (h) {
4150
4348
  const head = document.createElement("h2");
4151
4349
  head.textContent = h;
4152
- head.style.cssText = "margin:0;color:#fff;font:800 24px/1.2 Inter Tight,Inter,system-ui,sans-serif;letter-spacing:-0.02em;text-shadow:0 1px 8px rgba(0,0,0,0.35);max-width:90%;";
4350
+ head.style.cssText = `margin:0;color:#fff;font-weight:800;font-size:24px;line-height:1.2;${fontFamilyCss("display")}letter-spacing:-0.02em;text-shadow:0 1px 8px rgba(0,0,0,0.35);max-width:90%;`;
4153
4351
  content.appendChild(head);
4154
4352
  }
4155
4353
  const s = cardSub(c);
4156
4354
  if (s) {
4157
4355
  const sub = document.createElement("p");
4158
4356
  sub.textContent = s;
4159
- sub.style.cssText = "margin:0;color:rgba(255,255,255,0.92);font:500 14px/1.4 Inter,system-ui,sans-serif;text-shadow:0 1px 6px rgba(0,0,0,0.3);max-width:90%;";
4357
+ sub.style.cssText = `margin:0;color:rgba(255,255,255,0.92);font-weight:500;font-size:14px;line-height:1.4;${fontFamilyCss("body")}text-shadow:0 1px 6px rgba(0,0,0,0.3);max-width:90%;`;
4160
4358
  content.appendChild(sub);
4161
4359
  }
4162
4360
  const cta = cardCta(c);
@@ -4164,7 +4362,7 @@ function renderHeroInline(ctx, target) {
4164
4362
  if (cta && chrome.cta_style !== "none") {
4165
4363
  const btn = document.createElement("button");
4166
4364
  btn.textContent = cta;
4167
- btn.style.cssText = chrome.cta_style === "underline" ? `margin-top:6px;background:none;border:none;color:#fff;font:700 14px Inter,system-ui,sans-serif;text-decoration:underline;cursor:pointer;padding:0;` : `margin-top:8px;background:${accent};color:#fff;border:none;border-radius:999px;padding:9px 18px;font:700 13px Inter,system-ui,sans-serif;cursor:pointer;box-shadow:0 4px 12px rgba(0,0,0,0.2);`;
4365
+ btn.style.cssText = chrome.cta_style === "underline" ? `margin-top:6px;background:none;border:none;color:#fff;font-weight:500;font-size:14px;${fontFamilyCss("body")}text-decoration:underline;cursor:pointer;padding:0;` : `margin-top:8px;background:${accent};color:#fff;border:none;border-radius:999px;padding:9px 18px;font-weight:500;font-size:13px;${fontFamilyCss("body")}cursor:pointer;box-shadow:0 4px 12px rgba(0,0,0,0.2);`;
4168
4366
  btn.addEventListener("click", () => {
4169
4367
  var _a;
4170
4368
  trackEvent(campaign.id, "clicked", { stepId: `card_${i}` });
@@ -4912,7 +5110,7 @@ class AegisChat {
4912
5110
  }
4913
5111
  }
4914
5112
  const CHAT_CSS = `
4915
- .aegis-chat-root{position:fixed;bottom:20px;right:20px;z-index:2147483000;font-family:Inter,system-ui,-apple-system,sans-serif}
5113
+ .aegis-chat-root{position:fixed;bottom:20px;right:20px;z-index:2147483000;${fontFamilyCss("body")}}
4916
5114
  .aegis-chat-root--bottom-left{left:20px;right:auto}
4917
5115
  .aegis-chat-root--bottom-left .aegis-chat-panel{left:0;right:auto}
4918
5116
  .aegis-chat-bubble-logo{width:34px;height:34px;border-radius:9999px;object-fit:cover}
@@ -5783,7 +5981,6 @@ const SORTS = [
5783
5981
  ];
5784
5982
  function renderReviewsInline(ctx, target, creds) {
5785
5983
  if (typeof document === "undefined" || !(creds == null ? void 0 : creds.apiHost) || !(creds == null ? void 0 : creds.writeKey)) return false;
5786
- ensureInAppFont();
5787
5984
  const ic = ctx.campaign.interactive_config || {};
5788
5985
  const cfg = target.closest("[data-aegis-slot]") ?? target;
5789
5986
  const accent = ctx.sanitizeColor(
@@ -5794,7 +5991,7 @@ function renderReviewsInline(ctx, target, creds) {
5794
5991
  const productId = cfg.getAttribute("data-product-id") || ctx.campaign.product_id || null;
5795
5992
  const state = { sort: "recent", withPhotos: false };
5796
5993
  target.innerHTML = "";
5797
- target.appendChild(el("div", `font-family:${IN_APP_FONT_STACK};font-size:13px;color:#9ca3af;padding:10px 0;`, "Loading reviews…"));
5994
+ target.appendChild(el("div", `${fontFamilyCss("body")}font-size:13px;color:#9ca3af;padding:10px 0;`, "Loading reviews…"));
5798
5995
  function buildUrl() {
5799
5996
  const url = new URL("/v1/reviews/public", creds.apiHost);
5800
5997
  if (productId) url.searchParams.set("product_id", productId);
@@ -5960,7 +6157,7 @@ function renderReviewsInline(ctx, target, creds) {
5960
6157
  target.innerHTML = "";
5961
6158
  const root = el(
5962
6159
  "section",
5963
- `font-family:${IN_APP_FONT_STACK};color:#111827;max-width:860px;margin:0 auto;-webkit-font-smoothing:antialiased;`
6160
+ `${fontFamilyCss("body")}color:#111827;max-width:860px;margin:0 auto;-webkit-font-smoothing:antialiased;`
5964
6161
  );
5965
6162
  root.setAttribute("data-aegis-reviews", "true");
5966
6163
  const summary = data.aggregate.ai_summary;
@@ -5998,7 +6195,7 @@ function renderReviewsInline(ctx, target, creds) {
5998
6195
  if (data.aggregate.count === 0) return;
5999
6196
  const root = el(
6000
6197
  "section",
6001
- `font-family:${IN_APP_FONT_STACK};color:#111827;max-width:860px;margin:0 auto;border:1px solid #f0f1f3;border-radius:16px;padding:16px 18px;`
6198
+ `${fontFamilyCss("body")}color:#111827;max-width:860px;margin:0 auto;border:1px solid #f0f1f3;border-radius:16px;padding:16px 18px;`
6002
6199
  );
6003
6200
  const line = el("div", "display:flex;align-items:center;gap:8px;");
6004
6201
  const avg = data.aggregate.avg_rating ?? 0;
@@ -6030,12 +6227,11 @@ function renderReviewsInline(ctx, target, creds) {
6030
6227
  }
6031
6228
  function renderReviewsOverlay(ctx, creds) {
6032
6229
  if (typeof document === "undefined" || !(creds == null ? void 0 : creds.apiHost) || !(creds == null ? void 0 : creds.writeKey)) return;
6033
- ensureInAppFont();
6034
6230
  const overlay = document.createElement("div");
6035
6231
  overlay.setAttribute("data-campaign-id", ctx.campaign.id);
6036
6232
  overlay.style.cssText = "position:fixed;inset:0;background:rgba(17,24,39,0.5);display:flex;align-items:flex-end;justify-content:center;z-index:99999;";
6037
6233
  const sheet = document.createElement("div");
6038
- sheet.style.cssText = `background:#fff;color:#111827;max-width:680px;width:100%;max-height:84vh;overflow-y:auto;border-radius:24px 24px 0 0;padding:18px 18px 28px;font-family:${IN_APP_FONT_STACK};box-shadow:0 -16px 40px rgba(0,0,0,0.14);`;
6234
+ sheet.style.cssText = `background:#fff;color:#111827;max-width:680px;width:100%;max-height:84vh;overflow-y:auto;border-radius:24px 24px 0 0;padding:18px 18px 28px;${fontFamilyCss("body")}box-shadow:0 -16px 40px rgba(0,0,0,0.14);`;
6039
6235
  sheet.appendChild(el("div", "width:38px;height:4px;border-radius:999px;background:#e5e7eb;margin:0 auto 14px;"));
6040
6236
  const bar = el("div", "display:flex;justify-content:space-between;align-items:center;margin-bottom:10px;");
6041
6237
  bar.appendChild(el("div", "font-weight:800;font-size:17px;", ctx.campaign.title || "Customer reviews"));
@@ -6362,6 +6558,33 @@ function scratchOutcome(resp) {
6362
6558
  if (resp.won === false || (prize == null ? void 0 : prize.win) === false || (prize == null ? void 0 : prize.prize_type) === "no_prize") return false;
6363
6559
  return void 0;
6364
6560
  }
6561
+ function patternMatches(pattern, pageUrl) {
6562
+ let re;
6563
+ try {
6564
+ re = new RegExp(pattern.split("*").join(".*"), "y");
6565
+ } catch {
6566
+ return false;
6567
+ }
6568
+ re.lastIndex = 0;
6569
+ return re.test(pageUrl);
6570
+ }
6571
+ function pageUrlRulesPass(rules, pageUrl) {
6572
+ if (!rules || !pageUrl) return true;
6573
+ const match = rules.page_url_match;
6574
+ if (match) {
6575
+ const patterns = match.split(",").map((p) => p.trim()).filter((p) => p.length > 0);
6576
+ if (patterns.length > 0 && !patterns.some((p) => patternMatches(p, pageUrl))) {
6577
+ return false;
6578
+ }
6579
+ }
6580
+ const exclude = rules.page_url_exclude;
6581
+ if (exclude) {
6582
+ for (const piece of exclude.split(",")) {
6583
+ if (patternMatches(piece.trim(), pageUrl)) return false;
6584
+ }
6585
+ }
6586
+ return true;
6587
+ }
6365
6588
  const RETURNING_MARKER_KEY = "aegis_returning_user";
6366
6589
  const SESSION_VERDICT_KEY = "aegis_new_visitor_session";
6367
6590
  let cachedVerdict = null;
@@ -6553,8 +6776,11 @@ const _AegisInAppManager = class _AegisInAppManager {
6553
6776
  this.filledSlots = /* @__PURE__ */ new WeakSet();
6554
6777
  this.slotSignatures = /* @__PURE__ */ new WeakMap();
6555
6778
  this.slotTimers = /* @__PURE__ */ new WeakMap();
6779
+ this.renderedSlots = /* @__PURE__ */ new Set();
6556
6780
  this.slotObserver = null;
6557
6781
  this.slotRenderScheduled = false;
6782
+ this.slotsTornDown = false;
6783
+ this.lifecycleGen = 0;
6558
6784
  this.slotUnfilledBeaconed = /* @__PURE__ */ new Set();
6559
6785
  this.slotUnfilledSweepTimer = null;
6560
6786
  this._pushOptInLoading = false;
@@ -6573,6 +6799,12 @@ const _AegisInAppManager = class _AegisInAppManager {
6573
6799
  if (config.productUrl) this.productUrl = config.productUrl;
6574
6800
  this.getWorkspaceId = config.getWorkspaceId;
6575
6801
  this.getCartState = config.getCartState;
6802
+ if (config.surface && _AegisInAppManager.KNOWN_SURFACES.has(config.surface)) {
6803
+ this.currentSurface = config.surface;
6804
+ }
6805
+ const screen = config.screen || config.surface;
6806
+ if (screen && screen !== "page_view") this.currentScreen = screen;
6807
+ if (config.locationId) this.currentLocationId = config.locationId;
6576
6808
  }
6577
6809
  emit(eventName, payload) {
6578
6810
  const handlers = this.hooks.get(eventName);
@@ -6661,6 +6893,7 @@ const _AegisInAppManager = class _AegisInAppManager {
6661
6893
  return this.register("error", handler);
6662
6894
  }
6663
6895
  async initialize() {
6896
+ this.slotsTornDown = false;
6664
6897
  if (this.isInitialized) {
6665
6898
  this.log("AegisInApp already initialized");
6666
6899
  return;
@@ -6673,7 +6906,7 @@ const _AegisInAppManager = class _AegisInAppManager {
6673
6906
  }
6674
6907
  } catch {
6675
6908
  }
6676
- ensureInAppFont();
6909
+ applyRootFonts(null);
6677
6910
  await this.refreshCampaigns();
6678
6911
  if (this.enableSSE && this.organizationId) {
6679
6912
  this.connectSSE();
@@ -6681,8 +6914,10 @@ const _AegisInAppManager = class _AegisInAppManager {
6681
6914
  this.isInitialized = true;
6682
6915
  if (this.pendingPreInitRefresh) {
6683
6916
  this.pendingPreInitRefresh = false;
6684
- this.log("Re-fetching campaigns for surface/screen declared during init");
6685
- void this.refreshCampaigns();
6917
+ if (this.activeRequestKey() !== this.lastActiveRequestKey) {
6918
+ this.log("Re-fetching campaigns for surface/screen declared during init");
6919
+ void this.refreshCampaigns();
6920
+ }
6686
6921
  }
6687
6922
  if (typeof Notification !== "undefined" && Notification.permission === "granted" && this.propertyId) {
6688
6923
  let alreadyHealed = false;
@@ -6789,6 +7024,11 @@ const _AegisInAppManager = class _AegisInAppManager {
6789
7024
  }
6790
7025
  this.refreshCampaigns();
6791
7026
  }
7027
+ /** The page context a `/v1/in-app/active` request is built from now. */
7028
+ activeRequestKey() {
7029
+ const url = this.currentPageUrl() ?? "/";
7030
+ return [url, this.currentSurface ?? "", this.currentScreen ?? "", this.currentLocationId ?? ""].join("|");
7031
+ }
6792
7032
  /**
6793
7033
  * Qualifying-event refresh — schedule a debounced `refreshCampaigns()`
6794
7034
  * call in response to a host-app SDK event (`aegis.page()`,
@@ -6832,6 +7072,10 @@ const _AegisInAppManager = class _AegisInAppManager {
6832
7072
  this.log(`refreshOnEvent(${eventName}) before initialize — surface captured, refetch deferred to initialize()`);
6833
7073
  return;
6834
7074
  }
7075
+ if (isScreenDeclaration && this.lastActiveRequestKey !== void 0 && this.activeRequestKey() === this.lastActiveRequestKey) {
7076
+ this.log(`refreshOnEvent(${eventName}) — page context unchanged, no refetch`);
7077
+ return;
7078
+ }
6835
7079
  if (this.refreshDebounceTimer) {
6836
7080
  clearTimeout(this.refreshDebounceTimer);
6837
7081
  }
@@ -7077,6 +7321,8 @@ const _AegisInAppManager = class _AegisInAppManager {
7077
7321
  }, delay);
7078
7322
  }
7079
7323
  async refreshCampaigns() {
7324
+ const gen = this.lifecycleGen;
7325
+ let requestKey;
7080
7326
  try {
7081
7327
  const context = new URLSearchParams({
7082
7328
  device_type: this.detectDeviceType(),
@@ -7095,6 +7341,8 @@ const _AegisInAppManager = class _AegisInAppManager {
7095
7341
  context.set("location_id", this.currentLocationId);
7096
7342
  }
7097
7343
  const url = `${this.apiHost}/v1/in-app/active?${context.toString()}`;
7344
+ requestKey = this.activeRequestKey();
7345
+ this.lastActiveRequestKey = requestKey;
7098
7346
  const headers = {
7099
7347
  "X-Aegis-Write-Key": this.writeKey,
7100
7348
  "Content-Type": "application/json"
@@ -7123,11 +7371,14 @@ const _AegisInAppManager = class _AegisInAppManager {
7123
7371
  headers,
7124
7372
  credentials: "include"
7125
7373
  });
7374
+ if (gen !== this.lifecycleGen) return;
7126
7375
  if (!response.ok) {
7127
7376
  throw new Error(`Failed to fetch campaigns: ${response.status}`);
7128
7377
  }
7129
7378
  const payload = await response.json();
7379
+ if (gen !== this.lifecycleGen) return;
7130
7380
  this.campaigns = Array.isArray(payload) ? payload : [];
7381
+ applyCampaignFonts(this.campaigns);
7131
7382
  this.processABAssignments(this.campaigns);
7132
7383
  this.rehydrateSuppressionFromStorage();
7133
7384
  this.log(`Fetched ${this.campaigns.length} campaigns`);
@@ -7140,6 +7391,10 @@ const _AegisInAppManager = class _AegisInAppManager {
7140
7391
  this.renderIntoAnchors();
7141
7392
  this.renderTokenAnchors();
7142
7393
  } catch (error) {
7394
+ if (requestKey !== void 0 && this.lastActiveRequestKey === requestKey) {
7395
+ this.lastActiveRequestKey = void 0;
7396
+ }
7397
+ if (gen !== this.lifecycleGen) return;
7143
7398
  this.emitError(error, { stage: "refresh-campaigns" });
7144
7399
  this.log(`Error refreshing campaigns: ${error}`, "error");
7145
7400
  }
@@ -7277,6 +7532,30 @@ const _AegisInAppManager = class _AegisInAppManager {
7277
7532
  if (this.currentScreen !== null) return false;
7278
7533
  return true;
7279
7534
  }
7535
+ /** The page URL the server's page rules saw: what `refreshCampaigns` sends
7536
+ * as `page_url` (pathname + search, credential values redacted). Null off
7537
+ * the browser — no page, no filter (the server's rule too). */
7538
+ currentPageUrl() {
7539
+ if (typeof window === "undefined" || !window.location) return null;
7540
+ return redactUrl((window.location.pathname || "") + (window.location.search || ""));
7541
+ }
7542
+ /** The full client placement gate: screen/surface tier AND page rules, both
7543
+ * mirroring `/v1/in-app/active`, applied to CACHED campaigns (the page may
7544
+ * have changed since the fetch — SPA navigation). */
7545
+ isPlaceableHere(c) {
7546
+ return this.matchesCurrentScreenOrSurface(c) && pageUrlRulesPass(c, this.currentPageUrl());
7547
+ }
7548
+ /** Remove everything this manager injected into `slot` and stop its rotation. */
7549
+ clearSlotContent(slot) {
7550
+ const timer = this.slotTimers.get(slot);
7551
+ if (timer) {
7552
+ clearInterval(timer);
7553
+ this.slotTimers.delete(slot);
7554
+ }
7555
+ slot.querySelectorAll(
7556
+ ":scope > [data-aegis-rotate-pane], :scope > [data-aegis-slot-rendered], :scope > [data-aegis-rotate-dots]"
7557
+ ).forEach((n) => n.remove());
7558
+ }
7280
7559
  // Re-fill slots that mount after a poll (SPA route changes). Observes the DOM
7281
7560
  // once; when a new [data-aegis-slot] appears it re-runs renderIntoSlots from
7282
7561
  // the cached campaigns (idempotent — already-filled slots are skipped). Does
@@ -7303,6 +7582,7 @@ const _AegisInAppManager = class _AegisInAppManager {
7303
7582
  this.slotRenderScheduled = true;
7304
7583
  const run = () => {
7305
7584
  this.slotRenderScheduled = false;
7585
+ if (this.slotsTornDown) return;
7306
7586
  this.renderIntoSlots();
7307
7587
  };
7308
7588
  if (typeof requestAnimationFrame === "function") requestAnimationFrame(run);
@@ -7312,15 +7592,23 @@ const _AegisInAppManager = class _AegisInAppManager {
7312
7592
  }
7313
7593
  renderIntoSlots() {
7314
7594
  var _a, _b;
7315
- if (typeof document === "undefined") return;
7595
+ if (typeof document === "undefined" || this.slotsTornDown) return;
7316
7596
  this.ensureSlotObserver();
7317
7597
  this.scheduleSlotUnfilledSweep();
7598
+ this.renderedSlots.forEach((slot) => {
7599
+ if (slot.isConnected === false) {
7600
+ const timer = this.slotTimers.get(slot);
7601
+ if (timer) clearInterval(timer);
7602
+ this.slotTimers.delete(slot);
7603
+ this.renderedSlots.delete(slot);
7604
+ }
7605
+ });
7318
7606
  const slots = document.querySelectorAll("[data-aegis-slot]");
7319
7607
  if (slots.length === 0) return;
7320
7608
  const eligibleByCategory = /* @__PURE__ */ new Map();
7321
7609
  const seenIds = /* @__PURE__ */ new Set();
7322
7610
  for (const c of this.campaigns) {
7323
- if (!this.matchesCurrentScreenOrSurface(c)) continue;
7611
+ if (!this.isPlaceableHere(c)) continue;
7324
7612
  const modes = c.delivery_modes;
7325
7613
  const category = c.widget_category;
7326
7614
  if (!modes || !modes.includes("embedded_card")) continue;
@@ -7347,18 +7635,6 @@ const _AegisInAppManager = class _AegisInAppManager {
7347
7635
  if (!key) return;
7348
7636
  const list = eligibleByCategory.get(key);
7349
7637
  if (!list || list.length === 0) return;
7350
- const sig = list.map((c) => `${c.id}:${c.assigned_variant_id ?? ""}`).join(",");
7351
- if (this.filledSlots.has(slot) && this.slotSignatures.get(slot) === sig) return;
7352
- const oldTimer = this.slotTimers.get(slot);
7353
- if (oldTimer) {
7354
- clearInterval(oldTimer);
7355
- this.slotTimers.delete(slot);
7356
- }
7357
- slot.querySelectorAll(
7358
- ":scope > [data-aegis-rotate-pane], :scope > [data-aegis-slot-rendered], :scope > [data-aegis-rotate-dots]"
7359
- ).forEach((n) => n.remove());
7360
- this.slotSignatures.set(slot, sig);
7361
- slot.querySelectorAll(":scope > [data-aegis-slot-default]").forEach((d) => d.remove());
7362
7638
  const attrMs = parseInt(slot.getAttribute("data-aegis-slot-rotate") || "0", 10);
7363
7639
  const declaredMs = list.reduce((m2, c) => {
7364
7640
  var _a2;
@@ -7366,8 +7642,16 @@ const _AegisInAppManager = class _AegisInAppManager {
7366
7642
  return Number.isFinite(v) && v > m2 ? v : m2;
7367
7643
  }, 0);
7368
7644
  const rotateMs = attrMs > 0 ? attrMs : declaredMs;
7645
+ const rotating = rotateMs > 0 && list.length > 1;
7646
+ const shown = rotating ? list : list.slice(0, 1);
7647
+ const sig = (rotating ? "rotate:" : "one:") + shown.map((c) => `${c.id}:${c.assigned_variant_id ?? ""}`).join(",");
7648
+ if (this.filledSlots.has(slot) && this.slotSignatures.get(slot) === sig) return;
7649
+ this.clearSlotContent(slot);
7650
+ this.slotSignatures.set(slot, sig);
7651
+ this.renderedSlots.add(slot);
7652
+ slot.querySelectorAll(":scope > [data-aegis-slot-default]").forEach((d) => d.remove());
7369
7653
  const flush = slot.hasAttribute("data-aegis-slot-flush");
7370
- if (rotateMs > 0 && list.length > 1) {
7654
+ if (rotating) {
7371
7655
  this.renderRotatingSlot(slot, list, rotateMs, flush);
7372
7656
  } else {
7373
7657
  const host = document.createElement("div");
@@ -7414,7 +7698,7 @@ const _AegisInAppManager = class _AegisInAppManager {
7414
7698
  });
7415
7699
  const path = typeof window !== "undefined" ? window.location.pathname : "";
7416
7700
  for (const c of this.campaigns) {
7417
- if (!this.matchesCurrentScreenOrSurface(c)) continue;
7701
+ if (!this.isPlaceableHere(c)) continue;
7418
7702
  if (!c.delivery_modes || !c.delivery_modes.includes("embedded_card")) continue;
7419
7703
  const category = c.widget_category;
7420
7704
  if (!category || present.has(category)) continue;
@@ -7509,9 +7793,13 @@ const _AegisInAppManager = class _AegisInAppManager {
7509
7793
  });
7510
7794
  };
7511
7795
  let timer = null;
7512
- const start = () => setInterval(() => {
7513
- show(idx + 1);
7514
- }, rotateMs);
7796
+ const start = () => {
7797
+ const t = setInterval(() => {
7798
+ show(idx + 1);
7799
+ }, rotateMs);
7800
+ this.slotTimers.set(slot, t);
7801
+ return t;
7802
+ };
7515
7803
  function show(i, fromClick = false) {
7516
7804
  panes[idx].el.style.display = "none";
7517
7805
  idx = (i % panes.length + panes.length) % panes.length;
@@ -7528,7 +7816,6 @@ const _AegisInAppManager = class _AegisInAppManager {
7528
7816
  paintDots();
7529
7817
  if (panes.length === 1) return;
7530
7818
  timer = start();
7531
- this.slotTimers.set(slot, timer);
7532
7819
  if (typeof window !== "undefined") {
7533
7820
  window.addEventListener("beforeunload", () => timer && clearInterval(timer), { once: true });
7534
7821
  }
@@ -7553,7 +7840,7 @@ const _AegisInAppManager = class _AegisInAppManager {
7553
7840
  var _a;
7554
7841
  if (typeof document === "undefined") return;
7555
7842
  for (const c of this.campaigns) {
7556
- if (!this.matchesCurrentScreenOrSurface(c)) continue;
7843
+ if (!this.isPlaceableHere(c)) continue;
7557
7844
  const modes = c.delivery_modes;
7558
7845
  if (!modes || !modes.includes("embedded_card")) continue;
7559
7846
  const ic = c.interactive_config;
@@ -8355,7 +8642,7 @@ const _AegisInAppManager = class _AegisInAppManager {
8355
8642
  body.style.cssText = `padding: ${st.padY ?? 22}px ${st.padX ?? 20}px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px;`;
8356
8643
  if (campaign.title) {
8357
8644
  const t = document.createElement("div");
8358
- t.style.cssText = `font-size: 18px; font-weight: 800; letter-spacing: -0.01em; text-align: center; font-family: 'Urbanist', system-ui, -apple-system, sans-serif;`;
8645
+ t.style.cssText = `font-size: 18px; font-weight: 800; letter-spacing: -0.01em; text-align: center; ${fontFamilyCss("display")}`;
8359
8646
  t.textContent = campaign.title;
8360
8647
  body.appendChild(t);
8361
8648
  }
@@ -8455,7 +8742,7 @@ const _AegisInAppManager = class _AegisInAppManager {
8455
8742
  }
8456
8743
  const tx = document.createElement("span");
8457
8744
  tx.textContent = label;
8458
- tx.style.cssText = `white-space: nowrap; line-height: 1.05; font-size: ${fontPx}px; font-weight: 900; font-family: 'Urbanist', system-ui, -apple-system, sans-serif; letter-spacing: 0.2px; text-transform: uppercase; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.65), 0 0 1px rgba(0,0,0,0.9); -webkit-font-smoothing: antialiased;`;
8745
+ tx.style.cssText = `white-space: nowrap; line-height: 1.05; font-size: ${fontPx}px; font-weight: 900; ${fontFamilyCss("display")} letter-spacing: 0.2px; text-transform: uppercase; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.65), 0 0 1px rgba(0,0,0,0.9); -webkit-font-smoothing: antialiased;`;
8459
8746
  lab.appendChild(tx);
8460
8747
  wheel.appendChild(lab);
8461
8748
  });
@@ -8508,7 +8795,7 @@ const _AegisInAppManager = class _AegisInAppManager {
8508
8795
  }
8509
8796
  const btn = document.createElement("button");
8510
8797
  btn.textContent = campaign.button_text || "Spin the wheel";
8511
- btn.style.cssText = `padding: 9px 22px; border-radius: 999px; border: none; background: ${text}; color: ${bg}; font-size: 13px; font-weight: 700; letter-spacing: 0.2px; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.20); transition: transform 0.15s, box-shadow 0.15s; font-family: 'Urbanist', system-ui, -apple-system, sans-serif;`;
8798
+ btn.style.cssText = `padding: 9px 22px; border-radius: 999px; border: none; background: ${text}; color: ${bg}; font-size: 13px; font-weight: 700; letter-spacing: 0.2px; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.20); transition: transform 0.15s, box-shadow 0.15s; ${fontFamilyCss("body")}`;
8512
8799
  btn.addEventListener("mouseenter", () => {
8513
8800
  if (btn.disabled) return;
8514
8801
  btn.style.transform = "translateY(-1px)";
@@ -8605,7 +8892,7 @@ const _AegisInAppManager = class _AegisInAppManager {
8605
8892
  eyebrow.style.cssText = "font-size: 13px; font-weight: 700; letter-spacing: 0.3px; opacity: 0.8;";
8606
8893
  const big = document.createElement("div");
8607
8894
  big.textContent = r.label;
8608
- big.style.cssText = `font-size: 24px; font-weight: 900; letter-spacing: -0.02em; font-family: 'Urbanist', system-ui, -apple-system, sans-serif;`;
8895
+ big.style.cssText = `font-size: 24px; font-weight: 900; letter-spacing: -0.02em; ${fontFamilyCss("display")}`;
8609
8896
  ov.appendChild(eyebrow);
8610
8897
  ov.appendChild(big);
8611
8898
  if (r.code) {
@@ -9178,7 +9465,7 @@ const _AegisInAppManager = class _AegisInAppManager {
9178
9465
  eb.style.cssText = "font-size: 12px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; opacity: 0.7;";
9179
9466
  const big = document.createElement("div");
9180
9467
  big.textContent = label;
9181
- big.style.cssText = `font-size: 22px; font-weight: 900; letter-spacing: -0.02em; font-family: 'Urbanist', system-ui, sans-serif;`;
9468
+ big.style.cssText = `font-size: 22px; font-weight: 900; letter-spacing: -0.02em; ${fontFamilyCss("display")}`;
9182
9469
  ov.appendChild(eb);
9183
9470
  ov.appendChild(big);
9184
9471
  if (code) {
@@ -9760,7 +10047,7 @@ const _AegisInAppManager = class _AegisInAppManager {
9760
10047
  iframe.style.cssText = `width: 100%; height: ${height}px; border: none; display: block; background: #fff; transform: translateZ(0); backface-visibility: hidden;`;
9761
10048
  iframe.title = campaign.title || "In-app content";
9762
10049
  const shim = "<script>window.aegis={close:function(){parent.postMessage({__aegis:'close'},'*')},track:function(e,p){parent.postMessage({__aegis:'track',event:e,payload:p},'*')},cta:function(u){parent.postMessage({__aegis:'cta',url:u},'*')},resize:function(h){parent.postMessage({__aegis:'resize',height:h},'*')}};<\/script>";
9763
- iframe.srcdoc = '<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><style>' + brandVars + "html,body{margin:0;padding:0;font-family:system-ui,-apple-system,sans-serif;}</style>" + shim + "</head><body>" + html + "</body></html>";
10050
+ iframe.srcdoc = '<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><style>' + brandVars + "html,body{margin:0;padding:0;font-family:" + BODY_FONT_STACK + ";}</style>" + shim + "</head><body>" + html + "</body></html>";
9764
10051
  const onMsg = (e) => {
9765
10052
  if (e.source !== iframe.contentWindow) return;
9766
10053
  const d = e.data;
@@ -10305,7 +10592,7 @@ const _AegisInAppManager = class _AegisInAppManager {
10305
10592
  };
10306
10593
  const heading = (txt, big = false) => {
10307
10594
  const t = document.createElement("div");
10308
- t.style.cssText = `font-size: ${big ? 19 : 14}px; font-weight: ${big ? 800 : 600}; letter-spacing: -0.01em; line-height: 1.3; margin-bottom: ${big ? 6 : 14}px; font-family: 'Urbanist', system-ui, -apple-system, sans-serif;`;
10595
+ t.style.cssText = `font-size: ${big ? 19 : 14}px; font-weight: ${big ? 800 : 600}; letter-spacing: -0.01em; line-height: 1.3; margin-bottom: ${big ? 6 : 14}px; ${fontFamilyCss("display")}`;
10309
10596
  t.textContent = txt;
10310
10597
  return t;
10311
10598
  };
@@ -10720,7 +11007,7 @@ const _AegisInAppManager = class _AegisInAppManager {
10720
11007
  display: flex;
10721
11008
  align-items: center;
10722
11009
  justify-content: space-between;
10723
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
11010
+ ${fontFamilyCss("body")}
10724
11011
  animation: ${atBottom ? "aegisSlideInFromBottom" : "aegisSlideDown"} 0.3s ease-out;
10725
11012
  `;
10726
11013
  banner.setAttribute("data-banner-position", atBottom ? "bottom" : "top");
@@ -10840,7 +11127,7 @@ const _AegisInAppManager = class _AegisInAppManager {
10840
11127
  overflow: auto;
10841
11128
  box-shadow: 0 16px 48px rgba(0,0,0,0.22);
10842
11129
  animation: aegisScaleIn 0.3s ease-out;
10843
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
11130
+ ${fontFamilyCss("body")}
10844
11131
  `;
10845
11132
  if (videoUrl) {
10846
11133
  const mediaWrap = document.createElement("div");
@@ -11014,7 +11301,7 @@ const _AegisInAppManager = class _AegisInAppManager {
11014
11301
  z-index: 1000001; display: flex; flex-direction: column; align-items: center;
11015
11302
  justify-content: ${isBg ? "flex-end" : "center"}; padding: ${isBg ? "0" : "40px 20px"};
11016
11303
  animation: aegisFadeIn 0.3s ease-out; overflow: hidden;
11017
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
11304
+ ${fontFamilyCss("body")}
11018
11305
  `;
11019
11306
  if (isBg) {
11020
11307
  const media = document.createElement("div");
@@ -11152,7 +11439,7 @@ const _AegisInAppManager = class _AegisInAppManager {
11152
11439
  overflow: auto;
11153
11440
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
11154
11441
  animation: aegisSlideUp 0.3s ease-out;
11155
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
11442
+ ${fontFamilyCss("body")}
11156
11443
  `;
11157
11444
  const grabber = document.createElement("div");
11158
11445
  grabber.style.cssText = `width: 40px; height: 4px; border-radius: 2px; background: ${st.text}33; margin: 10px auto 0;`;
@@ -11297,7 +11584,7 @@ const _AegisInAppManager = class _AegisInAppManager {
11297
11584
  width: 85%;
11298
11585
  box-shadow: 0 16px 48px rgba(0,0,0,0.22);
11299
11586
  animation: aegisScaleIn 0.2s ease-out;
11300
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
11587
+ ${fontFamilyCss("body")}
11301
11588
  overflow: hidden;
11302
11589
  `;
11303
11590
  const content = document.createElement("div");
@@ -11415,7 +11702,7 @@ const _AegisInAppManager = class _AegisInAppManager {
11415
11702
  background: #000; border-radius: 14px; overflow: hidden;
11416
11703
  box-shadow: 0 10px 30px rgba(0,0,0,0.38); z-index: 999999;
11417
11704
  animation: ${slideAnim} 0.3s ease-out; transition: width 0.25s ease, border-radius 0.25s ease;
11418
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
11705
+ ${fontFamilyCss("body")}
11419
11706
  `;
11420
11707
  const mediaWrap = document.createElement("div");
11421
11708
  mediaWrap.style.cssText = "position: relative; width: 100%; background: #000; line-height: 0; aspect-ratio: 16 / 9;";
@@ -11566,7 +11853,7 @@ const _AegisInAppManager = class _AegisInAppManager {
11566
11853
  position: fixed; ${cornerCss} width: ${cornerW}px; max-width: calc(100vw - ${gap * 2}px);
11567
11854
  background: #000; border-radius: 14px; overflow: hidden;
11568
11855
  box-shadow: 0 10px 30px rgba(0,0,0,0.38); z-index: 999999; transition: none;
11569
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
11856
+ ${fontFamilyCss("body")}
11570
11857
  `;
11571
11858
  if (expandBtn) {
11572
11859
  expandBtn.textContent = "⤢";
@@ -11586,7 +11873,7 @@ const _AegisInAppManager = class _AegisInAppManager {
11586
11873
  width: ${theaterW}px; max-width: calc(100vw - ${gap * 2}px);
11587
11874
  background: #000; border-radius: 16px; overflow: hidden;
11588
11875
  box-shadow: 0 24px 60px rgba(0,0,0,0.55); z-index: 999999; transition: none;
11589
- font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
11876
+ ${fontFamilyCss("body")}
11590
11877
  `;
11591
11878
  if (expandBtn) {
11592
11879
  expandBtn.innerHTML = lucideSvg("x", { size: 16 });
@@ -11716,7 +12003,7 @@ const _AegisInAppManager = class _AegisInAppManager {
11716
12003
  tooltip.style.cssText = `
11717
12004
  position: absolute; z-index: 1000001; max-width: 280px; width: max-content;
11718
12005
  background: ${bg}; color: ${textColor}; border-radius: 10px; padding: 14px 16px;
11719
- box-shadow: 0 8px 24px rgba(0,0,0,0.18); font-family: 'Urbanist', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
12006
+ box-shadow: 0 8px 24px rgba(0,0,0,0.18); ${fontFamilyCss("body")}
11720
12007
  animation: aegisScaleIn 0.2s ease-out; pointer-events: auto;
11721
12008
  `;
11722
12009
  const arrow = document.createElement("div");
@@ -12434,6 +12721,23 @@ const _AegisInAppManager = class _AegisInAppManager {
12434
12721
  clearTimeout(this.refreshDebounceTimer);
12435
12722
  this.refreshDebounceTimer = void 0;
12436
12723
  }
12724
+ if (this.slotObserver) {
12725
+ this.slotObserver.disconnect();
12726
+ this.slotObserver = null;
12727
+ }
12728
+ this.slotRenderScheduled = false;
12729
+ this.slotsTornDown = true;
12730
+ this.lifecycleGen += 1;
12731
+ if (this.slotUnfilledSweepTimer) {
12732
+ clearTimeout(this.slotUnfilledSweepTimer);
12733
+ this.slotUnfilledSweepTimer = null;
12734
+ }
12735
+ this.renderedSlots.forEach((slot) => this.clearSlotContent(slot));
12736
+ this.renderedSlots.clear();
12737
+ this.filledSlots = /* @__PURE__ */ new WeakSet();
12738
+ this.slotSignatures = /* @__PURE__ */ new WeakMap();
12739
+ this.slotTimers = /* @__PURE__ */ new WeakMap();
12740
+ this.campaigns = [];
12437
12741
  if (typeof document !== "undefined") {
12438
12742
  document.querySelectorAll(
12439
12743
  ".aegis-in-app-banner, .aegis-in-app-modal-overlay, .aegis-in-app-fullscreen-overlay, .aegis-in-app-half-interstitial-overlay, .aegis-in-app-alert-overlay, .aegis-in-app-pip, .aegis-in-app-nps-overlay, .aegis-in-app-countdown-overlay, .aegis-in-app-rating-overlay, .aegis-in-app-poll-overlay, .aegis-in-app-quiz-overlay, .aegis-in-app-rating-card, .aegis-in-app-nps-card"
@@ -12473,6 +12777,7 @@ _AegisInAppManager.SERVED_DEDUP_PREFIX = "aegis_served_fired:";
12473
12777
  _AegisInAppManager.JOURNEY_ACK_RETRY_MS = 2e3;
12474
12778
  let AegisInAppManager = _AegisInAppManager;
12475
12779
  function renderPreview(config, opts) {
12780
+ applyCampaignFonts([config, ...(opts == null ? void 0 : opts.coGroup) ?? []]);
12476
12781
  document.querySelectorAll(
12477
12782
  '[class^="aegis-in-app-"]'
12478
12783
  ).forEach((el2) => {
@@ -14065,7 +14370,7 @@ class AegisWidgetManager {
14065
14370
  display: flex;
14066
14371
  align-items: center;
14067
14372
  gap: 12px;
14068
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
14373
+ ${fontFamilyCss("body")}
14069
14374
  font-weight: 600;
14070
14375
  font-size: 14px;
14071
14376
  animation: aegisBubbleIn 0.3s ease-out;
@@ -14126,7 +14431,7 @@ class AegisWidgetManager {
14126
14431
  align-items: center;
14127
14432
  gap: 12px;
14128
14433
  max-width: 350px;
14129
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
14434
+ ${fontFamilyCss("body")}
14130
14435
  animation: aegisToastIn 0.3s ease-out;
14131
14436
  `;
14132
14437
  if (icon) {
@@ -14167,7 +14472,7 @@ class AegisWidgetManager {
14167
14472
  z-index: 1000000;
14168
14473
  padding: 32px;
14169
14474
  overflow-y: auto;
14170
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
14475
+ ${fontFamilyCss("body")}
14171
14476
  animation: aegisSlideInRight 0.3s ease-out;
14172
14477
  `;
14173
14478
  const title = document.createElement("h2");
@@ -14298,7 +14603,7 @@ class AegisWidgetManager {
14298
14603
  width: 90%;
14299
14604
  overflow: hidden;
14300
14605
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
14301
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
14606
+ ${fontFamilyCss("body")}
14302
14607
  animation: aegisScaleIn 0.3s ease-out;
14303
14608
  `;
14304
14609
  if (image_url) {
@@ -14542,7 +14847,7 @@ class AegisWidgetManager {
14542
14847
  width: 90%;
14543
14848
  padding: 40px;
14544
14849
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
14545
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
14850
+ ${fontFamilyCss("body")}
14546
14851
  animation: aegisScaleIn 0.3s ease-out;
14547
14852
  position: relative;
14548
14853
  `;
@@ -14668,7 +14973,7 @@ class AegisWidgetManager {
14668
14973
  padding: 40px;
14669
14974
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
14670
14975
  text-align: center;
14671
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
14976
+ ${fontFamilyCss("body")}
14672
14977
  animation: aegisScaleIn 0.3s ease-out;
14673
14978
  position: relative;
14674
14979
  `;
@@ -15077,7 +15382,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
15077
15382
  this.initialized = false;
15078
15383
  this.armedInAppTriggers = /* @__PURE__ */ new Set();
15079
15384
  {
15080
- const v = "1.43.5";
15385
+ const v = "1.44.0";
15081
15386
  try {
15082
15387
  globalThis.__AEGIS_SDK_VERSION__ = v;
15083
15388
  } catch {
@@ -15143,7 +15448,12 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
15143
15448
  // native) registers ONE `onAction` to handle add_to_cart/open_product/…;
15144
15449
  // legacy `aegis:*` DOM events still fire for back-compat.
15145
15450
  onAction: config.onAction,
15146
- productUrl: config.productUrl
15451
+ productUrl: config.productUrl,
15452
+ // Page context known at build time: the FIRST /v1/in-app/active is
15453
+ // already scoped, so no page(surface) refetch (slot plan Phase 1).
15454
+ surface: config.surface,
15455
+ screen: config.screen,
15456
+ locationId: config.locationId
15147
15457
  });
15148
15458
  this.intentRuleEvaluator = new IntentRuleEvaluator();
15149
15459
  if (config.governance) {
@@ -15215,6 +15525,12 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
15215
15525
  /**
15216
15526
  * Boots both managers in parallel. Safe to call multiple times — the
15217
15527
  * second + subsequent calls are no-ops.
15528
+ *
15529
+ * In-app paint never waits on the widget config: `inApp.initialize()` paints
15530
+ * the slots as soon as ITS `/v1/in-app/active` returns; the returned promise
15531
+ * only resolves after both. So a host must not hold page context back until
15532
+ * this resolves — pass `surface` / `screen` in the config (or call `page()`
15533
+ * before `initialize()`) and the first fetch is already scoped.
15218
15534
  */
15219
15535
  async initialize() {
15220
15536
  var _a;