@sensiblestats/widget-react 0.48.0 → 0.48.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
@@ -1511,43 +1511,8 @@ function dueMatchIds(groups, states, nowMs) {
1511
1511
  return [...due];
1512
1512
  }
1513
1513
 
1514
- // src/liveClock.ts
1515
- var STALE_READING_MS = 5 * 6e4;
1516
- function parseMinute(label) {
1517
- if (!label) return null;
1518
- const plus = /^(\d+)\+(\d+)'$/.exec(label);
1519
- if (plus) return Number(plus[1]) + Number(plus[2]);
1520
- const plain = /^(\d+)'$/.exec(label);
1521
- return plain ? Number(plain[1]) : null;
1522
- }
1523
- function readingAgeMs(state, nowMs) {
1524
- if (!state?.stateAsOfUtc) return null;
1525
- const t = Date.parse(state.stateAsOfUtc);
1526
- return Number.isNaN(t) ? null : Math.max(0, nowMs - t);
1527
- }
1528
- function isReadingStale(state, nowMs) {
1529
- if (state?.isHalfTime) return false;
1530
- const age = readingAgeMs(state, nowMs);
1531
- return age !== null && age > STALE_READING_MS;
1532
- }
1533
- function displayMinute(state, nowMs) {
1534
- if (!state || state.phase !== "live") return null;
1535
- if (state.isHalfTime) return null;
1536
- if (isReadingStale(state, nowMs)) return null;
1537
- const base = parseMinute(state.minuteLabel);
1538
- if (base === null) return null;
1539
- const age = readingAgeMs(state, nowMs);
1540
- if (age === null) return state.minuteLabel ?? null;
1541
- const advanced = base + Math.floor(age / 6e4);
1542
- return `${advanced}'`;
1543
- }
1544
- function isTreatedLive(state, pollStale, nowMs) {
1545
- return state?.phase === "live" && !pollStale && !isReadingStale(state, nowMs);
1546
- }
1547
-
1548
1514
  // src/useMatchDiscovery.ts
1549
1515
  var POLL_MS = 6e4;
1550
- var CLOCK_MS = 1e4;
1551
1516
  var ROLLOVER_CHECK_MS = 6e4;
1552
1517
  var STALE_AFTER_FAILURES = 2;
1553
1518
  function localDateOf(now) {
@@ -1560,7 +1525,6 @@ function useMatchDiscovery(opts) {
1560
1525
  const [groups, setGroups] = useState2([]);
1561
1526
  const [states, setStates] = useState2({});
1562
1527
  const [failures, setFailures] = useState2(0);
1563
- const [nowMs, setNowMs] = useState2(() => Date.now());
1564
1528
  const [expanded, setExpanded] = useState2({});
1565
1529
  const [touched, setTouched] = useState2({});
1566
1530
  const groupsRef = useRef4(groups);
@@ -1638,21 +1602,16 @@ function useMatchDiscovery(opts) {
1638
1602
  }, POLL_MS);
1639
1603
  return () => clearInterval(id);
1640
1604
  }, [opts.isOpen, tick, groups]);
1641
- useEffect4(() => {
1642
- if (!opts.isOpen) return;
1643
- const id = setInterval(() => setNowMs(Date.now()), CLOCK_MS);
1644
- return () => clearInterval(id);
1645
- }, [opts.isOpen]);
1646
1605
  const stale = failures >= STALE_AFTER_FAILURES;
1647
1606
  const liveCount = useMemo2(
1648
- () => stale ? 0 : Object.values(states).filter((s) => s.phase === "live" && !isReadingStale(s, nowMs)).length,
1649
- [states, stale, nowMs]
1607
+ () => stale ? 0 : Object.values(states).filter((s) => s.phase === "live").length,
1608
+ [states, stale]
1650
1609
  );
1651
1610
  const toggleGroup = useCallback3((competitionId) => {
1652
1611
  setTouched((prev) => ({ ...prev, [competitionId]: true }));
1653
1612
  setExpanded((prev) => ({ ...prev, [competitionId]: !prev[competitionId] }));
1654
1613
  }, []);
