@saasquatch/squatch-js 2.8.2-2 → 2.8.2-21

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/squatch.js CHANGED
@@ -1110,393 +1110,32 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1110
1110
  setTimeout(resolve, duration);
1111
1111
  });
1112
1112
  }
1113
- const getSkeleton = ({
1114
- height = "500px",
1115
- skeletonBackgroundColor = "#e0e0e0",
1116
- skeletonShimmerColor = "#f5f5f5",
1117
- borderColor = "#ccc"
1118
- }) => {
1119
- return `
1120
- <style>
1121
- * {
1122
- box-sizing: border-box;
1123
- padding: 0;
1124
- margin: 0;
1125
- }
1126
-
1127
- .widget-container {
1128
- background: white;
1129
- width: 100%;
1130
- max-width: 900px;
1131
- padding: 40px;
1132
- border-radius: 12px;
1133
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
1134
- box-sizing: border-box;
1135
- }
1136
-
1137
- @keyframes shimmer {
1138
- 0% {
1139
- background-position: -100% 0;
1140
- }
1141
- 100% {
1142
- background-position: 100% 0;
1143
- }
1144
- }
1145
-
1146
- .skeleton {
1147
- background: ${skeletonBackgroundColor};
1148
- background: linear-gradient(
1149
- 90deg,
1150
- ${skeletonBackgroundColor} 25%,
1151
- ${skeletonShimmerColor} 50%,
1152
- ${skeletonBackgroundColor} 75%
1153
- );
1154
- background-size: 200% 100%;
1155
- animation: shimmer 1.5s infinite linear;
1156
- border-radius: 6px;
1157
- margin-bottom: 12px;
1158
- }
1159
-
1160
- .sk-title-lg {
1161
- height: 36px;
1162
- width: 50%;
1163
- margin-bottom: 16px;
1164
- }
1165
- .sk-title-md {
1166
- height: 28px;
1167
- width: 30%;
1168
- margin-bottom: 20px;
1169
- margin-top: 40px;
1170
- }
1171
- .sk-text {
1172
- height: 16px;
1173
- width: 80%;
1174
- margin-bottom: 8px;
1175
- }
1176
- .sk-text-short {
1177
- width: 40%;
1178
- }
1179
- .sk-label {
1180
- height: 14px;
1181
- width: 25%;
1182
- margin-bottom: 10px;
1183
- }
1184
-
1185
- .hero-section {
1186
- display: flex;
1187
- gap: 40px;
1188
- margin-bottom: 40px;
1189
- border-bottom: 1px solid ${borderColor};
1190
- padding-bottom: 40px;
1191
- flex-direction: row;
1192
- }
1193
- .hero-content {
1194
- flex: 1;
1195
- display: flex;
1196
- flex-direction: column;
1197
- justify-content: center;
1198
- }
1199
- .hero-image {
1200
- flex: 1;
1201
- height: 300px;
1202
- border-radius: 12px;
1203
- }
1204
-
1205
- .share-section {
1206
- margin-bottom: 40px;
1207
- }
1208
- .sk-input {
1209
- height: 50px;
1210
- width: 100%;
1211
- border-radius: 8px;
1212
- margin-bottom: 16px;
1213
- }
1214
- .social-buttons {
1215
- display: flex;
1216
- gap: 12px;
1217
- }
1218
- .sk-btn-social {
1219
- flex: 1;
1220
- height: 50px;
1221
- border-radius: 8px;
1222
- }
1223
-
1224
- .stats-section {
1225
- display: flex;
1226
- gap: 24px;
1227
- margin-bottom: 40px;
1228
- padding: 30px 0;
1229
- border-top: 1px solid ${borderColor};
1230
- border-bottom: 1px solid ${borderColor};
1231
- }
1232
- .stat-card {
1233
- flex: 1;
1234
- display: flex;
1235
- flex-direction: column;
1236
- align-items: center;
1237
- }
1238
- .stat-divider {
1239
- padding-left: 24px;
1240
- }
1241
-
1242
- .sk-stat-num {
1243
- height: 48px;
1244
- width: 120px;
1245
- margin-bottom: 8px;
1246
- }
1247
- .sk-stat-label {
1248
- height: 18px;
1249
- width: 80px;
1250
- }
1251
-
1252
- .table-header {
1253
- display: flex;
1254
- gap: 16px;
1255
- margin-bottom: 16px;
1256
- }
1257
- .sk-th {
1258
- height: 16px;
1259
- }
1260
- .table-row {
1261
- display: flex;
1262
- align-items: center;
1263
- gap: 16px;
1264
- padding: 16px 0;
1265
- border-bottom: 1px solid ${borderColor};
1266
- }
1267
-
1268
- .col-user {
1269
- flex: 2;
1270
- }
1271
- .col-status {
1272
- flex: 1;
1273
- }
1274
- .col-reward {
1275
- flex: 2;
1276
- }
1277
- .col-date {
1278
- flex: 1;
1279
- }
1280
-
1281
- .sk-badge {
1282
- height: 28px;
1283
- width: 90px;
1284
- border-radius: 14px;
1285
- }
1286
- .sk-reward-block {
1287
- height: 36px;
1288
- width: 100%;
1289
- border-radius: 6px;
1290
- }
1291
-
1292
- .pagination {
1293
- display: flex;
1294
- justify-content: flex-end;
1295
- gap: 8px;
1296
- margin-top: 24px;
1297
- }
1298
- .sk-btn-page {
1299
- height: 36px;
1300
- width: 64px;
1301
- border-radius: 6px;
1302
- margin-bottom: 0;
1303
- }
1304
-
1305
- @media (max-width: 768px) {
1306
- body {
1307
- padding: 20px;
1308
- }
1309
- .widget-container {
1310
- padding: 24px;
1311
- }
1312
-
1313
- .hero-section {
1314
- flex-direction: column-reverse;
1315
- gap: 24px;
1316
- }
1317
- .hero-image {
1318
- height: 220px;
1319
- width: 100%;
1320
- }
1321
- .sk-title-lg {
1322
- width: 80%;
1323
- }
1324
-
1325
- .col-date {
1326
- display: none;
1327
- }
1328
- }
1329
-
1330
- @media (max-width: 480px) {
1331
- body {
1332
- padding: 10px;
1333
- }
1334
- .widget-container {
1335
- padding: 16px;
1336
- }
1337
-
1338
- .sk-stat-num {
1339
- width: 80px;
1340
- height: 40px;
1341
- }
1342
-
1343
- .col-reward {
1344
- display: none;
1345
- }
1346
-
1347
- .col-user {
1348
- flex: 3;
1349
- }
1350
- .col-status {
1351
- flex: 2;
1352
- display: flex;
1353
- justify-content: flex-end;
1354
- }
1355
- }
1356
- </style>
1357
-
1358
- <div class="widget-container">
1359
- <div class="hero-section">
1360
- <div class="hero-content">
1361
- <div class="skeleton sk-title-lg"></div>
1362
- <div class="skeleton sk-text"></div>
1363
- <div class="skeleton sk-text sk-text-short"></div>
1364
- </div>
1365
- <div class="skeleton hero-image"></div>
1366
- </div>
1367
-
1368
- <div class="share-section">
1369
- <div class="skeleton sk-label"></div>
1370
- <div class="skeleton sk-input"></div>
1371
- <div class="social-buttons">
1372
- <div class="skeleton sk-btn-social"></div>
1373
- <div class="skeleton sk-btn-social"></div>
1374
- <div class="skeleton sk-btn-social"></div>
1375
- <div class="skeleton sk-btn-social"></div>
1376
- </div>
1377
- </div>
1378
-
1379
- <div
1380
- class="skeleton sk-title-md"
1381
- style="margin-top: 0; width: 30%; margin-left: auto; margin-right: auto"
1382
- ></div>
1383
- <div
1384
- class="skeleton sk-text"
1385
- style="width: 60%; margin-left: auto; margin-right: auto"
1386
- ></div>
1387
-
1388
- <div class="stats-section">
1389
- <div class="stat-card">
1390
- <div class="skeleton sk-stat-num"></div>
1391
- <div class="skeleton sk-stat-label"></div>
1392
- </div>
1393
- <div class="stat-card stat-divider">
1394
- <div class="skeleton sk-stat-num"></div>
1395
- <div class="skeleton sk-stat-label"></div>
1396
- </div>
1397
- </div>
1398
-
1399
- <div class="skeleton sk-title-md"></div>
1400
-
1401
- <div class="table-header">
1402
- <div class="skeleton sk-th col-user"></div>
1403
- <div class="skeleton sk-th col-status"></div>
1404
- <div class="skeleton sk-th col-reward"></div>
1405
- <div class="skeleton sk-th col-date"></div>
1406
- </div>
1407
-
1408
- <div class="table-row">
1409
- <div class="col-user">
1410
- <div class="skeleton sk-text" style="width: 70%; margin: 0"></div>
1411
- </div>
1412
- <div class="col-status">
1413
- <div class="skeleton sk-badge" style="margin: 0"></div>
1414
- </div>
1415
- <div class="col-reward">
1416
- <div class="skeleton sk-reward-block" style="margin: 0"></div>
1417
- </div>
1418
- <div class="col-date">
1419
- <div class="skeleton sk-text" style="width: 80%; margin: 0"></div>
1420
- </div>
1421
- </div>
1422
- <div class="table-row">
1423
- <div class="col-user">
1424
- <div class="skeleton sk-text" style="width: 60%; margin: 0"></div>
1425
- </div>
1426
- <div class="col-status">
1427
- <div class="skeleton sk-badge" style="margin: 0"></div>
1428
- </div>
1429
- <div class="col-reward">
1430
- <div class="skeleton sk-reward-block" style="margin: 0"></div>
1431
- </div>
1432
- <div class="col-date">
1433
- <div class="skeleton sk-text" style="width: 80%; margin: 0"></div>
1434
- </div>
1435
- </div>
1436
- <div class="table-row">
1437
- <div class="col-user">
1438
- <div class="skeleton sk-text" style="width: 75%; margin: 0"></div>
1439
- </div>
1440
- <div class="col-status">
1441
- <div class="skeleton sk-badge" style="margin: 0"></div>
1442
- </div>
1443
- <div class="col-reward">
1444
- <div class="skeleton sk-reward-block" style="margin: 0"></div>
1445
- </div>
1446
- <div class="col-date">
1447
- <div class="skeleton sk-text" style="width: 80%; margin: 0"></div>
1448
- </div>
1449
- </div>
1450
-
1451
- <div class="pagination">
1452
- <div class="skeleton sk-btn-page"></div>
1453
- <div class="skeleton sk-btn-page"></div>
1454
- </div>
1455
- </div>
1456
- `;
1457
- };
1458
1113
  const _log$7 = browserExports.debug("squatch-js:EMBEDwidget");
