@tolinku/web-sdk 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +27 -3
- package/dist/index.d.ts +27 -3
- package/dist/index.js +332 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +332 -56
- package/dist/index.mjs.map +1 -1
- package/dist/tolinku.min.js +27 -25
- package/dist/tolinku.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/types.ts
|
|
2
|
-
var SDK_VERSION = "0.6.
|
|
2
|
+
var SDK_VERSION = "0.6.1";
|
|
3
3
|
|
|
4
4
|
// src/client.ts
|
|
5
5
|
var MAX_RETRIES = 3;
|
|
@@ -720,6 +720,19 @@ function isSafeUrl(url) {
|
|
|
720
720
|
return false;
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
+
var EXECUTABLE_SCHEMES = /* @__PURE__ */ new Set(["javascript:", "vbscript:", "data:", "blob:", "file:"]);
|
|
724
|
+
function isNavigableUrl(url) {
|
|
725
|
+
if (typeof url !== "string") return false;
|
|
726
|
+
const trimmed = url.trim();
|
|
727
|
+
if (!trimmed) return false;
|
|
728
|
+
let parsed;
|
|
729
|
+
try {
|
|
730
|
+
parsed = new URL(trimmed);
|
|
731
|
+
} catch {
|
|
732
|
+
return true;
|
|
733
|
+
}
|
|
734
|
+
return !EXECUTABLE_SCHEMES.has(parsed.protocol);
|
|
735
|
+
}
|
|
723
736
|
|
|
724
737
|
// src/storage.ts
|
|
725
738
|
var BANNER_KEY = "tolinku_banner_dismissed";
|
|
@@ -1142,6 +1155,7 @@ var Messages = class {
|
|
|
1142
1155
|
this.client = client;
|
|
1143
1156
|
this.overlay = null;
|
|
1144
1157
|
this.styleEl = null;
|
|
1158
|
+
this.app = null;
|
|
1145
1159
|
}
|
|
1146
1160
|
/** Fetch messages and show the highest-priority non-dismissed one */
|
|
1147
1161
|
async show(options = {}, userId) {
|
|
@@ -1149,6 +1163,7 @@ var Messages = class {
|
|
|
1149
1163
|
if (options.trigger) params.trigger = options.trigger;
|
|
1150
1164
|
if (userId) params.user_id = userId;
|
|
1151
1165
|
const data = await this.client.get("/v1/api/messages", params);
|
|
1166
|
+
this.app = data.app || null;
|
|
1152
1167
|
if (!data.messages || data.messages.length === 0) return;
|
|
1153
1168
|
const candidates = data.messages.filter((m) => !isMessageDismissed(m.id, m.dismiss_days)).filter((m) => !isMessageSuppressed(m.id, m.max_impressions, m.min_interval_hours)).filter((m) => !options.triggerValue || m.trigger_value === options.triggerValue).sort((a, b) => b.priority - a.priority);
|
|
1154
1169
|
if (candidates.length === 0) return;
|
|
@@ -1178,15 +1193,16 @@ var Messages = class {
|
|
|
1178
1193
|
.tolk-msg-overlay {
|
|
1179
1194
|
position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000000;
|
|
1180
1195
|
display: flex; align-items: center; justify-content: center;
|
|
1196
|
+
padding: 24px 16px; box-sizing: border-box;
|
|
1181
1197
|
background: rgba(0,0,0,0.5);
|
|
1182
1198
|
opacity: 0; transition: opacity 0.3s ease;
|
|
1183
1199
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
1184
1200
|
}
|
|
1185
1201
|
.tolk-msg-overlay.tolk-visible { opacity: 1; }
|
|
1186
1202
|
.tolk-msg-card {
|
|
1187
|
-
position: relative;
|
|
1203
|
+
position: relative; width: 100%;
|
|
1188
1204
|
max-height: 80vh; overflow-y: auto;
|
|
1189
|
-
border-radius: 16px;
|
|
1205
|
+
border-radius: 16px; box-sizing: border-box;
|
|
1190
1206
|
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
1191
1207
|
}
|
|
1192
1208
|
.tolk-msg-close {
|
|
@@ -1197,6 +1213,7 @@ var Messages = class {
|
|
|
1197
1213
|
color: inherit; opacity: 0.6;
|
|
1198
1214
|
}
|
|
1199
1215
|
.tolk-msg-close:hover { opacity: 1; }
|
|
1216
|
+
.tolk-msg-card img { max-width: 100%; }
|
|
1200
1217
|
`;
|
|
1201
1218
|
const overlay = document.createElement("div");
|
|
1202
1219
|
overlay.className = "tolk-msg-overlay";
|
|
@@ -1209,7 +1226,24 @@ var Messages = class {
|
|
|
1209
1226
|
});
|
|
1210
1227
|
const card = document.createElement("div");
|
|
1211
1228
|
card.className = "tolk-msg-card";
|
|
1212
|
-
|
|
1229
|
+
const root = message.content && message.content.root && message.content.root.props || {};
|
|
1230
|
+
card.style.backgroundColor = sanitizeCssColor(root.bgColor) || sanitizeCssColor(message.background_color) || "#ffffff";
|
|
1231
|
+
if (root.bgGradient) {
|
|
1232
|
+
const gradient = safeGradient(String(root.bgGradient));
|
|
1233
|
+
if (gradient) card.style.backgroundImage = gradient;
|
|
1234
|
+
}
|
|
1235
|
+
if (root.bgImage) {
|
|
1236
|
+
const bgUrl = sanitizeCssUrl(root.bgImage);
|
|
1237
|
+
if (bgUrl) {
|
|
1238
|
+
card.style.backgroundImage = `url("${bgUrl}")`;
|
|
1239
|
+
card.style.backgroundSize = "cover";
|
|
1240
|
+
card.style.backgroundPosition = "center";
|
|
1241
|
+
card.style.backgroundRepeat = "no-repeat";
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
card.style.padding = clamp(authoredNumber(root.padding, 20), 0, 200) + "px";
|
|
1245
|
+
card.style.maxWidth = clamp(authoredNumber(root.contentWidth, 480), 100, 2e3) + "px";
|
|
1246
|
+
overlay.style.alignItems = root.verticalAlign === "top" ? "flex-start" : "center";
|
|
1213
1247
|
const closeBtn = document.createElement("button");
|
|
1214
1248
|
closeBtn.className = "tolk-msg-close";
|
|
1215
1249
|
closeBtn.setAttribute("aria-label", "Close message");
|
|
@@ -1220,10 +1254,37 @@ var Messages = class {
|
|
|
1220
1254
|
this.dismiss();
|
|
1221
1255
|
});
|
|
1222
1256
|
card.appendChild(closeBtn);
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1257
|
+
const context = {
|
|
1258
|
+
messageId: message.id,
|
|
1259
|
+
options,
|
|
1260
|
+
zones: message.content?.zones,
|
|
1261
|
+
app: this.app
|
|
1262
|
+
};
|
|
1263
|
+
const content = Array.isArray(message.content?.content) ? message.content.content : [];
|
|
1264
|
+
for (const component of content) {
|
|
1265
|
+
const el = this.renderComponent(component, context);
|
|
1266
|
+
if (el) card.appendChild(el);
|
|
1267
|
+
}
|
|
1268
|
+
const drew = drawsAnything(content, context, 0);
|
|
1269
|
+
if (!drew) {
|
|
1270
|
+
if (message.title) {
|
|
1271
|
+
const titleEl = document.createElement("h2");
|
|
1272
|
+
titleEl.textContent = message.title;
|
|
1273
|
+
titleEl.style.fontSize = "24px";
|
|
1274
|
+
titleEl.style.fontWeight = "700";
|
|
1275
|
+
titleEl.style.color = "#1B1B1B";
|
|
1276
|
+
titleEl.style.lineHeight = "1.2";
|
|
1277
|
+
titleEl.style.margin = "0";
|
|
1278
|
+
card.appendChild(titleEl);
|
|
1279
|
+
}
|
|
1280
|
+
if (message.body) {
|
|
1281
|
+
const bodyEl = document.createElement("p");
|
|
1282
|
+
bodyEl.textContent = message.body;
|
|
1283
|
+
bodyEl.style.fontSize = "15px";
|
|
1284
|
+
bodyEl.style.color = "#555555";
|
|
1285
|
+
bodyEl.style.lineHeight = "1.5";
|
|
1286
|
+
bodyEl.style.margin = message.title ? "8px 0 0 0" : "0";
|
|
1287
|
+
card.appendChild(bodyEl);
|
|
1227
1288
|
}
|
|
1228
1289
|
}
|
|
1229
1290
|
overlay.appendChild(card);
|
|
@@ -1237,108 +1298,323 @@ var Messages = class {
|
|
|
1237
1298
|
});
|
|
1238
1299
|
});
|
|
1239
1300
|
}
|
|
1240
|
-
renderComponent(component,
|
|
1241
|
-
|
|
1301
|
+
renderComponent(component, context, depth = 0) {
|
|
1302
|
+
if (!component || typeof component !== "object") return null;
|
|
1303
|
+
const props = component.props || {};
|
|
1242
1304
|
switch (component.type) {
|
|
1243
1305
|
case "Heading": {
|
|
1244
1306
|
const el = document.createElement("h2");
|
|
1245
1307
|
el.textContent = props.text || "";
|
|
1246
|
-
el.style.fontSize = (props.fontSize
|
|
1308
|
+
el.style.fontSize = authoredNumber(props.fontSize, 28) + "px";
|
|
1247
1309
|
el.style.fontWeight = "700";
|
|
1248
1310
|
el.style.color = sanitizeCssColor(props.color) || "#1B1B1B";
|
|
1249
1311
|
el.style.textAlign = sanitizeTextAlign(props.alignment);
|
|
1250
1312
|
el.style.lineHeight = "1.2";
|
|
1251
|
-
el.style.margin = "0
|
|
1313
|
+
el.style.margin = "0";
|
|
1252
1314
|
return el;
|
|
1253
1315
|
}
|
|
1254
1316
|
case "TextBlock": {
|
|
1255
1317
|
const el = document.createElement("p");
|
|
1256
|
-
el
|
|
1257
|
-
el.style.fontSize = (props.fontSize
|
|
1318
|
+
appendMarkdownText(el, props.content || "");
|
|
1319
|
+
el.style.fontSize = authoredNumber(props.fontSize, 15) + "px";
|
|
1258
1320
|
el.style.color = sanitizeCssColor(props.color) || "#555555";
|
|
1259
1321
|
el.style.textAlign = sanitizeTextAlign(props.alignment);
|
|
1260
1322
|
el.style.lineHeight = "1.5";
|
|
1261
|
-
el.style.margin = "0
|
|
1323
|
+
el.style.margin = "0";
|
|
1262
1324
|
return el;
|
|
1263
1325
|
}
|
|
1264
1326
|
case "Image": {
|
|
1265
1327
|
const url = props.url || "";
|
|
1266
1328
|
if (!isSafeUrl(url)) return null;
|
|
1329
|
+
const wrap = document.createElement("div");
|
|
1330
|
+
wrap.style.textAlign = "center";
|
|
1267
1331
|
const el = document.createElement("img");
|
|
1268
1332
|
el.src = url;
|
|
1269
1333
|
el.alt = props.alt || "";
|
|
1270
|
-
|
|
1271
|
-
el.style.
|
|
1272
|
-
el.style.
|
|
1273
|
-
el.style.
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
case "Button": {
|
|
1278
|
-
const el = document.createElement("button");
|
|
1279
|
-
el.textContent = props.label || "Click";
|
|
1280
|
-
el.style.backgroundColor = sanitizeCssColor(props.bgColor) || "#1B1B1B";
|
|
1281
|
-
el.style.color = sanitizeCssColor(props.textColor) || "#ffffff";
|
|
1282
|
-
el.style.fontSize = (props.fontSize || 16) + "px";
|
|
1283
|
-
el.style.borderRadius = (props.borderRadius || 8) + "px";
|
|
1284
|
-
el.style.border = "none";
|
|
1285
|
-
el.style.padding = "10px 20px";
|
|
1286
|
-
el.style.cursor = "pointer";
|
|
1287
|
-
el.style.fontWeight = "600";
|
|
1288
|
-
el.style.margin = "8px 0";
|
|
1289
|
-
if (props.fullWidth) {
|
|
1290
|
-
el.style.width = "100%";
|
|
1334
|
+
el.style.width = dimension(props.width) || "auto";
|
|
1335
|
+
el.style.height = dimension(props.height) || "auto";
|
|
1336
|
+
el.style.maxWidth = "100%";
|
|
1337
|
+
el.style.borderRadius = authoredNumber(props.borderRadius, 8) + "px";
|
|
1338
|
+
const borderWidth = authoredNumber(props.borderWidth, 0);
|
|
1339
|
+
if (borderWidth > 0) {
|
|
1340
|
+
el.style.border = `${borderWidth}px solid ${sanitizeCssColor(props.borderColor) || "#1B1B1B"}`;
|
|
1291
1341
|
}
|
|
1292
|
-
el.
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
options.onButtonPress(action, messageId);
|
|
1296
|
-
} else if (action) {
|
|
1297
|
-
if (isSafeUrl(action)) {
|
|
1298
|
-
window.location.href = action;
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
});
|
|
1302
|
-
return el;
|
|
1342
|
+
el.style.display = "inline-block";
|
|
1343
|
+
wrap.appendChild(el);
|
|
1344
|
+
return wrap;
|
|
1303
1345
|
}
|
|
1346
|
+
case "Button":
|
|
1347
|
+
return this.renderButton(props, props.action || "", "Click", context);
|
|
1304
1348
|
case "Section": {
|
|
1305
1349
|
const el = document.createElement("div");
|
|
1306
1350
|
if (props.bgColor) el.style.backgroundColor = sanitizeCssColor(props.bgColor) || "";
|
|
1307
|
-
el.style.padding = (props.padding
|
|
1308
|
-
el.style.borderRadius = (props.borderRadius
|
|
1309
|
-
el.style.
|
|
1351
|
+
el.style.padding = authoredNumber(props.padding, 16) + "px";
|
|
1352
|
+
el.style.borderRadius = authoredNumber(props.borderRadius, 0) + "px";
|
|
1353
|
+
el.style.minHeight = "60px";
|
|
1310
1354
|
if (props.bgImage) {
|
|
1311
1355
|
const sanitizedUrl = sanitizeCssUrl(props.bgImage);
|
|
1312
1356
|
if (sanitizedUrl) {
|
|
1313
1357
|
el.style.backgroundImage = `url("${sanitizedUrl}")`;
|
|
1314
1358
|
el.style.backgroundSize = sanitizeBackgroundSize(props.bgSize);
|
|
1315
1359
|
el.style.backgroundPosition = "center";
|
|
1360
|
+
el.style.backgroundRepeat = "no-repeat";
|
|
1316
1361
|
}
|
|
1317
1362
|
}
|
|
1318
|
-
const
|
|
1319
|
-
|
|
1320
|
-
const childEl = this.renderComponent(child, messageId, options);
|
|
1363
|
+
for (const child of sectionChildren(props, context, depth)) {
|
|
1364
|
+
const childEl = this.renderComponent(child, context, depth + 1);
|
|
1321
1365
|
if (childEl) el.appendChild(childEl);
|
|
1322
1366
|
}
|
|
1323
1367
|
return el;
|
|
1324
1368
|
}
|
|
1325
1369
|
case "Spacer": {
|
|
1326
1370
|
const el = document.createElement("div");
|
|
1327
|
-
el.style.height = (props.height
|
|
1371
|
+
el.style.height = authoredNumber(props.height, 24) + "px";
|
|
1328
1372
|
return el;
|
|
1329
1373
|
}
|
|
1330
1374
|
case "Divider": {
|
|
1331
1375
|
const el = document.createElement("hr");
|
|
1332
1376
|
el.style.border = "none";
|
|
1333
|
-
el.style.borderTop = `${props.thickness
|
|
1334
|
-
el.style.margin = "
|
|
1377
|
+
el.style.borderTop = `${authoredNumber(props.thickness, 1)}px solid ${sanitizeCssColor(props.color) || "#e5e5e5"}`;
|
|
1378
|
+
el.style.margin = "0";
|
|
1335
1379
|
return el;
|
|
1336
1380
|
}
|
|
1381
|
+
case "AppIcon": {
|
|
1382
|
+
const wrap = document.createElement("div");
|
|
1383
|
+
wrap.style.textAlign = "center";
|
|
1384
|
+
const size = authoredNumber(props.size, 80);
|
|
1385
|
+
const borderRadius = authoredNumber(props.borderRadius, 16);
|
|
1386
|
+
const iconUrl = context.app?.icon_url || "";
|
|
1387
|
+
if (isSafeUrl(iconUrl)) {
|
|
1388
|
+
const img = document.createElement("img");
|
|
1389
|
+
img.src = iconUrl;
|
|
1390
|
+
img.alt = context.app?.name ? `${context.app.name} icon` : "App Icon";
|
|
1391
|
+
img.style.width = size + "px";
|
|
1392
|
+
img.style.height = size + "px";
|
|
1393
|
+
img.style.borderRadius = borderRadius + "px";
|
|
1394
|
+
img.style.objectFit = "cover";
|
|
1395
|
+
img.style.display = "inline-block";
|
|
1396
|
+
wrap.appendChild(img);
|
|
1397
|
+
} else {
|
|
1398
|
+
const placeholder = document.createElement("div");
|
|
1399
|
+
placeholder.style.width = size + "px";
|
|
1400
|
+
placeholder.style.height = size + "px";
|
|
1401
|
+
placeholder.style.borderRadius = borderRadius + "px";
|
|
1402
|
+
placeholder.style.background = "#f0f0f0";
|
|
1403
|
+
placeholder.style.display = "inline-block";
|
|
1404
|
+
wrap.appendChild(placeholder);
|
|
1405
|
+
}
|
|
1406
|
+
return wrap;
|
|
1407
|
+
}
|
|
1408
|
+
case "StoreButtons": {
|
|
1409
|
+
const iosUrl = props.iosUrlOverride || context.app?.ios_store_url || "";
|
|
1410
|
+
const androidUrl = props.androidUrlOverride || context.app?.android_store_url || "";
|
|
1411
|
+
const showIos = props.showIos !== false && isNavigableUrl(iosUrl);
|
|
1412
|
+
const showAndroid = props.showAndroid !== false && isNavigableUrl(androidUrl);
|
|
1413
|
+
if (!showIos && !showAndroid) return null;
|
|
1414
|
+
const row = document.createElement("div");
|
|
1415
|
+
row.style.display = "flex";
|
|
1416
|
+
row.style.gap = "12px";
|
|
1417
|
+
row.style.flexWrap = "wrap";
|
|
1418
|
+
row.style.justifyContent = props.alignment === "center" ? "center" : props.alignment === "right" ? "flex-end" : "flex-start";
|
|
1419
|
+
const height = authoredNumber(props.height, 44);
|
|
1420
|
+
if (showIos) {
|
|
1421
|
+
row.appendChild(storeBadge(iosUrl, context.app?.ios_badge_url, "Download on the App Store", height, context));
|
|
1422
|
+
}
|
|
1423
|
+
if (showAndroid) {
|
|
1424
|
+
row.appendChild(
|
|
1425
|
+
storeBadge(androidUrl, context.app?.android_badge_url, "Get it on Google Play", height, context)
|
|
1426
|
+
);
|
|
1427
|
+
}
|
|
1428
|
+
return row;
|
|
1429
|
+
}
|
|
1430
|
+
case "DeepLinkButton": {
|
|
1431
|
+
const deepLink = context.app?.deep_link_url || "";
|
|
1432
|
+
if (!isNavigableUrl(deepLink)) return null;
|
|
1433
|
+
return this.renderButton(props, deepLink, "Open in App", context);
|
|
1434
|
+
}
|
|
1337
1435
|
default:
|
|
1338
1436
|
return null;
|
|
1339
1437
|
}
|
|
1340
1438
|
}
|
|
1439
|
+
/** A Button, or a DeepLinkButton, which the builder styles the same way. */
|
|
1440
|
+
renderButton(props, action, defaultLabel, context) {
|
|
1441
|
+
const wrap = document.createElement("div");
|
|
1442
|
+
wrap.style.textAlign = "center";
|
|
1443
|
+
const el = document.createElement("button");
|
|
1444
|
+
const variant = props.style || "filled";
|
|
1445
|
+
const isOutline = variant === "outline";
|
|
1446
|
+
const baseColor = sanitizeCssColor(props.bgColor) || "#1B1B1B";
|
|
1447
|
+
const tint = variant === "soft" ? softVariant(baseColor) : null;
|
|
1448
|
+
const isSoft = tint !== null;
|
|
1449
|
+
el.style.backgroundColor = isOutline ? "transparent" : isSoft ? tint : baseColor;
|
|
1450
|
+
el.style.color = isOutline || isSoft ? baseColor : sanitizeCssColor(props.textColor) || "#ffffff";
|
|
1451
|
+
el.style.border = isOutline ? `2px solid ${baseColor}` : "none";
|
|
1452
|
+
el.style.fontSize = authoredNumber(props.fontSize, 16) + "px";
|
|
1453
|
+
el.style.borderRadius = authoredNumber(props.borderRadius, 8) + "px";
|
|
1454
|
+
el.style.padding = "12px 24px";
|
|
1455
|
+
el.style.cursor = "pointer";
|
|
1456
|
+
el.style.fontWeight = "600";
|
|
1457
|
+
el.style.textAlign = "center";
|
|
1458
|
+
el.style.boxSizing = "border-box";
|
|
1459
|
+
el.style.width = props.fullWidth ? "100%" : "auto";
|
|
1460
|
+
if (props.emoji) {
|
|
1461
|
+
const emoji = document.createElement("span");
|
|
1462
|
+
emoji.setAttribute("aria-hidden", "true");
|
|
1463
|
+
emoji.textContent = props.emoji;
|
|
1464
|
+
el.appendChild(emoji);
|
|
1465
|
+
el.appendChild(document.createTextNode(" "));
|
|
1466
|
+
}
|
|
1467
|
+
el.appendChild(document.createTextNode(props.label || defaultLabel));
|
|
1468
|
+
el.addEventListener("click", () => {
|
|
1469
|
+
if (action === "close") {
|
|
1470
|
+
saveMessageDismissal(context.messageId);
|
|
1471
|
+
context.options.onDismiss?.(context.messageId);
|
|
1472
|
+
this.dismiss();
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
if (action && !isNavigableUrl(action)) return;
|
|
1476
|
+
if (context.options.onButtonPress) {
|
|
1477
|
+
context.options.onButtonPress(action, context.messageId);
|
|
1478
|
+
} else if (action) {
|
|
1479
|
+
window.location.href = action;
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1482
|
+
wrap.appendChild(el);
|
|
1483
|
+
return wrap;
|
|
1484
|
+
}
|
|
1341
1485
|
};
|
|
1486
|
+
var MAX_SECTION_DEPTH = 20;
|
|
1487
|
+
var SUPPORTED = /* @__PURE__ */ new Set([
|
|
1488
|
+
"Heading",
|
|
1489
|
+
"TextBlock",
|
|
1490
|
+
"Image",
|
|
1491
|
+
"Button",
|
|
1492
|
+
"Section",
|
|
1493
|
+
"Spacer",
|
|
1494
|
+
"Divider",
|
|
1495
|
+
"AppIcon",
|
|
1496
|
+
"StoreButtons",
|
|
1497
|
+
"DeepLinkButton"
|
|
1498
|
+
]);
|
|
1499
|
+
function sectionChildren(props, context, depth) {
|
|
1500
|
+
const sectionId = typeof props.id === "string" && props.id ? props.id : null;
|
|
1501
|
+
if (!sectionId || depth >= MAX_SECTION_DEPTH) return [];
|
|
1502
|
+
const children = context.zones?.[`${sectionId}:content`];
|
|
1503
|
+
return Array.isArray(children) ? children : [];
|
|
1504
|
+
}
|
|
1505
|
+
function drawsAnything(content, context, depth) {
|
|
1506
|
+
return content.some((component) => {
|
|
1507
|
+
if (!component || typeof component !== "object" || !SUPPORTED.has(component.type)) return false;
|
|
1508
|
+
const props = component.props || {};
|
|
1509
|
+
switch (component.type) {
|
|
1510
|
+
case "Image":
|
|
1511
|
+
return isSafeUrl(props.url || "");
|
|
1512
|
+
case "DeepLinkButton":
|
|
1513
|
+
return isNavigableUrl(context.app?.deep_link_url || "");
|
|
1514
|
+
case "StoreButtons": {
|
|
1515
|
+
const ios = props.iosUrlOverride || context.app?.ios_store_url || "";
|
|
1516
|
+
const android = props.androidUrlOverride || context.app?.android_store_url || "";
|
|
1517
|
+
return props.showIos !== false && isNavigableUrl(ios) || props.showAndroid !== false && isNavigableUrl(android);
|
|
1518
|
+
}
|
|
1519
|
+
case "Section":
|
|
1520
|
+
return drawsAnything(sectionChildren(props, context, depth), context, depth + 1);
|
|
1521
|
+
default:
|
|
1522
|
+
return true;
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
function storeBadge(url, badgeUrl, label, height, context) {
|
|
1527
|
+
const link = document.createElement("a");
|
|
1528
|
+
link.href = url;
|
|
1529
|
+
link.style.display = "inline-block";
|
|
1530
|
+
link.addEventListener("click", (event) => {
|
|
1531
|
+
if (!context.options.onButtonPress) return;
|
|
1532
|
+
event.preventDefault();
|
|
1533
|
+
context.options.onButtonPress(url, context.messageId);
|
|
1534
|
+
});
|
|
1535
|
+
if (isSafeUrl(badgeUrl)) {
|
|
1536
|
+
const img = document.createElement("img");
|
|
1537
|
+
img.src = badgeUrl;
|
|
1538
|
+
img.alt = label;
|
|
1539
|
+
img.style.height = height + "px";
|
|
1540
|
+
img.style.display = "block";
|
|
1541
|
+
link.appendChild(img);
|
|
1542
|
+
} else {
|
|
1543
|
+
link.textContent = label;
|
|
1544
|
+
link.style.lineHeight = height + "px";
|
|
1545
|
+
link.style.fontSize = "14px";
|
|
1546
|
+
link.style.fontWeight = "600";
|
|
1547
|
+
link.style.color = "inherit";
|
|
1548
|
+
}
|
|
1549
|
+
return link;
|
|
1550
|
+
}
|
|
1551
|
+
function authoredNumber(value, fallback) {
|
|
1552
|
+
const parsed = typeof value === "number" ? value : parseFloat(String(value ?? ""));
|
|
1553
|
+
if (!isFinite(parsed)) return fallback;
|
|
1554
|
+
return Math.max(0, parsed);
|
|
1555
|
+
}
|
|
1556
|
+
function clamp(value, min, max) {
|
|
1557
|
+
return Math.min(max, Math.max(min, value));
|
|
1558
|
+
}
|
|
1559
|
+
function dimension(raw) {
|
|
1560
|
+
if (typeof raw === "number") return isFinite(raw) ? `${raw}px` : null;
|
|
1561
|
+
if (typeof raw !== "string") return null;
|
|
1562
|
+
const value = raw.trim();
|
|
1563
|
+
if (!value || value.toLowerCase() === "auto") return null;
|
|
1564
|
+
if (/^\d+(?:\.\d+)?%$/.test(value)) return value;
|
|
1565
|
+
const match = /^(\d+(?:\.\d+)?)(?:px)?$/i.exec(value);
|
|
1566
|
+
return match ? `${match[1]}px` : null;
|
|
1567
|
+
}
|
|
1568
|
+
function softVariant(color) {
|
|
1569
|
+
if (/^#[0-9a-f]{6}$/i.test(color)) return color + "22";
|
|
1570
|
+
if (/^#[0-9a-f]{3}$/i.test(color)) {
|
|
1571
|
+
return "#" + color[1] + color[1] + color[2] + color[2] + color[3] + color[3] + "22";
|
|
1572
|
+
}
|
|
1573
|
+
return null;
|
|
1574
|
+
}
|
|
1575
|
+
function cssVal(value) {
|
|
1576
|
+
const cleaned = String(value).replace(/[;{}<>"'`\\]/g, "");
|
|
1577
|
+
if (/javascript:|expression\s*\(/i.test(cleaned)) return "";
|
|
1578
|
+
return cleaned;
|
|
1579
|
+
}
|
|
1580
|
+
var GRADIENT_FUNCTION = /^(?:repeating-)?(?:linear|radial|conic)-gradient\(/i;
|
|
1581
|
+
function safeGradient(value) {
|
|
1582
|
+
const cleaned = cssVal(value).trim();
|
|
1583
|
+
return GRADIENT_FUNCTION.test(cleaned) ? cleaned : "";
|
|
1584
|
+
}
|
|
1585
|
+
var MARKDOWN_LINK = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
1586
|
+
function appendMarkdownText(el, text) {
|
|
1587
|
+
if (!text) return;
|
|
1588
|
+
MARKDOWN_LINK.lastIndex = 0;
|
|
1589
|
+
let lastIndex = 0;
|
|
1590
|
+
let match;
|
|
1591
|
+
while ((match = MARKDOWN_LINK.exec(text)) !== null) {
|
|
1592
|
+
if (match.index > lastIndex) {
|
|
1593
|
+
el.appendChild(document.createTextNode(text.slice(lastIndex, match.index)));
|
|
1594
|
+
}
|
|
1595
|
+
const [full, linkText, rawUrl] = match;
|
|
1596
|
+
const url = (rawUrl || "").trim();
|
|
1597
|
+
if (/^(https?:\/\/|mailto:|tel:|\/)/i.test(url)) {
|
|
1598
|
+
const link = document.createElement("a");
|
|
1599
|
+
link.href = url;
|
|
1600
|
+
link.textContent = linkText || "";
|
|
1601
|
+
link.style.color = "inherit";
|
|
1602
|
+
link.style.textDecoration = "underline";
|
|
1603
|
+
const sameSite = url.startsWith("/") && !url.startsWith("//") && !url.startsWith("/\\");
|
|
1604
|
+
if (!sameSite) {
|
|
1605
|
+
link.target = "_blank";
|
|
1606
|
+
link.rel = "noopener noreferrer";
|
|
1607
|
+
}
|
|
1608
|
+
el.appendChild(link);
|
|
1609
|
+
} else {
|
|
1610
|
+
el.appendChild(document.createTextNode(full));
|
|
1611
|
+
}
|
|
1612
|
+
lastIndex = MARKDOWN_LINK.lastIndex;
|
|
1613
|
+
}
|
|
1614
|
+
if (lastIndex < text.length) {
|
|
1615
|
+
el.appendChild(document.createTextNode(text.slice(lastIndex)));
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1342
1618
|
function sanitizeCssUrl(url) {
|
|
1343
1619
|
if (!isSafeUrl(url)) return null;
|
|
1344
1620
|
return url.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "").replace(/\r/g, "");
|