1655
- return { groups, states, nowMs, liveCount, stale, expanded, toggleGroup, _tick: tick };
1614
+ return { groups, states, liveCount, stale, expanded, toggleGroup, _tick: tick };
1656
1615
  }
1657
1616
 
1658
1617
  // src/eventLogContext.ts
@@ -3010,7 +2969,7 @@ function computeDisplayMinute(minute, clockRunning, receivedAtMs) {
3010
2969
  return minute + Math.min(Math.max(0, elapsedMinutes), MAX_LIVE_TICK_MINUTES);
3011
2970
  }
3012
2971
  function useLiveClock(minute, clockRunning, receivedAtMs) {
3013
- const [displayMinute2, setDisplayMinute] = useState15(
2972
+ const [displayMinute, setDisplayMinute] = useState15(
3014
2973
  () => computeDisplayMinute(minute, clockRunning, receivedAtMs)
3015
2974
  );
3016
2975
  useEffect9(() => {
@@ -3021,7 +2980,7 @@ function useLiveClock(minute, clockRunning, receivedAtMs) {
3021
2980
  }, TICK_MS);
3022
2981
  return () => window.clearInterval(id);
3023
2982
  }, [minute, clockRunning, receivedAtMs]);
3024
- return displayMinute2;
2983
+ return displayMinute;
3025
2984
  }
3026
2985
 
3027
2986
  // src/components/dashboard/LiveScoreCard.tsx
@@ -3053,7 +3012,7 @@ function LiveScoreCard({
3053
3012
  if (!seedRef.current || seedRef.current.key !== seedKey) {
3054
3013
  seedRef.current = { key: seedKey, receivedAtMs: Date.now() };
3055
3014
  }
3056
- const displayMinute2 = useLiveClock(data.minute, data.clockRunning, seedRef.current.receivedAtMs);
3015
+ const displayMinute = useLiveClock(data.minute, data.clockRunning, seedRef.current.receivedAtMs);
3057
3016
  const minuteSuffix = data.minuteLabel.replace(/^\d+/, "");
3058
3017
  const scorers = scorersLine(goalEvents);
3059
3018
  return /* @__PURE__ */ jsxs32("div", { className: "ss-w-fandash-card ss-w-fandash-live-score", children: [
@@ -3063,7 +3022,7 @@ function LiveScoreCard({
3063
3022
  /* @__PURE__ */ jsx36("span", { className: "ss-w-fandash-live-dot", "aria-hidden": "true" }),
3064
3023
  data.statusLabel
3065
3024
  ] }),
3066
- /* @__PURE__ */ jsx36("span", { className: "ss-w-fandash-live-minute", children: `${displayMinute2}${minuteSuffix}` }),
3025
+ /* @__PURE__ */ jsx36("span", { className: "ss-w-fandash-live-minute", children: `${displayMinute}${minuteSuffix}` }),
3067
3026
  data.competition ? /* @__PURE__ */ jsx36("span", { className: "ss-w-fandash-live-competition", children: data.competition }) : null
3068
3027
  ] }),
3069
3028
  /* @__PURE__ */ jsxs32("div", { className: "ss-w-fandash-live-main", children: [
@@ -3745,11 +3704,10 @@ function Side({ name, crest }) {
3745
3704
  /* @__PURE__ */ jsx49("span", { className: "ss-w-drow-nm", children: name })
3746
3705
  ] });
3747
3706
  }
3748
- function FixtureRow({ match, state, stale, nowMs, ui, monitor }) {
3749
- const readingStale = isReadingStale(state, nowMs);
3750
- const isLive = state?.phase === "live" && !stale && !readingStale;
3707
+ function FixtureRow({ match, state, stale, ui, monitor }) {
3708
+ const isLive = state?.phase === "live" && !stale;
3751
3709
  const hasScore = (state?.phase === "live" || state?.phase === "fullTime") && typeof state.homeScore === "number" && typeof state.awayScore === "number";
3752
- const ticked = displayMinute(state, nowMs);
3710
+ const ticked = state?.phase === "live" ? state.minuteLabel ?? null : null;
3753
3711
  const isFinished = state?.phase === "fullTime";
3754
3712
  const when = state?.isHalfTime && !stale ? ui.halfTime : isLive ? ticked ?? "\u2014" : state?.phase === "live" ? "\u2014" : isFinished ? ui.fullTime : kickoffLabel(match.kickoffUnix);
3755
3713
  const pin = { kind: "match", matchId: match.matchId };
@@ -3765,10 +3723,15 @@ function FixtureRow({ match, state, stale, nowMs, ui, monitor }) {
3765
3723
  ] });
3766
3724
  }
