@xpert-ai/chatkit-web-component 0.3.4 → 0.3.5

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.
@@ -1142,6 +1142,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1142
1142
  const PET_SUMMARY_WIDTH = 320;
1143
1143
  const PET_SUMMARY_MARGIN = 12;
1144
1144
  const PET_CONTEXT_MENU_MARGIN = 8;
1145
+ const PET_SUMMARY_FONT_FAMILY = 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
1145
1146
  const PET_OVERLAY_COPY = {
1146
1147
  "en-US": {
1147
1148
  closePetMenuItem: "Close pet",
@@ -1233,6 +1234,65 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1233
1234
  }
1234
1235
  return "en-US";
1235
1236
  }
1237
+ function getSummaryDensityMetrics(density) {
1238
+ switch (density) {
1239
+ case "compact":
1240
+ return {
1241
+ padding: "8px 10px",
1242
+ gap: 6,
1243
+ marginTop: 3,
1244
+ toggleSize: 30,
1245
+ actionSize: 22
1246
+ };
1247
+ case "spacious":
1248
+ return {
1249
+ padding: "14px 16px",
1250
+ gap: 10,
1251
+ marginTop: 6,
1252
+ toggleSize: 38,
1253
+ actionSize: 28
1254
+ };
1255
+ case "normal":
1256
+ default:
1257
+ return {
1258
+ padding: "12px 14px",
1259
+ gap: 8,
1260
+ marginTop: 4,
1261
+ toggleSize: 34,
1262
+ actionSize: 26
1263
+ };
1264
+ }
1265
+ }
1266
+ function getSummaryRadius(radius) {
1267
+ switch (radius) {
1268
+ case "pill":
1269
+ return 24;
1270
+ case "round":
1271
+ return 16;
1272
+ case "sharp":
1273
+ return 0;
1274
+ case "soft":
1275
+ default:
1276
+ return 12;
1277
+ }
1278
+ }
1279
+ function getSummaryThemeMetrics(theme) {
1280
+ var _a2, _b2;
1281
+ const themeObject = typeof theme === "string" ? null : theme;
1282
+ const baseSize = ((_a2 = themeObject == null ? void 0 : themeObject.typography) == null ? void 0 : _a2.baseSize) ?? 16;
1283
+ const density = (themeObject == null ? void 0 : themeObject.density) ?? "normal";
1284
+ const densityOffset = density === "compact" ? -1 : density === "spacious" ? 1 : 0;
1285
+ const bodySize = clampNumber(baseSize - 2 + densityOffset, 11, 17);
1286
+ const densityMetrics = getSummaryDensityMetrics(density);
1287
+ return {
1288
+ ...densityMetrics,
1289
+ bodySize,
1290
+ titleSize: bodySize + 1,
1291
+ iconSize: clampNumber(bodySize + 2, 13, 19),
1292
+ radius: getSummaryRadius(themeObject == null ? void 0 : themeObject.radius),
1293
+ fontFamily: ((_b2 = themeObject == null ? void 0 : themeObject.typography) == null ? void 0 : _b2.fontFamily) ?? PET_SUMMARY_FONT_FAMILY
1294
+ };
1295
+ }
1236
1296
  function isPetState(value) {
1237
1297
  return value === "idle" || value === "running-right" || value === "running-left" || value === "waving" || value === "jumping" || value === "failed" || value === "waiting" || value === "running" || value === "review";
1238
1298
  }
@@ -1268,6 +1328,12 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1268
1328
  summary.messageId || summary.updatedAt || summary.message
1269
1329
  ].join(":");
1270
1330
  }
