@tolinku/web-sdk 0.5.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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/types.ts
2
- var SDK_VERSION = "0.5.0";
2
+ var SDK_VERSION = "0.6.1";
3
3
 
4
4
  // src/client.ts
5
5
  var MAX_RETRIES = 3;
@@ -66,6 +66,28 @@ var HttpClient = class {
66
66
  }
67
67
  return this.parseJson(res);
68
68
  }
69
+ /**
70
+ * POST to a host other than the configured one, without the API key.
71
+ *
72
+ * A few public endpoints work out which Appspace they belong to from the
73
+ * hostname the request arrives on rather than from a key or an id, so a
74
+ * question about a link on a customer's own domain has to be asked on that
75
+ * domain. No key goes with it: the origin comes from a URL the caller was
76
+ * handed, which is not necessarily ours.
77
+ */
78
+ async postPublicToOrigin(origin, path, body) {
79
+ const res = await this.fetchWithRetry(origin.replace(/\/+$/, "") + path, {
80
+ method: "POST",
81
+ headers: { "Content-Type": "application/json" },
82
+ body: body ? JSON.stringify(body) : void 0,
83
+ signal: this.signal
84
+ });
85
+ if (!res.ok) {
86
+ const data = await res.json().catch(() => ({ error: res.statusText }));
87
+ throw new TolinkuError(data.error || res.statusText, res.status, data.code);
88
+ }
89
+ return this.parseJson(res);
90
+ }
69
91
  /** GET without API key auth (for public endpoints like banner config) */
