@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.d.cts CHANGED
@@ -190,6 +190,7 @@ declare class MushiWidget {
190
190
  private lastSubmitQueuedOffline;
191
191
  /** Whether the user has clicked ✕ on the header banner this session. */
192
192
  private bannerDismissed;
193
+ private bannerResizeObserver;
193
194
  /** Persisted FAB position when draggable is enabled. */
194
195
  private fabPos;
195
196
  /** Cleanup fn for visualViewport keyboard listener. */
@@ -320,11 +321,18 @@ declare class MushiWidget {
320
321
  private syncAttachedLaunchers;
321
322
  private syncSmartHide;
322
323
  private shouldRenderTrigger;
323
- /** Height of the banner in px — kept in sync with the CSS `.mushi-banner` height (36px). */
324
+ /** Height of the banner in px — used as a fallback before first layout. */
324
325
  private static readonly BANNER_HEIGHT;
325
- /** CSS property applied to document.body so host-app content doesn't slide under the banner. */
326
+ /** CSS property applied to documentElement so host-app content doesn't slide under the banner. */
326
327
  private static readonly BODY_NUDGE_PROP;
327
328
  private applyBodyNudge;
329
+ /**
330
+ * Schedule a height measurement after the next paint and set up a ResizeObserver
331
+ * so --mushi-banner-offset always tracks the actual rendered banner height
332
+ * (which can exceed BANNER_HEIGHT when safe-area-inset-top is in play on iOS,
333
+ * or when rich-layout text wraps on narrow viewports).
334
+ */
335
+ private trackBannerHeight;
328
336
  private removeBodyNudge;
329
337
  private renderBanner;
330
338
  private effectiveTrigger;
@@ -397,6 +405,12 @@ declare class MushiWidget {
397
405
  getRecorderIntentButton(label: string): Element | null;
398
406
  getRecorderSubmitButton(): Element | null;
399
407
  recorderClickTrigger(): void;
408
+ /**
409
+ * Open the widget directly to the reporter's "My reports" history view.
410
+ * Can be called from host apps via `sdk.openReporter()` or triggered by
411
+ * the banner's "My reports" link button.
412
+ */
413
+ openReporter(): void;
400
414
  recorderSelectCategory(category: MushiReportCategory): void;
401
415
  recorderSelectIntent(label: string): void;
402
416
  recorderFocusDescription(): void;
@@ -431,6 +445,8 @@ interface ScreenshotCapture {
431
445
  }
432
446
  interface ScreenshotCaptureOptions {
433
447
  privacy?: MushiPrivacyConfig;
448
+ /** Callback invoked when capture fails (taint, security policy, etc.). */
449
+ onFailed?: (reason: 'taint' | 'error') => void;
434
450
  }
435
451
  declare function createScreenshotCapture(options?: ScreenshotCaptureOptions): ScreenshotCapture;
436
452
 
package/dist/index.d.ts CHANGED
@@ -190,6 +190,7 @@ declare class MushiWidget {
190
190
  private lastSubmitQueuedOffline;
191
191
  /** Whether the user has clicked ✕ on the header banner this session. */
192
192
  private bannerDismissed;
193
+ private bannerResizeObserver;
193
194
  /** Persisted FAB position when draggable is enabled. */
194
195
  private fabPos;
195
196
  /** Cleanup fn for visualViewport keyboard listener. */
@@ -320,11 +321,18 @@ declare class MushiWidget {
320
321
  private syncAttachedLaunchers;
321
322
  private syncSmartHide;
322
323
  private shouldRenderTrigger;
323
- /** Height of the banner in px — kept in sync with the CSS `.mushi-banner` height (36px). */
324
+ /** Height of the banner in px — used as a fallback before first layout. */
324
325
  private static readonly BANNER_HEIGHT;
325
- /** CSS property applied to document.body so host-app content doesn't slide under the banner. */
326
+ /** CSS property applied to documentElement so host-app content doesn't slide under the banner. */
326
327
  private static readonly BODY_NUDGE_PROP;
327
328
  private applyBodyNudge;
329
+ /**
330
+ * Schedule a height measurement after the next paint and set up a ResizeObserver
331
+ * so --mushi-banner-offset always tracks the actual rendered banner height
332
+ * (which can exceed BANNER_HEIGHT when safe-area-inset-top is in play on iOS,
333
+ * or when rich-layout text wraps on narrow viewports).
334
+ */
335
+ private trackBannerHeight;
328
336
  private removeBodyNudge;
329
337
  private renderBanner;
330
338
  private effectiveTrigger;
@@ -397,6 +405,12 @@ declare class MushiWidget {
397
405
  getRecorderIntentButton(label: string): Element | null;
398
406
  getRecorderSubmitButton(): Element | null;
399
407
  recorderClickTrigger(): void;
408
+ /**
409
+ * Open the widget directly to the reporter's "My reports" history view.
410
+ * Can be called from host apps via `sdk.openReporter()` or triggered by
411
+ * the banner's "My reports" link button.
412
+ */
413
+ openReporter(): void;
400
414
  recorderSelectCategory(category: MushiReportCategory): void;
401
415
  recorderSelectIntent(label: string): void;
402
416
  recorderFocusDescription(): void;
@@ -431,6 +445,8 @@ interface ScreenshotCapture {
431
445
  }
432
446
  interface ScreenshotCaptureOptions {
433
447
  privacy?: MushiPrivacyConfig;
448
+ /** Callback invoked when capture fails (taint, security policy, etc.). */
449
+ onFailed?: (reason: 'taint' | 'error') => void;
434
450
  }
435
451
  declare function createScreenshotCapture(options?: ScreenshotCaptureOptions): ScreenshotCapture;
436
452
 
package/dist/index.js CHANGED
@@ -1368,6 +1368,20 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
1368
1368
  .mushi-success-receipt-warn {
1369
1369
  color: ${widgetAccent};
1370
1370
  }
1371
+ .mushi-success-my-reports {
1372
+ display: block;
1373
+ margin: 12px auto 0;
1374
+ font-size: 12px;
1375
+ font-family: ${fontMono};
1376
+ color: ${widgetAccent};
1377
+ text-decoration: underline;
1378
+ text-underline-offset: 2px;
1379
+ background: none;
1380
+ border: none;
1381
+ cursor: pointer;
1382
+ padding: 4px 2px;
1383
+ }
1384
+ .mushi-success-my-reports:hover { opacity: 0.75; }
1371
1385
  .mushi-success-sla {
1372
1386
  margin-top: 2px;
1373
1387
  font-family: ${fontDisplay};
@@ -1859,6 +1873,28 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
1859
1873
  }
1860
1874
  .mushi-banner.neon .mushi-banner-dismiss:hover { background: rgba(0,0,0,0.18) !important; }
1861
1875
 
1876
+ /* "My reports" link in the simple (non-rich) banner layout */
1877
+ .mushi-banner-my-reports {
1878
+ background: transparent;
1879
+ border: none;
1880
+ cursor: pointer;
1881
+ font-size: 11px;
1882
+ font-family: ${fontMono};
1883
+ opacity: 0.75;
1884
+ color: inherit;
1885
+ padding: 2px 6px;
1886
+ border-radius: 3px;
1887
+ white-space: nowrap;
1888
+ flex-shrink: 0;
1889
+ transition: opacity 0.15s, background 0.15s;
1890
+ margin-left: 4px;
1891
+ }
1892
+ .mushi-banner-my-reports:hover {
1893
+ opacity: 1;
1894
+ background: rgba(0,0,0,0.10);
1895
+ }
1896
+ .mushi-banner.neon .mushi-banner-my-reports:hover { background: rgba(0,0,0,0.18); }
1897
+
1862
1898
  @keyframes mushi-banner-slide-in {
1863
1899
  from { transform: translateY(calc(-1 * 100%)); opacity: 0.5; }
1864
1900
  to { transform: translateY(0); opacity: 1; }
@@ -1926,7 +1962,7 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
1926
1962
 
1927
1963
  // src/version.ts
1928
1964
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
1929
- var MUSHI_SDK_VERSION = "1.16.0" ;
1965
+ var MUSHI_SDK_VERSION = "1.17.0" ;
1930
1966
 
1931
1967
  // src/widget-helpers.ts
1932
1968
  var CATEGORY_ICONS = {
@@ -2598,6 +2634,9 @@ function renderSuccessStep(ctx) {
2598
2634
  ${renderSuccessReceipt(ctx)}
2599
2635
  ${ctx.rewardsState ? renderSuccessRewards(ctx) : ""}
2600
2636
  ${ctx.config.betaMode?.enabled ? renderBetaSuccessFooter(ctx) : ""}
2637
+ <button type="button" class="mushi-link-btn mushi-success-my-reports" data-action="view-my-reports">
2638
+ \u{1F4EC} Track this report &rsaquo;
2639
+ </button>
2601
2640
  </div>
2602
2641
  </div>
2603
2642
  `;
@@ -2851,6 +2890,7 @@ var MushiWidget = class _MushiWidget {
2851
2890
  lastSubmitQueuedOffline = false;
2852
2891
  /** Whether the user has clicked ✕ on the header banner this session. */
2853
2892
  bannerDismissed = false;
2893
+ bannerResizeObserver = null;
2854
2894
  /** Persisted FAB position when draggable is enabled. */
2855
2895
  fabPos = null;
2856
2896
  /** Cleanup fn for visualViewport keyboard listener. */
@@ -3373,27 +3413,49 @@ var MushiWidget = class _MushiWidget {
3373
3413
  const action = this.config.environments[this.detectEnvironment()];
3374
3414
  return action !== "never" && action !== "manual";
3375
3415
  }
3376
- /** Height of the banner in px — kept in sync with the CSS `.mushi-banner` height (36px). */
3416
+ /** Height of the banner in px — used as a fallback before first layout. */
3377
3417
  static BANNER_HEIGHT = 36;
3378
- /** CSS property applied to document.body so host-app content doesn't slide under the banner. */
3418
+ /** CSS property applied to documentElement so host-app content doesn't slide under the banner. */
3379
3419
  static BODY_NUDGE_PROP = "--mushi-banner-offset";
3380
- applyBodyNudge(position) {
3381
- const h = `${_MushiWidget.BANNER_HEIGHT}px`;
3420
+ applyBodyNudge(position, heightPx = _MushiWidget.BANNER_HEIGHT) {
3421
+ const h = `${heightPx}px`;
3422
+ document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
3382
3423
  if (position === "top") {
3383
- document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
3384
- if (!document.body.style.paddingTop) {
3424
+ if (document.body.dataset.mushiBannerNudged === "top") {
3425
+ document.body.style.paddingTop = h;
3426
+ } else if (!document.body.style.paddingTop) {
3385
3427
  document.body.style.paddingTop = h;
3386
3428
  document.body.dataset.mushiBannerNudged = "top";
3387
3429
  }
3388
3430
  } else {
3389
- document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
3390
- if (!document.body.style.paddingBottom) {
3431
+ if (document.body.dataset.mushiBannerNudged === "bottom") {
3432
+ document.body.style.paddingBottom = h;
3433
+ } else if (!document.body.style.paddingBottom) {
3391
3434
  document.body.style.paddingBottom = h;
3392
3435
  document.body.dataset.mushiBannerNudged = "bottom";
3393
3436
  }
3394
3437
  }
3395
3438
  }
3439
+ /**
3440
+ * Schedule a height measurement after the next paint and set up a ResizeObserver
3441
+ * so --mushi-banner-offset always tracks the actual rendered banner height
3442
+ * (which can exceed BANNER_HEIGHT when safe-area-inset-top is in play on iOS,
3443
+ * or when rich-layout text wraps on narrow viewports).
3444
+ */
3445
+ trackBannerHeight(banner, position) {
3446
+ const update = () => {
3447
+ const h = banner.getBoundingClientRect().height;
3448
+ if (h > 0) this.applyBodyNudge(position, h);
3449
+ };
3450
+ requestAnimationFrame(update);
3451
+ if (typeof ResizeObserver !== "undefined") {
3452
+ this.bannerResizeObserver = new ResizeObserver(update);
3453
+ this.bannerResizeObserver.observe(banner);
3454
+ }
3455
+ }
3396
3456
  removeBodyNudge() {
3457
+ this.bannerResizeObserver?.disconnect();
3458
+ this.bannerResizeObserver = null;
3397
3459
  document.documentElement.style.removeProperty(_MushiWidget.BODY_NUDGE_PROP);
3398
3460
  const nudged = document.body.dataset.mushiBannerNudged;
3399
3461
  if (nudged === "top") {
@@ -3502,6 +3564,8 @@ var MushiWidget = class _MushiWidget {
3502
3564
  }, true);
3503
3565
  }
3504
3566
  }
3567
+ appendDivider(true);
3568
+ appendAction("\u{1F4EC} My reports", () => this.openReporter(), true);
3505
3569
  banner.appendChild(nav);
3506
3570
  banner.appendChild(dismissBtn);
3507
3571
  } else {
@@ -3517,10 +3581,17 @@ var MushiWidget = class _MushiWidget {
3517
3581
  featBtn.addEventListener("click", () => this.open({ featureRequest: true }));
3518
3582
  banner.appendChild(featBtn);
3519
3583
  }
3584
+ const myReportsBtn = document.createElement("button");
3585
+ myReportsBtn.className = "mushi-banner-my-reports";
3586
+ myReportsBtn.textContent = "\u{1F4EC} My reports";
3587
+ myReportsBtn.setAttribute("aria-label", "View my submitted reports");
3588
+ myReportsBtn.addEventListener("click", () => this.openReporter());
3589
+ banner.appendChild(myReportsBtn);
3520
3590
  banner.appendChild(dismissBtn);
3521
3591
  }
3522
3592
  this.shadow.appendChild(banner);
3523
3593
  this.applyBodyNudge(position);
3594
+ this.trackBannerHeight(banner, position);
3524
3595
  }
3525
3596
  effectiveTrigger() {
3526
3597
  if (!this.config.smartHide || typeof window === "undefined") return this.config.trigger;
@@ -3574,6 +3645,8 @@ var MushiWidget = class _MushiWidget {
3574
3645
  const theme = this.getTheme();
3575
3646
  const pos = this.config.position;
3576
3647
  const t = this.locale;
3648
+ this.bannerResizeObserver?.disconnect();
3649
+ this.bannerResizeObserver = null;
3577
3650
  this.shadow.innerHTML = "";
3578
3651
  const style = document.createElement("style");
3579
3652
  style.textContent = getWidgetStyles(theme, this.config.accent ?? "", this.config.accentText ?? "");
@@ -4127,6 +4200,9 @@ var MushiWidget = class _MushiWidget {
4127
4200
  panel.querySelector('[data-action="reporter-not-fixed"]')?.addEventListener("click", () => {
4128
4201
  void this.submitReporterReopen();
4129
4202
  });
4203
+ panel.querySelector('[data-action="view-my-reports"]')?.addEventListener("click", () => {
4204
+ void this.loadReporterReports();
4205
+ });
4130
4206
  panel.querySelector('[data-action="copy-report-id"]')?.addEventListener("click", (e) => {
4131
4207
  const btn = e.currentTarget;
4132
4208
  const id = btn.dataset.copyId;
@@ -4447,6 +4523,18 @@ var MushiWidget = class _MushiWidget {
4447
4523
  if (this.isOpen) this.close();
4448
4524
  this.open();
4449
4525
  }
4526
+ /**
4527
+ * Open the widget directly to the reporter's "My reports" history view.
4528
+ * Can be called from host apps via `sdk.openReporter()` or triggered by
4529
+ * the banner's "My reports" link button.
4530
+ */
4531
+ openReporter() {
4532
+ if (!this.isOpen) {
4533
+ this.isOpen = true;
4534
+ this.render();
4535
+ }
4536
+ void this.loadReporterReports();
4537
+ }
4450
4538
  recorderSelectCategory(category) {
4451
4539
  if (!this.isOpen) this.open();
4452
4540
  if (this.step !== "category") {
@@ -5093,19 +5181,26 @@ function createScreenshotCapture(options = {}) {
5093
5181
  try {
5094
5182
  ctx.drawImage(img, 0, 0, width, height);
5095
5183
  URL.revokeObjectURL(url);
5096
- resolve(canvas.toDataURL("image/jpeg", 0.7));
5184
+ const dataUrl = canvas.toDataURL("image/jpeg", 0.7);
5185
+ resolve(dataUrl);
5097
5186
  } catch {
5098
5187
  URL.revokeObjectURL(url);
5099
- resolve(buildDegradedScreenshot(width, height));
5188
+ activeOptions.onFailed?.("taint");
5189
+ emitScreenshotFailed("taint");
5190
+ resolve(null);
5100
5191
  }
5101
5192
  };
5102
5193
  img.onerror = () => {
5103
5194
  URL.revokeObjectURL(url);
5104
- resolve(buildDegradedScreenshot(width, height));
5195
+ activeOptions.onFailed?.("error");
5196
+ emitScreenshotFailed("error");
5197
+ resolve(null);
5105
5198
  };
5106
5199
  img.src = url;
5107
5200
  });
5108
5201
  } catch {
5202
+ activeOptions.onFailed?.("error");
5203
+ emitScreenshotFailed("error");
5109
5204
  return null;
5110
5205
  }
5111
5206
  }
@@ -5116,6 +5211,12 @@ function createScreenshotCapture(options = {}) {
5116
5211
  }
5117
5212
  };
5118
5213
  }
5214
+ function emitScreenshotFailed(reason) {
5215
+ try {
5216
+ document.dispatchEvent(new CustomEvent("mushi:screenshot_failed", { detail: { reason }, bubbles: false }));
5217
+ } catch {
5218
+ }
5219
+ }
5119
5220
  var DEFAULT_REDACT_SELECTORS = [
5120
5221
  'input[type="password"]',
5121
5222
  "[data-mushi-redact]"
@@ -5171,10 +5272,28 @@ function stripTaintSources(root) {
5171
5272
  const href = link.getAttribute("href");
5172
5273
  if (!href || isCrossOriginUrl(href, pageOrigin)) link.remove();
5173
5274
  }
5275
+ for (const styleEl of root.querySelectorAll("style")) {
5276
+ const cleaned = stripCssUrlRefs(styleEl.textContent ?? "", pageOrigin);
5277
+ if (cleaned !== styleEl.textContent) styleEl.textContent = cleaned;
5278
+ }
5279
+ for (const el of root.querySelectorAll("[style]")) {
5280
+ const s = el.getAttribute("style");
5281
+ if (!s) continue;
5282
+ const cleaned = stripCssUrlRefs(s, pageOrigin);
5283
+ if (cleaned !== s) el.setAttribute("style", cleaned);
5284
+ }
5174
5285
  for (const script of root.querySelectorAll("script")) {
5175
5286
  script.remove();
5176
5287
  }
5177
5288
  }
5289
+ function stripCssUrlRefs(css, pageOrigin) {
5290
+ return css.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi, (_match, _q, href) => {
5291
+ const trimmed = href.trim();
5292
+ if (!trimmed || trimmed.startsWith("data:") || trimmed.startsWith("#")) return _match;
5293
+ if (isCrossOriginUrl(trimmed, pageOrigin)) return "none";
5294
+ return _match;
5295
+ });
5296
+ }
5178
5297
  function isCrossOriginUrl(raw, pageOrigin) {
5179
5298
  if (!raw || raw.startsWith("data:") || raw.startsWith("blob:")) return false;
5180
5299
  try {
@@ -5184,24 +5303,6 @@ function isCrossOriginUrl(raw, pageOrigin) {
5184
5303
  return true;
5185
5304
  }
5186
5305
  }
5187
- function buildDegradedScreenshot(width, height) {
5188
- const canvas = document.createElement("canvas");
5189
- const ctx = canvas.getContext("2d");
5190
- if (!ctx) return null;
5191
- canvas.width = width;
5192
- canvas.height = height;
5193
- ctx.fillStyle = "#111827";
5194
- ctx.fillRect(0, 0, width, height);
5195
- ctx.fillStyle = "#e5e7eb";
5196
- ctx.font = "13px system-ui, sans-serif";
5197
- ctx.fillText("Screenshot: layout captured (external media stripped)", 16, 28);
5198
- ctx.fillText(`${width}\xD7${height}px`, 16, 48);
5199
- try {
5200
- return canvas.toDataURL("image/jpeg", 0.7);
5201
- } catch {
5202
- return null;
5203
- }
5204
- }
5205
5306
  function maskElement(el) {
5206
5307
  if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
5207
5308
  el.value = "";
@@ -6545,7 +6646,9 @@ function createInstance(config) {
6545
6646
  projectId: bootstrapConfig.projectId,
6546
6647
  apiKey: bootstrapConfig.apiKey,
6547
6648
  ...bootstrapConfig.apiEndpoint ? { apiEndpoint: bootstrapConfig.apiEndpoint } : {},
6548
- getUserToken: () => userToken
6649
+ getUserToken: () => userToken,
6650
+ sdkPackage: MUSHI_SDK_PACKAGE,
6651
+ sdkVersion: MUSHI_SDK_VERSION
6549
6652
  });
6550
6653
  const preFilter = createPreFilter(bootstrapConfig.preFilter);
6551
6654
  const offlineQueue = createOfflineQueue(bootstrapConfig.offline);
@@ -7353,6 +7456,9 @@ function createInstance(config) {
7353
7456
  setTrigger(trigger) {
7354
7457
  widget.setTrigger(trigger);
7355
7458
  },
7459
+ openReporter() {
7460
+ widget.openReporter();
7461
+ },
7356
7462
  close() {
7357
7463
  widget.close();
7358
7464
  },
@@ -7924,6 +8030,8 @@ function createNoopInstance() {
7924
8030
  },
7925
8031
  setTrigger: () => {
7926
8032
  },
8033
+ openReporter: () => {
8034
+ },
7927
8035
  destroy: () => {
7928
8036
  instance = null;
7929
8037
  },