1331
+ function getThreadSummaryInteractionKey(summary) {
1332
+ if (!summary) {
1333
+ return null;
1334
+ }
1335
+ return [summary.threadId, summary.messageId ?? ""].join(":");
1336
+ }
1271
1337
  function parseThreadSummaryPayload(value) {
1272
1338
  if (value === null) {
1273
1339
  return { summary: null };
@@ -1309,6 +1375,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1309
1375
  this.summaryToggleElement = null;
1310
1376
  this.mediaElement = null;
1311
1377
  this.options = null;
1378
+ this.theme = null;
1312
1379
  this.resolved = null;
1313
1380
  this.summary = null;
1314
1381
  this.summaryRenderKey = null;
@@ -1557,10 +1624,11 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1557
1624
  this.installReducedMotionListener();
1558
1625
  this.render();
1559
1626
  }
1560
- setOptions(pet) {
1627
+ setOptions(pet, theme) {
1561
1628
  this.closeContextMenu();
1562
1629
  const nextOptions = normalizePetOptions(pet);
1563
1630
  this.options = nextOptions;
1631
+ this.theme = theme ?? null;
1564
1632
  if (!nextOptions) {
1565
1633
  this.isDragging = false;
1566
1634
  this.isHovering = false;
@@ -1610,8 +1678,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1610
1678
  this.render();
1611
1679
  }
1612
1680
  setThreadSummary(summary) {
1613
- const previousKey = getThreadSummaryKey(this.summary);
1614
- const nextKey = getThreadSummaryKey(summary);
1681
+ const previousKey = getThreadSummaryInteractionKey(this.summary);
1682
+ const nextKey = getThreadSummaryInteractionKey(summary);
1615
1683
  this.summary = summary;
1616
1684
  if (!summary) {
1617
1685
  this.isSummaryCollapsed = false;
@@ -1906,10 +1974,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1906
1974
  return;
1907
1975
  }
1908
1976
  const nextRenderKey = [
1909
- summaryKey,
1910
- summary.title,
1911
- summary.message,
1912
- summary.status,
1913
1977
  this.copyLocale,
1914
1978
  this.isSummaryExpanded ? "expanded" : "compact",
1915
1979
  this.isSummaryHovering ? "hover" : "rest",
@@ -1934,6 +1998,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1934
1998
  }, 0);
1935
1999
  }
1936
2000
  }
2001
+ this.updateSummaryBubbleContent(summary);
1937
2002
  this.positionSummaryBubble(position, size);
1938
2003
  }
1939
2004
  renderCollapsedSummary(position, size) {
@@ -1954,7 +2019,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
1954
2019
  return;
1955
2020
  }
1956
2021
  const viewport = getViewportSize();
1957
- const badgeSize = 34;
2022
+ const badgeSize = getSummaryThemeMetrics(this.theme).toggleSize;
1958
2023
  const x = clampNumber(
1959
2024
  position.x + size.width - badgeSize * 0.35,
1960
2025
  PET_SUMMARY_MARGIN,
@@ -2000,6 +2065,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2000
2065
  }
