@mushi-mushi/web 1.16.0 → 1.17.0

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
@@ -1370,6 +1370,20 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
1370
1370
  .mushi-success-receipt-warn {
1371
1371
  color: ${widgetAccent};
1372
1372
  }
1373
+ .mushi-success-my-reports {
1374
+ display: block;
1375
+ margin: 12px auto 0;
1376
+ font-size: 12px;
1377
+ font-family: ${fontMono};
1378
+ color: ${widgetAccent};
1379
+ text-decoration: underline;
1380
+ text-underline-offset: 2px;
1381
+ background: none;
1382
+ border: none;
1383
+ cursor: pointer;
1384
+ padding: 4px 2px;
1385
+ }
1386
+ .mushi-success-my-reports:hover { opacity: 0.75; }
1373
1387
  .mushi-success-sla {
1374
1388
  margin-top: 2px;
1375
1389
  font-family: ${fontDisplay};
@@ -1861,6 +1875,28 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
1861
1875
  }
1862
1876
  .mushi-banner.neon .mushi-banner-dismiss:hover { background: rgba(0,0,0,0.18) !important; }
1863
1877
 
1878
+ /* "My reports" link in the simple (non-rich) banner layout */
1879
+ .mushi-banner-my-reports {
1880
+ background: transparent;
1881
+ border: none;
1882
+ cursor: pointer;
1883
+ font-size: 11px;
1884
+ font-family: ${fontMono};
1885
+ opacity: 0.75;
1886
+ color: inherit;
1887
+ padding: 2px 6px;
1888
+ border-radius: 3px;
1889
+ white-space: nowrap;
1890
+ flex-shrink: 0;
1891
+ transition: opacity 0.15s, background 0.15s;
1892
+ margin-left: 4px;
1893
+ }
1894
+ .mushi-banner-my-reports:hover {
1895
+ opacity: 1;
1896
+ background: rgba(0,0,0,0.10);
1897
+ }
1898
+ .mushi-banner.neon .mushi-banner-my-reports:hover { background: rgba(0,0,0,0.18); }
1899
+
1864
1900
  @keyframes mushi-banner-slide-in {
1865
1901
  from { transform: translateY(calc(-1 * 100%)); opacity: 0.5; }
1866
1902
  to { transform: translateY(0); opacity: 1; }
@@ -1928,7 +1964,7 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
1928
1964
 
1929
1965
  // src/version.ts
1930
1966
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
1931
- var MUSHI_SDK_VERSION = "1.16.0" ;
1967
+ var MUSHI_SDK_VERSION = "1.17.0" ;
1932
1968
 
1933
1969
  // src/widget-helpers.ts
1934
1970
  var CATEGORY_ICONS = {
@@ -2600,6 +2636,9 @@ function renderSuccessStep(ctx) {
2600
2636
  ${renderSuccessReceipt(ctx)}
2601
2637
  ${ctx.rewardsState ? renderSuccessRewards(ctx) : ""}
2602
2638
  ${ctx.config.betaMode?.enabled ? renderBetaSuccessFooter(ctx) : ""}
2639
+ <button type="button" class="mushi-link-btn mushi-success-my-reports" data-action="view-my-reports">
2640
+ \u{1F4EC} Track this report &rsaquo;
2641
+ </button>
2603
2642
  </div>
2604
2643
  </div>
2605
2644
  `;
@@ -2853,6 +2892,7 @@ var MushiWidget = class _MushiWidget {
2853
2892
  lastSubmitQueuedOffline = false;
2854
2893
  /** Whether the user has clicked ✕ on the header banner this session. */
2855
2894
  bannerDismissed = false;
2895
+ bannerResizeObserver = null;
2856
2896
  /** Persisted FAB position when draggable is enabled. */
2857
2897
  fabPos = null;
2858
2898
  /** Cleanup fn for visualViewport keyboard listener. */
@@ -3375,27 +3415,49 @@ var MushiWidget = class _MushiWidget {
3375
3415
  const action = this.config.environments[this.detectEnvironment()];
3376
3416
  return action !== "never" && action !== "manual";
3377
3417
  }
3378
- /** Height of the banner in px — kept in sync with the CSS `.mushi-banner` height (36px). */
3418
+ /** Height of the banner in px — used as a fallback before first layout. */
3379
3419
  static BANNER_HEIGHT = 36;
3380
- /** CSS property applied to document.body so host-app content doesn't slide under the banner. */
3420
+ /** CSS property applied to documentElement so host-app content doesn't slide under the banner. */
3381
3421
  static BODY_NUDGE_PROP = "--mushi-banner-offset";
3382
- applyBodyNudge(position) {
3383
- const h = `${_MushiWidget.BANNER_HEIGHT}px`;
3422
+ applyBodyNudge(position, heightPx = _MushiWidget.BANNER_HEIGHT) {
3423
+ const h = `${heightPx}px`;
3424
+ document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
3384
3425
  if (position === "top") {
3385
- document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
3386
- if (!document.body.style.paddingTop) {
3426
+ if (document.body.dataset.mushiBannerNudged === "top") {
3427
+ document.body.style.paddingTop = h;
3428
+ } else if (!document.body.style.paddingTop) {
3387
3429
  document.body.style.paddingTop = h;
3388
3430
  document.body.dataset.mushiBannerNudged = "top";
3389
3431
  }
3390
3432
  } else {
3391
- document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
3392
- if (!document.body.style.paddingBottom) {
3433
+ if (document.body.dataset.mushiBannerNudged === "bottom") {
3434
+ document.body.style.paddingBottom = h;
3435
+ } else if (!document.body.style.paddingBottom) {
3393
3436
  document.body.style.paddingBottom = h;
3394
3437
  document.body.dataset.mushiBannerNudged = "bottom";
3395
3438
  }
3396
3439
  }
3397
3440
  }
3441
+ /**
3442
+ * Schedule a height measurement after the next paint and set up a ResizeObserver
3443
+ * so --mushi-banner-offset always tracks the actual rendered banner height
3444
+ * (which can exceed BANNER_HEIGHT when safe-area-inset-top is in play on iOS,
3445
+ * or when rich-layout text wraps on narrow viewports).
3446
+ */
3447
+ trackBannerHeight(banner, position) {
3448
+ const update = () => {
3449
+ const h = banner.getBoundingClientRect().height;
3450
+ if (h > 0) this.applyBodyNudge(position, h);
3451
+ };
3452
+ requestAnimationFrame(update);
3453
+ if (typeof ResizeObserver !== "undefined") {
3454
+ this.bannerResizeObserver = new ResizeObserver(update);
3455
+ this.bannerResizeObserver.observe(banner);
3456
+ }
3457
+ }
3398
3458
  removeBodyNudge() {
3459
+ this.bannerResizeObserver?.disconnect();
3460
+ this.bannerResizeObserver = null;
3399
3461
  document.documentElement.style.removeProperty(_MushiWidget.BODY_NUDGE_PROP);
3400
3462
  const nudged = document.body.dataset.mushiBannerNudged;
3401
3463
  if (nudged === "top") {
@@ -3504,6 +3566,8 @@ var MushiWidget = class _MushiWidget {
3504
3566
  }, true);
3505
3567
  }
3506
3568
  }
3569
+ appendDivider(true);
3570
+ appendAction("\u{1F4EC} My reports", () => this.openReporter(), true);
3507
3571
  banner.appendChild(nav);
3508
3572
  banner.appendChild(dismissBtn);
3509
3573
  } else {
@@ -3519,10 +3583,17 @@ var MushiWidget = class _MushiWidget {
3519
3583
  featBtn.addEventListener("click", () => this.open({ featureRequest: true }));
3520
3584
  banner.appendChild(featBtn);
3521
3585
  }
3586
+ const myReportsBtn = document.createElement("button");
3587
+ myReportsBtn.className = "mushi-banner-my-reports";
3588
+ myReportsBtn.textContent = "\u{1F4EC} My reports";
3589
+ myReportsBtn.setAttribute("aria-label", "View my submitted reports");
3590
+ myReportsBtn.addEventListener("click", () => this.openReporter());
3591
+ banner.appendChild(myReportsBtn);
3522
3592
  banner.appendChild(dismissBtn);
3523
3593
  }
3524
3594
  this.shadow.appendChild(banner);
3525
3595
  this.applyBodyNudge(position);
3596
+ this.trackBannerHeight(banner, position);
3526
3597
  }
3527
3598
  effectiveTrigger() {
3528
3599
  if (!this.config.smartHide || typeof window === "undefined") return this.config.trigger;
@@ -3576,6 +3647,8 @@ var MushiWidget = class _MushiWidget {
3576
3647
  const theme = this.getTheme();
3577
3648
  const pos = this.config.position;
3578
3649
  const t = this.locale;
3650
+ this.bannerResizeObserver?.disconnect();
3651
+ this.bannerResizeObserver = null;
3579
3652
  this.shadow.innerHTML = "";
3580
3653
  const style = document.createElement("style");
3581
3654
  style.textContent = getWidgetStyles(theme, this.config.accent ?? "", this.config.accentText ?? "");
@@ -4129,6 +4202,9 @@ var MushiWidget = class _MushiWidget {
4129
4202
  panel.querySelector('[data-action="reporter-not-fixed"]')?.addEventListener("click", () => {
4130
4203
  void this.submitReporterReopen();
4131
4204
  });
4205
+ panel.querySelector('[data-action="view-my-reports"]')?.addEventListener("click", () => {
4206
+ void this.loadReporterReports();
4207
+ });
4132
4208
  panel.querySelector('[data-action="copy-report-id"]')?.addEventListener("click", (e) => {
4133
4209
  const btn = e.currentTarget;
4134
4210
  const id = btn.dataset.copyId;
@@ -4449,6 +4525,18 @@ var MushiWidget = class _MushiWidget {
4449
4525
  if (this.isOpen) this.close();
4450
4526
  this.open();
4451
4527
  }
4528
+ /**
4529
+ * Open the widget directly to the reporter's "My reports" history view.
4530
+ * Can be called from host apps via `sdk.openReporter()` or triggered by
4531
+ * the banner's "My reports" link button.
4532
+ */
4533
+ openReporter() {
4534
+ if (!this.isOpen) {
4535
+ this.isOpen = true;
4536
+ this.render();
4537
+ }
4538
+ void this.loadReporterReports();
4539
+ }
4452
4540
  recorderSelectCategory(category) {
4453
4541
  if (!this.isOpen) this.open();
4454
4542
  if (this.step !== "category") {
@@ -5095,19 +5183,26 @@ function createScreenshotCapture(options = {}) {
5095
5183
  try {
5096
5184
  ctx.drawImage(img, 0, 0, width, height);
5097
5185
  URL.revokeObjectURL(url);
5098
- resolve(canvas.toDataURL("image/jpeg", 0.7));
5186
+ const dataUrl = canvas.toDataURL("image/jpeg", 0.7);
5187
+ resolve(dataUrl);
5099
5188
  } catch {
5100
5189
  URL.revokeObjectURL(url);
5101
- resolve(buildDegradedScreenshot(width, height));
5190
+ activeOptions.onFailed?.("taint");
5191
+ emitScreenshotFailed("taint");
5192
+ resolve(null);
5102
5193
  }
5103
5194
  };
5104
5195
  img.onerror = () => {
5105
5196
  URL.revokeObjectURL(url);
5106
- resolve(buildDegradedScreenshot(width, height));
5197
+ activeOptions.onFailed?.("error");
5198
+ emitScreenshotFailed("error");
5199
+ resolve(null);
5107
5200
  };
5108
5201
  img.src = url;
5109
5202
  });
5110
5203
  } catch {
5204
+ activeOptions.onFailed?.("error");
5205
+ emitScreenshotFailed("error");
5111
5206
  return null;
5112
5207
  }
5113
5208
  }
@@ -5118,6 +5213,12 @@ function createScreenshotCapture(options = {}) {
5118
5213
  }
5119
5214
  };
5120
5215
  }
5216
+ function emitScreenshotFailed(reason) {
5217
+ try {
5218
+ document.dispatchEvent(new CustomEvent("mushi:screenshot_failed", { detail: { reason }, bubbles: false }));
5219
+ } catch {
5220
+ }
5221
+ }
5121
5222
  var DEFAULT_REDACT_SELECTORS = [
5122
5223
  'input[type="password"]',
5123
5224
  "[data-mushi-redact]"
@@ -5173,10 +5274,28 @@ function stripTaintSources(root) {
5173
5274
  const href = link.getAttribute("href");
5174
5275
  if (!href || isCrossOriginUrl(href, pageOrigin)) link.remove();
5175
5276
  }
5277
+ for (const styleEl of root.querySelectorAll("style")) {
5278
+ const cleaned = stripCssUrlRefs(styleEl.textContent ?? "", pageOrigin);
5279
+ if (cleaned !== styleEl.textContent) styleEl.textContent = cleaned;
5280
+ }
5281
+ for (const el of root.querySelectorAll("[style]")) {
5282
+ const s = el.getAttribute("style");
5283
+ if (!s) continue;
5284
+ const cleaned = stripCssUrlRefs(s, pageOrigin);
5285
+ if (cleaned !== s) el.setAttribute("style", cleaned);
5286
+ }
5176
5287
  for (const script of root.querySelectorAll("script")) {
5177
5288
  script.remove();
5178
5289
  }
5179
5290
  }
5291
+ function stripCssUrlRefs(css, pageOrigin) {
5292
+ return css.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi, (_match, _q, href) => {
5293
+ const trimmed = href.trim();
5294
+ if (!trimmed || trimmed.startsWith("data:") || trimmed.startsWith("#")) return _match;
5295
+ if (isCrossOriginUrl(trimmed, pageOrigin)) return "none";
5296
+ return _match;
5297
+ });
5298
+ }
5180
5299
  function isCrossOriginUrl(raw, pageOrigin) {
5181
5300
  if (!raw || raw.startsWith("data:") || raw.startsWith("blob:")) return false;
5182
5301
  try {
@@ -5186,24 +5305,6 @@ function isCrossOriginUrl(raw, pageOrigin) {
5186
5305
  return true;
5187
5306
  }
5188
5307
  }
5189
- function buildDegradedScreenshot(width, height) {
5190
- const canvas = document.createElement("canvas");
5191
- const ctx = canvas.getContext("2d");
5192
- if (!ctx) return null;
5193
- canvas.width = width;
5194
- canvas.height = height;
5195
- ctx.fillStyle = "#111827";
5196
- ctx.fillRect(0, 0, width, height);
5197
- ctx.fillStyle = "#e5e7eb";
5198
- ctx.font = "13px system-ui, sans-serif";
5199
- ctx.fillText("Screenshot: layout captured (external media stripped)", 16, 28);
5200
- ctx.fillText(`${width}\xD7${height}px`, 16, 48);
5201
- try {
5202
- return canvas.toDataURL("image/jpeg", 0.7);
5203
- } catch {
5204
- return null;
5205
- }
5206
- }
5207
5308
  function maskElement(el) {
5208
5309
  if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
5209
5310
  el.value = "";
@@ -6547,7 +6648,9 @@ function createInstance(config) {
6547
6648
  projectId: bootstrapConfig.projectId,
6548
6649
  apiKey: bootstrapConfig.apiKey,
6549
6650
  ...bootstrapConfig.apiEndpoint ? { apiEndpoint: bootstrapConfig.apiEndpoint } : {},
6550
- getUserToken: () => userToken
6651
+ getUserToken: () => userToken,
6652
+ sdkPackage: MUSHI_SDK_PACKAGE,
6653
+ sdkVersion: MUSHI_SDK_VERSION
6551
6654
  });
6552
6655
  const preFilter = core.createPreFilter(bootstrapConfig.preFilter);
6553
6656
  const offlineQueue = core.createOfflineQueue(bootstrapConfig.offline);
@@ -7355,6 +7458,9 @@ function createInstance(config) {
7355
7458
  setTrigger(trigger) {
7356
7459
  widget.setTrigger(trigger);
7357
7460
  },
7461
+ openReporter() {
7462
+ widget.openReporter();
7463
+ },
7358
7464
  close() {
7359
7465
  widget.close();
7360
7466
  },
@@ -7926,6 +8032,8 @@ function createNoopInstance() {
7926
8032
  },
7927
8033
  setTrigger: () => {
7928
8034
  },
8035
+ openReporter: () => {
8036
+ },
7929
8037
  destroy: () => {
7930
8038
  instance = null;
7931
8039
  },