@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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  // src/types.ts
4
- var SDK_VERSION = "0.5.0";
4
+ var SDK_VERSION = "0.6.1";
5
5
 
6
6
  // src/client.ts
7
7
  var MAX_RETRIES = 3;
@@ -68,6 +68,28 @@ var HttpClient = class {
68
68
  }
69
69
  return this.parseJson(res);
70
70
  }
71
+ /**
72
+ * POST to a host other than the configured one, without the API key.
73
+ *
74
+ * A few public endpoints work out which Appspace they belong to from the
75
+ * hostname the request arrives on rather than from a key or an id, so a
76
+ * question about a link on a customer's own domain has to be asked on that
77
+ * domain. No key goes with it: the origin comes from a URL the caller was
78
+ * handed, which is not necessarily ours.
79
+ */
80
+ async postPublicToOrigin(origin, path, body) {
81
+ const res = await this.fetchWithRetry(origin.replace(/\/+$/, "") + path, {
82
+ method: "POST",
83
+ headers: { "Content-Type": "application/json" },
84
+ body: body ? JSON.stringify(body) : void 0,
85
+ signal: this.signal
86
+ });
87
+ if (!res.ok) {
88
+ const data = await res.json().catch(() => ({ error: res.statusText }));
89
+ throw new TolinkuError(data.error || res.statusText, res.status, data.code);
90
+ }
91
+ return this.parseJson(res);
92
+ }
71
93
  /** GET without API key auth (for public endpoints like banner config) */
