@sensiblestats/widget-react 0.154.1 → 0.156.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/StatsWidget.tsx
2
2
  import { useCallback as useCallback31, useEffect as useEffect59, useMemo as useMemo17, useRef as useRef50, useState as useState89 } from "react";
3
- import { StatsWidgetClient } from "@sensiblestats/widget-sdk";
3
+ import { StatsWidgetClient, observingFetch } from "@sensiblestats/widget-sdk";
4
4
 
5
5
  // src/strings/tag.ts
6
6
  function familyOf(tag2) {
@@ -1383,9 +1383,19 @@ function parseCustomTotal(text2, format2) {
1383
1383
  }
1384
1384
 
1385
1385
  // src/version.generated.ts
1386
- var WIDGET_REACT_VERSION = "0.154.1";
1386
+ var WIDGET_REACT_VERSION = "0.156.0";
1387
1387
 
1388
1388
  // src/config.ts
1389
+ var COLOR_KEYS = ["accent", "cta", "surface", "ink"];
1390
+ function themeColors(group) {
1391
+ const out = {};
1392
+ if (!group || typeof group !== "object") return out;
1393
+ for (const k of COLOR_KEYS) {
1394
+ const v = group[k];
1395
+ if (typeof v === "string" && v.trim() !== "") out[k] = v.trim();
1396
+ }
1397
+ return out;
1398
+ }
1389
1399
  function hostTag(cfg) {
1390
1400
  const pick = (v) => typeof v === "string" && v.trim() !== "" ? v.trim() : void 0;
1391
1401
  return pick(cfg?.locale) ?? pick(cfg?.userContext?.defaultLanguage);
@@ -1397,7 +1407,7 @@ function normalizeUi(cfg, loaded) {
1397
1407
  return {
1398
1408
  theme: cfg.theme ?? "auto",
1399
1409
  oddsFormat: parseOddsFormat(cfg.oddsFormat) ?? "decimal",
1400
- accent: cfg.accent,
1410
+ colors: { light: themeColors(cfg.colors?.light), dark: themeColors(cfg.colors?.dark) },
1401
1411
  logoUrl: cfg.logoUrl,
1402
1412
  headerTitle: cfg.headerTitle,
1403
1413
  locale: loaded.tag,
@@ -1405,9 +1415,6 @@ function normalizeUi(cfg, loaded) {
1405
1415
  timeZone,
1406
1416
  hostTag: hostTag(cfg),
1407
1417
  rawBettingLabels: isBundledFamily(loaded.tag),
1408
- cta: cfg.cta,
1409
- surface: cfg.surface,
1410
- ink: cfg.ink,
1411
1418
  pinIcon: cfg.pinIcon ?? "pin",
1412
1419
  position: cfg.position ?? "right",
1413
1420
  offset: { x: cfg.offset?.x ?? 20, y: cfg.offset?.y ?? 20 },
@@ -2795,7 +2802,7 @@ function isValidId(value) {
2795
2802
  return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
2796
2803
  }
2797
2804
  function createWidgetHost() {
2798
- const state = { queue: [], sink: null };
2805
+ const state = { queue: [], sink: null, teaser: null };
2799
2806
  const dispatch = (command) => {
2800
2807
  if (state.sink) {
2801
2808
  state.sink(command);
@@ -2841,11 +2848,49 @@ function createWidgetHost() {
2841
2848
  if (isValidId(id)) dispatch({ kind: "matchOpened", matchId: id });
2842
2849
  } catch {
2843
2850
  }
2851
+ },
2852
+ // A teaser tap is about what is on screen now, so it is never queued for a widget that is not there.
2853
+ tapAsk(index) {
2854
+ teaser(state, (t) => t.tapAsk(index));
2855
+ },
2856
+ tapPrice() {
2857
+ try {
2858
+ return state.teaser ? state.teaser.tapPrice().catch(() => null) : Promise.resolve(null);
2859
+ } catch {
2860
+ return Promise.resolve(null);
2861
+ }
2862
+ },
2863
+ tapCta() {
2864
+ teaser(state, (t) => t.tapCta());
2865
+ },
2866
+ tapTeaser() {
2867
+ teaser(state, (t) => t.tapTeaser());
2868
+ },
2869
+ dismissTeaser() {
2870
+ teaser(state, (t) => t.dismissTeaser());
2871
+ },
2872
+ teaserShown() {
2873
+ teaser(state, (t) => t.teaserShown());
2844
2874
  }
2845
2875
  };
2846
2876
  STATES.set(host, state);
2847
2877
  return host;
2848
2878
  }
2879
+ function teaser(state, call) {
2880
+ try {
2881
+ if (state.teaser) call(state.teaser);
2882
+ } catch {
2883
+ }
2884
+ }
2885
+ function attachTeaser(host, control) {
2886
+ const state = STATES.get(host);
2887
+ if (!state) return () => {
2888
+ };
2889
+ state.teaser = control;
2890
+ return () => {
2891
+ if (state.teaser === control) state.teaser = null;
2892
+ };
2893
+ }
2849
2894
  function attachHost(host, sink) {
2850
2895
  const state = STATES.get(host);
2851
2896
  if (!state) return () => {
@@ -3081,6 +3126,12 @@ function useHostEvents(opts) {
3081
3126
  const { host, operatorId, currentUser, logger, isOpen, closePanel } = opts;
3082
3127
  const [added, setAdded] = useState2({});
3083
3128
  const [settled, setSettled] = useState2({});
3129
+ const [marksUser, setMarksUser] = useState2(currentUser);
3130
+ if (marksUser !== currentUser) {
3131
+ setMarksUser(currentUser);
3132
+ setAdded({});
3133
+ setSettled({});
3134
+ }
3084
3135
  const markAdded = useCallback((key) => {
3085
3136
  setAdded((prev) => prev[key] ? prev : { ...prev, [key]: true });
3086
3137
  }, []);
@@ -3243,32 +3294,33 @@ function pillFor(accent, panel, theme) {
3243
3294
  }
3244
3295
  return { pill: lightPanel ? "#000000" : "#ffffff", ink };
3245
3296
  }
3297
+ var PANEL = { light: LIGHT_PANEL, dark: DARK_PANEL };
3298
+ function brandVars(style, c, theme) {
3299
+ for (const k of ["accent", "cta", "surface", "ink"]) {
3300
+ const v = c[k];
3301
+ if (v) style[`--ss-w-brand-${k}-${theme}`] = v;
3302
+ }
3303
+ if (c.surface && c.ink) {
3304
+ style[`--ss-w-brand-bubble-${theme}`] = `color-mix(in srgb, ${c.ink} 5%, ${c.surface})`;
3305
+ style[`--ss-w-brand-line-${theme}`] = `color-mix(in srgb, ${c.ink} 12%, ${c.surface})`;
3306
+ style[`--ss-w-brand-faint-${theme}`] = `color-mix(in srgb, ${c.ink} 55%, ${c.surface})`;
3307
+ }
3308
+ if (c.accent || c.surface) {
3309
+ const panel = c.surface && rgb(c.surface) ? c.surface : PANEL[theme];
3310
+ const { pill, ink } = pillFor(c.accent, panel, theme);
3311
+ style[`--ss-w-pill-${theme}`] = pill;
3312
+ style[`--ss-w-on-pill-${theme}`] = ink;
3313
+ }
3314
+ }
3246
3315
  function themeAttrs(ui, userTheme) {
3247
3316
  const style = {
3248
3317
  "--ss-w-offset-x": `${ui.offset.x}px`,
3249
3318
  "--ss-w-offset-y": `${ui.offset.y}px`,
3250
3319
  "--ss-w-radius": `${ui.radius}px`
3251
3320
  };
3252
- if (ui.accent) style["--ss-w-accent"] = ui.accent;
3253
- if (ui.cta) style["--ss-w-cta"] = ui.cta;
3254
- if (ui.surface) style["--ss-w-panel"] = ui.surface;
3255
- if (ui.ink) style["--ss-w-ink"] = ui.ink;
3256
- if (ui.surface && ui.ink) {
3257
- style["--ss-w-bubble"] = "color-mix(in srgb, var(--ss-w-ink) 5%, var(--ss-w-panel))";
3258
- style["--ss-w-line"] = "color-mix(in srgb, var(--ss-w-ink) 12%, var(--ss-w-panel))";
3259
- style["--ss-w-faint"] = "color-mix(in srgb, var(--ss-w-ink) 55%, var(--ss-w-panel))";
3260
- }
3261
- if (ui.accent || ui.surface) {
3262
- const surface = ui.surface && rgb(ui.surface) ? ui.surface : void 0;
3263
- const light = pillFor(ui.accent, surface ?? LIGHT_PANEL, "light");
3264
- const dark = pillFor(ui.accent, surface ?? DARK_PANEL, "dark");
3265
- style["--ss-w-pill-light"] = light.pill;
3266
- style["--ss-w-on-pill-light"] = light.ink;
3267
- style["--ss-w-pill-dark"] = dark.pill;
3268
- style["--ss-w-on-pill-dark"] = dark.ink;
3269
- }
3270
- const theme = ui.surface || ui.ink ? ui.theme : userTheme ?? ui.theme;
3271
- return { "data-ss-w-theme": theme, "data-ss-w-pos": ui.position, style };
3321
+ brandVars(style, ui.colors.light, "light");
3322
+ brandVars(style, ui.colors.dark, "dark");
3323
+ return { "data-ss-w-theme": userTheme ?? ui.theme, "data-ss-w-pos": ui.position, style };
3272
3324
  }
3273
3325
 
3274
3326
  // src/oddsSettingsContext.ts
@@ -3332,7 +3384,6 @@ function writeOddsOffered(operatorKey, value) {
3332
3384
  var OddsSettingsContext = createContext({
3333
3385
  oddsFormat: "decimal",
3334
3386
  theme: "auto",
3335
- themeLocked: false,
3336
3387
  oddsOffered: true,
3337
3388
  setOddsFormat: () => {
3338
3389
  },
@@ -3364,11 +3415,10 @@ function useOddsSettingsState(ui, conversation, operatorKey) {
3364
3415
  userOddsFormat: stored.oddsFormat,
3365
3416
  theme: stored.theme ?? ui.theme,
3366
3417
  userTheme: stored.theme,
3367
- themeLocked: !!(ui.surface || ui.ink),
3368
3418
  oddsOffered,
3369
3419
  setOddsFormat: (f) => setStored(writeSettings({ oddsFormat: f })),
3370
3420
  setTheme: (t) => setStored(writeSettings({ theme: t }))
3371
- }), [stored, ui.oddsFormat, ui.theme, ui.surface, ui.ink, oddsOffered]);
3421
+ }), [stored, ui.oddsFormat, ui.theme, oddsOffered]);
3372
3422
  }
3373
3423
 
3374
3424
  // src/useChatStream.ts
@@ -4697,7 +4747,13 @@ function phaseForPin(snapshot, pin) {
4697
4747
  function useLiveMonitor(opts) {
4698
4748
  const sessionIdRef = useRef6(crypto.randomUUID());
4699
4749
  const [pins, setPins] = useState6([]);
4700
- const [store] = useState6(() => createPinStore(opts.storageKey, sessionIdRef.current, setPins));
4750
+ const [owned, setOwned] = useState6(() => ({ key: opts.storageKey, store: createPinStore(opts.storageKey, sessionIdRef.current, setPins) }));
4751
+ let current = owned;
4752
+ if (owned.key !== opts.storageKey) {
4753
+ current = { key: opts.storageKey, store: createPinStore(opts.storageKey, sessionIdRef.current, setPins) };
4754
+ setOwned(current);
4755
+ }
4756
+ const store = current.store;
4701
4757
  const [enabled, setEnabled] = useState6(true);
4702
4758
  const [snapshot, setSnapshotState] = useState6(null);
4703
4759
  const { activeTab, setActiveTab: setActiveTabState } = useTabs("chat");
@@ -8352,8 +8408,9 @@ function useMobileBinding(args) {
8352
8408
  tapTeaser: () => latest.current.onTeaserTap(),
8353
8409
  tapPrice: (matchOddsId) => {
8354
8410
  const { panelOpen: open, popupText: text2, price: shown2 } = latest.current;
8355
- if (open || !text2 || shown2?.matchOddsId !== matchOddsId) return;
8356
- priceRef.current?.();
8411
+ if (open || !text2 || shown2?.matchOddsId !== matchOddsId || !priceRef.current) return false;
8412
+ priceRef.current();
8413
+ return true;
8357
8414
  },
8358
8415
  dismissTeaser: () => latest.current.dismissPopup(),
8359
8416
  teaserShown: () => setConfirmedShown(latest.current.popupText),
@@ -8373,6 +8430,69 @@ function useMobileBinding(args) {
8373
8430
  return { confirmedShown, onCloseRequested, onRegisterBack, onRegisterPrice, onPriceResult, priceInFlight };
8374
8431
  }
8375
8432
 
8433
+ // src/webTeaser.ts
8434
+ function webTeaserBinding(host, deliver, drawsLauncher) {
8435
+ let price;
8436
+ let delivered = null;
8437
+ let detach = () => {
8438
+ };
8439
+ const waiting = /* @__PURE__ */ new Set();
8440
+ const emit = (teaser2) => {
8441
+ delivered = teaser2;
8442
+ try {
8443
+ deliver(teaser2);
8444
+ } catch {
8445
+ }
8446
+ };
8447
+ return {
8448
+ onTeaser: (teaser2) => {
8449
+ price = teaser2.price;
8450
+ emit(teaser2.text === null && teaser2.asks.length === 0 ? null : teaser2);
8451
+ },
8452
+ onCloseRequested: () => {
8453
+ },
8454
+ onPriceResult: (result) => {
8455
+ for (const w of [...waiting]) {
8456
+ if (w.matchOddsId !== result.matchOddsId) continue;
8457
+ waiting.delete(w);
8458
+ w.resolve(result);
8459
+ }
8460
+ },
8461
+ onHandle: (handle) => {
8462
+ detach();
8463
+ detach = () => {
8464
+ };
8465
+ if (!handle) {
8466
+ price = void 0;
8467
+ for (const w of [...waiting]) w.resolve(null);
8468
+ waiting.clear();
8469
+ if (delivered !== null) emit(null);
8470
+ return;
8471
+ }
8472
+ if (!host || !drawsLauncher) return;
8473
+ detach = attachTeaser(host, {
8474
+ tapAsk: handle.tapAsk,
8475
+ tapCta: handle.tapCta,
8476
+ tapTeaser: handle.tapTeaser,
8477
+ dismissTeaser: handle.dismissTeaser,
8478
+ teaserShown: handle.teaserShown,
8479
+ tapPrice: () => {
8480
+ if (!price) return Promise.resolve(null);
8481
+ const matchOddsId = price.matchOddsId;
8482
+ return new Promise((resolve) => {
8483
+ const w = { matchOddsId, resolve };
8484
+ waiting.add(w);
8485
+ if (!handle.tapPrice(matchOddsId)) {
8486
+ waiting.delete(w);
8487
+ resolve(null);
8488
+ }
8489
+ });
8490
+ }
8491
+ });
8492
+ }
8493
+ };
8494
+ }
8495
+
8376
8496
  // src/openTelemetry.ts
8377
8497
  import { useEffect as useEffect31, useRef as useRef26 } from "react";
8378
8498
  function useOpenTelemetry(log, isOpen) {
@@ -18978,7 +19098,7 @@ function SettingsSheet({ ui, onClose }) {
18978
19098
  ] }),
18979
19099
  /* @__PURE__ */ jsx161("div", { className: "ss-w-set-seg", role: "group", "aria-labelledby": "ss-w-set-odds", children: ODDS.map((f) => /* @__PURE__ */ jsx161("button", { type: "button", "aria-pressed": s.oddsFormat === f, onClick: () => s.setOddsFormat(f), children: t[f] }, f)) })
18980
19100
  ] }),
18981
- !s.themeLocked && /* @__PURE__ */ jsxs139("div", { className: "ss-w-set-row", children: [
19101
+ /* @__PURE__ */ jsxs139("div", { className: "ss-w-set-row", children: [
18982
19102
  /* @__PURE__ */ jsx161("div", { className: "ss-w-tool-label", id: "ss-w-set-theme", children: t.themeLabel }),
18983
19103
  /* @__PURE__ */ jsx161("div", { className: "ss-w-set-seg", role: "group", "aria-labelledby": "ss-w-set-theme", children: THEMES2.map((m) => /* @__PURE__ */ jsx161("button", { type: "button", "aria-pressed": s.theme === m, onClick: () => s.setTheme(m), children: t[m] }, m)) })
18984
19104
  ] })
@@ -19087,9 +19207,7 @@ function ChatPanel({ controller, ui, slip, onDashboardTap, monitor, discovery, s
19087
19207
  const focusAfterCloseRef = useRef49(null);
19088
19208
  const [tool, setTool] = useState88(null);
19089
19209
  const panelRef = useRef49(null);
19090
- const settings = useOddsSettings();
19091
19210
  const [settingsOpen, setSettingsOpen] = useState88(false);
19092
- const hasSettings = settings.oddsOffered || !settings.themeLocked;
19093
19211
  const openSettings = useCallback30(() => {
19094
19212
  setTool(null);
19095
19213
  setFavouritesOpen?.(false);
@@ -19156,7 +19274,7 @@ function ChatPanel({ controller, ui, slip, onDashboardTap, monitor, discovery, s
19156
19274
  closeFavourites();
19157
19275
  return true;
19158
19276
  }
19159
- if (settingsOpen && hasSettings) {
19277
+ if (settingsOpen) {
19160
19278
  closeSettings();
19161
19279
  return true;
19162
19280
  }
@@ -19191,7 +19309,7 @@ function ChatPanel({ controller, ui, slip, onDashboardTap, monitor, discovery, s
19191
19309
  canReset: state.messages.length > 0,
19192
19310
  newConversationLabel: ui.newConversation,
19193
19311
  moreOptionsLabel: ui.moreOptions,
19194
- onOpenSettings: hasSettings ? openSettings : void 0,
19312
+ onOpenSettings: openSettings,
19195
19313
  settingsLabel: ui.settings.title,
19196
19314
  onOpenFavourites: favouritesOffered ? openFavourites : void 0,
19197
19315
  favouritesLabel: ui.tabFavourites
@@ -19318,7 +19436,7 @@ function ChatPanel({ controller, ui, slip, onDashboardTap, monitor, discovery, s
19318
19436
  }
19319
19437
  )
19320
19438
  ] }),
19321
- settingsOpen && hasSettings ? /* @__PURE__ */ jsx162(SettingsSheet, { ui, onClose: closeSettings }) : null,
19439
+ settingsOpen ? /* @__PURE__ */ jsx162(SettingsSheet, { ui, onClose: closeSettings }) : null,
19322
19440
  favouritesOpen && favourites ? /* @__PURE__ */ jsx162(FavouritesSheet, { ui, controller: favourites.controller, sport: favourites.sport, sports: favourites.sports, onSportChange: favourites.onSportChange, onClose: closeFavourites }) : null
19323
19441
  ] });
19324
19442
  }
@@ -19333,11 +19451,11 @@ function HostEventsProvider({ value, children }) {
19333
19451
  var WIDGET_CSS = `.ss-w-root { all: revert; }
19334
19452
  .ss-w-root, .ss-w-root * { box-sizing: border-box; margin: 0; padding: 0; }
19335
19453
  .ss-w-root {
19336
- --ss-w-accent: #17936a;
19454
+ --ss-w-accent: var(--ss-w-brand-accent-light, #17936a);
19337
19455
  --ss-w-pill: var(--ss-w-pill-light, color-mix(in srgb, var(--ss-w-accent) 72%, #000)); --ss-w-on-accent: var(--ss-w-on-pill-light, #fff);
19338
- --ss-w-cta: #f5a623; --ss-w-cta-ink: #1b1300;
19339
- --ss-w-ink: #14181d; --ss-w-faint: #6b7580; --ss-w-line: #e4e8ec;
19340
- --ss-w-panel: #ffffff; --ss-w-bubble: #f3f5f7; --ss-w-nav: #0e1622;
19456
+ --ss-w-cta: var(--ss-w-brand-cta-light, #f5a623); --ss-w-cta-ink: #1b1300;
19457
+ --ss-w-ink: var(--ss-w-brand-ink-light, #14181d); --ss-w-faint: var(--ss-w-brand-faint-light, #6b7580); --ss-w-line: var(--ss-w-brand-line-light, #e4e8ec);
19458
+ --ss-w-panel: var(--ss-w-brand-surface-light, #ffffff); --ss-w-bubble: var(--ss-w-brand-bubble-light, #f3f5f7); --ss-w-nav: #0e1622;
19341
19459
  --ss-w-pos: #1aa563; --ss-w-neg: #e0524b; --ss-w-warn: #c07a00;
19342
19460
  --ss-w-home: #3a63a8; --ss-w-away: #c8102e; --ss-w-track: #e9edf1;
19343
19461
  --ss-w-correct: #1f9d55; --ss-w-wrong: #b9bbc2;
@@ -19347,29 +19465,29 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
19347
19465
  }
19348
19466
  @media (prefers-color-scheme: dark) {
19349
19467
  .ss-w-root[data-ss-w-theme="auto"] {
19350
- --ss-w-accent: #37c891; --ss-w-cta: #ffb638; --ss-w-cta-ink: #1b1300;
19468
+ --ss-w-accent: var(--ss-w-brand-accent-dark, #37c891); --ss-w-cta: var(--ss-w-brand-cta-dark, #ffb638); --ss-w-cta-ink: #1b1300;
19351
19469
  --ss-w-pill: var(--ss-w-pill-dark, var(--ss-w-accent)); --ss-w-on-accent: var(--ss-w-on-pill-dark, #06231a);
19352
- --ss-w-ink: #e8edf2; --ss-w-faint: #8b95a1;
19353
- --ss-w-line: #2a3441; --ss-w-panel: #141b24; --ss-w-bubble: #1e2732; --ss-w-nav: #0a0f16;
19470
+ --ss-w-ink: var(--ss-w-brand-ink-dark, #e8edf2); --ss-w-faint: var(--ss-w-brand-faint-dark, #8b95a1);
19471
+ --ss-w-line: var(--ss-w-brand-line-dark, #2a3441); --ss-w-panel: var(--ss-w-brand-surface-dark, #141b24); --ss-w-bubble: var(--ss-w-brand-bubble-dark, #1e2732); --ss-w-nav: #0a0f16;
19354
19472
  --ss-w-pos: #37c891; --ss-w-neg: #f0655d; --ss-w-warn: #e0a030;
19355
19473
  --ss-w-home: #5b83c8; --ss-w-away: #e8384f; --ss-w-track: #232d3a;
19356
19474
  --ss-w-correct: #37c86b; --ss-w-wrong: #3a3a41;
19357
19475
  }
19358
19476
  }
19359
19477
  .ss-w-root[data-ss-w-theme="dark"] {
19360
- --ss-w-accent: #37c891; --ss-w-cta: #ffb638; --ss-w-cta-ink: #1b1300;
19478
+ --ss-w-accent: var(--ss-w-brand-accent-dark, #37c891); --ss-w-cta: var(--ss-w-brand-cta-dark, #ffb638); --ss-w-cta-ink: #1b1300;
19361
19479
  --ss-w-pill: var(--ss-w-pill-dark, var(--ss-w-accent)); --ss-w-on-accent: var(--ss-w-on-pill-dark, #06231a);
19362
- --ss-w-ink: #e8edf2; --ss-w-faint: #8b95a1;
19363
- --ss-w-line: #2a3441; --ss-w-panel: #141b24; --ss-w-bubble: #1e2732; --ss-w-nav: #0a0f16;
19480
+ --ss-w-ink: var(--ss-w-brand-ink-dark, #e8edf2); --ss-w-faint: var(--ss-w-brand-faint-dark, #8b95a1);
19481
+ --ss-w-line: var(--ss-w-brand-line-dark, #2a3441); --ss-w-panel: var(--ss-w-brand-surface-dark, #141b24); --ss-w-bubble: var(--ss-w-brand-bubble-dark, #1e2732); --ss-w-nav: #0a0f16;
19364
19482
  --ss-w-pos: #37c891; --ss-w-neg: #f0655d; --ss-w-warn: #e0a030;
19365
19483
  --ss-w-home: #5b83c8; --ss-w-away: #e8384f; --ss-w-track: #232d3a;
19366
19484
  --ss-w-correct: #37c86b; --ss-w-wrong: #3a3a41;
19367
19485
  }
19368
19486
  .ss-w-root[data-ss-w-theme="light"] {
19369
- --ss-w-accent: #17936a; --ss-w-cta: #f5a623; --ss-w-cta-ink: #1b1300;
19487
+ --ss-w-accent: var(--ss-w-brand-accent-light, #17936a); --ss-w-cta: var(--ss-w-brand-cta-light, #f5a623); --ss-w-cta-ink: #1b1300;
19370
19488
  --ss-w-pill: var(--ss-w-pill-light, color-mix(in srgb, var(--ss-w-accent) 72%, #000)); --ss-w-on-accent: var(--ss-w-on-pill-light, #fff);
19371
- --ss-w-ink: #14181d; --ss-w-faint: #6b7580;
19372
- --ss-w-line: #e4e8ec; --ss-w-panel: #ffffff; --ss-w-bubble: #f3f5f7; --ss-w-nav: #0e1622;
19489
+ --ss-w-ink: var(--ss-w-brand-ink-light, #14181d); --ss-w-faint: var(--ss-w-brand-faint-light, #6b7580);
19490
+ --ss-w-line: var(--ss-w-brand-line-light, #e4e8ec); --ss-w-panel: var(--ss-w-brand-surface-light, #ffffff); --ss-w-bubble: var(--ss-w-brand-bubble-light, #f3f5f7); --ss-w-nav: #0e1622;
19373
19491
  --ss-w-home: #3a63a8; --ss-w-away: #c8102e; --ss-w-track: #e9edf1;
19374
19492
  --ss-w-correct: #1f9d55; --ss-w-wrong: #b9bbc2;
19375
19493
  }
@@ -22253,13 +22371,15 @@ var WIDGET_CSS = `.ss-w-root { all: revert; }
22253
22371
  // src/StatsWidget.tsx
22254
22372
  import { jsx as jsx164 } from "react/jsx-runtime";
22255
22373
  var NO_OWNER = {};
22256
- function buildClient(props) {
22374
+ function buildClient(props, onUnavailable) {
22257
22375
  try {
22258
22376
  if ("client" in props && props.client) {
22259
22377
  return { client: props.client, conversation: props.client.conversation() };
22260
22378
  }
22261
22379
  const cfg = props.config;
22262
- const client = new StatsWidgetClient(toClientOptions(cfg));
22380
+ const options = toClientOptions(cfg);
22381
+ const base = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
22382
+ const client = new StatsWidgetClient({ ...options, fetch: observingFetch(base, onUnavailable) });
22263
22383
  return { client, conversation: client.conversation(toUserContext(cfg)) };
22264
22384
  } catch (err) {
22265
22385
  console.error("[StatsWidget] failed to initialize:", err instanceof Error ? err.message : err);
@@ -22277,7 +22397,14 @@ function injectStyles(root) {
22277
22397
  function StatsWidget(props) {
22278
22398
  const injectedClient = "client" in props ? props.client : void 0;
22279
22399
  const cfg = props.config;
22280
- const built = useMemo17(() => buildClient(props), [injectedClient, cfg?.operatorId, cfg?.publicKey, cfg?.baseUrl]);
22400
+ const onUnavailableRef = useRef50(cfg?.onUnavailable);
22401
+ onUnavailableRef.current = cfg?.onUnavailable;
22402
+ const built = useMemo17(() => buildClient(props, (reason) => {
22403
+ try {
22404
+ onUnavailableRef.current?.(reason);
22405
+ } catch {
22406
+ }
22407
+ }), [injectedClient, cfg?.operatorId, cfg?.publicKey, cfg?.baseUrl, cfg?.userContext?.operatorUserId, cfg?.userContext?.anonymousUserId]);
22281
22408
  const trackingRef = useRef50({ envelope: { operatorId: "", widgetVersion: WIDGET_REACT_VERSION } });
22282
22409
  const track = useMemo17(() => createTracker(() => trackingRef.current), []);
22283
22410
  const eventTextRef = useRef50(false);
@@ -22304,7 +22431,7 @@ function StatsWidget(props) {
22304
22431
  }, []);
22305
22432
  const language = injectedClient ? void 0 : hostTag(cfg);
22306
22433
  const threadLanguage = familyOf(language);
22307
- const convStorageKey = `ss-w-conv:${cfg?.operatorId ?? ""}:${cfg?.userContext?.operatorUserId ?? "anon"}${threadLanguage ? `:lang=${threadLanguage}` : ""}`;
22434
+ const convStorageKey = `ss-w-conv:${cfg?.operatorId ?? ""}:${cfg?.userContext?.operatorUserId ?? "anon"}${cfg?.userContext?.anonymousUserId ? `:a=${cfg.userContext.anonymousUserId}` : ""}${threadLanguage ? `:lang=${threadLanguage}` : ""}`;
22308
22435
  const sportScope = useMemo17(
22309
22436
  () => ({ operatorId: cfg?.operatorId ?? "", operatorUserId: cfg?.userContext?.operatorUserId, anonymousUserId: cfg?.userContext?.anonymousUserId }),
22310
22437
  [cfg?.operatorId, cfg?.userContext?.operatorUserId, cfg?.userContext?.anonymousUserId]
@@ -22546,8 +22673,13 @@ function StatsWidget(props) {
22546
22673
  const bubblePrice = !stringsPending && controller.state.popupText && bubble?.price && bubble.matchId ? { matchId: bubble.matchId, price: bubble.price, sport: bubble.sport } : null;
22547
22674
  const bubbleGame = !stringsPending && controller.state.popupText && bubble?.game ? instantMs(bubble.startsAtUtc) === null ? bubble.game : ui.v2GameLine(bubble.game, bubble.startsAtUtc) : void 0;
22548
22675
  const bubbleCta = controller.state.popupText ? controller.state.greetingBubble?.cta ?? null : null;
22676
+ const onTeaserRef = useRef50(cfg?.onTeaser);
22677
+ onTeaserRef.current = cfg?.onTeaser;
22678
+ const wantsTeaser = cfg?.launcher === false || cfg?.onTeaser !== void 0;
22679
+ const webBinding = useMemo17(() => wantsTeaser ? webTeaserBinding(props.host, (teaser2) => onTeaserRef.current?.(teaser2), cfg?.launcher === false) : void 0, [wantsTeaser, props.host, cfg?.launcher]);
22680
+ const hostDrawsLauncher = props.mobile !== void 0 || cfg?.launcher === false;
22549
22681
  const mobile = useMobileBinding({
22550
- binding: props.mobile,
22682
+ binding: props.mobile ?? webBinding,
22551
22683
  panelOpen,
22552
22684
  popupText: controller.state.popupText,
22553
22685
  cta: bubbleCta,
@@ -22564,10 +22696,10 @@ function StatsWidget(props) {
22564
22696
  close: controller.close,
22565
22697
  dismissPopup: () => dismissPopupRef.current()
22566
22698
  });
22567
- const dismissPopup = usePopupTelemetry(logger, panelOpen, controller.state.popupText, controller.dismissPopup, mobile.confirmedShown);
22699
+ const dismissPopup = usePopupTelemetry(logger, panelOpen, controller.state.popupText, controller.dismissPopup, hostDrawsLauncher ? mobile.confirmedShown : void 0);
22568
22700
  dismissPopupRef.current = dismissPopup;
22569
22701
  const greetingMeta = latestGreetingMeta(controller.state.messages);
22570
- useBubbleGreetingShown(logger, logger ?? NO_OWNER, controller.state.popupText, greetingMeta, mobile.confirmedShown);
22702
+ useBubbleGreetingShown(logger, logger ?? NO_OWNER, controller.state.popupText, greetingMeta, hostDrawsLauncher ? mobile.confirmedShown : void 0);
22571
22703
  const [highlight, setHighlight] = useState89(null);
22572
22704
  const clearHighlight = useCallback31(() => setHighlight(null), []);
22573
22705
  useEffect59(() => {
@@ -22693,10 +22825,10 @@ function StatsWidget(props) {
22693
22825
  favouritesEnabled: favouritesEnabled && clubFixturesResult.tabReady && !clubFixturesResult.enabled,
22694
22826
  favourites: { controller: favourites, sport: favSport, sports: favSports, onSportChange: setFavSportPick, open: favouritesOpen, onOpenChange: setFavouritesOpen },
22695
22827
  builder: { options: builderOptions, sport: builderSport, onSportChange: setBuilderSportPick, onCoolOff: onBuilderCoolOff, tabs: monitor },
22696
- onCloseRequested: mobile.onCloseRequested,
22697
- onRegisterBack: mobile.onRegisterBack
22828
+ onCloseRequested: props.mobile ? mobile.onCloseRequested : void 0,
22829
+ onRegisterBack: props.mobile ? mobile.onRegisterBack : void 0
22698
22830
  }
22699
- ) }) }) : props.mobile ? bubblePrice && mobile.onRegisterPrice && mobile.onPriceResult && mobile.priceInFlight ? /* @__PURE__ */ jsx164(
22831
+ ) }) }) : hostDrawsLauncher ? bubblePrice && mobile.onRegisterPrice && mobile.onPriceResult && mobile.priceInFlight ? /* @__PURE__ */ jsx164(
22700
22832
  MobileBubblePrice,
22701
22833
  {
22702
22834
  matchId: bubblePrice.matchId,