@active-reach/web-sdk 1.46.2 → 1.47.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/{AegisWebPush-B7eajKzP.mjs → AegisWebPush-BE9wJcx0.mjs} +1 -1
- package/dist/{AegisWebPush-B7eajKzP.mjs.map → AegisWebPush-BE9wJcx0.mjs.map} +1 -1
- package/dist/aegis.min.js +1 -1
- package/dist/aegis.min.js.map +1 -1
- package/dist/{analytics-CfEHNTzy.mjs → analytics-C-Go3Pm5.mjs} +1 -1
- package/dist/{analytics-CfEHNTzy.mjs.map → analytics-C-Go3Pm5.mjs.map} +1 -1
- package/dist/cdn.d.ts.map +1 -1
- package/dist/chat/AegisChat.d.ts +25 -0
- package/dist/chat/AegisChat.d.ts.map +1 -1
- package/dist/chat/index.d.ts +2 -0
- package/dist/chat/index.d.ts.map +1 -1
- package/dist/chat/launcher-spec.d.ts +46 -0
- package/dist/chat/launcher-spec.d.ts.map +1 -0
- package/dist/chat/qr.d.ts +19 -0
- package/dist/chat/qr.d.ts.map +1 -0
- package/dist/chat/whatsapp-launcher.d.ts +45 -0
- package/dist/chat/whatsapp-launcher.d.ts.map +1 -0
- package/dist/inapp/AegisInAppManager.d.ts.map +1 -1
- package/dist/inapp/index.d.ts +2 -0
- package/dist/inapp/index.d.ts.map +1 -1
- package/dist/inapp/rail-heading.d.ts +90 -0
- package/dist/inapp/rail-heading.d.ts.map +1 -0
- package/dist/inapp/renderers/active-web-chat.d.ts.map +1 -1
- package/dist/inapp/renderers/product-recommendation.d.ts +2 -1
- package/dist/inapp/renderers/product-recommendation.d.ts.map +1 -1
- package/dist/inapp/renderers/types.d.ts +9 -0
- package/dist/inapp/renderers/types.d.ts.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +623 -26
- package/dist/index.js.map +1 -1
- package/dist/push/AegisWebPush.js +1 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { S as Storage, r as redactUrl, l as logger, A as Aegis } from "./analytics-
|
|
2
|
-
import { B, E, N, R, U, m } from "./analytics-
|
|
3
|
-
import { a as assetIdOf } from "./AegisWebPush-
|
|
4
|
-
import { A } from "./AegisWebPush-
|
|
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";
|
|
3
|
+
import { a as assetIdOf } from "./AegisWebPush-BE9wJcx0.mjs";
|
|
4
|
+
import { A } from "./AegisWebPush-BE9wJcx0.mjs";
|
|
5
5
|
function debounce(func, wait) {
|
|
6
6
|
let timeoutId = null;
|
|
7
7
|
return function debounced(...args) {
|
|
@@ -2852,6 +2852,91 @@ function renderCoachmarkTour(ctx) {
|
|
|
2852
2852
|
showStep(current);
|
|
2853
2853
|
window.aegisResetTour = (key) => clearResume(key);
|
|
2854
2854
|
}
|
|
2855
|
+
const RAIL_REASONS_WEAKEST_FIRST = [
|
|
2856
|
+
"popular_here",
|
|
2857
|
+
"same_category",
|
|
2858
|
+
"similar"
|
|
2859
|
+
];
|
|
2860
|
+
const RESERVED_BOUGHT_TOGETHER_HEADINGS = {
|
|
2861
|
+
item: "Often bought together",
|
|
2862
|
+
cart: "Complete your order"
|
|
2863
|
+
};
|
|
2864
|
+
const DEFAULT_RAIL_TITLES = [
|
|
2865
|
+
"You might also like",
|
|
2866
|
+
"View Similar items",
|
|
2867
|
+
"Recommended for you",
|
|
2868
|
+
"Bestsellers",
|
|
2869
|
+
"Buy again",
|
|
2870
|
+
"Buy it again",
|
|
2871
|
+
"Picked for you",
|
|
2872
|
+
"Frequently bought together",
|
|
2873
|
+
"Loved by reviewers",
|
|
2874
|
+
"While you wait"
|
|
2875
|
+
];
|
|
2876
|
+
const DEFAULT_KEYS = new Set(DEFAULT_RAIL_TITLES.map((t) => t.toLowerCase()));
|
|
2877
|
+
function isReplaceableRailTitle(title) {
|
|
2878
|
+
const t = (title ?? "").trim();
|
|
2879
|
+
return t === "" || DEFAULT_KEYS.has(t.toLowerCase());
|
|
2880
|
+
}
|
|
2881
|
+
const KNOWN = /* @__PURE__ */ new Set([
|
|
2882
|
+
"similar",
|
|
2883
|
+
"same_category",
|
|
2884
|
+
"popular_here",
|
|
2885
|
+
"top_rated"
|
|
2886
|
+
]);
|
|
2887
|
+
function baseReason(raw) {
|
|
2888
|
+
if (typeof raw !== "string") return null;
|
|
2889
|
+
const base = raw.split("+")[0].trim();
|
|
2890
|
+
return KNOWN.has(base) ? base : null;
|
|
2891
|
+
}
|
|
2892
|
+
function railCategory(cards, only) {
|
|
2893
|
+
var _a, _b;
|
|
2894
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2895
|
+
for (const c of cards) {
|
|
2896
|
+
if (only && baseReason((_a = c.metadata) == null ? void 0 : _a.reason) !== only) continue;
|
|
2897
|
+
const cat = (_b = c.metadata) == null ? void 0 : _b.category;
|
|
2898
|
+
if (typeof cat !== "string" || !cat.trim()) continue;
|
|
2899
|
+
const key = cat.trim();
|
|
2900
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
2901
|
+
}
|
|
2902
|
+
let best = null;
|
|
2903
|
+
let bestN = 0;
|
|
2904
|
+
for (const [cat, n] of counts) {
|
|
2905
|
+
if (n > bestN) {
|
|
2906
|
+
best = cat;
|
|
2907
|
+
bestN = n;
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
return best;
|
|
2911
|
+
}
|
|
2912
|
+
function resolveRailHeading(cards, fallback) {
|
|
2913
|
+
var _a;
|
|
2914
|
+
const keep = { show: cards.length > 0, heading: fallback ?? "", reason: null };
|
|
2915
|
+
if (cards.length === 0) return keep;
|
|
2916
|
+
if (!isReplaceableRailTitle(fallback)) return keep;
|
|
2917
|
+
const reasons = /* @__PURE__ */ new Set();
|
|
2918
|
+
for (const c of cards) {
|
|
2919
|
+
const r = baseReason((_a = c.metadata) == null ? void 0 : _a.reason);
|
|
2920
|
+
if (r === null) return keep;
|
|
2921
|
+
reasons.add(r);
|
|
2922
|
+
}
|
|
2923
|
+
if (reasons.has("top_rated")) {
|
|
2924
|
+
return reasons.size === 1 ? { show: true, heading: "Loved by reviewers", reason: "top_rated" } : keep;
|
|
2925
|
+
}
|
|
2926
|
+
const weakest = RAIL_REASONS_WEAKEST_FIRST.find((r) => reasons.has(r));
|
|
2927
|
+
switch (weakest) {
|
|
2928
|
+
case "popular_here":
|
|
2929
|
+
return { show: true, heading: "Popular here", reason: "popular_here" };
|
|
2930
|
+
case "same_category": {
|
|
2931
|
+
const category = railCategory(cards, "same_category") ?? railCategory(cards);
|
|
2932
|
+
return category ? { show: true, heading: `More ${category}`, reason: "same_category" } : keep;
|
|
2933
|
+
}
|
|
2934
|
+
case "similar":
|
|
2935
|
+
return { show: true, heading: "Similar items", reason: "similar" };
|
|
2936
|
+
default:
|
|
2937
|
+
return keep;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2855
2940
|
const MAX_PRODUCTS = 24;
|
|
2856
2941
|
function renderProductRecommendation(ctx) {
|
|
2857
2942
|
const { campaign, trackEvent, sanitizeColor, log, addAnimationStyles } = ctx;
|
|
@@ -2862,6 +2947,7 @@ function renderProductRecommendation(ctx) {
|
|
|
2862
2947
|
log("product_recommendation rendered with zero products — skipping", "warn");
|
|
2863
2948
|
return;
|
|
2864
2949
|
}
|
|
2950
|
+
const rail = resolveRailHeading(cards, campaign.title);
|
|
2865
2951
|
const layout = ic.rec_layout || "grid";
|
|
2866
2952
|
const template = resolveGlobalTemplate(ic);
|
|
2867
2953
|
addAnimationStyles();
|
|
@@ -2897,7 +2983,7 @@ function renderProductRecommendation(ctx) {
|
|
|
2897
2983
|
header.style.cssText = "display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;";
|
|
2898
2984
|
const headerText = document.createElement("div");
|
|
2899
2985
|
const title = document.createElement("div");
|
|
2900
|
-
title.textContent =
|
|
2986
|
+
title.textContent = rail.heading;
|
|
2901
2987
|
title.style.cssText = "font-weight: 700; font-size: 16px; margin-bottom: 2px;";
|
|
2902
2988
|
const body = document.createElement("div");
|
|
2903
2989
|
body.textContent = campaign.body;
|
|
@@ -2958,6 +3044,7 @@ function renderProductRecommendationInline(ctx, target) {
|
|
|
2958
3044
|
log("product_recommendation (inline) rendered with zero products — skipping", "warn");
|
|
2959
3045
|
return false;
|
|
2960
3046
|
}
|
|
3047
|
+
const rail = resolveRailHeading(cards, campaign.title);
|
|
2961
3048
|
const layout = ic.rec_layout || "row";
|
|
2962
3049
|
const template = resolveGlobalTemplate(ic);
|
|
2963
3050
|
const fg = "#0f172a";
|
|
@@ -2970,9 +3057,9 @@ function renderProductRecommendationInline(ctx, target) {
|
|
|
2970
3057
|
${fontFamilyCss("body")}
|
|
2971
3058
|
color: ${fg};
|
|
2972
3059
|
`;
|
|
2973
|
-
if (
|
|
3060
|
+
if (rail.heading) {
|
|
2974
3061
|
const title = document.createElement("h2");
|
|
2975
|
-
title.textContent =
|
|
3062
|
+
title.textContent = rail.heading;
|
|
2976
3063
|
title.style.cssText = "font-weight: 700; font-size: 16px; margin: 0 0 2px;";
|
|
2977
3064
|
section.appendChild(title);
|
|
2978
3065
|
}
|
|
@@ -4726,6 +4813,380 @@ function appendNodes(parent, nodes) {
|
|
|
4726
4813
|
function appendWaMarkup(parent, text) {
|
|
4727
4814
|
appendNodes(parent, parseWaMarkup(text));
|
|
4728
4815
|
}
|
|
4816
|
+
const LAUNCHER_SIZE_PX = 56;
|
|
4817
|
+
const LAUNCHER_OFFSET_DESKTOP_PX = 20;
|
|
4818
|
+
const LAUNCHER_OFFSET_MOBILE_PX = 16;
|
|
4819
|
+
const LAUNCHER_BOTTOM_MOBILE_PX = 84;
|
|
4820
|
+
const LAUNCHER_MOBILE_MAX_PX = 767;
|
|
4821
|
+
const LAUNCHER_Z_INDEX = 2147483e3;
|
|
4822
|
+
const LAUNCHER_Z_INDEX_BEHIND = 900;
|
|
4823
|
+
const LAUNCHER_BOTTOM_VAR = "--aegis-launcher-bottom";
|
|
4824
|
+
const LAUNCHER_ATTR = "data-aegis-launcher";
|
|
4825
|
+
function launcherHostMode() {
|
|
4826
|
+
if (typeof document === "undefined") return "on";
|
|
4827
|
+
const v = document.documentElement.getAttribute(LAUNCHER_ATTR);
|
|
4828
|
+
return v === "off" || v === "behind" ? v : "on";
|
|
4829
|
+
}
|
|
4830
|
+
function isLauncherOff() {
|
|
4831
|
+
return launcherHostMode() === "off";
|
|
4832
|
+
}
|
|
4833
|
+
function launcherRootCss(rootClass) {
|
|
4834
|
+
const d = LAUNCHER_OFFSET_DESKTOP_PX;
|
|
4835
|
+
const m2 = LAUNCHER_OFFSET_MOBILE_PX;
|
|
4836
|
+
return `.${rootClass}{position:fixed;bottom:var(${LAUNCHER_BOTTOM_VAR},${d}px);right:${d}px;z-index:${LAUNCHER_Z_INDEX}}.${rootClass}--bottom-left{left:${d}px;right:auto}html[${LAUNCHER_ATTR}="behind"] .${rootClass}{z-index:${LAUNCHER_Z_INDEX_BEHIND}}html[${LAUNCHER_ATTR}="off"] .${rootClass}{display:none!important}@media (max-width:${LAUNCHER_MOBILE_MAX_PX}px){.${rootClass}{bottom:var(${LAUNCHER_BOTTOM_VAR},${LAUNCHER_BOTTOM_MOBILE_PX}px);right:${m2}px}.${rootClass}--bottom-left{left:${m2}px;right:auto}}`;
|
|
4837
|
+
}
|
|
4838
|
+
const ECC_PER_BLOCK_L = [0, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28];
|
|
4839
|
+
const BLOCKS_L = [0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8];
|
|
4840
|
+
const MAX_VERSION = 20;
|
|
4841
|
+
function rawDataModules(ver) {
|
|
4842
|
+
let r = (16 * ver + 128) * ver + 64;
|
|
4843
|
+
if (ver >= 2) {
|
|
4844
|
+
const n = Math.floor(ver / 7) + 2;
|
|
4845
|
+
r -= (25 * n - 10) * n - 55;
|
|
4846
|
+
if (ver >= 7) r -= 36;
|
|
4847
|
+
}
|
|
4848
|
+
return r;
|
|
4849
|
+
}
|
|
4850
|
+
function dataCodewords(ver) {
|
|
4851
|
+
return Math.floor(rawDataModules(ver) / 8) - ECC_PER_BLOCK_L[ver] * BLOCKS_L[ver];
|
|
4852
|
+
}
|
|
4853
|
+
function utf8(text) {
|
|
4854
|
+
return Array.from(new TextEncoder().encode(text));
|
|
4855
|
+
}
|
|
4856
|
+
function gfMul(x, y) {
|
|
4857
|
+
let z = 0;
|
|
4858
|
+
for (let i = 7; i >= 0; i--) {
|
|
4859
|
+
z = z << 1 ^ (z >>> 7) * 285;
|
|
4860
|
+
z ^= (y >>> i & 1) * x;
|
|
4861
|
+
}
|
|
4862
|
+
return z;
|
|
4863
|
+
}
|
|
4864
|
+
function rsDivisor(degree) {
|
|
4865
|
+
const result = new Array(degree).fill(0);
|
|
4866
|
+
result[degree - 1] = 1;
|
|
4867
|
+
let root = 1;
|
|
4868
|
+
for (let i = 0; i < degree; i++) {
|
|
4869
|
+
for (let j = 0; j < degree; j++) {
|
|
4870
|
+
result[j] = gfMul(result[j], root);
|
|
4871
|
+
if (j + 1 < degree) result[j] ^= result[j + 1];
|
|
4872
|
+
}
|
|
4873
|
+
root = gfMul(root, 2);
|
|
4874
|
+
}
|
|
4875
|
+
return result;
|
|
4876
|
+
}
|
|
4877
|
+
function rsRemainder(data, divisor) {
|
|
4878
|
+
const result = new Array(divisor.length).fill(0);
|
|
4879
|
+
for (const b of data) {
|
|
4880
|
+
const factor = b ^ result.shift();
|
|
4881
|
+
result.push(0);
|
|
4882
|
+
divisor.forEach((coef, i) => {
|
|
4883
|
+
result[i] ^= gfMul(coef, factor);
|
|
4884
|
+
});
|
|
4885
|
+
}
|
|
4886
|
+
return result;
|
|
4887
|
+
}
|
|
4888
|
+
function alignmentPositions(ver, size) {
|
|
4889
|
+
if (ver === 1) return [];
|
|
4890
|
+
const n = Math.floor(ver / 7) + 2;
|
|
4891
|
+
const step = Math.ceil((ver * 4 + 4) / (n * 2 - 2)) * 2;
|
|
4892
|
+
const out = [6];
|
|
4893
|
+
for (let pos = size - 7; out.length < n; pos -= step) out.splice(1, 0, pos);
|
|
4894
|
+
return out;
|
|
4895
|
+
}
|
|
4896
|
+
const MASKS = [
|
|
4897
|
+
(x, y) => (x + y) % 2 === 0,
|
|
4898
|
+
(_x, y) => y % 2 === 0,
|
|
4899
|
+
(x) => x % 3 === 0,
|
|
4900
|
+
(x, y) => (x + y) % 3 === 0,
|
|
4901
|
+
(x, y) => (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0,
|
|
4902
|
+
(x, y) => x * y % 2 + x * y % 3 === 0,
|
|
4903
|
+
(x, y) => (x * y % 2 + x * y % 3) % 2 === 0,
|
|
4904
|
+
(x, y) => ((x + y) % 2 + x * y % 3) % 2 === 0
|
|
4905
|
+
];
|
|
4906
|
+
function penalty(m2, size) {
|
|
4907
|
+
let p = 0;
|
|
4908
|
+
const FINDER = [true, false, true, true, true, false, true, false, false, false, false];
|
|
4909
|
+
const matchAt = (get, start, rev) => {
|
|
4910
|
+
for (let k = 0; k < 11; k++) {
|
|
4911
|
+
if (get(start + k) !== FINDER[rev ? 10 - k : k]) return false;
|
|
4912
|
+
}
|
|
4913
|
+
return true;
|
|
4914
|
+
};
|
|
4915
|
+
for (let a = 0; a < size; a++) {
|
|
4916
|
+
for (const horiz of [true, false]) {
|
|
4917
|
+
const get = (i) => horiz ? m2[a][i] : m2[i][a];
|
|
4918
|
+
let run = 1;
|
|
4919
|
+
for (let i = 1; i < size; i++) {
|
|
4920
|
+
if (get(i) === get(i - 1)) {
|
|
4921
|
+
run++;
|
|
4922
|
+
if (run === 5) p += 3;
|
|
4923
|
+
else if (run > 5) p += 1;
|
|
4924
|
+
} else run = 1;
|
|
4925
|
+
}
|
|
4926
|
+
for (let s = 0; s + 11 <= size; s++) {
|
|
4927
|
+
if (matchAt(get, s, false)) p += 40;
|
|
4928
|
+
if (matchAt(get, s, true)) p += 40;
|
|
4929
|
+
}
|
|
4930
|
+
}
|
|
4931
|
+
}
|
|
4932
|
+
let dark = 0;
|
|
4933
|
+
for (let y = 0; y < size; y++) {
|
|
4934
|
+
for (let x = 0; x < size; x++) {
|
|
4935
|
+
if (m2[y][x]) dark++;
|
|
4936
|
+
if (x + 1 < size && y + 1 < size && m2[y][x] === m2[y][x + 1] && m2[y][x] === m2[y + 1][x] && m2[y][x] === m2[y + 1][x + 1]) p += 3;
|
|
4937
|
+
}
|
|
4938
|
+
}
|
|
4939
|
+
const total = size * size;
|
|
4940
|
+
p += (Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1) * 10;
|
|
4941
|
+
return p;
|
|
4942
|
+
}
|
|
4943
|
+
function encodeQr(text) {
|
|
4944
|
+
const bytes = utf8(text);
|
|
4945
|
+
let ver = 1;
|
|
4946
|
+
for (; ver <= MAX_VERSION; ver++) {
|
|
4947
|
+
const ccBits = ver < 10 ? 8 : 16;
|
|
4948
|
+
if (4 + ccBits + bytes.length * 8 <= dataCodewords(ver) * 8) break;
|
|
4949
|
+
}
|
|
4950
|
+
if (ver > MAX_VERSION) throw new Error("qr: text too long");
|
|
4951
|
+
const size = ver * 4 + 17;
|
|
4952
|
+
const bits = [];
|
|
4953
|
+
const put = (val, len) => {
|
|
4954
|
+
for (let i = len - 1; i >= 0; i--) bits.push(val >>> i & 1);
|
|
4955
|
+
};
|
|
4956
|
+
put(4, 4);
|
|
4957
|
+
put(bytes.length, ver < 10 ? 8 : 16);
|
|
4958
|
+
bytes.forEach((b) => put(b, 8));
|
|
4959
|
+
const capBits = dataCodewords(ver) * 8;
|
|
4960
|
+
put(0, Math.min(4, capBits - bits.length));
|
|
4961
|
+
put(0, (8 - bits.length % 8) % 8);
|
|
4962
|
+
for (let pad = 236; bits.length < capBits; pad ^= 236 ^ 17) put(pad, 8);
|
|
4963
|
+
const data = [];
|
|
4964
|
+
for (let i = 0; i < bits.length; i += 8) {
|
|
4965
|
+
let v = 0;
|
|
4966
|
+
for (let j = 0; j < 8; j++) v = v << 1 | bits[i + j];
|
|
4967
|
+
data.push(v);
|
|
4968
|
+
}
|
|
4969
|
+
const nBlocks = BLOCKS_L[ver];
|
|
4970
|
+
const eccLen = ECC_PER_BLOCK_L[ver];
|
|
4971
|
+
const raw = Math.floor(rawDataModules(ver) / 8);
|
|
4972
|
+
const nShort = nBlocks - raw % nBlocks;
|
|
4973
|
+
const shortLen = Math.floor(raw / nBlocks);
|
|
4974
|
+
const div = rsDivisor(eccLen);
|
|
4975
|
+
const blocks = [];
|
|
4976
|
+
for (let i = 0, k = 0; i < nBlocks; i++) {
|
|
4977
|
+
const dat = data.slice(k, k + shortLen - eccLen + (i < nShort ? 0 : 1));
|
|
4978
|
+
k += dat.length;
|
|
4979
|
+
const ecc = rsRemainder(dat, div);
|
|
4980
|
+
if (i < nShort) dat.push(0);
|
|
4981
|
+
blocks.push(dat.concat(ecc));
|
|
4982
|
+
}
|
|
4983
|
+
const all = [];
|
|
4984
|
+
for (let i = 0; i < blocks[0].length; i++) {
|
|
4985
|
+
blocks.forEach((blk, j) => {
|
|
4986
|
+
if (i !== shortLen - eccLen || j >= nShort) all.push(blk[i]);
|
|
4987
|
+
});
|
|
4988
|
+
}
|
|
4989
|
+
const m2 = Array.from({ length: size }, () => new Array(size).fill(false));
|
|
4990
|
+
const fn = Array.from({ length: size }, () => new Array(size).fill(false));
|
|
4991
|
+
const set = (x, y, dark) => {
|
|
4992
|
+
m2[y][x] = dark;
|
|
4993
|
+
fn[y][x] = true;
|
|
4994
|
+
};
|
|
4995
|
+
for (let i = 0; i < size; i++) {
|
|
4996
|
+
set(6, i, i % 2 === 0);
|
|
4997
|
+
set(i, 6, i % 2 === 0);
|
|
4998
|
+
}
|
|
4999
|
+
for (const [cx, cy] of [[3, 3], [size - 4, 3], [3, size - 4]]) {
|
|
5000
|
+
for (let dy = -4; dy <= 4; dy++) {
|
|
5001
|
+
for (let dx = -4; dx <= 4; dx++) {
|
|
5002
|
+
const x = cx + dx;
|
|
5003
|
+
const y = cy + dy;
|
|
5004
|
+
if (x < 0 || y < 0 || x >= size || y >= size) continue;
|
|
5005
|
+
const d = Math.max(Math.abs(dx), Math.abs(dy));
|
|
5006
|
+
set(x, y, d !== 2 && d !== 4);
|
|
5007
|
+
}
|
|
5008
|
+
}
|
|
5009
|
+
}
|
|
5010
|
+
const al = alignmentPositions(ver, size);
|
|
5011
|
+
al.forEach((ax, i) => {
|
|
5012
|
+
al.forEach((ay, j) => {
|
|
5013
|
+
if (i === 0 && j === 0 || i === 0 && j === al.length - 1 || i === al.length - 1 && j === 0) return;
|
|
5014
|
+
for (let dy = -2; dy <= 2; dy++) {
|
|
5015
|
+
for (let dx = -2; dx <= 2; dx++) set(ax + dx, ay + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
|
|
5016
|
+
}
|
|
5017
|
+
});
|
|
5018
|
+
});
|
|
5019
|
+
const drawFormat = (mask) => {
|
|
5020
|
+
const d = 1 << 3 | mask;
|
|
5021
|
+
let rem = d;
|
|
5022
|
+
for (let i = 0; i < 10; i++) rem = rem << 1 ^ (rem >>> 9) * 1335;
|
|
5023
|
+
const f = (d << 10 | rem) ^ 21522;
|
|
5024
|
+
const bit = (i) => (f >>> i & 1) !== 0;
|
|
5025
|
+
for (let i = 0; i <= 5; i++) set(8, i, bit(i));
|
|
5026
|
+
set(8, 7, bit(6));
|
|
5027
|
+
set(8, 8, bit(7));
|
|
5028
|
+
set(7, 8, bit(8));
|
|
5029
|
+
for (let i = 9; i < 15; i++) set(14 - i, 8, bit(i));
|
|
5030
|
+
for (let i = 0; i < 8; i++) set(size - 1 - i, 8, bit(i));
|
|
5031
|
+
for (let i = 8; i < 15; i++) set(8, size - 15 + i, bit(i));
|
|
5032
|
+
set(8, size - 8, true);
|
|
5033
|
+
};
|
|
5034
|
+
drawFormat(0);
|
|
5035
|
+
if (ver >= 7) {
|
|
5036
|
+
let rem = ver;
|
|
5037
|
+
for (let i = 0; i < 12; i++) rem = rem << 1 ^ (rem >>> 11) * 7973;
|
|
5038
|
+
const v = ver << 12 | rem;
|
|
5039
|
+
for (let i = 0; i < 18; i++) {
|
|
5040
|
+
const dark = (v >>> i & 1) !== 0;
|
|
5041
|
+
const a = size - 11 + i % 3;
|
|
5042
|
+
const b = Math.floor(i / 3);
|
|
5043
|
+
set(a, b, dark);
|
|
5044
|
+
set(b, a, dark);
|
|
5045
|
+
}
|
|
5046
|
+
}
|
|
5047
|
+
let idx = 0;
|
|
5048
|
+
for (let right = size - 1; right >= 1; right -= 2) {
|
|
5049
|
+
if (right === 6) right = 5;
|
|
5050
|
+
for (let vert = 0; vert < size; vert++) {
|
|
5051
|
+
for (let j = 0; j < 2; j++) {
|
|
5052
|
+
const x = right - j;
|
|
5053
|
+
const upward = (right + 1 & 2) === 0;
|
|
5054
|
+
const y = upward ? size - 1 - vert : vert;
|
|
5055
|
+
if (!fn[y][x] && idx < all.length * 8) {
|
|
5056
|
+
m2[y][x] = (all[idx >>> 3] >>> 7 - (idx & 7) & 1) !== 0;
|
|
5057
|
+
idx++;
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
5061
|
+
}
|
|
5062
|
+
const applyMask = (mask) => {
|
|
5063
|
+
for (let y = 0; y < size; y++) {
|
|
5064
|
+
for (let x = 0; x < size; x++) if (!fn[y][x] && MASKS[mask](x, y)) m2[y][x] = !m2[y][x];
|
|
5065
|
+
}
|
|
5066
|
+
};
|
|
5067
|
+
let best = 0;
|
|
5068
|
+
let bestPen = Infinity;
|
|
5069
|
+
for (let mask = 0; mask < 8; mask++) {
|
|
5070
|
+
applyMask(mask);
|
|
5071
|
+
drawFormat(mask);
|
|
5072
|
+
const p = penalty(m2, size);
|
|
5073
|
+
if (p < bestPen) {
|
|
5074
|
+
bestPen = p;
|
|
5075
|
+
best = mask;
|
|
5076
|
+
}
|
|
5077
|
+
applyMask(mask);
|
|
5078
|
+
}
|
|
5079
|
+
applyMask(best);
|
|
5080
|
+
drawFormat(best);
|
|
5081
|
+
return { size, version: ver, modules: m2 };
|
|
5082
|
+
}
|
|
5083
|
+
function qrToSvg(qr, px = 168) {
|
|
5084
|
+
const q = 4;
|
|
5085
|
+
const dim = qr.size + q * 2;
|
|
5086
|
+
let d = "";
|
|
5087
|
+
for (let y = 0; y < qr.size; y++) {
|
|
5088
|
+
for (let x = 0; x < qr.size; x++) {
|
|
5089
|
+
if (qr.modules[y][x]) d += `M${x + q},${y + q}h1v1h-1z`;
|
|
5090
|
+
}
|
|
5091
|
+
}
|
|
5092
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${px}" height="${px}" viewBox="0 0 ${dim} ${dim}" shape-rendering="crispEdges" role="img" aria-label="QR code"><rect width="${dim}" height="${dim}" fill="#fff"/><path d="${d}" fill="#000"/></svg>`;
|
|
5093
|
+
}
|
|
5094
|
+
const MAX_PRODUCT_NAME_CHARS = 80;
|
|
5095
|
+
const REF_VALUE_RE = /^[A-Za-z0-9_.-]{1,64}$/;
|
|
5096
|
+
let chatContext = {};
|
|
5097
|
+
function setChatContext(ctx) {
|
|
5098
|
+
chatContext = ctx ? { ...chatContext, ...ctx } : {};
|
|
5099
|
+
}
|
|
5100
|
+
function getChatContext() {
|
|
5101
|
+
return chatContext;
|
|
5102
|
+
}
|
|
5103
|
+
function parseChatWhatsapp(raw) {
|
|
5104
|
+
if (!raw || typeof raw !== "object") return null;
|
|
5105
|
+
const r = raw;
|
|
5106
|
+
if (typeof r.default !== "string" || !digitsOf(r.default)) return null;
|
|
5107
|
+
const by = {};
|
|
5108
|
+
if (r.by_location && typeof r.by_location === "object") {
|
|
5109
|
+
for (const [k, v] of Object.entries(r.by_location)) {
|
|
5110
|
+
if (typeof v === "string" && digitsOf(v)) by[k] = v;
|
|
5111
|
+
}
|
|
5112
|
+
}
|
|
5113
|
+
return { default: r.default, by_location: by };
|
|
5114
|
+
}
|
|
5115
|
+
function pickWhatsappNumber(p, locationId) {
|
|
5116
|
+
var _a;
|
|
5117
|
+
return (locationId ? (_a = p.by_location) == null ? void 0 : _a[locationId] : void 0) ?? p.default;
|
|
5118
|
+
}
|
|
5119
|
+
function digitsOf(num2) {
|
|
5120
|
+
return num2.replace(/\D/g, "");
|
|
5121
|
+
}
|
|
5122
|
+
function buildPrefill(ctx = chatContext) {
|
|
5123
|
+
const name = (ctx.productName ?? "").trim().slice(0, MAX_PRODUCT_NAME_CHARS);
|
|
5124
|
+
let text = name ? `Hi! I have a question about ${name}` : "Hi! I have a question";
|
|
5125
|
+
if (ctx.sku && REF_VALUE_RE.test(ctx.sku)) text += `
|
|
5126
|
+
(ref p.${ctx.sku})`;
|
|
5127
|
+
else if (ctx.storeSlug && REF_VALUE_RE.test(ctx.storeSlug)) text += `
|
|
5128
|
+
(ref s.${ctx.storeSlug})`;
|
|
5129
|
+
return text;
|
|
5130
|
+
}
|
|
5131
|
+
function buildWaLink(number, text) {
|
|
5132
|
+
return `https://wa.me/${digitsOf(number)}?text=${encodeURIComponent(text)}`;
|
|
5133
|
+
}
|
|
5134
|
+
function isPhoneLike() {
|
|
5135
|
+
var _a, _b;
|
|
5136
|
+
if (typeof window === "undefined") return false;
|
|
5137
|
+
const touch = typeof navigator !== "undefined" && (navigator.maxTouchPoints ?? 0) > 0;
|
|
5138
|
+
const narrow = ((_b = (_a = window.matchMedia) == null ? void 0 : _a.call(window, `(max-width: ${LAUNCHER_MOBILE_MAX_PX}px)`)) == null ? void 0 : _b.matches) === true;
|
|
5139
|
+
return touch || narrow;
|
|
5140
|
+
}
|
|
5141
|
+
const WHATSAPP_GLYPH_SVG = '<svg width="30" height="30" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M17.47 14.38c-.3-.15-1.76-.87-2.03-.97-.27-.1-.47-.15-.67.15-.2.3-.77.97-.94 1.17-.17.2-.35.22-.64.07-.3-.15-1.26-.46-2.4-1.48-.88-.79-1.48-1.76-1.66-2.06-.17-.3-.02-.46.13-.6.13-.13.3-.35.45-.52.15-.17.2-.3.3-.5.1-.2.05-.37-.03-.52-.07-.15-.67-1.62-.92-2.22-.24-.58-.49-.5-.67-.51h-.57c-.2 0-.52.07-.8.37-.27.3-1.04 1.02-1.04 2.48 0 1.46 1.07 2.88 1.21 3.07.15.2 2.1 3.2 5.08 4.49.71.31 1.26.49 1.7.63.71.23 1.36.2 1.87.12.57-.09 1.76-.72 2.01-1.41.25-.7.25-1.29.17-1.41-.07-.12-.27-.2-.57-.35z"/><path d="M12.04 2C6.58 2 2.13 6.45 2.13 11.91c0 1.75.46 3.45 1.32 4.95L2.05 22l5.25-1.38a9.9 9.9 0 0 0 4.74 1.21c5.46 0 9.91-4.45 9.91-9.91C21.95 6.45 17.5 2 12.04 2zm0 18.15c-1.48 0-2.93-.4-4.2-1.15l-.3-.18-3.12.82.83-3.04-.2-.31a8.2 8.2 0 0 1-1.26-4.38c0-4.54 3.7-8.24 8.25-8.24 4.54 0 8.24 3.7 8.24 8.24 0 4.54-3.7 8.24-8.24 8.24z" fill-rule="evenodd"/></svg>';
|
|
5142
|
+
function buildWhatsappCard(link, onClose) {
|
|
5143
|
+
const card = document.createElement("div");
|
|
5144
|
+
card.className = "aegis-wa-card";
|
|
5145
|
+
card.setAttribute("role", "dialog");
|
|
5146
|
+
card.setAttribute("aria-label", "Chat on WhatsApp");
|
|
5147
|
+
card.tabIndex = -1;
|
|
5148
|
+
const close = document.createElement("button");
|
|
5149
|
+
close.type = "button";
|
|
5150
|
+
close.className = "aegis-wa-card-close";
|
|
5151
|
+
close.setAttribute("aria-label", "Close");
|
|
5152
|
+
close.innerHTML = lucideSvg("x", { size: 16 });
|
|
5153
|
+
close.addEventListener("click", onClose);
|
|
5154
|
+
const title = document.createElement("div");
|
|
5155
|
+
title.className = "aegis-wa-card-title";
|
|
5156
|
+
title.textContent = "Chat with us on WhatsApp";
|
|
5157
|
+
const qr = document.createElement("div");
|
|
5158
|
+
qr.className = "aegis-wa-card-qr";
|
|
5159
|
+
try {
|
|
5160
|
+
qr.innerHTML = qrToSvg(encodeQr(link));
|
|
5161
|
+
} catch {
|
|
5162
|
+
qr.style.display = "none";
|
|
5163
|
+
}
|
|
5164
|
+
const hint = document.createElement("div");
|
|
5165
|
+
hint.className = "aegis-wa-card-hint";
|
|
5166
|
+
hint.textContent = "Scan with your phone camera";
|
|
5167
|
+
const a = document.createElement("a");
|
|
5168
|
+
a.className = "aegis-wa-card-link";
|
|
5169
|
+
a.href = link;
|
|
5170
|
+
a.target = "_blank";
|
|
5171
|
+
a.rel = "noopener noreferrer";
|
|
5172
|
+
a.textContent = "Open WhatsApp on this computer";
|
|
5173
|
+
card.append(close, title, qr, hint, a);
|
|
5174
|
+
return card;
|
|
5175
|
+
}
|
|
5176
|
+
function whatsappCss(sizePx, offsetPx) {
|
|
5177
|
+
return `
|
|
5178
|
+
.aegis-wa-bubble{width:${sizePx}px;height:${sizePx}px;border-radius:9999px;border:none;background:#25d366;color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;box-shadow:0 8px 24px rgba(0,0,0,.18);transition:transform .18s ease,box-shadow .18s ease;position:relative}
|
|
5179
|
+
.aegis-wa-bubble:hover{transform:translateY(-2px) scale(1.04);box-shadow:0 12px 28px rgba(0,0,0,.22)}
|
|
5180
|
+
.aegis-wa-card{position:absolute;bottom:${sizePx + 12}px;right:0;width:248px;max-width:calc(100vw - ${2 * offsetPx}px);box-sizing:border-box;background:#fff;color:#0f172a;border:1px solid #e2e8f0;border-radius:16px;box-shadow:0 16px 48px rgba(0,0,0,.24);padding:16px;display:none;flex-direction:column;align-items:center;gap:8px;font-size:14px}
|
|
5181
|
+
.aegis-wa-card--open{display:flex}
|
|
5182
|
+
.aegis-chat-root--bottom-left .aegis-wa-card{left:0;right:auto}
|
|
5183
|
+
.aegis-wa-card-close{position:absolute;top:4px;right:4px;width:32px;height:32px;padding:4px;box-sizing:border-box;border:none;background:transparent;color:#64748b;cursor:pointer;border-radius:9999px;display:flex;align-items:center;justify-content:center}
|
|
5184
|
+
.aegis-wa-card-title{font-weight:600;padding:0 20px}
|
|
5185
|
+
.aegis-wa-card-qr{line-height:0;border:1px solid #e2e8f0;border-radius:8px;overflow:hidden}
|
|
5186
|
+
.aegis-wa-card-hint{font-size:12px;color:#64748b}
|
|
5187
|
+
.aegis-wa-card-link{display:block;text-align:center;background:#25d366;color:#fff;text-decoration:none;font-weight:600;border-radius:9999px;padding:8px 14px;font-size:13px}
|
|
5188
|
+
`;
|
|
5189
|
+
}
|
|
4729
5190
|
const WORKSPACE_MISMATCH_CODE = "chat_workspace_mismatch";
|
|
4730
5191
|
const REMINT_WINDOW_MS = 3e4;
|
|
4731
5192
|
const AUTH_STOPPED_TEXT = "Sorry, chat is unavailable right now. Please try again in a moment.";
|
|
@@ -4784,6 +5245,7 @@ class AegisChat {
|
|
|
4784
5245
|
this.workspaceRejected = false;
|
|
4785
5246
|
this.lastRemintAt = 0;
|
|
4786
5247
|
this.authStopped = false;
|
|
5248
|
+
this.streamRefused = false;
|
|
4787
5249
|
this.renderedRows = /* @__PURE__ */ new Map();
|
|
4788
5250
|
this.sessionResumed = false;
|
|
4789
5251
|
this.open = false;
|
|
@@ -4808,6 +5270,9 @@ class AegisChat {
|
|
|
4808
5270
|
this.logoUrl = config.logoUrl;
|
|
4809
5271
|
this.position = config.position ?? "bottom-right";
|
|
4810
5272
|
this.displayMode = config.displayMode ?? "bubble";
|
|
5273
|
+
this.whatsapp = config.whatsapp;
|
|
5274
|
+
this.getLocationId = config.getLocationId;
|
|
5275
|
+
this.onLauncherOpened = config.onLauncherOpened;
|
|
4811
5276
|
this.agentPersona = config.agentPersona;
|
|
4812
5277
|
this.quickReplies = config.quickReplies;
|
|
4813
5278
|
this.onSessionStart = config.onSessionStart;
|
|
@@ -4821,6 +5286,15 @@ class AegisChat {
|
|
|
4821
5286
|
if (this.initialized || typeof document === "undefined") return;
|
|
4822
5287
|
this.initialized = true;
|
|
4823
5288
|
this.injectStyles();
|
|
5289
|
+
if (isLauncherOff()) {
|
|
5290
|
+
this.initialized = false;
|
|
5291
|
+
return;
|
|
5292
|
+
}
|
|
5293
|
+
if (this.whatsapp) {
|
|
5294
|
+
this.mountWhatsapp();
|
|
5295
|
+
currentLauncher = this;
|
|
5296
|
+
return;
|
|
5297
|
+
}
|
|
4824
5298
|
this.mount();
|
|
4825
5299
|
currentLauncher = this;
|
|
4826
5300
|
if (this.displayMode !== "nav") this.scheduleAttention();
|
|
@@ -4832,28 +5306,42 @@ class AegisChat {
|
|
|
4832
5306
|
}
|
|
4833
5307
|
/** Programmatic open (used by the proactive TriggerEngine wiring). */
|
|
4834
5308
|
openPanel(prefill) {
|
|
4835
|
-
var _a, _b, _c, _d;
|
|
5309
|
+
var _a, _b, _c, _d, _e;
|
|
5310
|
+
if (this.whatsapp) {
|
|
5311
|
+
this.openWhatsapp();
|
|
5312
|
+
return;
|
|
5313
|
+
}
|
|
4836
5314
|
if (!this.panel) this.initialize();
|
|
5315
|
+
if (!this.panel) return;
|
|
4837
5316
|
if (this.open) return;
|
|
5317
|
+
try {
|
|
5318
|
+
(_a = this.onLauncherOpened) == null ? void 0 : _a.call(this, "web_chat");
|
|
5319
|
+
} catch {
|
|
5320
|
+
}
|
|
4838
5321
|
this.open = true;
|
|
4839
5322
|
this.hasInteracted = true;
|
|
5323
|
+
this.streamRefused = false;
|
|
4840
5324
|
try {
|
|
4841
|
-
(
|
|
5325
|
+
(_b = this.onSessionStart) == null ? void 0 : _b.call(this);
|
|
4842
5326
|
} catch {
|
|
4843
5327
|
}
|
|
4844
5328
|
this.dismissAttention();
|
|
4845
|
-
(
|
|
4846
|
-
(
|
|
5329
|
+
(_c = this.panel) == null ? void 0 : _c.classList.add("aegis-chat-panel--open");
|
|
5330
|
+
(_d = this.bubble) == null ? void 0 : _d.classList.add("aegis-chat-bubble--hidden");
|
|
4847
5331
|
this.bindViewport();
|
|
4848
5332
|
this.revealLatest();
|
|
4849
5333
|
this.clearUnread();
|
|
4850
5334
|
if (prefill && this.input) this.input.value = prefill;
|
|
4851
5335
|
void this.resumeSession();
|
|
4852
5336
|
this.startPolling();
|
|
4853
|
-
(
|
|
5337
|
+
(_e = this.input) == null ? void 0 : _e.focus();
|
|
4854
5338
|
}
|
|
4855
5339
|
closePanel() {
|
|
4856
5340
|
var _a, _b, _c;
|
|
5341
|
+
if (this.whatsapp) {
|
|
5342
|
+
this.closeWhatsappCard();
|
|
5343
|
+
return;
|
|
5344
|
+
}
|
|
4857
5345
|
const wasOpen = this.open;
|
|
4858
5346
|
this.open = false;
|
|
4859
5347
|
(_a = this.panel) == null ? void 0 : _a.classList.remove("aegis-chat-panel--open");
|
|
@@ -4869,11 +5357,13 @@ class AegisChat {
|
|
|
4869
5357
|
}
|
|
4870
5358
|
}
|
|
4871
5359
|
destroy() {
|
|
4872
|
-
var _a;
|
|
5360
|
+
var _a, _b;
|
|
4873
5361
|
this.unbindViewport();
|
|
4874
5362
|
this.disconnectSSE();
|
|
4875
5363
|
this.stopPolling();
|
|
4876
|
-
(_a = this.
|
|
5364
|
+
(_a = this.waDismiss) == null ? void 0 : _a.call(this);
|
|
5365
|
+
this.waDismiss = void 0;
|
|
5366
|
+
(_b = this.root) == null ? void 0 : _b.remove();
|
|
4877
5367
|
this.initialized = false;
|
|
4878
5368
|
if (currentLauncher === this) currentLauncher = null;
|
|
4879
5369
|
}
|
|
@@ -4989,6 +5479,10 @@ class AegisChat {
|
|
|
4989
5479
|
if (!this.open) return;
|
|
4990
5480
|
if (typeof EventSource === "undefined" || !this.contactId) return;
|
|
4991
5481
|
if (!ticket) return;
|
|
5482
|
+
if (this.streamRefused) {
|
|
5483
|
+
this.startPolling();
|
|
5484
|
+
return;
|
|
5485
|
+
}
|
|
4992
5486
|
this.disconnectSSE();
|
|
4993
5487
|
const url = new URL("/v1/stream/realtime", this.apiHost || window.location.origin);
|
|
4994
5488
|
url.searchParams.set("ticket", ticket);
|
|
@@ -5008,6 +5502,12 @@ class AegisChat {
|
|
|
5008
5502
|
this.eventSource.onerror = () => {
|
|
5009
5503
|
if (this.eventSource && this.eventSource.readyState === 2) {
|
|
5010
5504
|
this.disconnectSSE();
|
|
5505
|
+
if (this.lastRemintAt && Date.now() - this.lastRemintAt < REMINT_WINDOW_MS) {
|
|
5506
|
+
this.streamRefused = true;
|
|
5507
|
+
this.log("SSE refused with a fresh ticket; polling");
|
|
5508
|
+
this.startPolling();
|
|
5509
|
+
return;
|
|
5510
|
+
}
|
|
5011
5511
|
void this.recoverAuth();
|
|
5012
5512
|
return;
|
|
5013
5513
|
}
|
|
@@ -5101,6 +5601,73 @@ class AegisChat {
|
|
|
5101
5601
|
}
|
|
5102
5602
|
return SPARKLE;
|
|
5103
5603
|
}
|
|
5604
|
+
/** WhatsApp mode: a green WhatsApp button. Phone → wa.me; desktop → QR card. */
|
|
5605
|
+
mountWhatsapp() {
|
|
5606
|
+
const root = document.createElement("div");
|
|
5607
|
+
root.className = `aegis-chat-root aegis-chat-root--${this.position}`;
|
|
5608
|
+
const bubble = document.createElement("button");
|
|
5609
|
+
bubble.type = "button";
|
|
5610
|
+
bubble.className = "aegis-wa-bubble";
|
|
5611
|
+
bubble.setAttribute("aria-label", "Chat on WhatsApp");
|
|
5612
|
+
bubble.innerHTML = WHATSAPP_GLYPH_SVG;
|
|
5613
|
+
bubble.addEventListener("click", () => this.openWhatsapp());
|
|
5614
|
+
root.appendChild(bubble);
|
|
5615
|
+
document.body.appendChild(root);
|
|
5616
|
+
this.root = root;
|
|
5617
|
+
this.bubble = bubble;
|
|
5618
|
+
}
|
|
5619
|
+
/** The number for the outlet being viewed → open WhatsApp (phone) or the QR card (desktop). */
|
|
5620
|
+
openWhatsapp() {
|
|
5621
|
+
var _a, _b;
|
|
5622
|
+
if (!this.whatsapp) return;
|
|
5623
|
+
if (!this.root) this.initialize();
|
|
5624
|
+
if (!this.root) return;
|
|
5625
|
+
if (this.waCard) {
|
|
5626
|
+
this.closeWhatsappCard();
|
|
5627
|
+
return;
|
|
5628
|
+
}
|
|
5629
|
+
const number = pickWhatsappNumber(this.whatsapp, ((_a = this.getLocationId) == null ? void 0 : _a.call(this)) ?? null);
|
|
5630
|
+
const link = buildWaLink(number, buildPrefill());
|
|
5631
|
+
try {
|
|
5632
|
+
(_b = this.onLauncherOpened) == null ? void 0 : _b.call(this, "whatsapp");
|
|
5633
|
+
} catch {
|
|
5634
|
+
}
|
|
5635
|
+
if (isPhoneLike()) {
|
|
5636
|
+
window.open(link, "_blank", "noopener");
|
|
5637
|
+
return;
|
|
5638
|
+
}
|
|
5639
|
+
this.closeWhatsappCard(false);
|
|
5640
|
+
const card = buildWhatsappCard(link, () => this.closePanel());
|
|
5641
|
+
card.classList.add("aegis-wa-card--open");
|
|
5642
|
+
this.root.appendChild(card);
|
|
5643
|
+
this.waCard = card;
|
|
5644
|
+
const onKey = (e) => {
|
|
5645
|
+
if (e.key === "Escape") this.closeWhatsappCard();
|
|
5646
|
+
};
|
|
5647
|
+
const onOutside = (e) => {
|
|
5648
|
+
var _a2;
|
|
5649
|
+
const t = e.target;
|
|
5650
|
+
if (t && (card.contains(t) || ((_a2 = this.bubble) == null ? void 0 : _a2.contains(t)))) return;
|
|
5651
|
+
this.closeWhatsappCard();
|
|
5652
|
+
};
|
|
5653
|
+
document.addEventListener("keydown", onKey);
|
|
5654
|
+
document.addEventListener("pointerdown", onOutside, true);
|
|
5655
|
+
this.waDismiss = () => {
|
|
5656
|
+
document.removeEventListener("keydown", onKey);
|
|
5657
|
+
document.removeEventListener("pointerdown", onOutside, true);
|
|
5658
|
+
};
|
|
5659
|
+
card.focus();
|
|
5660
|
+
}
|
|
5661
|
+
closeWhatsappCard(restoreFocus = true) {
|
|
5662
|
+
var _a, _b;
|
|
5663
|
+
(_a = this.waDismiss) == null ? void 0 : _a.call(this);
|
|
5664
|
+
this.waDismiss = void 0;
|
|
5665
|
+
const card = this.waCard;
|
|
5666
|
+
this.waCard = void 0;
|
|
5667
|
+
if (!card) return;
|
|
5668
|
+
card.remove();
|
|
5669
|
+
if (restoreFocus) (_b = this.bubble) == null ? void 0 : _b.focus();
|
|
5670
|
+
}
|
|
5104
5671
|
mount() {
|
|
5105
5672
|
const root = document.createElement("div");
|
|
5106
5673
|
root.className = `aegis-chat-root aegis-chat-root--${this.position}`;
|
|
@@ -5744,13 +6311,14 @@ class AegisChat {
|
|
|
5744
6311
|
}
|
|
5745
6312
|
}
|
|
5746
6313
|
const CHAT_CSS = `
|
|
5747
|
-
|
|
5748
|
-
.aegis-chat-root
|
|
6314
|
+
${launcherRootCss("aegis-chat-root")}
|
|
6315
|
+
.aegis-chat-root{${fontFamilyCss("body")}}
|
|
6316
|
+
${whatsappCss(LAUNCHER_SIZE_PX, LAUNCHER_OFFSET_MOBILE_PX)}
|
|
5749
6317
|
.aegis-chat-root--bottom-left .aegis-chat-panel{left:0;right:auto}
|
|
5750
6318
|
.aegis-chat-bubble-logo{width:34px;height:34px;border-radius:9999px;object-fit:cover}
|
|
5751
|
-
.aegis-chat-bubble{width
|
|
6319
|
+
.aegis-chat-bubble{width:${LAUNCHER_SIZE_PX}px;height:${LAUNCHER_SIZE_PX}px;border-radius:9999px;border:none;background:var(--aegis-chat-accent,#4169e1);color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;box-shadow:0 8px 24px rgba(0,0,0,.18);transition:transform .18s ease,box-shadow .18s ease;position:relative;animation:aegis-chat-in .4s cubic-bezier(.16,1,.3,1)}
|
|
5752
6320
|
.aegis-chat-bubble:hover{transform:translateY(-2px) scale(1.04);box-shadow:0 12px 28px rgba(0,0,0,.22)}
|
|
5753
|
-
.aegis-chat-bubble--hidden{display:none}
|
|
6321
|
+
.aegis-chat-bubble--hidden,.aegis-wa-bubble.aegis-chat-bubble--hidden{display:none}
|
|
5754
6322
|
/* Attention pulse — an expanding accent ring that draws the eye to a live, ready assistant. */
|
|
5755
6323
|
.aegis-chat-bubble--pulse::before{content:"";position:absolute;inset:0;border-radius:9999px;background:var(--aegis-chat-accent,#4169e1);z-index:-1;animation:aegis-chat-pulse 1.8s ease-out infinite}
|
|
5756
6324
|
.aegis-chat-bubble--pulse{animation:aegis-chat-in .4s cubic-bezier(.16,1,.3,1),aegis-chat-nudge 1.8s ease-in-out 2}
|
|
@@ -5758,7 +6326,7 @@ const CHAT_CSS = `
|
|
|
5758
6326
|
@keyframes aegis-chat-pulse{0%{transform:scale(1);opacity:.55}100%{transform:scale(1.9);opacity:0}}
|
|
5759
6327
|
@keyframes aegis-chat-nudge{0%,100%{transform:translateY(0)}25%{transform:translateY(-5px)}50%{transform:translateY(0)}}
|
|
5760
6328
|
/* One-time greeting tooltip */
|
|
5761
|
-
.aegis-chat-tip{position:absolute;bottom:
|
|
6329
|
+
.aegis-chat-tip{position:absolute;bottom:12px;right:${LAUNCHER_SIZE_PX + 14}px;max-width:230px;background:#fff;color:#0f172a;border:1px solid #e2e8f0;border-radius:14px;border-bottom-right-radius:4px;box-shadow:0 10px 30px rgba(0,0,0,.16);padding:10px 30px 10px 13px;font-size:13.5px;line-height:1.4;cursor:pointer;opacity:0;transform:translateX(8px) scale(.92);transform-origin:bottom right;pointer-events:none;transition:opacity .25s ease,transform .25s ease}
|
|
5762
6330
|
.aegis-chat-tip--show{opacity:1;transform:translateX(0) scale(1);pointer-events:auto}
|
|
5763
6331
|
.aegis-chat-tip-close{position:absolute;top:5px;right:6px;width:18px;height:18px;border:none;background:transparent;color:#94a3b8;font-size:12px;line-height:1;cursor:pointer;border-radius:9999px}
|
|
5764
6332
|
.aegis-chat-tip-close:hover{background:#f1f5f9;color:#475569}
|
|
@@ -5817,10 +6385,9 @@ const CHAT_CSS = `
|
|
|
5817
6385
|
.aegis-chat-media-img{max-width:200px;max-height:200px;border-radius:12px;object-fit:cover;cursor:pointer;display:block}
|
|
5818
6386
|
.aegis-chat-media-file{display:inline-flex;align-items:center;gap:6px;padding:8px 12px;border-radius:12px;background:#fff;border:1px solid #e2e8f0;font-size:13px;color:#0f172a;text-decoration:none;max-width:220px}
|
|
5819
6387
|
.aegis-chat-msg--customer .aegis-chat-media-file{background:rgba(255,255,255,.18);border-color:transparent;color:#fff}
|
|
5820
|
-
/* Mobile:
|
|
5821
|
-
|
|
6388
|
+
/* Mobile: dock position comes from launcher-spec (hosts raise it with
|
|
6389
|
+
--aegis-launcher-bottom); widen the panel and reduce the tooltip width. */
|
|
5822
6390
|
@media (max-width:767px){
|
|
5823
|
-
.aegis-chat-root{bottom:84px;right:16px}
|
|
5824
6391
|
/* Full-page chat on mobile — the open panel covers the whole viewport (incl.
|
|
5825
6392
|
the bottom nav) like a native chat screen, instead of a floating card. */
|
|
5826
6393
|
.aegis-chat-panel{position:fixed;inset:0;left:0;right:0;width:100vw;height:100vh;height:100dvh;max-width:none;max-height:none;border-radius:0}
|
|
@@ -6410,6 +6977,7 @@ function renderActiveWebChat(ctx, creds) {
|
|
|
6410
6977
|
const accent = str(ic.chat_accent_color);
|
|
6411
6978
|
const logo = str(ic.chat_logo_url);
|
|
6412
6979
|
const icon = str(ic.chat_icon);
|
|
6980
|
+
const whatsapp = parseChatWhatsapp(ic.chat_whatsapp);
|
|
6413
6981
|
const cfg = {
|
|
6414
6982
|
writeKey: creds.writeKey,
|
|
6415
6983
|
apiHost: creds.apiHost,
|
|
@@ -6420,7 +6988,19 @@ function renderActiveWebChat(ctx, creds) {
|
|
|
6420
6988
|
title: str(ic.chat_title),
|
|
6421
6989
|
greeting: str(ic.chat_greeting),
|
|
6422
6990
|
accentColor: accent ? ctx.sanitizeColor(accent) : void 0,
|
|
6423
|
-
icon: icon === "sparkle" || icon === "chat" || icon === "logo" ? icon : void 0,
|
|
6991
|
+
icon: icon === "sparkle" || icon === "chat" || icon === "logo" ? icon : icon === "whatsapp" ? "chat" : void 0,
|
|
6992
|
+
whatsapp: whatsapp ?? void 0,
|
|
6993
|
+
getLocationId: ctx.getLocationId,
|
|
6994
|
+
// `chat.launcher_opened` — source = the surface the host declared, mode =
|
|
6995
|
+
// whatsapp | web_chat. Declared in CHANNEL_CANONICAL_EVENT_MAP server side.
|
|
6996
|
+
onLauncherOpened: (mode) => {
|
|
6997
|
+
var _a, _b;
|
|
6998
|
+
const source = ((_a = ctx.getSurface) == null ? void 0 : _a.call(ctx)) ?? void 0;
|
|
6999
|
+
(_b = ctx.track) == null ? void 0 : _b.call(ctx, "chat.launcher_opened", { source, mode, campaign_id: ctx.campaign.id });
|
|
7000
|
+
if (mode === "whatsapp") {
|
|
7001
|
+
ctx.trackEvent(ctx.campaign.id, "clicked", { meta: { action: "launcher_opened", mode } });
|
|
7002
|
+
}
|
|
7003
|
+
},
|
|
6424
7004
|
logoUrl: logo ? ctx.sanitizeUrl(logo) ?? void 0 : void 0,
|
|
6425
7005
|
position: ic.chat_position === "bottom-left" ? "bottom-left" : void 0,
|
|
6426
7006
|
surfaceStyle: ic.chat_theme === "tinted" ? "tinted" : void 0,
|
|
@@ -6441,8 +7021,8 @@ function renderActiveWebChat(ctx, creds) {
|
|
|
6441
7021
|
chat.initialize();
|
|
6442
7022
|
activeInstance = chat;
|
|
6443
7023
|
const proactive = ic.chat_proactive || {};
|
|
6444
|
-
const wantExit = proactive.exit_intent === true;
|
|
6445
|
-
const wantIdle = proactive.cart_idle === true;
|
|
7024
|
+
const wantExit = !whatsapp && proactive.exit_intent === true;
|
|
7025
|
+
const wantIdle = !whatsapp && proactive.cart_idle === true;
|
|
6446
7026
|
if (wantExit || wantIdle) {
|
|
6447
7027
|
const engine = new TriggerEngine();
|
|
6448
7028
|
if (wantExit) {
|
|
@@ -10974,6 +11554,16 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10974
11554
|
trackEvent: (id, evt, extra) => {
|
|
10975
11555
|
void this.trackEvent(id, evt, extra);
|
|
10976
11556
|
},
|
|
11557
|
+
getLocationId: () => this.currentLocationId ?? null,
|
|
11558
|
+
getSurface: () => this.currentSurface ?? this.currentScreen ?? null,
|
|
11559
|
+
track: (eventName, properties) => {
|
|
11560
|
+
var _a2;
|
|
11561
|
+
try {
|
|
11562
|
+
const host = window.aegis;
|
|
11563
|
+
(_a2 = host == null ? void 0 : host.track) == null ? void 0 : _a2.call(host, eventName, properties);
|
|
11564
|
+
} catch {
|
|
11565
|
+
}
|
|
11566
|
+
},
|
|
10977
11567
|
sanitizeUrl: (url) => this.sanitizeUrl(url),
|
|
10978
11568
|
navigate: (url, buttonId) => this.navigateToCampaignAction(campaign, url, buttonId),
|
|
10979
11569
|
dispatchAction: (action) => this.dispatchAction(action, campaign.id),
|
|
@@ -16474,7 +17064,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
16474
17064
|
this.initialized = false;
|
|
16475
17065
|
this.armedInAppTriggers = /* @__PURE__ */ new Set();
|
|
16476
17066
|
{
|
|
16477
|
-
const v = "1.
|
|
17067
|
+
const v = "1.47.0";
|
|
16478
17068
|
try {
|
|
16479
17069
|
globalThis.__AEGIS_SDK_VERSION__ = v;
|
|
16480
17070
|
} catch {
|
|
@@ -16952,9 +17542,12 @@ export {
|
|
|
16952
17542
|
A as AegisWebPush,
|
|
16953
17543
|
B as BloomFilter,
|
|
16954
17544
|
BootstrapError,
|
|
17545
|
+
DEFAULT_RAIL_TITLES,
|
|
16955
17546
|
E as EcommerceTracker,
|
|
16956
17547
|
N as NameGovernor,
|
|
16957
17548
|
PrefetchBundleClient,
|
|
17549
|
+
RAIL_REASONS_WEAKEST_FIRST,
|
|
17550
|
+
RESERVED_BOUGHT_TOGETHER_HEADINGS,
|
|
16958
17551
|
R as RateLimiter,
|
|
16959
17552
|
SdkConfigPoller,
|
|
16960
17553
|
TriggerEngine,
|
|
@@ -16966,14 +17559,18 @@ export {
|
|
|
16966
17559
|
aegis as default,
|
|
16967
17560
|
deriveDeviceFingerprint,
|
|
16968
17561
|
fallbackUrlForAction,
|
|
17562
|
+
getChatContext,
|
|
16969
17563
|
getCurrentLauncher,
|
|
17564
|
+
isReplaceableRailTitle,
|
|
16970
17565
|
mountScratchSurface,
|
|
16971
17566
|
m as murmurhash3_x86_32,
|
|
16972
17567
|
openChat,
|
|
16973
17568
|
parseAction,
|
|
16974
17569
|
readFirstPartyCookie,
|
|
16975
17570
|
renderPreview,
|
|
17571
|
+
resolveRailHeading,
|
|
16976
17572
|
scratchFoilPalette,
|
|
17573
|
+
setChatContext,
|
|
16977
17574
|
throttle,
|
|
16978
17575
|
writeFirstPartyCookie
|
|
16979
17576
|
};
|