@mushi-mushi/web 1.13.0 → 1.14.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/README.md +1 -1
- package/dist/index.cjs +1969 -1362
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -87
- package/dist/index.d.ts +93 -87
- package/dist/index.js +1969 -1362
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -289,17 +289,21 @@ function getAvailableLocales() {
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
// src/styles.ts
|
|
292
|
-
function getWidgetStyles(theme) {
|
|
292
|
+
function getWidgetStyles(theme, accent = "", accentText = "") {
|
|
293
293
|
const isDark = theme === "dark";
|
|
294
|
+
const safeHex = (v) => /^#[0-9a-fA-F]{3,8}$/.test(v) ? v : "";
|
|
295
|
+
const safeAccent = safeHex(accent);
|
|
296
|
+
const safeAccentText = safeHex(accentText);
|
|
294
297
|
const paper = isDark ? "#0F0E0C" : "#F8F4ED";
|
|
295
298
|
const ink = isDark ? "#F2EBDD" : "#0E0D0B";
|
|
296
299
|
const inkMuted = isDark ? "#928B7E" : "#5C5852";
|
|
297
300
|
const inkFaint = isDark ? "#5A5650" : "#9A9489";
|
|
301
|
+
const inkDim = isDark ? "#7A7268" : "#6E6760";
|
|
298
302
|
const rule = isDark ? "rgba(242,235,221,0.10)" : "rgba(14,13,11,0.10)";
|
|
299
303
|
const ruleStrong = isDark ? "rgba(242,235,221,0.18)" : "rgba(14,13,11,0.16)";
|
|
300
|
-
const widgetAccent = isDark ? "#FF5A47" : "#E03C2C";
|
|
301
|
-
const widgetAccentWash = isDark ?
|
|
302
|
-
const widgetAccentInk = isDark ? "#FFE5E0" : "#7A1F15";
|
|
304
|
+
const widgetAccent = safeAccent || (isDark ? "#FF5A47" : "#E03C2C");
|
|
305
|
+
const widgetAccentWash = isDark ? `${widgetAccent}1F` : `${widgetAccent}14`;
|
|
306
|
+
const widgetAccentInk = safeAccentText || (isDark ? "#FFE5E0" : "#7A1F15");
|
|
303
307
|
const fontDisplay = `'Iowan Old Style', 'Palatino Linotype', 'Palatino', 'Book Antiqua', 'Cambria', Georgia, 'Times New Roman', serif`;
|
|
304
308
|
const fontBody = `system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI Variable Display', 'Segoe UI', sans-serif`;
|
|
305
309
|
const fontMono = `ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, 'Liberation Mono', monospace`;
|
|
@@ -446,6 +450,33 @@ function getWidgetStyles(theme) {
|
|
|
446
450
|
transform: scale(0.92);
|
|
447
451
|
}
|
|
448
452
|
|
|
453
|
+
/* \u2500\u2500 Draggable FAB \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
454
|
+
When draggable is enabled the trigger uses CSS translate to apply the
|
|
455
|
+
drag offset ON TOP of the existing inset positioning, so snapping and
|
|
456
|
+
safe-area clamp still work correctly via the inset vars.
|
|
457
|
+
--mushi-drag-active 0|1 gates the transform so non-draggable FABs are
|
|
458
|
+
completely unaffected. touch-action: none prevents browser pan/scroll
|
|
459
|
+
from racing the pointer capture. */
|
|
460
|
+
.mushi-trigger {
|
|
461
|
+
touch-action: none;
|
|
462
|
+
translate:
|
|
463
|
+
calc(var(--mushi-drag-active, 0) * var(--mushi-drag-x, 0px))
|
|
464
|
+
calc(var(--mushi-drag-active, 0) * var(--mushi-drag-y, 0px));
|
|
465
|
+
}
|
|
466
|
+
.mushi-trigger.dragging {
|
|
467
|
+
cursor: grabbing !important;
|
|
468
|
+
z-index: calc(var(--z, 99999) + 2);
|
|
469
|
+
transition: none !important;
|
|
470
|
+
box-shadow:
|
|
471
|
+
0 1px 0 ${rule},
|
|
472
|
+
0 20px 40px -12px rgba(14,13,11,0.55),
|
|
473
|
+
inset 0 -3px 0 ${widgetAccent};
|
|
474
|
+
opacity: 0.92;
|
|
475
|
+
}
|
|
476
|
+
@media (prefers-reduced-motion: reduce) {
|
|
477
|
+
.mushi-trigger { transition: none !important; }
|
|
478
|
+
}
|
|
479
|
+
|
|
449
480
|
@keyframes mushi-pulse {
|
|
450
481
|
0% { box-shadow: 0 0 0 0 ${widgetAccent}; opacity: 1; }
|
|
451
482
|
70% { box-shadow: 0 0 0 8px rgba(224,60,44,0); opacity: 0.5; }
|
|
@@ -456,7 +487,7 @@ function getWidgetStyles(theme) {
|
|
|
456
487
|
position: fixed;
|
|
457
488
|
width: 384px;
|
|
458
489
|
max-width: calc(100vw - 32px);
|
|
459
|
-
max-height: min(640px, calc(
|
|
490
|
+
max-height: min(640px, calc(100dvh - 120px - var(--mushi-keyboard-inset, 0px)));
|
|
460
491
|
background: ${paper};
|
|
461
492
|
border: 1px solid ${ruleStrong};
|
|
462
493
|
border-radius: 6px;
|
|
@@ -468,6 +499,26 @@ function getWidgetStyles(theme) {
|
|
|
468
499
|
display: flex;
|
|
469
500
|
flex-direction: column;
|
|
470
501
|
transform-origin: var(--mushi-origin, bottom right);
|
|
502
|
+
transition: bottom 120ms ease, top 120ms ease, max-height 120ms ease;
|
|
503
|
+
}
|
|
504
|
+
/* Keyboard-safe: on narrow viewports lift above the keyboard */
|
|
505
|
+
.mushi-panel.keyboard-open {
|
|
506
|
+
bottom: calc(var(--mushi-keyboard-inset, 0px) + 8px) !important;
|
|
507
|
+
}
|
|
508
|
+
/* On narrow mobile, fill the width as a bottom sheet */
|
|
509
|
+
@media (max-width: 480px) {
|
|
510
|
+
.mushi-panel {
|
|
511
|
+
left: 0 !important;
|
|
512
|
+
right: 0 !important;
|
|
513
|
+
width: 100% !important;
|
|
514
|
+
max-width: 100% !important;
|
|
515
|
+
border-bottom-left-radius: 0;
|
|
516
|
+
border-bottom-right-radius: 0;
|
|
517
|
+
bottom: var(--mushi-keyboard-inset, 0px) !important;
|
|
518
|
+
}
|
|
519
|
+
.mushi-panel.keyboard-open {
|
|
520
|
+
bottom: calc(var(--mushi-keyboard-inset, 0px) + 4px) !important;
|
|
521
|
+
}
|
|
471
522
|
}
|
|
472
523
|
.mushi-panel.open { animation: mushi-stamp-in 320ms ${easeStamp} both; }
|
|
473
524
|
.mushi-panel.closed { display: none; }
|
|
@@ -1496,7 +1547,7 @@ function getWidgetStyles(theme) {
|
|
|
1496
1547
|
}
|
|
1497
1548
|
|
|
1498
1549
|
.mushi-beta-perks li {
|
|
1499
|
-
font-size:
|
|
1550
|
+
font-size: 12px;
|
|
1500
1551
|
color: ${widgetAccentInk};
|
|
1501
1552
|
font-weight: 500;
|
|
1502
1553
|
}
|
|
@@ -1508,8 +1559,8 @@ function getWidgetStyles(theme) {
|
|
|
1508
1559
|
}
|
|
1509
1560
|
|
|
1510
1561
|
.mushi-changelog-summary {
|
|
1511
|
-
font-size:
|
|
1512
|
-
color:
|
|
1562
|
+
font-size: 11px;
|
|
1563
|
+
color: ${inkDim};
|
|
1513
1564
|
cursor: pointer;
|
|
1514
1565
|
list-style: none;
|
|
1515
1566
|
display: flex;
|
|
@@ -1539,8 +1590,8 @@ function getWidgetStyles(theme) {
|
|
|
1539
1590
|
}
|
|
1540
1591
|
|
|
1541
1592
|
.mushi-changelog-list li {
|
|
1542
|
-
font-size:
|
|
1543
|
-
color:
|
|
1593
|
+
font-size: 11px;
|
|
1594
|
+
color: ${inkDim};
|
|
1544
1595
|
line-height: 1.5;
|
|
1545
1596
|
}
|
|
1546
1597
|
|
|
@@ -1559,14 +1610,14 @@ function getWidgetStyles(theme) {
|
|
|
1559
1610
|
}
|
|
1560
1611
|
|
|
1561
1612
|
.mushi-beta-success-line {
|
|
1562
|
-
font-size:
|
|
1563
|
-
color:
|
|
1613
|
+
font-size: 12px;
|
|
1614
|
+
color: ${widgetAccentInk};
|
|
1564
1615
|
line-height: 1.5;
|
|
1565
1616
|
}
|
|
1566
1617
|
|
|
1567
1618
|
.mushi-beta-success-dim {
|
|
1568
1619
|
opacity: 0.65;
|
|
1569
|
-
font-size:
|
|
1620
|
+
font-size: 12px;
|
|
1570
1621
|
}
|
|
1571
1622
|
|
|
1572
1623
|
/* \u2500\u2500\u2500 Banner launcher (trigger: 'banner') \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
@@ -1582,7 +1633,7 @@ function getWidgetStyles(theme) {
|
|
|
1582
1633
|
gap: 10px;
|
|
1583
1634
|
padding: 0 16px;
|
|
1584
1635
|
font-family: ${fontMono};
|
|
1585
|
-
font-size:
|
|
1636
|
+
font-size: 12px;
|
|
1586
1637
|
letter-spacing: 0.04em;
|
|
1587
1638
|
white-space: nowrap;
|
|
1588
1639
|
overflow: hidden;
|
|
@@ -1710,7 +1761,7 @@ function getWidgetStyles(theme) {
|
|
|
1710
1761
|
overflow: hidden;
|
|
1711
1762
|
text-overflow: ellipsis;
|
|
1712
1763
|
white-space: nowrap;
|
|
1713
|
-
font-size:
|
|
1764
|
+
font-size: 12px;
|
|
1714
1765
|
font-weight: 500;
|
|
1715
1766
|
line-height: 1.3;
|
|
1716
1767
|
opacity: 0.9;
|
|
@@ -1826,10 +1877,31 @@ function getWidgetStyles(theme) {
|
|
|
1826
1877
|
.mushi-success-stamp-label { opacity: 1; }
|
|
1827
1878
|
.mushi-success-pts-award { opacity: 1; }
|
|
1828
1879
|
}
|
|
1880
|
+
|
|
1881
|
+
.mushi-community-footer{display:flex;align-items:center;gap:8px;padding:10px 0 2px;border-top:1px solid ${isDark ? "rgba(255,255,255,0.07)" : "rgba(0,0,0,0.07)"};margin-top:8px;flex-wrap:wrap}
|
|
1882
|
+
.mushi-community-btn{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
1883
|
+
.mushi-link-btn{background:none;border:none;padding:4px 2px;cursor:pointer;color:${widgetAccent};font-size:12px;font-family:${fontMono};text-decoration:underline;text-underline-offset:2px}
|
|
1884
|
+
.mushi-link-btn:hover{opacity:0.8}
|
|
1885
|
+
.mushi-link-btn:focus-visible,.mushi-nav-item:focus-visible{outline:2px solid ${widgetAccent};outline-offset:2px;border-radius:2px}
|
|
1886
|
+
.mushi-nav-item{display:block;width:100%;text-align:left;background:${isDark ? "rgba(255,255,255,0.05)" : "rgba(0,0,0,0.04)"};border:1px solid ${isDark ? "rgba(255,255,255,0.08)" : "rgba(0,0,0,0.08)"};border-radius:8px;padding:10px 14px;margin-bottom:8px;cursor:pointer;font-size:13px;color:${ink};transition:background .15s,border-color .15s}
|
|
1887
|
+
.mushi-nav-item:hover{background:${isDark ? "rgba(255,255,255,0.09)" : "rgba(0,0,0,0.07)"}}
|
|
1888
|
+
.mushi-account-card{display:flex;align-items:center;gap:12px;background:${isDark ? "rgba(255,255,255,0.06)" : "rgba(0,0,0,0.04)"};border-radius:10px;padding:12px 14px;margin-bottom:14px}
|
|
1889
|
+
.mushi-account-avatar{width:40px;height:40px;border-radius:50%;background:${widgetAccentWash};color:${widgetAccentInk};display:flex;align-items:center;justify-content:center;font-size:16px;font-weight:700;flex-shrink:0}
|
|
1890
|
+
.mushi-account-info{display:flex;flex-direction:column;gap:2px;min-width:0}
|
|
1891
|
+
.mushi-account-info strong{font:700 14px/1.3 inherit;color:${ink}}
|
|
1892
|
+
.mushi-account-rank,.mushi-xapp-app-name,.mushi-label{font-size:12px;color:${inkDim};font-family:${fontMono}}
|
|
1893
|
+
.mushi-account-rank{display:block}
|
|
1894
|
+
.mushi-xapp-app-name{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;margin:0 0 6px}
|
|
1895
|
+
.mushi-xapp-group{margin-bottom:14px}
|
|
1896
|
+
.mushi-label{display:block;font-weight:600;margin-bottom:6px}
|
|
1829
1897
|
`;
|
|
1830
1898
|
}
|
|
1831
1899
|
|
|
1832
|
-
// src/
|
|
1900
|
+
// src/version.ts
|
|
1901
|
+
var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
|
|
1902
|
+
var MUSHI_SDK_VERSION = "1.14.1" ;
|
|
1903
|
+
|
|
1904
|
+
// src/widget-helpers.ts
|
|
1833
1905
|
var CATEGORY_ICONS = {
|
|
1834
1906
|
bug: "\u26A0\uFE0F",
|
|
1835
1907
|
slow: "\u{1F40C}",
|
|
@@ -1949,1365 +2021,1745 @@ function isSubmitShortcut(e) {
|
|
|
1949
2021
|
function escapeHtml(value) {
|
|
1950
2022
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1951
2023
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
hideOnSelector: config.hideOnSelector ?? "",
|
|
1977
|
-
hideOnRoutes: config.hideOnRoutes ?? [],
|
|
1978
|
-
environments: config.environments ?? {},
|
|
1979
|
-
smartHide: config.smartHide ?? false,
|
|
1980
|
-
draggable: config.draggable ?? false,
|
|
1981
|
-
brandFooter: config.brandFooter ?? true,
|
|
1982
|
-
outdatedBanner: config.outdatedBanner ?? "auto",
|
|
1983
|
-
betaMode: config.betaMode ?? {},
|
|
1984
|
-
minDescriptionLength: config.minDescriptionLength ?? 20,
|
|
1985
|
-
dashboardUrl: config.dashboardUrl ?? "",
|
|
1986
|
-
responseSlaLabel: config.responseSlaLabel ?? "",
|
|
1987
|
-
featureRequestCard: config.featureRequestCard ?? true,
|
|
1988
|
-
featureRequestLabel: config.featureRequestLabel ?? "",
|
|
1989
|
-
featureRequestDescription: config.featureRequestDescription ?? "",
|
|
1990
|
-
avoidSelectors: config.avoidSelectors ?? [],
|
|
1991
|
-
categories: config.categories ?? []
|
|
1992
|
-
};
|
|
1993
|
-
this.callbacks = callbacks;
|
|
1994
|
-
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
1995
|
-
this.host = document.createElement("div");
|
|
1996
|
-
this.host.id = "mushi-mushi-widget";
|
|
1997
|
-
this.shadow = this.host.attachShadow({ mode: "closed" });
|
|
1998
|
-
}
|
|
1999
|
-
sdkVersion;
|
|
2000
|
-
host;
|
|
2001
|
-
shadow;
|
|
2002
|
-
config;
|
|
2003
|
-
callbacks;
|
|
2004
|
-
locale;
|
|
2005
|
-
isOpen = false;
|
|
2006
|
-
step = "category";
|
|
2007
|
-
/**
|
|
2008
|
-
* The selected category id. May be a built-in `MushiReportCategory` or a
|
|
2009
|
-
* custom id from `config.categories`. Cast to `MushiReportCategory` only
|
|
2010
|
-
* after resolving through `resolveBaseCategory()`.
|
|
2011
|
-
*/
|
|
2012
|
-
selectedCategory = null;
|
|
2013
|
-
selectedIntent = null;
|
|
2014
|
-
/**
|
|
2015
|
-
* True when the user took the "Feature request" shortcut. We track this
|
|
2016
|
-
* separately from `selectedCategory='other'` so the Back button on the
|
|
2017
|
-
* details step jumps straight back to the category picker instead of
|
|
2018
|
-
* landing on the intent picker the user explicitly skipped.
|
|
2019
|
-
*/
|
|
2020
|
-
viaFeatureRequest = false;
|
|
2021
|
-
screenshotAttached = false;
|
|
2022
|
-
screenshotCapturing = false;
|
|
2023
|
-
screenshotError = false;
|
|
2024
|
-
allowScreenshotRemove = true;
|
|
2025
|
-
elementSelected = false;
|
|
2026
|
-
elementCapturing = false;
|
|
2027
|
-
submitting = false;
|
|
2028
|
-
/** Hint element injected outside the shadow DOM during element selection. */
|
|
2029
|
-
selectorHint = null;
|
|
2030
|
-
triggerVisible = true;
|
|
2031
|
-
triggerShrunk = false;
|
|
2032
|
-
triggerHiddenByScroll = false;
|
|
2033
|
-
/** Milliseconds since mount — used for the 30s first-time nudge gate. */
|
|
2034
|
-
mountedAt = null;
|
|
2035
|
-
nudgeShown = false;
|
|
2036
|
-
nudgeEl = null;
|
|
2037
|
-
nudgeTimer = null;
|
|
2038
|
-
sdkFreshness = null;
|
|
2039
|
-
reporterReports = [];
|
|
2040
|
-
featureBoard = [];
|
|
2041
|
-
reporterComments = [];
|
|
2042
|
-
selectedReportId = null;
|
|
2043
|
-
reporterLoading = false;
|
|
2044
|
-
reporterError = null;
|
|
2045
|
-
attachedLaunchers = [];
|
|
2046
|
-
smartHideCleanup = null;
|
|
2047
|
-
smartHideTimer = null;
|
|
2048
|
-
/** Captured at the moment of submit so the success ledger metadata
|
|
2049
|
-
* ("REPORT · 14:23:07 JST") doesn't drift while the success step
|
|
2050
|
-
* is on screen. */
|
|
2051
|
-
submittedAt = null;
|
|
2052
|
-
/** Pending success-state + auto-close timers. Tracked so destroy()
|
|
2053
|
-
* can clear them — otherwise a host that unmounts mid-submit leaks
|
|
2054
|
-
* this MushiWidget reference (and re-renders into a detached shadow
|
|
2055
|
-
* root) for up to ~3.3s after destroy. */
|
|
2056
|
-
successTimer = null;
|
|
2057
|
-
autoCloseTimer = null;
|
|
2058
|
-
rewardsState = null;
|
|
2059
|
-
leaderboardEntries = null;
|
|
2060
|
-
leaderboardLoading = false;
|
|
2061
|
-
/** Server-confirmed id for the just-submitted report. Surfaces in
|
|
2062
|
-
* the success step as a copyable receipt + optional deep link to
|
|
2063
|
-
* the Mushi console (when `dashboardUrl` is configured). Cleared
|
|
2064
|
-
* on every new `open()` so a re-opened widget never reuses a
|
|
2065
|
-
* stale id from the previous session. */
|
|
2066
|
-
lastReportId = null;
|
|
2067
|
-
/** True when the just-submitted report was queued offline (no
|
|
2068
|
-
* network, or the API errored and went into the retry queue).
|
|
2069
|
-
* Drives a different success copy so the user knows the report
|
|
2070
|
-
* hasn't actually reached the console yet. */
|
|
2071
|
-
lastSubmitQueuedOffline = false;
|
|
2072
|
-
/** Whether the user has clicked ✕ on the header banner this session. */
|
|
2073
|
-
bannerDismissed = false;
|
|
2074
|
-
mount() {
|
|
2075
|
-
if (this.host.isConnected) return;
|
|
2076
|
-
this.syncHostChromeState();
|
|
2077
|
-
document.body.appendChild(this.host);
|
|
2078
|
-
this.syncAttachedLaunchers();
|
|
2079
|
-
this.syncSmartHide();
|
|
2080
|
-
this.render();
|
|
2081
|
-
this.mountedAt = Date.now();
|
|
2082
|
-
}
|
|
2083
|
-
getIsMounted() {
|
|
2084
|
-
return this.host.isConnected;
|
|
2085
|
-
}
|
|
2086
|
-
updateConfig(config = {}) {
|
|
2087
|
-
this.config = {
|
|
2088
|
-
...this.config,
|
|
2089
|
-
...config.position ? { position: config.position } : {},
|
|
2090
|
-
...config.anchor !== void 0 ? { anchor: config.anchor } : {},
|
|
2091
|
-
...config.theme ? { theme: config.theme } : {},
|
|
2092
|
-
...config.triggerText !== void 0 ? { triggerText: config.triggerText || "\u{1F41B}" } : {},
|
|
2093
|
-
...config.expandedTitle !== void 0 ? { expandedTitle: config.expandedTitle } : {},
|
|
2094
|
-
...config.mode ? { mode: config.mode } : {},
|
|
2095
|
-
...config.locale ? { locale: config.locale } : {},
|
|
2096
|
-
...config.zIndex !== void 0 ? { zIndex: config.zIndex } : {},
|
|
2097
|
-
...config.trigger ? { trigger: config.trigger } : {},
|
|
2098
|
-
...config.attachToSelector !== void 0 ? { attachToSelector: config.attachToSelector } : {},
|
|
2099
|
-
...config.inset !== void 0 ? { inset: config.inset } : {},
|
|
2100
|
-
...config.respectSafeArea !== void 0 ? { respectSafeArea: config.respectSafeArea } : {},
|
|
2101
|
-
...config.hideOnSelector !== void 0 ? { hideOnSelector: config.hideOnSelector } : {},
|
|
2102
|
-
...config.hideOnRoutes !== void 0 ? { hideOnRoutes: config.hideOnRoutes } : {},
|
|
2103
|
-
...config.environments !== void 0 ? { environments: config.environments } : {},
|
|
2104
|
-
...config.smartHide !== void 0 ? { smartHide: config.smartHide } : {},
|
|
2105
|
-
...config.draggable !== void 0 ? { draggable: config.draggable } : {},
|
|
2106
|
-
...config.brandFooter !== void 0 ? { brandFooter: config.brandFooter } : {},
|
|
2107
|
-
...config.outdatedBanner !== void 0 ? { outdatedBanner: config.outdatedBanner } : {},
|
|
2108
|
-
...config.betaMode !== void 0 ? { betaMode: config.betaMode } : {},
|
|
2109
|
-
...config.minDescriptionLength !== void 0 ? { minDescriptionLength: config.minDescriptionLength } : {},
|
|
2110
|
-
...config.dashboardUrl !== void 0 ? { dashboardUrl: config.dashboardUrl } : {},
|
|
2111
|
-
...config.responseSlaLabel !== void 0 ? { responseSlaLabel: config.responseSlaLabel } : {},
|
|
2112
|
-
...config.featureRequestCard !== void 0 ? { featureRequestCard: config.featureRequestCard } : {},
|
|
2113
|
-
...config.featureRequestLabel !== void 0 ? { featureRequestLabel: config.featureRequestLabel } : {},
|
|
2114
|
-
...config.featureRequestDescription !== void 0 ? { featureRequestDescription: config.featureRequestDescription } : {},
|
|
2115
|
-
// Runtime/dashboard config delivers bannerMessage/bannerLabel via
|
|
2116
|
-
// mergeRuntimeConfig → bannerConfig. The widget is constructed before
|
|
2117
|
-
// that fetch resolves, so this pass-through is what makes server-driven
|
|
2118
|
-
// banner copy actually render.
|
|
2119
|
-
...config.bannerConfig !== void 0 ? { bannerConfig: config.bannerConfig } : {},
|
|
2120
|
-
...config.categories !== void 0 ? { categories: config.categories } : {}
|
|
2121
|
-
};
|
|
2122
|
-
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
2123
|
-
if (this.host.isConnected) this.syncHostChromeState();
|
|
2124
|
-
this.syncAttachedLaunchers();
|
|
2125
|
-
this.syncSmartHide();
|
|
2126
|
-
this.render();
|
|
2127
|
-
}
|
|
2128
|
-
// ─── Custom category helpers ──────────────────────────────────────────────
|
|
2129
|
-
/** Find a custom category entry by id. Returns undefined for built-in ids. */
|
|
2130
|
-
resolveCustomCategory(id) {
|
|
2131
|
-
return this.config.categories?.find((c) => c.id === id);
|
|
2132
|
-
}
|
|
2133
|
-
/**
|
|
2134
|
-
* Map a (possibly custom) category id to the built-in `MushiReportCategory`
|
|
2135
|
-
* used for the report wire format. Falls back to `'other'`.
|
|
2136
|
-
*/
|
|
2137
|
-
resolveBaseCategory(id) {
|
|
2138
|
-
const BUILTIN = ["bug", "slow", "visual", "confusing", "other"];
|
|
2139
|
-
if (BUILTIN.includes(id)) return id;
|
|
2140
|
-
const custom = this.resolveCustomCategory(id);
|
|
2141
|
-
return custom?.baseCategory ?? "other";
|
|
2142
|
-
}
|
|
2143
|
-
/** Icon for the selected category — custom entry's icon or built-in emoji. */
|
|
2144
|
-
categoryIcon(id) {
|
|
2145
|
-
const custom = this.resolveCustomCategory(id);
|
|
2146
|
-
if (custom?.icon) return custom.icon;
|
|
2147
|
-
return CATEGORY_ICONS[id] ?? "\u{1F4AC}";
|
|
2148
|
-
}
|
|
2149
|
-
/** Label for the selected category — custom entry label or built-in i18n string. */
|
|
2150
|
-
categoryLabel(id) {
|
|
2151
|
-
const custom = this.resolveCustomCategory(id);
|
|
2152
|
-
if (custom) return custom.label;
|
|
2153
|
-
const t = this.locale;
|
|
2154
|
-
return t.step1.categories[id] ?? id;
|
|
2024
|
+
|
|
2025
|
+
// src/widget-render.ts
|
|
2026
|
+
function renderStep(ctx) {
|
|
2027
|
+
switch (ctx.step) {
|
|
2028
|
+
case "category":
|
|
2029
|
+
return renderCategoryStep(ctx);
|
|
2030
|
+
case "intent":
|
|
2031
|
+
return renderIntentStep(ctx);
|
|
2032
|
+
case "details":
|
|
2033
|
+
return renderDetailsStep(ctx);
|
|
2034
|
+
case "success":
|
|
2035
|
+
return renderSuccessStep(ctx);
|
|
2036
|
+
case "reports":
|
|
2037
|
+
return renderReportsStep(ctx);
|
|
2038
|
+
case "report-detail":
|
|
2039
|
+
return renderReportDetailStep(ctx);
|
|
2040
|
+
case "leaderboard":
|
|
2041
|
+
return renderLeaderboardStep(ctx);
|
|
2042
|
+
case "roadmap":
|
|
2043
|
+
return renderRoadmapStep(ctx);
|
|
2044
|
+
case "account":
|
|
2045
|
+
return renderAccountStep(ctx);
|
|
2046
|
+
case "cross-app-reports":
|
|
2047
|
+
return renderCrossAppReportsStep(ctx);
|
|
2155
2048
|
}
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2049
|
+
}
|
|
2050
|
+
function renderOutdatedBanner(ctx) {
|
|
2051
|
+
if (!ctx.sdkFreshness) return "";
|
|
2052
|
+
if (ctx.config.outdatedBanner === "off" || ctx.config.outdatedBanner === "console-only") return "";
|
|
2053
|
+
const { latest, current, deprecated, message } = ctx.sdkFreshness;
|
|
2054
|
+
if (!latest && !deprecated) return "";
|
|
2055
|
+
return `
|
|
2056
|
+
<div class="mushi-outdated" role="status">
|
|
2057
|
+
<strong>Mushi SDK ${escapeHtml(current)}</strong>
|
|
2058
|
+
${latest ? `latest is ${escapeHtml(latest)}.` : "needs attention."}
|
|
2059
|
+
${message ? `<span>${escapeHtml(message)}</span>` : ""}
|
|
2060
|
+
</div>
|
|
2061
|
+
`;
|
|
2062
|
+
}
|
|
2063
|
+
function renderBrandFooter(ctx) {
|
|
2064
|
+
if (ctx.config.brandFooter === false) return "";
|
|
2065
|
+
return `<div class="mushi-brand-footer">Powered by Mushi v${escapeHtml(ctx.sdkVersion)}</div>`;
|
|
2066
|
+
}
|
|
2067
|
+
function renderHeader(ctx, opts) {
|
|
2068
|
+
const t = ctx.locale;
|
|
2069
|
+
const { title, showBack = false, step, eyebrow } = opts;
|
|
2070
|
+
const eyebrowHtml = showBack ? `<button type="button" class="mushi-back" data-action="back" aria-label="${t.widget.back}">\u2190</button>` : `<span class="mushi-header-eyebrow">${eyebrow ?? "Mushi \xB7 Report"}</span>`;
|
|
2071
|
+
const counterHtml = step ? `<span class="mushi-step-counter" aria-label="Step ${step} of ${TOTAL_STEPS}"><b>${pad2(step)}</b> / ${pad2(TOTAL_STEPS)}</span>` : "";
|
|
2072
|
+
return `
|
|
2073
|
+
<div class="mushi-header">
|
|
2074
|
+
<div class="mushi-header-mark" aria-hidden="true">\u866B</div>
|
|
2075
|
+
<div class="mushi-header-titles">
|
|
2076
|
+
${eyebrowHtml}
|
|
2077
|
+
<h3>${title}</h3>
|
|
2078
|
+
</div>
|
|
2079
|
+
<div class="mushi-header-meta">
|
|
2080
|
+
${counterHtml}
|
|
2081
|
+
<button type="button" class="mushi-close" data-action="close" aria-label="${t.widget.close}">\u2715</button>
|
|
2082
|
+
</div>
|
|
2083
|
+
</div>
|
|
2084
|
+
`;
|
|
2085
|
+
}
|
|
2086
|
+
function renderStepIndicator(_ctx, currentStep) {
|
|
2087
|
+
const segments = [];
|
|
2088
|
+
for (let i = 1; i <= TOTAL_STEPS; i++) {
|
|
2089
|
+
const cls = i < currentStep ? "mushi-step-num done" : i === currentStep ? "mushi-step-num active" : "mushi-step-num";
|
|
2090
|
+
segments.push(`<span class="${cls}">${pad2(i)}</span>`);
|
|
2091
|
+
if (i < TOTAL_STEPS) segments.push('<span class="mushi-step-sep" aria-hidden="true"></span>');
|
|
2092
|
+
}
|
|
2093
|
+
return `<div class="mushi-step-indicator" aria-hidden="true">${segments.join("")}</div>`;
|
|
2094
|
+
}
|
|
2095
|
+
function renderCategoryStep(ctx) {
|
|
2096
|
+
const t = ctx.locale;
|
|
2097
|
+
const categoryEntries = ctx.config.categories && ctx.config.categories.length > 0 ? ctx.config.categories.map((c) => ({
|
|
2098
|
+
id: c.id,
|
|
2099
|
+
icon: c.icon ?? "\u{1F4AC}",
|
|
2100
|
+
label: c.label,
|
|
2101
|
+
desc: c.description ?? ""
|
|
2102
|
+
})) : ["bug", "slow", "visual", "confusing", "other"].map((id) => ({
|
|
2103
|
+
id,
|
|
2104
|
+
icon: CATEGORY_ICONS[id],
|
|
2105
|
+
label: t.step1.categories[id],
|
|
2106
|
+
desc: t.step1.categoryDescriptions[id]
|
|
2107
|
+
}));
|
|
2108
|
+
const categories = categoryEntries.map(({ id, icon, label, desc }) => `
|
|
2109
|
+
<button type="button" class="mushi-option-btn" data-category="${escapeHtml(id)}" role="radio" aria-checked="false">
|
|
2110
|
+
<span class="mushi-option-icon" aria-hidden="true">${escapeHtml(icon)}</span>
|
|
2111
|
+
<div class="mushi-option-text">
|
|
2112
|
+
<span class="mushi-option-label">${escapeHtml(label)}</span>
|
|
2113
|
+
${desc ? `<span class="mushi-option-desc">${escapeHtml(desc)}</span>` : ""}
|
|
2114
|
+
</div>
|
|
2115
|
+
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2116
|
+
</button>
|
|
2117
|
+
`).join("");
|
|
2118
|
+
return `
|
|
2119
|
+
${renderHeader(ctx, { title: t.step1.heading, step: STEP_NUMBER.category })}
|
|
2120
|
+
${ctx.config.betaMode?.enabled ? renderBetaStrip(ctx) : ""}
|
|
2121
|
+
<div class="mushi-body" role="radiogroup" aria-label="${t.step1.heading}">
|
|
2122
|
+
<button type="button" class="mushi-option-btn mushi-reports-entry" data-action="reports">
|
|
2123
|
+
<span class="mushi-option-icon" aria-hidden="true">\u{1F4EC}</span>
|
|
2124
|
+
<div class="mushi-option-text">
|
|
2125
|
+
<span class="mushi-option-label">Your reports${ctx.unreadCount() ? ` (${ctx.unreadCount()} new)` : ""}</span>
|
|
2126
|
+
<span class="mushi-option-desc">See status, developer replies, and respond</span>
|
|
2127
|
+
</div>
|
|
2128
|
+
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2129
|
+
</button>
|
|
2130
|
+
${renderFeatureRequestEntry(ctx)}
|
|
2131
|
+
${ctx.callbacks.onFeatureBoardRequest ? `
|
|
2132
|
+
<button type="button" class="mushi-option-btn" data-action="roadmap">
|
|
2133
|
+
<span class="mushi-option-icon" aria-hidden="true">\u{1F5F3}\uFE0F</span>
|
|
2134
|
+
<div class="mushi-option-text">
|
|
2135
|
+
<span class="mushi-option-label">Community ideas</span>
|
|
2136
|
+
<span class="mushi-option-desc">Vote on features and see what shipped</span>
|
|
2137
|
+
</div>
|
|
2138
|
+
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2139
|
+
</button>` : ""}
|
|
2140
|
+
${categories}
|
|
2141
|
+
${ctx.rewardsState ? renderRewardsNudge(ctx) : ""}
|
|
2142
|
+
<div class="mushi-community-footer">
|
|
2143
|
+
<button type="button" class="mushi-link-btn mushi-community-btn" data-action="open-account">
|
|
2144
|
+
${ctx.testerInfo ? `\u{1F464} ${escapeHtml(ctx.testerInfo.public_handle ?? ctx.testerInfo.display_name ?? "My account")}` : "\u{1F310} Join community \xB7 Track reports across apps"}
|
|
2145
|
+
</button>
|
|
2146
|
+
${ctx.rewardsState ? `<button type="button" class="mushi-link-btn" data-action="open-leaderboard">\u{1F3C6} Leaderboard</button>` : ""}
|
|
2147
|
+
</div>
|
|
2148
|
+
</div>
|
|
2149
|
+
${renderStepIndicator(ctx, STEP_NUMBER.category)}
|
|
2150
|
+
`;
|
|
2151
|
+
}
|
|
2152
|
+
function renderFeatureRequestEntry(ctx) {
|
|
2153
|
+
const enabled = ctx.config.featureRequestCard !== false;
|
|
2154
|
+
if (!enabled) return "";
|
|
2155
|
+
const label = ctx.config.featureRequestLabel || "Feature request";
|
|
2156
|
+
const desc = ctx.config.featureRequestDescription || "Suggest something new \u2014 even rough ideas help us prioritise";
|
|
2157
|
+
return `
|
|
2158
|
+
<button
|
|
2159
|
+
type="button"
|
|
2160
|
+
class="mushi-option-btn mushi-feature-entry"
|
|
2161
|
+
data-action="feature-request"
|
|
2162
|
+
aria-label="${escapeHtml(label)}"
|
|
2163
|
+
>
|
|
2164
|
+
<span class="mushi-option-icon" aria-hidden="true">\u2728</span>
|
|
2165
|
+
<div class="mushi-option-text">
|
|
2166
|
+
<span class="mushi-option-label">${escapeHtml(label)}</span>
|
|
2167
|
+
<span class="mushi-option-desc">${escapeHtml(desc)}</span>
|
|
2168
|
+
</div>
|
|
2169
|
+
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2170
|
+
</button>
|
|
2171
|
+
`;
|
|
2172
|
+
}
|
|
2173
|
+
function renderBetaChangelog(ctx) {
|
|
2174
|
+
const entries = ctx.config.betaMode?.changelogItems;
|
|
2175
|
+
if (!entries?.length) return "";
|
|
2176
|
+
const latest = entries[0];
|
|
2177
|
+
const items = latest.items.map((item) => `<li>\u2022 ${escapeHtml(item)}</li>`).join("");
|
|
2178
|
+
const label = latest.date ? `What\u2019s new in ${escapeHtml(latest.version)} \xB7 ${escapeHtml(latest.date)}` : `What\u2019s new in ${escapeHtml(latest.version)}`;
|
|
2179
|
+
return `
|
|
2180
|
+
<details class="mushi-changelog">
|
|
2181
|
+
<summary class="mushi-changelog-summary">${label}</summary>
|
|
2182
|
+
<ul class="mushi-changelog-list">${items}</ul>
|
|
2183
|
+
</details>
|
|
2184
|
+
`;
|
|
2185
|
+
}
|
|
2186
|
+
function renderBetaStrip(ctx) {
|
|
2187
|
+
const beta = ctx.config.betaMode;
|
|
2188
|
+
const appName = escapeHtml(beta.appName ?? "This app");
|
|
2189
|
+
const message = beta.message ? escapeHtml(beta.message) : `${appName} is in early development \u2014 updates ship weekly`;
|
|
2190
|
+
const email = beta.contactEmail ? escapeHtml(beta.contactEmail) : null;
|
|
2191
|
+
const perks = beta.perks ?? [];
|
|
2192
|
+
return `
|
|
2193
|
+
<div class="mushi-beta-strip" role="note" aria-label="Beta status">
|
|
2194
|
+
<div class="mushi-beta-strip-row">
|
|
2195
|
+
<span class="mushi-beta-tag" aria-hidden="true">BETA</span>
|
|
2196
|
+
<span class="mushi-beta-msg">${message}</span>
|
|
2197
|
+
</div>
|
|
2198
|
+
${email ? `<div class="mushi-beta-contact-hint">Reports go to ${email} \xB7 reviewed by the team</div>` : ""}
|
|
2199
|
+
${perks.length > 0 ? `
|
|
2200
|
+
<ul class="mushi-beta-perks" aria-label="Beta tester perks">
|
|
2201
|
+
${perks.map((p) => `<li>\u2713 ${escapeHtml(p)}</li>`).join("")}
|
|
2202
|
+
</ul>
|
|
2203
|
+
` : ""}
|
|
2204
|
+
${renderBetaChangelog(ctx)}
|
|
2205
|
+
</div>
|
|
2206
|
+
`;
|
|
2207
|
+
}
|
|
2208
|
+
function renderReportsStep(ctx) {
|
|
2209
|
+
const reports = ctx.reporterReports.map((report) => {
|
|
2210
|
+
const title = report.summary ?? report.description ?? `Report ${report.id.slice(0, 8)}`;
|
|
2211
|
+
const tone = reporterStatusTone(report.status);
|
|
2212
|
+
const when = formatRelativeTime(report.created_at);
|
|
2213
|
+
const unread = report.unread_count && report.unread_count > 0 ? `<span class="mushi-unread-badge" aria-label="${report.unread_count} unread">${report.unread_count}</span>` : "";
|
|
2214
|
+
return `
|
|
2215
|
+
<button type="button" class="mushi-report-row" data-report-id="${escapeHtml(report.id)}" aria-label="View report: ${escapeHtml(title)}">
|
|
2216
|
+
<div class="mushi-report-main">
|
|
2217
|
+
<span class="mushi-report-title">${escapeHtml(title)}</span>
|
|
2218
|
+
<span class="mushi-report-meta">
|
|
2219
|
+
<span class="mushi-report-status mushi-status-${tone}">${escapeHtml(reporterStatusShort(report.status))}</span>
|
|
2220
|
+
${when ? `<span class="mushi-report-when">${escapeHtml(when)}</span>` : ""}
|
|
2221
|
+
${unread}
|
|
2222
|
+
</span>
|
|
2223
|
+
</div>
|
|
2224
|
+
<span class="mushi-report-chevron" aria-hidden="true">\u203A</span>
|
|
2225
|
+
</button>`;
|
|
2226
|
+
}).join("");
|
|
2227
|
+
const leaderboardBtn = ctx.rewardsState ? `<button type="button" class="mushi-leaderboard-link" data-action="open-leaderboard">\u{1F3C6} Leaderboard</button>` : "";
|
|
2228
|
+
return `
|
|
2229
|
+
${renderHeader(ctx, { title: "Your reports", showBack: true, eyebrow: "Mushi \xB7 Inbox" })}
|
|
2230
|
+
<div class="mushi-body">
|
|
2231
|
+
${ctx.reporterLoading ? '<p class="mushi-muted">Loading reports\u2026</p>' : ""}
|
|
2232
|
+
${ctx.reporterError ? `<p class="mushi-error-inline">${escapeHtml(ctx.reporterError)}</p>` : ""}
|
|
2233
|
+
${reports || (!ctx.reporterLoading ? '<p class="mushi-muted">No reports from this browser yet.</p>' : "")}
|
|
2234
|
+
${leaderboardBtn}
|
|
2235
|
+
</div>
|
|
2236
|
+
`;
|
|
2237
|
+
}
|
|
2238
|
+
function renderRoadmapStep(ctx) {
|
|
2239
|
+
const rows = ctx.featureBoard.map((ticket) => {
|
|
2240
|
+
const id = String(ticket.id ?? "");
|
|
2241
|
+
const subject = escapeHtml(String(ticket.subject ?? "Untitled idea"));
|
|
2242
|
+
const votes = Number(ticket.vote_count ?? 0);
|
|
2243
|
+
const shipped = Boolean(ticket.shipped_at);
|
|
2244
|
+
const voted = Boolean(ticket.my_vote);
|
|
2245
|
+
const status = shipped ? "Shipped" : String(ticket.status_label ?? ticket.status ?? "open");
|
|
2246
|
+
return `
|
|
2247
|
+
<div class="mushi-report-row mushi-roadmap-row">
|
|
2248
|
+
<div class="mushi-report-main">
|
|
2249
|
+
<span class="mushi-report-title">${subject}</span>
|
|
2250
|
+
<span class="mushi-report-meta">
|
|
2251
|
+
<span class="mushi-report-status">${escapeHtml(status)}</span>
|
|
2252
|
+
<span class="mushi-report-when">${votes} vote${votes === 1 ? "" : "s"}</span>
|
|
2253
|
+
</span>
|
|
2254
|
+
</div>
|
|
2255
|
+
${ctx.callbacks.onFeatureBoardVote ? `
|
|
2256
|
+
<button type="button" class="mushi-vote-btn" data-vote-id="${escapeHtml(id)}" aria-pressed="${voted}">
|
|
2257
|
+
${voted ? "Voted" : "Vote"}
|
|
2258
|
+
</button>` : ""}
|
|
2259
|
+
</div>`;
|
|
2260
|
+
}).join("");
|
|
2261
|
+
return `
|
|
2262
|
+
${renderHeader(ctx, { title: "Community ideas", showBack: true, eyebrow: "Mushi \xB7 Roadmap" })}
|
|
2263
|
+
<div class="mushi-body">
|
|
2264
|
+
${ctx.reporterLoading ? '<p class="mushi-muted">Loading ideas\u2026</p>' : ""}
|
|
2265
|
+
${ctx.reporterError ? `<p class="mushi-error-inline">${escapeHtml(ctx.reporterError)}</p>` : ""}
|
|
2266
|
+
${rows || (!ctx.reporterLoading ? '<p class="mushi-muted">No community ideas yet. Be the first to suggest one.</p>' : "")}
|
|
2267
|
+
</div>
|
|
2268
|
+
`;
|
|
2269
|
+
}
|
|
2270
|
+
function renderLeaderboardStep(ctx) {
|
|
2271
|
+
const isGlobal = ctx.globalLeaderboard !== null || ctx.globalLeaderboardLoading;
|
|
2272
|
+
const entries = isGlobal ? ctx.globalLeaderboard ?? [] : (ctx.leaderboardEntries ?? []).map((e) => ({
|
|
2273
|
+
tester_id: "",
|
|
2274
|
+
public_handle: null,
|
|
2275
|
+
display_name: e.display_name,
|
|
2276
|
+
rank: 0,
|
|
2277
|
+
points_30d: e.points_30d,
|
|
2278
|
+
total_points: e.total_points
|
|
2279
|
+
}));
|
|
2280
|
+
const loading = isGlobal ? ctx.globalLeaderboardLoading : ctx.leaderboardLoading;
|
|
2281
|
+
const myRank = ctx.testerReputation?.rank ?? null;
|
|
2282
|
+
const rows = entries.map((e, i) => {
|
|
2283
|
+
const rank = e.rank || i + 1;
|
|
2284
|
+
const isMe = ctx.testerReputation && e.tester_id === ctx.testerReputation.tester_id;
|
|
2285
|
+
return `
|
|
2286
|
+
<div class="mushi-lb-row ${rank === 1 ? "mushi-lb-top" : ""}${isMe ? " mushi-lb-me" : ""}">
|
|
2287
|
+
<span class="mushi-lb-rank">#${rank}</span>
|
|
2288
|
+
<span class="mushi-lb-name">${escapeHtml(e.public_handle ?? e.display_name ?? "Anon")}</span>
|
|
2289
|
+
<span class="mushi-lb-pts">${(e.points_30d ?? e.total_points).toLocaleString()} pts</span>
|
|
2290
|
+
</div>
|
|
2291
|
+
`;
|
|
2292
|
+
}).join("");
|
|
2293
|
+
const myRankBadge = myRank ? `<div class="mushi-lb-myrank">You are ranked <strong>#${myRank}</strong> this month</div>` : !ctx.testerJwt ? `<button type="button" class="mushi-link-btn" data-action="open-account">Sign in to see your rank \u2192</button>` : "";
|
|
2294
|
+
return `
|
|
2295
|
+
${renderHeader(ctx, { title: "\u{1F3C6} Global Leaderboard", showBack: true, eyebrow: "Mushi \xB7 Community" })}
|
|
2296
|
+
<div class="mushi-body">
|
|
2297
|
+
${loading ? '<p class="mushi-muted">Loading leaderboard\u2026</p>' : ""}
|
|
2298
|
+
${!loading && !entries.length ? '<p class="mushi-muted">No contributors yet \u2014 be the first!</p>' : ""}
|
|
2299
|
+
<div class="mushi-lb-list">${rows}</div>
|
|
2300
|
+
${myRankBadge}
|
|
2301
|
+
<p class="mushi-lb-note">Global contributors this month \xB7 Points refresh monthly</p>
|
|
2302
|
+
</div>
|
|
2303
|
+
`;
|
|
2304
|
+
}
|
|
2305
|
+
function renderAccountStep(ctx) {
|
|
2306
|
+
const tester = ctx.testerInfo;
|
|
2307
|
+
if (tester) {
|
|
2308
|
+
const handle = tester.public_handle ?? tester.display_name ?? "Tester";
|
|
2309
|
+
const rep = ctx.testerReputation;
|
|
2310
|
+
return `
|
|
2311
|
+
${renderHeader(ctx, { title: "\u866B Mushi Account", showBack: true, eyebrow: "Mushi \xB7 Identity" })}
|
|
2312
|
+
<div class="mushi-body">
|
|
2313
|
+
<div class="mushi-account-card">
|
|
2314
|
+
<div class="mushi-account-avatar">${escapeHtml(handle.charAt(0).toUpperCase())}</div>
|
|
2315
|
+
<div class="mushi-account-info">
|
|
2316
|
+
<strong>${escapeHtml(handle)}</strong>
|
|
2317
|
+
${rep ? `<span class="mushi-account-rank">Rank #${rep.rank ?? "\u2014"} \xB7 ${(rep.points_30d ?? 0).toLocaleString()} pts this month</span>` : ""}
|
|
2318
|
+
</div>
|
|
2319
|
+
</div>
|
|
2320
|
+
<button type="button" class="mushi-nav-item" data-action="open-cross-app-reports">
|
|
2321
|
+
My reports across all apps \u2192
|
|
2322
|
+
</button>
|
|
2323
|
+
<button type="button" class="mushi-nav-item" data-action="open-global-leaderboard">
|
|
2324
|
+
View global leaderboard \u2192
|
|
2325
|
+
</button>
|
|
2326
|
+
<button type="button" class="mushi-link-btn" data-action="sign-out-tester">Sign out</button>
|
|
2327
|
+
</div>
|
|
2328
|
+
`;
|
|
2261
2329
|
}
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2330
|
+
if (ctx.magicLinkSent) {
|
|
2331
|
+
return `
|
|
2332
|
+
${renderHeader(ctx, { title: "\u866B Check your email", showBack: true, eyebrow: "Mushi \xB7 Sign in" })}
|
|
2333
|
+
<div class="mushi-body">
|
|
2334
|
+
<p class="mushi-muted">We sent a sign-in link to <strong>${escapeHtml(ctx.magicLinkEmail)}</strong>. Click it to connect your reports across apps and join the community.</p>
|
|
2335
|
+
<button type="button" class="mushi-link-btn" data-action="resend-magic-link">Resend email</button>
|
|
2336
|
+
${ctx.magicLinkError ? `<p class="mushi-error">${escapeHtml(ctx.magicLinkError)}</p>` : ""}
|
|
2337
|
+
</div>
|
|
2338
|
+
`;
|
|
2270
2339
|
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2340
|
+
return `
|
|
2341
|
+
${renderHeader(ctx, { title: "\u866B Join the community", showBack: true, eyebrow: "Mushi \xB7 Sign in" })}
|
|
2342
|
+
<div class="mushi-body">
|
|
2343
|
+
<p class="mushi-muted">Sign in to see your reports across all apps and climb the global leaderboard. No password needed.</p>
|
|
2344
|
+
<label class="mushi-label" for="mushi-email-input">Email address</label>
|
|
2345
|
+
<input
|
|
2346
|
+
id="mushi-email-input"
|
|
2347
|
+
type="email"
|
|
2348
|
+
class="mushi-textarea"
|
|
2349
|
+
data-role="magic-link-email"
|
|
2350
|
+
placeholder="you@example.com"
|
|
2351
|
+
autocomplete="email"
|
|
2352
|
+
value="${escapeHtml(ctx.magicLinkEmail)}"
|
|
2353
|
+
style="padding: 10px 12px; height: auto; resize: none;"
|
|
2354
|
+
/>
|
|
2355
|
+
${ctx.magicLinkError ? `<p class="mushi-error">${escapeHtml(ctx.magicLinkError)}</p>` : ""}
|
|
2356
|
+
<button type="button" class="mushi-submit" data-action="send-magic-link"${ctx.magicLinkSending ? ' disabled aria-disabled="true"' : ""}>
|
|
2357
|
+
<span>${ctx.magicLinkSending ? "Sending\u2026" : "Send sign-in link"}</span><span class="mushi-submit-arrow" aria-hidden="true">\u2192</span>
|
|
2358
|
+
</button>
|
|
2359
|
+
</div>
|
|
2360
|
+
`;
|
|
2361
|
+
}
|
|
2362
|
+
function renderCrossAppReportsStep(ctx) {
|
|
2363
|
+
const reports = ctx.crossAppReports ?? [];
|
|
2364
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
2365
|
+
for (const r of reports) {
|
|
2366
|
+
const key = r.project_id ?? "unknown";
|
|
2367
|
+
if (!grouped.has(key)) grouped.set(key, { name: r.app_name ?? "Unknown App", reports: [] });
|
|
2368
|
+
grouped.get(key).reports.push(r);
|
|
2369
|
+
}
|
|
2370
|
+
const rows = [...grouped.entries()].map(([, group]) => `
|
|
2371
|
+
<div class="mushi-xapp-group">
|
|
2372
|
+
<h4 class="mushi-xapp-app-name">${escapeHtml(group.name)}</h4>
|
|
2373
|
+
${group.reports.map((r) => {
|
|
2374
|
+
const tone = reporterStatusTone(r.status);
|
|
2375
|
+
return `
|
|
2376
|
+
<div class="mushi-report-row" data-report-id="${escapeHtml(r.id)}" tabindex="0" role="button">
|
|
2377
|
+
<span class="mushi-report-status mushi-status-${tone}">${escapeHtml(reporterStatusShort(r.status))}</span>
|
|
2378
|
+
<span class="mushi-report-title">${escapeHtml(r.title ?? r.category)}</span>
|
|
2379
|
+
<span class="mushi-report-when">${escapeHtml(formatRelativeTime(r.created_at))}</span>
|
|
2380
|
+
</div>
|
|
2381
|
+
`;
|
|
2382
|
+
}).join("")}
|
|
2383
|
+
</div>
|
|
2384
|
+
`).join("");
|
|
2385
|
+
return `
|
|
2386
|
+
${renderHeader(ctx, { title: "My reports", showBack: true, eyebrow: "Mushi \xB7 All apps" })}
|
|
2387
|
+
<div class="mushi-body">
|
|
2388
|
+
${ctx.crossAppLoading ? '<p class="mushi-muted">Loading your reports\u2026</p>' : ""}
|
|
2389
|
+
${!ctx.crossAppLoading && !reports.length ? '<p class="mushi-muted">No reports filed yet.</p>' : ""}
|
|
2390
|
+
${rows}
|
|
2391
|
+
</div>
|
|
2392
|
+
`;
|
|
2393
|
+
}
|
|
2394
|
+
function renderReportDetailStep(ctx) {
|
|
2395
|
+
const report = ctx.reporterReports.find((r) => r.id === ctx.selectedReportId);
|
|
2396
|
+
const status = report?.status ?? "unknown";
|
|
2397
|
+
const tone = reporterStatusTone(status);
|
|
2398
|
+
const when = report?.created_at ? formatRelativeTime(report.created_at) : "";
|
|
2399
|
+
const comments = ctx.reporterComments.map((comment) => `
|
|
2400
|
+
<div class="mushi-thread-comment ${comment.author_kind}">
|
|
2401
|
+
<strong>${escapeHtml(comment.author_kind === "reporter" ? "You" : comment.author_name ?? "Developer")}</strong>
|
|
2402
|
+
<p>${escapeHtml(comment.body)}</p>
|
|
2403
|
+
</div>
|
|
2404
|
+
`).join("");
|
|
2405
|
+
return `
|
|
2406
|
+
${renderHeader(ctx, { title: "Report thread", showBack: true, eyebrow: "Mushi \xB7 Inbox" })}
|
|
2407
|
+
<div class="mushi-body">
|
|
2408
|
+
<div class="mushi-thread-summary">
|
|
2409
|
+
<div class="mushi-thread-summary-meta">
|
|
2410
|
+
<span class="mushi-report-status mushi-status-${tone}">${escapeHtml(reporterStatusLabel(status))}</span>
|
|
2411
|
+
${when ? `<span class="mushi-report-when">Reported ${escapeHtml(when)}</span>` : ""}
|
|
2412
|
+
</div>
|
|
2413
|
+
<p>${escapeHtml(report?.summary ?? report?.description ?? "Report details")}</p>
|
|
2414
|
+
</div>
|
|
2415
|
+
<div class="mushi-thread">
|
|
2416
|
+
${ctx.reporterLoading ? '<p class="mushi-muted">Loading thread\u2026</p>' : comments || '<p class="mushi-muted">No developer replies yet.</p>'}
|
|
2417
|
+
</div>
|
|
2418
|
+
${["fixed", "resolved", "verified"].includes(status) ? `
|
|
2419
|
+
<div class="mushi-verify-actions" role="group" aria-label="Fix verification">
|
|
2420
|
+
<button type="button" class="mushi-intent-btn" data-action="reporter-confirms">Yes, fixed for me</button>
|
|
2421
|
+
<button type="button" class="mushi-intent-btn" data-action="reporter-not-fixed">Not fixed yet</button>
|
|
2422
|
+
</div>
|
|
2423
|
+
` : ""}
|
|
2424
|
+
<textarea class="mushi-textarea" data-role="reporter-reply" rows="3" placeholder="Reply to the developer\u2026"></textarea>
|
|
2425
|
+
<button type="button" class="mushi-submit" data-action="reporter-reply">
|
|
2426
|
+
<span>Reply</span><span class="mushi-submit-arrow" aria-hidden="true">\u2192</span>
|
|
2427
|
+
</button>
|
|
2428
|
+
</div>
|
|
2429
|
+
`;
|
|
2430
|
+
}
|
|
2431
|
+
function renderIntentStep(ctx) {
|
|
2432
|
+
const t = ctx.locale;
|
|
2433
|
+
const catId = ctx.selectedCategory;
|
|
2434
|
+
const customEntry = ctx.resolveCustomCategory(catId);
|
|
2435
|
+
const intents = customEntry?.intents ?? (t.step2.intents[catId] || []);
|
|
2436
|
+
const options = intents.map((intent) => `
|
|
2437
|
+
<button type="button" class="mushi-intent-btn" data-intent="${escapeHtml(intent)}">
|
|
2438
|
+
${escapeHtml(intent)}
|
|
2439
|
+
</button>
|
|
2440
|
+
`).join("");
|
|
2441
|
+
const icon = ctx.categoryIcon(catId);
|
|
2442
|
+
const label = ctx.categoryLabel(catId);
|
|
2443
|
+
return `
|
|
2444
|
+
${renderHeader(ctx, { title: t.step2.heading, showBack: true, step: STEP_NUMBER.intent })}
|
|
2445
|
+
<div class="mushi-body">
|
|
2446
|
+
<div class="mushi-selected-category">
|
|
2447
|
+
<span aria-hidden="true">${escapeHtml(icon)}</span>
|
|
2448
|
+
<span>${escapeHtml(label)}</span>
|
|
2449
|
+
</div>
|
|
2450
|
+
<div class="mushi-intents">
|
|
2451
|
+
${options}
|
|
2452
|
+
</div>
|
|
2453
|
+
</div>
|
|
2454
|
+
${renderStepIndicator(ctx, STEP_NUMBER.intent)}
|
|
2455
|
+
`;
|
|
2456
|
+
}
|
|
2457
|
+
function renderDetailsStep(ctx) {
|
|
2458
|
+
const t = ctx.locale;
|
|
2459
|
+
const minLen = ctx.effectiveMinLength();
|
|
2460
|
+
const screenshotLabel = ctx.screenshotCapturing ? t.step3.screenshotCapturing : ctx.screenshotError ? t.step3.screenshotFailed : ctx.screenshotAttached ? t.step3.screenshotAttached : t.step3.screenshotButton;
|
|
2461
|
+
const screenshotClass = [
|
|
2462
|
+
"mushi-attach-btn",
|
|
2463
|
+
ctx.screenshotAttached ? "active" : "",
|
|
2464
|
+
ctx.screenshotError ? "error" : "",
|
|
2465
|
+
ctx.screenshotCapturing ? "loading" : ""
|
|
2466
|
+
].filter(Boolean).join(" ");
|
|
2467
|
+
const elementLabel = ctx.elementCapturing ? t.step3.elementCapturing : ctx.elementSelected ? t.step3.elementSelected : t.step3.elementButton;
|
|
2468
|
+
const elementClass = [
|
|
2469
|
+
"mushi-attach-btn",
|
|
2470
|
+
ctx.elementSelected ? "active" : "",
|
|
2471
|
+
ctx.elementCapturing ? "loading" : ""
|
|
2472
|
+
].filter(Boolean).join(" ");
|
|
2473
|
+
const exampleChips = t.step3.examplePrompts.map((p) => `<button type="button" class="mushi-example-chip" data-example="${escapeHtml(p)}">${escapeHtml(p)}</button>`).join("");
|
|
2474
|
+
return `
|
|
2475
|
+
${renderHeader(ctx, { title: t.step3.heading, showBack: true, step: STEP_NUMBER.details })}
|
|
2476
|
+
<div class="mushi-body">
|
|
2477
|
+
<div class="mushi-example-chips" aria-label="Example prompts">${exampleChips}</div>
|
|
2478
|
+
<div class="mushi-textarea-wrap">
|
|
2479
|
+
<textarea
|
|
2480
|
+
class="mushi-textarea"
|
|
2481
|
+
placeholder="${t.step3.descriptionPlaceholder}"
|
|
2482
|
+
rows="4"
|
|
2483
|
+
aria-label="${t.step3.heading}"
|
|
2484
|
+
autofocus
|
|
2485
|
+
></textarea>
|
|
2486
|
+
<div class="mushi-char-counter" data-role="char-counter" aria-hidden="true">
|
|
2487
|
+
<span data-role="char-current">0</span>/<span data-role="char-min">${minLen}</span>
|
|
2488
|
+
</div>
|
|
2489
|
+
</div>
|
|
2490
|
+
<div class="mushi-attachments">
|
|
2491
|
+
<button type="button" class="${screenshotClass}"
|
|
2492
|
+
data-action="screenshot"
|
|
2493
|
+
${ctx.screenshotCapturing ? "disabled" : ""}
|
|
2494
|
+
aria-label="${escapeHtml(screenshotLabel)}"
|
|
2495
|
+
>
|
|
2496
|
+
${ctx.screenshotCapturing ? '<span class="mushi-spinner" aria-hidden="true"></span>' : "\u{1F4F8}"}
|
|
2497
|
+
${escapeHtml(screenshotLabel)}
|
|
2498
|
+
</button>
|
|
2499
|
+
${ctx.screenshotAttached && ctx.allowScreenshotRemove ? '<button type="button" class="mushi-attach-btn danger" data-action="remove-screenshot" aria-label="Remove screenshot">\u2715 Remove</button>' : ""}
|
|
2500
|
+
${ctx.screenshotAttached ? '<button type="button" class="mushi-attach-btn" data-action="annotate-screenshot" aria-label="Mark up screenshot">\u270F Mark up</button><div class="mushi-annotate-host" data-role="annotate-host"></div>' : ""}
|
|
2501
|
+
<button type="button" class="${elementClass}"
|
|
2502
|
+
data-action="element"
|
|
2503
|
+
${ctx.elementCapturing ? "disabled" : ""}
|
|
2504
|
+
aria-label="${escapeHtml(elementLabel)}"
|
|
2505
|
+
>
|
|
2506
|
+
${ctx.elementCapturing ? '<span class="mushi-spinner" aria-hidden="true"></span>' : "\u{1F3AF}"}
|
|
2507
|
+
${escapeHtml(elementLabel)}
|
|
2508
|
+
</button>
|
|
2509
|
+
</div>
|
|
2510
|
+
<div class="mushi-error" style="display:none" role="alert"></div>
|
|
2511
|
+
</div>
|
|
2512
|
+
<div class="mushi-footer">
|
|
2513
|
+
<span class="mushi-footer-hint" aria-hidden="true">\u2318 + ENTER \u2192 send</span>
|
|
2514
|
+
<button type="button" class="mushi-submit" data-action="submit"${ctx.submitting ? " disabled" : ""}>
|
|
2515
|
+
<span>${ctx.submitting ? t.widget.submitting : t.widget.submit}</span>
|
|
2516
|
+
<span class="mushi-submit-arrow" aria-hidden="true">\u2192</span>
|
|
2517
|
+
</button>
|
|
2518
|
+
</div>
|
|
2519
|
+
${renderStepIndicator(ctx, STEP_NUMBER.details)}
|
|
2520
|
+
`;
|
|
2521
|
+
}
|
|
2522
|
+
function renderSuccessStep(ctx) {
|
|
2523
|
+
const t = ctx.locale;
|
|
2524
|
+
const stamp = ctx.submittedAt ?? /* @__PURE__ */ new Date();
|
|
2525
|
+
const time = stamp.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false });
|
|
2526
|
+
return `
|
|
2527
|
+
${renderHeader(ctx, { title: t.widget.title, eyebrow: "Mushi \xB7 Receipt" })}
|
|
2528
|
+
<div class="mushi-body">
|
|
2529
|
+
<div class="mushi-success">
|
|
2530
|
+
<div class="mushi-success-stamp" aria-hidden="true">
|
|
2531
|
+
<svg viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet"><circle cx="50" cy="50" r="44"/></svg>
|
|
2532
|
+
<span class="mushi-success-stamp-label">\u53D7</span>
|
|
2533
|
+
</div>
|
|
2534
|
+
<div class="mushi-success-headline">${t.widget.submitted}</div>
|
|
2535
|
+
<div class="mushi-success-meta">REPORT \xB7 ${time}</div>
|
|
2536
|
+
${renderSuccessReceipt(ctx)}
|
|
2537
|
+
${ctx.rewardsState ? renderSuccessRewards(ctx) : ""}
|
|
2538
|
+
${ctx.config.betaMode?.enabled ? renderBetaSuccessFooter(ctx) : ""}
|
|
2539
|
+
</div>
|
|
2540
|
+
</div>
|
|
2541
|
+
`;
|
|
2542
|
+
}
|
|
2543
|
+
function renderSuccessReceipt(ctx) {
|
|
2544
|
+
if (ctx.lastSubmitQueuedOffline) {
|
|
2545
|
+
return `
|
|
2546
|
+
<div class="mushi-success-receipt" role="status">
|
|
2547
|
+
<div class="mushi-success-receipt-row mushi-success-receipt-warn">
|
|
2548
|
+
<span class="mushi-success-receipt-label">Queued offline</span>
|
|
2549
|
+
<span class="mushi-success-receipt-hint">We’ll send it the moment you’re back online.</span>
|
|
2550
|
+
</div>
|
|
2551
|
+
</div>
|
|
2552
|
+
`;
|
|
2277
2553
|
}
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2554
|
+
if (!ctx.lastReportId) {
|
|
2555
|
+
return `
|
|
2556
|
+
<div class="mushi-success-receipt" role="status">
|
|
2557
|
+
<div class="mushi-success-receipt-row">
|
|
2558
|
+
<span class="mushi-success-receipt-spinner" aria-hidden="true"></span>
|
|
2559
|
+
<span class="mushi-success-receipt-hint">Delivering to the team\u2026</span>
|
|
2560
|
+
</div>
|
|
2561
|
+
${renderSlaLine(ctx)}
|
|
2562
|
+
</div>
|
|
2563
|
+
`;
|
|
2281
2564
|
}
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2565
|
+
const idShort = `#${ctx.lastReportId.slice(0, 8)}`;
|
|
2566
|
+
const dashboard = (ctx.config.dashboardUrl ?? "").replace(/\/$/, "");
|
|
2567
|
+
const trackHref = dashboard ? `${dashboard}/reports/${encodeURIComponent(ctx.lastReportId)}` : "";
|
|
2568
|
+
return `
|
|
2569
|
+
<div class="mushi-success-receipt" role="status">
|
|
2570
|
+
<div class="mushi-success-receipt-row">
|
|
2571
|
+
<span class="mushi-success-receipt-label">Receipt</span>
|
|
2572
|
+
<button
|
|
2573
|
+
type="button"
|
|
2574
|
+
class="mushi-success-receipt-id"
|
|
2575
|
+
data-action="copy-report-id"
|
|
2576
|
+
data-copy-id="${escapeHtml(ctx.lastReportId)}"
|
|
2577
|
+
title="Copy report id ${escapeHtml(ctx.lastReportId)}"
|
|
2578
|
+
aria-label="Copy report id ${escapeHtml(ctx.lastReportId)}"
|
|
2579
|
+
>${escapeHtml(idShort)}<span class="mushi-success-receipt-copy" aria-hidden="true">\u2398</span></button>
|
|
2580
|
+
</div>
|
|
2581
|
+
${trackHref ? `
|
|
2582
|
+
<a
|
|
2583
|
+
class="mushi-success-receipt-track"
|
|
2584
|
+
href="${escapeHtml(trackHref)}"
|
|
2585
|
+
target="_blank"
|
|
2586
|
+
rel="noopener noreferrer"
|
|
2587
|
+
>Track on Mushi <span aria-hidden="true">\u2197</span></a>
|
|
2588
|
+
` : ""}
|
|
2589
|
+
${renderSlaLine(ctx)}
|
|
2590
|
+
</div>
|
|
2305
2591
|
`;
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2592
|
+
}
|
|
2593
|
+
function renderSlaLine(ctx) {
|
|
2594
|
+
const sla = (ctx.config.responseSlaLabel ?? "").trim();
|
|
2595
|
+
if (sla) {
|
|
2596
|
+
return `<div class="mushi-success-sla">${escapeHtml(sla)}</div>`;
|
|
2309
2597
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2598
|
+
return `<div class="mushi-success-sla mushi-success-sla-default">A human will look at this within a working day.</div>`;
|
|
2599
|
+
}
|
|
2600
|
+
function renderBetaSuccessFooter(ctx) {
|
|
2601
|
+
const beta = ctx.config.betaMode;
|
|
2602
|
+
const email = beta.contactEmail ? escapeHtml(beta.contactEmail) : null;
|
|
2603
|
+
const appName = escapeHtml(beta.appName ?? "the team");
|
|
2604
|
+
return `
|
|
2605
|
+
<div class="mushi-beta-success-footer" role="note" aria-label="Beta feedback acknowledgement">
|
|
2606
|
+
${email ? `<div class="mushi-beta-success-line">\u{1F4EC} Sent to ${email}</div>` : `<div class="mushi-beta-success-line">\u{1F4EC} Sent to ${appName}</div>`}
|
|
2607
|
+
<div class="mushi-beta-success-line mushi-beta-success-dim">We aim to review within 48h \xB7 thank you for helping build this</div>
|
|
2608
|
+
</div>
|
|
2609
|
+
`;
|
|
2610
|
+
}
|
|
2611
|
+
function renderRewardsNudge(ctx) {
|
|
2612
|
+
const { tier, nextTier, totalPoints, pointsForReport } = ctx.rewardsState;
|
|
2613
|
+
const tierName = tier?.displayName ?? "Free";
|
|
2614
|
+
const tierSlug = tier?.slug ?? "free";
|
|
2615
|
+
const color = ctx.tierColor(tierSlug);
|
|
2616
|
+
let pct = 100;
|
|
2617
|
+
let nextLabel = "";
|
|
2618
|
+
if (nextTier) {
|
|
2619
|
+
const base = tier?.pointsThreshold ?? 0;
|
|
2620
|
+
const ceiling = nextTier.pointsThreshold;
|
|
2621
|
+
pct = ceiling > base ? Math.round(Math.min(1, (totalPoints - base) / (ceiling - base)) * 100) : 100;
|
|
2622
|
+
const remaining = Math.max(0, ceiling - totalPoints);
|
|
2623
|
+
nextLabel = `${remaining.toLocaleString()} pts to ${escapeHtml(nextTier.displayName)}`;
|
|
2314
2624
|
}
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
2331
|
-
font-size: 12px;
|
|
2332
|
-
line-height: 1.4;
|
|
2333
|
-
padding: 8px 12px;
|
|
2334
|
-
border-radius: 8px;
|
|
2335
|
-
max-width: 200px;
|
|
2336
|
-
pointer-events: none;
|
|
2337
|
-
backdrop-filter: blur(4px);
|
|
2338
|
-
box-shadow: 0 2px 12px rgba(0,0,0,0.35);
|
|
2339
|
-
animation: mushi-fade-in 0.15s ease forwards;
|
|
2625
|
+
return `
|
|
2626
|
+
<div class="mushi-rewards-nudge" aria-label="Rewards progress">
|
|
2627
|
+
<div class="mushi-rewards-row">
|
|
2628
|
+
<span class="mushi-tier-pip" style="background:${color}" aria-hidden="true"></span>
|
|
2629
|
+
<span class="mushi-rewards-tier-name">${escapeHtml(tierName)}</span>
|
|
2630
|
+
<span class="mushi-rewards-pts-count">${totalPoints.toLocaleString()} pts</span>
|
|
2631
|
+
<span class="mushi-rewards-pts-earn">+${pointsForReport} pts for a report</span>
|
|
2632
|
+
</div>
|
|
2633
|
+
${nextTier ? `
|
|
2634
|
+
<div class="mushi-tier-bar-track" role="progressbar" aria-valuenow="${pct}" aria-valuemin="0" aria-valuemax="100" aria-label="Progress to ${escapeHtml(nextTier.displayName)}">
|
|
2635
|
+
<div class="mushi-tier-bar-fill" style="width:${pct}%"></div>
|
|
2636
|
+
</div>
|
|
2637
|
+
<div class="mushi-rewards-next-label">${nextLabel}</div>
|
|
2638
|
+
` : ""}
|
|
2639
|
+
</div>
|
|
2340
2640
|
`;
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2641
|
+
}
|
|
2642
|
+
function renderSuccessRewards(ctx) {
|
|
2643
|
+
const { tier, nextTier, totalPoints, pointsForReport } = ctx.rewardsState;
|
|
2644
|
+
const projected = totalPoints + pointsForReport;
|
|
2645
|
+
let pctAfter = 100;
|
|
2646
|
+
let nextLabel = "";
|
|
2647
|
+
if (nextTier) {
|
|
2648
|
+
const base = tier?.pointsThreshold ?? 0;
|
|
2649
|
+
const ceiling = nextTier.pointsThreshold;
|
|
2650
|
+
pctAfter = ceiling > base ? Math.round(Math.min(1, (projected - base) / (ceiling - base)) * 100) : 100;
|
|
2651
|
+
const remaining = Math.max(0, ceiling - projected);
|
|
2652
|
+
nextLabel = remaining > 0 ? `${remaining.toLocaleString()} pts to ${escapeHtml(nextTier.displayName)}` : `\u{1F389} ${escapeHtml(nextTier.displayName)} reached!`;
|
|
2346
2653
|
}
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2654
|
+
return `
|
|
2655
|
+
<div class="mushi-success-rewards">
|
|
2656
|
+
<div class="mushi-success-pts-award">+${pointsForReport} pts</div>
|
|
2657
|
+
${nextTier ? `
|
|
2658
|
+
<div class="mushi-tier-bar-track success-bar" role="progressbar" aria-valuenow="${pctAfter}" aria-valuemin="0" aria-valuemax="100" aria-label="Progress to ${escapeHtml(nextTier.displayName)}">
|
|
2659
|
+
<div class="mushi-tier-bar-fill" style="width:${pctAfter}%"></div>
|
|
2660
|
+
</div>
|
|
2661
|
+
<div class="mushi-rewards-next-label">${nextLabel}</div>
|
|
2662
|
+
` : ""}
|
|
2663
|
+
</div>
|
|
2664
|
+
`;
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
// src/widget.ts
|
|
2668
|
+
var MushiWidget = class _MushiWidget {
|
|
2669
|
+
// double-submit guard
|
|
2670
|
+
constructor(config = {}, callbacks, sdkVersion = MUSHI_SDK_VERSION) {
|
|
2671
|
+
this.sdkVersion = sdkVersion;
|
|
2672
|
+
this.config = {
|
|
2673
|
+
position: config.position ?? "bottom-right",
|
|
2674
|
+
anchor: config.anchor ?? {},
|
|
2675
|
+
theme: config.theme ?? "auto",
|
|
2676
|
+
// Falsy-OR (NOT `??`) on purpose: `triggerText: ''` is semantically
|
|
2677
|
+
// nonsense — it would render a labelless, glyphless trigger button
|
|
2678
|
+
// that users can't see or aim at. Treat empty string the same as
|
|
2679
|
+
// omitted so any caller that wires this to a cleared form input or
|
|
2680
|
+
// pastes a legacy snippet that emitted `triggerText: ""` (see
|
|
2681
|
+
// apps/admin/src/lib/sdkSnippets.ts widgetLines history) still gets
|
|
2682
|
+
// the default 🐛 and a visible button.
|
|
2683
|
+
triggerText: config.triggerText || "\u{1F41B}",
|
|
2684
|
+
expandedTitle: config.expandedTitle ?? "",
|
|
2685
|
+
mode: config.mode ?? "conversational",
|
|
2686
|
+
locale: config.locale ?? "auto",
|
|
2687
|
+
zIndex: config.zIndex ?? 99999,
|
|
2688
|
+
trigger: config.trigger ?? "auto",
|
|
2689
|
+
bannerConfig: config.bannerConfig ?? {},
|
|
2690
|
+
attachToSelector: config.attachToSelector ?? "",
|
|
2691
|
+
inset: config.inset ?? {},
|
|
2692
|
+
respectSafeArea: config.respectSafeArea ?? true,
|
|
2693
|
+
hideOnSelector: config.hideOnSelector ?? "",
|
|
2694
|
+
hideOnRoutes: config.hideOnRoutes ?? [],
|
|
2695
|
+
environments: config.environments ?? {},
|
|
2696
|
+
smartHide: config.smartHide ?? false,
|
|
2697
|
+
draggable: config.draggable ?? false,
|
|
2698
|
+
brandFooter: config.brandFooter ?? true,
|
|
2699
|
+
outdatedBanner: config.outdatedBanner ?? "auto",
|
|
2700
|
+
betaMode: config.betaMode ?? {},
|
|
2701
|
+
minDescriptionLength: config.minDescriptionLength ?? 20,
|
|
2702
|
+
dashboardUrl: config.dashboardUrl ?? "",
|
|
2703
|
+
responseSlaLabel: config.responseSlaLabel ?? "",
|
|
2704
|
+
featureRequestCard: config.featureRequestCard ?? true,
|
|
2705
|
+
featureRequestLabel: config.featureRequestLabel || "Feature request",
|
|
2706
|
+
featureRequestDescription: config.featureRequestDescription || "Suggest something new \u2014 even rough ideas help us prioritise",
|
|
2707
|
+
avoidSelectors: config.avoidSelectors ?? [],
|
|
2708
|
+
categories: config.categories ?? [],
|
|
2709
|
+
accent: config.accent ?? "",
|
|
2710
|
+
accentText: config.accentText ?? ""
|
|
2711
|
+
};
|
|
2712
|
+
this.callbacks = callbacks;
|
|
2713
|
+
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
2714
|
+
this.host = document.createElement("div");
|
|
2715
|
+
this.host.id = "mushi-mushi-widget";
|
|
2716
|
+
this.shadow = this.host.attachShadow({ mode: "closed" });
|
|
2355
2717
|
}
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2718
|
+
sdkVersion;
|
|
2719
|
+
host;
|
|
2720
|
+
shadow;
|
|
2721
|
+
config;
|
|
2722
|
+
callbacks;
|
|
2723
|
+
locale;
|
|
2724
|
+
isOpen = false;
|
|
2725
|
+
step = "category";
|
|
2726
|
+
/**
|
|
2727
|
+
* The selected category id. May be a built-in `MushiReportCategory` or a
|
|
2728
|
+
* custom id from `config.categories`. Cast to `MushiReportCategory` only
|
|
2729
|
+
* after resolving through `resolveBaseCategory()`.
|
|
2730
|
+
*/
|
|
2731
|
+
selectedCategory = null;
|
|
2732
|
+
selectedIntent = null;
|
|
2733
|
+
/**
|
|
2734
|
+
* True when the user took the "Feature request" shortcut. We track this
|
|
2735
|
+
* separately from `selectedCategory='other'` so the Back button on the
|
|
2736
|
+
* details step jumps straight back to the category picker instead of
|
|
2737
|
+
* landing on the intent picker the user explicitly skipped.
|
|
2738
|
+
*/
|
|
2739
|
+
viaFeatureRequest = false;
|
|
2740
|
+
screenshotAttached = false;
|
|
2741
|
+
screenshotCapturing = false;
|
|
2742
|
+
screenshotError = false;
|
|
2743
|
+
allowScreenshotRemove = true;
|
|
2744
|
+
elementSelected = false;
|
|
2745
|
+
elementCapturing = false;
|
|
2746
|
+
submitting = false;
|
|
2747
|
+
/** Hint element injected outside the shadow DOM during element selection. */
|
|
2748
|
+
selectorHint = null;
|
|
2749
|
+
triggerVisible = true;
|
|
2750
|
+
triggerShrunk = false;
|
|
2751
|
+
triggerHiddenByScroll = false;
|
|
2752
|
+
/** Milliseconds since mount — used for the 30s first-time nudge gate. */
|
|
2753
|
+
mountedAt = null;
|
|
2754
|
+
nudgeShown = false;
|
|
2755
|
+
nudgeEl = null;
|
|
2756
|
+
nudgeTimer = null;
|
|
2757
|
+
sdkFreshness = null;
|
|
2758
|
+
reporterReports = [];
|
|
2759
|
+
featureBoard = [];
|
|
2760
|
+
reporterComments = [];
|
|
2761
|
+
selectedReportId = null;
|
|
2762
|
+
reporterLoading = false;
|
|
2763
|
+
reporterError = null;
|
|
2764
|
+
attachedLaunchers = [];
|
|
2765
|
+
smartHideCleanup = null;
|
|
2766
|
+
smartHideTimer = null;
|
|
2767
|
+
/** Captured at the moment of submit so the success ledger metadata
|
|
2768
|
+
* ("REPORT · 14:23:07 JST") doesn't drift while the success step
|
|
2769
|
+
* is on screen. */
|
|
2770
|
+
submittedAt = null;
|
|
2771
|
+
/** Pending success-state + auto-close timers. Tracked so destroy()
|
|
2772
|
+
* can clear them — otherwise a host that unmounts mid-submit leaks
|
|
2773
|
+
* this MushiWidget reference (and re-renders into a detached shadow
|
|
2774
|
+
* root) for up to ~3.3s after destroy. */
|
|
2775
|
+
successTimer = null;
|
|
2776
|
+
autoCloseTimer = null;
|
|
2777
|
+
rewardsState = null;
|
|
2778
|
+
leaderboardEntries = null;
|
|
2779
|
+
leaderboardLoading = false;
|
|
2780
|
+
/** Server-confirmed id for the just-submitted report. Surfaces in
|
|
2781
|
+
* the success step as a copyable receipt + optional deep link to
|
|
2782
|
+
* the Mushi console (when `dashboardUrl` is configured). Cleared
|
|
2783
|
+
* on every new `open()` so a re-opened widget never reuses a
|
|
2784
|
+
* stale id from the previous session. */
|
|
2785
|
+
lastReportId = null;
|
|
2786
|
+
/** True when the just-submitted report was queued offline (no
|
|
2787
|
+
* network, or the API errored and went into the retry queue).
|
|
2788
|
+
* Drives a different success copy so the user knows the report
|
|
2789
|
+
* hasn't actually reached the console yet. */
|
|
2790
|
+
lastSubmitQueuedOffline = false;
|
|
2791
|
+
/** Whether the user has clicked ✕ on the header banner this session. */
|
|
2792
|
+
bannerDismissed = false;
|
|
2793
|
+
/** Persisted FAB position when draggable is enabled. */
|
|
2794
|
+
fabPos = null;
|
|
2795
|
+
/** Cleanup fn for visualViewport keyboard listener. */
|
|
2796
|
+
vvCleanup = null;
|
|
2797
|
+
/** Mushi tester session JWT — set after in-widget sign-in or by mushi.ts. */
|
|
2798
|
+
testerJwt = null;
|
|
2799
|
+
/** Tester identity (public_handle, display_name). */
|
|
2800
|
+
testerInfo = null;
|
|
2801
|
+
/** Cross-app reports for the signed-in tester. */
|
|
2802
|
+
crossAppReports = null;
|
|
2803
|
+
crossAppLoading = false;
|
|
2804
|
+
/** Global leaderboard entries (from mushi_testers, not org-scoped). */
|
|
2805
|
+
globalLeaderboard = null;
|
|
2806
|
+
globalLeaderboardLoading = false;
|
|
2807
|
+
/** Reputation for the signed-in tester. */
|
|
2808
|
+
testerReputation = null;
|
|
2809
|
+
/** Whether an in-widget magic-link email was just sent. */
|
|
2810
|
+
magicLinkSent = false;
|
|
2811
|
+
magicLinkEmail = "";
|
|
2812
|
+
magicLinkError = "";
|
|
2813
|
+
magicLinkSending = false;
|
|
2814
|
+
mount() {
|
|
2815
|
+
if (this.host.isConnected) return;
|
|
2816
|
+
this.syncHostChromeState();
|
|
2817
|
+
document.body.appendChild(this.host);
|
|
2818
|
+
this.syncAttachedLaunchers();
|
|
2819
|
+
this.syncSmartHide();
|
|
2820
|
+
this.render();
|
|
2821
|
+
this.mountedAt = Date.now();
|
|
2359
2822
|
}
|
|
2360
|
-
|
|
2361
|
-
this.
|
|
2362
|
-
if (this.isOpen) this.render();
|
|
2823
|
+
getIsMounted() {
|
|
2824
|
+
return this.host.isConnected;
|
|
2363
2825
|
}
|
|
2364
|
-
|
|
2365
|
-
this.
|
|
2366
|
-
|
|
2367
|
-
|
|
2826
|
+
updateConfig(config = {}) {
|
|
2827
|
+
this.config = {
|
|
2828
|
+
...this.config,
|
|
2829
|
+
...config.position ? { position: config.position } : {},
|
|
2830
|
+
...config.anchor !== void 0 ? { anchor: config.anchor } : {},
|
|
2831
|
+
...config.theme ? { theme: config.theme } : {},
|
|
2832
|
+
...config.triggerText !== void 0 ? { triggerText: config.triggerText || "\u{1F41B}" } : {},
|
|
2833
|
+
...config.expandedTitle !== void 0 ? { expandedTitle: config.expandedTitle } : {},
|
|
2834
|
+
...config.mode ? { mode: config.mode } : {},
|
|
2835
|
+
...config.locale ? { locale: config.locale } : {},
|
|
2836
|
+
...config.zIndex !== void 0 ? { zIndex: config.zIndex } : {},
|
|
2837
|
+
...config.trigger ? { trigger: config.trigger } : {},
|
|
2838
|
+
...config.attachToSelector !== void 0 ? { attachToSelector: config.attachToSelector } : {},
|
|
2839
|
+
...config.inset !== void 0 ? { inset: config.inset } : {},
|
|
2840
|
+
...config.respectSafeArea !== void 0 ? { respectSafeArea: config.respectSafeArea } : {},
|
|
2841
|
+
...config.hideOnSelector !== void 0 ? { hideOnSelector: config.hideOnSelector } : {},
|
|
2842
|
+
...config.hideOnRoutes !== void 0 ? { hideOnRoutes: config.hideOnRoutes } : {},
|
|
2843
|
+
...config.environments !== void 0 ? { environments: config.environments } : {},
|
|
2844
|
+
...config.smartHide !== void 0 ? { smartHide: config.smartHide } : {},
|
|
2845
|
+
...config.draggable !== void 0 ? { draggable: config.draggable } : {},
|
|
2846
|
+
...config.brandFooter !== void 0 ? { brandFooter: config.brandFooter } : {},
|
|
2847
|
+
...config.outdatedBanner !== void 0 ? { outdatedBanner: config.outdatedBanner } : {},
|
|
2848
|
+
...config.betaMode !== void 0 ? { betaMode: config.betaMode } : {},
|
|
2849
|
+
...config.minDescriptionLength !== void 0 ? { minDescriptionLength: config.minDescriptionLength } : {},
|
|
2850
|
+
...config.dashboardUrl !== void 0 ? { dashboardUrl: config.dashboardUrl } : {},
|
|
2851
|
+
...config.responseSlaLabel !== void 0 ? { responseSlaLabel: config.responseSlaLabel } : {},
|
|
2852
|
+
...config.featureRequestCard !== void 0 ? { featureRequestCard: config.featureRequestCard } : {},
|
|
2853
|
+
...config.featureRequestLabel !== void 0 ? { featureRequestLabel: config.featureRequestLabel || "Feature request" } : {},
|
|
2854
|
+
...config.featureRequestDescription !== void 0 ? { featureRequestDescription: config.featureRequestDescription || "Suggest something new \u2014 even rough ideas help us prioritise" } : {},
|
|
2855
|
+
// Runtime/dashboard config delivers bannerMessage/bannerLabel via
|
|
2856
|
+
// mergeRuntimeConfig → bannerConfig. The widget is constructed before
|
|
2857
|
+
// that fetch resolves, so this pass-through is what makes server-driven
|
|
2858
|
+
// banner copy actually render.
|
|
2859
|
+
...config.bannerConfig !== void 0 ? { bannerConfig: config.bannerConfig } : {},
|
|
2860
|
+
...config.categories !== void 0 ? { categories: config.categories } : {}
|
|
2861
|
+
};
|
|
2862
|
+
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
2863
|
+
if (this.host.isConnected) this.syncHostChromeState();
|
|
2864
|
+
this.syncAttachedLaunchers();
|
|
2865
|
+
this.syncSmartHide();
|
|
2866
|
+
this.render();
|
|
2368
2867
|
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
}
|
|
2374
|
-
if (this.autoCloseTimer !== null) {
|
|
2375
|
-
clearTimeout(this.autoCloseTimer);
|
|
2376
|
-
this.autoCloseTimer = null;
|
|
2377
|
-
}
|
|
2378
|
-
if (this.smartHideTimer !== null) {
|
|
2379
|
-
clearTimeout(this.smartHideTimer);
|
|
2380
|
-
this.smartHideTimer = null;
|
|
2381
|
-
}
|
|
2382
|
-
this.smartHideCleanup?.();
|
|
2383
|
-
this.smartHideCleanup = null;
|
|
2384
|
-
this.attachedLaunchers.forEach((cleanup) => cleanup());
|
|
2385
|
-
this.attachedLaunchers = [];
|
|
2386
|
-
this.removeSelectorHint();
|
|
2387
|
-
this.removeNudge();
|
|
2388
|
-
this.removeBodyNudge();
|
|
2389
|
-
this.host.remove();
|
|
2868
|
+
// ─── Custom category helpers ──────────────────────────────────────────────
|
|
2869
|
+
/** Find a custom category entry by id. Returns undefined for built-in ids. */
|
|
2870
|
+
resolveCustomCategory(id) {
|
|
2871
|
+
return this.config.categories?.find((c) => c.id === id);
|
|
2390
2872
|
}
|
|
2391
|
-
/* ── Host chrome contract ────────────────────────────────────────────────
|
|
2392
|
-
The host element must never create an invisible full-screen touch blocker.
|
|
2393
|
-
We own these inline styles — consumer CSS can only win with `!important`,
|
|
2394
|
-
which is explicitly banned by the SDK contract. Calling this at mount()
|
|
2395
|
-
and after every zIndex update is the only safe invariant. */
|
|
2396
2873
|
/**
|
|
2397
|
-
*
|
|
2398
|
-
*
|
|
2399
|
-
* internals (`.mushi-trigger`, `.mushi-banner`, `.mushi-panel`) opt back
|
|
2400
|
-
* into pointer events. This is idempotent and safe to call repeatedly.
|
|
2874
|
+
* Map a (possibly custom) category id to the built-in `MushiReportCategory`
|
|
2875
|
+
* used for the report wire format. Falls back to `'other'`.
|
|
2401
2876
|
*/
|
|
2402
|
-
|
|
2403
|
-
const
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
s.setProperty("width", "0");
|
|
2408
|
-
s.setProperty("height", "0");
|
|
2409
|
-
s.setProperty("overflow", "visible");
|
|
2410
|
-
s.setProperty("pointer-events", "none");
|
|
2411
|
-
s.setProperty("z-index", String(this.config.zIndex));
|
|
2412
|
-
s.setProperty("margin", "0");
|
|
2413
|
-
s.setProperty("padding", "0");
|
|
2414
|
-
s.setProperty("border", "none");
|
|
2415
|
-
s.setProperty("background", "none");
|
|
2877
|
+
resolveBaseCategory(id) {
|
|
2878
|
+
const BUILTIN = ["bug", "slow", "visual", "confusing", "other"];
|
|
2879
|
+
if (BUILTIN.includes(id)) return id;
|
|
2880
|
+
const custom = this.resolveCustomCategory(id);
|
|
2881
|
+
return custom?.baseCategory ?? "other";
|
|
2416
2882
|
}
|
|
2417
|
-
/**
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2883
|
+
/** Icon for the selected category — custom entry's icon or built-in emoji. */
|
|
2884
|
+
categoryIcon(id) {
|
|
2885
|
+
const custom = this.resolveCustomCategory(id);
|
|
2886
|
+
if (custom?.icon) return custom.icon;
|
|
2887
|
+
return CATEGORY_ICONS[id] ?? "\u{1F4AC}";
|
|
2888
|
+
}
|
|
2889
|
+
/** Label for the selected category — custom entry label or built-in i18n string. */
|
|
2890
|
+
categoryLabel(id) {
|
|
2891
|
+
const custom = this.resolveCustomCategory(id);
|
|
2892
|
+
if (custom) return custom.label;
|
|
2893
|
+
const t = this.locale;
|
|
2894
|
+
return t.step1.categories[id] ?? id;
|
|
2895
|
+
}
|
|
2896
|
+
// ─── Open / close ─────────────────────────────────────────────────────────
|
|
2897
|
+
open(options) {
|
|
2898
|
+
if (this.isOpen) return;
|
|
2899
|
+
this.isOpen = true;
|
|
2900
|
+
this.screenshotAttached = false;
|
|
2901
|
+
this.screenshotCapturing = false;
|
|
2902
|
+
this.screenshotError = false;
|
|
2903
|
+
this.elementSelected = false;
|
|
2904
|
+
this.elementCapturing = false;
|
|
2905
|
+
this.submitting = false;
|
|
2906
|
+
this.submittedAt = null;
|
|
2907
|
+
this.removeSelectorHint();
|
|
2908
|
+
this.lastReportId = null;
|
|
2909
|
+
this.lastSubmitQueuedOffline = false;
|
|
2910
|
+
this.viaFeatureRequest = false;
|
|
2911
|
+
if (options?.featureRequest) {
|
|
2912
|
+
this.selectedCategory = "other";
|
|
2913
|
+
this.selectedIntent = FEATURE_REQUEST_INTENT;
|
|
2914
|
+
this.viaFeatureRequest = true;
|
|
2915
|
+
this.step = "details";
|
|
2916
|
+
} else if (options?.category) {
|
|
2917
|
+
this.selectedCategory = options.category;
|
|
2918
|
+
this.selectedIntent = null;
|
|
2919
|
+
const custom = this.resolveCustomCategory(options.category);
|
|
2920
|
+
this.step = custom && (!custom.intents || custom.intents.length === 0) ? "details" : "intent";
|
|
2921
|
+
} else {
|
|
2922
|
+
this.selectedCategory = null;
|
|
2923
|
+
this.selectedIntent = null;
|
|
2924
|
+
this.step = "category";
|
|
2429
2925
|
}
|
|
2926
|
+
this.render();
|
|
2927
|
+
this.callbacks.onOpen();
|
|
2928
|
+
}
|
|
2929
|
+
close() {
|
|
2930
|
+
if (!this.isOpen) return;
|
|
2931
|
+
this.isOpen = false;
|
|
2932
|
+
this.render();
|
|
2933
|
+
this.callbacks.onClose();
|
|
2430
2934
|
}
|
|
2431
2935
|
/**
|
|
2432
|
-
*
|
|
2433
|
-
*
|
|
2434
|
-
*
|
|
2936
|
+
* Briefly highlight the trigger button (a soft pulse + tooltip) without
|
|
2937
|
+
* opening the full reporter panel. Use for first-session welcome nudges
|
|
2938
|
+
* and other "by the way, this exists" prompts where forcing the panel
|
|
2939
|
+
* open would feel aggressive. Honours `position: 'none'` (no-op when
|
|
2940
|
+
* the trigger button is hidden).
|
|
2435
2941
|
*/
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
const
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
syncAttachedLaunchers() {
|
|
2445
|
-
this.attachedLaunchers.forEach((cleanup) => cleanup());
|
|
2446
|
-
this.attachedLaunchers = [];
|
|
2447
|
-
if (this.config.trigger !== "attach" || !this.config.attachToSelector) return;
|
|
2448
|
-
if (typeof document === "undefined") return;
|
|
2449
|
-
this.attachedLaunchers.push(this.attachTo(this.config.attachToSelector));
|
|
2942
|
+
pulseTrigger() {
|
|
2943
|
+
if (this.isOpen) return;
|
|
2944
|
+
const trigger = this.shadow.querySelector(".mushi-trigger");
|
|
2945
|
+
if (!trigger) return;
|
|
2946
|
+
trigger.classList.add("mushi-trigger-pulse");
|
|
2947
|
+
window.setTimeout(() => {
|
|
2948
|
+
trigger.classList.remove("mushi-trigger-pulse");
|
|
2949
|
+
}, 2400);
|
|
2450
2950
|
}
|
|
2451
|
-
|
|
2452
|
-
this.
|
|
2453
|
-
this.smartHideCleanup = null;
|
|
2454
|
-
this.triggerShrunk = false;
|
|
2455
|
-
this.triggerHiddenByScroll = false;
|
|
2456
|
-
if (!this.config.smartHide || typeof window === "undefined") return;
|
|
2457
|
-
const smart = this.config.smartHide === true ? { onScroll: "shrink", onIdleMs: 900 } : this.config.smartHide;
|
|
2458
|
-
if (!smart.onScroll) return;
|
|
2459
|
-
const onScroll = () => {
|
|
2460
|
-
if (smart.onScroll === "hide") {
|
|
2461
|
-
this.triggerHiddenByScroll = true;
|
|
2462
|
-
} else {
|
|
2463
|
-
this.triggerShrunk = true;
|
|
2464
|
-
}
|
|
2465
|
-
this.render();
|
|
2466
|
-
if (this.smartHideTimer !== null) clearTimeout(this.smartHideTimer);
|
|
2467
|
-
this.smartHideTimer = setTimeout(() => {
|
|
2468
|
-
this.triggerHiddenByScroll = false;
|
|
2469
|
-
this.triggerShrunk = false;
|
|
2470
|
-
this.render();
|
|
2471
|
-
}, smart.onIdleMs ?? 900);
|
|
2472
|
-
};
|
|
2473
|
-
window.addEventListener("scroll", onScroll, { passive: true });
|
|
2474
|
-
this.smartHideCleanup = () => window.removeEventListener("scroll", onScroll);
|
|
2951
|
+
getIsOpen() {
|
|
2952
|
+
return this.isOpen;
|
|
2475
2953
|
}
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
if (this.config.trigger === "manual" || this.config.trigger === "hidden" || this.config.trigger === "attach" || this.config.trigger === "banner") {
|
|
2480
|
-
return false;
|
|
2481
|
-
}
|
|
2482
|
-
if (this.isMobileSmartHidden()) return false;
|
|
2483
|
-
if (this.isRouteHidden()) return false;
|
|
2484
|
-
if (this.isSuppressedByHost()) return false;
|
|
2485
|
-
const action = this.config.environments[this.detectEnvironment()];
|
|
2486
|
-
return action !== "never" && action !== "manual";
|
|
2954
|
+
showTrigger() {
|
|
2955
|
+
this.triggerVisible = true;
|
|
2956
|
+
this.render();
|
|
2487
2957
|
}
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
static BODY_NUDGE_PROP = "--mushi-banner-offset";
|
|
2492
|
-
applyBodyNudge(position) {
|
|
2493
|
-
const h = `${_MushiWidget.BANNER_HEIGHT}px`;
|
|
2494
|
-
if (position === "top") {
|
|
2495
|
-
document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
|
|
2496
|
-
if (!document.body.style.paddingTop) {
|
|
2497
|
-
document.body.style.paddingTop = h;
|
|
2498
|
-
document.body.dataset.mushiBannerNudged = "top";
|
|
2499
|
-
}
|
|
2500
|
-
} else {
|
|
2501
|
-
document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
|
|
2502
|
-
if (!document.body.style.paddingBottom) {
|
|
2503
|
-
document.body.style.paddingBottom = h;
|
|
2504
|
-
document.body.dataset.mushiBannerNudged = "bottom";
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2958
|
+
hideTrigger() {
|
|
2959
|
+
this.triggerVisible = false;
|
|
2960
|
+
this.render();
|
|
2507
2961
|
}
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
const nudged = document.body.dataset.mushiBannerNudged;
|
|
2511
|
-
if (nudged === "top") {
|
|
2512
|
-
document.body.style.paddingTop = "";
|
|
2513
|
-
delete document.body.dataset.mushiBannerNudged;
|
|
2514
|
-
} else if (nudged === "bottom") {
|
|
2515
|
-
document.body.style.paddingBottom = "";
|
|
2516
|
-
delete document.body.dataset.mushiBannerNudged;
|
|
2517
|
-
}
|
|
2962
|
+
setTrigger(trigger) {
|
|
2963
|
+
this.updateConfig({ trigger });
|
|
2518
2964
|
}
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
this.removeBodyNudge();
|
|
2527
|
-
return;
|
|
2528
|
-
}
|
|
2529
|
-
if (this.isRouteHidden()) {
|
|
2530
|
-
this.removeBodyNudge();
|
|
2531
|
-
return;
|
|
2532
|
-
}
|
|
2533
|
-
if (this.isSuppressedByHost()) {
|
|
2534
|
-
this.removeBodyNudge();
|
|
2535
|
-
return;
|
|
2536
|
-
}
|
|
2537
|
-
const bc = this.config.bannerConfig ?? {};
|
|
2538
|
-
const variant = bc.variant ?? "brand";
|
|
2539
|
-
const position = bc.position ?? "top";
|
|
2540
|
-
const message = bc.message?.trim() ?? "";
|
|
2541
|
-
const richLayout = message.length > 0;
|
|
2542
|
-
const bugLabel = bc.bugCta ?? "\u{1F41B} Report a bug";
|
|
2543
|
-
const showFeat = bc.featureCta !== false;
|
|
2544
|
-
const featLabel = bc.featureCtaLabel ?? "\u2728 Request feature";
|
|
2545
|
-
const zIdx = bc.zIndex ?? (this.config.zIndex ?? 99999) - 1;
|
|
2546
|
-
const banner = document.createElement("div");
|
|
2547
|
-
banner.className = `mushi-banner ${variant} ${position}${richLayout ? " mushi-banner--rich" : ""}`;
|
|
2548
|
-
banner.style.setProperty("--mushi-banner-z", String(zIdx));
|
|
2549
|
-
banner.setAttribute("role", "banner");
|
|
2550
|
-
const dismissBtn = document.createElement("button");
|
|
2551
|
-
dismissBtn.className = "mushi-banner-dismiss";
|
|
2552
|
-
dismissBtn.textContent = "\u2715";
|
|
2553
|
-
dismissBtn.setAttribute("aria-label", "Dismiss feedback banner");
|
|
2554
|
-
dismissBtn.addEventListener("click", () => {
|
|
2555
|
-
this.bannerDismissed = true;
|
|
2556
|
-
this.removeBodyNudge();
|
|
2557
|
-
this.render();
|
|
2558
|
-
});
|
|
2559
|
-
if (richLayout) {
|
|
2560
|
-
const body = document.createElement("div");
|
|
2561
|
-
body.className = "mushi-banner-body";
|
|
2562
|
-
const labelText = bc.label === false ? null : bc.label ?? "Beta";
|
|
2563
|
-
if (labelText) {
|
|
2564
|
-
const pill = document.createElement("span");
|
|
2565
|
-
pill.className = "mushi-banner-pill";
|
|
2566
|
-
pill.textContent = labelText;
|
|
2567
|
-
body.appendChild(pill);
|
|
2568
|
-
}
|
|
2569
|
-
const msg = document.createElement("span");
|
|
2570
|
-
msg.className = "mushi-banner-message";
|
|
2571
|
-
msg.textContent = message;
|
|
2572
|
-
body.appendChild(msg);
|
|
2573
|
-
banner.appendChild(body);
|
|
2574
|
-
const nav = document.createElement("nav");
|
|
2575
|
-
nav.className = "mushi-banner-actions";
|
|
2576
|
-
nav.setAttribute("aria-label", "Feedback banner actions");
|
|
2577
|
-
const appendDivider = (extra = false) => {
|
|
2578
|
-
const sep = document.createElement("span");
|
|
2579
|
-
sep.className = `mushi-banner-divider${extra ? " mushi-banner-extra" : ""}`;
|
|
2580
|
-
sep.setAttribute("aria-hidden", "true");
|
|
2581
|
-
sep.textContent = "|";
|
|
2582
|
-
nav.appendChild(sep);
|
|
2583
|
-
};
|
|
2584
|
-
const appendAction = (label, onClick, extra = false) => {
|
|
2585
|
-
const btn = document.createElement("button");
|
|
2586
|
-
btn.type = "button";
|
|
2587
|
-
btn.className = `mushi-banner-link${extra ? " mushi-banner-extra" : ""}`;
|
|
2588
|
-
btn.textContent = label;
|
|
2589
|
-
btn.addEventListener("click", onClick);
|
|
2590
|
-
nav.appendChild(btn);
|
|
2965
|
+
attachTo(selectorOrElement, options = {}) {
|
|
2966
|
+
const elements = typeof selectorOrElement === "string" ? Array.from(document.querySelectorAll(selectorOrElement)) : [selectorOrElement];
|
|
2967
|
+
const cleanups = elements.map((el) => {
|
|
2968
|
+
const onClick = (event) => {
|
|
2969
|
+
event.preventDefault();
|
|
2970
|
+
this.updateConfig(options);
|
|
2971
|
+
this.open();
|
|
2591
2972
|
};
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2973
|
+
el.addEventListener("click", onClick);
|
|
2974
|
+
return () => el.removeEventListener("click", onClick);
|
|
2975
|
+
});
|
|
2976
|
+
return () => cleanups.forEach((cleanup) => cleanup());
|
|
2977
|
+
}
|
|
2978
|
+
setScreenshotAttached(attached) {
|
|
2979
|
+
this.screenshotAttached = attached;
|
|
2980
|
+
if (this.isOpen) this.render();
|
|
2981
|
+
}
|
|
2982
|
+
setAllowScreenshotRemove(allow) {
|
|
2983
|
+
this.allowScreenshotRemove = allow;
|
|
2984
|
+
if (this.isOpen) this.render();
|
|
2985
|
+
}
|
|
2986
|
+
setElementSelected(selected) {
|
|
2987
|
+
this.elementSelected = selected;
|
|
2988
|
+
this.elementCapturing = false;
|
|
2989
|
+
this.removeSelectorHint();
|
|
2990
|
+
if (this.isOpen) this.render();
|
|
2991
|
+
}
|
|
2992
|
+
setScreenshotCapturing(capturing) {
|
|
2993
|
+
this.screenshotCapturing = capturing;
|
|
2994
|
+
this.screenshotError = false;
|
|
2995
|
+
if (this.isOpen) this.render();
|
|
2996
|
+
}
|
|
2997
|
+
setScreenshotError(failed) {
|
|
2998
|
+
this.screenshotError = failed;
|
|
2999
|
+
this.screenshotCapturing = false;
|
|
3000
|
+
if (this.isOpen) this.render();
|
|
3001
|
+
}
|
|
3002
|
+
setElementCapturing(capturing) {
|
|
3003
|
+
this.elementCapturing = capturing;
|
|
3004
|
+
if (capturing) {
|
|
3005
|
+
this.showSelectorHint();
|
|
2619
3006
|
} else {
|
|
2620
|
-
|
|
2621
|
-
bugBtn.className = "mushi-banner-btn";
|
|
2622
|
-
bugBtn.textContent = bugLabel;
|
|
2623
|
-
bugBtn.addEventListener("click", () => this.open());
|
|
2624
|
-
banner.appendChild(bugBtn);
|
|
2625
|
-
if (showFeat) {
|
|
2626
|
-
const featBtn = document.createElement("button");
|
|
2627
|
-
featBtn.className = "mushi-banner-btn";
|
|
2628
|
-
featBtn.textContent = featLabel;
|
|
2629
|
-
featBtn.addEventListener("click", () => this.open({ featureRequest: true }));
|
|
2630
|
-
banner.appendChild(featBtn);
|
|
2631
|
-
}
|
|
2632
|
-
banner.appendChild(dismissBtn);
|
|
3007
|
+
this.removeSelectorHint();
|
|
2633
3008
|
}
|
|
2634
|
-
this.
|
|
2635
|
-
this.applyBodyNudge(position);
|
|
3009
|
+
if (this.isOpen) this.render();
|
|
2636
3010
|
}
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
return this.config.trigger;
|
|
3011
|
+
/** Hide the widget panel (but keep the host element) during element selection
|
|
3012
|
+
* so the user can click any element on the page without the panel
|
|
3013
|
+
* intercepting the event. */
|
|
3014
|
+
hidePanel() {
|
|
3015
|
+
const panel = this.shadow.querySelector(".mushi-panel");
|
|
3016
|
+
if (panel) panel.style.display = "none";
|
|
2644
3017
|
}
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
return window.matchMedia("(max-width: 768px)").matches && smart.onMobile === "hide";
|
|
3018
|
+
showPanel() {
|
|
3019
|
+
const panel = this.shadow.querySelector(".mushi-panel");
|
|
3020
|
+
if (panel) panel.style.display = "";
|
|
2649
3021
|
}
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
3022
|
+
showSelectorHint() {
|
|
3023
|
+
this.removeSelectorHint();
|
|
3024
|
+
const hint = document.createElement("div");
|
|
3025
|
+
hint.id = "mushi-selector-hint";
|
|
3026
|
+
hint.setAttribute("role", "status");
|
|
3027
|
+
hint.setAttribute("aria-live", "polite");
|
|
3028
|
+
hint.style.cssText = `
|
|
3029
|
+
position: fixed;
|
|
3030
|
+
bottom: 24px;
|
|
3031
|
+
left: 50%;
|
|
3032
|
+
transform: translateX(-50%);
|
|
3033
|
+
z-index: 2147483646;
|
|
3034
|
+
background: rgba(17,17,17,0.92);
|
|
3035
|
+
color: #fff;
|
|
3036
|
+
font-family: ui-monospace, SFMono-Regular, monospace;
|
|
3037
|
+
font-size: 12px;
|
|
3038
|
+
letter-spacing: 0.04em;
|
|
3039
|
+
padding: 8px 16px;
|
|
3040
|
+
border-radius: 20px;
|
|
3041
|
+
pointer-events: none;
|
|
3042
|
+
white-space: nowrap;
|
|
3043
|
+
backdrop-filter: blur(4px);
|
|
3044
|
+
box-shadow: 0 2px 12px rgba(0,0,0,0.35);
|
|
3045
|
+
`;
|
|
3046
|
+
hint.textContent = this.locale.step3.elementSelectorHint;
|
|
3047
|
+
document.body.appendChild(hint);
|
|
3048
|
+
this.selectorHint = hint;
|
|
2655
3049
|
}
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
3050
|
+
removeSelectorHint() {
|
|
3051
|
+
this.selectorHint?.remove();
|
|
3052
|
+
this.selectorHint = null;
|
|
3053
|
+
document.getElementById("mushi-selector-hint")?.remove();
|
|
2659
3054
|
}
|
|
2660
|
-
|
|
2661
|
-
if (this.
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
3055
|
+
showNudge() {
|
|
3056
|
+
if (this.nudgeShown || this.nudgeEl) return;
|
|
3057
|
+
this.nudgeShown = true;
|
|
3058
|
+
const trigger = this.shadow.querySelector(".mushi-trigger");
|
|
3059
|
+
const rect = trigger?.getBoundingClientRect();
|
|
3060
|
+
const nudge = document.createElement("div");
|
|
3061
|
+
nudge.id = "mushi-nudge-bubble";
|
|
3062
|
+
nudge.setAttribute("role", "tooltip");
|
|
3063
|
+
const isRight = this.config.position.includes("right");
|
|
3064
|
+
nudge.style.cssText = `
|
|
3065
|
+
position: fixed;
|
|
3066
|
+
z-index: 2147483645;
|
|
3067
|
+
${rect ? `bottom: ${window.innerHeight - rect.top + 8}px; ${isRight ? `right: ${window.innerWidth - rect.right}px;` : `left: ${rect.left}px;`}` : "bottom: 80px; right: 24px;"}
|
|
3068
|
+
background: rgba(17,17,17,0.92);
|
|
3069
|
+
color: #fff;
|
|
3070
|
+
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
3071
|
+
font-size: 12px;
|
|
3072
|
+
line-height: 1.4;
|
|
3073
|
+
padding: 8px 12px;
|
|
3074
|
+
border-radius: 8px;
|
|
3075
|
+
max-width: 200px;
|
|
3076
|
+
pointer-events: none;
|
|
3077
|
+
backdrop-filter: blur(4px);
|
|
3078
|
+
box-shadow: 0 2px 12px rgba(0,0,0,0.35);
|
|
3079
|
+
animation: mushi-fade-in 0.15s ease forwards;
|
|
3080
|
+
`;
|
|
3081
|
+
nudge.textContent = this.locale.step3.tooShort.startsWith("A bit") ? "Found a bug? One sentence is enough \u{1F41B}" : "\u30D0\u30B0\u3092\u898B\u3064\u3051\u305F\uFF1F\u4E00\u884C\u3067\u5927\u4E08\u592B\u3067\u3059 \u{1F41B}";
|
|
3082
|
+
document.body.appendChild(nudge);
|
|
3083
|
+
this.nudgeEl = nudge;
|
|
3084
|
+
if (this.nudgeTimer !== null) clearTimeout(this.nudgeTimer);
|
|
3085
|
+
this.nudgeTimer = setTimeout(() => this.removeNudge(), 5e3);
|
|
2666
3086
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
this.shadow.innerHTML = "";
|
|
2672
|
-
const style = document.createElement("style");
|
|
2673
|
-
style.textContent = getWidgetStyles(theme);
|
|
2674
|
-
this.shadow.appendChild(style);
|
|
2675
|
-
this.renderBanner();
|
|
2676
|
-
if (this.shouldRenderTrigger()) {
|
|
2677
|
-
const effectiveTrigger = this.effectiveTrigger();
|
|
2678
|
-
const trigger = document.createElement("button");
|
|
2679
|
-
trigger.className = `mushi-trigger ${pos}${effectiveTrigger === "edge-tab" ? " edge-tab" : ""}${this.triggerShrunk ? " shrunk" : ""}`;
|
|
2680
|
-
trigger.textContent = this.config.triggerText;
|
|
2681
|
-
trigger.setAttribute("aria-label", t.widget.trigger);
|
|
2682
|
-
trigger.setAttribute("aria-haspopup", "dialog");
|
|
2683
|
-
trigger.setAttribute("aria-expanded", String(this.isOpen));
|
|
2684
|
-
trigger.style.zIndex = String(this.config.zIndex);
|
|
2685
|
-
this.applyInsetVars(trigger);
|
|
2686
|
-
trigger.addEventListener("click", () => {
|
|
2687
|
-
this.removeNudge();
|
|
2688
|
-
if (this.isOpen) this.close();
|
|
2689
|
-
else this.open();
|
|
2690
|
-
});
|
|
2691
|
-
trigger.addEventListener("mouseenter", () => {
|
|
2692
|
-
const onPageMs = this.mountedAt ? Date.now() - this.mountedAt : 0;
|
|
2693
|
-
if (!this.nudgeShown && !this.isOpen && onPageMs >= 3e4) {
|
|
2694
|
-
this.showNudge();
|
|
2695
|
-
}
|
|
2696
|
-
});
|
|
2697
|
-
trigger.addEventListener("mouseleave", () => {
|
|
2698
|
-
if (this.nudgeEl) {
|
|
2699
|
-
if (this.nudgeTimer !== null) clearTimeout(this.nudgeTimer);
|
|
2700
|
-
this.nudgeTimer = setTimeout(() => this.removeNudge(), 2e3);
|
|
2701
|
-
}
|
|
2702
|
-
});
|
|
2703
|
-
this.shadow.appendChild(trigger);
|
|
2704
|
-
}
|
|
2705
|
-
const panel = document.createElement("div");
|
|
2706
|
-
panel.className = `mushi-panel ${pos}${this.isOpen ? " open" : " closed"}`;
|
|
2707
|
-
panel.setAttribute("role", "dialog");
|
|
2708
|
-
panel.setAttribute("aria-modal", "true");
|
|
2709
|
-
panel.setAttribute("aria-label", t.widget.title);
|
|
2710
|
-
panel.style.zIndex = String(this.config.zIndex + 1);
|
|
2711
|
-
this.applyInsetVars(panel);
|
|
2712
|
-
if (this.isOpen) {
|
|
2713
|
-
panel.innerHTML = `${this.renderOutdatedBanner()}${this.renderStep()}${this.renderBrandFooter()}`;
|
|
2714
|
-
this.shadow.appendChild(panel);
|
|
2715
|
-
this.attachHandlers(panel);
|
|
2716
|
-
this.trapFocus(panel);
|
|
3087
|
+
removeNudge() {
|
|
3088
|
+
if (this.nudgeTimer !== null) {
|
|
3089
|
+
clearTimeout(this.nudgeTimer);
|
|
3090
|
+
this.nudgeTimer = null;
|
|
2717
3091
|
}
|
|
3092
|
+
this.nudgeEl?.remove();
|
|
3093
|
+
this.nudgeEl = null;
|
|
3094
|
+
document.getElementById("mushi-nudge-bubble")?.remove();
|
|
2718
3095
|
}
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
* of them by `gap` pixels. Returns `null` when no selectors are provided
|
|
2723
|
-
* or no matching elements have a non-zero bounding rect.
|
|
2724
|
-
*
|
|
2725
|
-
* Runs in the host document (not shadow DOM) so it can reach fixed headers,
|
|
2726
|
-
* sticky nav bars, and sign-in CTAs.
|
|
2727
|
-
*/
|
|
2728
|
-
computeAvoidTopPx(gap = 8) {
|
|
2729
|
-
const sels = this.config.avoidSelectors;
|
|
2730
|
-
if (!sels?.length) return null;
|
|
2731
|
-
let maxBottom = 0;
|
|
2732
|
-
for (const sel of sels) {
|
|
2733
|
-
try {
|
|
2734
|
-
const el = document.querySelector(sel);
|
|
2735
|
-
if (!el) continue;
|
|
2736
|
-
const r = el.getBoundingClientRect();
|
|
2737
|
-
if (r.bottom > maxBottom && r.width > 0 && r.height > 0) {
|
|
2738
|
-
maxBottom = r.bottom;
|
|
2739
|
-
}
|
|
2740
|
-
} catch {
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
return maxBottom > 0 ? Math.ceil(maxBottom) + gap : null;
|
|
3096
|
+
setSdkFreshness(info) {
|
|
3097
|
+
this.sdkFreshness = info;
|
|
3098
|
+
if (this.isOpen) this.render();
|
|
2744
3099
|
}
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
if (
|
|
2748
|
-
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
2749
|
-
const value = anchor[edge];
|
|
2750
|
-
if (value !== void 0) el.style.setProperty(`--mushi-${edge}`, value);
|
|
2751
|
-
});
|
|
2752
|
-
el.style.setProperty("--mushi-safe-area", this.config.respectSafeArea ? "1" : "0");
|
|
2753
|
-
} else {
|
|
2754
|
-
const { inset } = this.config;
|
|
2755
|
-
if (!this.config.respectSafeArea) {
|
|
2756
|
-
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
2757
|
-
if (inset[edge] === void 0) el.style.setProperty(`--mushi-${edge}`, "24px");
|
|
2758
|
-
});
|
|
2759
|
-
}
|
|
2760
|
-
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
2761
|
-
const value = inset[edge];
|
|
2762
|
-
if (value === void 0) return;
|
|
2763
|
-
el.style.setProperty(`--mushi-${edge}`, value === "auto" ? "auto" : `${value}px`);
|
|
2764
|
-
});
|
|
2765
|
-
el.style.setProperty("--mushi-safe-area", this.config.respectSafeArea ? "1" : "0");
|
|
2766
|
-
}
|
|
2767
|
-
const isTopAnchored = anchor?.top !== void 0 || this.config.position?.startsWith("top") || !this.config.position && !anchor?.bottom;
|
|
2768
|
-
if (isTopAnchored) {
|
|
2769
|
-
const avoidPx = this.computeAvoidTopPx();
|
|
2770
|
-
if (avoidPx !== null) {
|
|
2771
|
-
el.style.setProperty("--mushi-top", `${avoidPx}px`);
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
3100
|
+
setRewardsState(state) {
|
|
3101
|
+
this.rewardsState = state;
|
|
3102
|
+
if (this.isOpen) this.render();
|
|
2774
3103
|
}
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
case "reports":
|
|
2786
|
-
return this.renderReportsStep();
|
|
2787
|
-
case "report-detail":
|
|
2788
|
-
return this.renderReportDetailStep();
|
|
2789
|
-
case "leaderboard":
|
|
2790
|
-
return this.renderLeaderboardStep();
|
|
2791
|
-
case "roadmap":
|
|
2792
|
-
return this.renderRoadmapStep();
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
renderOutdatedBanner() {
|
|
2796
|
-
if (!this.sdkFreshness) return "";
|
|
2797
|
-
if (this.config.outdatedBanner === "off" || this.config.outdatedBanner === "console-only") return "";
|
|
2798
|
-
const { latest, current, deprecated, message } = this.sdkFreshness;
|
|
2799
|
-
if (!latest && !deprecated) return "";
|
|
2800
|
-
return `
|
|
2801
|
-
<div class="mushi-outdated" role="status">
|
|
2802
|
-
<strong>Mushi SDK ${escapeHtml(current)}</strong>
|
|
2803
|
-
${latest ? `latest is ${escapeHtml(latest)}.` : "needs attention."}
|
|
2804
|
-
${message ? `<span>${escapeHtml(message)}</span>` : ""}
|
|
2805
|
-
</div>
|
|
2806
|
-
`;
|
|
3104
|
+
setLeaderboard(entries, loading = false) {
|
|
3105
|
+
this.leaderboardEntries = entries;
|
|
3106
|
+
this.leaderboardLoading = loading;
|
|
3107
|
+
if (this.isOpen && this.step === "leaderboard") this.render();
|
|
3108
|
+
}
|
|
3109
|
+
// ── Community public setters (called by mushi.ts after API calls) ──────────
|
|
3110
|
+
setTesterSession(jwt, info) {
|
|
3111
|
+
this.testerJwt = jwt;
|
|
3112
|
+
this.testerInfo = info;
|
|
3113
|
+
if (this.isOpen) this.render();
|
|
2807
3114
|
}
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
3115
|
+
setGlobalLeaderboard(entries, loading = false) {
|
|
3116
|
+
this.globalLeaderboard = entries;
|
|
3117
|
+
this.globalLeaderboardLoading = loading;
|
|
3118
|
+
if (this.isOpen && (this.step === "leaderboard" || this.step === "account")) this.render();
|
|
3119
|
+
}
|
|
3120
|
+
setCrossAppReports(reports, loading = false) {
|
|
3121
|
+
this.crossAppReports = reports;
|
|
3122
|
+
this.crossAppLoading = loading;
|
|
3123
|
+
if (this.isOpen && this.step === "cross-app-reports") this.render();
|
|
3124
|
+
}
|
|
3125
|
+
setTesterReputation(rep) {
|
|
3126
|
+
this.testerReputation = rep;
|
|
3127
|
+
if (this.isOpen && (this.step === "account" || this.step === "leaderboard")) this.render();
|
|
3128
|
+
}
|
|
3129
|
+
destroy() {
|
|
3130
|
+
if (this.successTimer !== null) {
|
|
3131
|
+
clearTimeout(this.successTimer);
|
|
3132
|
+
this.successTimer = null;
|
|
3133
|
+
}
|
|
3134
|
+
if (this.autoCloseTimer !== null) {
|
|
3135
|
+
clearTimeout(this.autoCloseTimer);
|
|
3136
|
+
this.autoCloseTimer = null;
|
|
3137
|
+
}
|
|
3138
|
+
if (this.smartHideTimer !== null) {
|
|
3139
|
+
clearTimeout(this.smartHideTimer);
|
|
3140
|
+
this.smartHideTimer = null;
|
|
3141
|
+
}
|
|
3142
|
+
this.smartHideCleanup?.();
|
|
3143
|
+
this.smartHideCleanup = null;
|
|
3144
|
+
this.teardownViewportHandlers();
|
|
3145
|
+
this.attachedLaunchers.forEach((cleanup) => cleanup());
|
|
3146
|
+
this.attachedLaunchers = [];
|
|
3147
|
+
this.removeSelectorHint();
|
|
3148
|
+
this.removeNudge();
|
|
3149
|
+
this.removeBodyNudge();
|
|
3150
|
+
this.host.remove();
|
|
2811
3151
|
}
|
|
3152
|
+
/* ── Host chrome contract ────────────────────────────────────────────────
|
|
3153
|
+
The host element must never create an invisible full-screen touch blocker.
|
|
3154
|
+
We own these inline styles — consumer CSS can only win with `!important`,
|
|
3155
|
+
which is explicitly banned by the SDK contract. Calling this at mount()
|
|
3156
|
+
and after every zIndex update is the only safe invariant. */
|
|
2812
3157
|
/**
|
|
2813
|
-
*
|
|
2814
|
-
*
|
|
2815
|
-
*
|
|
2816
|
-
*
|
|
2817
|
-
*
|
|
2818
|
-
* On sub-steps it additionally renders a back button (replacing the
|
|
2819
|
-
* "MUSHI" eyebrow with a "← BACK" mono link) and a step counter
|
|
2820
|
-
* ledger ("02 / 03") on the far right.
|
|
3158
|
+
* Apply the SDK-owned pass-through layout to the host element so it is
|
|
3159
|
+
* always zero-sized and click/touch-transparent. Only the shadow-root
|
|
3160
|
+
* internals (`.mushi-trigger`, `.mushi-banner`, `.mushi-panel`) opt back
|
|
3161
|
+
* into pointer events. This is idempotent and safe to call repeatedly.
|
|
2821
3162
|
*/
|
|
2822
|
-
|
|
2823
|
-
const
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
<button type="button" class="mushi-close" data-action="close" aria-label="${t.widget.close}">\u2715</button>
|
|
2837
|
-
</div>
|
|
2838
|
-
</div>
|
|
2839
|
-
`;
|
|
3163
|
+
syncHostChromeState() {
|
|
3164
|
+
const s = this.host.style;
|
|
3165
|
+
s.setProperty("position", "fixed");
|
|
3166
|
+
s.setProperty("top", "0");
|
|
3167
|
+
s.setProperty("left", "0");
|
|
3168
|
+
s.setProperty("width", "0");
|
|
3169
|
+
s.setProperty("height", "0");
|
|
3170
|
+
s.setProperty("overflow", "visible");
|
|
3171
|
+
s.setProperty("pointer-events", "none");
|
|
3172
|
+
s.setProperty("z-index", String(this.config.zIndex));
|
|
3173
|
+
s.setProperty("margin", "0");
|
|
3174
|
+
s.setProperty("padding", "0");
|
|
3175
|
+
s.setProperty("border", "none");
|
|
3176
|
+
s.setProperty("background", "none");
|
|
2840
3177
|
}
|
|
2841
3178
|
/**
|
|
2842
|
-
*
|
|
2843
|
-
*
|
|
2844
|
-
*
|
|
3179
|
+
* Returns true when a DOM element matching `hideOnSelector` is currently
|
|
3180
|
+
* present in the host document. Used by both the trigger and the banner
|
|
3181
|
+
* so a single selector consistently hides ALL SDK-injected launcher
|
|
3182
|
+
* surfaces. Invalid selectors are swallowed silently (non-fatal).
|
|
2845
3183
|
*/
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
3184
|
+
isSuppressedByHost() {
|
|
3185
|
+
if (!this.config.hideOnSelector || typeof document === "undefined") return false;
|
|
3186
|
+
try {
|
|
3187
|
+
return Boolean(document.querySelector(this.config.hideOnSelector));
|
|
3188
|
+
} catch {
|
|
3189
|
+
return false;
|
|
2852
3190
|
}
|
|
2853
|
-
return `<div class="mushi-step-indicator" aria-hidden="true">${segments.join("")}</div>`;
|
|
2854
|
-
}
|
|
2855
|
-
renderCategoryStep() {
|
|
2856
|
-
const t = this.locale;
|
|
2857
|
-
const categoryEntries = this.config.categories && this.config.categories.length > 0 ? this.config.categories.map((c) => ({
|
|
2858
|
-
id: c.id,
|
|
2859
|
-
icon: c.icon ?? "\u{1F4AC}",
|
|
2860
|
-
label: c.label,
|
|
2861
|
-
desc: c.description ?? ""
|
|
2862
|
-
})) : ["bug", "slow", "visual", "confusing", "other"].map((id) => ({
|
|
2863
|
-
id,
|
|
2864
|
-
icon: CATEGORY_ICONS[id],
|
|
2865
|
-
label: t.step1.categories[id],
|
|
2866
|
-
desc: t.step1.categoryDescriptions[id]
|
|
2867
|
-
}));
|
|
2868
|
-
const categories = categoryEntries.map(({ id, icon, label, desc }) => `
|
|
2869
|
-
<button type="button" class="mushi-option-btn" data-category="${escapeHtml(id)}" role="radio" aria-checked="false">
|
|
2870
|
-
<span class="mushi-option-icon" aria-hidden="true">${escapeHtml(icon)}</span>
|
|
2871
|
-
<div class="mushi-option-text">
|
|
2872
|
-
<span class="mushi-option-label">${escapeHtml(label)}</span>
|
|
2873
|
-
${desc ? `<span class="mushi-option-desc">${escapeHtml(desc)}</span>` : ""}
|
|
2874
|
-
</div>
|
|
2875
|
-
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2876
|
-
</button>
|
|
2877
|
-
`).join("");
|
|
2878
|
-
return `
|
|
2879
|
-
${this.renderHeader({ title: t.step1.heading, step: STEP_NUMBER.category })}
|
|
2880
|
-
${this.config.betaMode?.enabled ? this.renderBetaStrip() : ""}
|
|
2881
|
-
<div class="mushi-body" role="radiogroup" aria-label="${t.step1.heading}">
|
|
2882
|
-
<button type="button" class="mushi-option-btn mushi-reports-entry" data-action="reports">
|
|
2883
|
-
<span class="mushi-option-icon" aria-hidden="true">\u{1F4EC}</span>
|
|
2884
|
-
<div class="mushi-option-text">
|
|
2885
|
-
<span class="mushi-option-label">Your reports${this.unreadCount() ? ` (${this.unreadCount()} new)` : ""}</span>
|
|
2886
|
-
<span class="mushi-option-desc">See status, developer replies, and respond</span>
|
|
2887
|
-
</div>
|
|
2888
|
-
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2889
|
-
</button>
|
|
2890
|
-
${this.renderFeatureRequestEntry()}
|
|
2891
|
-
${this.callbacks.onFeatureBoardRequest ? `
|
|
2892
|
-
<button type="button" class="mushi-option-btn" data-action="roadmap">
|
|
2893
|
-
<span class="mushi-option-icon" aria-hidden="true">\u{1F5F3}\uFE0F</span>
|
|
2894
|
-
<div class="mushi-option-text">
|
|
2895
|
-
<span class="mushi-option-label">Community ideas</span>
|
|
2896
|
-
<span class="mushi-option-desc">Vote on features and see what shipped</span>
|
|
2897
|
-
</div>
|
|
2898
|
-
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2899
|
-
</button>` : ""}
|
|
2900
|
-
${categories}
|
|
2901
|
-
${this.rewardsState ? this.renderRewardsNudge() : ""}
|
|
2902
|
-
</div>
|
|
2903
|
-
${this.renderStepIndicator(STEP_NUMBER.category)}
|
|
2904
|
-
`;
|
|
2905
3191
|
}
|
|
2906
3192
|
/**
|
|
2907
|
-
*
|
|
2908
|
-
*
|
|
2909
|
-
*
|
|
2910
|
-
* it as an intent under the "Other" category drops feature submissions
|
|
2911
|
-
* by ~40% in industry studies (Userpilot, Usersnap 2025).
|
|
2912
|
-
*
|
|
2913
|
-
* Wire format: still routes through the standard `other` category with
|
|
2914
|
-
* a `user_category = 'Feature request'` stamp, so we don't need a DB
|
|
2915
|
-
* migration. The admin console filters on that string to surface the
|
|
2916
|
-
* Feature-request swimlane.
|
|
3193
|
+
* Returns a snapshot of the widget's host-layer health for use in
|
|
3194
|
+
* `Mushi.diagnose()`. Callers check this to know whether the widget
|
|
3195
|
+
* could ever block host-app UI without opening a browser devtools.
|
|
2917
3196
|
*/
|
|
2918
|
-
|
|
2919
|
-
const
|
|
2920
|
-
|
|
2921
|
-
const
|
|
2922
|
-
const
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
type="button"
|
|
2926
|
-
class="mushi-option-btn mushi-feature-entry"
|
|
2927
|
-
data-action="feature-request"
|
|
2928
|
-
aria-label="${escapeHtml(label)}"
|
|
2929
|
-
>
|
|
2930
|
-
<span class="mushi-option-icon" aria-hidden="true">\u2728</span>
|
|
2931
|
-
<div class="mushi-option-text">
|
|
2932
|
-
<span class="mushi-option-label">${escapeHtml(label)}</span>
|
|
2933
|
-
<span class="mushi-option-desc">${escapeHtml(desc)}</span>
|
|
2934
|
-
</div>
|
|
2935
|
-
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2936
|
-
</button>
|
|
2937
|
-
`;
|
|
3197
|
+
getWidgetDiagnostics() {
|
|
3198
|
+
const s = this.host.style;
|
|
3199
|
+
const widgetHostPointerSafe = s.pointerEvents === "none" && (s.width === "0" || s.width === "0px") && (s.height === "0" || s.height === "0px");
|
|
3200
|
+
const widgetHostBounds = this.host.isConnected ? { width: this.host.offsetWidth, height: this.host.offsetHeight } : null;
|
|
3201
|
+
const widgetSuppressed = this.isSuppressedByHost() || this.isRouteHidden() || !this.triggerVisible;
|
|
3202
|
+
const bannerRendered = this.config.trigger === "banner" && !this.bannerDismissed && !this.isSuppressedByHost() && !this.isRouteHidden() && this.triggerVisible;
|
|
3203
|
+
return { widgetHostPointerSafe, widgetHostBounds, widgetSuppressed, bannerRendered };
|
|
2938
3204
|
}
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
if (!
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
const label = latest.date ? `What\u2019s new in ${escapeHtml(latest.version)} \xB7 ${escapeHtml(latest.date)}` : `What\u2019s new in ${escapeHtml(latest.version)}`;
|
|
2946
|
-
return `
|
|
2947
|
-
<details class="mushi-changelog">
|
|
2948
|
-
<summary class="mushi-changelog-summary">${label}</summary>
|
|
2949
|
-
<ul class="mushi-changelog-list">${items}</ul>
|
|
2950
|
-
</details>
|
|
2951
|
-
`;
|
|
3205
|
+
syncAttachedLaunchers() {
|
|
3206
|
+
this.attachedLaunchers.forEach((cleanup) => cleanup());
|
|
3207
|
+
this.attachedLaunchers = [];
|
|
3208
|
+
if (this.config.trigger !== "attach" || !this.config.attachToSelector) return;
|
|
3209
|
+
if (typeof document === "undefined") return;
|
|
3210
|
+
this.attachedLaunchers.push(this.attachTo(this.config.attachToSelector));
|
|
2952
3211
|
}
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
const
|
|
2960
|
-
|
|
2961
|
-
const
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
</div>
|
|
2978
|
-
`;
|
|
3212
|
+
syncSmartHide() {
|
|
3213
|
+
this.smartHideCleanup?.();
|
|
3214
|
+
this.smartHideCleanup = null;
|
|
3215
|
+
this.triggerShrunk = false;
|
|
3216
|
+
this.triggerHiddenByScroll = false;
|
|
3217
|
+
if (!this.config.smartHide || typeof window === "undefined") return;
|
|
3218
|
+
const smart = this.config.smartHide === true ? { onScroll: "shrink", onIdleMs: 900 } : this.config.smartHide;
|
|
3219
|
+
if (!smart.onScroll) return;
|
|
3220
|
+
const onScroll = () => {
|
|
3221
|
+
if (smart.onScroll === "hide") {
|
|
3222
|
+
this.triggerHiddenByScroll = true;
|
|
3223
|
+
} else {
|
|
3224
|
+
this.triggerShrunk = true;
|
|
3225
|
+
}
|
|
3226
|
+
this.render();
|
|
3227
|
+
if (this.smartHideTimer !== null) clearTimeout(this.smartHideTimer);
|
|
3228
|
+
this.smartHideTimer = setTimeout(() => {
|
|
3229
|
+
this.triggerHiddenByScroll = false;
|
|
3230
|
+
this.triggerShrunk = false;
|
|
3231
|
+
this.render();
|
|
3232
|
+
}, smart.onIdleMs ?? 900);
|
|
3233
|
+
};
|
|
3234
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
3235
|
+
this.smartHideCleanup = () => window.removeEventListener("scroll", onScroll);
|
|
2979
3236
|
}
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3237
|
+
shouldRenderTrigger() {
|
|
3238
|
+
if (!this.triggerVisible) return false;
|
|
3239
|
+
if (this.triggerHiddenByScroll) return false;
|
|
3240
|
+
if (this.config.trigger === "manual" || this.config.trigger === "hidden" || this.config.trigger === "attach" || this.config.trigger === "banner") {
|
|
3241
|
+
return false;
|
|
3242
|
+
}
|
|
3243
|
+
if (this.isMobileSmartHidden()) return false;
|
|
3244
|
+
if (this.isRouteHidden()) return false;
|
|
3245
|
+
if (this.isSuppressedByHost()) return false;
|
|
3246
|
+
const action = this.config.environments[this.detectEnvironment()];
|
|
3247
|
+
return action !== "never" && action !== "manual";
|
|
3248
|
+
}
|
|
3249
|
+
/** Height of the banner in px — kept in sync with the CSS `.mushi-banner` height (36px). */
|
|
3250
|
+
static BANNER_HEIGHT = 36;
|
|
3251
|
+
/** CSS property applied to document.body so host-app content doesn't slide under the banner. */
|
|
3252
|
+
static BODY_NUDGE_PROP = "--mushi-banner-offset";
|
|
3253
|
+
applyBodyNudge(position) {
|
|
3254
|
+
const h = `${_MushiWidget.BANNER_HEIGHT}px`;
|
|
3255
|
+
if (position === "top") {
|
|
3256
|
+
document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
|
|
3257
|
+
if (!document.body.style.paddingTop) {
|
|
3258
|
+
document.body.style.paddingTop = h;
|
|
3259
|
+
document.body.dataset.mushiBannerNudged = "top";
|
|
3260
|
+
}
|
|
3261
|
+
} else {
|
|
3262
|
+
document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
|
|
3263
|
+
if (!document.body.style.paddingBottom) {
|
|
3264
|
+
document.body.style.paddingBottom = h;
|
|
3265
|
+
document.body.dataset.mushiBannerNudged = "bottom";
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
removeBodyNudge() {
|
|
3270
|
+
document.documentElement.style.removeProperty(_MushiWidget.BODY_NUDGE_PROP);
|
|
3271
|
+
const nudged = document.body.dataset.mushiBannerNudged;
|
|
3272
|
+
if (nudged === "top") {
|
|
3273
|
+
document.body.style.paddingTop = "";
|
|
3274
|
+
delete document.body.dataset.mushiBannerNudged;
|
|
3275
|
+
} else if (nudged === "bottom") {
|
|
3276
|
+
document.body.style.paddingBottom = "";
|
|
3277
|
+
delete document.body.dataset.mushiBannerNudged;
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
renderBanner() {
|
|
3281
|
+
if (this.config.trigger !== "banner") return;
|
|
3282
|
+
if (this.bannerDismissed) {
|
|
3283
|
+
this.removeBodyNudge();
|
|
3284
|
+
return;
|
|
3285
|
+
}
|
|
3286
|
+
if (!this.triggerVisible) {
|
|
3287
|
+
this.removeBodyNudge();
|
|
3288
|
+
return;
|
|
3289
|
+
}
|
|
3290
|
+
if (this.isRouteHidden()) {
|
|
3291
|
+
this.removeBodyNudge();
|
|
3292
|
+
return;
|
|
3293
|
+
}
|
|
3294
|
+
if (this.isSuppressedByHost()) {
|
|
3295
|
+
this.removeBodyNudge();
|
|
3296
|
+
return;
|
|
3297
|
+
}
|
|
3298
|
+
const bc = this.config.bannerConfig ?? {};
|
|
3299
|
+
const variant = bc.variant ?? "brand";
|
|
3300
|
+
const position = bc.position ?? "top";
|
|
3301
|
+
const message = bc.message?.trim() ?? "";
|
|
3302
|
+
const richLayout = message.length > 0;
|
|
3303
|
+
const bugLabel = bc.bugCta ?? "\u{1F41B} Report a bug";
|
|
3304
|
+
const showFeat = bc.featureCta !== false;
|
|
3305
|
+
const featLabel = bc.featureCtaLabel ?? "Request feature";
|
|
3306
|
+
const zIdx = bc.zIndex ?? (this.config.zIndex ?? 99999) - 1;
|
|
3307
|
+
const banner = document.createElement("div");
|
|
3308
|
+
banner.className = `mushi-banner ${variant} ${position}${richLayout ? " mushi-banner--rich" : ""}`;
|
|
3309
|
+
banner.style.setProperty("--mushi-banner-z", String(zIdx));
|
|
3310
|
+
banner.setAttribute("role", "banner");
|
|
3311
|
+
const dismissBtn = document.createElement("button");
|
|
3312
|
+
dismissBtn.className = "mushi-banner-dismiss";
|
|
3313
|
+
dismissBtn.textContent = "\u2715";
|
|
3314
|
+
dismissBtn.setAttribute("aria-label", "Dismiss feedback banner");
|
|
3315
|
+
dismissBtn.addEventListener("click", () => {
|
|
3316
|
+
this.bannerDismissed = true;
|
|
3317
|
+
this.removeBodyNudge();
|
|
3318
|
+
this.render();
|
|
3319
|
+
});
|
|
3320
|
+
if (richLayout) {
|
|
3321
|
+
const body = document.createElement("div");
|
|
3322
|
+
body.className = "mushi-banner-body";
|
|
3323
|
+
const labelText = bc.label === false ? null : bc.label ?? "Beta";
|
|
3324
|
+
if (labelText) {
|
|
3325
|
+
const pill = document.createElement("span");
|
|
3326
|
+
pill.className = "mushi-banner-pill";
|
|
3327
|
+
pill.textContent = labelText;
|
|
3328
|
+
body.appendChild(pill);
|
|
3329
|
+
}
|
|
3330
|
+
const msg = document.createElement("span");
|
|
3331
|
+
msg.className = "mushi-banner-message";
|
|
3332
|
+
msg.textContent = message;
|
|
3333
|
+
body.appendChild(msg);
|
|
3334
|
+
banner.appendChild(body);
|
|
3335
|
+
const nav = document.createElement("nav");
|
|
3336
|
+
nav.className = "mushi-banner-actions";
|
|
3337
|
+
nav.setAttribute("aria-label", "Feedback banner actions");
|
|
3338
|
+
const appendDivider = (extra = false) => {
|
|
3339
|
+
const sep = document.createElement("span");
|
|
3340
|
+
sep.className = `mushi-banner-divider${extra ? " mushi-banner-extra" : ""}`;
|
|
3341
|
+
sep.setAttribute("aria-hidden", "true");
|
|
3342
|
+
sep.textContent = "|";
|
|
3343
|
+
nav.appendChild(sep);
|
|
3344
|
+
};
|
|
3345
|
+
const appendAction = (label, onClick, extra = false) => {
|
|
3346
|
+
const btn = document.createElement("button");
|
|
3347
|
+
btn.type = "button";
|
|
3348
|
+
btn.className = `mushi-banner-link${extra ? " mushi-banner-extra" : ""}`;
|
|
3349
|
+
btn.textContent = label;
|
|
3350
|
+
btn.addEventListener("click", onClick);
|
|
3351
|
+
nav.appendChild(btn);
|
|
3352
|
+
};
|
|
3353
|
+
appendAction(bugLabel, () => this.open());
|
|
3354
|
+
if (showFeat) {
|
|
3355
|
+
appendDivider(true);
|
|
3356
|
+
appendAction(featLabel, () => this.open({ featureRequest: true }), true);
|
|
3357
|
+
}
|
|
3358
|
+
for (const link of bc.links ?? []) {
|
|
3359
|
+
const linkLabel = link.label?.trim();
|
|
3360
|
+
if (!linkLabel) continue;
|
|
3361
|
+
const href = link.href && (/^https?:\/\//i.test(link.href) || link.href.startsWith("/")) ? link.href : void 0;
|
|
3362
|
+
appendDivider(true);
|
|
3363
|
+
if (href) {
|
|
3364
|
+
const anchor = document.createElement("a");
|
|
3365
|
+
anchor.className = "mushi-banner-link mushi-banner-extra";
|
|
3366
|
+
anchor.href = href;
|
|
3367
|
+
anchor.textContent = linkLabel;
|
|
3368
|
+
anchor.target = "_blank";
|
|
3369
|
+
anchor.rel = "noopener noreferrer";
|
|
3370
|
+
nav.appendChild(anchor);
|
|
3371
|
+
} else {
|
|
3372
|
+
appendAction(linkLabel, () => {
|
|
3373
|
+
if (link.featureRequest) this.open({ featureRequest: true });
|
|
3374
|
+
else this.open();
|
|
3375
|
+
}, true);
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
banner.appendChild(nav);
|
|
3379
|
+
banner.appendChild(dismissBtn);
|
|
3380
|
+
} else {
|
|
3381
|
+
const bugBtn = document.createElement("button");
|
|
3382
|
+
bugBtn.className = "mushi-banner-btn";
|
|
3383
|
+
bugBtn.textContent = bugLabel;
|
|
3384
|
+
bugBtn.addEventListener("click", () => this.open());
|
|
3385
|
+
banner.appendChild(bugBtn);
|
|
3386
|
+
if (showFeat) {
|
|
3387
|
+
const featBtn = document.createElement("button");
|
|
3388
|
+
featBtn.className = "mushi-banner-btn";
|
|
3389
|
+
featBtn.textContent = featLabel;
|
|
3390
|
+
featBtn.addEventListener("click", () => this.open({ featureRequest: true }));
|
|
3391
|
+
banner.appendChild(featBtn);
|
|
3392
|
+
}
|
|
3393
|
+
banner.appendChild(dismissBtn);
|
|
3394
|
+
}
|
|
3395
|
+
this.shadow.appendChild(banner);
|
|
3396
|
+
this.applyBodyNudge(position);
|
|
3009
3397
|
}
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
const status = shipped ? "Shipped" : String(ticket.status_label ?? ticket.status ?? "open");
|
|
3018
|
-
return `
|
|
3019
|
-
<div class="mushi-report-row mushi-roadmap-row">
|
|
3020
|
-
<div class="mushi-report-main">
|
|
3021
|
-
<span class="mushi-report-title">${subject}</span>
|
|
3022
|
-
<span class="mushi-report-meta">
|
|
3023
|
-
<span class="mushi-report-status">${escapeHtml(status)}</span>
|
|
3024
|
-
<span class="mushi-report-when">${votes} vote${votes === 1 ? "" : "s"}</span>
|
|
3025
|
-
</span>
|
|
3026
|
-
</div>
|
|
3027
|
-
${this.callbacks.onFeatureBoardVote ? `
|
|
3028
|
-
<button type="button" class="mushi-vote-btn" data-vote-id="${escapeHtml(id)}" aria-pressed="${voted}">
|
|
3029
|
-
${voted ? "Voted" : "Vote"}
|
|
3030
|
-
</button>` : ""}
|
|
3031
|
-
</div>`;
|
|
3032
|
-
}).join("");
|
|
3033
|
-
return `
|
|
3034
|
-
${this.renderHeader({ title: "Community ideas", showBack: true, eyebrow: "Mushi \xB7 Roadmap" })}
|
|
3035
|
-
<div class="mushi-body">
|
|
3036
|
-
${this.reporterLoading ? '<p class="mushi-muted">Loading ideas\u2026</p>' : ""}
|
|
3037
|
-
${this.reporterError ? `<p class="mushi-error-inline">${escapeHtml(this.reporterError)}</p>` : ""}
|
|
3038
|
-
${rows || (!this.reporterLoading ? '<p class="mushi-muted">No community ideas yet. Be the first to suggest one.</p>' : "")}
|
|
3039
|
-
</div>
|
|
3040
|
-
`;
|
|
3398
|
+
effectiveTrigger() {
|
|
3399
|
+
if (!this.config.smartHide || typeof window === "undefined") return this.config.trigger;
|
|
3400
|
+
const smart = this.config.smartHide === true ? { onMobile: "edge-tab" } : this.config.smartHide;
|
|
3401
|
+
if (window.matchMedia("(max-width: 768px)").matches && smart.onMobile === "edge-tab") {
|
|
3402
|
+
return "edge-tab";
|
|
3403
|
+
}
|
|
3404
|
+
return this.config.trigger;
|
|
3041
3405
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
const
|
|
3045
|
-
|
|
3046
|
-
<span class="mushi-lb-rank">#${i + 1}</span>
|
|
3047
|
-
<span class="mushi-lb-name">${escapeHtml(e.display_name)}</span>
|
|
3048
|
-
${e.tier_name ? `<span class="mushi-lb-tier">${escapeHtml(e.tier_name)}</span>` : ""}
|
|
3049
|
-
<span class="mushi-lb-pts">${e.total_points.toLocaleString()} pts</span>
|
|
3050
|
-
</div>
|
|
3051
|
-
`).join("");
|
|
3052
|
-
return `
|
|
3053
|
-
${this.renderHeader({ title: "\u{1F3C6} Leaderboard", showBack: true, eyebrow: "Mushi \xB7 Contributors" })}
|
|
3054
|
-
<div class="mushi-body">
|
|
3055
|
-
${this.leaderboardLoading ? '<p class="mushi-muted">Loading leaderboard\u2026</p>' : ""}
|
|
3056
|
-
${!this.leaderboardLoading && !this.leaderboardEntries?.length ? '<p class="mushi-muted">No contributors yet \u2014 be the first!</p>' : ""}
|
|
3057
|
-
<div class="mushi-lb-list">${rows}</div>
|
|
3058
|
-
${myRank > 0 ? `<p class="mushi-lb-myrank">You are ranked #${myRank}</p>` : ""}
|
|
3059
|
-
<p class="mushi-lb-note">Top contributors this month \xB7 Points refresh monthly</p>
|
|
3060
|
-
</div>
|
|
3061
|
-
`;
|
|
3406
|
+
isMobileSmartHidden() {
|
|
3407
|
+
if (!this.config.smartHide || typeof window === "undefined") return false;
|
|
3408
|
+
const smart = this.config.smartHide === true ? { onMobile: "edge-tab" } : this.config.smartHide;
|
|
3409
|
+
return window.matchMedia("(max-width: 768px)").matches && smart.onMobile === "hide";
|
|
3062
3410
|
}
|
|
3063
|
-
|
|
3064
|
-
const
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
const comments = this.reporterComments.map((comment) => `
|
|
3069
|
-
<div class="mushi-thread-comment ${comment.author_kind}">
|
|
3070
|
-
<strong>${escapeHtml(comment.author_kind === "reporter" ? "You" : comment.author_name ?? "Developer")}</strong>
|
|
3071
|
-
<p>${escapeHtml(comment.body)}</p>
|
|
3072
|
-
</div>
|
|
3073
|
-
`).join("");
|
|
3074
|
-
return `
|
|
3075
|
-
${this.renderHeader({ title: "Report thread", showBack: true, eyebrow: "Mushi \xB7 Inbox" })}
|
|
3076
|
-
<div class="mushi-body">
|
|
3077
|
-
<div class="mushi-thread-summary">
|
|
3078
|
-
<div class="mushi-thread-summary-meta">
|
|
3079
|
-
<span class="mushi-report-status mushi-status-${tone}">${escapeHtml(reporterStatusLabel(status))}</span>
|
|
3080
|
-
${when ? `<span class="mushi-report-when">Reported ${escapeHtml(when)}</span>` : ""}
|
|
3081
|
-
</div>
|
|
3082
|
-
<p>${escapeHtml(report?.summary ?? report?.description ?? "Report details")}</p>
|
|
3083
|
-
</div>
|
|
3084
|
-
<div class="mushi-thread">
|
|
3085
|
-
${this.reporterLoading ? '<p class="mushi-muted">Loading thread\u2026</p>' : comments || '<p class="mushi-muted">No developer replies yet.</p>'}
|
|
3086
|
-
</div>
|
|
3087
|
-
${["fixed", "resolved", "verified"].includes(status) ? `
|
|
3088
|
-
<div class="mushi-verify-actions" role="group" aria-label="Fix verification">
|
|
3089
|
-
<button type="button" class="mushi-intent-btn" data-action="reporter-confirms">Yes, fixed for me</button>
|
|
3090
|
-
<button type="button" class="mushi-intent-btn" data-action="reporter-not-fixed">Not fixed yet</button>
|
|
3091
|
-
</div>
|
|
3092
|
-
` : ""}
|
|
3093
|
-
<textarea class="mushi-textarea" data-role="reporter-reply" rows="3" placeholder="Reply to the developer\u2026"></textarea>
|
|
3094
|
-
<button type="button" class="mushi-submit" data-action="reporter-reply">
|
|
3095
|
-
<span>Reply</span><span class="mushi-submit-arrow" aria-hidden="true">\u2192</span>
|
|
3096
|
-
</button>
|
|
3097
|
-
</div>
|
|
3098
|
-
`;
|
|
3411
|
+
detectEnvironment() {
|
|
3412
|
+
const host = typeof location !== "undefined" ? location.hostname : "";
|
|
3413
|
+
if (host === "localhost" || host === "127.0.0.1" || host.endsWith(".local")) return "development";
|
|
3414
|
+
if (/\b(staging|stage|preview|dev)\b/i.test(host)) return "staging";
|
|
3415
|
+
return "production";
|
|
3099
3416
|
}
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
const customEntry = this.resolveCustomCategory(catId);
|
|
3104
|
-
const intents = customEntry?.intents ?? (t.step2.intents[catId] || []);
|
|
3105
|
-
const options = intents.map((intent) => `
|
|
3106
|
-
<button type="button" class="mushi-intent-btn" data-intent="${escapeHtml(intent)}">
|
|
3107
|
-
${escapeHtml(intent)}
|
|
3108
|
-
</button>
|
|
3109
|
-
`).join("");
|
|
3110
|
-
const icon = this.categoryIcon(catId);
|
|
3111
|
-
const label = this.categoryLabel(catId);
|
|
3112
|
-
return `
|
|
3113
|
-
${this.renderHeader({ title: t.step2.heading, showBack: true, step: STEP_NUMBER.intent })}
|
|
3114
|
-
<div class="mushi-body">
|
|
3115
|
-
<div class="mushi-selected-category">
|
|
3116
|
-
<span aria-hidden="true">${escapeHtml(icon)}</span>
|
|
3117
|
-
<span>${escapeHtml(label)}</span>
|
|
3118
|
-
</div>
|
|
3119
|
-
<div class="mushi-intents">
|
|
3120
|
-
${options}
|
|
3121
|
-
</div>
|
|
3122
|
-
</div>
|
|
3123
|
-
${this.renderStepIndicator(STEP_NUMBER.intent)}
|
|
3124
|
-
`;
|
|
3417
|
+
isRouteHidden() {
|
|
3418
|
+
if (!this.config.hideOnRoutes.length || typeof location === "undefined") return false;
|
|
3419
|
+
return this.config.hideOnRoutes.some((route) => location.pathname.includes(route));
|
|
3125
3420
|
}
|
|
3126
|
-
|
|
3127
|
-
const
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3421
|
+
getTheme() {
|
|
3422
|
+
const t = this.config.theme;
|
|
3423
|
+
if (t === "light" || t === "dark") return t;
|
|
3424
|
+
if (t === "inherit") {
|
|
3425
|
+
const root = document.documentElement;
|
|
3426
|
+
const colorScheme = root.getAttribute("data-color-scheme") || root.getAttribute("data-theme") || root.getAttribute("color-scheme") || "";
|
|
3427
|
+
if (/dark/i.test(colorScheme)) return "dark";
|
|
3428
|
+
if (/light/i.test(colorScheme)) return "light";
|
|
3429
|
+
if (root.classList.contains("dark")) return "dark";
|
|
3430
|
+
if (root.classList.contains("light")) return "light";
|
|
3431
|
+
try {
|
|
3432
|
+
const bg = getComputedStyle(root).backgroundColor;
|
|
3433
|
+
const m = bg.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
3434
|
+
if (m) {
|
|
3435
|
+
const L = 0.299 * +m[1] + 0.587 * +m[2] + 0.114 * +m[3];
|
|
3436
|
+
return L < 128 ? "dark" : "light";
|
|
3437
|
+
}
|
|
3438
|
+
} catch {
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
if (typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
3442
|
+
return "dark";
|
|
3443
|
+
}
|
|
3444
|
+
return "light";
|
|
3131
3445
|
}
|
|
3132
|
-
|
|
3446
|
+
render() {
|
|
3447
|
+
const theme = this.getTheme();
|
|
3448
|
+
const pos = this.config.position;
|
|
3133
3449
|
const t = this.locale;
|
|
3134
|
-
|
|
3135
|
-
const
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
"
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3450
|
+
this.shadow.innerHTML = "";
|
|
3451
|
+
const style = document.createElement("style");
|
|
3452
|
+
style.textContent = getWidgetStyles(theme, this.config.accent ?? "", this.config.accentText ?? "");
|
|
3453
|
+
this.shadow.appendChild(style);
|
|
3454
|
+
this.renderBanner();
|
|
3455
|
+
if (this.shouldRenderTrigger()) {
|
|
3456
|
+
const effectiveTrigger = this.effectiveTrigger();
|
|
3457
|
+
const trigger = document.createElement("button");
|
|
3458
|
+
trigger.className = `mushi-trigger ${pos}${effectiveTrigger === "edge-tab" ? " edge-tab" : ""}${this.triggerShrunk ? " shrunk" : ""}`;
|
|
3459
|
+
trigger.textContent = this.config.triggerText;
|
|
3460
|
+
trigger.setAttribute("aria-label", t.widget.trigger);
|
|
3461
|
+
trigger.setAttribute("aria-haspopup", "dialog");
|
|
3462
|
+
trigger.setAttribute("aria-expanded", String(this.isOpen));
|
|
3463
|
+
trigger.style.zIndex = String(this.config.zIndex);
|
|
3464
|
+
this.applyInsetVars(trigger);
|
|
3465
|
+
trigger.addEventListener("click", () => {
|
|
3466
|
+
this.removeNudge();
|
|
3467
|
+
if (this.isOpen) this.close();
|
|
3468
|
+
else this.open();
|
|
3469
|
+
});
|
|
3470
|
+
trigger.addEventListener("mouseenter", () => {
|
|
3471
|
+
const onPageMs = this.mountedAt ? Date.now() - this.mountedAt : 0;
|
|
3472
|
+
if (!this.nudgeShown && !this.isOpen && onPageMs >= 3e4) {
|
|
3473
|
+
this.showNudge();
|
|
3474
|
+
}
|
|
3475
|
+
});
|
|
3476
|
+
trigger.addEventListener("mouseleave", () => {
|
|
3477
|
+
if (this.nudgeEl) {
|
|
3478
|
+
if (this.nudgeTimer !== null) clearTimeout(this.nudgeTimer);
|
|
3479
|
+
this.nudgeTimer = setTimeout(() => this.removeNudge(), 2e3);
|
|
3480
|
+
}
|
|
3481
|
+
});
|
|
3482
|
+
trigger.addEventListener("keydown", (e) => {
|
|
3483
|
+
const draggableConfig = this.config.draggable;
|
|
3484
|
+
if (!draggableConfig) return;
|
|
3485
|
+
const STEP = 8;
|
|
3486
|
+
const axis = typeof draggableConfig === "object" ? draggableConfig.axis ?? "both" : "both";
|
|
3487
|
+
let dx = 0, dy = 0;
|
|
3488
|
+
if (axis !== "y") {
|
|
3489
|
+
if (e.key === "ArrowLeft") dx = -STEP;
|
|
3490
|
+
else if (e.key === "ArrowRight") dx = STEP;
|
|
3491
|
+
}
|
|
3492
|
+
if (axis !== "x") {
|
|
3493
|
+
if (e.key === "ArrowUp") dy = -STEP;
|
|
3494
|
+
else if (e.key === "ArrowDown") dy = STEP;
|
|
3495
|
+
}
|
|
3496
|
+
if (dx !== 0 || dy !== 0) {
|
|
3497
|
+
e.preventDefault();
|
|
3498
|
+
const cur = this.fabPos ?? { x: 0, y: 0 };
|
|
3499
|
+
this.moveFab(trigger, cur.x + dx, cur.y + dy, false);
|
|
3500
|
+
}
|
|
3501
|
+
});
|
|
3502
|
+
if (this.config.draggable) {
|
|
3503
|
+
this.attachDragHandlers(trigger);
|
|
3504
|
+
}
|
|
3505
|
+
this.shadow.appendChild(trigger);
|
|
3506
|
+
if (this.fabPos && this.config.draggable) {
|
|
3507
|
+
const savedPos = this.fabPos;
|
|
3508
|
+
this.fabPos = { x: 0, y: 0 };
|
|
3509
|
+
this.moveFab(trigger, savedPos.x, savedPos.y, false);
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
const panel = document.createElement("div");
|
|
3513
|
+
panel.className = `mushi-panel ${pos}${this.isOpen ? " open" : " closed"}`;
|
|
3514
|
+
panel.setAttribute("role", "dialog");
|
|
3515
|
+
panel.setAttribute("aria-modal", "true");
|
|
3516
|
+
panel.setAttribute("aria-label", t.widget.title);
|
|
3517
|
+
panel.style.zIndex = String(this.config.zIndex + 1);
|
|
3518
|
+
this.applyInsetVars(panel);
|
|
3519
|
+
if (this.isOpen) {
|
|
3520
|
+
const ctx = this.renderCtx();
|
|
3521
|
+
panel.innerHTML = `${renderOutdatedBanner(ctx)}${renderStep(ctx)}${renderBrandFooter(ctx)}`;
|
|
3522
|
+
this.shadow.appendChild(panel);
|
|
3523
|
+
this.attachHandlers(panel);
|
|
3524
|
+
this.trapFocus(panel);
|
|
3525
|
+
this.attachViewportHandlers(panel);
|
|
3526
|
+
} else {
|
|
3527
|
+
this.teardownViewportHandlers();
|
|
3528
|
+
}
|
|
3196
3529
|
}
|
|
3197
3530
|
/**
|
|
3198
|
-
*
|
|
3199
|
-
*
|
|
3200
|
-
*
|
|
3201
|
-
*
|
|
3202
|
-
*
|
|
3203
|
-
*
|
|
3531
|
+
* Queries each `avoidSelectors` element in the host document and returns
|
|
3532
|
+
* the minimum top-offset in px so that a top-anchored element clears all
|
|
3533
|
+
* of them by `gap` pixels. Returns `null` when no selectors are provided
|
|
3534
|
+
* or no matching elements have a non-zero bounding rect.
|
|
3535
|
+
*
|
|
3536
|
+
* Runs in the host document (not shadow DOM) so it can reach fixed headers,
|
|
3537
|
+
* sticky nav bars, and sign-in CTAs.
|
|
3204
3538
|
*/
|
|
3205
|
-
|
|
3206
|
-
const
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
${this.config.betaMode?.enabled ? this.renderBetaSuccessFooter() : ""}
|
|
3222
|
-
</div>
|
|
3223
|
-
</div>
|
|
3224
|
-
`;
|
|
3539
|
+
computeAvoidTopPx(gap = 8) {
|
|
3540
|
+
const sels = this.config.avoidSelectors;
|
|
3541
|
+
if (!sels?.length) return null;
|
|
3542
|
+
let maxBottom = 0;
|
|
3543
|
+
for (const sel of sels) {
|
|
3544
|
+
try {
|
|
3545
|
+
const el = document.querySelector(sel);
|
|
3546
|
+
if (!el) continue;
|
|
3547
|
+
const r = el.getBoundingClientRect();
|
|
3548
|
+
if (r.bottom > maxBottom && r.width > 0 && r.height > 0) {
|
|
3549
|
+
maxBottom = r.bottom;
|
|
3550
|
+
}
|
|
3551
|
+
} catch {
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
return maxBottom > 0 ? Math.ceil(maxBottom) + gap : null;
|
|
3225
3555
|
}
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3556
|
+
applyInsetVars(el) {
|
|
3557
|
+
const { anchor } = this.config;
|
|
3558
|
+
if (anchor && Object.keys(anchor).length > 0) {
|
|
3559
|
+
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
3560
|
+
const value = anchor[edge];
|
|
3561
|
+
if (value !== void 0) el.style.setProperty(`--mushi-${edge}`, value);
|
|
3562
|
+
});
|
|
3563
|
+
el.style.setProperty("--mushi-safe-area", this.config.respectSafeArea ? "1" : "0");
|
|
3564
|
+
} else {
|
|
3565
|
+
const { inset } = this.config;
|
|
3566
|
+
if (!this.config.respectSafeArea) {
|
|
3567
|
+
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
3568
|
+
if (inset[edge] === void 0) el.style.setProperty(`--mushi-${edge}`, "24px");
|
|
3569
|
+
});
|
|
3570
|
+
}
|
|
3571
|
+
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
3572
|
+
const value = inset[edge];
|
|
3573
|
+
if (value === void 0) return;
|
|
3574
|
+
el.style.setProperty(`--mushi-${edge}`, value === "auto" ? "auto" : `${value}px`);
|
|
3575
|
+
});
|
|
3576
|
+
el.style.setProperty("--mushi-safe-area", this.config.respectSafeArea ? "1" : "0");
|
|
3247
3577
|
}
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3578
|
+
const isTopAnchored = anchor?.top !== void 0 || this.config.position?.startsWith("top") || !this.config.position && !anchor?.bottom;
|
|
3579
|
+
if (isTopAnchored) {
|
|
3580
|
+
const avoidPx = this.computeAvoidTopPx();
|
|
3581
|
+
if (avoidPx !== null) {
|
|
3582
|
+
el.style.setProperty("--mushi-top", `${avoidPx}px`);
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
// ─── Draggable FAB ──────────────────────────────────────────────────────────
|
|
3587
|
+
/** Storage key for the FAB position, scoped to projectId when available. */
|
|
3588
|
+
fabStorageKey() {
|
|
3589
|
+
const id = this.config["projectId"] ?? "";
|
|
3590
|
+
return `mushi_fab_pos${id ? `_${id}` : ""}`;
|
|
3591
|
+
}
|
|
3592
|
+
/** Move the FAB to the given translated offset (relative to the inset origin),
|
|
3593
|
+
* clamping inside viewport safe area, and optionally snap to nearest edge.
|
|
3594
|
+
*
|
|
3595
|
+
* The FAB's CSS anchor can be any corner (bottom-right, bottom-left, …) so we
|
|
3596
|
+
* must derive the *base* position (CSS anchor with zero drag offset) to compute
|
|
3597
|
+
* correct clamp bounds and snap targets. We do this by subtracting the
|
|
3598
|
+
* already-applied drag offset from the live getBoundingClientRect() value. */
|
|
3599
|
+
moveFab(trigger, x, y, snap) {
|
|
3600
|
+
const axis = (() => {
|
|
3601
|
+
const d2 = this.config.draggable;
|
|
3602
|
+
if (!d2) return "both";
|
|
3603
|
+
return typeof d2 === "object" ? d2.axis ?? "both" : "both";
|
|
3604
|
+
})();
|
|
3605
|
+
const W = window.innerWidth;
|
|
3606
|
+
const H = window.innerHeight;
|
|
3607
|
+
const btnW = trigger.offsetWidth || 52;
|
|
3608
|
+
const btnH = trigger.offsetHeight || 52;
|
|
3609
|
+
const safeL = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--sai-left") || "0") || 0;
|
|
3610
|
+
const safeR = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--sai-right") || "0") || 0;
|
|
3611
|
+
const safeT = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--sai-top") || "0") || 0;
|
|
3612
|
+
const safeB = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--sai-bottom") || "0") || 0;
|
|
3613
|
+
const margin = 8;
|
|
3614
|
+
const rect = trigger.getBoundingClientRect();
|
|
3615
|
+
const prevDragX = this.fabPos?.x ?? 0;
|
|
3616
|
+
const prevDragY = this.fabPos?.y ?? 0;
|
|
3617
|
+
const baseLeft = rect.left - prevDragX;
|
|
3618
|
+
const baseTop = rect.top - prevDragY;
|
|
3619
|
+
const minX = safeL + margin - baseLeft;
|
|
3620
|
+
const maxX = W - safeR - margin - btnW - baseLeft;
|
|
3621
|
+
const minY = safeT + margin - baseTop;
|
|
3622
|
+
const maxY = H - safeB - margin - btnH - baseTop;
|
|
3623
|
+
const newX = axis === "y" ? 0 : Math.max(minX, Math.min(maxX, x));
|
|
3624
|
+
const newY = axis === "x" ? 0 : Math.max(minY, Math.min(maxY, y));
|
|
3625
|
+
let finalX = newX;
|
|
3626
|
+
if (snap) {
|
|
3627
|
+
const d2 = this.config.draggable;
|
|
3628
|
+
const shouldSnap = d2 === true || typeof d2 === "object" && (d2.snapToEdge ?? true);
|
|
3629
|
+
if (shouldSnap && axis !== "y") {
|
|
3630
|
+
const center = rect.left + btnW / 2;
|
|
3631
|
+
finalX = center < W / 2 ? safeL + margin - baseLeft : W - safeR - margin - btnW - baseLeft;
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
this.fabPos = { x: finalX, y: newY };
|
|
3635
|
+
trigger.style.setProperty("--mushi-drag-x", `${finalX}px`);
|
|
3636
|
+
trigger.style.setProperty("--mushi-drag-y", `${newY}px`);
|
|
3637
|
+
trigger.style.setProperty("--mushi-drag-active", "1");
|
|
3638
|
+
const d = this.config.draggable;
|
|
3639
|
+
const shouldPersist = d === true || typeof d === "object" && (d.persist ?? true);
|
|
3640
|
+
if (shouldPersist) {
|
|
3641
|
+
try {
|
|
3642
|
+
localStorage.setItem(this.fabStorageKey(), JSON.stringify(this.fabPos));
|
|
3643
|
+
} catch {
|
|
3644
|
+
}
|
|
3258
3645
|
}
|
|
3259
|
-
const idShort = `#${this.lastReportId.slice(0, 8)}`;
|
|
3260
|
-
const dashboard = (this.config.dashboardUrl ?? "").replace(/\/$/, "");
|
|
3261
|
-
const trackHref = dashboard ? `${dashboard}/reports/${encodeURIComponent(this.lastReportId)}` : "";
|
|
3262
|
-
return `
|
|
3263
|
-
<div class="mushi-success-receipt" role="status">
|
|
3264
|
-
<div class="mushi-success-receipt-row">
|
|
3265
|
-
<span class="mushi-success-receipt-label">Receipt</span>
|
|
3266
|
-
<button
|
|
3267
|
-
type="button"
|
|
3268
|
-
class="mushi-success-receipt-id"
|
|
3269
|
-
data-action="copy-report-id"
|
|
3270
|
-
data-copy-id="${escapeHtml(this.lastReportId)}"
|
|
3271
|
-
title="Copy report id ${escapeHtml(this.lastReportId)}"
|
|
3272
|
-
aria-label="Copy report id ${escapeHtml(this.lastReportId)}"
|
|
3273
|
-
>${escapeHtml(idShort)}<span class="mushi-success-receipt-copy" aria-hidden="true">\u2398</span></button>
|
|
3274
|
-
</div>
|
|
3275
|
-
${trackHref ? `
|
|
3276
|
-
<a
|
|
3277
|
-
class="mushi-success-receipt-track"
|
|
3278
|
-
href="${escapeHtml(trackHref)}"
|
|
3279
|
-
target="_blank"
|
|
3280
|
-
rel="noopener noreferrer"
|
|
3281
|
-
>Track on Mushi <span aria-hidden="true">\u2197</span></a>
|
|
3282
|
-
` : ""}
|
|
3283
|
-
${this.renderSlaLine()}
|
|
3284
|
-
</div>
|
|
3285
|
-
`;
|
|
3286
3646
|
}
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3647
|
+
/** Load previously persisted FAB position. */
|
|
3648
|
+
loadFabPos() {
|
|
3649
|
+
const d = this.config.draggable;
|
|
3650
|
+
if (!d) return;
|
|
3651
|
+
const shouldPersist = d === true || typeof d === "object" && (d.persist ?? true);
|
|
3652
|
+
if (!shouldPersist) return;
|
|
3653
|
+
try {
|
|
3654
|
+
const raw = localStorage.getItem(this.fabStorageKey());
|
|
3655
|
+
if (raw) {
|
|
3656
|
+
const parsed = JSON.parse(raw);
|
|
3657
|
+
if (typeof parsed?.x === "number" && typeof parsed?.y === "number") {
|
|
3658
|
+
this.fabPos = parsed;
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
} catch {
|
|
3291
3662
|
}
|
|
3292
|
-
|
|
3663
|
+
}
|
|
3664
|
+
/** Attach Pointer Events-based drag to the trigger element. */
|
|
3665
|
+
attachDragHandlers(trigger) {
|
|
3666
|
+
if (this.fabPos === null) this.loadFabPos();
|
|
3667
|
+
let startX = 0, startY = 0;
|
|
3668
|
+
let originX = 0, originY = 0;
|
|
3669
|
+
let dragging = false;
|
|
3670
|
+
let moved = false;
|
|
3671
|
+
const onPointerDown = (e) => {
|
|
3672
|
+
if (e.button !== 0 && e.pointerType !== "touch") return;
|
|
3673
|
+
trigger.setPointerCapture(e.pointerId);
|
|
3674
|
+
startX = e.clientX;
|
|
3675
|
+
startY = e.clientY;
|
|
3676
|
+
const cur = this.fabPos ?? { x: 0, y: 0 };
|
|
3677
|
+
originX = cur.x;
|
|
3678
|
+
originY = cur.y;
|
|
3679
|
+
dragging = true;
|
|
3680
|
+
moved = false;
|
|
3681
|
+
};
|
|
3682
|
+
const DRAG_THRESHOLD = 6;
|
|
3683
|
+
const onPointerMove = (e) => {
|
|
3684
|
+
if (!dragging) return;
|
|
3685
|
+
const dx = e.clientX - startX;
|
|
3686
|
+
const dy = e.clientY - startY;
|
|
3687
|
+
if (!moved && Math.hypot(dx, dy) > DRAG_THRESHOLD) {
|
|
3688
|
+
moved = true;
|
|
3689
|
+
trigger.classList.add("dragging");
|
|
3690
|
+
trigger.setAttribute("aria-grabbed", "true");
|
|
3691
|
+
}
|
|
3692
|
+
if (moved) {
|
|
3693
|
+
e.preventDefault();
|
|
3694
|
+
this.moveFab(trigger, originX + dx, originY + dy, false);
|
|
3695
|
+
}
|
|
3696
|
+
};
|
|
3697
|
+
const onPointerUp = (e) => {
|
|
3698
|
+
if (!dragging) return;
|
|
3699
|
+
dragging = false;
|
|
3700
|
+
trigger.classList.remove("dragging");
|
|
3701
|
+
trigger.removeAttribute("aria-grabbed");
|
|
3702
|
+
if (moved) {
|
|
3703
|
+
const dx = e.clientX - startX;
|
|
3704
|
+
const dy = e.clientY - startY;
|
|
3705
|
+
this.moveFab(trigger, originX + dx, originY + dy, true);
|
|
3706
|
+
const suppressClick = (ev) => {
|
|
3707
|
+
ev.stopImmediatePropagation();
|
|
3708
|
+
trigger.removeEventListener("click", suppressClick, { capture: true });
|
|
3709
|
+
};
|
|
3710
|
+
trigger.addEventListener("click", suppressClick, { capture: true });
|
|
3711
|
+
}
|
|
3712
|
+
moved = false;
|
|
3713
|
+
};
|
|
3714
|
+
trigger.addEventListener("pointerdown", onPointerDown);
|
|
3715
|
+
trigger.addEventListener("pointermove", onPointerMove);
|
|
3716
|
+
trigger.addEventListener("pointerup", onPointerUp);
|
|
3717
|
+
trigger.addEventListener("pointercancel", onPointerUp);
|
|
3718
|
+
}
|
|
3719
|
+
// ─── Keyboard / visualViewport ──────────────────────────────────────────────
|
|
3720
|
+
/** Lift the panel above the software keyboard using visualViewport. */
|
|
3721
|
+
attachViewportHandlers(panel) {
|
|
3722
|
+
this.teardownViewportHandlers();
|
|
3723
|
+
const vv = window.visualViewport;
|
|
3724
|
+
if (!vv) return;
|
|
3725
|
+
const update = () => {
|
|
3726
|
+
const keyboardInset = window.innerHeight - vv.height - vv.offsetTop;
|
|
3727
|
+
if (keyboardInset > 50) {
|
|
3728
|
+
panel.style.setProperty("--mushi-keyboard-inset", `${Math.round(keyboardInset)}px`);
|
|
3729
|
+
panel.classList.add("keyboard-open");
|
|
3730
|
+
const ta = panel.querySelector('textarea, input[type="text"]');
|
|
3731
|
+
ta?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
3732
|
+
} else {
|
|
3733
|
+
panel.style.setProperty("--mushi-keyboard-inset", "0px");
|
|
3734
|
+
panel.classList.remove("keyboard-open");
|
|
3735
|
+
}
|
|
3736
|
+
};
|
|
3737
|
+
vv.addEventListener("resize", update, { passive: true });
|
|
3738
|
+
vv.addEventListener("scroll", update, { passive: true });
|
|
3739
|
+
const onFocus = () => requestAnimationFrame(update);
|
|
3740
|
+
panel.addEventListener("focusin", onFocus);
|
|
3741
|
+
this.vvCleanup = () => {
|
|
3742
|
+
vv.removeEventListener("resize", update);
|
|
3743
|
+
vv.removeEventListener("scroll", update);
|
|
3744
|
+
panel.removeEventListener("focusin", onFocus);
|
|
3745
|
+
};
|
|
3746
|
+
}
|
|
3747
|
+
teardownViewportHandlers() {
|
|
3748
|
+
this.vvCleanup?.();
|
|
3749
|
+
this.vvCleanup = null;
|
|
3293
3750
|
}
|
|
3294
3751
|
/**
|
|
3295
|
-
*
|
|
3296
|
-
*
|
|
3297
|
-
*
|
|
3298
|
-
* the user sees shapes their entire impression of the interaction).
|
|
3752
|
+
* Minimum description length, lowered for CJK locales where each character
|
|
3753
|
+
* carries more meaning. Used by both the view layer (via renderCtx) and the
|
|
3754
|
+
* details-step input validation in attachHandlers.
|
|
3299
3755
|
*/
|
|
3300
|
-
|
|
3301
|
-
const
|
|
3302
|
-
const
|
|
3303
|
-
const
|
|
3304
|
-
return
|
|
3305
|
-
<div class="mushi-beta-success-footer" role="note" aria-label="Beta feedback acknowledgement">
|
|
3306
|
-
${email ? `<div class="mushi-beta-success-line">\u{1F4EC} Sent to ${email}</div>` : `<div class="mushi-beta-success-line">\u{1F4EC} Sent to ${appName}</div>`}
|
|
3307
|
-
<div class="mushi-beta-success-line mushi-beta-success-dim">We aim to review within 48h \xB7 thank you for helping build this</div>
|
|
3308
|
-
</div>
|
|
3309
|
-
`;
|
|
3756
|
+
effectiveMinLength() {
|
|
3757
|
+
const base = this.config.minDescriptionLength ?? 20;
|
|
3758
|
+
const lang = this.config.locale === "auto" ? typeof navigator !== "undefined" ? navigator.language ?? "" : "" : this.config.locale ?? "";
|
|
3759
|
+
const isCjk = /^(ja|zh|ko)/i.test(lang);
|
|
3760
|
+
return isCjk ? Math.max(4, Math.floor(base / 2)) : base;
|
|
3310
3761
|
}
|
|
3762
|
+
/** Tier accent colour for the rewards UI. */
|
|
3311
3763
|
tierColor(slug) {
|
|
3312
3764
|
const colors = {
|
|
3313
3765
|
free: "#6b7280",
|
|
@@ -3317,62 +3769,57 @@ var MushiWidget = class _MushiWidget {
|
|
|
3317
3769
|
};
|
|
3318
3770
|
return colors[slug] ?? "#6c47ff";
|
|
3319
3771
|
}
|
|
3320
|
-
/**
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
</div>
|
|
3372
|
-
<div class="mushi-rewards-next-label">${nextLabel}</div>
|
|
3373
|
-
` : ""}
|
|
3374
|
-
</div>
|
|
3375
|
-
`;
|
|
3772
|
+
/**
|
|
3773
|
+
* Build the read-only snapshot + bound helper closures the stateless view
|
|
3774
|
+
* layer (widget-render.ts) renders from. Rebuilt once per render() pass so
|
|
3775
|
+
* the HTML always reflects current state.
|
|
3776
|
+
*/
|
|
3777
|
+
renderCtx() {
|
|
3778
|
+
return {
|
|
3779
|
+
config: this.config,
|
|
3780
|
+
rewardsState: this.rewardsState,
|
|
3781
|
+
lastReportId: this.lastReportId,
|
|
3782
|
+
reporterLoading: this.reporterLoading,
|
|
3783
|
+
locale: this.locale,
|
|
3784
|
+
testerReputation: this.testerReputation,
|
|
3785
|
+
testerInfo: this.testerInfo,
|
|
3786
|
+
screenshotCapturing: this.screenshotCapturing,
|
|
3787
|
+
screenshotAttached: this.screenshotAttached,
|
|
3788
|
+
reporterError: this.reporterError,
|
|
3789
|
+
magicLinkError: this.magicLinkError,
|
|
3790
|
+
elementCapturing: this.elementCapturing,
|
|
3791
|
+
submitting: this.submitting,
|
|
3792
|
+
sdkFreshness: this.sdkFreshness,
|
|
3793
|
+
screenshotError: this.screenshotError,
|
|
3794
|
+
reporterReports: this.reporterReports,
|
|
3795
|
+
magicLinkSending: this.magicLinkSending,
|
|
3796
|
+
magicLinkEmail: this.magicLinkEmail,
|
|
3797
|
+
globalLeaderboardLoading: this.globalLeaderboardLoading,
|
|
3798
|
+
globalLeaderboard: this.globalLeaderboard,
|
|
3799
|
+
elementSelected: this.elementSelected,
|
|
3800
|
+
crossAppLoading: this.crossAppLoading,
|
|
3801
|
+
callbacks: this.callbacks,
|
|
3802
|
+
testerJwt: this.testerJwt,
|
|
3803
|
+
submittedAt: this.submittedAt,
|
|
3804
|
+
step: this.step,
|
|
3805
|
+
selectedReportId: this.selectedReportId,
|
|
3806
|
+
selectedCategory: this.selectedCategory,
|
|
3807
|
+
sdkVersion: this.sdkVersion,
|
|
3808
|
+
reporterComments: this.reporterComments,
|
|
3809
|
+
magicLinkSent: this.magicLinkSent,
|
|
3810
|
+
leaderboardLoading: this.leaderboardLoading,
|
|
3811
|
+
leaderboardEntries: this.leaderboardEntries,
|
|
3812
|
+
lastSubmitQueuedOffline: this.lastSubmitQueuedOffline,
|
|
3813
|
+
featureBoard: this.featureBoard,
|
|
3814
|
+
crossAppReports: this.crossAppReports,
|
|
3815
|
+
allowScreenshotRemove: this.allowScreenshotRemove,
|
|
3816
|
+
unreadCount: () => this.unreadCount(),
|
|
3817
|
+
tierColor: (slug) => this.tierColor(slug),
|
|
3818
|
+
resolveCustomCategory: (id) => this.resolveCustomCategory(id),
|
|
3819
|
+
effectiveMinLength: () => this.effectiveMinLength(),
|
|
3820
|
+
categoryLabel: (id) => this.categoryLabel(id),
|
|
3821
|
+
categoryIcon: (id) => this.categoryIcon(id)
|
|
3822
|
+
};
|
|
3376
3823
|
}
|
|
3377
3824
|
attachHandlers(panel) {
|
|
3378
3825
|
const t = this.locale;
|
|
@@ -3431,6 +3878,56 @@ var MushiWidget = class _MushiWidget {
|
|
|
3431
3878
|
panel.querySelector('[data-action="open-leaderboard"]')?.addEventListener("click", () => {
|
|
3432
3879
|
this.step = "leaderboard";
|
|
3433
3880
|
this.callbacks.onLeaderboardOpen?.();
|
|
3881
|
+
this.callbacks.onGlobalLeaderboardOpen?.();
|
|
3882
|
+
this.render();
|
|
3883
|
+
});
|
|
3884
|
+
panel.querySelector('[data-action="open-account"]')?.addEventListener("click", () => {
|
|
3885
|
+
this.step = "account";
|
|
3886
|
+
this.render();
|
|
3887
|
+
});
|
|
3888
|
+
panel.querySelector('[data-action="open-cross-app-reports"]')?.addEventListener("click", () => {
|
|
3889
|
+
this.step = "cross-app-reports";
|
|
3890
|
+
this.crossAppLoading = true;
|
|
3891
|
+
this.crossAppReports = null;
|
|
3892
|
+
this.render();
|
|
3893
|
+
if (this.callbacks.onCrossAppReportsOpen) {
|
|
3894
|
+
this.callbacks.onCrossAppReportsOpen();
|
|
3895
|
+
} else {
|
|
3896
|
+
this.crossAppLoading = false;
|
|
3897
|
+
this.crossAppReports = [];
|
|
3898
|
+
this.render();
|
|
3899
|
+
}
|
|
3900
|
+
});
|
|
3901
|
+
panel.querySelector('[data-action="open-global-leaderboard"]')?.addEventListener("click", () => {
|
|
3902
|
+
this.step = "leaderboard";
|
|
3903
|
+
this.globalLeaderboard = null;
|
|
3904
|
+
this.globalLeaderboardLoading = true;
|
|
3905
|
+
this.render();
|
|
3906
|
+
if (this.callbacks.onGlobalLeaderboardOpen) {
|
|
3907
|
+
this.callbacks.onGlobalLeaderboardOpen();
|
|
3908
|
+
} else {
|
|
3909
|
+
this.globalLeaderboardLoading = false;
|
|
3910
|
+
this.globalLeaderboard = [];
|
|
3911
|
+
this.render();
|
|
3912
|
+
}
|
|
3913
|
+
});
|
|
3914
|
+
panel.querySelector('[data-action="send-magic-link"]')?.addEventListener("click", () => {
|
|
3915
|
+
void this.handleMagicLinkSend(panel);
|
|
3916
|
+
});
|
|
3917
|
+
panel.querySelector('[data-action="resend-magic-link"]')?.addEventListener("click", () => {
|
|
3918
|
+
this.magicLinkSent = false;
|
|
3919
|
+
this.magicLinkError = "";
|
|
3920
|
+
this.render();
|
|
3921
|
+
});
|
|
3922
|
+
panel.querySelector('[data-action="sign-out-tester"]')?.addEventListener("click", () => {
|
|
3923
|
+
this.testerJwt = null;
|
|
3924
|
+
this.testerInfo = null;
|
|
3925
|
+
this.testerReputation = null;
|
|
3926
|
+
this.crossAppReports = null;
|
|
3927
|
+
this.magicLinkSent = false;
|
|
3928
|
+
this.magicLinkEmail = "";
|
|
3929
|
+
this.step = "category";
|
|
3930
|
+
this.callbacks.onTesterSignOut?.();
|
|
3434
3931
|
this.render();
|
|
3435
3932
|
});
|
|
3436
3933
|
panel.querySelector('[data-action="reporter-reply"]')?.addEventListener("click", () => {
|
|
@@ -3716,6 +4213,30 @@ var MushiWidget = class _MushiWidget {
|
|
|
3716
4213
|
this.render();
|
|
3717
4214
|
}
|
|
3718
4215
|
}
|
|
4216
|
+
/* ── Community: magic-link sign-in ───────────────────────────────── */
|
|
4217
|
+
async handleMagicLinkSend(panel) {
|
|
4218
|
+
if (this.magicLinkSending) return;
|
|
4219
|
+
const emailInput = panel.querySelector('[data-role="magic-link-email"]');
|
|
4220
|
+
const email = (emailInput?.value ?? this.magicLinkEmail).trim();
|
|
4221
|
+
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
4222
|
+
this.magicLinkError = "Please enter a valid email address.";
|
|
4223
|
+
this.render();
|
|
4224
|
+
return;
|
|
4225
|
+
}
|
|
4226
|
+
this.magicLinkEmail = email;
|
|
4227
|
+
this.magicLinkError = "";
|
|
4228
|
+
this.magicLinkSending = true;
|
|
4229
|
+
this.render();
|
|
4230
|
+
try {
|
|
4231
|
+
await this.callbacks.onMushiSignIn?.(email);
|
|
4232
|
+
this.magicLinkSent = true;
|
|
4233
|
+
} catch (err) {
|
|
4234
|
+
this.magicLinkError = err instanceof Error ? err.message : "Could not send sign-in link. Try again.";
|
|
4235
|
+
} finally {
|
|
4236
|
+
this.magicLinkSending = false;
|
|
4237
|
+
this.render();
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
3719
4240
|
/* ── Marketing / Playwright recorder (debug GIF capture) ─────────── */
|
|
3720
4241
|
getRecorderStep() {
|
|
3721
4242
|
return this.step;
|
|
@@ -5798,10 +6319,6 @@ function createProactiveManager(config = {}) {
|
|
|
5798
6319
|
return { shouldShow, recordDismissal, recordSubmission, reset };
|
|
5799
6320
|
}
|
|
5800
6321
|
|
|
5801
|
-
// src/version.ts
|
|
5802
|
-
var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
|
|
5803
|
-
var MUSHI_SDK_VERSION = "1.13.0" ;
|
|
5804
|
-
|
|
5805
6322
|
// src/mushi.ts
|
|
5806
6323
|
var instance = null;
|
|
5807
6324
|
var Mushi = class {
|
|
@@ -5882,6 +6399,42 @@ function createInstance(config) {
|
|
|
5882
6399
|
let replayCap = null;
|
|
5883
6400
|
let replayGeneration = 0;
|
|
5884
6401
|
let widget;
|
|
6402
|
+
const TESTER_JWT_KEY = `mushi:tester-jwt:${bootstrapConfig.projectId}`;
|
|
6403
|
+
function readTesterJwt() {
|
|
6404
|
+
try {
|
|
6405
|
+
return typeof localStorage !== "undefined" ? localStorage.getItem(TESTER_JWT_KEY) : null;
|
|
6406
|
+
} catch {
|
|
6407
|
+
return null;
|
|
6408
|
+
}
|
|
6409
|
+
}
|
|
6410
|
+
function clearTesterJwt() {
|
|
6411
|
+
try {
|
|
6412
|
+
if (typeof localStorage !== "undefined") localStorage.removeItem(TESTER_JWT_KEY);
|
|
6413
|
+
} catch {
|
|
6414
|
+
}
|
|
6415
|
+
}
|
|
6416
|
+
async function loadTesterSession(jwt) {
|
|
6417
|
+
const statusResult = await apiClient2.getTesterStatus(jwt);
|
|
6418
|
+
if (!statusResult.ok || !statusResult.data) {
|
|
6419
|
+
clearTesterJwt();
|
|
6420
|
+
return;
|
|
6421
|
+
}
|
|
6422
|
+
const status = statusResult.data;
|
|
6423
|
+
if (!status.is_tester) {
|
|
6424
|
+
clearTesterJwt();
|
|
6425
|
+
return;
|
|
6426
|
+
}
|
|
6427
|
+
widget.setTesterSession(jwt, {
|
|
6428
|
+
id: jwt.substring(0, 16),
|
|
6429
|
+
public_handle: status.public_handle ?? null,
|
|
6430
|
+
display_name: status.display_name ?? null
|
|
6431
|
+
});
|
|
6432
|
+
const repResult = await apiClient2.getMyReputation(jwt);
|
|
6433
|
+
if (repResult.ok && repResult.data) {
|
|
6434
|
+
const repData = repResult.data;
|
|
6435
|
+
if (repData.reputation) widget.setTesterReputation(repData.reputation);
|
|
6436
|
+
}
|
|
6437
|
+
}
|
|
5885
6438
|
function syncCaptureModules() {
|
|
5886
6439
|
if (activeConfig.capture?.console !== false) {
|
|
5887
6440
|
consoleCap ??= createConsoleCapture();
|
|
@@ -6175,6 +6728,56 @@ function createInstance(config) {
|
|
|
6175
6728
|
void fetchLeaderboard(10).then((entries) => {
|
|
6176
6729
|
widget.setLeaderboard(entries, false);
|
|
6177
6730
|
});
|
|
6731
|
+
},
|
|
6732
|
+
// ── Community callbacks ──────────────────────────────────────────────
|
|
6733
|
+
async onMushiSignIn(email) {
|
|
6734
|
+
const res = await apiClient2.sendMagicLink(email);
|
|
6735
|
+
if (!res.ok) throw new Error(res.error?.message ?? "Could not send sign-in link");
|
|
6736
|
+
return { ok: true };
|
|
6737
|
+
},
|
|
6738
|
+
async onGlobalLeaderboardOpen() {
|
|
6739
|
+
widget.setGlobalLeaderboard(null, true);
|
|
6740
|
+
try {
|
|
6741
|
+
const jwt = readTesterJwt();
|
|
6742
|
+
const res = await apiClient2.getPublicLeaderboard(50);
|
|
6743
|
+
const rawEntries = res.ok ? res.data?.leaderboard ?? [] : [];
|
|
6744
|
+
const entries = rawEntries.map((e) => ({
|
|
6745
|
+
tester_id: e.tester_id,
|
|
6746
|
+
rank: e.rank,
|
|
6747
|
+
public_handle: e.public_handle,
|
|
6748
|
+
display_name: e.display_name,
|
|
6749
|
+
points_30d: e.points_30d,
|
|
6750
|
+
total_points: e.total_points ?? 0,
|
|
6751
|
+
badge: e.badge_slug
|
|
6752
|
+
}));
|
|
6753
|
+
widget.setGlobalLeaderboard(entries, false);
|
|
6754
|
+
if (jwt) {
|
|
6755
|
+
const repRes = await apiClient2.getMyReputation(jwt);
|
|
6756
|
+
if (repRes.ok && repRes.data) {
|
|
6757
|
+
const repData = repRes.data;
|
|
6758
|
+
if (repData.reputation) widget.setTesterReputation(repData.reputation);
|
|
6759
|
+
}
|
|
6760
|
+
}
|
|
6761
|
+
} catch {
|
|
6762
|
+
widget.setGlobalLeaderboard([], false);
|
|
6763
|
+
}
|
|
6764
|
+
},
|
|
6765
|
+
async onCrossAppReportsOpen() {
|
|
6766
|
+
const jwt = readTesterJwt();
|
|
6767
|
+
if (!jwt) {
|
|
6768
|
+
widget.setCrossAppReports([], false);
|
|
6769
|
+
return;
|
|
6770
|
+
}
|
|
6771
|
+
try {
|
|
6772
|
+
const res = await apiClient2.getCrossAppReports(jwt);
|
|
6773
|
+
const reports = res.ok ? res.data?.reports ?? [] : [];
|
|
6774
|
+
widget.setCrossAppReports(reports, false);
|
|
6775
|
+
} catch {
|
|
6776
|
+
widget.setCrossAppReports([], false);
|
|
6777
|
+
}
|
|
6778
|
+
},
|
|
6779
|
+
onTesterSignOut() {
|
|
6780
|
+
clearTesterJwt();
|
|
6178
6781
|
}
|
|
6179
6782
|
}, MUSHI_SDK_VERSION);
|
|
6180
6783
|
syncCaptureModules();
|
|
@@ -6185,6 +6788,10 @@ function createInstance(config) {
|
|
|
6185
6788
|
widget.mount();
|
|
6186
6789
|
}
|
|
6187
6790
|
}
|
|
6791
|
+
const cachedJwt = readTesterJwt();
|
|
6792
|
+
if (cachedJwt) {
|
|
6793
|
+
void loadTesterSession(cachedJwt).catch(() => clearTesterJwt());
|
|
6794
|
+
}
|
|
6188
6795
|
let proactiveTriggers = null;
|
|
6189
6796
|
let proactiveManager = null;
|
|
6190
6797
|
const proactiveCfg = activeConfig.proactive;
|