1459
1114
  class EmbedWidget extends Widget {
1460
1115
  constructor(params, container) {
1461
1116
  super(params);
1462
1117
  __publicField(this, "show", this.open);
1463
1118
  __publicField(this, "hide", this.close);
1464
- if (container) this.container = container;
1119
+ if (container) {
1120
+ this.container = container;
1121
+ }
1465
1122
  }
1466
1123
  async load() {
1467
1124
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1468
- const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1469
- const initialHeight = brandingConfig == null ? void 0 : brandingConfig.loadingHeight;
1470
- const skeletonBackgroundColor = (_d = (_c = brandingConfig == null ? void 0 : brandingConfig.color) == null ? void 0 : _c.loadingSkeleton) == null ? void 0 : _d.background;
1471
- const skeletonShimmerColor = (_f = (_e = brandingConfig == null ? void 0 : brandingConfig.color) == null ? void 0 : _e.loadingSkeleton) == null ? void 0 : _f.animationBackground;
1472
- const borderColor = (_g = brandingConfig == null ? void 0 : brandingConfig.border) == null ? void 0 : _g.borderColor;
1473
- const sizes = (_h = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _h.embeddedWidgets;
1125
+ const brandingConfig2 = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1126
+ const initialHeight = brandingConfig2 == null ? void 0 : brandingConfig2.loadingHeight;
1127
+ (_d = (_c = brandingConfig2 == null ? void 0 : brandingConfig2.color) == null ? void 0 : _c.loadingSkeleton) == null ? void 0 : _d.background;
1128
+ (_f = (_e = brandingConfig2 == null ? void 0 : brandingConfig2.color) == null ? void 0 : _e.loadingSkeleton) == null ? void 0 : _f.animationBackground;
1129
+ (_g = brandingConfig2 == null ? void 0 : brandingConfig2.border) == null ? void 0 : _g.borderColor;
1130
+ const sizes = (_h = brandingConfig2 == null ? void 0 : brandingConfig2.widgetSize) == null ? void 0 : _h.embeddedWidgets;
1474
1131
  const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "";
1475
1132
  const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "";
1476
- console.log({
1477
- brandingConfig,
1478
- initialHeight,
1479
- widgetConfig: this.context.widgetConfig
1480
- });
1481
- const skeletonHTML = getSkeleton({
1482
- height: initialHeight,
1483
- skeletonBackgroundColor,
1484
- skeletonShimmerColor,
1485
- borderColor
1486
- });
1487
- const skeletonContainer = document.createElement("div");
1488
- skeletonContainer.innerHTML = skeletonHTML;
1489
1133
  const frame = this._createFrame({
1490
1134
  minWidth,
1491
1135
  maxWidth,
1492
1136
  initialHeight
1493
1137
  });
1494
1138
  const element = this._findElement();
1495
- frame.style.display = "none";
1496
- const injectContents = (target) => {
1497
- target.appendChild(skeletonContainer);
1498
- target.appendChild(frame);
1499
- };
1500
1139
  if ((_i = this.context) == null ? void 0 : _i.container) {
1501
1140
  element.style.visibility = "hidden";
1502
1141
  element.style.height = "0";
@@ -1507,16 +1146,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1507
1146
  if (((_j = element.shadowRoot.lastChild) == null ? void 0 : _j.nodeName) === "IFRAME") {
1508
1147
  element.shadowRoot.replaceChild(frame, element.shadowRoot.lastChild);
1509
1148
  } else {
1510
- injectContents(element.shadowRoot);
1149
+ element.shadowRoot.appendChild(frame);
1511
1150
  }
1512
1151
  } else if (element.firstChild) {
1513
- element.innerHTML = "";
1514
- injectContents(element);
1152
+ element.replaceChild(frame, element.firstChild);
1515
1153
  } else {
1516
- injectContents(element);
1154
+ element.appendChild(frame);
1517
1155
  }
1518
1156
  } else if (!element.firstChild || element.firstChild.nodeName === "#text") {
1519
- injectContents(element);
1157
+ element.appendChild(frame);
1520
1158
  }
1521
1159
  const { contentWindow } = frame;
1522
1160
  if (!contentWindow) {
@@ -1524,16 +1162,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1524
1162
  }
1525
1163
  const frameDoc = contentWindow.document;
1526
1164
  frameDoc.open();
1527
- console.log({ content: this.content, context: this.context, this: this });
1528
1165
  const domain = this.widgetApi.domain;
1529
1166
  frameDoc.write(`
1530
- ${((_k = brandingConfig == null ? void 0 : brandingConfig.main) == null ? void 0 : _k.brandFont) && `
1167
+ ${((_k = brandingConfig2 == null ? void 0 : brandingConfig2.main) == null ? void 0 : _k.brandFont) ? `
1531
1168
  <link rel="preconnect" href="https://fast${domain === "https://staging.referralsaasquatch.com" && "-staging"}.ssqt.io">
1532
1169
  <link rel="preconnect" href="https://fonts.gstatic.com">
1533
1170
  <link rel="preconnect" href="https://fonts.googleapis.com">
1534
1171
  <link rel="preload" href="https://fonts.googleapis.com/css2?family=${encodeURIComponent(
1535
- (_l = brandingConfig == null ? void 0 : brandingConfig.main) == null ? void 0 : _l.brandFont
1536
- )}">`}
1172
+ (_l = brandingConfig2 == null ? void 0 : brandingConfig2.main) == null ? void 0 : _l.brandFont
1173
+ )}" as="style">` : ""}
1537
1174
  <script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>
1538
1175
  <style data-styles>
1539
1176
  html { visibility:hidden;}
@@ -1543,10 +1180,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1543
1180
  `);
1544
1181
  frameDoc.close();
1545
1182
  domready(frameDoc, async () => {
1546
- if (skeletonContainer && skeletonContainer.parentNode) {
1547
- skeletonContainer.parentNode.removeChild(skeletonContainer);
1548
- }
1549
- frame.style.display = "block";
1550
1183
  const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
1551
1184
  frame.height = initialHeight || frameDoc.body.scrollHeight;
1552
1185
  console.log({ height: frameDoc.body.scrollHeight });
@@ -1648,8 +1281,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1648
1281
  _createPopupDialog() {
1649
1282
  var _a2, _b, _c;
1650
1283
  const dialog = document.createElement("dialog");
1651
- const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1652
- const sizes = (_c = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _c.popupWidgets;
1284
+ const brandingConfig2 = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1285
+ const sizes = (_c = brandingConfig2 == null ? void 0 : brandingConfig2.widgetSize) == null ? void 0 : _c.popupWidgets;
1653
1286
  const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "auto";
1654
1287
  const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "500px";
1655
1288
  dialog.id = this.id;
@@ -2112,125 +1745,470 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2112
1745
  [prop]: isDeep(prop) ? deepMerge(target[prop], source[prop]) : source[prop]
2113
1746
  })).reduce((a, b) => ({ ...a, ...b }), {});
2114
1747
  return {
2115
- ...target,
2116
- ...replaced
1748
+ ...target,
1749
+ ...replaced
1750
+ };
1751
+ };
1752
+ function b64decode(input) {
1753
+ const binary = atob(input.replace(/_/g, "/").replace(/-/g, "+"));
1754
+ const bytes = new Uint8Array(binary.length);
1755
+ for (let i = 0; i < binary.length; i++) {
1756
+ bytes[i] = binary.charCodeAt(i);
1757
+ }
1758
+ return new TextDecoder("utf8").decode(bytes);
1759
+ }
1760
+ function b64encode(input) {
1761
+ const encodedInput = new TextEncoder().encode(input);
1762
+ const binary = Array.from(
1763
+ encodedInput,
1764
+ (byte) => String.fromCodePoint(byte)
1765
+ ).join("");
1766
+ return btoa(binary).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
1767
+ }
1768
+ function getTopDomain() {
1769
+ var i, h, weird_cookie = "weird_get_top_level_domain=cookie", hostname = document.location.hostname.split(".");
1770
+ for (i = hostname.length - 1; i >= 0; i--) {
1771
+ h = hostname.slice(i).join(".");
1772
+ document.cookie = weird_cookie + ";domain=." + h + ";";
1773
+ if (document.cookie.indexOf(weird_cookie) > -1) {
1774
+ document.cookie = weird_cookie.split("=")[0] + "=;domain=." + h + ";expires=Thu, 01 Jan 1970 00:00:01 GMT;";
1775
+ return h;
1776
+ }
1777
+ }
1778
+ }
1779
+ function _pushCookie() {
1780
+ const queryString = window.location.search;
1781
+ const urlParams = new URLSearchParams(queryString);
1782
+ const refParam = urlParams.get("_saasquatch") || "";
1783
+ if (refParam) {
1784
+ let paramsJSON = "", existingCookie = "", reEncodedCookie = "";
1785
+ try {
1786
+ paramsJSON = JSON.parse(b64decode(refParam));
1787
+ } catch (error) {
1788
+ _log$4("Unable to decode params", error);
1789
+ return;
1790
+ }
1791
+ try {
1792
+ existingCookie = JSON.parse(b64decode(api$1.get("_saasquatch")));
1793
+ _log$4("existing cookie", existingCookie);
1794
+ } catch (error) {
1795
+ _log$4("Unable to retrieve cookie", error);
1796
+ }
1797
+ try {
1798
+ const domain = getTopDomain();
1799
+ _log$4("domain retrieved:", domain);
1800
+ if (existingCookie) {
1801
+ const newCookie = deepMerge(existingCookie, paramsJSON);
1802
+ reEncodedCookie = b64encode(JSON.stringify(newCookie));
1803
+ _log$4("cookie to store:", newCookie);
1804
+ } else {
1805
+ reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
1806
+ _log$4("cookie to store:", paramsJSON);
1807
+ }
1808
+ api$1.set("_saasquatch", reEncodedCookie, {
1809
+ expires: 365,
1810
+ secure: false,
1811
+ sameSite: "Lax",
1812
+ domain,
1813
+ path: "/"
1814
+ });
1815
+ } catch (error) {
1816
+ _log$4("Unable to set cookie", error);
1817
+ }
1818
+ }
1819
+ }
1820
+ const _log$3 = browserExports.debug("squatch-js");
1821
+ function _getAutoConfig() {
1822
+ var _a2;
1823
+ const queryString = window.location.search;
1824
+ const urlParams = new URLSearchParams(queryString);
1825
+ const refParam = urlParams.get("_saasquatchExtra") || "";
1826
+ if (!refParam) {
1827
+ _log$3("No _saasquatchExtra param");
1828
+ return;
1829
+ }
1830
+ const config = validateConfig({
1831
+ tenantAlias: "UNKNOWN"
1832
+ });
1833
+ if (!config.domain) {
1834
+ _log$3("domain must be provided in config to use _saasquatchExtra");
1835
+ return;
1836
+ }
1837
+ let raw;
1838
+ try {
1839
+ raw = JSON.parse(b64decode(refParam));
1840
+ } catch (e) {
1841
+ _log$3("Unable to decode _saasquatchExtra config");
1842
+ return;
1843
+ }
1844
+ function normalizeDomain(domain) {
1845
+ return domain.replace(/^https?:\/\//, "");
1846
+ }
1847
+ const normalizedDomain = normalizeDomain(config.domain);
1848
+ const tenantAlias = Object.keys((raw == null ? void 0 : raw[normalizedDomain]) || {})[0];
1849
+ const widgetConfig = (_a2 = raw == null ? void 0 : raw[normalizedDomain]) == null ? void 0 : _a2[tenantAlias];
1850
+ if (!widgetConfig) {
1851
+ _log$3("_saasquatchExtra did not have an expected structure");
1852
+ return void 0;
1853
+ }
1854
+ const { autoPopupWidgetType, ...rest } = widgetConfig;
1855
+ return {
1856
+ widgetConfig: {
1857
+ widgetType: autoPopupWidgetType,
1858
+ displayOnLoad: true,
1859
+ ...rest
1860
+ },
1861
+ squatchConfig: {
1862
+ ...config,
1863
+ tenantAlias
1864
+ }
2117
1865
  };
1866
+ }
1867
+ const getSkeleton = ({
1868
+ height = "500px",
1869
+ skeletonBackgroundColor = "#e0e0e0",
1870
+ skeletonShimmerColor = "#f5f5f5",
1871
+ borderColor = "#ccc"
1872
+ }) => {
1873
+ return `
1874
+ <style>
1875
+ * {
1876
+ box-sizing: border-box;
1877
+ padding: 0;
1878
+ margin: 0;
1879
+ }
1880
+
1881
+ .widget-container {
1882
+ background: white;
1883
+ width: 100%;
1884
+ max-width: 900px;
1885
+ padding: 40px;
1886
+ border-radius: 12px;
1887
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
1888
+ box-sizing: border-box;
1889
+ }
1890
+
1891
+ @keyframes shimmer {
1892
+ 0% {
1893
+ background-position: -100% 0;
1894
+ }
1895
+ 100% {
1896
+ background-position: 100% 0;
1897
+ }
1898
+ }
1899
+
1900
+ .skeleton {
1901
+ background: ${skeletonBackgroundColor};
1902
+ background: linear-gradient(
1903
+ 90deg,
1904
+ ${skeletonBackgroundColor} 25%,
1905
+ ${skeletonShimmerColor} 50%,
1906
+ ${skeletonBackgroundColor} 75%
1907
+ );
1908
+ background-size: 200% 100%;
1909
+ animation: shimmer 1.5s infinite linear;
1910
+ border-radius: 6px;
1911
+ margin-bottom: 12px;
1912
+ }
1913
+
1914
+ .sk-title-lg {
1915
+ height: 36px;
1916
+ width: 50%;
1917
+ margin-bottom: 16px;
1918
+ }
1919
+ .sk-title-md {
1920
+ height: 28px;
1921
+ width: 30%;
1922
+ margin-bottom: 20px;
1923
+ margin-top: 40px;
1924
+ }
1925
+ .sk-text {
1926
+ height: 16px;
1927
+ width: 80%;
1928
+ margin-bottom: 8px;
1929
+ }
1930
+ .sk-text-short {
1931
+ width: 40%;
1932
+ }
1933
+ .sk-label {
1934
+ height: 14px;
1935
+ width: 25%;
1936
+ margin-bottom: 10px;
1937
+ }
1938
+
1939
+ .hero-section {
1940
+ display: flex;
1941
+ gap: 40px;
1942
+ margin-bottom: 40px;
1943
+ border-bottom: 1px solid ${borderColor};
1944
+ padding-bottom: 40px;
1945
+ flex-direction: row;
1946
+ }
1947
+ .hero-content {
1948
+ flex: 1;
1949
+ display: flex;
1950
+ flex-direction: column;
1951
+ justify-content: center;
1952
+ }
1953
+ .hero-image {
1954
+ flex: 1;
1955
+ height: 300px;
1956
+ border-radius: 12px;
1957
+ }
1958
+
1959
+ .share-section {
1960
+ margin-bottom: 40px;
1961
+ }
1962
+ .sk-input {
1963
+ height: 50px;
1964
+ width: 100%;
1965
+ border-radius: 8px;
1966
+ margin-bottom: 16px;
1967
+ }
1968
+ .social-buttons {
1969
+ display: flex;
1970
+ gap: 12px;
1971
+ }
1972
+ .sk-btn-social {
1973
+ flex: 1;
1974
+ height: 50px;
1975
+ border-radius: 8px;
1976
+ }
1977
+
1978
+ .stats-section {
1979
+ display: flex;
1980
+ gap: 24px;
1981
+ margin-bottom: 40px;
1982
+ padding: 30px 0;
1983
+ border-top: 1px solid ${borderColor};
1984
+ border-bottom: 1px solid ${borderColor};
1985
+ }
1986
+ .stat-card {
1987
+ flex: 1;
1988
+ display: flex;
1989
+ flex-direction: column;
1990
+ align-items: center;
1991
+ }
1992
+ .stat-divider {
1993
+ padding-left: 24px;
1994
+ }
1995
+
1996
+ .sk-stat-num {
1997
+ height: 48px;
1998
+ width: 120px;
1999
+ margin-bottom: 8px;
2000
+ }
2001
+ .sk-stat-label {
2002
+ height: 18px;
2003
+ width: 80px;
2004
+ }
2005
+
2006
+ .table-header {
2007
+ display: flex;
2008
+ gap: 16px;
2009
+ margin-bottom: 16px;
2010
+ }
2011
+ .sk-th {
2012
+ height: 16px;
2013
+ }
2014
+ .table-row {
2015
+ display: flex;
2016
+ align-items: center;
2017
+ gap: 16px;
2018
+ padding: 16px 0;
2019
+ border-bottom: 1px solid ${borderColor};
2020
+ }
2021
+
2022
+ .col-user {
2023
+ flex: 2;
2024
+ }
2025
+ .col-status {
2026
+ flex: 1;
2027
+ }
2028
+ .col-reward {
2029
+ flex: 2;
2030
+ }
2031
+ .col-date {
2032
+ flex: 1;
2033
+ }
2034
+
2035
+ .sk-badge {
2036
+ height: 28px;
2037
+ width: 90px;
2038
+ border-radius: 14px;
2039
+ }
2040
+ .sk-reward-block {
2041
+ height: 36px;
2042
+ width: 100%;
2043
+ border-radius: 6px;
2044
+ }
2045
+
2046
+ .pagination {
2047
+ display: flex;
2048
+ justify-content: flex-end;
2049
+ gap: 8px;
2050
+ margin-top: 24px;
2051
+ }
2052
+ .sk-btn-page {
2053
+ height: 36px;
2054
+ width: 64px;
2055
+ border-radius: 6px;
2056
+ margin-bottom: 0;
2057
+ }
2058
+
2059
+ @media (max-width: 768px) {
2060
+ body {
2061
+ padding: 20px;
2062
+ }
2063
+ .widget-container {
2064
+ padding: 24px;
2065
+ }
2066
+
2067
+ .hero-section {
2068
+ flex-direction: column-reverse;
2069
+ gap: 24px;
2070
+ }
2071
+ .hero-image {
2072
+ height: 220px;
2073
+ width: 100%;
2074
+ }
2075
+ .sk-title-lg {
2076
+ width: 80%;
2077
+ }
2078
+
2079
+ .col-date {
2080
+ display: none;
2081
+ }
2082
+ }
2083
+
2084
+ @media (max-width: 480px) {
2085
+ body {
2086
+ padding: 10px;
2087
+ }
2088
+ .widget-container {
2089
+ padding: 16px;
2090
+ }
2091
+
2092
+ .sk-stat-num {
2093
+ width: 80px;
2094
+ height: 40px;
2095
+ }
2096
+
2097
+ .col-reward {
2098
+ display: none;
2099
+ }
2100
+
2101
+ .col-user {
2102
+ flex: 3;
2103
+ }
2104
+ .col-status {
2105
+ flex: 2;
2106
+ display: flex;
2107
+ justify-content: flex-end;
2108
+ }
2109
+ }
2110
+ </style>
2111
+
2112
+ <div class="widget-container">
2113
+ <div class="hero-section">
2114
+ <div class="hero-content">
2115
+ <div class="skeleton sk-title-lg"></div>
2116
+ <div class="skeleton sk-text"></div>
2117
+ <div class="skeleton sk-text sk-text-short"></div>
2118
+ </div>
2119
+ <div class="skeleton hero-image"></div>
2120
+ </div>
2121
+
2122
+ <div class="share-section">
2123
+ <div class="skeleton sk-label"></div>
2124
+ <div class="skeleton sk-input"></div>
2125
+ <div class="social-buttons">
2126
+ <div class="skeleton sk-btn-social"></div>
2127
+ <div class="skeleton sk-btn-social"></div>
2128
+ <div class="skeleton sk-btn-social"></div>
2129
+ <div class="skeleton sk-btn-social"></div>
2130
+ </div>
2131
+ </div>
2132
+
2133
+ <div
2134
+ class="skeleton sk-title-md"
2135
+ style="margin-top: 0; width: 30%; margin-left: auto; margin-right: auto"
2136
+ ></div>
2137
+ <div
2138
+ class="skeleton sk-text"
2139
+ style="width: 60%; margin-left: auto; margin-right: auto"
2140
+ ></div>
2141
+
2142
+ <div class="stats-section">
2143
+ <div class="stat-card">
2144
+ <div class="skeleton sk-stat-num"></div>
2145
+ <div class="skeleton sk-stat-label"></div>
2146
+ </div>
2147
+ <div class="stat-card stat-divider">
2148
+ <div class="skeleton sk-stat-num"></div>
2149
+ <div class="skeleton sk-stat-label"></div>
2150
+ </div>
2151
+ </div>
2152
+
2153
+ <div class="skeleton sk-title-md"></div>
2154
+
2155
+ <div class="table-header">
2156
+ <div class="skeleton sk-th col-user"></div>
2157
+ <div class="skeleton sk-th col-status"></div>
2158
+ <div class="skeleton sk-th col-reward"></div>
2159
+ <div class="skeleton sk-th col-date"></div>
2160
+ </div>
2161
+
2162
+ <div class="table-row">
2163
+ <div class="col-user">
2164
+ <div class="skeleton sk-text" style="width: 70%; margin: 0"></div>
2165
+ </div>
2166
+ <div class="col-status">
2167
+ <div class="skeleton sk-badge" style="margin: 0"></div>
2168
+ </div>
2169
+ <div class="col-reward">
2170
+ <div class="skeleton sk-reward-block" style="margin: 0"></div>
2171
+ </div>
2172
+ <div class="col-date">
2173
+ <div class="skeleton sk-text" style="width: 80%; margin: 0"></div>
2174
+ </div>
2175
+ </div>
2176
+ <div class="table-row">
2177
+ <div class="col-user">
2178
+ <div class="skeleton sk-text" style="width: 60%; margin: 0"></div>
2179
+ </div>
2180
+ <div class="col-status">
2181
+ <div class="skeleton sk-badge" style="margin: 0"></div>
2182
+ </div>
2183
+ <div class="col-reward">
2184
+ <div class="skeleton sk-reward-block" style="margin: 0"></div>
2185
+ </div>
2186
+ <div class="col-date">
2187
+ <div class="skeleton sk-text" style="width: 80%; margin: 0"></div>
2188
+ </div>
2189
+ </div>
2190
+ <div class="table-row">
2191
+ <div class="col-user">
2192
+ <div class="skeleton sk-text" style="width: 75%; margin: 0"></div>
2193
+ </div>
2194
+ <div class="col-status">
2195
+ <div class="skeleton sk-badge" style="margin: 0"></div>
2196
+ </div>
2197
+ <div class="col-reward">
2198
+ <div class="skeleton sk-reward-block" style="margin: 0"></div>
2199
+ </div>
2200
+ <div class="col-date">
2201
+ <div class="skeleton sk-text" style="width: 80%; margin: 0"></div>
2202
+ </div>
2203
+ </div>
2204
+
2205
+ <div class="pagination">
2206
+ <div class="skeleton sk-btn-page"></div>
2207
+ <div class="skeleton sk-btn-page"></div>
2208
+ </div>
2209
+ </div>
2210
+ `;
2118
2211
  };
2119
- function b64decode(input) {
2120
- const binary = atob(input.replace(/_/g, "/").replace(/-/g, "+"));
2121
- const bytes = new Uint8Array(binary.length);
2122
- for (let i = 0; i < binary.length; i++) {
2123
- bytes[i] = binary.charCodeAt(i);
2124
- }
2125
- return new TextDecoder("utf8").decode(bytes);
2126
- }
2127
- function b64encode(input) {
2128
- const encodedInput = new TextEncoder().encode(input);
2129
- const binary = Array.from(
2130
- encodedInput,
2131
- (byte) => String.fromCodePoint(byte)
2132
- ).join("");
2133
- return btoa(binary).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
2134
- }
2135
- function getTopDomain() {
2136
- var i, h, weird_cookie = "weird_get_top_level_domain=cookie", hostname = document.location.hostname.split(".");
2137
- for (i = hostname.length - 1; i >= 0; i--) {
2138
- h = hostname.slice(i).join(".");
2139
- document.cookie = weird_cookie + ";domain=." + h + ";";
2140
- if (document.cookie.indexOf(weird_cookie) > -1) {
2141
- document.cookie = weird_cookie.split("=")[0] + "=;domain=." + h + ";expires=Thu, 01 Jan 1970 00:00:01 GMT;";
2142
- return h;
2143
- }
2144
- }
2145
- }
2146
- function _pushCookie() {
2147
- const queryString = window.location.search;
2148
- const urlParams = new URLSearchParams(queryString);
2149
- const refParam = urlParams.get("_saasquatch") || "";
2150
- if (refParam) {
2151
- let paramsJSON = "", existingCookie = "", reEncodedCookie = "";
2152
- try {
2153
- paramsJSON = JSON.parse(b64decode(refParam));
2154
- } catch (error) {
2155
- _log$4("Unable to decode params", error);
2156
- return;
2157
- }
2158
- try {
2159
- existingCookie = JSON.parse(b64decode(api$1.get("_saasquatch")));
2160
- _log$4("existing cookie", existingCookie);
2161
- } catch (error) {
2162
- _log$4("Unable to retrieve cookie", error);
2163
- }
2164
- try {
2165
- const domain = getTopDomain();
2166
- _log$4("domain retrieved:", domain);
2167
- if (existingCookie) {
2168
- const newCookie = deepMerge(existingCookie, paramsJSON);
2169
- reEncodedCookie = b64encode(JSON.stringify(newCookie));
2170
- _log$4("cookie to store:", newCookie);
2171
- } else {
2172
- reEncodedCookie = b64encode(JSON.stringify(paramsJSON));
2173
- _log$4("cookie to store:", paramsJSON);
2174
- }
2175
- api$1.set("_saasquatch", reEncodedCookie, {
2176
- expires: 365,
2177
- secure: false,
2178
- sameSite: "Lax",
2179
- domain,
2180
- path: "/"
2181
- });
2182
- } catch (error) {
2183
- _log$4("Unable to set cookie", error);
2184
- }
2185
- }
2186
- }
2187
- const _log$3 = browserExports.debug("squatch-js");
2188
- function _getAutoConfig() {
2189
- var _a2;
2190
- const queryString = window.location.search;
2191
- const urlParams = new URLSearchParams(queryString);
2192
- const refParam = urlParams.get("_saasquatchExtra") || "";
2193
- if (!refParam) {
2194
- _log$3("No _saasquatchExtra param");
2195
- return;
2196
- }
2197
- const config = validateConfig({
2198
- tenantAlias: "UNKNOWN"
2199
- });
2200
- if (!config.domain) {
2201
- _log$3("domain must be provided in config to use _saasquatchExtra");
2202
- return;
2203
- }
2204
- let raw;
2205
- try {
2206
- raw = JSON.parse(b64decode(refParam));
2207
- } catch (e) {
2208
- _log$3("Unable to decode _saasquatchExtra config");
2209
- return;
2210
- }
2211
- function normalizeDomain(domain) {
2212
- return domain.replace(/^https?:\/\//, "");
2213
- }
2214
- const normalizedDomain = normalizeDomain(config.domain);
2215
- const tenantAlias = Object.keys((raw == null ? void 0 : raw[normalizedDomain]) || {})[0];
2216
- const widgetConfig = (_a2 = raw == null ? void 0 : raw[normalizedDomain]) == null ? void 0 : _a2[tenantAlias];
2217
- if (!widgetConfig) {
2218
- _log$3("_saasquatchExtra did not have an expected structure");
2219
- return void 0;
2220
- }
2221
- const { autoPopupWidgetType, ...rest } = widgetConfig;
2222
- return {
2223
- widgetConfig: {
2224
- widgetType: autoPopupWidgetType,
2225
- displayOnLoad: true,
2226
- ...rest
2227
- },
2228
- squatchConfig: {
2229
- ...config,
2230
- tenantAlias
2231
- }
2232
- };
2233
- }
2234
2212
  const _log$2 = browserExports.debug("squatch-js:decodeUserJwt");
2235
2213
  function decodeUserJwt(tokenStr) {
2236
2214
  var _a2;
@@ -2464,12 +2442,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2464
2442
  }
2465
2443
  }
2466
2444
  async connectedCallback() {
2467
- var _a2, _b;
2468
2445
  this.loaded = true;
2469
2446
  this.container = this.getAttribute("container");
2447
+ brandingConfig == null ? void 0 : brandingConfig.loadingHeight;
2448
+ const skeletonHTML = getSkeleton({});
2449
+ const skeletonContainer = document.createElement("div");
2450
+ skeletonContainer.id = "loading-skeleton";
2451
+ skeletonContainer.innerHTML = skeletonHTML;
2452
+ const root = this.shadowRoot || this.attachShadow({ mode: "open" });
2453
+ root.innerHTML = "";
2454
+ root.appendChild(skeletonContainer);
2470
2455
  await this.renderWidget();
2471
- const slot = (_a2 = this.shadowRoot && Array.from(this.shadowRoot.children)) == null ? void 0 : _a2.find((c) => c.tagName === "SLOT");
2472
- if (slot) (_b = this.shadowRoot) == null ? void 0 : _b.removeChild(slot);
2456
+ const loadingElement = root.getElementById("loading-skeleton");
2457
+ if (loadingElement) {
2458
+ loadingElement.remove();
2459
+ }
2473
2460
  if (this.getAttribute("open") !== null) this.open();
2474
2461
  }
2475
2462
  }
@@ -2496,9 +2483,29 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2496
2483
  }
2497
2484
  }
2498
2485
  async connectedCallback() {
2486
+ var _a2;
2499
2487
  this.loaded = true;
2500
2488
  this.container = this.getAttribute("container");
2489
+ const skeletonHTML = `
2490
+ <div>
2491
+ <h1>Dynamic Content</h1>
2492
+ <p>This content was dynamically added to the widget before it loaded.</p>
2493
+ </div>
2494
+ `;
2495
+ const skeletonContainer = document.createElement("div");
2496
+ skeletonContainer.id = "loading-skeleton";
2497
+ skeletonContainer.innerHTML = skeletonHTML;
2498
+ if (!this.shadowRoot) {
2499
+ this.attachShadow({ mode: "open" });
2500
+ }
2501
+ if (this.shadowRoot) {
2502
+ this.shadowRoot.innerHTML = skeletonHTML;
2503
+ }
2501
2504
  await this.renderWidget();
2505
+ const loadingElement = (_a2 = this.shadowRoot) == null ? void 0 : _a2.getElementById("loading-skeleton");
2506
+ if (loadingElement) {
2507
+ loadingElement.remove();
2508
+ }
2502
2509
  if (this.getAttribute("open") !== null) this.open();
2503
2510
  }
2504
2511
  }