3767
3725
 
3726
+ // src/liveClock.ts
3727
+ function isTreatedLive(state, pollStale) {
3728
+ return state?.phase === "live" && !pollStale;
3729
+ }
3730
+
3768
3731
  // src/components/CompetitionGroup.tsx
3769
3732
  import { jsx as jsx50, jsxs as jsxs45 } from "react/jsx-runtime";
3770
- function CompetitionGroup({ group, open, onToggle, states, stale, nowMs, ui, monitor, disambiguate = false }) {
3771
- const own = group.matches.filter((m) => !isTreatedLive(states[m.matchId], stale, nowMs));
3733
+ function CompetitionGroup({ group, open, onToggle, states, stale, ui, monitor, disambiguate = false }) {
3734
+ const own = group.matches.filter((m) => !isTreatedLive(states[m.matchId], stale));
3772
3735
  const hasLive = own.length !== group.matches.length;
3773
3736
  if (own.length === 0) {
3774
3737
  return null;
@@ -3787,15 +3750,15 @@ function CompetitionGroup({ group, open, onToggle, states, stale, nowMs, ui, mon
3787
3750
  ] }),
3788
3751
  /* @__PURE__ */ jsx50("span", { className: "ss-w-grp-count", children: own.length })
3789
3752
  ] }),
3790
- open && /* @__PURE__ */ jsx50("div", { className: "ss-w-grp-body", children: own.map((m) => /* @__PURE__ */ jsx50(FixtureRow, { match: m, state: states[m.matchId], stale, nowMs, ui, monitor }, m.matchId)) })
3753
+ open && /* @__PURE__ */ jsx50("div", { className: "ss-w-grp-body", children: own.map((m) => /* @__PURE__ */ jsx50(FixtureRow, { match: m, state: states[m.matchId], stale, ui, monitor }, m.matchId)) })
3791
3754
  ] });
3792
3755
  }
3793
3756
 
3794
3757
  // src/components/TodayPanel.tsx
3795
3758
  import { Fragment as Fragment7, jsx as jsx51, jsxs as jsxs46 } from "react/jsx-runtime";
3796
3759
  function TodayPanel({ discovery, ui, monitor }) {
3797
- const { groups, states, nowMs, stale, expanded, toggleGroup } = discovery;
3798
- const liveRows = stale ? [] : groups.flatMap((group) => group.matches.filter((m) => isTreatedLive(states[m.matchId], stale, nowMs)).map((match) => ({ match, rank: group.rank }))).sort((a, b) => a.rank - b.rank);
3760
+ const { groups, states, stale, expanded, toggleGroup } = discovery;
3761
+ const liveRows = stale ? [] : groups.flatMap((group) => group.matches.filter((m) => isTreatedLive(states[m.matchId], stale)).map((match) => ({ match, rank: group.rank }))).sort((a, b) => a.rank - b.rank);
3799
3762
  const nameCounts = groups.reduce((acc, g) => {
3800
3763
  acc[g.competitionName] = (acc[g.competitionName] ?? 0) + 1;
3801
3764
  return acc;
@@ -3813,7 +3776,6 @@ function TodayPanel({ discovery, ui, monitor }) {
3813
3776
  match,
3814
3777
  state: states[match.matchId],
3815
3778
  stale,
3816
- nowMs,
3817
3779
  ui,
3818
3780
  monitor
3819
3781
  },
@@ -3829,7 +3791,6 @@ function TodayPanel({ discovery, ui, monitor }) {
3829
3791
  disambiguate: (nameCounts[group.competitionName] ?? 0) > 1,
3830
3792
  states,
3831
3793
  stale,
3832
- nowMs,
3833
3794
  ui,
3834
3795
  monitor
3835
3796
  },