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