@sentinel-nvr/web 0.16.11 → 0.17.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/ui/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  PlayerController,
3
3
  rlog
4
- } from "../chunk-RJXSSHIR.js";
4
+ } from "../chunk-5RHE6TBS.js";
5
5
  import {
6
6
  SENTINEL_CLASS_PRIORITY,
7
7
  SENTINEL_DAY_MS,
8
8
  SENTINEL_EVENT_CLASSES,
9
+ SentinelHttpError,
9
10
  fmtDay,
10
11
  fmtDayPrefix,
11
12
  fmtMonthYear,
@@ -24,6 +25,7 @@ import {
24
25
  sentinelEventHidden,
25
26
  sentinelEventPlayTs,
26
27
  sentinelEventSpan,
28
+ sentinelHasFeature,
27
29
  sentinelHumanBytes,
28
30
  sentinelMergeDays,
29
31
  sentinelRecordingState,
@@ -31,7 +33,7 @@ import {
31
33
  sentinelWallMarks,
32
34
  sentinelWallSeconds,
33
35
  weekdayShorts
34
- } from "../chunk-CNXMCQJ3.js";
36
+ } from "../chunk-UK7LBC3R.js";
35
37
 
36
38
  // src/ui/context.tsx
37
39
  import { createContext, useContext } from "react";
@@ -625,12 +627,14 @@ function outsideAppHref(url, env = {
625
627
 
626
628
  // src/ui/components/EventList.tsx
627
629
  import { Fragment as Fragment3 } from "react";
630
+ import { Download } from "lucide-react";
628
631
  import { Fragment as Fragment4, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
629
632
  function EventList({
630
633
  camId,
631
634
  events,
632
635
  filterOff,
633
- onPick
636
+ onPick,
637
+ onClip
634
638
  }) {
635
639
  const { client, t, locale } = useSentinelUi();
636
640
  const evs = events.filter((e) => !sentinelEventHidden(e, filterOff)).slice().sort((a, b) => b.timestamp - a.timestamp);
@@ -642,19 +646,32 @@ function EventList({
642
646
  lastDay = d;
643
647
  return /* @__PURE__ */ jsxs3(Fragment3, { children: [
644
648
  head && /* @__PURE__ */ jsx5("div", { className: "nvr-evlist__day nvr-data", children: fmtDay(ev.timestamp, locale) }),
645
- /* @__PURE__ */ jsxs3("button", { type: "button", className: "nvr-evrow", onClick: () => onPick(ev), children: [
646
- /* @__PURE__ */ jsx5("img", { className: "nvr-evrow__img", src: client.eventThumbUrl(camId, ev.timestamp), alt: "", loading: "lazy" }),
647
- /* @__PURE__ */ jsxs3("span", { className: "nvr-evrow__text", children: [
648
- /* @__PURE__ */ jsxs3("span", { className: "nvr-evrow__cls", children: [
649
- /* @__PURE__ */ jsx5(EventBadges, { ev, size: 16, t }),
650
- " ",
651
- eventLabel(t, ev)
652
- ] }),
653
- /* @__PURE__ */ jsxs3("span", { className: "nvr-evrow__t nvr-data", children: [
654
- fmtTimeSec(ev.timestamp, locale),
655
- /* @__PURE__ */ jsx5(EventSpanNote, { ev, t })
649
+ /* @__PURE__ */ jsxs3("div", { className: "nvr-evrow-wrap" + (onClip ? " nvr-evrow-wrap--clip" : ""), children: [
650
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: "nvr-evrow", onClick: () => onPick(ev), children: [
651
+ /* @__PURE__ */ jsx5("img", { className: "nvr-evrow__img", src: client.eventThumbUrl(camId, ev.timestamp), alt: "", loading: "lazy" }),
652
+ /* @__PURE__ */ jsxs3("span", { className: "nvr-evrow__text", children: [
653
+ /* @__PURE__ */ jsxs3("span", { className: "nvr-evrow__cls", children: [
654
+ /* @__PURE__ */ jsx5(EventBadges, { ev, size: 16, t }),
655
+ " ",
656
+ eventLabel(t, ev)
657
+ ] }),
658
+ /* @__PURE__ */ jsxs3("span", { className: "nvr-evrow__t nvr-data", children: [
659
+ fmtTimeSec(ev.timestamp, locale),
660
+ /* @__PURE__ */ jsx5(EventSpanNote, { ev, t })
661
+ ] })
656
662
  ] })
657
- ] })
663
+ ] }),
664
+ onClip && /* @__PURE__ */ jsx5(
665
+ "button",
666
+ {
667
+ type: "button",
668
+ className: "nvr-iconbtn nvr-evrow__clip",
669
+ "aria-label": `${t("nvr.clip.event")} ${fmtTimeSec(ev.timestamp, locale)}`,
670
+ title: t("nvr.clip.event"),
671
+ onClick: () => onClip(ev),
672
+ children: /* @__PURE__ */ jsx5(Download, { size: 16 })
673
+ }
674
+ )
658
675
  ] })
659
676
  ] }, ev.id);
660
677
  }) });
@@ -1186,7 +1203,7 @@ function VerticalTimeline(p) {
1186
1203
  }, []);
1187
1204
  const followTick = () => {
1188
1205
  const v = VT.current;
1189
- if (!v.user) {
1206
+ if (!v.user && !p.hold) {
1190
1207
  const ts = p.live ? Date.now() : p.following() ? p.playhead() : null;
1191
1208
  if (ts != null) {
1192
1209
  const cur = centerTs();
@@ -1297,6 +1314,7 @@ function VerticalTimeline(p) {
1297
1314
  v.lastC = { ts: c, at: now2 };
1298
1315
  v.smooth = v.smooth == null ? c : v.smooth + 0.45 * (c - v.smooth);
1299
1316
  p.scrub.move(c, v.vel, v.smooth);
1317
+ p.onUserCenter?.(clampRange(c));
1300
1318
  notifyCenter();
1301
1319
  tick((n) => n + 1);
1302
1320
  clearTimeout(v.holdT);
@@ -1332,7 +1350,7 @@ function VerticalTimeline(p) {
1332
1350
  setPx(c);
1333
1351
  };
1334
1352
  const zoomStep = (f) => {
1335
- const a = p.live ? Date.now() : p.following() ? p.playhead() ?? centerTs() : centerTs();
1353
+ const a = p.hold ? centerTs() : p.live ? Date.now() : p.following() ? p.playhead() ?? centerTs() : centerTs();
1336
1354
  applyZoom(px * f, a, vh * HEAD);
1337
1355
  };
1338
1356
  const runs = useMemo(() => sentinelClipRuns(p.clips), [p.clips]);
@@ -1376,7 +1394,7 @@ function VerticalTimeline(p) {
1376
1394
  const thumbGap = (window.innerWidth < 900 ? 63 : 77) + 6;
1377
1395
  const now = Date.now();
1378
1396
  const viewCenter = clamp(centerTs(), p.rangeStart, p.rangeEnd - 1);
1379
- const center = VT.current.user || !p.following() ? viewCenter : p.live ? now : p.playhead() ?? viewCenter;
1397
+ const center = VT.current.user || p.hold || !p.following() ? viewCenter : p.live ? now : p.playhead() ?? viewCenter;
1380
1398
  const centerIsToday = new Date(center).toDateString() === (/* @__PURE__ */ new Date()).toDateString();
1381
1399
  const down = () => {
1382
1400
  VT.current.down = true;
@@ -1398,6 +1416,14 @@ function VerticalTimeline(p) {
1398
1416
  }),
1399
1417
  axis.map((t2) => /* @__PURE__ */ jsx8("div", { className: "vaxis nvr-data", style: { top: yFor(t2) }, children: hhmm(t2) }, t2)),
1400
1418
  midnights.map((t2) => /* @__PURE__ */ jsx8("div", { className: "vday", style: { top: yFor(t2) }, children: /* @__PURE__ */ jsx8("span", { className: "nvr-data", children: dayLbl(t2) }) }, "d" + t2)),
1419
+ p.clip && inWin(Math.min(p.clip.from, p.clip.to), Math.max(p.clip.from, p.clip.to)) && /* @__PURE__ */ jsx8(
1420
+ "div",
1421
+ {
1422
+ className: "vclip" + (p.clip.edge ? ` vclip--${p.clip.edge}` : "") + (p.clip.bad ? " vclip--bad" : ""),
1423
+ style: { top: yFor(p.clip.to), height: Math.max(2, (p.clip.to - p.clip.from) * px) },
1424
+ "aria-hidden": "true"
1425
+ }
1426
+ ),
1401
1427
  runs.map(
1402
1428
  (r, i) => inWin(r.s, r.e) && /* @__PURE__ */ jsx8("div", { className: "vseg", style: { top: yFor(r.e), height: Math.max(2, (r.e - r.s) * px) } }, i)
1403
1429
  ),
@@ -1482,12 +1508,13 @@ function VerticalTimeline(p) {
1482
1508
  }
1483
1509
 
1484
1510
  // src/ui/components/CameraPage.tsx
1485
- import { useCallback, useEffect as useEffect3, useMemo as useMemo2, useRef as useRef2, useState as useState4 } from "react";
1511
+ import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef3, useState as useState5 } from "react";
1486
1512
  import {
1487
1513
  Calendar,
1488
1514
  Camera as Camera2,
1489
1515
  ChevronLeft as ChevronLeft2,
1490
1516
  ChevronRight as ChevronRight2,
1517
+ Download as Download2,
1491
1518
  FastForward,
1492
1519
  Maximize2,
1493
1520
  Pause,
@@ -1496,7 +1523,7 @@ import {
1496
1523
  Rewind,
1497
1524
  Volume2,
1498
1525
  VolumeX,
1499
- X
1526
+ X as X2
1500
1527
  } from "lucide-react";
1501
1528
 
1502
1529
  // src/ui/camera-logic.ts
@@ -1533,8 +1560,546 @@ function eventsOnDay(events, day) {
1533
1560
  return n;
1534
1561
  }
1535
1562
 
1563
+ // src/ui/clip-logic.ts
1564
+ var CLIP_MAX_MS = 30 * 6e4;
1565
+ var CLIP_PAD_MS = 5e3;
1566
+ var CLIP_LEAD_MS = 1e4;
1567
+ var CLIP_LIVE_EDGE_MS = 1e4;
1568
+ var CLIP_AROUND_MS = 3e4;
1569
+ var CLIP_LIVE_MS = 6e4;
1570
+ var CLIP_GAP_MS = 2e3;
1571
+ var CLIP_SHARE_MAX = 100 * 1024 * 1024;
1572
+ var CLIP_BLOB_MAX = CLIP_SHARE_MAX;
1573
+ var CLIP_POLL_MS = 700;
1574
+ var CLIP_POLL_GIVEUP_MS = 6e4;
1575
+ function clipRangeForEvent(ev, now = Date.now()) {
1576
+ const t = ev.timestamp;
1577
+ const start = Math.max(Math.min(ev.startTs ?? t, t), t - CLIP_LEAD_MS);
1578
+ const open = !!ev.open;
1579
+ const end = open ? Math.max(now, ev.endTs ?? t) : Math.max(ev.endTs ?? t, t);
1580
+ return { from: start - CLIP_PAD_MS, to: end + CLIP_PAD_MS, open };
1581
+ }
1582
+ function clampClipRange(r, opts) {
1583
+ const hi = opts.now - CLIP_LIVE_EDGE_MS;
1584
+ let from = r.from, to = r.to;
1585
+ if (opts.oldest != null && from < opts.oldest) from = opts.oldest;
1586
+ if (to > hi) to = hi;
1587
+ if (opts.cap !== false && to - from > CLIP_MAX_MS) to = from + CLIP_MAX_MS;
1588
+ if (to < from) from = to;
1589
+ return { from, to };
1590
+ }
1591
+ function clipProposal(s) {
1592
+ const hi = s.now - CLIP_LIVE_EDGE_MS;
1593
+ if (s.live || s.playhead == null) {
1594
+ return { ...clampClipRange({ from: hi - CLIP_LIVE_MS, to: hi }, s), open: false };
1595
+ }
1596
+ const p = s.playhead;
1597
+ let hit = null;
1598
+ let hitTs = -Infinity;
1599
+ for (const e of s.events) {
1600
+ const r = clipRangeForEvent(e, s.now);
1601
+ if (p >= r.from && p <= r.to && e.timestamp > hitTs) {
1602
+ hit = r;
1603
+ hitTs = e.timestamp;
1604
+ }
1605
+ }
1606
+ if (hit) return { ...clampClipRange(hit, s), open: hit.open };
1607
+ return { ...clampClipRange({ from: p - CLIP_AROUND_MS, to: p + CLIP_AROUND_MS }, s), open: false };
1608
+ }
1609
+ function clipSetEdge(r, edge, ts) {
1610
+ if (edge === "from")
1611
+ return ts <= r.to ? { range: { from: ts, to: r.to }, edge } : { range: { from: r.to, to: ts }, edge: "to" };
1612
+ return ts >= r.from ? { range: { from: r.from, to: ts }, edge } : { range: { from: ts, to: r.from }, edge: "from" };
1613
+ }
1614
+ function clipCoverage(clips, r) {
1615
+ const runs = sentinelClipRuns(clips, CLIP_GAP_MS).filter((x) => x.e > r.from && x.s < r.to);
1616
+ let covered = 0, cur = r.from;
1617
+ const gaps = [];
1618
+ for (const x of runs) {
1619
+ const s = Math.max(x.s, r.from), e = Math.min(x.e, r.to);
1620
+ if (s - cur >= CLIP_GAP_MS) gaps.push([cur, s]);
1621
+ covered += Math.max(0, e - s);
1622
+ cur = Math.max(cur, e);
1623
+ }
1624
+ if (runs.length && r.to - cur >= CLIP_GAP_MS) gaps.push([cur, r.to]);
1625
+ return { covered, gaps };
1626
+ }
1627
+ function clipHints(r, clips, now) {
1628
+ const tooLong = r.to - r.from > CLIP_MAX_MS;
1629
+ const hi = now - CLIP_LIVE_EDGE_MS;
1630
+ const endsAt = r.to > hi ? Math.max(r.from, hi) : null;
1631
+ const cov = clipCoverage(clips, { from: r.from, to: Math.min(r.to, hi) });
1632
+ const noRecording = cov.covered <= 0;
1633
+ return {
1634
+ tooLong,
1635
+ noRecording,
1636
+ gaps: !noRecording && cov.gaps.length > 0,
1637
+ endsAt,
1638
+ canCreate: !tooLong && !noRecording && r.to - r.from >= 1e3 && r.from < hi
1639
+ };
1640
+ }
1641
+ function clipLength(r) {
1642
+ return sentinelDuration(r.to - r.from);
1643
+ }
1644
+ function clipTimeAmbiguous(ts) {
1645
+ const wall = (x) => {
1646
+ const d = new Date(x);
1647
+ return d.getHours() * 3600 + d.getMinutes() * 60 + d.getSeconds();
1648
+ };
1649
+ const w = wall(ts);
1650
+ return wall(ts - 36e5) === w || wall(ts + 36e5) === w;
1651
+ }
1652
+ function fmtClipTime(ts, locale) {
1653
+ const base = { hour: "2-digit", minute: "2-digit", second: "2-digit" };
1654
+ if (!clipTimeAmbiguous(ts)) return new Intl.DateTimeFormat(locale, base).format(ts);
1655
+ try {
1656
+ return new Intl.DateTimeFormat(locale, { ...base, timeZoneName: "shortOffset" }).format(ts);
1657
+ } catch {
1658
+ return new Intl.DateTimeFormat(locale, { ...base, timeZoneName: "short" }).format(ts);
1659
+ }
1660
+ }
1661
+ function clipWays(s) {
1662
+ const known = s.bytes > 0;
1663
+ const fits = known && s.bytes <= CLIP_SHARE_MAX;
1664
+ if (s.standalone)
1665
+ return fits ? { prefetch: true, share: s.canShareFiles, save: "blob" } : { prefetch: false, share: false, save: "safari" };
1666
+ if (s.crossOrigin)
1667
+ return known && s.bytes <= CLIP_BLOB_MAX ? { prefetch: true, share: fits && s.canShareFiles, save: "blob" } : { prefetch: false, share: false, save: "tab" };
1668
+ if (fits && s.canShareFiles) return { prefetch: true, share: true, save: "link" };
1669
+ return { prefetch: false, share: false, save: "link" };
1670
+ }
1671
+ function isCrossOrigin(url, base = typeof location !== "undefined" ? location.href : "") {
1672
+ try {
1673
+ return new URL(url, base).origin !== new URL(base).origin;
1674
+ } catch {
1675
+ return false;
1676
+ }
1677
+ }
1678
+ function clipErrorKind(status, code) {
1679
+ if (code === "busy" || status === 429) return "busy";
1680
+ if (code === "no space" || status === 507) return "noSpace";
1681
+ if (code === "no recording") return "noRecording";
1682
+ if (code === "too long" || status === 413) return "tooLong";
1683
+ if (code === "stream change") return "streamChange";
1684
+ if (code === "unknown export") return "expired";
1685
+ if (status === 404 && !code) return "oldServer";
1686
+ return "failed";
1687
+ }
1688
+
1689
+ // src/ui/components/ClipBar.tsx
1690
+ import { useCallback, useEffect as useEffect3, useRef as useRef2, useState as useState4 } from "react";
1691
+ import { Share2, X } from "lucide-react";
1692
+ import { Fragment as Fragment7, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1693
+ function canShareFiles() {
1694
+ try {
1695
+ const n = navigator;
1696
+ if (typeof n.canShare !== "function" || typeof n.share !== "function") return false;
1697
+ return n.canShare({ files: [new File([new Uint8Array(1)], "clip.mp4", { type: "video/mp4" })] });
1698
+ } catch {
1699
+ return false;
1700
+ }
1701
+ }
1702
+ function viewerTz() {
1703
+ try {
1704
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
1705
+ } catch {
1706
+ return void 0;
1707
+ }
1708
+ }
1709
+ function ClipBar(p) {
1710
+ const { client, t, locale } = useSentinelUi();
1711
+ const [job, setJobState] = useState4({ s: "idle" });
1712
+ const jobRef = useRef2(job);
1713
+ const setJob = useCallback((j) => {
1714
+ jobRef.current = j;
1715
+ setJobState(j);
1716
+ }, []);
1717
+ const gen = useRef2(0);
1718
+ const alive = useRef2(true);
1719
+ const abort = useRef2(null);
1720
+ const standalone = isIosHomeScreenApp();
1721
+ const release = useCallback(() => {
1722
+ abort.current?.abort();
1723
+ abort.current = null;
1724
+ const j = jobRef.current;
1725
+ if (j.s === "ready" && j.blobUrl) URL.revokeObjectURL(j.blobUrl);
1726
+ }, []);
1727
+ const cancelRunning = useCallback(() => {
1728
+ const j = jobRef.current;
1729
+ if (j.s === "running") void client.cancelExport(j.id);
1730
+ }, [client]);
1731
+ useEffect3(() => {
1732
+ alive.current = true;
1733
+ return () => {
1734
+ alive.current = false;
1735
+ gen.current++;
1736
+ cancelRunning();
1737
+ release();
1738
+ };
1739
+ }, [cancelRunning, release]);
1740
+ const rangeKey = `${p.range.from}|${p.range.to}`;
1741
+ const lastKey = useRef2(rangeKey);
1742
+ useEffect3(() => {
1743
+ if (lastKey.current === rangeKey) return;
1744
+ lastKey.current = rangeKey;
1745
+ if (jobRef.current.s === "idle") return;
1746
+ cancelRunning();
1747
+ gen.current++;
1748
+ release();
1749
+ setJob({ s: "idle" });
1750
+ }, [rangeKey, cancelRunning, release, setJob]);
1751
+ const fail = useCallback(
1752
+ (kind, vars, extra) => {
1753
+ rlog("clip", { ok: false, err: kind, standalone, ...extra });
1754
+ setJob(vars ? { s: "error", kind, vars } : { s: "error", kind });
1755
+ },
1756
+ [setJob, standalone]
1757
+ );
1758
+ const errorOf = useCallback(
1759
+ (e) => {
1760
+ const st2 = e instanceof SentinelHttpError ? e.status : 0;
1761
+ const code = e instanceof SentinelHttpError ? e.code : void 0;
1762
+ const body = e instanceof SentinelHttpError ? e.body : void 0;
1763
+ const kind = clipErrorKind(st2, code);
1764
+ const vars = {};
1765
+ if (kind === "tooLong") vars.max = Math.round(Number(body?.maxMs ?? CLIP_MAX_MS) / 6e4);
1766
+ let k = kind;
1767
+ if (kind === "streamChange") {
1768
+ if (typeof body?.at === "number") vars.time = fmtClipTime(body.at, locale);
1769
+ else k = "failed";
1770
+ }
1771
+ fail(k, vars, { status: st2, code });
1772
+ },
1773
+ [fail, locale]
1774
+ );
1775
+ const finish = useCallback(
1776
+ async (g, d) => {
1777
+ const crossOrigin = isCrossOrigin(client.exportFileUrl(d.id));
1778
+ const ways = clipWays({ bytes: d.bytes, canShareFiles: canShareFiles(), standalone, crossOrigin });
1779
+ if (!ways.prefetch) {
1780
+ setJob({ s: "ready", ...d, ways });
1781
+ return;
1782
+ }
1783
+ setJob({ s: "loading", ...d, ways });
1784
+ const ac = new AbortController();
1785
+ abort.current = ac;
1786
+ try {
1787
+ const r = await fetch(client.exportFileUrl(d.id), { cache: "no-store", signal: ac.signal });
1788
+ if (r.status === 404) {
1789
+ if (g === gen.current) fail("expired");
1790
+ return;
1791
+ }
1792
+ if (!r.ok) throw new Error(String(r.status));
1793
+ const blob = await r.blob();
1794
+ if (g !== gen.current || !alive.current) return;
1795
+ const file = new File([blob], d.filename, { type: blob.type || "video/mp4" });
1796
+ setJob({ s: "ready", ...d, ways, file, blobUrl: URL.createObjectURL(blob) });
1797
+ } catch (e) {
1798
+ if (g !== gen.current || !alive.current) return;
1799
+ rlog("clip", {
1800
+ ok: false,
1801
+ err: "prefetch",
1802
+ msg: String(e?.message ?? e).slice(0, 80),
1803
+ bytes: d.bytes,
1804
+ standalone,
1805
+ xo: crossOrigin
1806
+ });
1807
+ setJob({ s: "ready", ...d, ways: { prefetch: false, share: false, save: crossOrigin ? "tab" : "link" } });
1808
+ } finally {
1809
+ if (abort.current === ac) abort.current = null;
1810
+ }
1811
+ },
1812
+ [client, fail, setJob, standalone]
1813
+ );
1814
+ const running = job.s === "running" ? job.id : null;
1815
+ useEffect3(() => {
1816
+ if (!running) return;
1817
+ const g = gen.current;
1818
+ let timer = 0;
1819
+ let busy2 = false;
1820
+ let lastOk = Date.now();
1821
+ const poll = async () => {
1822
+ if (busy2 || g !== gen.current) return;
1823
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
1824
+ busy2 = true;
1825
+ try {
1826
+ const st2 = await client.exportStatus(running);
1827
+ if (g !== gen.current || !alive.current) return;
1828
+ lastOk = Date.now();
1829
+ const j = jobRef.current;
1830
+ if (j.s !== "running") return;
1831
+ if (st2.state === "running") setJob({ ...j, pct: Math.max(0, Math.min(1, st2.progress || 0)) });
1832
+ else if (st2.state === "done") {
1833
+ window.clearInterval(timer);
1834
+ void finish(g, {
1835
+ id: j.id,
1836
+ bytes: st2.bytes ?? j.start.estBytes,
1837
+ filename: st2.filename || j.start.filename,
1838
+ start: j.start,
1839
+ t0: j.t0,
1840
+ expiresAt: st2.expiresAt
1841
+ });
1842
+ } else if (st2.state === "cancelled") {
1843
+ window.clearInterval(timer);
1844
+ setJob({ s: "idle" });
1845
+ } else {
1846
+ window.clearInterval(timer);
1847
+ fail("failed", void 0, { serverErr: st2.error });
1848
+ }
1849
+ } catch (e) {
1850
+ if (g !== gen.current || !alive.current) return;
1851
+ const status = e instanceof SentinelHttpError ? e.status : 0;
1852
+ if (status === 404 || status === 401 || status === 403 || Date.now() - lastOk > CLIP_POLL_GIVEUP_MS) {
1853
+ window.clearInterval(timer);
1854
+ if (status !== 404) void client.cancelExport(running);
1855
+ gen.current++;
1856
+ fail("failed", void 0, { status, code: e instanceof SentinelHttpError ? e.code : void 0 });
1857
+ }
1858
+ } finally {
1859
+ busy2 = false;
1860
+ }
1861
+ };
1862
+ timer = window.setInterval(() => void poll(), CLIP_POLL_MS);
1863
+ const vis = () => {
1864
+ if (document.visibilityState === "visible") void poll();
1865
+ };
1866
+ document.addEventListener("visibilitychange", vis);
1867
+ return () => {
1868
+ window.clearInterval(timer);
1869
+ document.removeEventListener("visibilitychange", vis);
1870
+ };
1871
+ }, [running, client, finish, fail, setJob]);
1872
+ const expiresAt = job.s === "ready" || job.s === "loading" ? job.expiresAt : void 0;
1873
+ useEffect3(() => {
1874
+ if (!expiresAt) return;
1875
+ const g = gen.current;
1876
+ const i = window.setTimeout(
1877
+ () => {
1878
+ if (g !== gen.current || !alive.current) return;
1879
+ const j = jobRef.current;
1880
+ if (j.s === "ready" && j.file) return;
1881
+ gen.current++;
1882
+ release();
1883
+ setJob({ s: "error", kind: "expired" });
1884
+ },
1885
+ Math.min(2 ** 31 - 1, Math.max(0, expiresAt - Date.now()))
1886
+ );
1887
+ return () => window.clearTimeout(i);
1888
+ }, [expiresAt, release, setJob]);
1889
+ const create = useCallback(async () => {
1890
+ const j = jobRef.current;
1891
+ if (j.s === "starting" || j.s === "running" || j.s === "loading") return;
1892
+ gen.current++;
1893
+ const g = gen.current;
1894
+ release();
1895
+ p.onEdge(null);
1896
+ setJob({ s: "starting" });
1897
+ const t0 = Date.now();
1898
+ try {
1899
+ const start = await client.startExport(p.camId, p.range.from, p.range.to, viewerTz());
1900
+ if (g !== gen.current) {
1901
+ void client.cancelExport(start.id);
1902
+ return;
1903
+ }
1904
+ setJob({ s: "running", id: start.id, pct: 0, start, t0 });
1905
+ } catch (e) {
1906
+ if (g !== gen.current || !alive.current) return;
1907
+ errorOf(e);
1908
+ }
1909
+ }, [client, p, release, setJob, errorOf]);
1910
+ const cancel = useCallback(() => {
1911
+ cancelRunning();
1912
+ gen.current++;
1913
+ release();
1914
+ setJob({ s: "idle" });
1915
+ }, [cancelRunning, release, setJob]);
1916
+ const log = (w, ok = true, err) => {
1917
+ const j = jobRef.current;
1918
+ if (j.s !== "ready" && j.s !== "loading") return;
1919
+ rlog("clip", { ms: Date.now() - j.t0, bytes: j.bytes, w, standalone, ok, ...err ? { err } : {} });
1920
+ };
1921
+ const share = () => {
1922
+ const j = jobRef.current;
1923
+ if (j.s !== "ready" || !j.file) return;
1924
+ try {
1925
+ void navigator.share({ files: [j.file] }).then(
1926
+ () => log("share"),
1927
+ (e) => {
1928
+ const name = e?.name;
1929
+ if (name !== "AbortError") log("share", false, name || "error");
1930
+ }
1931
+ );
1932
+ } catch (e) {
1933
+ log("share", false, e?.name || "error");
1934
+ }
1935
+ };
1936
+ const busy = job.s === "starting" || job.s === "running" || job.s === "loading";
1937
+ const now = Date.now();
1938
+ const hints = clipHints(p.range, p.clips, now);
1939
+ const chip = (e) => {
1940
+ const ts = e === "from" ? p.range.from : p.range.to;
1941
+ const active = p.edge === e;
1942
+ const bad = e === "to" && hints.tooLong;
1943
+ const k = t(e === "from" ? "nvr.clip.from" : "nvr.clip.to");
1944
+ const v = fmtClipTime(ts, locale);
1945
+ return /* @__PURE__ */ jsxs7(
1946
+ "button",
1947
+ {
1948
+ type: "button",
1949
+ className: "nvr-clipchip" + (active ? " nvr-clipchip--active" : "") + (bad ? " nvr-clipchip--bad" : ""),
1950
+ "aria-pressed": active,
1951
+ "aria-label": `${k} ${v}`,
1952
+ disabled: busy,
1953
+ onClick: () => p.onEdge(active ? null : e),
1954
+ children: [
1955
+ /* @__PURE__ */ jsx9("span", { className: "nvr-clipchip__k", children: k }),
1956
+ " ",
1957
+ /* @__PURE__ */ jsx9("span", { className: "nvr-clipchip__v nvr-data", children: v })
1958
+ ]
1959
+ }
1960
+ );
1961
+ };
1962
+ let note = null;
1963
+ const st = job.s === "running" || job.s === "loading" || job.s === "ready" ? job.start : null;
1964
+ if (job.s === "error") {
1965
+ note = { text: t(`nvr.clip.${job.kind}`, job.vars), tone: job.kind === "expired" ? "info" : "bad" };
1966
+ } else if (job.s === "ready" && job.ways.save === "safari") note = { text: t("nvr.clip.tooLarge"), tone: "info" };
1967
+ else if (st) {
1968
+ if (st.clipped) note = { text: t("nvr.clip.endsAt", { time: fmtClipTime(st.to, locale) }), tone: "info" };
1969
+ else if (st.gaps?.length) note = { text: t("nvr.clip.gaps"), tone: "info" };
1970
+ } else if (job.s === "starting") note = null;
1971
+ else if (hints.tooLong) note = { text: t("nvr.clip.tooLong", { max: CLIP_MAX_MS / 6e4 }), tone: "bad" };
1972
+ else if (hints.noRecording) note = { text: t("nvr.clip.noRecording"), tone: "bad" };
1973
+ else if (p.edge) note = { text: t("nvr.clip.edgeHint"), tone: "info" };
1974
+ else if (p.open) note = { text: t("nvr.clip.eventRunning"), tone: "info" };
1975
+ else if (hints.endsAt != null)
1976
+ note = { text: t("nvr.clip.endsAt", { time: fmtClipTime(hints.endsAt, locale) }), tone: "info" };
1977
+ else if (hints.gaps) note = { text: t("nvr.clip.gaps"), tone: "info" };
1978
+ const lenText = t("nvr.clip.length", { d: clipLength(p.range) });
1979
+ const ready = job.s === "ready" || job.s === "loading" ? job : null;
1980
+ const fileUrl = ready ? client.exportFileUrl(ready.id) : "";
1981
+ let state = null;
1982
+ let pct = null;
1983
+ let actions;
1984
+ if (job.s === "starting" || job.s === "running") {
1985
+ pct = job.s === "running" ? Math.round(job.pct * 100) : 0;
1986
+ state = t("nvr.clip.preparing", { pct });
1987
+ actions = /* @__PURE__ */ jsx9("button", { type: "button", className: "nvr-btn nvr-btn--ghost", onClick: cancel, children: t("nvr.clip.cancel") });
1988
+ } else if (ready) {
1989
+ state = job.s === "loading" ? t("nvr.clip.loading") : t("nvr.clip.ready", { size: humanBytes(ready.bytes, locale) });
1990
+ const save = ready.ways.save === "safari" ? /* @__PURE__ */ jsx9(
1991
+ "a",
1992
+ {
1993
+ className: "nvr-btn nvr-btn--primary",
1994
+ href: outsideAppHref(fileUrl),
1995
+ target: "_blank",
1996
+ rel: "noopener noreferrer",
1997
+ onClick: () => log("safari"),
1998
+ children: t("nvr.player.openInSafari")
1999
+ }
2000
+ ) : ready.ways.save === "blob" ? job.s === "ready" && job.blobUrl ? /* @__PURE__ */ jsx9(
2001
+ "a",
2002
+ {
2003
+ className: "nvr-btn nvr-btn--primary",
2004
+ href: job.blobUrl,
2005
+ download: ready.filename,
2006
+ onClick: () => log("blob"),
2007
+ children: t("nvr.clip.save")
2008
+ }
2009
+ ) : /* @__PURE__ */ jsx9("button", { type: "button", className: "nvr-btn nvr-btn--primary", disabled: true, children: t("nvr.clip.save") }) : ready.ways.save === "tab" ? (
2010
+ // another origin, too large for the page: a new tab saves it (attachment), the host page stays
2011
+ /* @__PURE__ */ jsx9(
2012
+ "a",
2013
+ {
2014
+ className: "nvr-btn nvr-btn--primary",
2015
+ href: fileUrl,
2016
+ target: "_blank",
2017
+ rel: "noopener noreferrer",
2018
+ onClick: () => log("tab"),
2019
+ children: t("nvr.clip.save")
2020
+ }
2021
+ )
2022
+ ) : /* @__PURE__ */ jsx9(
2023
+ "a",
2024
+ {
2025
+ className: "nvr-btn nvr-btn--primary",
2026
+ href: fileUrl,
2027
+ download: ready.filename,
2028
+ onClick: () => log("download"),
2029
+ children: t("nvr.clip.save")
2030
+ }
2031
+ );
2032
+ actions = /* @__PURE__ */ jsxs7(Fragment7, { children: [
2033
+ save,
2034
+ ready.ways.share && /* @__PURE__ */ jsxs7(
2035
+ "button",
2036
+ {
2037
+ type: "button",
2038
+ className: "nvr-btn nvr-btn--ghost",
2039
+ disabled: !(job.s === "ready" && job.file),
2040
+ onClick: share,
2041
+ children: [
2042
+ /* @__PURE__ */ jsx9(Share2, { size: 16 }),
2043
+ t("nvr.clip.share")
2044
+ ]
2045
+ }
2046
+ )
2047
+ ] });
2048
+ } else {
2049
+ const again = job.s === "error" && job.kind === "expired";
2050
+ actions = /* @__PURE__ */ jsx9(
2051
+ "button",
2052
+ {
2053
+ type: "button",
2054
+ className: "nvr-btn nvr-btn--primary",
2055
+ disabled: !hints.canCreate,
2056
+ onClick: () => void create(),
2057
+ children: t(again ? "nvr.clip.recreate" : "nvr.clip.create")
2058
+ }
2059
+ );
2060
+ }
2061
+ return /* @__PURE__ */ jsxs7("div", { className: "nvr-clipbar", role: "group", "aria-label": t("nvr.clip.download"), children: [
2062
+ /* @__PURE__ */ jsxs7("div", { className: "nvr-clipbar__row", children: [
2063
+ chip("from"),
2064
+ chip("to"),
2065
+ /* @__PURE__ */ jsx9(
2066
+ "button",
2067
+ {
2068
+ type: "button",
2069
+ className: "nvr-iconbtn nvr-clipbar__close",
2070
+ "aria-label": t("nvr.clip.close"),
2071
+ onClick: p.onClose,
2072
+ children: /* @__PURE__ */ jsx9(X, { size: 16 })
2073
+ }
2074
+ )
2075
+ ] }),
2076
+ /* @__PURE__ */ jsxs7(
2077
+ "div",
2078
+ {
2079
+ className: "nvr-clipbar__note" + (note?.tone === "bad" ? " nvr-clipbar__note--bad" : ""),
2080
+ title: [lenText, state, note?.text].filter(Boolean).join(" \xB7 "),
2081
+ children: [
2082
+ /* @__PURE__ */ jsx9("span", { className: "nvr-clipbar__len nvr-data", children: lenText }),
2083
+ /* @__PURE__ */ jsxs7("span", { role: "status", children: [
2084
+ state && /* @__PURE__ */ jsxs7(Fragment7, { children: [
2085
+ " \xB7 ",
2086
+ /* @__PURE__ */ jsx9("span", { className: "nvr-clipbar__state", children: state })
2087
+ ] }),
2088
+ note && /* @__PURE__ */ jsxs7(Fragment7, { children: [
2089
+ " \xB7 ",
2090
+ /* @__PURE__ */ jsx9("span", { className: note.tone === "bad" ? "nvr-clipbar__bad" : void 0, children: note.text })
2091
+ ] })
2092
+ ] })
2093
+ ]
2094
+ }
2095
+ ),
2096
+ pct != null && /* @__PURE__ */ jsx9("div", { className: "nvr-clipbar__prog", "aria-hidden": "true", children: /* @__PURE__ */ jsx9("i", { style: { width: `${pct}%` } }) }),
2097
+ /* @__PURE__ */ jsx9("div", { className: "nvr-clipbar__row nvr-clipbar__actions", children: actions })
2098
+ ] });
2099
+ }
2100
+
1536
2101
  // src/ui/components/CameraPage.tsx
1537
- import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
2102
+ import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
1538
2103
  var IDLE = {
1539
2104
  live: true,
1540
2105
  label: "live",
@@ -1548,37 +2113,37 @@ var IDLE = {
1548
2113
  var todayStart = () => sentinelDayOf(Date.now());
1549
2114
  function CameraTitle({ name, onBack, children }) {
1550
2115
  const { t } = useSentinelUi();
1551
- return /* @__PURE__ */ jsxs7("div", { className: "nvr-cam__head", children: [
1552
- /* @__PURE__ */ jsxs7("div", { className: "nvr-cam__title", children: [
1553
- /* @__PURE__ */ jsx9("button", { type: "button", className: "nvr-iconbtn", "aria-label": t("nvr.back"), onClick: onBack, children: /* @__PURE__ */ jsx9(ChevronLeft2, { size: 20 }) }),
1554
- /* @__PURE__ */ jsx9("h1", { className: "nvr-cam__h1", children: name })
2116
+ return /* @__PURE__ */ jsxs8("div", { className: "nvr-cam__head", children: [
2117
+ /* @__PURE__ */ jsxs8("div", { className: "nvr-cam__title", children: [
2118
+ /* @__PURE__ */ jsx10("button", { type: "button", className: "nvr-iconbtn", "aria-label": t("nvr.back"), onClick: onBack, children: /* @__PURE__ */ jsx10(ChevronLeft2, { size: 20 }) }),
2119
+ /* @__PURE__ */ jsx10("h1", { className: "nvr-cam__h1", children: name })
1555
2120
  ] }),
1556
- children ? /* @__PURE__ */ jsx9("div", { className: "nvr-cam__actions", children }) : null
2121
+ children ? /* @__PURE__ */ jsx10("div", { className: "nvr-cam__actions", children }) : null
1557
2122
  ] });
1558
2123
  }
1559
2124
  function CameraPage(p) {
1560
2125
  const { client, t, locale } = useSentinelUi();
1561
2126
  const { camId, name, earliest, startAt = 0, posterTs = 0 } = p;
1562
- const [days, setDays] = useState4({});
1563
- const [nowTick, setNowTick] = useState4(Date.now());
1564
- useEffect3(() => {
2127
+ const [days, setDays] = useState5({});
2128
+ const [nowTick, setNowTick] = useState5(Date.now());
2129
+ useEffect4(() => {
1565
2130
  const i = setInterval(() => setNowTick(Date.now()), 3e4);
1566
2131
  return () => clearInterval(i);
1567
2132
  }, []);
1568
- const [centerDay, setCenterDay] = useState4(todayStart());
1569
- const [jump, setJump] = useState4(null);
1570
- const [tab, setTab] = useState4("tl");
1571
- const [filterOff, setFilterOff] = useState4({});
1572
- const [ps, setPs] = useState4(IDLE);
1573
- const [loadError, setLoadError] = useState4(false);
1574
- const [dt, setDt] = useState4(false);
1575
- const [pipNote, setPipNote] = useState4(null);
1576
- useEffect3(() => {
2133
+ const [centerDay, setCenterDay] = useState5(todayStart());
2134
+ const [jump, setJump] = useState5(null);
2135
+ const [tab, setTab] = useState5("tl");
2136
+ const [filterOff, setFilterOff] = useState5({});
2137
+ const [ps, setPs] = useState5(IDLE);
2138
+ const [loadError, setLoadError] = useState5(false);
2139
+ const [dt, setDt] = useState5(false);
2140
+ const [pipNote, setPipNote] = useState5(null);
2141
+ useEffect4(() => {
1577
2142
  if (!pipNote) return;
1578
2143
  const i = setTimeout(() => setPipNote(null), 15e3);
1579
2144
  return () => clearTimeout(i);
1580
2145
  }, [pipNote]);
1581
- const onPip = useCallback(() => {
2146
+ const onPip = useCallback2(() => {
1582
2147
  const c = ctl.current;
1583
2148
  if (!c) return;
1584
2149
  void c.pip().then((r) => {
@@ -1586,28 +2151,35 @@ function CameraPage(p) {
1586
2151
  else if (r === "entered") setPipNote(null);
1587
2152
  });
1588
2153
  }, []);
1589
- const body = useRef2(null);
1590
- const stage = useRef2(null);
1591
- const video = useRef2(null);
1592
- const freeze = useRef2(null);
1593
- const img = useRef2(null);
1594
- const ctl = useRef2(null);
1595
- const psRef = useRef2(ps);
2154
+ const body = useRef3(null);
2155
+ const stage = useRef3(null);
2156
+ const video = useRef3(null);
2157
+ const freeze = useRef3(null);
2158
+ const img = useRef3(null);
2159
+ const ctl = useRef3(null);
2160
+ const psRef = useRef3(ps);
1596
2161
  psRef.current = ps;
1597
- const loading = useRef2(/* @__PURE__ */ new Set());
1598
- const daysRef = useRef2(days);
2162
+ const loading = useRef3(/* @__PURE__ */ new Set());
2163
+ const daysRef = useRef3(days);
1599
2164
  daysRef.current = days;
1600
- const camRef = useRef2(camId);
2165
+ const camRef = useRef3(camId);
1601
2166
  camRef.current = camId;
1602
- const deepRef = useRef2("");
1603
- const gestureAt = useRef2(0);
2167
+ const deepRef = useRef3("");
2168
+ const [clip, setClip] = useState5(null);
2169
+ const [clipEdge, setClipEdge] = useState5(null);
2170
+ const clipRef = useRef3(clip);
2171
+ clipRef.current = clip;
2172
+ const clipEdgeRef = useRef3(clipEdge);
2173
+ clipEdgeRef.current = clipEdge;
2174
+ const lineTs = useRef3(null);
2175
+ const gestureAt = useRef3(0);
1604
2176
  const merged = useMemo2(() => {
1605
2177
  const m = sentinelMergeDays(days);
1606
2178
  const rangeStart = m.oldestDay ?? todayStart();
1607
2179
  const rangeEnd = Math.min(sentinelDayEnd(todayStart()), nowTick + 20 * 6e4);
1608
2180
  return { ...m, rangeStart, rangeEnd };
1609
2181
  }, [days, nowTick]);
1610
- const mergedNow = useCallback(() => {
2182
+ const mergedNow = useCallback2(() => {
1611
2183
  const m = sentinelMergeDays(daysRef.current);
1612
2184
  return {
1613
2185
  ...m,
@@ -1615,10 +2187,10 @@ function CameraPage(p) {
1615
2187
  rangeEnd: Math.min(sentinelDayEnd(todayStart()), Date.now() + 20 * 6e4)
1616
2188
  };
1617
2189
  }, []);
1618
- useEffect3(() => {
2190
+ useEffect4(() => {
1619
2191
  ctl.current?.setClips(merged.clips, merged.codecs, merged.rangeStart, merged.rangeEnd);
1620
2192
  }, [merged]);
1621
- const fetchDay = useCallback(
2193
+ const fetchDay = useCallback2(
1622
2194
  async (ds) => {
1623
2195
  const d = await client.getJson(
1624
2196
  `api/clips?camera=${encodeURIComponent(camId)}&start=${ds}&end=${sentinelDayEnd(ds)}`
@@ -1630,7 +2202,7 @@ function CameraPage(p) {
1630
2202
  },
1631
2203
  [client, camId]
1632
2204
  );
1633
- const ensureDay = useCallback(
2205
+ const ensureDay = useCallback2(
1634
2206
  async (ds, force = false) => {
1635
2207
  if (ds > todayStart()) return;
1636
2208
  if (earliest && sentinelAddDays(ds, 1) < sentinelDayOf(earliest)) return;
@@ -1648,15 +2220,16 @@ function CameraPage(p) {
1648
2220
  },
1649
2221
  [fetchDay, earliest, camId]
1650
2222
  );
1651
- const onCenter = useCallback(
2223
+ const onCenter = useCallback2(
1652
2224
  (ts) => {
2225
+ lineTs.current = ts;
1653
2226
  const d = sentinelDayOf(ts);
1654
2227
  setCenterDay(d);
1655
2228
  for (const x of [d, sentinelAddDays(d, -1), sentinelAddDays(d, 1)]) ensureDay(x).catch(() => setLoadError(true));
1656
2229
  },
1657
2230
  [ensureDay]
1658
2231
  );
1659
- useEffect3(() => {
2232
+ useEffect4(() => {
1660
2233
  const st = stage.current, cd = body.current;
1661
2234
  if (!st || !cd) return;
1662
2235
  const sync = () => {
@@ -1669,7 +2242,7 @@ function CameraPage(p) {
1669
2242
  mo.observe(st, { attributes: true, attributeFilter: ["style"] });
1670
2243
  return () => mo.disconnect();
1671
2244
  }, []);
1672
- useEffect3(() => {
2245
+ useEffect4(() => {
1673
2246
  const c = new PlayerController(client, {
1674
2247
  onState: (s) => setPs(s),
1675
2248
  onClipsRefresh: async () => {
@@ -1688,7 +2261,7 @@ function CameraPage(p) {
1688
2261
  delete window.__snvr;
1689
2262
  };
1690
2263
  }, [client]);
1691
- useEffect3(() => {
2264
+ useEffect4(() => {
1692
2265
  const c = ctl.current;
1693
2266
  if (!c || !camId) return;
1694
2267
  c.setCamera(camId, name);
@@ -1696,10 +2269,13 @@ function CameraPage(p) {
1696
2269
  daysRef.current = {};
1697
2270
  setFilterOff({});
1698
2271
  setTab("tl");
2272
+ setClip(null);
2273
+ setClipEdge(null);
1699
2274
  setLoadError(false);
1700
2275
  loading.current.clear();
1701
- if (startAt) c.posterEvent(posterTs || startAt);
1702
- else {
2276
+ if (startAt) {
2277
+ if (posterTs) c.posterEvent(posterTs);
2278
+ } else {
1703
2279
  c.posterFromSnapshot(lastTileSnapshot(camId));
1704
2280
  c.goLive();
1705
2281
  }
@@ -1726,19 +2302,19 @@ function CameraPage(p) {
1726
2302
  });
1727
2303
  deepRef.current = `${camId}|${startAt}`;
1728
2304
  }, [camId, client]);
1729
- useEffect3(() => {
2305
+ useEffect4(() => {
1730
2306
  const key = `${camId}|${startAt}`;
1731
2307
  if (!startAt || !ctl.current || key === deepRef.current) return;
1732
2308
  deepRef.current = key;
1733
2309
  const c = ctl.current;
1734
2310
  c.freezeCurrent();
1735
- c.posterEvent(posterTs || startAt);
2311
+ if (posterTs) c.posterEvent(posterTs);
1736
2312
  goToDay(sentinelDayOf(startAt), startAt).catch(() => setLoadError(true));
1737
2313
  }, [startAt, posterTs]);
1738
- useEffect3(() => {
2314
+ useEffect4(() => {
1739
2315
  if (ctl.current && name) ctl.current.camName = name;
1740
2316
  }, [name]);
1741
- useEffect3(() => {
2317
+ useEffect4(() => {
1742
2318
  const i = setInterval(() => {
1743
2319
  const ok = todayRefreshAllowed({
1744
2320
  hidden: document.visibilityState === "hidden",
@@ -1762,11 +2338,11 @@ function CameraPage(p) {
1762
2338
  [merged.events, filterOff]
1763
2339
  );
1764
2340
  const dayCount = useMemo2(() => eventsOnDay(visEvents, centerDay), [visEvents, centerDay]);
1765
- const goLive = useCallback(() => {
2341
+ const goLive = useCallback2(() => {
1766
2342
  ctl.current?.goLive();
1767
2343
  setJump({ ts: Date.now(), n: Date.now() });
1768
2344
  }, []);
1769
- const playEvent = useCallback((ev) => {
2345
+ const playEvent = useCallback2((ev) => {
1770
2346
  const c = ctl.current;
1771
2347
  if (!c) return;
1772
2348
  setTab("tl");
@@ -1774,7 +2350,7 @@ function CameraPage(p) {
1774
2350
  c.posterEvent(ev.timestamp);
1775
2351
  c.playAt(sentinelEventPlayTs(ev), {});
1776
2352
  }, []);
1777
- const seekTo = useCallback(
2353
+ const seekTo = useCallback2(
1778
2354
  (ts) => {
1779
2355
  const c = ctl.current;
1780
2356
  if (!c) return;
@@ -1787,7 +2363,7 @@ function CameraPage(p) {
1787
2363
  },
1788
2364
  [goLive]
1789
2365
  );
1790
- const jumpEvent = useCallback(
2366
+ const jumpEvent = useCallback2(
1791
2367
  (dir) => {
1792
2368
  const c = ctl.current;
1793
2369
  if (!c) return;
@@ -1807,7 +2383,7 @@ function CameraPage(p) {
1807
2383
  },
1808
2384
  [visEvents, playEvent]
1809
2385
  );
1810
- const goToDay = useCallback(
2386
+ const goToDay = useCallback2(
1811
2387
  async (ds, at2) => {
1812
2388
  const c = ctl.current;
1813
2389
  if (!c) return;
@@ -1833,6 +2409,80 @@ function CameraPage(p) {
1833
2409
  },
1834
2410
  [ensureDay, camId, goLive, mergedNow]
1835
2411
  );
2412
+ const canExport = useMemo2(() => Object.values(days).some((d) => sentinelHasFeature(d, "export")), [days]);
2413
+ const oldestRec = earliest ?? merged.clips[0]?.startTime;
2414
+ const clipEvent = useCallback2(
2415
+ (ev) => {
2416
+ const now = Date.now();
2417
+ const r = clipRangeForEvent(ev, now);
2418
+ setClip({ ...clampClipRange(r, { now, oldest: oldestRec }), open: r.open });
2419
+ setClipEdge(null);
2420
+ setTab("tl");
2421
+ const c = ctl.current;
2422
+ if (!c) return;
2423
+ c.freezeCurrent();
2424
+ c.posterEvent(ev.timestamp);
2425
+ c.playAt(Math.max(r.from, oldestRec ?? -Infinity), {});
2426
+ },
2427
+ [oldestRec]
2428
+ );
2429
+ const closeClip = useCallback2(() => {
2430
+ setClip(null);
2431
+ setClipEdge(null);
2432
+ }, []);
2433
+ const toggleClip = useCallback2(() => {
2434
+ if (clipRef.current) {
2435
+ closeClip();
2436
+ return;
2437
+ }
2438
+ const s = psRef.current;
2439
+ setClip(
2440
+ clipProposal({
2441
+ live: s.live,
2442
+ playhead: s.live ? null : ctl.current?.currentTs() ?? s.playhead,
2443
+ now: Date.now(),
2444
+ events: visEvents,
2445
+ oldest: oldestRec
2446
+ })
2447
+ );
2448
+ setClipEdge(null);
2449
+ setTab("tl");
2450
+ }, [closeClip, visEvents, oldestRec]);
2451
+ const activateEdge = useCallback2((e) => {
2452
+ setClipEdge(e);
2453
+ const r = clipRef.current;
2454
+ if (!e || !r) return;
2455
+ const ts = e === "from" ? r.from : r.to;
2456
+ setJump({ ts, n: Date.now() });
2457
+ lineTs.current = ts;
2458
+ const c = ctl.current;
2459
+ if (c && ts < Date.now() - 8e3) {
2460
+ c.freezeCurrent();
2461
+ c.playAt(ts, {});
2462
+ }
2463
+ }, []);
2464
+ const onUserCenter = useCallback2((ts) => {
2465
+ lineTs.current = ts;
2466
+ const e = clipEdgeRef.current, r = clipRef.current;
2467
+ if (!e || !r) return;
2468
+ const n = clipSetEdge(r, e, ts);
2469
+ setClip({ ...n.range, open: false });
2470
+ if (n.edge !== e) setClipEdge(n.edge);
2471
+ }, []);
2472
+ const setEdgeToLine = useCallback2((e) => {
2473
+ const r = clipRef.current;
2474
+ if (!r) return;
2475
+ const s = psRef.current;
2476
+ const ts = clipEdgeRef.current ? lineTs.current : s.live ? Date.now() : ctl.current?.currentTs() ?? lineTs.current;
2477
+ if (ts == null) return;
2478
+ const n = clipSetEdge(r, e, ts);
2479
+ setClip({ ...n.range, open: false });
2480
+ if (clipEdgeRef.current) setClipEdge(n.edge);
2481
+ }, []);
2482
+ const onTimelineEvent = useCallback2(
2483
+ (ev) => clipRef.current ? clipEvent(ev) : playEvent(ev),
2484
+ [clipEvent, playEvent]
2485
+ );
1836
2486
  const scrub = useMemo2(
1837
2487
  () => ({
1838
2488
  begin: () => {
@@ -1858,11 +2508,17 @@ function CameraPage(p) {
1858
2508
  }),
1859
2509
  []
1860
2510
  );
1861
- useEffect3(() => {
2511
+ useEffect4(() => {
1862
2512
  const k = (e) => {
1863
2513
  if (dt || !shouldHandleKey(e)) return;
1864
2514
  const c = ctl.current;
1865
2515
  if (!c) return;
2516
+ if (clipRef.current && (e.key === "Escape" || e.key === "i" || e.key === "o")) {
2517
+ e.preventDefault();
2518
+ if (e.key === "Escape") closeClip();
2519
+ else setEdgeToLine(e.key === "i" ? "from" : "to");
2520
+ return;
2521
+ }
1866
2522
  if (e.key === " ") {
1867
2523
  e.preventDefault();
1868
2524
  c.togglePlayPause();
@@ -1877,7 +2533,7 @@ function CameraPage(p) {
1877
2533
  };
1878
2534
  document.addEventListener("keydown", k);
1879
2535
  return () => document.removeEventListener("keydown", k);
1880
- }, [dt, jumpEvent, goLive]);
2536
+ }, [dt, jumpEvent, goLive, closeClip, setEdgeToLine]);
1881
2537
  const mjpeg = ps.transport === "mjpeg";
1882
2538
  const oldestAllowed = earliest ? sentinelDayOf(earliest) : -Infinity;
1883
2539
  const statusText = stageStatus(ps, t, locale, loadError);
@@ -1886,15 +2542,15 @@ function CameraPage(p) {
1886
2542
  const at = !ps.live && ps.playhead != null ? ps.playhead : void 0;
1887
2543
  const header = typeof p.header === "function" ? p.header(at) : p.header;
1888
2544
  const externalUrl = typeof p.externalUrl === "function" ? p.externalUrl(at) : p.externalUrl;
1889
- return /* @__PURE__ */ jsxs7("div", { className: "nvr-cam", children: [
2545
+ return /* @__PURE__ */ jsxs8("div", { className: "nvr-cam", children: [
1890
2546
  header,
1891
- /* @__PURE__ */ jsxs7("div", { className: "nvr-cam__body", ref: body, children: [
1892
- /* @__PURE__ */ jsx9("div", { className: "nvr-cam__left", children: /* @__PURE__ */ jsxs7("div", { className: "nvr-card nvr-stage-card", children: [
1893
- /* @__PURE__ */ jsx9("div", { className: "nvr-stage-wrap", children: /* @__PURE__ */ jsxs7("div", { className: "nvr-stage", ref: stage, children: [
1894
- /* @__PURE__ */ jsx9("video", { ref: video, playsInline: true, autoPlay: true, muted: true, crossOrigin: cors, className: "nvr-stage__video" }),
1895
- /* @__PURE__ */ jsx9("img", { ref: img, crossOrigin: cors, className: "nvr-stage__video nvr-stage__img hidden", alt: "" }),
1896
- /* @__PURE__ */ jsx9("canvas", { ref: freeze, className: "nvr-stage__video nvr-stage__freeze hidden" }),
1897
- !mjpeg && /* @__PURE__ */ jsx9(
2547
+ /* @__PURE__ */ jsxs8("div", { className: "nvr-cam__body" + (clip ? " nvr-cam__body--clip" : ""), ref: body, children: [
2548
+ /* @__PURE__ */ jsx10("div", { className: "nvr-cam__left", children: /* @__PURE__ */ jsxs8("div", { className: "nvr-card nvr-stage-card", children: [
2549
+ /* @__PURE__ */ jsx10("div", { className: "nvr-stage-wrap", children: /* @__PURE__ */ jsxs8("div", { className: "nvr-stage", ref: stage, children: [
2550
+ /* @__PURE__ */ jsx10("video", { ref: video, playsInline: true, autoPlay: true, muted: true, crossOrigin: cors, className: "nvr-stage__video" }),
2551
+ /* @__PURE__ */ jsx10("img", { ref: img, crossOrigin: cors, className: "nvr-stage__video nvr-stage__img hidden", alt: "" }),
2552
+ /* @__PURE__ */ jsx10("canvas", { ref: freeze, className: "nvr-stage__video nvr-stage__freeze hidden" }),
2553
+ !mjpeg && /* @__PURE__ */ jsx10(
1898
2554
  "button",
1899
2555
  {
1900
2556
  type: "button",
@@ -1902,21 +2558,21 @@ function CameraPage(p) {
1902
2558
  "aria-label": t("nvr.player.sound"),
1903
2559
  "aria-pressed": ps.sound,
1904
2560
  onClick: () => ctl.current?.setSound(!ps.sound),
1905
- children: ps.sound && !ps.muted ? /* @__PURE__ */ jsx9(Volume2, { size: 18 }) : /* @__PURE__ */ jsx9(VolumeX, { size: 18 })
2561
+ children: ps.sound && !ps.muted ? /* @__PURE__ */ jsx10(Volume2, { size: 18 }) : /* @__PURE__ */ jsx10(VolumeX, { size: 18 })
1906
2562
  }
1907
2563
  ),
1908
- /* @__PURE__ */ jsxs7("div", { className: "nvr-pill-ctl" + (ps.live ? " nvr-pill-ctl--live" : ""), children: [
1909
- /* @__PURE__ */ jsx9(
2564
+ /* @__PURE__ */ jsxs8("div", { className: "nvr-pill-ctl" + (ps.live ? " nvr-pill-ctl--live" : ""), children: [
2565
+ /* @__PURE__ */ jsx10(
1910
2566
  "button",
1911
2567
  {
1912
2568
  type: "button",
1913
2569
  className: "nvr-pb",
1914
2570
  "aria-label": t("nvr.player.back15"),
1915
2571
  onClick: () => ctl.current?.skip(-15e3),
1916
- children: /* @__PURE__ */ jsx9(Rewind, { size: 18 })
2572
+ children: /* @__PURE__ */ jsx10(Rewind, { size: 18 })
1917
2573
  }
1918
2574
  ),
1919
- /* @__PURE__ */ jsx9(
2575
+ /* @__PURE__ */ jsx10(
1920
2576
  "button",
1921
2577
  {
1922
2578
  type: "button",
@@ -1924,10 +2580,10 @@ function CameraPage(p) {
1924
2580
  "aria-label": ps.paused ? t("nvr.player.play") : t("nvr.player.pause"),
1925
2581
  disabled: ps.live,
1926
2582
  onClick: () => ctl.current?.togglePlayPause(),
1927
- children: ps.paused ? /* @__PURE__ */ jsx9(Play, { size: 18 }) : /* @__PURE__ */ jsx9(Pause, { size: 18 })
2583
+ children: ps.paused ? /* @__PURE__ */ jsx10(Play, { size: 18 }) : /* @__PURE__ */ jsx10(Pause, { size: 18 })
1928
2584
  }
1929
2585
  ),
1930
- /* @__PURE__ */ jsx9(
2586
+ /* @__PURE__ */ jsx10(
1931
2587
  "button",
1932
2588
  {
1933
2589
  type: "button",
@@ -1935,10 +2591,10 @@ function CameraPage(p) {
1935
2591
  "aria-label": t("nvr.player.fwd15"),
1936
2592
  disabled: ps.live,
1937
2593
  onClick: () => ctl.current?.skip(15e3),
1938
- children: /* @__PURE__ */ jsx9(FastForward, { size: 18 })
2594
+ children: /* @__PURE__ */ jsx10(FastForward, { size: 18 })
1939
2595
  }
1940
2596
  ),
1941
- /* @__PURE__ */ jsxs7(
2597
+ /* @__PURE__ */ jsxs8(
1942
2598
  "button",
1943
2599
  {
1944
2600
  type: "button",
@@ -1954,39 +2610,51 @@ function CameraPage(p) {
1954
2610
  )
1955
2611
  ] })
1956
2612
  ] }) }),
1957
- /* @__PURE__ */ jsxs7("div", { className: "nvr-stage-bar", children: [
1958
- /* @__PURE__ */ jsx9("span", { className: "nvr-statusdot" + (ps.live ? " nvr-statusdot--live" : ""), "aria-hidden": "true" }),
1959
- /* @__PURE__ */ jsxs7("span", { className: "nvr-stage-title", children: [
1960
- /* @__PURE__ */ jsx9("b", { children: name }),
1961
- /* @__PURE__ */ jsx9("small", { children: statusText })
2613
+ /* @__PURE__ */ jsxs8("div", { className: "nvr-stage-bar", children: [
2614
+ /* @__PURE__ */ jsx10("span", { className: "nvr-statusdot" + (ps.live ? " nvr-statusdot--live" : ""), "aria-hidden": "true" }),
2615
+ /* @__PURE__ */ jsxs8("span", { className: "nvr-stage-title", children: [
2616
+ /* @__PURE__ */ jsx10("b", { children: name }),
2617
+ /* @__PURE__ */ jsx10("small", { children: statusText })
1962
2618
  ] }),
1963
- /* @__PURE__ */ jsxs7("span", { className: "nvr-stage-actions", children: [
1964
- /* @__PURE__ */ jsx9(
2619
+ /* @__PURE__ */ jsxs8("span", { className: "nvr-stage-actions", children: [
2620
+ /* @__PURE__ */ jsx10(
1965
2621
  "button",
1966
2622
  {
1967
2623
  type: "button",
1968
2624
  className: "nvr-iconbtn",
1969
2625
  "aria-label": t("nvr.player.snapshot"),
1970
2626
  onClick: () => ctl.current?.snapshot(),
1971
- children: /* @__PURE__ */ jsx9(Camera2, { size: 16 })
2627
+ children: /* @__PURE__ */ jsx10(Camera2, { size: 16 })
2628
+ }
2629
+ ),
2630
+ canExport && /* @__PURE__ */ jsx10(
2631
+ "button",
2632
+ {
2633
+ type: "button",
2634
+ className: "nvr-iconbtn" + (clip ? " nvr-iconbtn--on" : ""),
2635
+ "aria-label": t("nvr.clip.download"),
2636
+ title: t("nvr.clip.download"),
2637
+ "aria-pressed": !!clip,
2638
+ onClick: toggleClip,
2639
+ children: /* @__PURE__ */ jsx10(Download2, { size: 16 })
1972
2640
  }
1973
2641
  ),
1974
- /* @__PURE__ */ jsx9("button", { type: "button", className: "nvr-iconbtn", "aria-label": t("nvr.player.pip"), onClick: onPip, children: /* @__PURE__ */ jsx9(PictureInPicture2, { size: 16 }) }),
1975
- /* @__PURE__ */ jsx9(
2642
+ /* @__PURE__ */ jsx10("button", { type: "button", className: "nvr-iconbtn", "aria-label": t("nvr.player.pip"), onClick: onPip, children: /* @__PURE__ */ jsx10(PictureInPicture2, { size: 16 }) }),
2643
+ /* @__PURE__ */ jsx10(
1976
2644
  "button",
1977
2645
  {
1978
2646
  type: "button",
1979
2647
  className: "nvr-iconbtn",
1980
2648
  "aria-label": t("nvr.player.fullscreen"),
1981
2649
  onClick: () => ctl.current?.fullscreen(),
1982
- children: /* @__PURE__ */ jsx9(Maximize2, { size: 16 })
2650
+ children: /* @__PURE__ */ jsx10(Maximize2, { size: 16 })
1983
2651
  }
1984
2652
  )
1985
2653
  ] })
1986
2654
  ] }),
1987
- pipNote && /* @__PURE__ */ jsxs7("div", { className: "nvr-pipnote", role: "status", children: [
1988
- /* @__PURE__ */ jsx9("span", { children: t(pipNote === "homescreen" ? "nvr.player.pipHomeScreen" : "nvr.player.pipUnsupported") }),
1989
- pipNote === "homescreen" && externalUrl && /* @__PURE__ */ jsx9(
2655
+ pipNote && /* @__PURE__ */ jsxs8("div", { className: "nvr-pipnote", role: "status", children: [
2656
+ /* @__PURE__ */ jsx10("span", { children: t(pipNote === "homescreen" ? "nvr.player.pipHomeScreen" : "nvr.player.pipUnsupported") }),
2657
+ pipNote === "homescreen" && externalUrl && /* @__PURE__ */ jsx10(
1990
2658
  "a",
1991
2659
  {
1992
2660
  className: "nvr-pipnote__open",
@@ -1997,21 +2665,21 @@ function CameraPage(p) {
1997
2665
  children: t("nvr.player.openInSafari")
1998
2666
  }
1999
2667
  ),
2000
- /* @__PURE__ */ jsx9(
2668
+ /* @__PURE__ */ jsx10(
2001
2669
  "button",
2002
2670
  {
2003
2671
  type: "button",
2004
2672
  className: "nvr-iconbtn nvr-pipnote__close",
2005
2673
  "aria-label": t("nvr.player.dismiss"),
2006
2674
  onClick: () => setPipNote(null),
2007
- children: /* @__PURE__ */ jsx9(X, { size: 14 })
2675
+ children: /* @__PURE__ */ jsx10(X2, { size: 14 })
2008
2676
  }
2009
2677
  )
2010
2678
  ] })
2011
2679
  ] }) }),
2012
- /* @__PURE__ */ jsxs7("aside", { className: "nvr-card nvr-cam__right", children: [
2013
- /* @__PURE__ */ jsxs7("div", { className: "nvr-tabs", role: "tablist", children: [
2014
- /* @__PURE__ */ jsx9(
2680
+ /* @__PURE__ */ jsxs8("aside", { className: "nvr-card nvr-cam__right" + (clip ? " nvr-cam__right--clip" : ""), children: [
2681
+ /* @__PURE__ */ jsxs8("div", { className: "nvr-tabs", role: "tablist", children: [
2682
+ /* @__PURE__ */ jsx10(
2015
2683
  "button",
2016
2684
  {
2017
2685
  type: "button",
@@ -2022,7 +2690,7 @@ function CameraPage(p) {
2022
2690
  children: t("nvr.tab.timeline")
2023
2691
  }
2024
2692
  ),
2025
- /* @__PURE__ */ jsxs7(
2693
+ /* @__PURE__ */ jsxs8(
2026
2694
  "button",
2027
2695
  {
2028
2696
  type: "button",
@@ -2037,7 +2705,7 @@ function CameraPage(p) {
2037
2705
  }
2038
2706
  )
2039
2707
  ] }),
2040
- /* @__PURE__ */ jsx9("div", { className: "nvr-filters", children: SENTINEL_EVENT_CLASSES.filter((k) => present[k]).map((k) => /* @__PURE__ */ jsxs7(
2708
+ /* @__PURE__ */ jsx10("div", { className: "nvr-filters", children: SENTINEL_EVENT_CLASSES.filter((k) => present[k]).map((k) => /* @__PURE__ */ jsxs8(
2041
2709
  "button",
2042
2710
  {
2043
2711
  type: "button",
@@ -2046,13 +2714,13 @@ function CameraPage(p) {
2046
2714
  title: classLabel(t, k),
2047
2715
  "aria-pressed": !filterOff[k],
2048
2716
  children: [
2049
- /* @__PURE__ */ jsx9(ClassBadge, { cls: k, size: 18 }),
2717
+ /* @__PURE__ */ jsx10(ClassBadge, { cls: k, size: 18 }),
2050
2718
  present[k]
2051
2719
  ]
2052
2720
  },
2053
2721
  k
2054
2722
  )) }),
2055
- tab === "tl" ? /* @__PURE__ */ jsx9(
2723
+ tab === "tl" ? /* @__PURE__ */ jsx10(
2056
2724
  VerticalTimeline,
2057
2725
  {
2058
2726
  camId,
@@ -2065,26 +2733,51 @@ function CameraPage(p) {
2065
2733
  playhead: () => ctl.current?.currentTs() ?? null,
2066
2734
  following: () => !psRef.current.paused && !ctl.current?.scrubSettling(),
2067
2735
  filterOff,
2068
- onEvent: playEvent,
2736
+ onEvent: onTimelineEvent,
2069
2737
  onSeekTo: seekTo,
2070
2738
  onGoLive: goLive,
2071
2739
  scrub,
2072
2740
  onCenter,
2073
- jump
2741
+ jump,
2742
+ clip: clip ? { from: clip.from, to: clip.to, edge: clipEdge, bad: clip.to - clip.from > CLIP_MAX_MS } : null,
2743
+ hold: !!clip && !!clipEdge,
2744
+ onUserCenter
2745
+ }
2746
+ ) : /* @__PURE__ */ jsx10(
2747
+ EventList,
2748
+ {
2749
+ camId,
2750
+ events: merged.events,
2751
+ filterOff,
2752
+ onPick: playEvent,
2753
+ onClip: canExport ? clipEvent : void 0
2074
2754
  }
2075
- ) : /* @__PURE__ */ jsx9(EventList, { camId, events: merged.events, filterOff, onPick: playEvent }),
2076
- /* @__PURE__ */ jsxs7("div", { className: "nvr-datechip" + (ps.live ? "" : " nvr-datechip--rec"), children: [
2077
- /* @__PURE__ */ jsx9(
2755
+ ),
2756
+ clip && /* @__PURE__ */ jsx10(
2757
+ ClipBar,
2758
+ {
2759
+ camId,
2760
+ range: clip,
2761
+ open: clip.open,
2762
+ edge: clipEdge,
2763
+ clips: merged.clips,
2764
+ onEdge: activateEdge,
2765
+ onClose: closeClip
2766
+ },
2767
+ camId
2768
+ ),
2769
+ !clip && /* @__PURE__ */ jsxs8("div", { className: "nvr-datechip" + (ps.live ? "" : " nvr-datechip--rec"), children: [
2770
+ /* @__PURE__ */ jsx10(
2078
2771
  "button",
2079
2772
  {
2080
2773
  type: "button",
2081
2774
  onClick: () => goToDay(sentinelAddDays(centerDay, -1)).catch(() => setLoadError(true)),
2082
2775
  disabled: nav.prevDisabled,
2083
2776
  "aria-label": t("nvr.date.prevDay"),
2084
- children: /* @__PURE__ */ jsx9(ChevronLeft2, { size: 14 })
2777
+ children: /* @__PURE__ */ jsx10(ChevronLeft2, { size: 14 })
2085
2778
  }
2086
2779
  ),
2087
- /* @__PURE__ */ jsxs7(
2780
+ /* @__PURE__ */ jsxs8(
2088
2781
  "button",
2089
2782
  {
2090
2783
  type: "button",
@@ -2092,19 +2785,19 @@ function CameraPage(p) {
2092
2785
  onClick: () => setDt(true),
2093
2786
  "aria-label": t("nvr.date.title"),
2094
2787
  children: [
2095
- /* @__PURE__ */ jsx9(Calendar, { size: 13 }),
2788
+ /* @__PURE__ */ jsx10(Calendar, { size: 13 }),
2096
2789
  fmtDay(centerDay, locale)
2097
2790
  ]
2098
2791
  }
2099
2792
  ),
2100
- /* @__PURE__ */ jsx9(
2793
+ /* @__PURE__ */ jsx10(
2101
2794
  "button",
2102
2795
  {
2103
2796
  type: "button",
2104
2797
  onClick: () => goToDay(sentinelAddDays(centerDay, 1)).catch(() => setLoadError(true)),
2105
2798
  disabled: nav.nextDisabled,
2106
2799
  "aria-label": t("nvr.date.nextDay"),
2107
- children: /* @__PURE__ */ jsx9(ChevronRight2, { size: 14 })
2800
+ children: /* @__PURE__ */ jsx10(ChevronRight2, { size: 14 })
2108
2801
  }
2109
2802
  )
2110
2803
  ] })
@@ -2125,9 +2818,9 @@ function CameraPage(p) {
2125
2818
  }
2126
2819
 
2127
2820
  // src/ui/components/Appearance.tsx
2128
- import { useState as useState5 } from "react";
2821
+ import { useState as useState6 } from "react";
2129
2822
  import { ChevronDown, Languages, Palette, Sun } from "lucide-react";
2130
- import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
2823
+ import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
2131
2824
  function hexHue(hex) {
2132
2825
  const r = parseInt(hex.slice(1, 3), 16) / 255, g = parseInt(hex.slice(3, 5), 16) / 255, b = parseInt(hex.slice(5, 7), 16) / 255;
2133
2826
  const max = Math.max(r, g, b), min = Math.min(r, g, b);
@@ -2147,7 +2840,7 @@ function ThemeSwatch({
2147
2840
  ariaLabel
2148
2841
  }) {
2149
2842
  const c = THEMES[name][previewMode];
2150
- return /* @__PURE__ */ jsxs8(
2843
+ return /* @__PURE__ */ jsxs9(
2151
2844
  "button",
2152
2845
  {
2153
2846
  type: "button",
@@ -2156,8 +2849,8 @@ function ThemeSwatch({
2156
2849
  "aria-label": ariaLabel,
2157
2850
  "aria-pressed": active,
2158
2851
  children: [
2159
- /* @__PURE__ */ jsxs8("div", { className: "nvr-swatch__preview", style: { background: c.bg }, "aria-hidden": "true", children: [
2160
- /* @__PURE__ */ jsx10(
2852
+ /* @__PURE__ */ jsxs9("div", { className: "nvr-swatch__preview", style: { background: c.bg }, "aria-hidden": "true", children: [
2853
+ /* @__PURE__ */ jsx11(
2161
2854
  "div",
2162
2855
  {
2163
2856
  style: {
@@ -2172,7 +2865,7 @@ function ThemeSwatch({
2172
2865
  }
2173
2866
  }
2174
2867
  ),
2175
- /* @__PURE__ */ jsx10(
2868
+ /* @__PURE__ */ jsx11(
2176
2869
  "div",
2177
2870
  {
2178
2871
  style: {
@@ -2186,7 +2879,7 @@ function ThemeSwatch({
2186
2879
  }
2187
2880
  }
2188
2881
  ),
2189
- /* @__PURE__ */ jsx10(
2882
+ /* @__PURE__ */ jsx11(
2190
2883
  "div",
2191
2884
  {
2192
2885
  style: {
@@ -2201,7 +2894,7 @@ function ThemeSwatch({
2201
2894
  }
2202
2895
  }
2203
2896
  ),
2204
- /* @__PURE__ */ jsx10(
2897
+ /* @__PURE__ */ jsx11(
2205
2898
  "div",
2206
2899
  {
2207
2900
  style: {
@@ -2217,7 +2910,7 @@ function ThemeSwatch({
2217
2910
  }
2218
2911
  )
2219
2912
  ] }),
2220
- /* @__PURE__ */ jsx10("span", { className: "nvr-swatch__name", children: THEME_LABELS[name] })
2913
+ /* @__PURE__ */ jsx11("span", { className: "nvr-swatch__name", children: THEME_LABELS[name] })
2221
2914
  ]
2222
2915
  }
2223
2916
  );
@@ -2226,19 +2919,19 @@ function AppearanceSection(p) {
2226
2919
  const { t } = useSentinelUi();
2227
2920
  const resolved = resolveMode(p.mode);
2228
2921
  const defaultHue = (name) => hexHue(THEMES[name][resolved].accent);
2229
- const [localHue, setLocalHue] = useState5(p.accentHue ?? defaultHue(p.theme));
2922
+ const [localHue, setLocalHue] = useState6(p.accentHue ?? defaultHue(p.theme));
2230
2923
  const previewColor = p.accentHue !== void 0 ? `hsl(${p.accentHue}, 78%, ${resolved === "dark" ? 60 : 50}%)` : THEMES[p.theme][resolved].accent;
2231
2924
  const modes = ["light", "dark", "auto"];
2232
- const chip = (bg, fg, icon) => /* @__PURE__ */ jsx10("span", { className: "nvr-set__chip", style: { background: bg, color: fg }, children: icon });
2233
- return /* @__PURE__ */ jsxs8("section", { className: "nvr-set__section", children: [
2234
- /* @__PURE__ */ jsx10("div", { className: "nvr-section__label", children: t("nvr.settings.appearance") }),
2235
- /* @__PURE__ */ jsxs8("div", { className: "nvr-card nvr-set-card", children: [
2236
- /* @__PURE__ */ jsxs8("div", { className: "nvr-set__row nvr-set__row--inline", children: [
2237
- /* @__PURE__ */ jsxs8("span", { className: "nvr-set__label", children: [
2238
- chip("var(--warning-soft)", "var(--warning)", /* @__PURE__ */ jsx10(Sun, { size: 14, strokeWidth: 1.75 })),
2925
+ const chip = (bg, fg, icon) => /* @__PURE__ */ jsx11("span", { className: "nvr-set__chip", style: { background: bg, color: fg }, children: icon });
2926
+ return /* @__PURE__ */ jsxs9("section", { className: "nvr-set__section", children: [
2927
+ /* @__PURE__ */ jsx11("div", { className: "nvr-section__label", children: t("nvr.settings.appearance") }),
2928
+ /* @__PURE__ */ jsxs9("div", { className: "nvr-card nvr-set-card", children: [
2929
+ /* @__PURE__ */ jsxs9("div", { className: "nvr-set__row nvr-set__row--inline", children: [
2930
+ /* @__PURE__ */ jsxs9("span", { className: "nvr-set__label", children: [
2931
+ chip("var(--warning-soft)", "var(--warning)", /* @__PURE__ */ jsx11(Sun, { size: 14, strokeWidth: 1.75 })),
2239
2932
  t("nvr.settings.mode")
2240
2933
  ] }),
2241
- /* @__PURE__ */ jsx10("div", { className: "nvr-seg", role: "group", "aria-label": t("nvr.settings.mode"), children: modes.map((m) => /* @__PURE__ */ jsx10(
2934
+ /* @__PURE__ */ jsx11("div", { className: "nvr-seg", role: "group", "aria-label": t("nvr.settings.mode"), children: modes.map((m) => /* @__PURE__ */ jsx11(
2242
2935
  "button",
2243
2936
  {
2244
2937
  type: "button",
@@ -2250,13 +2943,13 @@ function AppearanceSection(p) {
2250
2943
  m
2251
2944
  )) })
2252
2945
  ] }),
2253
- /* @__PURE__ */ jsxs8("div", { className: "nvr-set__row nvr-set__row--inline", children: [
2254
- /* @__PURE__ */ jsxs8("span", { className: "nvr-set__label", children: [
2255
- chip("var(--accent-soft)", "var(--accent)", /* @__PURE__ */ jsx10(Languages, { size: 14, strokeWidth: 1.75 })),
2946
+ /* @__PURE__ */ jsxs9("div", { className: "nvr-set__row nvr-set__row--inline", children: [
2947
+ /* @__PURE__ */ jsxs9("span", { className: "nvr-set__label", children: [
2948
+ chip("var(--accent-soft)", "var(--accent)", /* @__PURE__ */ jsx11(Languages, { size: 14, strokeWidth: 1.75 })),
2256
2949
  t("nvr.settings.language")
2257
2950
  ] }),
2258
- /* @__PURE__ */ jsxs8("div", { className: "nvr-select", children: [
2259
- /* @__PURE__ */ jsxs8(
2951
+ /* @__PURE__ */ jsxs9("div", { className: "nvr-select", children: [
2952
+ /* @__PURE__ */ jsxs9(
2260
2953
  "select",
2261
2954
  {
2262
2955
  className: "nvr-select__native",
@@ -2264,20 +2957,20 @@ function AppearanceSection(p) {
2264
2957
  onChange: (e) => p.onLanguage(e.target.value),
2265
2958
  "aria-label": t("nvr.settings.language"),
2266
2959
  children: [
2267
- /* @__PURE__ */ jsx10("option", { value: "auto", children: t("nvr.settings.language.auto") }),
2268
- p.languages.map((l) => /* @__PURE__ */ jsx10("option", { value: l.id, children: l.label }, l.id))
2960
+ /* @__PURE__ */ jsx11("option", { value: "auto", children: t("nvr.settings.language.auto") }),
2961
+ p.languages.map((l) => /* @__PURE__ */ jsx11("option", { value: l.id, children: l.label }, l.id))
2269
2962
  ]
2270
2963
  }
2271
2964
  ),
2272
- /* @__PURE__ */ jsx10(ChevronDown, { size: 14, strokeWidth: 2, className: "nvr-select__chevron", "aria-hidden": "true" })
2965
+ /* @__PURE__ */ jsx11(ChevronDown, { size: 14, strokeWidth: 2, className: "nvr-select__chevron", "aria-hidden": "true" })
2273
2966
  ] })
2274
2967
  ] }),
2275
- /* @__PURE__ */ jsxs8("div", { className: "nvr-set__row", children: [
2276
- /* @__PURE__ */ jsxs8("div", { className: "nvr-set__label", children: [
2277
- chip("var(--accent-soft)", "var(--accent)", /* @__PURE__ */ jsx10(Palette, { size: 14, strokeWidth: 1.75 })),
2968
+ /* @__PURE__ */ jsxs9("div", { className: "nvr-set__row", children: [
2969
+ /* @__PURE__ */ jsxs9("div", { className: "nvr-set__label", children: [
2970
+ chip("var(--accent-soft)", "var(--accent)", /* @__PURE__ */ jsx11(Palette, { size: 14, strokeWidth: 1.75 })),
2278
2971
  t("nvr.settings.theme")
2279
2972
  ] }),
2280
- /* @__PURE__ */ jsx10("div", { className: "nvr-swatches", children: THEME_NAMES.map((n) => /* @__PURE__ */ jsx10(
2973
+ /* @__PURE__ */ jsx11("div", { className: "nvr-swatches", children: THEME_NAMES.map((n) => /* @__PURE__ */ jsx11(
2281
2974
  ThemeSwatch,
2282
2975
  {
2283
2976
  name: n,
@@ -2292,14 +2985,14 @@ function AppearanceSection(p) {
2292
2985
  n
2293
2986
  )) })
2294
2987
  ] }),
2295
- /* @__PURE__ */ jsx10("div", { className: "nvr-set__row", children: /* @__PURE__ */ jsxs8("div", { className: "nvr-accent", children: [
2296
- /* @__PURE__ */ jsxs8("div", { className: "nvr-accent__label", children: [
2297
- /* @__PURE__ */ jsxs8("span", { className: "nvr-set__label", children: [
2298
- chip("var(--accent-soft)", "var(--accent)", /* @__PURE__ */ jsx10(Palette, { size: 14, strokeWidth: 1.75 })),
2988
+ /* @__PURE__ */ jsx11("div", { className: "nvr-set__row", children: /* @__PURE__ */ jsxs9("div", { className: "nvr-accent", children: [
2989
+ /* @__PURE__ */ jsxs9("div", { className: "nvr-accent__label", children: [
2990
+ /* @__PURE__ */ jsxs9("span", { className: "nvr-set__label", children: [
2991
+ chip("var(--accent-soft)", "var(--accent)", /* @__PURE__ */ jsx11(Palette, { size: 14, strokeWidth: 1.75 })),
2299
2992
  t("nvr.settings.accent"),
2300
- /* @__PURE__ */ jsx10("span", { className: "nvr-accent__dot", style: { background: previewColor }, "aria-hidden": "true" })
2993
+ /* @__PURE__ */ jsx11("span", { className: "nvr-accent__dot", style: { background: previewColor }, "aria-hidden": "true" })
2301
2994
  ] }),
2302
- p.accentHue !== void 0 && /* @__PURE__ */ jsx10(
2995
+ p.accentHue !== void 0 && /* @__PURE__ */ jsx11(
2303
2996
  "button",
2304
2997
  {
2305
2998
  type: "button",
@@ -2312,7 +3005,7 @@ function AppearanceSection(p) {
2312
3005
  }
2313
3006
  )
2314
3007
  ] }),
2315
- /* @__PURE__ */ jsx10(
3008
+ /* @__PURE__ */ jsx11(
2316
3009
  "input",
2317
3010
  {
2318
3011
  type: "range",