2001
2066
  createSummaryBubble(summary) {
2002
2067
  const shouldShowReplyButton = this.isSummaryHovering && !this.isReplyOpen;
2068
+ const metrics = getSummaryThemeMetrics(this.theme);
2003
2069
  const bubble = document.createElement("div");
2004
2070
  bubble.setAttribute("data-chatkit-pet-summary", "");
2005
2071
  bubble.addEventListener("pointerenter", this.handleSummaryPointerEnter);
@@ -2010,19 +2076,18 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2010
2076
  bubble.style.left = "0";
2011
2077
  bubble.style.boxSizing = "border-box";
2012
2078
  bubble.style.pointerEvents = "auto";
2013
- bubble.style.padding = "12px 14px";
2014
- bubble.style.paddingBottom = "12px";
2079
+ bubble.style.padding = metrics.padding;
2015
2080
  bubble.style.border = "1px solid rgba(148, 163, 184, 0.22)";
2016
- bubble.style.borderRadius = "22px";
2081
+ bubble.style.borderRadius = `${metrics.radius}px`;
2017
2082
  bubble.style.background = "rgba(255, 255, 255, 0.94)";
2018
2083
  bubble.style.color = "#1f2937";
2019
2084
  bubble.style.boxShadow = "0 8px 24px rgba(15, 23, 42, 0.1)";
2020
- bubble.style.font = '500 14px/1.35 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
2085
+ bubble.style.font = `500 ${metrics.bodySize}px/1.35 ${metrics.fontFamily}`;
2021
2086
  bubble.style.backdropFilter = "blur(10px)";
2022
2087
  const header = document.createElement("div");
2023
2088
  header.style.display = "flex";
2024
2089
  header.style.alignItems = "center";
2025
- header.style.gap = "8px";
2090
+ header.style.gap = `${metrics.gap}px`;
2026
2091
  if (this.isSummaryHovering || this.isReplyOpen) {
2027
2092
  header.append(
2028
2093
  this.createSummaryActionButton(
@@ -2040,7 +2105,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2040
2105
  title.style.textOverflow = "ellipsis";
2041
2106
  title.style.whiteSpace = "nowrap";
2042
2107
  title.style.fontWeight = "700";
2043
- title.style.fontSize = "15px";
2108
+ title.style.fontSize = `${metrics.titleSize}px`;
2109
+ title.dataset.chatkitPetSummaryTitle = "";
2044
2110
  header.append(title);
2045
2111
  if (this.isSummaryHovering || this.isReplyOpen) {
2046
2112
  header.append(
@@ -2055,7 +2121,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2055
2121
  }
2056
2122
  const message = document.createElement("div");
2057
2123
  message.textContent = summary.message;
2058
- message.style.marginTop = "4px";
2124
+ message.style.marginTop = `${metrics.marginTop}px`;
2059
2125
  message.style.fontWeight = "400";
2060
2126
  message.style.color = "#374151";
2061
2127
  message.style.overflow = "hidden";
@@ -2067,6 +2133,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2067
2133
  message.style.setProperty("-webkit-line-clamp", "2");
2068
2134
  message.style.setProperty("-webkit-box-orient", "vertical");
2069
2135
  }
2136
+ message.dataset.chatkitPetSummaryMessage = "";
2070
2137
  bubble.append(header, message);
2071
2138
  if (shouldShowReplyButton) {
2072
2139
  const reply = this.createTextButton(
@@ -2083,7 +2150,30 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2083
2150
  }
2084
2151
  return bubble;
2085
2152
  }
2153
+ updateSummaryBubbleContent(summary) {
2154
+ var _a2, _b2, _c2;
2155
+ const title = (_a2 = this.summaryElement) == null ? void 0 : _a2.querySelector(
2156
+ "[data-chatkit-pet-summary-title]"
2157
+ );
2158
+ if (title && title.textContent !== summary.title) {
2159
+ title.textContent = summary.title;
2160
+ }
2161
+ const message = (_b2 = this.summaryElement) == null ? void 0 : _b2.querySelector(
2162
+ "[data-chatkit-pet-summary-message]"
2163
+ );
2164
+ if (message && message.textContent !== summary.message) {
2165
+ message.textContent = summary.message;
2166
+ }
2167
+ const statusIcon = (_c2 = this.summaryElement) == null ? void 0 : _c2.querySelector(
2168
+ "[data-chatkit-pet-summary-status]"
2169
+ );
2170
+ if (statusIcon && statusIcon.dataset.chatkitPetSummaryStatus !== summary.status) {
2171
+ const nextIcon = this.createStatusIcon(summary.status);
2172
+ statusIcon.replaceWith(nextIcon);
2173
+ }
2174
+ }
2086
2175
  createSummaryToggleButton(label) {
2176
+ const metrics = getSummaryThemeMetrics(this.theme);
2087
2177
  const button = document.createElement("button");
2088
2178
  button.type = "button";
2089
2179
  button.textContent = label;
@@ -2099,18 +2189,21 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2099
2189
  button.style.color = "#475569";
2100
2190
  button.style.boxShadow = "0 6px 18px rgba(15, 23, 42, 0.1)";
2101
2191
  button.style.cursor = "pointer";
2102
- button.style.font = '600 15px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
2192
+ button.style.font = `600 ${metrics.titleSize}px/1 ${metrics.fontFamily}`;
2103
2193
  button.style.display = "flex";
2104
2194
  button.style.alignItems = "center";
2105
2195
  button.style.justifyContent = "center";
2106
2196
  return button;
2107
2197
  }
2108
2198
  createStatusIcon(status) {
2199
+ const metrics = getSummaryThemeMetrics(this.theme);
2200
+ const iconSize = metrics.iconSize;
2109
2201
  const icon = document.createElement("span");
2110
2202
  icon.setAttribute("aria-hidden", "true");
2203
+ icon.dataset.chatkitPetSummaryStatus = status;
2111
2204
  icon.style.display = "inline-flex";
2112
- icon.style.width = "16px";
2113
- icon.style.height = "16px";
2205
+ icon.style.width = `${iconSize}px`;
2206
+ icon.style.height = `${iconSize}px`;
2114
2207
  icon.style.alignItems = "center";
2115
2208
  icon.style.justifyContent = "center";
2116
2209
  icon.style.flex = "0 0 auto";
@@ -2122,7 +2215,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2122
2215
  return icon;
2123
2216
  }
2124
2217
  icon.style.borderRadius = "999px";
2125
- icon.style.fontSize = "12px";
2218
+ icon.style.fontSize = `${Math.max(10, iconSize - 4)}px`;
2126
2219
  icon.style.fontWeight = "700";
2127
2220
  if (status === "failed") {
2128
2221
  icon.textContent = "!";
@@ -2134,8 +2227,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2134
2227
  icon.style.border = "2px solid #22c55e";
2135
2228
  icon.style.position = "relative";
2136
2229
  const check = document.createElement("span");
2137
- check.style.width = "7px";
2138
- check.style.height = "4px";
2230
+ check.style.width = `${Math.round(iconSize * 0.44)}px`;
2231
+ check.style.height = `${Math.round(iconSize * 0.25)}px`;
2139
2232
  check.style.borderLeft = "2px solid #22c55e";
2140
2233
  check.style.borderBottom = "2px solid #22c55e";
2141
2234
  check.style.transform = "rotate(-45deg) translate(1px, -1px)";
@@ -2143,6 +2236,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2143
2236
  return icon;
2144
2237
  }
2145
2238
  createSummaryActionButton(label, title, onClick) {
2239
+ const metrics = getSummaryThemeMetrics(this.theme);
2146
2240
  const button = document.createElement("button");
2147
2241
  button.type = "button";
2148
2242
  button.textContent = label;
@@ -2152,14 +2246,14 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
2152
2246
  event.stopPropagation();
2153
2247
  onClick();
2154
2248
  });
2155
- button.style.width = "26px";
2156
- button.style.height = "26px";
2249
+ button.style.width = `${metrics.actionSize}px`;
2250
+ button.style.height = `${metrics.actionSize}px`;
2157
2251
  button.style.border = "0";
2158
2252
  button.style.borderRadius = "999px";
2159
2253
  button.style.background = "rgba(241, 245, 249, 0.96)";
2160
2254
  button.style.color = "#475569";
2161
2255
  button.style.cursor = "pointer";
2162
- button.style.font = '600 15px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
2256
+ button.style.font = `600 ${metrics.titleSize}px/1 ${metrics.fontFamily}`;
2163
2257
  return button;
2164
2258
  }
2165
2259
  createTextButton(label, onClick) {
@@ -3099,8 +3193,9 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
3099
3193
  }
3100
3194
  };
3101
3195
  syncPetOverlayOptions_fn = function() {
3196
+ var _a2;
3102
3197
  const overlayPetOptions = __privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this);
3103
- __privateGet(this, _petOverlay).setOptions(overlayPetOptions);
3198
+ __privateGet(this, _petOverlay).setOptions(overlayPetOptions, (_a2 = __privateGet(this, _opts)) == null ? void 0 : _a2.theme);
3104
3199
  if (!overlayPetOptions) {
3105
3200
  __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3106
3201
  }