72
94
  async getPublic(path, params) {
73
95
  let url = this._baseUrl + path;
@@ -646,6 +668,47 @@ function override(value) {
646
668
  return void 0;
647
669
  }
648
670
 
671
+ // src/links.ts
672
+ function isRoutablePath(path) {
673
+ return typeof path === "string" && path.startsWith("/") && !path.startsWith("//");
674
+ }
675
+ var Links = class {
676
+ constructor(client) {
677
+ this.client = client;
678
+ }
679
+ /**
680
+ * What this link means, or null if it means nothing here.
681
+ *
682
+ * The question goes to the link's own host, because that is how Tolinku knows
683
+ * which Appspace is being asked about, which also means a link on a domain
684
+ * that is not yours simply answers nothing.
685
+ *
686
+ * Never throws. A link that cannot be resolved, for a bad network or any
687
+ * other reason, is one to fall back to your own handling for.
688
+ */
689
+ async resolve(url) {
690
+ if (!url || typeof url !== "string") return null;
691
+ let parsed;
692
+ try {
693
+ parsed = new URL(url.trim());
694
+ } catch {
695
+ return null;
696
+ }
697
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
698
+ try {
699
+ const result = await this.client.postPublicToOrigin(
700
+ parsed.origin,
701
+ "/v1/api/path",
702
+ { path: parsed.pathname }
703
+ );
704
+ if (!result || !result.route || !isRoutablePath(result.deep_link_path)) return null;
705
+ return result;
706
+ } catch {
707
+ return null;
708
+ }
709
+ }
710
+ };
711
+
649
712
  // src/url-safety.ts
650
713
  function isSafeUrl(url) {
651
714
  if (typeof url !== "string") return false;
@@ -659,6 +722,19 @@ function isSafeUrl(url) {
659
722
  return false;
660
723
  }
661
724
  }
725
+ var EXECUTABLE_SCHEMES = /* @__PURE__ */ new Set(["javascript:", "vbscript:", "data:", "blob:", "file:"]);
726
+ function isNavigableUrl(url) {
727
+ if (typeof url !== "string") return false;
728
+ const trimmed = url.trim();
729
+ if (!trimmed) return false;
730
+ let parsed;
731
+ try {
732
+ parsed = new URL(trimmed);
733
+ } catch {
734
+ return true;
735
+ }
736
+ return !EXECUTABLE_SCHEMES.has(parsed.protocol);
737
+ }
662
738
 
663
739
  // src/storage.ts
664
740
  var BANNER_KEY = "tolinku_banner_dismissed";
@@ -1081,6 +1157,7 @@ var Messages = class {
1081
1157
  this.client = client;
1082
1158
  this.overlay = null;
1083
1159
  this.styleEl = null;
1160
+ this.app = null;
1084
1161
  }
1085
1162
  /** Fetch messages and show the highest-priority non-dismissed one */
1086
1163
  async show(options = {}, userId) {
@@ -1088,6 +1165,7 @@ var Messages = class {
1088
1165
  if (options.trigger) params.trigger = options.trigger;
1089
1166
  if (userId) params.user_id = userId;
1090
1167
  const data = await this.client.get("/v1/api/messages", params);
1168
+ this.app = data.app || null;
1091
1169
  if (!data.messages || data.messages.length === 0) return;
1092
1170
  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);
1093
1171
  if (candidates.length === 0) return;
@@ -1117,15 +1195,16 @@ var Messages = class {
1117
1195
  .tolk-msg-overlay {
1118
1196
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000000;
1119
1197
  display: flex; align-items: center; justify-content: center;
1198
+ padding: 24px 16px; box-sizing: border-box;
1120
1199
  background: rgba(0,0,0,0.5);
1121
1200
  opacity: 0; transition: opacity 0.3s ease;
1122
1201
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
1123
1202
  }
1124
1203
  .tolk-msg-overlay.tolk-visible { opacity: 1; }
1125
1204
  .tolk-msg-card {
1126
- position: relative; max-width: 375px; width: 90%;
1205
+ position: relative; width: 100%;
1127
1206
  max-height: 80vh; overflow-y: auto;
1128
- border-radius: 16px; padding: 24px;
1207
+ border-radius: 16px; box-sizing: border-box;
1129
1208
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
1130
1209
  }
1131
1210
  .tolk-msg-close {
@@ -1136,6 +1215,7 @@ var Messages = class {
1136
1215
  color: inherit; opacity: 0.6;
1137
1216
  }
1138
1217
  .tolk-msg-close:hover { opacity: 1; }
1218
+ .tolk-msg-card img { max-width: 100%; }
1139
1219
  `;
1140
1220
  const overlay = document.createElement("div");
1141
1221
  overlay.className = "tolk-msg-overlay";
@@ -1148,7 +1228,24 @@ var Messages = class {
1148
1228
  });
1149
1229
  const card = document.createElement("div");
1150
1230
  card.className = "tolk-msg-card";
1151
- card.style.background = sanitizeCssColor(message.background_color) || "#ffffff";
1231
+ const root = message.content && message.content.root && message.content.root.props || {};
1232
+ card.style.backgroundColor = sanitizeCssColor(root.bgColor) || sanitizeCssColor(message.background_color) || "#ffffff";
1233
+ if (root.bgGradient) {
1234
+ const gradient = safeGradient(String(root.bgGradient));
1235
+ if (gradient) card.style.backgroundImage = gradient;
1236
+ }
1237
+ if (root.bgImage) {
1238
+ const bgUrl = sanitizeCssUrl(root.bgImage);
1239
+ if (bgUrl) {
1240
+ card.style.backgroundImage = `url("${bgUrl}")`;
1241
+ card.style.backgroundSize = "cover";
1242
+ card.style.backgroundPosition = "center";
1243
+ card.style.backgroundRepeat = "no-repeat";
1244
+ }
1245
+ }
1246
+ card.style.padding = clamp(authoredNumber(root.padding, 20), 0, 200) + "px";
1247
+ card.style.maxWidth = clamp(authoredNumber(root.contentWidth, 480), 100, 2e3) + "px";
1248
+ overlay.style.alignItems = root.verticalAlign === "top" ? "flex-start" : "center";
1152
1249
  const closeBtn = document.createElement("button");
1153
1250
  closeBtn.className = "tolk-msg-close";
1154
1251
  closeBtn.setAttribute("aria-label", "Close message");
@@ -1159,10 +1256,37 @@ var Messages = class {
1159
1256
  this.dismiss();
1160
1257
  });
1161
1258
  card.appendChild(closeBtn);
1162
- if (message.content && message.content.content) {
1163
- for (const component of message.content.content) {
1164
- const el = this.renderComponent(component, message.id, options);
1165
- if (el) card.appendChild(el);
1259
+ const context = {
1260
+ messageId: message.id,
1261
+ options,
1262
+ zones: message.content?.zones,
1263
+ app: this.app
1264
+ };
1265
+ const content = Array.isArray(message.content?.content) ? message.content.content : [];
1266
+ for (const component of content) {
1267
+ const el = this.renderComponent(component, context);
1268
+ if (el) card.appendChild(el);
1269
+ }
1270
+ const drew = drawsAnything(content, context, 0);
1271
+ if (!drew) {
1272
+ if (message.title) {
1273
+ const titleEl = document.createElement("h2");
1274
+ titleEl.textContent = message.title;
1275
+ titleEl.style.fontSize = "24px";
1276
+ titleEl.style.fontWeight = "700";
1277
+ titleEl.style.color = "#1B1B1B";
1278
+ titleEl.style.lineHeight = "1.2";
1279
+ titleEl.style.margin = "0";
1280
+ card.appendChild(titleEl);
1281
+ }
1282
+ if (message.body) {
1283
+ const bodyEl = document.createElement("p");
1284
+ bodyEl.textContent = message.body;
1285
+ bodyEl.style.fontSize = "15px";
1286
+ bodyEl.style.color = "#555555";
1287
+ bodyEl.style.lineHeight = "1.5";
1288
+ bodyEl.style.margin = message.title ? "8px 0 0 0" : "0";
1289
+ card.appendChild(bodyEl);
1166
1290
  }
1167
1291
  }
1168
1292
  overlay.appendChild(card);
@@ -1176,108 +1300,323 @@ var Messages = class {
1176
1300
  });
1177
1301
  });
1178
1302
  }
1179
- renderComponent(component, messageId, options) {
1180
- const props = component.props;
1303
+ renderComponent(component, context, depth = 0) {
1304
+ if (!component || typeof component !== "object") return null;
1305
+ const props = component.props || {};
1181
1306
  switch (component.type) {
1182
1307
  case "Heading": {
1183
1308
  const el = document.createElement("h2");
1184
1309
  el.textContent = props.text || "";
1185
- el.style.fontSize = (props.fontSize || 28) + "px";
1310
+ el.style.fontSize = authoredNumber(props.fontSize, 28) + "px";
1186
1311
  el.style.fontWeight = "700";
1187
1312
  el.style.color = sanitizeCssColor(props.color) || "#1B1B1B";
1188
1313
  el.style.textAlign = sanitizeTextAlign(props.alignment);
1189
1314
  el.style.lineHeight = "1.2";
1190
- el.style.margin = "0 0 8px 0";
1315
+ el.style.margin = "0";
1191
1316
  return el;
1192
1317
  }
1193
1318
  case "TextBlock": {
1194
1319
  const el = document.createElement("p");
1195
- el.textContent = props.content || "";
1196
- el.style.fontSize = (props.fontSize || 15) + "px";
1320
+ appendMarkdownText(el, props.content || "");
1321
+ el.style.fontSize = authoredNumber(props.fontSize, 15) + "px";
1197
1322
  el.style.color = sanitizeCssColor(props.color) || "#555555";
1198
1323
  el.style.textAlign = sanitizeTextAlign(props.alignment);
1199
1324
  el.style.lineHeight = "1.5";
1200
- el.style.margin = "0 0 8px 0";
1325
+ el.style.margin = "0";
1201
1326
  return el;
1202
1327
  }
1203
1328
  case "Image": {
1204
1329
  const url = props.url || "";
1205
1330
  if (!isSafeUrl(url)) return null;
1331
+ const wrap = document.createElement("div");
1332
+ wrap.style.textAlign = "center";
1206
1333
  const el = document.createElement("img");
1207
1334
  el.src = url;
1208
1335
  el.alt = props.alt || "";
1209
- const width = props.width || "100%";
1210
- el.style.width = width.endsWith("px") || width.endsWith("%") ? width : width + "px";
1211
- el.style.borderRadius = (props.borderRadius || 8) + "px";
1212
- el.style.display = "block";
1213
- el.style.margin = "0 auto 8px auto";
1214
- return el;
1215
- }
1216
- case "Button": {
1217
- const el = document.createElement("button");
1218
- el.textContent = props.label || "Click";
1219
- el.style.backgroundColor = sanitizeCssColor(props.bgColor) || "#1B1B1B";
1220
- el.style.color = sanitizeCssColor(props.textColor) || "#ffffff";
1221
- el.style.fontSize = (props.fontSize || 16) + "px";
1222
- el.style.borderRadius = (props.borderRadius || 8) + "px";
1223
- el.style.border = "none";
1224
- el.style.padding = "10px 20px";
1225
- el.style.cursor = "pointer";
1226
- el.style.fontWeight = "600";
1227
- el.style.margin = "8px 0";
1228
- if (props.fullWidth) {
1229
- el.style.width = "100%";
1336
+ el.style.width = dimension(props.width) || "auto";
1337
+ el.style.height = dimension(props.height) || "auto";
1338
+ el.style.maxWidth = "100%";
1339
+ el.style.borderRadius = authoredNumber(props.borderRadius, 8) + "px";
1340
+ const borderWidth = authoredNumber(props.borderWidth, 0);
1341
+ if (borderWidth > 0) {
1342
+ el.style.border = `${borderWidth}px solid ${sanitizeCssColor(props.borderColor) || "#1B1B1B"}`;
1230
1343
  }
1231
- el.addEventListener("click", () => {
1232
- const action = props.action || "";
1233
- if (options.onButtonPress) {
1234
- options.onButtonPress(action, messageId);
1235
- } else if (action) {
1236
- if (isSafeUrl(action)) {
1237
- window.location.href = action;
1238
- }
1239
- }
1240
- });
1241
- return el;
1344
+ el.style.display = "inline-block";
1345
+ wrap.appendChild(el);
1346
+ return wrap;
1242
1347
  }
1348
+ case "Button":
1349
+ return this.renderButton(props, props.action || "", "Click", context);
1243
1350
  case "Section": {
1244
1351
  const el = document.createElement("div");
1245
1352
  if (props.bgColor) el.style.backgroundColor = sanitizeCssColor(props.bgColor) || "";
1246
- el.style.padding = (props.padding || 16) + "px";
1247
- el.style.borderRadius = (props.borderRadius || 0) + "px";
1248
- el.style.margin = "8px 0";
1353
+ el.style.padding = authoredNumber(props.padding, 16) + "px";
1354
+ el.style.borderRadius = authoredNumber(props.borderRadius, 0) + "px";
1355
+ el.style.minHeight = "60px";
1249
1356
  if (props.bgImage) {
1250
1357
  const sanitizedUrl = sanitizeCssUrl(props.bgImage);
1251
1358
  if (sanitizedUrl) {
1252
1359
  el.style.backgroundImage = `url("${sanitizedUrl}")`;
1253
1360
  el.style.backgroundSize = sanitizeBackgroundSize(props.bgSize);
1254
1361
  el.style.backgroundPosition = "center";
1362
+ el.style.backgroundRepeat = "no-repeat";
1255
1363
  }
1256
1364
  }
1257
- const children = props.children || [];
1258
- for (const child of children) {
1259
- const childEl = this.renderComponent(child, messageId, options);
1365
+ for (const child of sectionChildren(props, context, depth)) {
1366
+ const childEl = this.renderComponent(child, context, depth + 1);
1260
1367
  if (childEl) el.appendChild(childEl);
1261
1368
  }
1262
1369
  return el;
1263
1370
  }
1264
1371
  case "Spacer": {
1265
1372
  const el = document.createElement("div");
1266
- el.style.height = (props.height || 24) + "px";
1373
+ el.style.height = authoredNumber(props.height, 24) + "px";
1267
1374
  return el;
1268
1375
  }
1269
1376
  case "Divider": {
1270
1377
  const el = document.createElement("hr");
1271
1378
  el.style.border = "none";
1272
- el.style.borderTop = `${props.thickness || 1}px solid ${sanitizeCssColor(props.color) || "#e5e5e5"}`;
1273
- el.style.margin = "8px 0";
1379
+ el.style.borderTop = `${authoredNumber(props.thickness, 1)}px solid ${sanitizeCssColor(props.color) || "#e5e5e5"}`;
1380
+ el.style.margin = "0";
1274
1381
  return el;
1275
1382
  }
1383
+ case "AppIcon": {
1384
+ const wrap = document.createElement("div");
1385
+ wrap.style.textAlign = "center";
1386
+ const size = authoredNumber(props.size, 80);
1387
+ const borderRadius = authoredNumber(props.borderRadius, 16);
1388
+ const iconUrl = context.app?.icon_url || "";
1389
+ if (isSafeUrl(iconUrl)) {
1390
+ const img = document.createElement("img");
1391
+ img.src = iconUrl;
1392
+ img.alt = context.app?.name ? `${context.app.name} icon` : "App Icon";
1393
+ img.style.width = size + "px";
1394
+ img.style.height = size + "px";
1395
+ img.style.borderRadius = borderRadius + "px";
1396
+ img.style.objectFit = "cover";
1397
+ img.style.display = "inline-block";
1398
+ wrap.appendChild(img);
1399
+ } else {
1400
+ const placeholder = document.createElement("div");
1401
+ placeholder.style.width = size + "px";
1402
+ placeholder.style.height = size + "px";
1403
+ placeholder.style.borderRadius = borderRadius + "px";
1404
+ placeholder.style.background = "#f0f0f0";
1405
+ placeholder.style.display = "inline-block";
1406
+ wrap.appendChild(placeholder);
1407
+ }
1408
+ return wrap;
1409
+ }
1410
+ case "StoreButtons": {
1411
+ const iosUrl = props.iosUrlOverride || context.app?.ios_store_url || "";
1412
+ const androidUrl = props.androidUrlOverride || context.app?.android_store_url || "";
1413
+ const showIos = props.showIos !== false && isNavigableUrl(iosUrl);
1414
+ const showAndroid = props.showAndroid !== false && isNavigableUrl(androidUrl);
1415
+ if (!showIos && !showAndroid) return null;
1416
+ const row = document.createElement("div");
1417
+ row.style.display = "flex";
1418
+ row.style.gap = "12px";
1419
+ row.style.flexWrap = "wrap";
1420
+ row.style.justifyContent = props.alignment === "center" ? "center" : props.alignment === "right" ? "flex-end" : "flex-start";
1421
+ const height = authoredNumber(props.height, 44);
1422
+ if (showIos) {
1423
+ row.appendChild(storeBadge(iosUrl, context.app?.ios_badge_url, "Download on the App Store", height, context));
1424
+ }
1425
+ if (showAndroid) {
1426
+ row.appendChild(
1427
+ storeBadge(androidUrl, context.app?.android_badge_url, "Get it on Google Play", height, context)
1428
+ );
1429
+ }
1430
+ return row;
1431
+ }
1432
+ case "DeepLinkButton": {
1433
+ const deepLink = context.app?.deep_link_url || "";
1434
+ if (!isNavigableUrl(deepLink)) return null;
1435
+ return this.renderButton(props, deepLink, "Open in App", context);
1436
+ }
1276
1437
  default:
1277
1438
  return null;
1278
1439
  }
1279
1440
  }
1441
+ /** A Button, or a DeepLinkButton, which the builder styles the same way. */
1442
+ renderButton(props, action, defaultLabel, context) {
1443
+ const wrap = document.createElement("div");
1444
+ wrap.style.textAlign = "center";
1445
+ const el = document.createElement("button");
1446
+ const variant = props.style || "filled";
1447
+ const isOutline = variant === "outline";
1448
+ const baseColor = sanitizeCssColor(props.bgColor) || "#1B1B1B";
1449
+ const tint = variant === "soft" ? softVariant(baseColor) : null;
1450
+ const isSoft = tint !== null;
1451
+ el.style.backgroundColor = isOutline ? "transparent" : isSoft ? tint : baseColor;
1452
+ el.style.color = isOutline || isSoft ? baseColor : sanitizeCssColor(props.textColor) || "#ffffff";
1453
+ el.style.border = isOutline ? `2px solid ${baseColor}` : "none";
1454
+ el.style.fontSize = authoredNumber(props.fontSize, 16) + "px";
1455
+ el.style.borderRadius = authoredNumber(props.borderRadius, 8) + "px";
1456
+ el.style.padding = "12px 24px";
1457
+ el.style.cursor = "pointer";
1458
+ el.style.fontWeight = "600";
1459
+ el.style.textAlign = "center";
1460
+ el.style.boxSizing = "border-box";
1461
+ el.style.width = props.fullWidth ? "100%" : "auto";
1462
+ if (props.emoji) {
1463
+ const emoji = document.createElement("span");
1464
+ emoji.setAttribute("aria-hidden", "true");
1465
+ emoji.textContent = props.emoji;
1466
+ el.appendChild(emoji);
1467
+ el.appendChild(document.createTextNode(" "));
1468
+ }
1469
+ el.appendChild(document.createTextNode(props.label || defaultLabel));
1470
+ el.addEventListener("click", () => {
1471
+ if (action === "close") {
1472
+ saveMessageDismissal(context.messageId);
1473
+ context.options.onDismiss?.(context.messageId);
1474
+ this.dismiss();
1475
+ return;
1476
+ }
1477
+ if (action && !isNavigableUrl(action)) return;
1478
+ if (context.options.onButtonPress) {
1479
+ context.options.onButtonPress(action, context.messageId);
1480
+ } else if (action) {
1481
+ window.location.href = action;
1482
+ }
1483
+ });
1484
+ wrap.appendChild(el);
1485
+ return wrap;
1486
+ }
1280
1487
  };
1488
+ var MAX_SECTION_DEPTH = 20;
1489
+ var SUPPORTED = /* @__PURE__ */ new Set([
1490
+ "Heading",
1491
+ "TextBlock",
1492
+ "Image",
1493
+ "Button",
1494
+ "Section",
1495
+ "Spacer",
1496
+ "Divider",
1497
+ "AppIcon",
1498
+ "StoreButtons",
1499
+ "DeepLinkButton"
1500
+ ]);
1501
+ function sectionChildren(props, context, depth) {
1502
+ const sectionId = typeof props.id === "string" && props.id ? props.id : null;
1503
+ if (!sectionId || depth >= MAX_SECTION_DEPTH) return [];
1504
+ const children = context.zones?.[`${sectionId}:content`];
1505
+ return Array.isArray(children) ? children : [];
1506
+ }
1507
+ function drawsAnything(content, context, depth) {
1508
+ return content.some((component) => {
1509
+ if (!component || typeof component !== "object" || !SUPPORTED.has(component.type)) return false;
1510
+ const props = component.props || {};
1511
+ switch (component.type) {
1512
+ case "Image":
1513
+ return isSafeUrl(props.url || "");
1514
+ case "DeepLinkButton":
1515
+ return isNavigableUrl(context.app?.deep_link_url || "");
1516
+ case "StoreButtons": {
1517
+ const ios = props.iosUrlOverride || context.app?.ios_store_url || "";
1518
+ const android = props.androidUrlOverride || context.app?.android_store_url || "";
1519
+ return props.showIos !== false && isNavigableUrl(ios) || props.showAndroid !== false && isNavigableUrl(android);
1520
+ }
1521
+ case "Section":
1522
+ return drawsAnything(sectionChildren(props, context, depth), context, depth + 1);
1523
+ default:
1524
+ return true;
1525
+ }
1526
+ });
1527
+ }
1528
+ function storeBadge(url, badgeUrl, label, height, context) {
1529
+ const link = document.createElement("a");
1530
+ link.href = url;
1531
+ link.style.display = "inline-block";
1532
+ link.addEventListener("click", (event) => {
1533
+ if (!context.options.onButtonPress) return;
1534
+ event.preventDefault();
1535
+ context.options.onButtonPress(url, context.messageId);
1536
+ });
1537
+ if (isSafeUrl(badgeUrl)) {
1538
+ const img = document.createElement("img");
1539
+ img.src = badgeUrl;
1540
+ img.alt = label;
1541
+ img.style.height = height + "px";
1542
+ img.style.display = "block";
1543
+ link.appendChild(img);
1544
+ } else {
1545
+ link.textContent = label;
1546
+ link.style.lineHeight = height + "px";
1547
+ link.style.fontSize = "14px";
1548
+ link.style.fontWeight = "600";
1549
+ link.style.color = "inherit";
1550
+ }
1551
+ return link;
1552
+ }
1553
+ function authoredNumber(value, fallback) {
1554
+ const parsed = typeof value === "number" ? value : parseFloat(String(value ?? ""));
1555
+ if (!isFinite(parsed)) return fallback;
1556
+ return Math.max(0, parsed);
1557
+ }
1558
+ function clamp(value, min, max) {
1559
+ return Math.min(max, Math.max(min, value));
1560
+ }
1561
+ function dimension(raw) {
1562
+ if (typeof raw === "number") return isFinite(raw) ? `${raw}px` : null;
1563
+ if (typeof raw !== "string") return null;
1564
+ const value = raw.trim();
1565
+ if (!value || value.toLowerCase() === "auto") return null;
1566
+ if (/^\d+(?:\.\d+)?%$/.test(value)) return value;
1567
+ const match = /^(\d+(?:\.\d+)?)(?:px)?$/i.exec(value);
1568
+ return match ? `${match[1]}px` : null;
1569
+ }
1570
+ function softVariant(color) {
1571
+ if (/^#[0-9a-f]{6}$/i.test(color)) return color + "22";
1572
+ if (/^#[0-9a-f]{3}$/i.test(color)) {
1573
+ return "#" + color[1] + color[1] + color[2] + color[2] + color[3] + color[3] + "22";
1574
+ }
1575
+ return null;
1576
+ }
1577
+ function cssVal(value) {
1578
+ const cleaned = String(value).replace(/[;{}<>"'`\\]/g, "");
1579
+ if (/javascript:|expression\s*\(/i.test(cleaned)) return "";
1580
+ return cleaned;
1581
+ }
1582
+ var GRADIENT_FUNCTION = /^(?:repeating-)?(?:linear|radial|conic)-gradient\(/i;
1583
+ function safeGradient(value) {
1584
+ const cleaned = cssVal(value).trim();
1585
+ return GRADIENT_FUNCTION.test(cleaned) ? cleaned : "";
1586
+ }
1587
+ var MARKDOWN_LINK = /\[([^\]]+)\]\(([^)]+)\)/g;
1588
+ function appendMarkdownText(el, text) {
1589
+ if (!text) return;
1590
+ MARKDOWN_LINK.lastIndex = 0;
1591
+ let lastIndex = 0;
1592
+ let match;
1593
+ while ((match = MARKDOWN_LINK.exec(text)) !== null) {
1594
+ if (match.index > lastIndex) {
1595
+ el.appendChild(document.createTextNode(text.slice(lastIndex, match.index)));
1596
+ }
1597
+ const [full, linkText, rawUrl] = match;
1598
+ const url = (rawUrl || "").trim();
1599
+ if (/^(https?:\/\/|mailto:|tel:|\/)/i.test(url)) {
1600
+ const link = document.createElement("a");
1601
+ link.href = url;
1602
+ link.textContent = linkText || "";
1603
+ link.style.color = "inherit";
1604
+ link.style.textDecoration = "underline";
1605
+ const sameSite = url.startsWith("/") && !url.startsWith("//") && !url.startsWith("/\\");
1606
+ if (!sameSite) {
1607
+ link.target = "_blank";
1608
+ link.rel = "noopener noreferrer";
1609
+ }
1610
+ el.appendChild(link);
1611
+ } else {
1612
+ el.appendChild(document.createTextNode(full));
1613
+ }
1614
+ lastIndex = MARKDOWN_LINK.lastIndex;
1615
+ }
1616
+ if (lastIndex < text.length) {
1617
+ el.appendChild(document.createTextNode(text.slice(lastIndex)));
1618
+ }
1619
+ }
1281
1620
  function sanitizeCssUrl(url) {
1282
1621
  if (!isSafeUrl(url)) return null;
1283
1622
  return url.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "").replace(/\r/g, "");
@@ -1328,6 +1667,7 @@ var Tolinku = class {
1328
1667
  this.ecommerce = new Ecommerce(this.client, () => this._userId);
1329
1668
  this.referrals = new Referrals(this.client);
1330
1669
  this.deferred = new Deferred(this.client);
1670
+ this.links = new Links(this.client);
1331
1671
  this.banners = new Banners(this.client);
1332
1672
  this.messages = new Messages(this.client);
1333
1673
  }