@sensiblestats/widget-react 0.121.0 → 0.122.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.js CHANGED
@@ -240,6 +240,8 @@ var BUNDLED_EN_GB = {
240
240
  "widget.v8GamesGroup": "Games",
241
241
  "widget.v8NoGame": "No game in the window",
242
242
  "widget.v8Ask": "Ask",
243
+ "widget.actionContinue": "Continue",
244
+ "widget.countdownTitle": "Kick-off in",
243
245
  "widget.v8NoLine": "No line posted yet. Lines usually post on the day.",
244
246
  "widget.v8FollowWho": "Who do you follow?",
245
247
  "widget.tabLeaderboard": "Leaderboard",
@@ -716,6 +718,26 @@ var BUNDLED_EN_GB = {
716
718
  "widget.code.positionShort.Defender": "DF",
717
719
  "widget.code.positionShort.Midfielder": "MF",
718
720
  "widget.code.positionShort.Attacker": "FW",
721
+ "widget.code.positionShort.GK": "GK",
722
+ "widget.code.positionShort.DEF": "DEF",
723
+ "widget.code.positionShort.CB": "CB",
724
+ "widget.code.positionShort.LB": "LB",
725
+ "widget.code.positionShort.RB": "RB",
726
+ "widget.code.positionShort.LWB": "LWB",
727
+ "widget.code.positionShort.RWB": "RWB",
728
+ "widget.code.positionShort.SW": "SW",
729
+ "widget.code.positionShort.MID": "MID",
730
+ "widget.code.positionShort.DM": "DM",
731
+ "widget.code.positionShort.CM": "CM",
732
+ "widget.code.positionShort.AM": "AM",
733
+ "widget.code.positionShort.LM": "LM",
734
+ "widget.code.positionShort.RM": "RM",
735
+ "widget.code.positionShort.LW": "LW",
736
+ "widget.code.positionShort.RW": "RW",
737
+ "widget.code.positionShort.FWD": "FWD",
738
+ "widget.code.positionShort.ST": "ST",
739
+ "widget.code.positionShort.SS": "SS",
740
+ "widget.code.positionShort.CF": "CF",
719
741
  "widget.code.settle.over": "Over",
720
742
  "widget.code.settle.under": "Under",
721
743
  "widget.code.settle.push": "Push",
@@ -850,6 +872,7 @@ function formDay(etDate, anchorEtDate, tag2) {
850
872
  // src/strings/build.ts
851
873
  var LEG_COUNTS = [2, 3, 4, 5, 6, 7, 8, 9, 10];
852
874
  var POSITIONS = ["Goalkeeper", "Defender", "Midfielder", "Attacker"];
875
+ var TILE_POSITION_CODES = ["GK", "DEF", "CB", "LB", "RB", "LWB", "RWB", "SW", "MID", "DM", "CM", "AM", "LM", "RM", "LW", "RW", "FWD", "ST", "SS", "CF"];
853
876
  var CODE_SETS = {
854
877
  result: ["W", "D", "L"],
855
878
  gridAbbrev: ["Goalkeeper", "Defender", "Midfielder", "Forward"],
@@ -871,7 +894,7 @@ var CODE_SETS = {
871
894
  ],
872
895
  groupNoun: ["G", "D", "M", "F"],
873
896
  position: POSITIONS,
874
- positionShort: POSITIONS,
897
+ positionShort: [...POSITIONS, ...TILE_POSITION_CODES],
875
898
  foot: ["right", "left", "both"],
876
899
  settle: ["over", "under", "push", "void", "yes", "no"],
877
900
  window: ["1q", "first3min"],
@@ -1071,6 +1094,7 @@ var ROW_LEAVES = {
1071
1094
  var CODE_LEAVES = [
1072
1095
  ["venue", "venue", { home: "home", away: "away", short: "short" }],
1073
1096
  ["positionGroupShort", "positionShort", { Goalkeeper: "Goalkeeper", Defender: "Defender", Midfielder: "Midfielder", Attacker: "Attacker" }],
1097
+ ["positionTile", "positionShort", Object.fromEntries(TILE_POSITION_CODES.map((c) => [c, c]))],
1074
1098
  ["sport", "sport", { football: "football", nba: "nba", nfl: "nfl" }],
1075
1099
  ["resultLetter", "result", { W: "W", D: "D", L: "L" }],
1076
1100
  ["perfGroupNoun", "groupNoun", { G: "G", D: "D", M: "M", F: "F" }],
@@ -1124,7 +1148,7 @@ function parseOddsFormat(value) {
1124
1148
  }
1125
1149
 
1126
1150
  // src/version.generated.ts
1127
- var WIDGET_REACT_VERSION = "0.121.0";
1151
+ var WIDGET_REACT_VERSION = "0.122.1";
1128
1152
 
1129
1153
  // src/config.ts
1130
1154
  function hostTag(cfg) {
@@ -1320,6 +1344,7 @@ function normalizeUi(cfg, loaded) {
1320
1344
  sportFootball: strings.sportFootball,
1321
1345
  venue: strings.venue,
1322
1346
  positionGroupShort: strings.positionGroupShort,
1347
+ positionTile: strings.positionTile,
1323
1348
  sport: strings.sport,
1324
1349
  liveCountLabel: strings.liveCountLabel,
1325
1350
  myLeagues: strings.myLeagues,
@@ -1455,6 +1480,8 @@ function normalizeUi(cfg, loaded) {
1455
1480
  v8NoPrices: strings.v8NoPrices,
1456
1481
  v8NoGame: strings.v8NoGame,
1457
1482
  v8Ask: strings.v8Ask,
1483
+ actionContinue: strings.actionContinue,
1484
+ countdownTitle: strings.countdownTitle,
1458
1485
  v8NoLine: strings.v8NoLine,
1459
1486
  v8Hits: strings.v8Hits,
1460
1487
  v8FollowWho: strings.v8FollowWho,
@@ -1498,6 +1525,21 @@ function toUserContext(cfg) {
1498
1525
  import { useEffect, useRef, useState } from "react";
1499
1526
  var BUNDLED = { tag: BUNDLED_TAG, clock: BUNDLED_CLOCK, version: "", strings: BUNDLED_EN_GB };
1500
1527
  var RETRY_MS = [1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
1528
+ var SLOW_RETRY_MS = 3e5;
1529
+ var MAX_RETRY_AFTER_MS = 3e5;
1530
+ function isPermanent(err) {
1531
+ const status2 = err?.status;
1532
+ return typeof status2 === "number" && status2 >= 400 && status2 < 500 && status2 !== 429;
1533
+ }
1534
+ function holdsRetryAfter(err) {
1535
+ const e = err;
1536
+ return e?.status === 429 && typeof e.retryAfter === "number" && e.retryAfter >= 0;
1537
+ }
1538
+ function retryDelay(err, n) {
1539
+ const after = err;
1540
+ if (after?.status === 429 && typeof after.retryAfter === "number" && after.retryAfter >= 0) return Math.min(after.retryAfter * 1e3, MAX_RETRY_AFTER_MS);
1541
+ return n < RETRY_MS.length ? RETRY_MS[n] : SLOW_RETRY_MS;
1542
+ }
1501
1543
  var cacheKey = (operatorId, tag2) => `ss-w-strings:${operatorId}:${tag2 || "_"}`;
1502
1544
  function readCache(key) {
1503
1545
  try {
@@ -1534,15 +1576,21 @@ function useWidgetStrings(cfg, source) {
1534
1576
  useEffect(() => {
1535
1577
  let cancelled = false;
1536
1578
  let timer;
1579
+ let inFlight2 = false;
1580
+ let waitingFor = 0;
1581
+ let holdUntil = 0;
1537
1582
  const cached = readCache(key);
1538
1583
  const attempt = (n) => {
1539
1584
  if (cancelled) return;
1585
+ timer = void 0;
1586
+ inFlight2 = true;
1540
1587
  const src = sourceRef.current;
1541
1588
  Promise.resolve().then(() => {
1542
1589
  if (cancelled) throw new Error("unmounted");
1543
1590
  if (!src) throw new Error("no client");
1544
1591
  return src.getWidgetStrings(tag2, cached?.version);
1545
1592
  }).then((res) => {
1593
+ inFlight2 = false;
1546
1594
  if (cancelled) return;
1547
1595
  if (res.strings) {
1548
1596
  const next = { tag: res.tag, clock: res.clock, version: res.version, strings: res.strings };
@@ -1553,19 +1601,40 @@ function useWidgetStrings(cfg, source) {
1553
1601
  } else {
1554
1602
  throw new Error("strings response carried no rows");
1555
1603
  }
1556
- }).catch(() => {
1604
+ }).catch((err) => {
1605
+ inFlight2 = false;
1557
1606
  if (cancelled || cached) return;
1558
1607
  if (isEnglish(tag2)) {
1559
1608
  setHeld({ key, state: "fallback", strings: BUNDLED });
1560
1609
  return;
1561
1610
  }
1562
- setHeld({ key, state: "retrying" });
1563
- timer = setTimeout(() => attempt(n + 1), RETRY_MS[Math.min(n, RETRY_MS.length - 1)]);
1611
+ if (isPermanent(err)) {
1612
+ setHeld({ key, state: "unavailable" });
1613
+ return;
1614
+ }
1615
+ setHeld({ key, state: n >= RETRY_MS.length ? "unavailable" : "retrying" });
1616
+ waitingFor = n + 1;
1617
+ const delay = retryDelay(err, n);
1618
+ holdUntil = holdsRetryAfter(err) ? Date.now() + delay : 0;
1619
+ timer = setTimeout(() => attempt(waitingFor), delay);
1564
1620
  });
1565
1621
  };
1622
+ const rearm = () => {
1623
+ if (cancelled || inFlight2 || timer === void 0) return;
1624
+ if (waitingFor <= RETRY_MS.length || Date.now() < holdUntil) return;
1625
+ clearTimeout(timer);
1626
+ attempt(waitingFor);
1627
+ };
1628
+ const onVisible = () => {
1629
+ if (document.visibilityState === "visible") rearm();
1630
+ };
1631
+ window.addEventListener("online", rearm);
1632
+ document.addEventListener("visibilitychange", onVisible);
1566
1633
  attempt(0);
1567
1634
  return () => {
1568
1635
  cancelled = true;
1636
+ window.removeEventListener("online", rearm);
1637
+ document.removeEventListener("visibilitychange", onVisible);
1569
1638
  if (timer !== void 0) clearTimeout(timer);
1570
1639
  };
1571
1640
  }, [key, tag2, source !== null]);
@@ -1666,7 +1735,7 @@ function toCardVM(card) {
1666
1735
  };
1667
1736
  }
1668
1737
  function toActionVM(action) {
1669
- const label = str(action.actionLabel) ?? str(action.label) ?? str(action.text) ?? str(action.title) ?? "Continue";
1738
+ const label = str(action.actionLabel) ?? str(action.label) ?? str(action.text) ?? str(action.title) ?? "";
1670
1739
  const actionId = str(action.actionId) ?? str(action.id);
1671
1740
  const actionRef = str(action.actionRef);
1672
1741
  const message = str(action.actionValue) ?? str(action.message) ?? str(action.query) ?? label;
@@ -8655,10 +8724,13 @@ function OddsMovementCardList({ cards, ui, monitor }) {
8655
8724
 
8656
8725
  // src/components/ActionButtons.tsx
8657
8726
  import { Fragment as Fragment8, jsx as jsx40, jsxs as jsxs36 } from "react/jsx-runtime";
8658
- function ActionButtons({ actions, loading, disabled, onAct }) {
8727
+ function ActionButtons({ actions, ui, loading, disabled, onAct }) {
8659
8728
  if (actions.length === 0 && !loading) return null;
8660
8729
  return /* @__PURE__ */ jsxs36("div", { className: "ss-w-actions", children: [
8661
- actions.map((a, i) => /* @__PURE__ */ jsx40("button", { type: "button", className: "ss-w-abtn", disabled, onClick: () => onAct(a), children: a.label }, `${a.label}-${i}`)),
8730
+ actions.map((a, i) => {
8731
+ const label = a.label || ui.actionContinue;
8732
+ return /* @__PURE__ */ jsx40("button", { type: "button", className: "ss-w-abtn", disabled, onClick: () => onAct(a.label ? a : { ...a, label, message: a.message || label }), children: label }, `${label}-${i}`);
8733
+ }),
8662
8734
  actions.length === 0 && loading ? /* @__PURE__ */ jsxs36(Fragment8, { children: [
8663
8735
  /* @__PURE__ */ jsx40("span", { className: "ss-w-abtn-shimmer" }),
8664
8736
  /* @__PURE__ */ jsx40("span", { className: "ss-w-abtn-shimmer" })
@@ -8773,7 +8845,7 @@ function remainingSegments(kickoffUnix, nowMs, withSeconds) {
8773
8845
  if (withSeconds) segs.push({ value: pad2(seconds), unit: "s" });
8774
8846
  return segs;
8775
8847
  }
8776
- function CountdownCard({ card }) {
8848
+ function CountdownCard({ card, ui }) {
8777
8849
  const { data } = card;
8778
8850
  const unitLabel = { d: data.daysUnit, h: data.hoursUnit, m: data.minutesUnit, s: data.secondsUnit };
8779
8851
  const [nowMs, setNowMs] = useState36(() => Date.now());
@@ -8788,7 +8860,7 @@ function CountdownCard({ card }) {
8788
8860
  }, [reduced, withinDay]);
8789
8861
  const segments = remainingSegments(data.kickoffUnix, nowMs, withinDay && !reduced);
8790
8862
  return /* @__PURE__ */ jsx42("div", { className: "ss-w-fandash-card ss-w-fandash-countdown", children: /* @__PURE__ */ jsxs38("div", { className: "ss-w-fandash-countdown-top", children: [
8791
- /* @__PURE__ */ jsx42("span", { className: "ss-w-fandash-eyebrow", children: card.title ?? "Kick-off in" }),
8863
+ /* @__PURE__ */ jsx42("span", { className: "ss-w-fandash-eyebrow", children: card.title ?? ui.countdownTitle }),
8792
8864
  segments ? /* @__PURE__ */ jsx42("span", { className: "ss-w-fandash-countdown-clock", children: segments.map((s, i) => /* @__PURE__ */ jsxs38(Fragment10, { children: [
8793
8865
  i > 0 ? /* @__PURE__ */ jsx42("span", { className: "ss-w-fandash-countdown-colon", children: ":" }) : null,
8794
8866
  /* @__PURE__ */ jsxs38("span", { className: "ss-w-fandash-countdown-seg", children: [
@@ -9433,7 +9505,7 @@ function FanDashboardCard({ card, onTap, ui, goalEvents }) {
9433
9505
  case "fixture":
9434
9506
  return /* @__PURE__ */ jsx62(FixtureCard, { card, ui });
9435
9507
  case "countdown":
9436
- return /* @__PURE__ */ jsx62(CountdownCard, { card });
9508
+ return /* @__PURE__ */ jsx62(CountdownCard, { card, ui });
9437
9509
  case "injuries":
9438
9510
  return /* @__PURE__ */ jsx62(InjuriesCard, { card, ui });
9439
9511
  case "reasonToBet":
@@ -9500,7 +9572,7 @@ function ChatMessage({ message, disabled, onAct, onTap, ui, slip, monitor }) {
9500
9572
  /* @__PURE__ */ jsx63(ComboCardList, { cards: message.comboCards ?? [], ui, slip, monitor }),
9501
9573
  compact ? /* @__PURE__ */ jsx63(CompactOddsList, { list: compact, ui, slip, monitor }) : /* @__PURE__ */ jsx63(MarketOddsCardList, { cards: message.marketOdds, ui, slip, monitor }),
9502
9574
  /* @__PURE__ */ jsx63(OddsMovementCardList, { cards: message.oddsMovement, ui, monitor }),
9503
- /* @__PURE__ */ jsx63(ActionButtons, { actions, loading: false, disabled, onAct })
9575
+ /* @__PURE__ */ jsx63(ActionButtons, { actions, ui, loading: false, disabled, onAct })
9504
9576
  ] });
9505
9577
  }
9506
9578
 
@@ -9575,7 +9647,7 @@ function MessageList({ controller, ui, slip, onDashboardTap, monitor }) {
9575
9647
  },
9576
9648
  m.id
9577
9649
  )),
9578
- state.isStreaming && state.actionsLoading ? /* @__PURE__ */ jsx65(ActionButtons, { actions: [], loading: true, onAct: () => {
9650
+ state.isStreaming && state.actionsLoading ? /* @__PURE__ */ jsx65(ActionButtons, { actions: [], ui, loading: true, onAct: () => {
9579
9651
  } }) : null,
9580
9652
  state.status ? /* @__PURE__ */ jsx65("div", { className: "ss-w-status", children: state.status }) : null,
9581
9653
  state.error ? /* @__PURE__ */ jsxs60("div", { className: "ss-w-error", role: "alert", children: [
@@ -12784,7 +12856,7 @@ function AnswerTray({ id, label, placeholder, optionsLabel, options, query, onQu
12784
12856
  }
12785
12857
 
12786
12858
  // src/components/games/positionCodes.ts
12787
- var POSITION_SHORT = {
12859
+ var POSITION_NAME_TO_CODE = {
12788
12860
  goalkeeper: "GK",
12789
12861
  keeper: "GK",
12790
12862
  defender: "DEF",
@@ -12811,11 +12883,18 @@ var POSITION_SHORT = {
12811
12883
  forward: "FWD",
12812
12884
  attacker: "FWD",
12813
12885
  striker: "ST",
12886
+ "secondary striker": "SS",
12814
12887
  "second striker": "SS",
12815
12888
  "centre forward": "CF",
12816
12889
  "center forward": "CF",
12817
12890
  "centre-forward": "CF"
12818
12891
  };
12892
+ function tilePosition(tiles, value) {
12893
+ const code = POSITION_NAME_TO_CODE[value.trim().toLowerCase()];
12894
+ if (code) return tiles[code] || code;
12895
+ if (value.length <= 3) return value.toUpperCase();
12896
+ return value.split(/[\s-]+/).filter(Boolean).map((w) => (w[0] ?? "").toUpperCase()).join("").slice(0, 3);
12897
+ }
12819
12898
 
12820
12899
  // src/components/games/ui/FooterBar.tsx
12821
12900
  import { jsx as jsx105 } from "react/jsx-runtime";
@@ -12894,22 +12973,16 @@ function directionArrow(v) {
12894
12973
  if (v.direction === "down") return "\u25BC";
12895
12974
  return "";
12896
12975
  }
12897
- function shortPosition(value) {
12898
- const mapped = POSITION_SHORT[value.trim().toLowerCase()];
12899
- if (mapped) return mapped;
12900
- if (value.length <= 3) return value.toUpperCase();
12901
- return value.split(/[\s-]+/).filter(Boolean).map((w) => (w[0] ?? "").toUpperCase()).join("").slice(0, 3);
12902
- }
12903
- function tileFace(key, v) {
12976
+ function tileFace(key, v, tiles) {
12904
12977
  if (!v.value) return verdictGlyph(v);
12905
12978
  if (key === "nationality") return nationalityFlag(v.value);
12906
- if (key === "position") return shortPosition(v.value);
12979
+ if (key === "position") return tilePosition(tiles, v.value);
12907
12980
  return v.value;
12908
12981
  }
12909
- function deriveKnownAttributes(guesses, keys) {
12982
+ function deriveKnownAttributes(guesses, keys, tiles) {
12910
12983
  return keys.map((key) => {
12911
12984
  const exact = guesses.find((g) => g[key].verdict === "exact");
12912
- if (exact) return { key, state: "known", text: tileFace(key, exact[key]) };
12985
+ if (exact) return { key, state: "known", text: tileFace(key, exact[key], tiles) };
12913
12986
  if (!NUMERIC_KEYS.has(key)) return { key, state: "unknown", text: "?" };
12914
12987
  let maxUp = null;
12915
12988
  let minDown = null;
@@ -12973,7 +13046,7 @@ function MysteryTigerGame({
12973
13046
  ] }) });
12974
13047
  const segments = Array.from({ length: totalGuesses }, (_, i) => i < guessesUsed ? "done" : i === guessesUsed ? "current" : "todo");
12975
13048
  const cols = { gridTemplateColumns: `minmax(0, 1fr) repeat(${keys.length}, 42px)` };
12976
- const known = deriveKnownAttributes(guessResults, keys);
13049
+ const known = deriveKnownAttributes(guessResults, keys, ui.positionTile);
12977
13050
  return /* @__PURE__ */ jsxs100("div", { className: "ss-g-screen ss-g-mt", "data-game": "mystery-tiger", "data-testid": "game-screen-mystery-tiger", children: [
12978
13051
  /* @__PURE__ */ jsx110(
12979
13052
  GameHeader,
@@ -13027,7 +13100,7 @@ function MysteryTigerGame({
13027
13100
  "data-verdict": v.verdict,
13028
13101
  "aria-label": `${t.labels[key]}: ${v.value ?? v.verdict}${v.direction ? ` ${v.direction}` : ""}`,
13029
13102
  children: [
13030
- /* @__PURE__ */ jsx110("span", { className: "ss-g-mt-cell-v", "aria-hidden": "true", children: tileFace(key, v) }),
13103
+ /* @__PURE__ */ jsx110("span", { className: "ss-g-mt-cell-v", "aria-hidden": "true", children: tileFace(key, v, ui.positionTile) }),
13031
13104
  arrow && /* @__PURE__ */ jsx110("span", { className: "ss-g-mt-cell-dir", "aria-hidden": "true", children: arrow })
13032
13105
  ]
13033
13106
  },
@@ -19209,8 +19282,8 @@ function StatsWidget(props) {
19209
19282
  [built, operatorUserId, anonymousUserId]
19210
19283
  );
19211
19284
  const getStates = useCallback27(
19212
- (matchIds, nbaGameIds, nflGameIds) => built ? built.conversation.getStates(matchIds, nbaGameIds, nflGameIds) : Promise.resolve(null),
19213
- [built]
19285
+ (matchIds, nbaGameIds, nflGameIds) => built ? built.conversation.getStates(matchIds, nbaGameIds, nflGameIds, requestTag) : Promise.resolve(null),
19286
+ [built, requestTag]
19214
19287
  );
19215
19288
  const pinnedMatchIds = useMemo13(
19216
19289
  () => footballMatchPinIds(monitor.pins),
@@ -19426,10 +19499,10 @@ function StatsWidget(props) {
19426
19499
  };
19427
19500
  }, [logger]);
19428
19501
  useEffect50(() => {
19429
- if (!built || !ui.injectStyles) return;
19502
+ if (!built || !ui.injectStyles || widgetStrings.state === "unavailable") return;
19430
19503
  const node = rootRef.current?.getRootNode();
19431
19504
  if (node) injectStyles(node);
19432
- }, [built, ui.injectStyles]);
19505
+ }, [built, ui.injectStyles, widgetStrings.state]);
19433
19506
  const holds = useSessionHolds();
19434
19507
  const builderConversation = built?.conversation ?? null;
19435
19508
  const builderMemory = useMemo13(() => createBuilderMemory(), [builderConversation, controller.state.threadEpoch]);
@@ -19444,7 +19517,7 @@ function StatsWidget(props) {
19444
19517
  holds,
19445
19518
  memory: builderMemory
19446
19519
  }), [favouritesEnabled, monitor.enabled, clubFixturesResult.settled, clubFixturesResult.tabReady, clubFixturesResult.enabled, monitor.setActiveTab, favourites, built, holds, builderMemory]);
19447
- if (!built) return null;
19520
+ if (!built || widgetStrings.state === "unavailable") return null;
19448
19521
  const attrs = themeAttrs(ui, oddsSettings.userTheme);
19449
19522
  return /* @__PURE__ */ jsx146(EventLogContext.Provider, { value: logger, children: /* @__PURE__ */ jsx146(TrackingContext.Provider, { value: track, children: /* @__PURE__ */ jsx146(SportScopeContext.Provider, { value: sportScope, children: /* @__PURE__ */ jsx146(OddsSettingsContext.Provider, { value: oddsSettings, children: /* @__PURE__ */ jsx146(HostEventsProvider, { value: hostEvents, children: /* @__PURE__ */ jsx146("div", { ref: rootRef, className: "ss-w-root", "data-ss-w-theme": attrs["data-ss-w-theme"], "data-ss-w-pos": attrs["data-ss-w-pos"], style: attrs.style, children: panelOpen ? /* @__PURE__ */ jsx146(PersonalGreetingContext.Provider, { value: personalGreeting, children: /* @__PURE__ */ jsx146(
19450
19523
  ChatPanel,