@mushi-mushi/web 1.32.2 → 1.32.3

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.cjs CHANGED
@@ -1748,16 +1748,26 @@ function intentOptions(ctx) {
1748
1748
  const list = ctx.locale.step2.intents[id] ?? [];
1749
1749
  return list.slice(0, -1).slice(0, 4);
1750
1750
  }
1751
+ function reportTypeIds(config) {
1752
+ const primary = [...BUILTIN_CHIPS];
1753
+ if (config.featureRequestCard !== false) primary.push("idea");
1754
+ const seen = new Set(primary);
1755
+ const more = [];
1756
+ for (const { id } of config.categories ?? []) {
1757
+ if (seen.has(id)) continue;
1758
+ seen.add(id);
1759
+ more.push(id);
1760
+ }
1761
+ return { primary, more };
1762
+ }
1751
1763
  function reportView(ctx) {
1752
1764
  const t = ctx.locale;
1753
1765
  const p = t.panel;
1754
1766
  const s3 = t.step3;
1755
- const ids = [...BUILTIN_CHIPS];
1756
- if (ctx.config.featureRequestCard !== false) ids.push("idea");
1757
- const custom = ctx.config.categories ?? [];
1758
- if (ctx.showAllCategories) ids.push(...custom.map((c) => c.id));
1767
+ const { primary, more: extra } = reportTypeIds(ctx.config);
1768
+ const ids = ctx.showAllCategories ? [...primary, ...extra] : primary;
1759
1769
  const chips = ids.map((id, i) => chip(ctx, id, i, ids.includes(ctx.chip ?? "") ? ctx.chip : null)).join("");
1760
- const more = custom.length && !ctx.showAllCategories ? btn("show-all-categories", esc(p.more), "mushi-chip mushi-chip-more") : "";
1770
+ const more = extra.length && !ctx.showAllCategories ? btn("show-all-categories", esc(p.more), "mushi-chip mushi-chip-more") : "";
1761
1771
  const intents = intentOptions(ctx);
1762
1772
  const intentRow = intents.length ? `<div class="mushi-chips mushi-intents" role="radiogroup" aria-label="${esc(chipLabel(ctx, ctx.chip))}">${intents.map((it, i) => `<button type="button" class="mushi-chip mushi-chip-sm" role="radio" aria-checked="${ctx.intent === it}" tabindex="${ctx.intent === it || !ctx.intent && i === 0 ? "0" : "-1"}" data-action="intent" data-intent="${esc(it)}">${esc(it)}</button>`).join("")}</div>` : "";
1763
1773
  const shotLabel = ctx.screenshotCapturing ? s3.screenshotCapturing : ctx.screenshotError ? s3.screenshotRetry : s3.screenshotButton;
@@ -2494,19 +2504,27 @@ var MushiWidget = class _MushiWidget {
2494
2504
  this.onColorSchemeChange = null;
2495
2505
  }
2496
2506
  /* ── Host chrome contract ────────────────────────────────────────────────
2497
- The host element must never create an invisible full-screen touch blocker.
2498
- We own these inline styles; only the shadow internals opt back into
2499
- pointer events. Idempotent. */
2507
+ The host element must never create an invisible full-screen touch blocker.
2508
+ We own these inline styles; only the shadow internals opt back into
2509
+ pointer events. Idempotent.
2510
+
2511
+ The host must not form a stacking context either. A `position: fixed`
2512
+ element always does, and so does any positioned element with a z-index;
2513
+ either one ranks every surface inside the shadow root at the host's
2514
+ level, so `bannerConfig.zIndex` could never put the banner under the
2515
+ host app's own sheets. The host is an absolute 0×0 box with
2516
+ `z-index: auto`, and the trigger, panel, toast and banner each carry
2517
+ their own z-index, which is then compared directly with the page's. */
2500
2518
  syncHostChromeState() {
2501
2519
  const s = this.host.style;
2502
- s.setProperty("position", "fixed");
2520
+ s.setProperty("position", "absolute");
2503
2521
  s.setProperty("top", "0");
2504
2522
  s.setProperty("left", "0");
2505
2523
  s.setProperty("width", "0");
2506
2524
  s.setProperty("height", "0");
2507
2525
  s.setProperty("overflow", "visible");
2508
2526
  s.setProperty("pointer-events", "none");
2509
- s.setProperty("z-index", String(this.config.zIndex));
2527
+ s.setProperty("z-index", "auto");
2510
2528
  s.setProperty("margin", "0");
2511
2529
  s.setProperty("padding", "0");
2512
2530
  s.setProperty("border", "none");
@@ -2671,7 +2689,7 @@ var MushiWidget = class _MushiWidget {
2671
2689
  if (richLayout) {
2672
2690
  const body = document.createElement("div");
2673
2691
  body.className = "mushi-banner-body";
2674
- const labelText = bc.label === false ? null : bc.label ?? "Beta";
2692
+ const labelText = bc.label === false ? null : bc.label ?? core.MUSHI_COPY.bannerLabel;
2675
2693
  if (labelText) {
2676
2694
  const pill = document.createElement("span");
2677
2695
  pill.className = "mushi-banner-pill";
@@ -3026,32 +3044,44 @@ var MushiWidget = class _MushiWidget {
3026
3044
  }
3027
3045
  }
3028
3046
  }
3029
- /** Queries `avoidSelectors` and returns a top offset clearing all of them, or null. */
3047
+ /**
3048
+ * Queries `avoidSelectors` and returns a top offset clearing the ones in the
3049
+ * top half of the viewport, or null. A bottom tab bar is ignored here: clearing
3050
+ * it from the top edge would push the widget off-screen.
3051
+ */
3030
3052
  computeAvoidTopPx(gap = 8) {
3031
3053
  const sels = this.config.avoidSelectors;
3032
3054
  if (!sels?.length) return null;
3055
+ const mid = window.innerHeight / 2;
3033
3056
  let maxBottom = 0;
3034
3057
  for (const sel of sels) {
3035
3058
  try {
3036
3059
  const el = document.querySelector(sel);
3037
3060
  if (!el) continue;
3038
3061
  const r = el.getBoundingClientRect();
3062
+ if ((r.top + r.bottom) / 2 >= mid) continue;
3039
3063
  if (r.bottom > maxBottom && r.width > 0 && r.height > 0) maxBottom = r.bottom;
3040
3064
  } catch {
3041
3065
  }
3042
3066
  }
3043
3067
  return maxBottom > 0 ? Math.ceil(maxBottom) + gap : null;
3044
3068
  }
3045
- /** Bottom offset so a bottom-anchored trigger clears avoided elements (tab bars, fixed CTAs). */
3069
+ /**
3070
+ * Bottom offset so a bottom-anchored trigger clears avoided elements in the
3071
+ * bottom half of the viewport (tab bars, fixed CTAs). A top header is ignored
3072
+ * here: clearing it from the bottom edge would push the widget off-screen.
3073
+ */
3046
3074
  computeAvoidBottomPx(gap = 8) {
3047
3075
  const sels = this.config.avoidSelectors;
3048
3076
  if (!sels?.length) return null;
3077
+ const mid = window.innerHeight / 2;
3049
3078
  let maxClearance = 0;
3050
3079
  for (const sel of sels) {
3051
3080
  try {
3052
3081
  const el = document.querySelector(sel);
3053
3082
  if (!el) continue;
3054
3083
  const r = el.getBoundingClientRect();
3084
+ if ((r.top + r.bottom) / 2 <= mid) continue;
3055
3085
  if (r.width > 0 && r.height > 0) {
3056
3086
  const clearance = window.innerHeight - r.top + gap;
3057
3087
  if (clearance > maxClearance) maxClearance = clearance;
@@ -3984,10 +4014,13 @@ var MushiWidget = class _MushiWidget {
3984
4014
  void this.loadReporterReports();
3985
4015
  }
3986
4016
  /* ── Marketing / Playwright recorder (debug GIF capture) ─────────── */
4017
+ // Hooks for `window.__mushiRecorder` (marketing-recorder.ts, `debug: true`
4018
+ // only). Tagged @internal: not supported public API, may change any release.
4019
+ /** @internal */
3987
4020
  getRecorderStep() {
3988
4021
  return this.step;
3989
4022
  }
3990
- /** QA / Playwright: report-screen IA without piercing the shadow root. */
4023
+ /** @internal QA / Playwright: report-screen IA without piercing the shadow root. */
3991
4024
  getRecorderCategoryStepIA() {
3992
4025
  return {
3993
4026
  sectionLabel: this.shadow.querySelector("#mushi-title")?.textContent?.trim() ?? "",
@@ -3995,22 +4028,28 @@ var MushiWidget = class _MushiWidget {
3995
4028
  footerStepIndicators: 0
3996
4029
  };
3997
4030
  }
4031
+ /** @internal */
3998
4032
  getRecorderTrigger() {
3999
4033
  return this.triggerEl;
4000
4034
  }
4035
+ /** @internal */
4001
4036
  getRecorderCategoryButton(category) {
4002
4037
  return this.shadow.querySelector(`[data-category="${category}"]`);
4003
4038
  }
4039
+ /** @internal */
4004
4040
  getRecorderIntentButton(label) {
4005
4041
  return Array.from(this.shadow.querySelectorAll("[data-intent]")).find((el) => el.dataset.intent === label) ?? null;
4006
4042
  }
4043
+ /** @internal */
4007
4044
  getRecorderSubmitButton() {
4008
4045
  return this.shadow.querySelector('[data-action="submit"]');
4009
4046
  }
4047
+ /** @internal */
4010
4048
  recorderClickTrigger() {
4011
4049
  if (this.isOpen) this.close();
4012
4050
  this.open();
4013
4051
  }
4052
+ /** @internal */
4014
4053
  recorderSelectCategory(category) {
4015
4054
  if (!this.isOpen) this.open();
4016
4055
  this.step = "report";
@@ -4018,17 +4057,21 @@ var MushiWidget = class _MushiWidget {
4018
4057
  this.intent = null;
4019
4058
  this.render();
4020
4059
  }
4060
+ /** @internal */
4021
4061
  recorderSelectIntent(label) {
4022
4062
  if (!this.isOpen || this.step !== "report") return;
4023
4063
  this.intent = label;
4024
4064
  this.render();
4025
4065
  }
4066
+ /** @internal */
4026
4067
  recorderFocusDescription() {
4027
4068
  this.shadow.querySelector('[data-role="description"]')?.focus();
4028
4069
  }
4070
+ /** @internal */
4029
4071
  recorderSubmit() {
4030
4072
  this.submitReport();
4031
4073
  }
4074
+ /** @internal */
4032
4075
  recorderOpenMyReports() {
4033
4076
  void this.loadReporterReports();
4034
4077
  }
@@ -4192,10 +4235,8 @@ function exposeMarketingRecorder(widget) {
4192
4235
  }
4193
4236
 
4194
4237
  // src/history-patch.ts
4195
- var capturedPushState = null;
4196
- var capturedReplaceState = null;
4197
- var nativePushState = null;
4198
- var nativeReplaceState = null;
4238
+ var prevPushState = null;
4239
+ var prevReplaceState = null;
4199
4240
  var pushWrapper = null;
4200
4241
  var replaceWrapper = null;
4201
4242
  var popListener = null;
@@ -4227,24 +4268,24 @@ function notifyPop() {
4227
4268
  }
4228
4269
  function ensurePatch() {
4229
4270
  if (patched || typeof window === "undefined") return;
4230
- nativePushState = History.prototype.pushState;
4231
- nativeReplaceState = History.prototype.replaceState;
4232
- capturedPushState = nativePushState.bind(history);
4233
- capturedReplaceState = nativeReplaceState.bind(history);
4234
- pushWrapper = function historyPatchPushState(...args) {
4235
- const call = capturedPushState ?? History.prototype.pushState.bind(history);
4236
- const ret = call(...args);
4237
- notifyPush();
4271
+ const prevPush = history.pushState;
4272
+ const prevReplace = history.replaceState;
4273
+ prevPushState = prevPush;
4274
+ prevReplaceState = prevReplace;
4275
+ const push = function historyPatchPushState(...args) {
4276
+ const ret = prevPush.apply(history, args);
4277
+ if (pushWrapper === push) notifyPush();
4238
4278
  return ret;
4239
4279
  };
4240
- replaceWrapper = function historyPatchReplaceState(...args) {
4241
- const call = capturedReplaceState ?? History.prototype.replaceState.bind(history);
4242
- const ret = call(...args);
4243
- notifyReplace();
4280
+ const replace = function historyPatchReplaceState(...args) {
4281
+ const ret = prevReplace.apply(history, args);
4282
+ if (replaceWrapper === replace) notifyReplace();
4244
4283
  return ret;
4245
4284
  };
4246
- history.pushState = pushWrapper;
4247
- history.replaceState = replaceWrapper;
4285
+ pushWrapper = push;
4286
+ replaceWrapper = replace;
4287
+ history.pushState = push;
4288
+ history.replaceState = replace;
4248
4289
  popListener = () => notifyPop();
4249
4290
  window.addEventListener("popstate", popListener);
4250
4291
  patched = true;
@@ -4255,22 +4296,22 @@ function uninstallPatch() {
4255
4296
  window.removeEventListener("popstate", popListener);
4256
4297
  popListener = null;
4257
4298
  }
4258
- if (pushWrapper && history.pushState === pushWrapper && nativePushState) {
4259
- history.pushState = nativePushState;
4299
+ if (pushWrapper && history.pushState === pushWrapper && prevPushState) {
4300
+ history.pushState = prevPushState;
4260
4301
  }
4261
- if (replaceWrapper && history.replaceState === replaceWrapper && nativeReplaceState) {
4262
- history.replaceState = nativeReplaceState;
4302
+ if (replaceWrapper && history.replaceState === replaceWrapper && prevReplaceState) {
4303
+ history.replaceState = prevReplaceState;
4263
4304
  }
4264
4305
  pushWrapper = null;
4265
4306
  replaceWrapper = null;
4266
- capturedPushState = null;
4267
- capturedReplaceState = null;
4268
- nativePushState = null;
4269
- nativeReplaceState = null;
4307
+ prevPushState = null;
4308
+ prevReplaceState = null;
4270
4309
  patched = false;
4271
4310
  }
4272
4311
  function subscribeHistory(sub) {
4273
4312
  ensurePatch();
4313
+ if (!patched) return () => {
4314
+ };
4274
4315
  subscribers.add(sub);
4275
4316
  return () => {
4276
4317
  subscribers.delete(sub);
@@ -4496,6 +4537,14 @@ function installActivityListeners(projectId) {
4496
4537
  removeActivityListeners();
4497
4538
  }
4498
4539
  listenersInstalled = true;
4540
+ try {
4541
+ attachActivityListeners(projectId);
4542
+ } catch (err) {
4543
+ removeActivityListeners();
4544
+ throw err;
4545
+ }
4546
+ }
4547
+ function attachActivityListeners(projectId) {
4499
4548
  const emitRoute = () => {
4500
4549
  const route = location.pathname;
4501
4550
  if (route === lastRoute) return;
@@ -4834,6 +4883,10 @@ function createNetworkCapture(options = {}) {
4834
4883
  const _prevXhrState = xhrStateMap.get(this);
4835
4884
  if (_prevXhrState?._listener) {
4836
4885
  this.removeEventListener("readystatechange", _prevXhrState._listener);
4886
+ if (_prevXhrState.correlationId) {
4887
+ const idx = _activeCorrelationStack.lastIndexOf(_prevXhrState.correlationId);
4888
+ if (idx !== -1) _activeCorrelationStack.splice(idx, 1);
4889
+ }
4837
4890
  }
4838
4891
  xhrStateMap.set(this, {
4839
4892
  method: String(method).toUpperCase(),
@@ -4862,6 +4915,8 @@ function createNetworkCapture(options = {}) {
4862
4915
  if (state.correlationId) _activeCorrelationStack.push(state.correlationId);
4863
4916
  const _readystateHandler = () => {
4864
4917
  if (this.readyState !== 4) return;
4918
+ this.removeEventListener("readystatechange", _readystateHandler);
4919
+ state._listener = void 0;
4865
4920
  if (state.shouldRecord) {
4866
4921
  const duration = Date.now() - state.startTime;
4867
4922
  const entry = {
@@ -4887,7 +4942,19 @@ function createNetworkCapture(options = {}) {
4887
4942
  state._listener = _readystateHandler;
4888
4943
  this.addEventListener("readystatechange", _readystateHandler);
4889
4944
  }
4890
- originalXhrSend.call(this, body);
4945
+ try {
4946
+ originalXhrSend.call(this, body);
4947
+ } catch (err) {
4948
+ if (state?.correlationId) {
4949
+ const idx = _activeCorrelationStack.lastIndexOf(state.correlationId);
4950
+ if (idx !== -1) _activeCorrelationStack.splice(idx, 1);
4951
+ }
4952
+ if (state?._listener) {
4953
+ this.removeEventListener("readystatechange", state._listener);
4954
+ state._listener = void 0;
4955
+ }
4956
+ throw err;
4957
+ }
4891
4958
  };
4892
4959
  }
4893
4960
  const xhrOpenWrapper = OriginalXHR ? XMLHttpRequest.prototype.open : null;
@@ -5594,8 +5661,10 @@ function createTimelineCapture() {
5594
5661
  onReplace: () => recordRoute("replaceState"),
5595
5662
  onPop: () => recordRoute("popstate")
5596
5663
  });
5597
- window.addEventListener("hashchange", handleHashChange);
5598
- document.addEventListener("click", handleClick, true);
5664
+ const hasWindow = typeof window !== "undefined";
5665
+ const hasDocument = typeof document !== "undefined";
5666
+ if (hasWindow) window.addEventListener("hashchange", handleHashChange);
5667
+ if (hasDocument) document.addEventListener("click", handleClick, true);
5599
5668
  return {
5600
5669
  setScreen(screen) {
5601
5670
  record({
@@ -5634,8 +5703,8 @@ function createTimelineCapture() {
5634
5703
  },
5635
5704
  destroy() {
5636
5705
  unsubHistory();
5637
- window.removeEventListener("hashchange", handleHashChange);
5638
- document.removeEventListener("click", handleClick, true);
5706
+ if (hasWindow) window.removeEventListener("hashchange", handleHashChange);
5707
+ if (hasDocument) document.removeEventListener("click", handleClick, true);
5639
5708
  }
5640
5709
  };
5641
5710
  }
@@ -6476,7 +6545,7 @@ function createProactiveManager(config = {}) {
6476
6545
 
6477
6546
  // src/version.ts
6478
6547
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
6479
- var MUSHI_SDK_VERSION = "1.32.2" ;
6548
+ var MUSHI_SDK_VERSION = "1.32.3" ;
6480
6549
  function resolveReportAppVersion(config, environment) {
6481
6550
  if (config.appVersion) return config.appVersion;
6482
6551
  const vercelId = config.integrations?.vercel?.analyticsId;
@@ -6487,7 +6556,7 @@ var instance = null;
6487
6556
  var Mushi = class {
6488
6557
  constructor() {
6489
6558
  }
6490
- static init(config) {
6559
+ static init(config = {}) {
6491
6560
  if (instance) {
6492
6561
  core.createLogger({ scope: "mushi", level: "warn", format: "pretty" }).warn("Already initialized \u2014 call destroy() first to reinitialize");
6493
6562
  return instance;
@@ -6914,7 +6983,8 @@ function createInstance(config) {
6914
6983
  screenshotCaptureInFlight = true;
6915
6984
  try {
6916
6985
  const result = await provider();
6917
- if (result) return result;
6986
+ if (result?.startsWith("data:image/")) return result;
6987
+ if (result) log.warn("screenshotProvider must resolve to a data:image/ URL; ignoring", { prefix: result.slice(0, 16) });
6918
6988
  } catch (err) {
6919
6989
  log.warn("screenshotProvider threw, falling back to built-in capturer", {
6920
6990
  error: err instanceof Error ? err.message : String(err)
@@ -6957,7 +7027,7 @@ function createInstance(config) {
6957
7027
  widget = new MushiWidget(bootstrapConfig.widget, {
6958
7028
  onSubmit: async ({ category, userCategory, description, intent }) => {
6959
7029
  log.info("Report submitted", { category, userCategory, intent });
6960
- proactiveManager?.recordSubmission();
7030
+ if (pendingProactiveTrigger) proactiveManager?.recordSubmission();
6961
7031
  await autoCaptureScreenshot("submit");
6962
7032
  const outcome = await submitReport(category, description, intent, userCategory);
6963
7033
  return outcome ?? { reportId: null, queuedOffline: true };
@@ -7892,7 +7962,11 @@ function createInstance(config) {
7892
7962
  breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken() refreshed" });
7893
7963
  return;
7894
7964
  }
7895
- core.updateSessionIdentity(claims.sub);
7965
+ const sub = claims.sub;
7966
+ void core.sha256Hex(sub).then((hash) => {
7967
+ if (userInfo?.id === sub) core.updateSessionIdentity(hash);
7968
+ }).catch(() => {
7969
+ });
7896
7970
  userInfo = {
7897
7971
  id: claims.sub,
7898
7972
  ...claims.email ? { email: claims.email } : {},
@@ -7910,6 +7984,7 @@ function createInstance(config) {
7910
7984
  } else {
7911
7985
  userInfo = null;
7912
7986
  lastIdentifySig = null;
7987
+ core.updateSessionIdentity(null);
7913
7988
  widget.setIdentifiedUser(null);
7914
7989
  breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken(null)" });
7915
7990
  }