@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 CHANGED
@@ -179,16 +179,40 @@ interface Message {
179
179
  }
180
180
  /** Puck component content tree */
181
181
  interface MessageContent {
182
- root: {
183
- props: Record<string, unknown>;
182
+ root?: {
183
+ props?: Record<string, unknown>;
184
184
  };
185
185
  content: MessageComponent[];
186
+ /**
187
+ * Where a Section's children actually live.
188
+ *
189
+ * Puck stores the contents of a drop zone here, keyed `<component id>:content`,
190
+ * and never writes `props.children`. A renderer that reads `props.children`
191
+ * draws every Section as an empty box and loses everything inside it.
192
+ */
193
+ zones?: Record<string, MessageComponent[]>;
186
194
  }
187
195
  /** A single Puck component */
188
196
  interface MessageComponent {
189
197
  type: string;
190
198
  props: Record<string, unknown>;
191
199
  }
200
+ /**
201
+ * The app a message belongs to, sent alongside the messages.
202
+ *
203
+ * AppIcon, StoreButtons and DeepLinkButton describe the app rather than the
204
+ * message, so the content itself carries nothing to draw them from.
205
+ */
206
+ interface MessageAppContext {
207
+ name: string;
208
+ icon_url: string | null;
209
+ ios_store_url: string | null;
210
+ android_store_url: string | null;
211
+ deep_link_url: string | null;
212
+ /** The store badge artwork, absolute and PNG, served by the API host. */
213
+ ios_badge_url?: string | null;
214
+ android_badge_url?: string | null;
215
+ }
192
216
  /** Options for showing an in-app message */
193
217
  interface ShowMessageOptions {
194
218
  trigger?: string;
@@ -545,4 +569,4 @@ declare class Tolinku {
545
569
  destroy(): void;
546
570
  }
547
571
 
548
- export { type AddPaymentInfoParams, type AddToCartParams, type AddToWishlistParams, type BannerConfig, type BannerItem, type BeginCheckoutParams, type ClaimBySignalsOptions, type CompleteReferralOptions, type CompleteReferralResult, type CreateReferralOptions, type CreateReferralResult, type DeferredLink, type EcommerceItem, type LeaderboardEntry, type Message, type MessageComponent, type MessageContent, type MilestoneOptions, type MilestoneResult, type PurchaseParams, type RateParams, type ReferralInfo, type RefundParams, type RemoveFromCartParams, type ResolvedLink, type SearchParams, type ShareParams, type ShowBannerOptions, type ShowMessageOptions, type SpendCreditsParams, Tolinku, type TolinkuConfig, TolinkuError, type TrackProperties, type ViewItemParams };
572
+ export { type AddPaymentInfoParams, type AddToCartParams, type AddToWishlistParams, type BannerConfig, type BannerItem, type BeginCheckoutParams, type ClaimBySignalsOptions, type CompleteReferralOptions, type CompleteReferralResult, type CreateReferralOptions, type CreateReferralResult, type DeferredLink, type EcommerceItem, type LeaderboardEntry, type Message, type MessageAppContext, type MessageComponent, type MessageContent, type MilestoneOptions, type MilestoneResult, type PurchaseParams, type RateParams, type ReferralInfo, type RefundParams, type RemoveFromCartParams, type ResolvedLink, type SearchParams, type ShareParams, type ShowBannerOptions, type ShowMessageOptions, type SpendCreditsParams, Tolinku, type TolinkuConfig, TolinkuError, type TrackProperties, type ViewItemParams };
package/dist/index.d.ts CHANGED
@@ -179,16 +179,40 @@ interface Message {
179
179
  }
180
180
  /** Puck component content tree */
181
181
  interface MessageContent {
182
- root: {
183
- props: Record<string, unknown>;
182
+ root?: {
183
+ props?: Record<string, unknown>;
184
184
  };
185
185
  content: MessageComponent[];
186
+ /**
187
+ * Where a Section's children actually live.
188
+ *
189
+ * Puck stores the contents of a drop zone here, keyed `<component id>:content`,
190
+ * and never writes `props.children`. A renderer that reads `props.children`
191
+ * draws every Section as an empty box and loses everything inside it.
192
+ */
193
+ zones?: Record<string, MessageComponent[]>;
186
194
  }
187
195
  /** A single Puck component */
188
196
  interface MessageComponent {
189
197
  type: string;
190
198
  props: Record<string, unknown>;
191
199
  }
200
+ /**
201
+ * The app a message belongs to, sent alongside the messages.
202
+ *
203
+ * AppIcon, StoreButtons and DeepLinkButton describe the app rather than the
204
+ * message, so the content itself carries nothing to draw them from.
205
+ */
206
+ interface MessageAppContext {
207
+ name: string;
208
+ icon_url: string | null;
209
+ ios_store_url: string | null;
210
+ android_store_url: string | null;
211
+ deep_link_url: string | null;
212
+ /** The store badge artwork, absolute and PNG, served by the API host. */
213
+ ios_badge_url?: string | null;
214
+ android_badge_url?: string | null;
215
+ }
192
216
  /** Options for showing an in-app message */
193
217
  interface ShowMessageOptions {
194
218
  trigger?: string;
@@ -545,4 +569,4 @@ declare class Tolinku {
545
569
  destroy(): void;
546
570
  }
547
571
 
548
- export { type AddPaymentInfoParams, type AddToCartParams, type AddToWishlistParams, type BannerConfig, type BannerItem, type BeginCheckoutParams, type ClaimBySignalsOptions, type CompleteReferralOptions, type CompleteReferralResult, type CreateReferralOptions, type CreateReferralResult, type DeferredLink, type EcommerceItem, type LeaderboardEntry, type Message, type MessageComponent, type MessageContent, type MilestoneOptions, type MilestoneResult, type PurchaseParams, type RateParams, type ReferralInfo, type RefundParams, type RemoveFromCartParams, type ResolvedLink, type SearchParams, type ShareParams, type ShowBannerOptions, type ShowMessageOptions, type SpendCreditsParams, Tolinku, type TolinkuConfig, TolinkuError, type TrackProperties, type ViewItemParams };
572
+ export { type AddPaymentInfoParams, type AddToCartParams, type AddToWishlistParams, type BannerConfig, type BannerItem, type BeginCheckoutParams, type ClaimBySignalsOptions, type CompleteReferralOptions, type CompleteReferralResult, type CreateReferralOptions, type CreateReferralResult, type DeferredLink, type EcommerceItem, type LeaderboardEntry, type Message, type MessageAppContext, type MessageComponent, type MessageContent, type MilestoneOptions, type MilestoneResult, type PurchaseParams, type RateParams, type ReferralInfo, type RefundParams, type RemoveFromCartParams, type ResolvedLink, type SearchParams, type ShareParams, type ShowBannerOptions, type ShowMessageOptions, type SpendCreditsParams, Tolinku, type TolinkuConfig, TolinkuError, type TrackProperties, type ViewItemParams };
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.6.0";
4
+ var SDK_VERSION = "0.6.1";
5
5
 
6
6
  // src/client.ts
7
7
  var MAX_RETRIES = 3;
@@ -722,6 +722,19 @@ function isSafeUrl(url) {
722
722
  return false;
723
723
  }
724
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
+ }
725
738
 
726
739
  // src/storage.ts
727
740
  var BANNER_KEY = "tolinku_banner_dismissed";
@@ -1144,6 +1157,7 @@ var Messages = class {
1144
1157
  this.client = client;
1145
1158
  this.overlay = null;
1146
1159
  this.styleEl = null;
1160
+ this.app = null;
1147
1161
  }
1148
1162
  /** Fetch messages and show the highest-priority non-dismissed one */
1149
1163
  async show(options = {}, userId) {
@@ -1151,6 +1165,7 @@ var Messages = class {
1151
1165
  if (options.trigger) params.trigger = options.trigger;
1152
1166
  if (userId) params.user_id = userId;
1153
1167
  const data = await this.client.get("/v1/api/messages", params);
1168
+ this.app = data.app || null;
1154
1169
  if (!data.messages || data.messages.length === 0) return;
1155
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);
1156
1171
  if (candidates.length === 0) return;
@@ -1180,15 +1195,16 @@ var Messages = class {
1180
1195
  .tolk-msg-overlay {
1181
1196
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000000;
1182
1197
  display: flex; align-items: center; justify-content: center;
1198
+ padding: 24px 16px; box-sizing: border-box;
1183
1199
  background: rgba(0,0,0,0.5);
1184
1200
  opacity: 0; transition: opacity 0.3s ease;
1185
1201
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
1186
1202
  }
1187
1203
  .tolk-msg-overlay.tolk-visible { opacity: 1; }
1188
1204
  .tolk-msg-card {
1189
- position: relative; max-width: 375px; width: 90%;
1205
+ position: relative; width: 100%;
1190
1206
  max-height: 80vh; overflow-y: auto;
1191
- border-radius: 16px; padding: 24px;
1207
+ border-radius: 16px; box-sizing: border-box;
1192
1208
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
1193
1209
  }
1194
1210
  .tolk-msg-close {
@@ -1199,6 +1215,7 @@ var Messages = class {
1199
1215
  color: inherit; opacity: 0.6;
1200
1216
  }
1201
1217
  .tolk-msg-close:hover { opacity: 1; }
1218
+ .tolk-msg-card img { max-width: 100%; }
1202
1219
  `;
1203
1220
  const overlay = document.createElement("div");
1204
1221
  overlay.className = "tolk-msg-overlay";
@@ -1211,7 +1228,24 @@ var Messages = class {
1211
1228
  });
1212
1229
  const card = document.createElement("div");
1213
1230
  card.className = "tolk-msg-card";
1214
- 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";
1215
1249
  const closeBtn = document.createElement("button");
1216
1250
  closeBtn.className = "tolk-msg-close";
1217
1251
  closeBtn.setAttribute("aria-label", "Close message");
@@ -1222,10 +1256,37 @@ var Messages = class {
1222
1256
  this.dismiss();
1223
1257
  });
1224
1258
  card.appendChild(closeBtn);
1225
- if (message.content && message.content.content) {
1226
- for (const component of message.content.content) {
1227
- const el = this.renderComponent(component, message.id, options);
1228
- 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);
1229
1290
  }
1230
1291
  }
1231
1292
  overlay.appendChild(card);
@@ -1239,108 +1300,323 @@ var Messages = class {
1239
1300
  });
1240
1301
  });
1241
1302
  }
1242
- renderComponent(component, messageId, options) {
1243
- const props = component.props;
1303
+ renderComponent(component, context, depth = 0) {
1304
+ if (!component || typeof component !== "object") return null;
1305
+ const props = component.props || {};
1244
1306
  switch (component.type) {
1245
1307
  case "Heading": {
1246
1308
  const el = document.createElement("h2");
1247
1309
  el.textContent = props.text || "";
1248
- el.style.fontSize = (props.fontSize || 28) + "px";
1310
+ el.style.fontSize = authoredNumber(props.fontSize, 28) + "px";
1249
1311
  el.style.fontWeight = "700";
1250
1312
  el.style.color = sanitizeCssColor(props.color) || "#1B1B1B";
1251
1313
  el.style.textAlign = sanitizeTextAlign(props.alignment);
1252
1314
  el.style.lineHeight = "1.2";
1253
- el.style.margin = "0 0 8px 0";
1315
+ el.style.margin = "0";
1254
1316
  return el;
1255
1317
  }
1256
1318
  case "TextBlock": {
1257
1319
  const el = document.createElement("p");
1258
- el.textContent = props.content || "";
1259
- el.style.fontSize = (props.fontSize || 15) + "px";
1320
+ appendMarkdownText(el, props.content || "");
1321
+ el.style.fontSize = authoredNumber(props.fontSize, 15) + "px";
1260
1322
  el.style.color = sanitizeCssColor(props.color) || "#555555";
1261
1323
  el.style.textAlign = sanitizeTextAlign(props.alignment);
1262
1324
  el.style.lineHeight = "1.5";
1263
- el.style.margin = "0 0 8px 0";
1325
+ el.style.margin = "0";
1264
1326
  return el;
1265
1327
  }
1266
1328
  case "Image": {
1267
1329
  const url = props.url || "";
1268
1330
  if (!isSafeUrl(url)) return null;
1331
+ const wrap = document.createElement("div");
1332
+ wrap.style.textAlign = "center";
1269
1333
  const el = document.createElement("img");
1270
1334
  el.src = url;
1271
1335
  el.alt = props.alt || "";
1272
- const width = props.width || "100%";
1273
- el.style.width = width.endsWith("px") || width.endsWith("%") ? width : width + "px";
1274
- el.style.borderRadius = (props.borderRadius || 8) + "px";
1275
- el.style.display = "block";
1276
- el.style.margin = "0 auto 8px auto";
1277
- return el;
1278
- }
1279
- case "Button": {
1280
- const el = document.createElement("button");
1281
- el.textContent = props.label || "Click";
1282
- el.style.backgroundColor = sanitizeCssColor(props.bgColor) || "#1B1B1B";
1283
- el.style.color = sanitizeCssColor(props.textColor) || "#ffffff";
1284
- el.style.fontSize = (props.fontSize || 16) + "px";
1285
- el.style.borderRadius = (props.borderRadius || 8) + "px";
1286
- el.style.border = "none";
1287
- el.style.padding = "10px 20px";
1288
- el.style.cursor = "pointer";
1289
- el.style.fontWeight = "600";
1290
- el.style.margin = "8px 0";
1291
- if (props.fullWidth) {
1292
- 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"}`;
1293
1343
  }
1294
- el.addEventListener("click", () => {
1295
- const action = props.action || "";
1296
- if (options.onButtonPress) {
1297
- options.onButtonPress(action, messageId);
1298
- } else if (action) {
1299
- if (isSafeUrl(action)) {
1300
- window.location.href = action;
1301
- }
1302
- }
1303
- });
1304
- return el;
1344
+ el.style.display = "inline-block";
1345
+ wrap.appendChild(el);
1346
+ return wrap;
1305
1347
  }
1348
+ case "Button":
1349
+ return this.renderButton(props, props.action || "", "Click", context);
1306
1350
  case "Section": {
1307
1351
  const el = document.createElement("div");
1308
1352
  if (props.bgColor) el.style.backgroundColor = sanitizeCssColor(props.bgColor) || "";
1309
- el.style.padding = (props.padding || 16) + "px";
1310
- el.style.borderRadius = (props.borderRadius || 0) + "px";
1311
- 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";
1312
1356
  if (props.bgImage) {
1313
1357
  const sanitizedUrl = sanitizeCssUrl(props.bgImage);
1314
1358
  if (sanitizedUrl) {
1315
1359
  el.style.backgroundImage = `url("${sanitizedUrl}")`;
1316
1360
  el.style.backgroundSize = sanitizeBackgroundSize(props.bgSize);
1317
1361
  el.style.backgroundPosition = "center";
1362
+ el.style.backgroundRepeat = "no-repeat";
1318
1363
  }
1319
1364
  }
1320
- const children = props.children || [];
1321
- for (const child of children) {
1322
- 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);
1323
1367
  if (childEl) el.appendChild(childEl);
1324
1368
  }
1325
1369
  return el;
1326
1370
  }
1327
1371
  case "Spacer": {
1328
1372
  const el = document.createElement("div");
1329
- el.style.height = (props.height || 24) + "px";
1373
+ el.style.height = authoredNumber(props.height, 24) + "px";
1330
1374
  return el;
1331
1375
  }
1332
1376
  case "Divider": {
1333
1377
  const el = document.createElement("hr");
1334
1378
  el.style.border = "none";
1335
- el.style.borderTop = `${props.thickness || 1}px solid ${sanitizeCssColor(props.color) || "#e5e5e5"}`;
1336
- el.style.margin = "8px 0";
1379
+ el.style.borderTop = `${authoredNumber(props.thickness, 1)}px solid ${sanitizeCssColor(props.color) || "#e5e5e5"}`;
1380
+ el.style.margin = "0";
1337
1381
  return el;
1338
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
+ }
1339
1437
  default:
1340
1438
  return null;
1341
1439
  }
1342
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
+ }
1343
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
+ }
1344
1620
  function sanitizeCssUrl(url) {
1345
1621
  if (!isSafeUrl(url)) return null;
1346
1622
  return url.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "").replace(/\r/g, "");