@returningai/widget-sdk 1.6.0 → 1.6.2
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/CHANGELOG.md +11 -0
- package/README.md +32 -25
- package/dist/rai-banner.iife.js +1 -1
- package/dist/rai-banner.js +79 -30
- package/dist/rai-widget.iife.js +2 -2
- package/dist/rai-widget.js +80 -31
- package/package.json +1 -1
package/dist/rai-widget.js
CHANGED
|
@@ -12291,6 +12291,7 @@ function sanitizeBannerHtml(html2) {
|
|
|
12291
12291
|
});
|
|
12292
12292
|
}
|
|
12293
12293
|
function resolveCssToken(token) {
|
|
12294
|
+
const normalizedToken = token.startsWith("--") ? token : `--${token}`;
|
|
12294
12295
|
const candidates = [
|
|
12295
12296
|
document.documentElement,
|
|
12296
12297
|
document.body,
|
|
@@ -12312,23 +12313,28 @@ function resolveCssToken(token) {
|
|
|
12312
12313
|
)
|
|
12313
12314
|
].filter(Boolean);
|
|
12314
12315
|
for (const node of candidates) {
|
|
12315
|
-
const value = getComputedStyle(node).getPropertyValue(
|
|
12316
|
+
const value = getComputedStyle(node).getPropertyValue(normalizedToken).trim();
|
|
12317
|
+
if (value) return value;
|
|
12318
|
+
}
|
|
12319
|
+
for (const node of Array.from(document.querySelectorAll("*"))) {
|
|
12320
|
+
const value = getComputedStyle(node).getPropertyValue(normalizedToken).trim();
|
|
12316
12321
|
if (value) return value;
|
|
12317
12322
|
}
|
|
12318
12323
|
return void 0;
|
|
12319
12324
|
}
|
|
12320
12325
|
const safeColor = (v) => {
|
|
12321
12326
|
if (!v) return void 0;
|
|
12322
|
-
|
|
12323
|
-
if (
|
|
12324
|
-
|
|
12325
|
-
|
|
12327
|
+
const value = v.trim();
|
|
12328
|
+
if (/^(#|rgb|hsl)/i.test(value)) return value;
|
|
12329
|
+
if (/^(--)?[a-z0-9-]+$/i.test(value)) {
|
|
12330
|
+
const resolved = resolveCssToken(value);
|
|
12331
|
+
return resolved;
|
|
12326
12332
|
}
|
|
12327
|
-
const varMatch =
|
|
12333
|
+
const varMatch = value.match(/^var\((--[a-z0-9-]+)\)$/i);
|
|
12328
12334
|
if (varMatch) {
|
|
12329
12335
|
const token = varMatch[1];
|
|
12330
12336
|
const resolved = resolveCssToken(token);
|
|
12331
|
-
return resolved
|
|
12337
|
+
return resolved;
|
|
12332
12338
|
}
|
|
12333
12339
|
return void 0;
|
|
12334
12340
|
};
|
|
@@ -12354,6 +12360,11 @@ function imageAlign(pos) {
|
|
|
12354
12360
|
if (pos === "right" || pos === "bottom") return "flex-end";
|
|
12355
12361
|
return "center";
|
|
12356
12362
|
}
|
|
12363
|
+
function imageObjectPosition(horizontal, vertical) {
|
|
12364
|
+
const x = horizontal === "left" ? "left" : horizontal === "right" ? "right" : "center";
|
|
12365
|
+
const y = vertical === "top" ? "top" : vertical === "bottom" ? "bottom" : "center";
|
|
12366
|
+
return `${x} ${y}`;
|
|
12367
|
+
}
|
|
12357
12368
|
function getCtaStyleValue(banner, keys) {
|
|
12358
12369
|
var _a;
|
|
12359
12370
|
const sources = [(_a = banner.cta) == null ? void 0 : _a.style, banner.cta, banner.ctaStyle];
|
|
@@ -12368,19 +12379,26 @@ function getCtaStyleValue(banner, keys) {
|
|
|
12368
12379
|
function styleRichText(container) {
|
|
12369
12380
|
container.querySelectorAll("p").forEach((p) => {
|
|
12370
12381
|
p.style.margin = "0";
|
|
12382
|
+
p.style.whiteSpace = "normal";
|
|
12383
|
+
p.style.overflowWrap = "anywhere";
|
|
12371
12384
|
});
|
|
12372
12385
|
container.querySelectorAll("strong").forEach((strong) => {
|
|
12373
12386
|
strong.style.fontWeight = "700";
|
|
12387
|
+
strong.style.whiteSpace = "normal";
|
|
12374
12388
|
});
|
|
12375
12389
|
container.querySelectorAll("em").forEach((em) => {
|
|
12376
12390
|
em.style.fontStyle = "italic";
|
|
12391
|
+
em.style.whiteSpace = "normal";
|
|
12377
12392
|
});
|
|
12378
12393
|
container.querySelectorAll("u").forEach((u) => {
|
|
12379
12394
|
u.style.textDecoration = "underline";
|
|
12395
|
+
u.style.whiteSpace = "normal";
|
|
12380
12396
|
});
|
|
12381
12397
|
container.querySelectorAll("a").forEach((a) => {
|
|
12382
12398
|
a.style.color = "#3b82f6";
|
|
12383
12399
|
a.style.textDecoration = "underline";
|
|
12400
|
+
a.style.whiteSpace = "normal";
|
|
12401
|
+
a.style.overflowWrap = "anywhere";
|
|
12384
12402
|
if (a.getAttribute("target") === "_blank") {
|
|
12385
12403
|
a.setAttribute("rel", "noopener noreferrer");
|
|
12386
12404
|
}
|
|
@@ -12390,8 +12408,21 @@ function styleRichText(container) {
|
|
|
12390
12408
|
img.style.height = "auto";
|
|
12391
12409
|
});
|
|
12392
12410
|
}
|
|
12411
|
+
function readTextAlign(container) {
|
|
12412
|
+
const aligned = container.querySelector(
|
|
12413
|
+
'[style*="text-align"]'
|
|
12414
|
+
);
|
|
12415
|
+
const value = ((aligned == null ? void 0 : aligned.style.textAlign) || container.style.textAlign || "").toLowerCase().trim();
|
|
12416
|
+
if (value === "center" || value === "right" || value === "justify") return value;
|
|
12417
|
+
return "left";
|
|
12418
|
+
}
|
|
12419
|
+
function justifyFromTextAlign(align) {
|
|
12420
|
+
if (align === "center") return "center";
|
|
12421
|
+
if (align === "right") return "flex-end";
|
|
12422
|
+
return "flex-start";
|
|
12423
|
+
}
|
|
12393
12424
|
function renderBanner(banner, handlers) {
|
|
12394
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
12425
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
12395
12426
|
const placement = banner.placement || {};
|
|
12396
12427
|
const mode = placement.mode || "overlay";
|
|
12397
12428
|
const position = placement.position || "top";
|
|
@@ -12405,20 +12436,21 @@ function renderBanner(banner, handlers) {
|
|
|
12405
12436
|
const imageVertical = imageAlign((_d = banner.image) == null ? void 0 : _d.verticalAlignment);
|
|
12406
12437
|
const imageHorizontalPosition = ((_e = banner.image) == null ? void 0 : _e.horizontalAlignment) || "center";
|
|
12407
12438
|
const imageVerticalPosition = ((_f = banner.image) == null ? void 0 : _f.verticalAlignment) || "center";
|
|
12439
|
+
const closeColor = imageBanner ? "#ffffff" : color;
|
|
12408
12440
|
const root = el("div", {
|
|
12409
12441
|
boxSizing: "border-box",
|
|
12410
12442
|
fontFamily: "Roboto, sans-serif",
|
|
12411
|
-
fontSize: "
|
|
12443
|
+
fontSize: "14px",
|
|
12412
12444
|
lineHeight: "1.35",
|
|
12413
12445
|
background: bg,
|
|
12414
12446
|
color,
|
|
12415
12447
|
borderRadius: isCard && !imageBanner ? "6px" : "0",
|
|
12416
12448
|
boxShadow: isCard && !imageBanner ? "0 8px 24px rgba(0,0,0,0.22)" : "none",
|
|
12417
|
-
padding: imageBanner ? "0" : isCard ? "12px 24px" : "8px 16px",
|
|
12449
|
+
padding: imageBanner ? "0" : isCard ? "12px 42px 12px 24px" : "8px 42px 8px 16px",
|
|
12418
12450
|
display: "flex",
|
|
12419
12451
|
alignItems: imageBanner ? imageVertical : "flex-start",
|
|
12420
12452
|
justifyContent: "center",
|
|
12421
|
-
gap: imageBanner ? "
|
|
12453
|
+
gap: imageBanner ? "0" : "16px"
|
|
12422
12454
|
});
|
|
12423
12455
|
root.setAttribute("role", isCard ? "dialog" : "region");
|
|
12424
12456
|
root.setAttribute("aria-label", "community banner");
|
|
@@ -12427,12 +12459,12 @@ function renderBanner(banner, handlers) {
|
|
|
12427
12459
|
Object.assign(root.style, {
|
|
12428
12460
|
position: "fixed",
|
|
12429
12461
|
left: "50%",
|
|
12430
|
-
width:
|
|
12431
|
-
maxWidth: imageBanner ? "
|
|
12462
|
+
width: "fit-content",
|
|
12463
|
+
maxWidth: imageBanner ? "70vw" : "min(700px, 80vw)",
|
|
12432
12464
|
height: "auto",
|
|
12433
12465
|
minHeight: imageBanner ? "0" : "80px",
|
|
12434
|
-
maxHeight: "calc(100vh - 300px)",
|
|
12435
|
-
overflowY: "auto",
|
|
12466
|
+
maxHeight: imageBanner ? "70vh" : "calc(100vh - 300px)",
|
|
12467
|
+
overflowY: imageBanner ? "visible" : "auto",
|
|
12436
12468
|
zIndex
|
|
12437
12469
|
});
|
|
12438
12470
|
if (imageBanner) {
|
|
@@ -12473,7 +12505,7 @@ function renderBanner(banner, handlers) {
|
|
|
12473
12505
|
}
|
|
12474
12506
|
const contentWrap = el("div", {
|
|
12475
12507
|
display: "flex",
|
|
12476
|
-
width: imageBanner ? "auto" : "100%",
|
|
12508
|
+
width: imageBanner || isCard ? "auto" : "100%",
|
|
12477
12509
|
maxWidth: "100%",
|
|
12478
12510
|
flexDirection: "column",
|
|
12479
12511
|
gap: imageBanner ? "0" : "12px",
|
|
@@ -12481,16 +12513,19 @@ function renderBanner(banner, handlers) {
|
|
|
12481
12513
|
});
|
|
12482
12514
|
const contentRow = el("div", {
|
|
12483
12515
|
display: "flex",
|
|
12484
|
-
width: "100%",
|
|
12516
|
+
width: imageBanner || isCard ? "auto" : "100%",
|
|
12485
12517
|
justifyContent: imageBanner ? imageHorizontal : "space-between",
|
|
12486
12518
|
alignItems: imageBanner ? imageVertical : "flex-start",
|
|
12487
12519
|
gap: "12px"
|
|
12488
12520
|
});
|
|
12489
12521
|
const content = el("div", {
|
|
12490
|
-
width: imageBanner ? "auto" : "100%",
|
|
12491
|
-
maxWidth: "100%",
|
|
12522
|
+
width: imageBanner || isCard ? "auto" : "100%",
|
|
12523
|
+
maxWidth: imageBanner ? "70vw" : isCard ? "calc(min(700px, 80vw) - 66px)" : "100%",
|
|
12492
12524
|
overflow: "hidden",
|
|
12493
|
-
wordBreak: "
|
|
12525
|
+
wordBreak: "normal",
|
|
12526
|
+
overflowWrap: "anywhere",
|
|
12527
|
+
whiteSpace: "normal",
|
|
12528
|
+
color
|
|
12494
12529
|
});
|
|
12495
12530
|
const imageUrl = ((_g = banner.image) == null ? void 0 : _g.desktopUrl) || ((_h = banner.image) == null ? void 0 : _h.mobileUrl);
|
|
12496
12531
|
if (imageBanner && imageUrl) {
|
|
@@ -12500,12 +12535,17 @@ function renderBanner(banner, handlers) {
|
|
|
12500
12535
|
"img",
|
|
12501
12536
|
{
|
|
12502
12537
|
display: "block",
|
|
12503
|
-
maxWidth: "
|
|
12504
|
-
maxHeight: "
|
|
12538
|
+
maxWidth: "70vw",
|
|
12539
|
+
maxHeight: "70vh",
|
|
12540
|
+
width: "auto",
|
|
12505
12541
|
height: "auto",
|
|
12506
12542
|
objectFit: "contain",
|
|
12543
|
+
objectPosition: imageObjectPosition(
|
|
12544
|
+
(_k = banner.image) == null ? void 0 : _k.horizontalAlignment,
|
|
12545
|
+
(_l = banner.image) == null ? void 0 : _l.verticalAlignment
|
|
12546
|
+
),
|
|
12507
12547
|
cursor: imageLinkUrl ? "pointer" : "",
|
|
12508
|
-
borderRadius: ((
|
|
12548
|
+
borderRadius: ((_m = banner.image) == null ? void 0 : _m.cornerRadius) === "rounded" ? "8px" : "0"
|
|
12509
12549
|
},
|
|
12510
12550
|
{ src: imageUrl, alt: banner.title || "banner" }
|
|
12511
12551
|
);
|
|
@@ -12522,23 +12562,29 @@ function renderBanner(banner, handlers) {
|
|
|
12522
12562
|
} else {
|
|
12523
12563
|
content.innerHTML = sanitizeBannerHtml(banner.text);
|
|
12524
12564
|
styleRichText(content);
|
|
12565
|
+
const textAlign = readTextAlign(content);
|
|
12566
|
+
content.style.textAlign = textAlign;
|
|
12567
|
+
if (isCard) {
|
|
12568
|
+
contentRow.style.justifyContent = justifyFromTextAlign(textAlign);
|
|
12569
|
+
}
|
|
12525
12570
|
}
|
|
12526
|
-
if (!imageBanner && ((
|
|
12571
|
+
if (!imageBanner && ((_n = banner.cta) == null ? void 0 : _n.enabled)) {
|
|
12527
12572
|
const ctaBg = safeColor(
|
|
12528
12573
|
getCtaStyleValue(banner, ["backgroundColor", "buttonColor", "aColor"])
|
|
12529
|
-
) ||
|
|
12574
|
+
) || "#2f6df6";
|
|
12530
12575
|
const ctaColor = safeColor(getCtaStyleValue(banner, ["textColor", "color"])) || "#ffffff";
|
|
12531
12576
|
const btn = el("button", {
|
|
12532
12577
|
cursor: "pointer",
|
|
12533
12578
|
border: "none",
|
|
12534
|
-
borderRadius: "
|
|
12579
|
+
borderRadius: "6px",
|
|
12535
12580
|
height: "36px",
|
|
12536
12581
|
minHeight: "36px",
|
|
12537
12582
|
padding: "0 16px",
|
|
12583
|
+
fontFamily: "Roboto, sans-serif",
|
|
12538
12584
|
fontSize: "12px",
|
|
12539
12585
|
fontWeight: "600",
|
|
12540
12586
|
lineHeight: "20px",
|
|
12541
|
-
|
|
12587
|
+
backgroundColor: ctaBg,
|
|
12542
12588
|
color: ctaColor,
|
|
12543
12589
|
boxSizing: "border-box",
|
|
12544
12590
|
display: "inline-flex",
|
|
@@ -12577,7 +12623,10 @@ function renderBanner(banner, handlers) {
|
|
|
12577
12623
|
}
|
|
12578
12624
|
root.appendChild(contentWrap);
|
|
12579
12625
|
const close = el("button", {
|
|
12580
|
-
|
|
12626
|
+
position: isCard ? "absolute" : "",
|
|
12627
|
+
top: isCard ? imageBanner ? "16px" : "12px" : "",
|
|
12628
|
+
right: isCard ? imageBanner ? "16px" : "12px" : "",
|
|
12629
|
+
marginTop: isCard ? "0" : "8px",
|
|
12581
12630
|
width: "20px",
|
|
12582
12631
|
minWidth: "20px",
|
|
12583
12632
|
height: "20px",
|
|
@@ -12585,7 +12634,7 @@ function renderBanner(banner, handlers) {
|
|
|
12585
12634
|
border: "none",
|
|
12586
12635
|
borderRadius: "50%",
|
|
12587
12636
|
background: "rgba(0,0,0,0.25)",
|
|
12588
|
-
color,
|
|
12637
|
+
color: closeColor,
|
|
12589
12638
|
fontSize: "16px",
|
|
12590
12639
|
lineHeight: "1",
|
|
12591
12640
|
display: "flex",
|
|
@@ -13868,7 +13917,7 @@ class CustomWidget extends BaseWidget {
|
|
|
13868
13917
|
}
|
|
13869
13918
|
}
|
|
13870
13919
|
}
|
|
13871
|
-
console.log(`[rai-widget] v${"1.6.
|
|
13920
|
+
console.log(`[rai-widget] v${"1.6.2"}`);
|
|
13872
13921
|
class StoreWidgetCompat extends StoreWidget {
|
|
13873
13922
|
}
|
|
13874
13923
|
const WIDGET_REGISTRY = [
|
|
@@ -13932,7 +13981,7 @@ function exposePublicApi() {
|
|
|
13932
13981
|
})();
|
|
13933
13982
|
const widget = container == null ? void 0 : container.querySelector(ALL_WIDGET_SELECTOR);
|
|
13934
13983
|
window.ReturningAIWidget = {
|
|
13935
|
-
version: "1.6.
|
|
13984
|
+
version: "1.6.2",
|
|
13936
13985
|
reload: () => (widget == null ? void 0 : widget.reload()) ?? Promise.resolve(),
|
|
13937
13986
|
logout: () => (widget == null ? void 0 : widget.logoutPublic()) ?? Promise.resolve(),
|
|
13938
13987
|
isAuthenticated: () => (widget == null ? void 0 : widget.isAuthenticated()) ?? false,
|