@sentinel-nvr/web 0.16.5 → 0.16.7

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,8 +1,9 @@
1
1
  import {
2
2
  PlayerController,
3
3
  rlog
4
- } from "../chunk-R7V2JDTA.js";
4
+ } from "../chunk-QAYPO6TS.js";
5
5
  import {
6
+ SENTINEL_CLASS_PRIORITY,
6
7
  SENTINEL_DAY_MS,
7
8
  SENTINEL_EVENT_CLASSES,
8
9
  fmtDay,
@@ -14,6 +15,7 @@ import {
14
15
  sentinelAtTime,
15
16
  sentinelClassOf,
16
17
  sentinelClassesOf,
18
+ sentinelClipIndexFor,
17
19
  sentinelClipRuns,
18
20
  sentinelDayEnd,
19
21
  sentinelDayOf,
@@ -993,6 +995,45 @@ function StorageCard({ stats }) {
993
995
  // src/ui/components/VerticalTimeline.tsx
994
996
  import { useEffect as useEffect2, useLayoutEffect, useMemo, useRef, useState as useState3 } from "react";
995
997
  import { Plus, Minus, ArrowUp } from "lucide-react";
998
+
999
+ // src/ui/timeline-groups.ts
1000
+ var GROUP_PX = 14;
1001
+ var GROUP_FILL = 0.5;
1002
+ var GROUP_MIN_STEP = 1.7;
1003
+ function groupEvents(eventsNewestFirst, px, gapPx = GROUP_PX) {
1004
+ const out = [];
1005
+ let cur = null;
1006
+ for (const ev of eventsNewestFirst) {
1007
+ if (cur && px > 0 && (cur.newest.timestamp - ev.timestamp) * px < gapPx) {
1008
+ cur.events.push(ev);
1009
+ cur.oldest = ev;
1010
+ continue;
1011
+ }
1012
+ cur = { events: [ev], newest: ev, oldest: ev, cls: "motion" };
1013
+ out.push(cur);
1014
+ }
1015
+ for (const g of out) g.cls = groupClass(g.events);
1016
+ return out;
1017
+ }
1018
+ function groupClass(events) {
1019
+ let best = SENTINEL_CLASS_PRIORITY.length;
1020
+ for (const ev of events) {
1021
+ const i = SENTINEL_CLASS_PRIORITY.indexOf(sentinelClassOf(ev));
1022
+ if (i < best) best = i;
1023
+ }
1024
+ return SENTINEL_CLASS_PRIORITY[best] ?? "motion";
1025
+ }
1026
+ function groupZoomPx(g, px, vh, maxPx) {
1027
+ if (!(px > 0) || px >= maxPx * 0.999) return null;
1028
+ const span = g.newest.timestamp - g.oldest.timestamp;
1029
+ const want = span > 0 ? vh * GROUP_FILL / span : maxPx;
1030
+ return Math.min(maxPx, Math.max(want, px * GROUP_MIN_STEP));
1031
+ }
1032
+ function groupCountLabel(n) {
1033
+ return n > 99 ? "99+" : String(n);
1034
+ }
1035
+
1036
+ // src/ui/components/VerticalTimeline.tsx
996
1037
  import { Fragment as Fragment5, jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
997
1038
  function VerticalTimeline(p) {
998
1039
  const { client, t, locale } = useSentinelUi();
@@ -1275,6 +1316,24 @@ function VerticalTimeline(p) {
1275
1316
  () => p.events.filter((e) => !sentinelEventHidden(e, p.filterOff)).slice().sort((a, b) => b.timestamp - a.timestamp),
1276
1317
  [p.events, p.filterOff]
1277
1318
  );
1319
+ const groups = useMemo(() => groupEvents(vis, px), [vis, px]);
1320
+ const openGroup = (g) => {
1321
+ const npx = groupZoomPx(g, px, vh, maxPx);
1322
+ if (npx == null) {
1323
+ p.onEvent(g.newest);
1324
+ return;
1325
+ }
1326
+ const mid = (g.newest.timestamp + g.oldest.timestamp) / 2;
1327
+ const ts = clampRange(sentinelClipIndexFor(p.clips, mid) >= 0 ? mid : g.newest.timestamp);
1328
+ const v = VT.current;
1329
+ if (!v.user) markUser();
1330
+ applyZoom(npx, ts, vh * HEAD);
1331
+ if (p.onSeekTo) p.onSeekTo(ts);
1332
+ else scrubSeek(ts);
1333
+ clearTimeout(v.holdT);
1334
+ clearTimeout(v.relT);
1335
+ v.relT = window.setTimeout(userIdle, 250);
1336
+ };
1278
1337
  const top = scroll.current?.scrollTop || 0;
1279
1338
  const winStart = tsForY(top + 2 * vh), winEnd = tsForY(top - vh);
1280
1339
  const inWin = (a, b = a) => b >= winStart && a <= winEnd;
@@ -1321,26 +1380,41 @@ function VerticalTimeline(p) {
1321
1380
  p.motion.map(
1322
1381
  (m, i) => inWin(m[0], m[1]) && /* @__PURE__ */ jsx8("div", { className: "vmot", style: { top: yFor(m[1]), height: Math.max(4, (m[1] - m[0]) * px) } }, i)
1323
1382
  ),
1324
- vis.map((ev) => {
1325
- if (!inWin(ev.timestamp)) return null;
1383
+ groups.map((g) => {
1384
+ if (!inWin(g.oldest.timestamp, g.newest.timestamp)) return null;
1385
+ const ev = g.newest;
1326
1386
  const y = yFor(ev.timestamp);
1327
- const k = sentinelClassOf(ev);
1387
+ const n = g.events.length;
1388
+ const k = n > 1 ? g.cls : sentinelClassOf(ev);
1328
1389
  const thumb = y - lastThumbY >= thumbGap && px > vh / (8 * 3600 * 1e3);
1329
1390
  if (thumb) lastThumbY = y;
1330
- const sp = sentinelEventSpan(ev, now);
1331
1391
  return /* @__PURE__ */ jsxs6("div", { children: [
1332
- sp && /* @__PURE__ */ jsx8(
1333
- "div",
1392
+ g.events.map((m) => {
1393
+ const sp = sentinelEventSpan(m, now);
1394
+ return sp && /* @__PURE__ */ jsx8(
1395
+ "div",
1396
+ {
1397
+ className: "vspan" + (sp.open ? " vspan--open" : ""),
1398
+ style: {
1399
+ top: yFor(sp.end),
1400
+ height: Math.max(3, (sp.end - sp.start) * px),
1401
+ background: `var(--nvr-c-${sentinelClassOf(m)})`
1402
+ }
1403
+ },
1404
+ m.id
1405
+ );
1406
+ }),
1407
+ n > 1 ? /* @__PURE__ */ jsx8(
1408
+ "button",
1334
1409
  {
1335
- className: "vspan" + (sp.open ? " vspan--open" : ""),
1336
- style: {
1337
- top: yFor(sp.end),
1338
- height: Math.max(3, (sp.end - sp.start) * px),
1339
- background: `var(--nvr-c-${k})`
1340
- }
1410
+ className: "vev vev--group",
1411
+ style: { top: y, background: `var(--nvr-c-${k})` },
1412
+ onClick: () => openGroup(g),
1413
+ "aria-label": `${t("nvr.timeline.zoomIn")}: ${n} \xD7 ${classLabel(t, k)} ${hhmmss(g.oldest.timestamp)}\u2013${hhmmss(ev.timestamp)}`,
1414
+ title: `${n} \xD7 ${hhmmss(g.oldest.timestamp)}\u2013${hhmmss(ev.timestamp)}`,
1415
+ children: groupCountLabel(n)
1341
1416
  }
1342
- ),
1343
- /* @__PURE__ */ jsx8(
1417
+ ) : /* @__PURE__ */ jsx8(
1344
1418
  "button",
1345
1419
  {
1346
1420
  className: "vev" + (thumb ? "" : " vev--minor"),
@@ -1670,6 +1744,19 @@ function CameraPage(p) {
1670
1744
  c.posterEvent(ev.timestamp);
1671
1745
  c.playAt(sentinelEventPlayTs(ev), {});
1672
1746
  }, []);
1747
+ const seekTo = useCallback(
1748
+ (ts) => {
1749
+ const c = ctl.current;
1750
+ if (!c) return;
1751
+ if (Date.now() - ts < 8e3) {
1752
+ goLive();
1753
+ return;
1754
+ }
1755
+ c.freezeCurrent();
1756
+ c.playAt(ts, {});
1757
+ },
1758
+ [goLive]
1759
+ );
1673
1760
  const jumpEvent = useCallback(
1674
1761
  (dir) => {
1675
1762
  const c = ctl.current;
@@ -1946,6 +2033,7 @@ function CameraPage(p) {
1946
2033
  following: () => !psRef.current.paused && !ctl.current?.scrubSettling(),
1947
2034
  filterOff,
1948
2035
  onEvent: playEvent,
2036
+ onSeekTo: seekTo,
1949
2037
  onGoLive: goLive,
1950
2038
  scrub,
1951
2039
  onCenter,