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