@active-reach/web-sdk 1.44.0 → 1.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Storage, r as redactUrl, l as logger, A as Aegis } from "./analytics-C-Go3Pm5.mjs";
2
- import { B, E, N, R, U, m } from "./analytics-C-Go3Pm5.mjs";
1
+ import { S as Storage, r as redactUrl, l as logger, A as Aegis } from "./analytics-CfEHNTzy.mjs";
2
+ import { B, E, N, R, U, m } from "./analytics-CfEHNTzy.mjs";
3
3
  import { AegisWebPush } from "./push/AegisWebPush.js";
4
4
  function debounce(func, wait) {
5
5
  let timeoutId = null;
@@ -672,6 +672,21 @@ function interpolateTokens(s, ctx) {
672
672
  });
673
673
  }
674
674
  const ASPECT$2 = { "1/1": "1 / 1", "4/3": "4 / 3", "16/9": "16 / 9" };
675
+ const IMAGE_SIZE = {
676
+ "1/1": { width: 300, height: 300 },
677
+ "4/3": { width: 400, height: 300 },
678
+ "16/9": { width: 400, height: 225 }
679
+ };
680
+ function fadeInOnDecode(img) {
681
+ const decode = img.decode;
682
+ if (typeof decode !== "function") return;
683
+ img.style.opacity = "0";
684
+ img.style.transition = "opacity 0.2s ease";
685
+ const show = () => {
686
+ img.style.opacity = "1";
687
+ };
688
+ decode.call(img).then(show, show);
689
+ }
675
690
  const DEFAULT_CARD_TEMPLATE = {
676
691
  id: "clean",
677
692
  frame: { bg: "#ffffff", border: "#f1f1f3", radius: 14 },
@@ -1794,10 +1809,15 @@ function renderCardFromTemplate(card, opts) {
1794
1809
  const safe = sanitizeUrl(card.image_url);
1795
1810
  if (safe) {
1796
1811
  const img = document.createElement("img");
1812
+ const size = IMAGE_SIZE[el2.aspect || "1/1"] || IMAGE_SIZE["1/1"];
1813
+ img.loading = "lazy";
1814
+ img.setAttribute("decoding", "async");
1815
+ img.setAttribute("width", String(size.width));
1816
+ img.setAttribute("height", String(size.height));
1797
1817
  img.src = safe;
1798
1818
  img.alt = "";
1799
- img.loading = "lazy";
1800
1819
  img.style.cssText = "width:100%;height:100%;object-fit:cover;display:block;";
1820
+ fadeInOnDecode(img);
1801
1821
  wrap.appendChild(img);
1802
1822
  }
1803
1823
  }
@@ -4229,6 +4249,13 @@ const ASPECT = { "16:9": "16 / 9", "4:3": "4 / 3", "21:9": "21 / 9" };
4229
4249
  const HERO_DESKTOP_RATIO = "8 / 3";
4230
4250
  const HERO_PHONE_RATIO = "1 / 1";
4231
4251
  const HERO_PHONE_MAX_WIDTH_PX = 767;
4252
+ const HERO_DESKTOP_SIZE = { width: 2400, height: 900 };
4253
+ const HERO_PHONE_SIZE = {
4254
+ "16:9": { width: 1920, height: 1080 },
4255
+ "4:3": { width: 1440, height: 1080 },
4256
+ "21:9": { width: 2520, height: 1080 },
4257
+ square: { width: 1080, height: 1080 }
4258
+ };
4232
4259
  function _injectHeroResponsiveCss() {
4233
4260
  if (typeof document === "undefined") return;
4234
4261
  if (document.getElementById("aegis-hero-style")) return;
@@ -4237,7 +4264,7 @@ function _injectHeroResponsiveCss() {
4237
4264
  style.textContent = `.aegis-hero-root{border-radius:16px;}.aegis-hero-auto{min-height:300px;}@media (max-width:${HERO_PHONE_MAX_WIDTH_PX}px){.aegis-hero-auto.aegis-hero-phone-square{min-height:0;aspect-ratio:${HERO_PHONE_RATIO};}}@media (min-width:${HERO_PHONE_MAX_WIDTH_PX + 1}px){.aegis-hero-root{border-radius:0;min-height:0;max-height:70vh;aspect-ratio:${HERO_DESKTOP_RATIO} !important;}}`;
4238
4265
  document.head.appendChild(style);
4239
4266
  }
4240
- function srcsetUrl(url) {
4267
+ function srcsetUrl$1(url) {
4241
4268
  return url.replace(/\s/g, "%20").replace(/,/g, "%2C");
4242
4269
  }
4243
4270
  function cardHeadline(c) {
@@ -4300,6 +4327,8 @@ function renderHeroInline(ctx, target) {
4300
4327
  track.style.cssText = "display:flex;height:100%;width:100%;transition:transform 0.5s ease;";
4301
4328
  root.appendChild(track);
4302
4329
  const overlayCss = chrome.overlay === "none" ? "" : chrome.overlay === "full-scrim" ? "background:linear-gradient(0deg,rgba(0,0,0,0.55),rgba(0,0,0,0.25));" : "background:linear-gradient(to top right,rgba(0,0,0,0.7),rgba(0,0,0,0.25) 45%,transparent);";
4330
+ const phoneSize = explicitRatio ? HERO_PHONE_SIZE[chrome.aspect_ratio] : hasPhoneImage ? HERO_PHONE_SIZE.square : void 0;
4331
+ const slideImgs = [];
4303
4332
  const justify = chrome.text_position === "center" ? "center" : "flex-end";
4304
4333
  const align = chrome.text_position === "bottom-left" || !chrome.text_position ? "flex-start" : "center";
4305
4334
  cards.forEach((c, i) => {
@@ -4307,7 +4336,7 @@ function renderHeroInline(ctx, target) {
4307
4336
  slide.style.cssText = "position:relative;flex:0 0 100%;width:100%;height:100%;min-height:inherit;background:#f1f5f9;";
4308
4337
  const videoUrl = c.video_url ? sanitizeUrl(c.video_url) ?? "" : "";
4309
4338
  const isVideo = !!videoUrl || c.media_type === "video";
4310
- const mediaUrl = isVideo ? videoUrl || sanitizeUrl(c.media_url ?? "") : sanitizeUrl(c.image_url ?? c.media_url ?? "") ?? (c.image_url_mobile ? sanitizeUrl(c.image_url_mobile) : null);
4339
+ const mediaUrl = isVideo ? videoUrl || sanitizeUrl(c.media_url ?? "") : sanitizeUrl(c.image_url || c.media_url || "") ?? (c.image_url_mobile ? sanitizeUrl(c.image_url_mobile) : null);
4311
4340
  if (mediaUrl) {
4312
4341
  if (isVideo) {
4313
4342
  const v = document.createElement("video");
@@ -4324,13 +4353,26 @@ function renderHeroInline(ctx, target) {
4324
4353
  if (phoneUrl) {
4325
4354
  const source = document.createElement("source");
4326
4355
  source.setAttribute("media", `(max-width:${HERO_PHONE_MAX_WIDTH_PX}px)`);
4327
- source.setAttribute("srcset", srcsetUrl(phoneUrl));
4356
+ source.setAttribute("srcset", srcsetUrl$1(phoneUrl));
4357
+ if (phoneSize) {
4358
+ source.setAttribute("width", String(phoneSize.width));
4359
+ source.setAttribute("height", String(phoneSize.height));
4360
+ }
4328
4361
  picture.appendChild(source);
4329
4362
  }
4330
4363
  const img = document.createElement("img");
4364
+ if (i === 0) {
4365
+ img.setAttribute("fetchpriority", "high");
4366
+ img.setAttribute("loading", "eager");
4367
+ } else {
4368
+ img.setAttribute("loading", "lazy");
4369
+ }
4370
+ img.setAttribute("width", String(HERO_DESKTOP_SIZE.width));
4371
+ img.setAttribute("height", String(HERO_DESKTOP_SIZE.height));
4331
4372
  img.src = mediaUrl;
4332
4373
  img.alt = "";
4333
- img.decoding = "async";
4374
+ img.setAttribute("decoding", "async");
4375
+ slideImgs[i] = img;
4334
4376
  img.style.cssText = "position:absolute;inset:0;width:100%;height:100%;object-fit:cover;object-position:center;display:block;";
4335
4377
  picture.appendChild(img);
4336
4378
  slide.appendChild(picture);
@@ -4378,6 +4420,8 @@ function renderHeroInline(ctx, target) {
4378
4420
  const goto = (idx) => {
4379
4421
  activeIdx = (idx % cards.length + cards.length) % cards.length;
4380
4422
  track.style.transform = `translateX(-${activeIdx * 100}%)`;
4423
+ const next = slideImgs[(activeIdx + 1) % cards.length];
4424
+ if (next && next.getAttribute("loading") === "lazy") next.setAttribute("loading", "eager");
4381
4425
  dotEls.forEach((d, i) => {
4382
4426
  d.style.width = i === activeIdx ? "18px" : "6px";
4383
4427
  d.style.background = i === activeIdx ? accent : "rgba(255,255,255,0.7)";
@@ -4408,7 +4452,7 @@ function renderHeroInline(ctx, target) {
4408
4452
  trackEvent(campaign.id, "impression");
4409
4453
  return true;
4410
4454
  }
4411
- const STYLE_ID = "aegis-chat-styles";
4455
+ const STYLE_ID$1 = "aegis-chat-styles";
4412
4456
  const POLL_INTERVAL_MS = 5e3;
4413
4457
  let currentLauncher = null;
4414
4458
  function getCurrentLauncher() {
@@ -5102,9 +5146,9 @@ class AegisChat {
5102
5146
  if (this.debugMode) console.log("[AegisChat]", ...args);
5103
5147
  }
5104
5148
  injectStyles() {
5105
- if (typeof document === "undefined" || document.getElementById(STYLE_ID)) return;
5149
+ if (typeof document === "undefined" || document.getElementById(STYLE_ID$1)) return;
5106
5150
  const style = document.createElement("style");
5107
- style.id = STYLE_ID;
5151
+ style.id = STYLE_ID$1;
5108
5152
  style.textContent = CHAT_CSS;
5109
5153
  document.head.appendChild(style);
5110
5154
  }
@@ -6585,6 +6629,225 @@ function pageUrlRulesPass(rules, pageUrl) {
6585
6629
  }
6586
6630
  return true;
6587
6631
  }
6632
+ function anchorSelector(c) {
6633
+ var _a, _b;
6634
+ const sel = (_b = (_a = c.interactive_config) == null ? void 0 : _a.anchor) == null ? void 0 : _b.element_selector;
6635
+ return typeof sel === "string" && sel.trim() ? sel : null;
6636
+ }
6637
+ function declaredRotateMs(members) {
6638
+ return members.reduce((m2, c) => {
6639
+ var _a;
6640
+ const v = Number((_a = c.interactive_config) == null ? void 0 : _a.slot_rotate_ms);
6641
+ return Number.isFinite(v) && v > m2 ? v : m2;
6642
+ }, 0);
6643
+ }
6644
+ function pickSlotWinners(campaigns, opts = {}) {
6645
+ const groups = /* @__PURE__ */ new Map();
6646
+ const seen = /* @__PURE__ */ new Set();
6647
+ for (const c of campaigns) {
6648
+ if (opts.isPlaceable && !opts.isPlaceable(c)) continue;
6649
+ const modes = c.delivery_modes;
6650
+ if (!Array.isArray(modes) || !modes.includes("embedded_card")) continue;
6651
+ const slot = c.widget_category;
6652
+ if (!slot) continue;
6653
+ const sel = anchorSelector(c);
6654
+ if (sel !== null && opts.anchorResolves && opts.anchorResolves(sel)) continue;
6655
+ if (seen.has(c.id)) continue;
6656
+ seen.add(c.id);
6657
+ const arr2 = groups.get(slot);
6658
+ if (arr2) arr2.push(c);
6659
+ else groups.set(slot, [c]);
6660
+ }
6661
+ const out = [];
6662
+ groups.forEach((members, slot) => {
6663
+ out.push({ slot, members, declaredRotateMs: declaredRotateMs(members) });
6664
+ });
6665
+ return out;
6666
+ }
6667
+ const STORAGE_PREFIX = "aegis_slot_shapes:v2:";
6668
+ const SHAPE_CACHE_TTL_MS = 6 * 60 * 60 * 1e3;
6669
+ const PHONE_MAX_WIDTH_PX = 767;
6670
+ const STYLE_ID = "aegis-slot-shell-style";
6671
+ const SHELL_SELECTOR = ":scope > [data-aegis-slot-shell]";
6672
+ const LAYOUTS = /* @__PURE__ */ new Set(["hero", "rail", "grid", "bar", "card"]);
6673
+ function storageKey(ctx) {
6674
+ return `${STORAGE_PREFIX}${ctx.propertyId || "-"}:${ctx.surface || "-"}:${ctx.screen || "-"}:${ctx.locationId || "-"}`;
6675
+ }
6676
+ function cssAspect(v) {
6677
+ if (typeof v !== "string") return null;
6678
+ const m2 = v.trim().match(/^(\d+(?:\.\d+)?)\s*[/:]\s*(\d+(?:\.\d+)?)$/);
6679
+ if (!m2 || Number(m2[1]) <= 0 || Number(m2[2]) <= 0) return null;
6680
+ return `${m2[1]} / ${m2[2]}`;
6681
+ }
6682
+ function cssLength(v) {
6683
+ if (typeof v === "number" && Number.isFinite(v) && v > 0) return `${Math.round(v)}px`;
6684
+ if (typeof v !== "string") return null;
6685
+ const s = v.trim();
6686
+ if (/^\d+(\.\d+)?$/.test(s)) return `${s}px`;
6687
+ return /^\d+(\.\d+)?(px|rem|em|vh|svh|dvh|%)$/.test(s) ? s : null;
6688
+ }
6689
+ function isShape(v) {
6690
+ if (!v || typeof v !== "object") return false;
6691
+ const o = v;
6692
+ return typeof o.slot === "string" && !!o.slot && typeof o.layout === "string" && LAYOUTS.has(o.layout);
6693
+ }
6694
+ function toShapeMap(list) {
6695
+ const out = /* @__PURE__ */ new Map();
6696
+ const arr2 = Array.isArray(list) ? list : list && typeof list === "object" && Array.isArray(list.shapes) ? list.shapes : [];
6697
+ for (const s of arr2) if (isShape(s) && !out.has(s.slot)) out.set(s.slot, s);
6698
+ return out;
6699
+ }
6700
+ function readInlineShapes(doc = document) {
6701
+ const out = /* @__PURE__ */ new Map();
6702
+ doc.querySelectorAll("[data-aegis-slot-shapes]").forEach((el2) => {
6703
+ try {
6704
+ toShapeMap(JSON.parse(el2.textContent || "null")).forEach((s, k) => {
6705
+ if (!out.has(k)) out.set(k, s);
6706
+ });
6707
+ } catch {
6708
+ }
6709
+ });
6710
+ return out;
6711
+ }
6712
+ function readCachedShapes(ctx, now = Date.now()) {
6713
+ try {
6714
+ if (typeof localStorage === "undefined") return /* @__PURE__ */ new Map();
6715
+ const raw = localStorage.getItem(storageKey(ctx));
6716
+ if (!raw) return /* @__PURE__ */ new Map();
6717
+ const parsed = JSON.parse(raw);
6718
+ if (typeof (parsed == null ? void 0 : parsed.t) !== "number" || now - parsed.t > SHAPE_CACHE_TTL_MS || parsed.t > now + 6e4) {
6719
+ return /* @__PURE__ */ new Map();
6720
+ }
6721
+ return toShapeMap(parsed.shapes);
6722
+ } catch {
6723
+ return /* @__PURE__ */ new Map();
6724
+ }
6725
+ }
6726
+ function saveShapes(ctx, shapes, now = Date.now()) {
6727
+ try {
6728
+ if (typeof localStorage === "undefined") return;
6729
+ localStorage.setItem(storageKey(ctx), JSON.stringify({ t: now, shapes }));
6730
+ } catch {
6731
+ }
6732
+ }
6733
+ function attributeShape(slot) {
6734
+ const key = slot.getAttribute("data-aegis-slot");
6735
+ if (!key) return null;
6736
+ const aspect = cssAspect(slot.getAttribute("data-aegis-slot-aspect"));
6737
+ const minH = cssLength(slot.getAttribute("data-aegis-slot-min-height"));
6738
+ if (!aspect && !minH) return null;
6739
+ return { slot: key, layout: "card", aspect, min_height: minH };
6740
+ }
6741
+ function injectShellCss(doc) {
6742
+ if (doc.getElementById(STYLE_ID)) return;
6743
+ const style = doc.createElement("style");
6744
+ style.id = STYLE_ID;
6745
+ style.textContent = `[data-aegis-slot-shell]{position:relative;display:block;box-sizing:border-box;width:100%;overflow:hidden;border-radius:12px;background:#f1f5f9;aspect-ratio:var(--aegis-shell-ar,auto);min-height:var(--aegis-shell-min-h,0px);max-height:var(--aegis-shell-max-h,none);}@media (min-width:${PHONE_MAX_WIDTH_PX + 1}px){[data-aegis-slot-shell]{max-height:var(--aegis-shell-max-h-desktop,var(--aegis-shell-max-h,none));}}@media (max-width:${PHONE_MAX_WIDTH_PX}px){[data-aegis-slot-shell]{aspect-ratio:var(--aegis-shell-ar-phone,var(--aegis-shell-ar,auto));min-height:var(--aegis-shell-min-h-phone,var(--aegis-shell-min-h,0px));}}[data-aegis-slot-shell="hero"]{border-radius:16px;}@media (min-width:${PHONE_MAX_WIDTH_PX + 1}px){[data-aegis-slot-shell="hero"]{border-radius:0;}}[data-aegis-slot-shell] img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;object-position:center;display:block;}@keyframes aegis-shell-pulse{0%,100%{opacity:1}50%{opacity:.6}}@media (prefers-reduced-motion:no-preference){[data-aegis-slot-shell]:not([data-aegis-shell-has-image]){animation:aegis-shell-pulse 1.6s ease-in-out infinite;}}`;
6746
+ (doc.head || doc.documentElement).appendChild(style);
6747
+ }
6748
+ function srcsetUrl(url) {
6749
+ return url.replace(/\s/g, "%20").replace(/,/g, "%2C");
6750
+ }
6751
+ function safeHttpUrl(v) {
6752
+ var _a;
6753
+ if (typeof v !== "string" || !v) return null;
6754
+ try {
6755
+ const base = typeof window !== "undefined" && ((_a = window.location) == null ? void 0 : _a.origin) ? window.location.origin : "https://x.invalid";
6756
+ const u = new URL(v, `${base}/`);
6757
+ return u.protocol === "https:" || u.protocol === "http:" ? u.href : null;
6758
+ } catch {
6759
+ return null;
6760
+ }
6761
+ }
6762
+ function buildShell(doc, shape) {
6763
+ const el2 = doc.createElement("div");
6764
+ el2.setAttribute("data-aegis-slot-shell", shape.layout);
6765
+ el2.setAttribute("data-aegis-shell-owner", "sdk");
6766
+ el2.setAttribute("aria-hidden", "true");
6767
+ const ar = cssAspect(shape.aspect ?? null);
6768
+ if (ar) el2.style.setProperty("--aegis-shell-ar", ar);
6769
+ if (shape.layout === "hero") {
6770
+ const phone = cssAspect(shape.aspect_phone ?? null);
6771
+ el2.style.setProperty("--aegis-shell-ar-phone", phone ?? "auto");
6772
+ const phoneMin = phone ? null : cssLength(shape.min_height ?? null);
6773
+ if (phoneMin) el2.style.setProperty("--aegis-shell-min-h-phone", phoneMin);
6774
+ } else {
6775
+ const minH = cssLength(shape.min_height ?? null);
6776
+ if (minH) el2.style.setProperty("--aegis-shell-min-h", minH);
6777
+ }
6778
+ const maxH = cssLength(shape.max_height ?? null);
6779
+ if (maxH) {
6780
+ el2.style.setProperty(shape.layout === "hero" ? "--aegis-shell-max-h-desktop" : "--aegis-shell-max-h", maxH);
6781
+ }
6782
+ const img = shape.layout === "hero" ? shape.image : null;
6783
+ const src = img ? safeHttpUrl(img.src) : null;
6784
+ if (img && src) {
6785
+ const picture = doc.createElement("picture");
6786
+ const phoneSrc = safeHttpUrl(img.src_phone ?? null);
6787
+ if (phoneSrc) {
6788
+ const source = doc.createElement("source");
6789
+ source.setAttribute("media", `(max-width:${PHONE_MAX_WIDTH_PX}px)`);
6790
+ source.setAttribute("srcset", srcsetUrl(phoneSrc));
6791
+ picture.appendChild(source);
6792
+ }
6793
+ const im = doc.createElement("img");
6794
+ im.setAttribute("fetchpriority", "high");
6795
+ im.setAttribute("decoding", "async");
6796
+ im.alt = img.alt || "";
6797
+ if (img.width && img.height) {
6798
+ im.setAttribute("width", String(img.width));
6799
+ im.setAttribute("height", String(img.height));
6800
+ }
6801
+ im.src = src;
6802
+ picture.appendChild(im);
6803
+ el2.appendChild(picture);
6804
+ el2.setAttribute("data-aegis-shell-has-image", "");
6805
+ }
6806
+ return el2;
6807
+ }
6808
+ function removeSlotShell(slot) {
6809
+ slot.querySelectorAll(SHELL_SELECTOR).forEach((n) => n.remove());
6810
+ }
6811
+ function collapseUnfilledShells(slots, winners) {
6812
+ Array.prototype.forEach.call(slots, (slot) => {
6813
+ const key = slot.getAttribute("data-aegis-slot");
6814
+ const list = key ? winners.get(key) : void 0;
6815
+ if (!list || list.length === 0) removeSlotShell(slot);
6816
+ });
6817
+ }
6818
+ function removeAllShells(doc = document, opts = {}) {
6819
+ doc.querySelectorAll("[data-aegis-slot]").forEach((slot) => {
6820
+ slot.querySelectorAll(SHELL_SELECTOR).forEach((n) => {
6821
+ if (!opts.sdkOnly || n.getAttribute("data-aegis-shell-owner") === "sdk") n.remove();
6822
+ });
6823
+ });
6824
+ }
6825
+ function drawSlotShells(ctx, doc = document) {
6826
+ const slots = doc.querySelectorAll("[data-aegis-slot]");
6827
+ if (slots.length === 0) return 0;
6828
+ const inline = readInlineShapes(doc);
6829
+ const inlinePrinted = doc.querySelectorAll("[data-aegis-slot-shapes]").length > 0;
6830
+ let cached = null;
6831
+ let drawn = 0;
6832
+ slots.forEach((slot) => {
6833
+ if (slot.childElementCount > 0) return;
6834
+ const key = slot.getAttribute("data-aegis-slot");
6835
+ if (!key) return;
6836
+ let shape = inline.get(key) ?? null;
6837
+ if (shape && shape.may_be_empty) shape = null;
6838
+ if (!shape) shape = attributeShape(slot);
6839
+ if (!shape && !inlinePrinted) {
6840
+ if (cached === null) cached = readCachedShapes(ctx);
6841
+ const c = cached.get(key) ?? null;
6842
+ shape = c && !c.may_be_empty ? c : null;
6843
+ }
6844
+ if (!shape) return;
6845
+ injectShellCss(doc);
6846
+ slot.appendChild(buildShell(doc, shape));
6847
+ drawn += 1;
6848
+ });
6849
+ return drawn;
6850
+ }
6588
6851
  const RETURNING_MARKER_KEY = "aegis_returning_user";
6589
6852
  const SESSION_VERDICT_KEY = "aegis_new_visitor_session";
6590
6853
  let cachedVerdict = null;
@@ -6780,6 +7043,8 @@ const _AegisInAppManager = class _AegisInAppManager {
6780
7043
  this.slotObserver = null;
6781
7044
  this.slotRenderScheduled = false;
6782
7045
  this.slotsTornDown = false;
7046
+ this.campaignsLoaded = false;
7047
+ this.shellTimeout = null;
6783
7048
  this.lifecycleGen = 0;
6784
7049
  this.slotUnfilledBeaconed = /* @__PURE__ */ new Set();
6785
7050
  this.slotUnfilledSweepTimer = null;
@@ -6907,6 +7172,7 @@ const _AegisInAppManager = class _AegisInAppManager {
6907
7172
  } catch {
6908
7173
  }
6909
7174
  applyRootFonts(null);
7175
+ this.drawShells();
6910
7176
  await this.refreshCampaigns();
6911
7177
  if (this.enableSSE && this.organizationId) {
6912
7178
  this.connectSSE();
@@ -7343,6 +7609,7 @@ const _AegisInAppManager = class _AegisInAppManager {
7343
7609
  const url = `${this.apiHost}/v1/in-app/active?${context.toString()}`;
7344
7610
  requestKey = this.activeRequestKey();
7345
7611
  this.lastActiveRequestKey = requestKey;
7612
+ const shellCtx = this.shellContext();
7346
7613
  const headers = {
7347
7614
  "X-Aegis-Write-Key": this.writeKey,
7348
7615
  "Content-Type": "application/json"
@@ -7378,6 +7645,9 @@ const _AegisInAppManager = class _AegisInAppManager {
7378
7645
  const payload = await response.json();
7379
7646
  if (gen !== this.lifecycleGen) return;
7380
7647
  this.campaigns = Array.isArray(payload) ? payload : [];
7648
+ this.campaignsLoaded = true;
7649
+ this.campaignsRequestKey = requestKey;
7650
+ this.clearShellTimeout();
7381
7651
  applyCampaignFonts(this.campaigns);
7382
7652
  this.processABAssignments(this.campaigns);
7383
7653
  this.rehydrateSuppressionFromStorage();
@@ -7388,6 +7658,7 @@ const _AegisInAppManager = class _AegisInAppManager {
7388
7658
  this.mountPersistentLaunchers();
7389
7659
  this.tryDisplayNextCampaign();
7390
7660
  this.renderIntoSlots();
7661
+ this.saveSlotShapes(shellCtx);
7391
7662
  this.renderIntoAnchors();
7392
7663
  this.renderTokenAnchors();
7393
7664
  } catch (error) {
@@ -7395,6 +7666,7 @@ const _AegisInAppManager = class _AegisInAppManager {
7395
7666
  this.lastActiveRequestKey = void 0;
7396
7667
  }
7397
7668
  if (gen !== this.lifecycleGen) return;
7669
+ if (!this.campaignsLoaded) this.removeShells();
7398
7670
  this.emitError(error, { stage: "refresh-campaigns" });
7399
7671
  this.log(`Error refreshing campaigns: ${error}`, "error");
7400
7672
  }
@@ -7545,6 +7817,70 @@ const _AegisInAppManager = class _AegisInAppManager {
7545
7817
  isPlaceableHere(c) {
7546
7818
  return this.matchesCurrentScreenOrSurface(c) && pageUrlRulesPass(c, this.currentPageUrl());
7547
7819
  }
7820
+ /** Does an operator element anchor resolve on this page? (An invalid
7821
+ * selector does not.) */
7822
+ anchorResolvesHere(sel) {
7823
+ if (typeof document === "undefined") return false;
7824
+ try {
7825
+ return !!document.querySelector(sel);
7826
+ } catch {
7827
+ return false;
7828
+ }
7829
+ }
7830
+ /** Shell storage key parts: this property + the declared surface/screen. */
7831
+ shellContext() {
7832
+ return {
7833
+ propertyId: this.propertyId ?? null,
7834
+ surface: this.currentSurface,
7835
+ screen: this.currentScreen,
7836
+ locationId: this.currentLocationId ?? null
7837
+ };
7838
+ }
7839
+ drawShells() {
7840
+ if (typeof document === "undefined" || this.slotsTornDown || this.campaignsLoaded) return;
7841
+ try {
7842
+ if (drawSlotShells(this.shellContext()) > 0 && !this.shellTimeout) {
7843
+ this.shellTimeout = setTimeout(() => {
7844
+ this.shellTimeout = null;
7845
+ if (!this.campaignsLoaded) this.removeShells();
7846
+ }, _AegisInAppManager.SHELL_TIMEOUT_MS);
7847
+ }
7848
+ } catch (err) {
7849
+ this.log(`slot shells skipped: ${err}`, "warn");
7850
+ }
7851
+ }
7852
+ clearShellTimeout() {
7853
+ if (this.shellTimeout) {
7854
+ clearTimeout(this.shellTimeout);
7855
+ this.shellTimeout = null;
7856
+ }
7857
+ }
7858
+ removeShells(opts = {}) {
7859
+ this.clearShellTimeout();
7860
+ if (typeof document === "undefined") return;
7861
+ try {
7862
+ removeAllShells(document, opts);
7863
+ } catch (err) {
7864
+ this.log(`slot shell cleanup skipped: ${err}`, "warn");
7865
+ }
7866
+ }
7867
+ /** Save the winners' shapes for the next visit to this page context. Every
7868
+ * winner of the response counts, on this page or not; a slot absent from
7869
+ * the save will not fill (no shell next time). */
7870
+ saveSlotShapes(ctx) {
7871
+ const shapes = [];
7872
+ const winners = pickSlotWinners(this.campaigns, {
7873
+ isPlaceable: (c) => this.isPlaceableHere(c),
7874
+ anchorResolves: (sel) => this.anchorResolvesHere(sel)
7875
+ });
7876
+ for (const g of winners) {
7877
+ const shape = g.members[0].slot_shape;
7878
+ if (!shape || typeof shape !== "object") continue;
7879
+ const rotating = g.declaredRotateMs > 0 && g.members.length > 1;
7880
+ shapes.push(rotating ? { ...shape, rotate_count: g.members.length } : shape);
7881
+ }
7882
+ saveShapes(ctx, shapes);
7883
+ }
7548
7884
  /** Remove everything this manager injected into `slot` and stop its rotation. */
7549
7885
  clearSlotContent(slot) {
7550
7886
  const timer = this.slotTimers.get(slot);
@@ -7591,7 +7927,6 @@ const _AegisInAppManager = class _AegisInAppManager {
7591
7927
  this.slotObserver.observe(document.body, { childList: true, subtree: true });
7592
7928
  }
7593
7929
  renderIntoSlots() {
7594
- var _a, _b;
7595
7930
  if (typeof document === "undefined" || this.slotsTornDown) return;
7596
7931
  this.ensureSlotObserver();
7597
7932
  this.scheduleSlotUnfilledSweep();
@@ -7606,28 +7941,16 @@ const _AegisInAppManager = class _AegisInAppManager {
7606
7941
  const slots = document.querySelectorAll("[data-aegis-slot]");
7607
7942
  if (slots.length === 0) return;
7608
7943
  const eligibleByCategory = /* @__PURE__ */ new Map();
7609
- const seenIds = /* @__PURE__ */ new Set();
7610
- for (const c of this.campaigns) {
7611
- if (!this.isPlaceableHere(c)) continue;
7612
- const modes = c.delivery_modes;
7613
- const category = c.widget_category;
7614
- if (!modes || !modes.includes("embedded_card")) continue;
7615
- if (!category) continue;
7616
- const anchorSel = (_b = (_a = c.interactive_config) == null ? void 0 : _a.anchor) == null ? void 0 : _b.element_selector;
7617
- if (typeof anchorSel === "string" && anchorSel.trim()) {
7618
- let anchorResolves = false;
7619
- try {
7620
- anchorResolves = !!document.querySelector(anchorSel);
7621
- } catch {
7622
- anchorResolves = false;
7623
- }
7624
- if (anchorResolves) continue;
7625
- }
7626
- if (seenIds.has(c.id)) continue;
7627
- seenIds.add(c.id);
7628
- const arr2 = eligibleByCategory.get(category);
7629
- if (arr2) arr2.push(c);
7630
- else eligibleByCategory.set(category, [c]);
7944
+ const declaredRotate = /* @__PURE__ */ new Map();
7945
+ for (const g of pickSlotWinners(this.campaigns, {
7946
+ isPlaceable: (c) => this.isPlaceableHere(c),
7947
+ anchorResolves: (sel) => this.anchorResolvesHere(sel)
7948
+ })) {
7949
+ eligibleByCategory.set(g.slot, g.members);
7950
+ declaredRotate.set(g.slot, g.declaredRotateMs);
7951
+ }
7952
+ if (this.campaignsLoaded && this.campaignsRequestKey === this.activeRequestKey()) {
7953
+ collapseUnfilledShells(slots, eligibleByCategory);
7631
7954
  }
7632
7955
  if (eligibleByCategory.size === 0) return;
7633
7956
  slots.forEach((slot) => {
@@ -7636,11 +7959,7 @@ const _AegisInAppManager = class _AegisInAppManager {
7636
7959
  const list = eligibleByCategory.get(key);
7637
7960
  if (!list || list.length === 0) return;
7638
7961
  const attrMs = parseInt(slot.getAttribute("data-aegis-slot-rotate") || "0", 10);
7639
- const declaredMs = list.reduce((m2, c) => {
7640
- var _a2;
7641
- const v = Number((_a2 = c.interactive_config) == null ? void 0 : _a2.slot_rotate_ms);
7642
- return Number.isFinite(v) && v > m2 ? v : m2;
7643
- }, 0);
7962
+ const declaredMs = declaredRotate.get(key) ?? 0;
7644
7963
  const rotateMs = attrMs > 0 ? attrMs : declaredMs;
7645
7964
  const rotating = rotateMs > 0 && list.length > 1;
7646
7965
  const shown = rotating ? list : list.slice(0, 1);
@@ -7650,6 +7969,7 @@ const _AegisInAppManager = class _AegisInAppManager {
7650
7969
  this.slotSignatures.set(slot, sig);
7651
7970
  this.renderedSlots.add(slot);
7652
7971
  slot.querySelectorAll(":scope > [data-aegis-slot-default]").forEach((d) => d.remove());
7972
+ removeSlotShell(slot);
7653
7973
  const flush = slot.hasAttribute("data-aegis-slot-flush");
7654
7974
  if (rotating) {
7655
7975
  this.renderRotatingSlot(slot, list, rotateMs, flush);
@@ -11982,16 +12302,16 @@ const _AegisInAppManager = class _AegisInAppManager {
11982
12302
  }
11983
12303
  renderTooltip(campaign) {
11984
12304
  const ic = campaign.interactive_config || {};
11985
- const anchorSelector = ic.tooltip_anchor_selector || "[data-aegis-tooltip]";
12305
+ const anchorSelector2 = ic.tooltip_anchor_selector || "[data-aegis-tooltip]";
11986
12306
  const preferredPosition = ic.tooltip_position || "auto";
11987
12307
  const highlightOn = ic.tooltip_highlight !== false;
11988
- let anchor = document.querySelector(anchorSelector);
12308
+ let anchor = document.querySelector(anchorSelector2);
11989
12309
  if (!anchor) {
11990
12310
  console.warn(
11991
- `[AegisInApp] Tooltip anchor "${anchorSelector}" not found on this surface — tooltip not shown. On native apps this must be a key registered via registerInAppAnchor(); adding a new anchor needs an app release.`
12311
+ `[AegisInApp] Tooltip anchor "${anchorSelector2}" not found on this surface — tooltip not shown. On native apps this must be a key registered via registerInAppAnchor(); adding a new anchor needs an app release.`
11992
12312
  );
11993
12313
  void this.trackEvent(campaign.id, "anchor_unresolved", {
11994
- meta: { anchor_resolved: false, anchor_selector: anchorSelector, widget_type: "tooltip" }
12314
+ meta: { anchor_resolved: false, anchor_selector: anchorSelector2, widget_type: "tooltip" }
11995
12315
  });
11996
12316
  return;
11997
12317
  }
@@ -12150,13 +12470,13 @@ const _AegisInAppManager = class _AegisInAppManager {
12150
12470
  };
12151
12471
  const ensureAnchor = () => {
12152
12472
  if (anchor && anchor.isConnected) return true;
12153
- const next = document.querySelector(anchorSelector);
12473
+ const next = document.querySelector(anchorSelector2);
12154
12474
  if (next) {
12155
12475
  anchor = next;
12156
12476
  return true;
12157
12477
  }
12158
12478
  void this.trackEvent(campaign.id, "anchor_unresolved", {
12159
- meta: { anchor_resolved: false, anchor_selector: anchorSelector, widget_type: "tooltip", phase: "runtime" }
12479
+ meta: { anchor_resolved: false, anchor_selector: anchorSelector2, widget_type: "tooltip", phase: "runtime" }
12160
12480
  });
12161
12481
  dismiss();
12162
12482
  return false;
@@ -12738,6 +13058,9 @@ const _AegisInAppManager = class _AegisInAppManager {
12738
13058
  this.slotSignatures = /* @__PURE__ */ new WeakMap();
12739
13059
  this.slotTimers = /* @__PURE__ */ new WeakMap();
12740
13060
  this.campaigns = [];
13061
+ this.removeShells({ sdkOnly: true });
13062
+ this.campaignsLoaded = false;
13063
+ this.campaignsRequestKey = void 0;
12741
13064
  if (typeof document !== "undefined") {
12742
13065
  document.querySelectorAll(
12743
13066
  ".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"
@@ -12774,6 +13097,7 @@ _AegisInAppManager.KNOWN_SURFACES = /* @__PURE__ */ new Set([
12774
13097
  "external_mobile_screen"
12775
13098
  ]);
12776
13099
  _AegisInAppManager.SERVED_DEDUP_PREFIX = "aegis_served_fired:";
13100
+ _AegisInAppManager.SHELL_TIMEOUT_MS = 1e4;
12777
13101
  _AegisInAppManager.JOURNEY_ACK_RETRY_MS = 2e3;
12778
13102
  let AegisInAppManager = _AegisInAppManager;
12779
13103
  function renderPreview(config, opts) {
@@ -15382,7 +15706,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
15382
15706
  this.initialized = false;
15383
15707
  this.armedInAppTriggers = /* @__PURE__ */ new Set();
15384
15708
  {
15385
- const v = "1.44.0";
15709
+ const v = "1.45.0";
15386
15710
  try {
15387
15711
  globalThis.__AEGIS_SDK_VERSION__ = v;
15388
15712
  } catch {