70
92
  async getPublic(path, params) {
71
93
  let url = this._baseUrl + path;
@@ -644,6 +666,47 @@ function override(value) {
644
666
  return void 0;
645
667
  }
646
668
 
669
+ // src/links.ts
670
+ function isRoutablePath(path) {
671
+ return typeof path === "string" && path.startsWith("/") && !path.startsWith("//");
672
+ }
673
+ var Links = class {
674
+ constructor(client) {
675
+ this.client = client;
676
+ }
677
+ /**
678
+ * What this link means, or null if it means nothing here.
679
+ *
680
+ * The question goes to the link's own host, because that is how Tolinku knows
681
+ * which Appspace is being asked about, which also means a link on a domain
682
+ * that is not yours simply answers nothing.
683
+ *
684
+ * Never throws. A link that cannot be resolved, for a bad network or any
685
+ * other reason, is one to fall back to your own handling for.
686
+ */
687
+ async resolve(url) {
688
+ if (!url || typeof url !== "string") return null;
689
+ let parsed;
690
+ try {
691
+ parsed = new URL(url.trim());
692
+ } catch {
693
+ return null;
694
+ }
695
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
696
+ try {
697
+ const result = await this.client.postPublicToOrigin(
698
+ parsed.origin,
699
+ "/v1/api/path",
700
+ { path: parsed.pathname }
701
+ );
702
+ if (!result || !result.route || !isRoutablePath(result.deep_link_path)) return null;
703
+ return result;
704
+ } catch {
705
+ return null;
706
+ }
707
+ }
708
+ };
709
+
647
710
  // src/url-safety.ts
648
711
  function isSafeUrl(url) {
649
712
  if (typeof url !== "string") return false;
@@ -657,6 +720,19 @@ function isSafeUrl(url) {
657
720
  return false;
658
721
  }
659
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
+ }
660
736
 
661
737
  // src/storage.ts
662
738
  var BANNER_KEY = "tolinku_banner_dismissed";
@@ -1079,6 +1155,7 @@ var Messages = class {
1079
1155
  this.client = client;
1080
1156
  this.overlay = null;
1081
1157
  this.styleEl = null;
1158
+ this.app = null;
1082
1159
  }
1083
1160
  /** Fetch messages and show the highest-priority non-dismissed one */
1084
1161
  async show(options = {}, userId) {
@@ -1086,6 +1163,7 @@ var Messages = class {
1086
1163
  if (options.trigger) params.trigger = options.trigger;
1087
1164
  if (userId) params.user_id = userId;
1088
1165
  const data = await this.client.get("/v1/api/messages", params);
1166
+ this.app = data.app || null;
1089
1167
  if (!data.messages || data.messages.length === 0) return;
1090
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);
1091
1169
  if (candidates.length === 0) return;
@@ -1115,15 +1193,16 @@ var Messages = class {
1115
1193
  .tolk-msg-overlay {
1116
1194
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000000;
1117
1195
  display: flex; align-items: center; justify-content: center;
1196
+ padding: 24px 16px; box-sizing: border-box;
1118
1197
  background: rgba(0,0,0,0.5);
1119
1198
  opacity: 0; transition: opacity 0.3s ease;
1120
1199
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
1121
1200
  }
1122
1201
  .tolk-msg-overlay.tolk-visible { opacity: 1; }
1123
1202
  .tolk-msg-card {
1124
- position: relative; max-width: 375px; width: 90%;
1203
+ position: relative; width: 100%;
1125
1204
  max-height: 80vh; overflow-y: auto;
1126
- border-radius: 16px; padding: 24px;
1205
+ border-radius: 16px; box-sizing: border-box;
1127
1206
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
1128
1207
  }
1129
1208
  .tolk-msg-close {
@@ -1134,6 +1213,7 @@ var Messages = class {
1134
1213
  color: inherit; opacity: 0.6;
1135
1214
  }
1136
1215
  .tolk-msg-close:hover { opacity: 1; }
1216
+ .tolk-msg-card img { max-width: 100%; }
1137
1217
  `;
1138
1218
  const overlay = document.createElement("div");
1139
1219
  overlay.className = "tolk-msg-overlay";
@@ -1146,7 +1226,24 @@ var Messages = class {
1146
1226
  });
1147
1227
  const card = document.createElement("div");
1148
1228
  card.className = "tolk-msg-card";
1149
- card.style.background = sanitizeCssColor(message.background_color) || "#ffffff";
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";
1150
1247
  const closeBtn = document.createElement("button");
1151
1248
  closeBtn.className = "tolk-msg-close";
1152
1249
  closeBtn.setAttribute("aria-label", "Close message");
@@ -1157,10 +1254,37 @@ var Messages = class {
1157
1254
  this.dismiss();
1158
1255
  });
1159
1256
  card.appendChild(closeBtn);
1160
- if (message.content && message.content.content) {
1161
- for (const component of message.content.content) {
1162
- const el = this.renderComponent(component, message.id, options);
1163
- if (el) card.appendChild(el);
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);
1164
1288
  }
1165
1289
  }
1166
1290
  overlay.appendChild(card);
@@ -1174,108 +1298,323 @@ var Messages = class {
1174
1298
  });
1175
1299
  });
1176
1300
  }
1177
- renderComponent(component, messageId, options) {
1178
- const props = component.props;
1301
+ renderComponent(component, context, depth = 0) {
1302
+ if (!component || typeof component !== "object") return null;
1303
+ const props = component.props || {};
1179
1304
  switch (component.type) {
1180
1305
  case "Heading": {
1181
1306
  const el = document.createElement("h2");
1182
1307
  el.textContent = props.text || "";
1183
- el.style.fontSize = (props.fontSize || 28) + "px";
1308
+ el.style.fontSize = authoredNumber(props.fontSize, 28) + "px";
1184
1309
  el.style.fontWeight = "700";
1185
1310
  el.style.color = sanitizeCssColor(props.color) || "#1B1B1B";
1186
1311
  el.style.textAlign = sanitizeTextAlign(props.alignment);
1187
1312
  el.style.lineHeight = "1.2";
1188
- el.style.margin = "0 0 8px 0";
1313
+ el.style.margin = "0";
1189
1314
  return el;
1190
1315
  }
1191
1316
  case "TextBlock": {
1192
1317
  const el = document.createElement("p");
1193
- el.textContent = props.content || "";
1194
- el.style.fontSize = (props.fontSize || 15) + "px";
1318
+ appendMarkdownText(el, props.content || "");
1319
+ el.style.fontSize = authoredNumber(props.fontSize, 15) + "px";
1195
1320
  el.style.color = sanitizeCssColor(props.color) || "#555555";
1196
1321
  el.style.textAlign = sanitizeTextAlign(props.alignment);
1197
1322
  el.style.lineHeight = "1.5";
1198
- el.style.margin = "0 0 8px 0";
1323
+ el.style.margin = "0";
1199
1324
  return el;
1200
1325
  }
1201
1326
  case "Image": {
1202
1327
  const url = props.url || "";
1203
1328
  if (!isSafeUrl(url)) return null;
1329
+ const wrap = document.createElement("div");
1330
+ wrap.style.textAlign = "center";
1204
1331
  const el = document.createElement("img");
1205
1332
  el.src = url;
1206
1333
  el.alt = props.alt || "";
1207
- const width = props.width || "100%";
1208
- el.style.width = width.endsWith("px") || width.endsWith("%") ? width : width + "px";
1209
- el.style.borderRadius = (props.borderRadius || 8) + "px";
1210
- el.style.display = "block";
1211
- el.style.margin = "0 auto 8px auto";
1212
- return el;
1213
- }
1214
- case "Button": {
1215
- const el = document.createElement("button");
1216
- el.textContent = props.label || "Click";
1217
- el.style.backgroundColor = sanitizeCssColor(props.bgColor) || "#1B1B1B";
1218
- el.style.color = sanitizeCssColor(props.textColor) || "#ffffff";
1219
- el.style.fontSize = (props.fontSize || 16) + "px";
1220
- el.style.borderRadius = (props.borderRadius || 8) + "px";
1221
- el.style.border = "none";
1222
- el.style.padding = "10px 20px";
1223
- el.style.cursor = "pointer";
1224
- el.style.fontWeight = "600";
1225
- el.style.margin = "8px 0";
1226
- if (props.fullWidth) {
1227
- 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"}`;
1228
1341
  }
1229
- el.addEventListener("click", () => {
1230
- const action = props.action || "";
1231
- if (options.onButtonPress) {
1232
- options.onButtonPress(action, messageId);
1233
- } else if (action) {
1234
- if (isSafeUrl(action)) {
1235
- window.location.href = action;
1236
- }
1237
- }
1238
- });
1239
- return el;
1342
+ el.style.display = "inline-block";
1343
+ wrap.appendChild(el);
1344
+ return wrap;
1240
1345
  }
1346
+ case "Button":
1347
+ return this.renderButton(props, props.action || "", "Click", context);
1241
1348
  case "Section": {
1242
1349
  const el = document.createElement("div");
1243
1350
  if (props.bgColor) el.style.backgroundColor = sanitizeCssColor(props.bgColor) || "";
1244
- el.style.padding = (props.padding || 16) + "px";
1245
- el.style.borderRadius = (props.borderRadius || 0) + "px";
1246
- el.style.margin = "8px 0";
1351
+ el.style.padding = authoredNumber(props.padding, 16) + "px";
1352
+ el.style.borderRadius = authoredNumber(props.borderRadius, 0) + "px";
1353
+ el.style.minHeight = "60px";
1247
1354
  if (props.bgImage) {
1248
1355
  const sanitizedUrl = sanitizeCssUrl(props.bgImage);
1249
1356
  if (sanitizedUrl) {
1250
1357
  el.style.backgroundImage = `url("${sanitizedUrl}")`;
1251
1358
  el.style.backgroundSize = sanitizeBackgroundSize(props.bgSize);
1252
1359
  el.style.backgroundPosition = "center";
1360
+ el.style.backgroundRepeat = "no-repeat";
1253
1361
  }
1254
1362
  }
1255
- const children = props.children || [];
1256
- for (const child of children) {
1257
- 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);
1258
1365
  if (childEl) el.appendChild(childEl);
1259
1366
  }
1260
1367
  return el;
1261
1368
  }
1262
1369
  case "Spacer": {
1263
1370
  const el = document.createElement("div");
1264
- el.style.height = (props.height || 24) + "px";
1371
+ el.style.height = authoredNumber(props.height, 24) + "px";
1265
1372
  return el;
1266
1373
  }
1267
1374
  case "Divider": {
1268
1375
  const el = document.createElement("hr");
1269
1376
  el.style.border = "none";
1270
- el.style.borderTop = `${props.thickness || 1}px solid ${sanitizeCssColor(props.color) || "#e5e5e5"}`;
1271
- el.style.margin = "8px 0";
1377
+ el.style.borderTop = `${authoredNumber(props.thickness, 1)}px solid ${sanitizeCssColor(props.color) || "#e5e5e5"}`;
1378
+ el.style.margin = "0";
1272
1379
  return el;
1273
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
+ }
1274
1435
  default:
1275
1436
  return null;
1276
1437
  }
1277
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
+ }
1278
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
+ }
1279
1618
  function sanitizeCssUrl(url) {
1280
1619
  if (!isSafeUrl(url)) return null;
1281
1620
  return url.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "").replace(/\r/g, "");
@@ -1326,6 +1665,7 @@ var Tolinku = class {
1326
1665
  this.ecommerce = new Ecommerce(this.client, () => this._userId);
1327
1666
  this.referrals = new Referrals(this.client);
1328
1667
  this.deferred = new Deferred(this.client);
1668
+ this.links = new Links(this.client);
1329
1669
  this.banners = new Banners(this.client);
1330
1670
  this.messages = new Messages(this.client);
1331
1671
  }