@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-banner.js
CHANGED
|
@@ -1408,6 +1408,7 @@ function sanitizeBannerHtml(html2) {
|
|
|
1408
1408
|
});
|
|
1409
1409
|
}
|
|
1410
1410
|
function resolveCssToken(token) {
|
|
1411
|
+
const normalizedToken = token.startsWith("--") ? token : `--${token}`;
|
|
1411
1412
|
const candidates = [
|
|
1412
1413
|
document.documentElement,
|
|
1413
1414
|
document.body,
|
|
@@ -1429,23 +1430,28 @@ function resolveCssToken(token) {
|
|
|
1429
1430
|
)
|
|
1430
1431
|
].filter(Boolean);
|
|
1431
1432
|
for (const node of candidates) {
|
|
1432
|
-
const value = getComputedStyle(node).getPropertyValue(
|
|
1433
|
+
const value = getComputedStyle(node).getPropertyValue(normalizedToken).trim();
|
|
1434
|
+
if (value) return value;
|
|
1435
|
+
}
|
|
1436
|
+
for (const node of Array.from(document.querySelectorAll("*"))) {
|
|
1437
|
+
const value = getComputedStyle(node).getPropertyValue(normalizedToken).trim();
|
|
1433
1438
|
if (value) return value;
|
|
1434
1439
|
}
|
|
1435
1440
|
return void 0;
|
|
1436
1441
|
}
|
|
1437
1442
|
const safeColor = (v) => {
|
|
1438
1443
|
if (!v) return void 0;
|
|
1439
|
-
|
|
1440
|
-
if (
|
|
1441
|
-
|
|
1442
|
-
|
|
1444
|
+
const value = v.trim();
|
|
1445
|
+
if (/^(#|rgb|hsl)/i.test(value)) return value;
|
|
1446
|
+
if (/^(--)?[a-z0-9-]+$/i.test(value)) {
|
|
1447
|
+
const resolved = resolveCssToken(value);
|
|
1448
|
+
return resolved;
|
|
1443
1449
|
}
|
|
1444
|
-
const varMatch =
|
|
1450
|
+
const varMatch = value.match(/^var\((--[a-z0-9-]+)\)$/i);
|
|
1445
1451
|
if (varMatch) {
|
|
1446
1452
|
const token = varMatch[1];
|
|
1447
1453
|
const resolved = resolveCssToken(token);
|
|
1448
|
-
return resolved
|
|
1454
|
+
return resolved;
|
|
1449
1455
|
}
|
|
1450
1456
|
return void 0;
|
|
1451
1457
|
};
|
|
@@ -1471,6 +1477,11 @@ function imageAlign(pos) {
|
|
|
1471
1477
|
if (pos === "right" || pos === "bottom") return "flex-end";
|
|
1472
1478
|
return "center";
|
|
1473
1479
|
}
|
|
1480
|
+
function imageObjectPosition(horizontal, vertical) {
|
|
1481
|
+
const x = horizontal === "left" ? "left" : horizontal === "right" ? "right" : "center";
|
|
1482
|
+
const y = vertical === "top" ? "top" : vertical === "bottom" ? "bottom" : "center";
|
|
1483
|
+
return `${x} ${y}`;
|
|
1484
|
+
}
|
|
1474
1485
|
function getCtaStyleValue(banner, keys) {
|
|
1475
1486
|
var _a;
|
|
1476
1487
|
const sources = [(_a = banner.cta) == null ? void 0 : _a.style, banner.cta, banner.ctaStyle];
|
|
@@ -1485,19 +1496,26 @@ function getCtaStyleValue(banner, keys) {
|
|
|
1485
1496
|
function styleRichText(container) {
|
|
1486
1497
|
container.querySelectorAll("p").forEach((p) => {
|
|
1487
1498
|
p.style.margin = "0";
|
|
1499
|
+
p.style.whiteSpace = "normal";
|
|
1500
|
+
p.style.overflowWrap = "anywhere";
|
|
1488
1501
|
});
|
|
1489
1502
|
container.querySelectorAll("strong").forEach((strong) => {
|
|
1490
1503
|
strong.style.fontWeight = "700";
|
|
1504
|
+
strong.style.whiteSpace = "normal";
|
|
1491
1505
|
});
|
|
1492
1506
|
container.querySelectorAll("em").forEach((em) => {
|
|
1493
1507
|
em.style.fontStyle = "italic";
|
|
1508
|
+
em.style.whiteSpace = "normal";
|
|
1494
1509
|
});
|
|
1495
1510
|
container.querySelectorAll("u").forEach((u) => {
|
|
1496
1511
|
u.style.textDecoration = "underline";
|
|
1512
|
+
u.style.whiteSpace = "normal";
|
|
1497
1513
|
});
|
|
1498
1514
|
container.querySelectorAll("a").forEach((a) => {
|
|
1499
1515
|
a.style.color = "#3b82f6";
|
|
1500
1516
|
a.style.textDecoration = "underline";
|
|
1517
|
+
a.style.whiteSpace = "normal";
|
|
1518
|
+
a.style.overflowWrap = "anywhere";
|
|
1501
1519
|
if (a.getAttribute("target") === "_blank") {
|
|
1502
1520
|
a.setAttribute("rel", "noopener noreferrer");
|
|
1503
1521
|
}
|
|
@@ -1507,8 +1525,21 @@ function styleRichText(container) {
|
|
|
1507
1525
|
img.style.height = "auto";
|
|
1508
1526
|
});
|
|
1509
1527
|
}
|
|
1528
|
+
function readTextAlign(container) {
|
|
1529
|
+
const aligned = container.querySelector(
|
|
1530
|
+
'[style*="text-align"]'
|
|
1531
|
+
);
|
|
1532
|
+
const value = ((aligned == null ? void 0 : aligned.style.textAlign) || container.style.textAlign || "").toLowerCase().trim();
|
|
1533
|
+
if (value === "center" || value === "right" || value === "justify") return value;
|
|
1534
|
+
return "left";
|
|
1535
|
+
}
|
|
1536
|
+
function justifyFromTextAlign(align) {
|
|
1537
|
+
if (align === "center") return "center";
|
|
1538
|
+
if (align === "right") return "flex-end";
|
|
1539
|
+
return "flex-start";
|
|
1540
|
+
}
|
|
1510
1541
|
function renderBanner(banner, handlers) {
|
|
1511
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1542
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1512
1543
|
const placement = banner.placement || {};
|
|
1513
1544
|
const mode = placement.mode || "overlay";
|
|
1514
1545
|
const position = placement.position || "top";
|
|
@@ -1522,20 +1553,21 @@ function renderBanner(banner, handlers) {
|
|
|
1522
1553
|
const imageVertical = imageAlign((_d = banner.image) == null ? void 0 : _d.verticalAlignment);
|
|
1523
1554
|
const imageHorizontalPosition = ((_e = banner.image) == null ? void 0 : _e.horizontalAlignment) || "center";
|
|
1524
1555
|
const imageVerticalPosition = ((_f = banner.image) == null ? void 0 : _f.verticalAlignment) || "center";
|
|
1556
|
+
const closeColor = imageBanner ? "#ffffff" : color;
|
|
1525
1557
|
const root = el("div", {
|
|
1526
1558
|
boxSizing: "border-box",
|
|
1527
1559
|
fontFamily: "Roboto, sans-serif",
|
|
1528
|
-
fontSize: "
|
|
1560
|
+
fontSize: "14px",
|
|
1529
1561
|
lineHeight: "1.35",
|
|
1530
1562
|
background: bg,
|
|
1531
1563
|
color,
|
|
1532
1564
|
borderRadius: isCard && !imageBanner ? "6px" : "0",
|
|
1533
1565
|
boxShadow: isCard && !imageBanner ? "0 8px 24px rgba(0,0,0,0.22)" : "none",
|
|
1534
|
-
padding: imageBanner ? "0" : isCard ? "12px 24px" : "8px 16px",
|
|
1566
|
+
padding: imageBanner ? "0" : isCard ? "12px 42px 12px 24px" : "8px 42px 8px 16px",
|
|
1535
1567
|
display: "flex",
|
|
1536
1568
|
alignItems: imageBanner ? imageVertical : "flex-start",
|
|
1537
1569
|
justifyContent: "center",
|
|
1538
|
-
gap: imageBanner ? "
|
|
1570
|
+
gap: imageBanner ? "0" : "16px"
|
|
1539
1571
|
});
|
|
1540
1572
|
root.setAttribute("role", isCard ? "dialog" : "region");
|
|
1541
1573
|
root.setAttribute("aria-label", "community banner");
|
|
@@ -1544,12 +1576,12 @@ function renderBanner(banner, handlers) {
|
|
|
1544
1576
|
Object.assign(root.style, {
|
|
1545
1577
|
position: "fixed",
|
|
1546
1578
|
left: "50%",
|
|
1547
|
-
width:
|
|
1548
|
-
maxWidth: imageBanner ? "
|
|
1579
|
+
width: "fit-content",
|
|
1580
|
+
maxWidth: imageBanner ? "70vw" : "min(700px, 80vw)",
|
|
1549
1581
|
height: "auto",
|
|
1550
1582
|
minHeight: imageBanner ? "0" : "80px",
|
|
1551
|
-
maxHeight: "calc(100vh - 300px)",
|
|
1552
|
-
overflowY: "auto",
|
|
1583
|
+
maxHeight: imageBanner ? "70vh" : "calc(100vh - 300px)",
|
|
1584
|
+
overflowY: imageBanner ? "visible" : "auto",
|
|
1553
1585
|
zIndex
|
|
1554
1586
|
});
|
|
1555
1587
|
if (imageBanner) {
|
|
@@ -1590,7 +1622,7 @@ function renderBanner(banner, handlers) {
|
|
|
1590
1622
|
}
|
|
1591
1623
|
const contentWrap = el("div", {
|
|
1592
1624
|
display: "flex",
|
|
1593
|
-
width: imageBanner ? "auto" : "100%",
|
|
1625
|
+
width: imageBanner || isCard ? "auto" : "100%",
|
|
1594
1626
|
maxWidth: "100%",
|
|
1595
1627
|
flexDirection: "column",
|
|
1596
1628
|
gap: imageBanner ? "0" : "12px",
|
|
@@ -1598,16 +1630,19 @@ function renderBanner(banner, handlers) {
|
|
|
1598
1630
|
});
|
|
1599
1631
|
const contentRow = el("div", {
|
|
1600
1632
|
display: "flex",
|
|
1601
|
-
width: "100%",
|
|
1633
|
+
width: imageBanner || isCard ? "auto" : "100%",
|
|
1602
1634
|
justifyContent: imageBanner ? imageHorizontal : "space-between",
|
|
1603
1635
|
alignItems: imageBanner ? imageVertical : "flex-start",
|
|
1604
1636
|
gap: "12px"
|
|
1605
1637
|
});
|
|
1606
1638
|
const content = el("div", {
|
|
1607
|
-
width: imageBanner ? "auto" : "100%",
|
|
1608
|
-
maxWidth: "100%",
|
|
1639
|
+
width: imageBanner || isCard ? "auto" : "100%",
|
|
1640
|
+
maxWidth: imageBanner ? "70vw" : isCard ? "calc(min(700px, 80vw) - 66px)" : "100%",
|
|
1609
1641
|
overflow: "hidden",
|
|
1610
|
-
wordBreak: "
|
|
1642
|
+
wordBreak: "normal",
|
|
1643
|
+
overflowWrap: "anywhere",
|
|
1644
|
+
whiteSpace: "normal",
|
|
1645
|
+
color
|
|
1611
1646
|
});
|
|
1612
1647
|
const imageUrl = ((_g = banner.image) == null ? void 0 : _g.desktopUrl) || ((_h = banner.image) == null ? void 0 : _h.mobileUrl);
|
|
1613
1648
|
if (imageBanner && imageUrl) {
|
|
@@ -1617,12 +1652,17 @@ function renderBanner(banner, handlers) {
|
|
|
1617
1652
|
"img",
|
|
1618
1653
|
{
|
|
1619
1654
|
display: "block",
|
|
1620
|
-
maxWidth: "
|
|
1621
|
-
maxHeight: "
|
|
1655
|
+
maxWidth: "70vw",
|
|
1656
|
+
maxHeight: "70vh",
|
|
1657
|
+
width: "auto",
|
|
1622
1658
|
height: "auto",
|
|
1623
1659
|
objectFit: "contain",
|
|
1660
|
+
objectPosition: imageObjectPosition(
|
|
1661
|
+
(_k = banner.image) == null ? void 0 : _k.horizontalAlignment,
|
|
1662
|
+
(_l = banner.image) == null ? void 0 : _l.verticalAlignment
|
|
1663
|
+
),
|
|
1624
1664
|
cursor: imageLinkUrl ? "pointer" : "",
|
|
1625
|
-
borderRadius: ((
|
|
1665
|
+
borderRadius: ((_m = banner.image) == null ? void 0 : _m.cornerRadius) === "rounded" ? "8px" : "0"
|
|
1626
1666
|
},
|
|
1627
1667
|
{ src: imageUrl, alt: banner.title || "banner" }
|
|
1628
1668
|
);
|
|
@@ -1639,23 +1679,29 @@ function renderBanner(banner, handlers) {
|
|
|
1639
1679
|
} else {
|
|
1640
1680
|
content.innerHTML = sanitizeBannerHtml(banner.text);
|
|
1641
1681
|
styleRichText(content);
|
|
1682
|
+
const textAlign = readTextAlign(content);
|
|
1683
|
+
content.style.textAlign = textAlign;
|
|
1684
|
+
if (isCard) {
|
|
1685
|
+
contentRow.style.justifyContent = justifyFromTextAlign(textAlign);
|
|
1686
|
+
}
|
|
1642
1687
|
}
|
|
1643
|
-
if (!imageBanner && ((
|
|
1688
|
+
if (!imageBanner && ((_n = banner.cta) == null ? void 0 : _n.enabled)) {
|
|
1644
1689
|
const ctaBg = safeColor(
|
|
1645
1690
|
getCtaStyleValue(banner, ["backgroundColor", "buttonColor", "aColor"])
|
|
1646
|
-
) ||
|
|
1691
|
+
) || "#2f6df6";
|
|
1647
1692
|
const ctaColor = safeColor(getCtaStyleValue(banner, ["textColor", "color"])) || "#ffffff";
|
|
1648
1693
|
const btn = el("button", {
|
|
1649
1694
|
cursor: "pointer",
|
|
1650
1695
|
border: "none",
|
|
1651
|
-
borderRadius: "
|
|
1696
|
+
borderRadius: "6px",
|
|
1652
1697
|
height: "36px",
|
|
1653
1698
|
minHeight: "36px",
|
|
1654
1699
|
padding: "0 16px",
|
|
1700
|
+
fontFamily: "Roboto, sans-serif",
|
|
1655
1701
|
fontSize: "12px",
|
|
1656
1702
|
fontWeight: "600",
|
|
1657
1703
|
lineHeight: "20px",
|
|
1658
|
-
|
|
1704
|
+
backgroundColor: ctaBg,
|
|
1659
1705
|
color: ctaColor,
|
|
1660
1706
|
boxSizing: "border-box",
|
|
1661
1707
|
display: "inline-flex",
|
|
@@ -1694,7 +1740,10 @@ function renderBanner(banner, handlers) {
|
|
|
1694
1740
|
}
|
|
1695
1741
|
root.appendChild(contentWrap);
|
|
1696
1742
|
const close = el("button", {
|
|
1697
|
-
|
|
1743
|
+
position: isCard ? "absolute" : "",
|
|
1744
|
+
top: isCard ? imageBanner ? "16px" : "12px" : "",
|
|
1745
|
+
right: isCard ? imageBanner ? "16px" : "12px" : "",
|
|
1746
|
+
marginTop: isCard ? "0" : "8px",
|
|
1698
1747
|
width: "20px",
|
|
1699
1748
|
minWidth: "20px",
|
|
1700
1749
|
height: "20px",
|
|
@@ -1702,7 +1751,7 @@ function renderBanner(banner, handlers) {
|
|
|
1702
1751
|
border: "none",
|
|
1703
1752
|
borderRadius: "50%",
|
|
1704
1753
|
background: "rgba(0,0,0,0.25)",
|
|
1705
|
-
color,
|
|
1754
|
+
color: closeColor,
|
|
1706
1755
|
fontSize: "16px",
|
|
1707
1756
|
lineHeight: "1",
|
|
1708
1757
|
display: "flex",
|
|
@@ -1878,7 +1927,7 @@ class BannerRuntime extends HTMLElement {
|
|
|
1878
1927
|
this.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));
|
|
1879
1928
|
}
|
|
1880
1929
|
}
|
|
1881
|
-
console.log(`[rai-banner] v${"1.6.
|
|
1930
|
+
console.log(`[rai-banner] v${"1.6.2"}`);
|
|
1882
1931
|
if (typeof customElements !== "undefined" && !customElements.get("rai-banner")) {
|
|
1883
1932
|
customElements.define("rai-banner", BannerRuntime);
|
|
1884
1933
|
}
|