@sentinel-nvr/web 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1109 @@
1
+ import {
2
+ SENTINEL_DAY_MS,
3
+ fmtDay,
4
+ fmtMonthYear,
5
+ fmtTime,
6
+ fmtTimeSec,
7
+ hhmmInput,
8
+ sentinelClassOf,
9
+ sentinelClassesOf,
10
+ sentinelClipRuns,
11
+ sentinelEventPlayTs,
12
+ sentinelHumanBytes,
13
+ sentinelStorageForecast,
14
+ weekdayShorts
15
+ } from "../chunk-VUKE4DDM.js";
16
+ import {
17
+ rlog
18
+ } from "../chunk-VHZTAIPQ.js";
19
+
20
+ // src/ui/context.tsx
21
+ import { createContext, useContext } from "react";
22
+ import { jsx } from "react/jsx-runtime";
23
+ var Ctx = createContext(null);
24
+ function SentinelUiProvider({ value, children }) {
25
+ return /* @__PURE__ */ jsx(Ctx.Provider, { value, children });
26
+ }
27
+ function useSentinelUi() {
28
+ const v = useContext(Ctx);
29
+ if (!v) throw new Error("SentinelUiProvider missing");
30
+ return v;
31
+ }
32
+
33
+ // src/ui/i18n.ts
34
+ var rulesCache = /* @__PURE__ */ new Map();
35
+ function plural(locale) {
36
+ let r = rulesCache.get(locale);
37
+ if (!r) {
38
+ try {
39
+ r = new Intl.PluralRules(locale);
40
+ } catch {
41
+ r = new Intl.PluralRules("en");
42
+ }
43
+ rulesCache.set(locale, r);
44
+ }
45
+ return r;
46
+ }
47
+ function interpolate(s, vars) {
48
+ if (!vars) return s;
49
+ return s.replace(/\{(\w+)\}/g, (m, k) => k in vars ? String(vars[k]) : m);
50
+ }
51
+ function translate(dict, fallback, locale, key, vars) {
52
+ const candidates = [];
53
+ if (typeof vars?.count === "number") {
54
+ candidates.push(`${key}.${plural(locale).select(vars.count)}`, `${key}.other`);
55
+ }
56
+ candidates.push(key);
57
+ for (const c of candidates) {
58
+ const hit = dict[c] ?? fallback[c];
59
+ if (hit !== void 0) return interpolate(hit, vars);
60
+ }
61
+ return key;
62
+ }
63
+ function createT(dict, fallback, locale) {
64
+ return (key, vars) => translate(dict, fallback, locale, key, vars);
65
+ }
66
+ var UI_LOCALES = ["de", "en", "es", "fr", "it", "pt", "sv"];
67
+ function pickLocale(tags) {
68
+ for (const t of tags) {
69
+ const base = t.toLowerCase().split("-")[0];
70
+ if (UI_LOCALES.includes(base)) return base;
71
+ }
72
+ return "en";
73
+ }
74
+
75
+ // src/ui/themes-data.ts
76
+ var THEME_NAMES = ["aurora", "sunset", "ocean", "forest"];
77
+ var THEME_LABELS = {
78
+ aurora: "Aurora",
79
+ sunset: "Sunset",
80
+ ocean: "Ocean",
81
+ forest: "Forest"
82
+ };
83
+ var THEMES = {
84
+ // Aurora — the default: neutral surfaces, warm orange accent (matches mockups)
85
+ aurora: {
86
+ light: {
87
+ bg: "#f3f4f6",
88
+ bgRaised: "#ffffff",
89
+ bgCard: "#ffffff",
90
+ bgCardHover: "#f8f9fb",
91
+ bgSubtle: "#f1f3f5",
92
+ text: "#1a1d23",
93
+ textDim: "#697079",
94
+ textFaint: "#9aa1ab",
95
+ accent: "#f2941c",
96
+ accentSoft: "rgba(242, 148, 28, 0.12)",
97
+ onAccent: "#ffffff",
98
+ line: "rgba(20, 24, 30, 0.07)",
99
+ border: "#e8eaee",
100
+ positive: "#16a34a",
101
+ positiveSoft: "rgba(22, 163, 74, 0.12)",
102
+ warning: "#e59411",
103
+ warningSoft: "rgba(229, 148, 17, 0.12)",
104
+ danger: "#e5484d",
105
+ dangerSoft: "rgba(229, 72, 77, 0.10)",
106
+ info: "#3b82f6",
107
+ infoSoft: "rgba(59, 130, 246, 0.12)",
108
+ shadowCard: "0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06)",
109
+ shadowElevated: "0 12px 32px -8px rgba(16, 24, 40, 0.16)",
110
+ shadowActive: "0 0 0 1px var(--accent-soft), 0 6px 20px -8px rgba(242, 148, 28, 0.30)"
111
+ },
112
+ dark: {
113
+ bg: "#0f1116",
114
+ bgRaised: "#171a21",
115
+ bgCard: "#171a21",
116
+ bgCardHover: "#1e222b",
117
+ bgSubtle: "#22262f",
118
+ text: "#f2f4f7",
119
+ textDim: "#9aa1ad",
120
+ textFaint: "#646b76",
121
+ accent: "#f5a623",
122
+ accentSoft: "rgba(245, 166, 35, 0.16)",
123
+ onAccent: "#1a1205",
124
+ line: "rgba(255, 255, 255, 0.08)",
125
+ border: "rgba(255, 255, 255, 0.09)",
126
+ positive: "#3ad07f",
127
+ positiveSoft: "rgba(58, 208, 127, 0.15)",
128
+ warning: "#f5b53d",
129
+ warningSoft: "rgba(245, 181, 61, 0.15)",
130
+ danger: "#f0686d",
131
+ dangerSoft: "rgba(240, 104, 109, 0.15)",
132
+ info: "#5fa0f5",
133
+ infoSoft: "rgba(95, 160, 245, 0.15)",
134
+ shadowCard: "0 2px 8px -2px rgba(0, 0, 0, 0.5)",
135
+ shadowElevated: "0 16px 40px -12px rgba(0, 0, 0, 0.7)",
136
+ shadowActive: "0 0 0 1px var(--accent-soft), 0 6px 24px -8px rgba(245, 166, 35, 0.30)"
137
+ }
138
+ },
139
+ // Sunset — warm amber identity, warm-tinted surfaces
140
+ sunset: {
141
+ light: {
142
+ bg: "#f6f1ea",
143
+ bgRaised: "#fffdfa",
144
+ bgCard: "#fffdfa",
145
+ bgCardHover: "#f7f1e9",
146
+ bgSubtle: "#f1e9dd",
147
+ text: "#241d15",
148
+ textDim: "#7c6f5e",
149
+ textFaint: "#b3a692",
150
+ accent: "#d98324",
151
+ accentSoft: "rgba(217, 131, 36, 0.13)",
152
+ onAccent: "#ffffff",
153
+ line: "rgba(40, 30, 18, 0.09)",
154
+ border: "#ece2d3",
155
+ positive: "#3f8a5d",
156
+ positiveSoft: "rgba(63, 138, 93, 0.13)",
157
+ warning: "#c98a1e",
158
+ warningSoft: "rgba(201, 138, 30, 0.14)",
159
+ danger: "#c75a44",
160
+ dangerSoft: "rgba(199, 90, 68, 0.12)",
161
+ info: "#3f7da0",
162
+ infoSoft: "rgba(63, 125, 160, 0.13)",
163
+ shadowCard: "0 1px 3px rgba(80, 55, 20, 0.07)",
164
+ shadowElevated: "0 12px 32px -8px rgba(80, 55, 20, 0.18)",
165
+ shadowActive: "0 0 0 1px var(--accent-soft), 0 6px 20px -8px rgba(217, 131, 36, 0.30)"
166
+ },
167
+ dark: {
168
+ bg: "#161310",
169
+ bgRaised: "#1f1b16",
170
+ bgCard: "#241f19",
171
+ bgCardHover: "#2a241d",
172
+ bgSubtle: "#2f2820",
173
+ text: "#f2ece2",
174
+ textDim: "#a39a8c",
175
+ textFaint: "#6f675c",
176
+ accent: "#e8a84b",
177
+ accentSoft: "rgba(232, 168, 75, 0.16)",
178
+ onAccent: "#1c1610",
179
+ line: "rgba(242, 236, 226, 0.08)",
180
+ border: "rgba(242, 236, 226, 0.09)",
181
+ positive: "#8fc7a2",
182
+ positiveSoft: "rgba(143, 199, 162, 0.16)",
183
+ warning: "#e8a84b",
184
+ warningSoft: "rgba(232, 168, 75, 0.16)",
185
+ danger: "#e08a78",
186
+ dangerSoft: "rgba(224, 138, 120, 0.16)",
187
+ info: "#8fb7c7",
188
+ infoSoft: "rgba(143, 183, 199, 0.16)",
189
+ shadowCard: "0 2px 10px -3px rgba(0, 0, 0, 0.5)",
190
+ shadowElevated: "0 16px 40px -12px rgba(0, 0, 0, 0.66)",
191
+ shadowActive: "0 0 0 1px var(--accent-soft), 0 6px 24px -8px rgba(232, 168, 75, 0.28)"
192
+ }
193
+ },
194
+ // Ocean — cool steel-blue identity
195
+ ocean: {
196
+ light: {
197
+ bg: "#eef1f5",
198
+ bgRaised: "#ffffff",
199
+ bgCard: "#ffffff",
200
+ bgCardHover: "#f4f7fa",
201
+ bgSubtle: "#eaeef3",
202
+ text: "#172029",
203
+ textDim: "#5f6c7a",
204
+ textFaint: "#9aa6b3",
205
+ accent: "#2f7fd6",
206
+ accentSoft: "rgba(47, 127, 214, 0.12)",
207
+ onAccent: "#ffffff",
208
+ line: "rgba(20, 30, 45, 0.08)",
209
+ border: "#e3e8ee",
210
+ positive: "#159a6e",
211
+ positiveSoft: "rgba(21, 154, 110, 0.12)",
212
+ warning: "#e09112",
213
+ warningSoft: "rgba(224, 145, 18, 0.13)",
214
+ danger: "#e0495a",
215
+ dangerSoft: "rgba(224, 73, 90, 0.11)",
216
+ info: "#2f7fd6",
217
+ infoSoft: "rgba(47, 127, 214, 0.12)",
218
+ shadowCard: "0 1px 3px rgba(20, 35, 60, 0.07)",
219
+ shadowElevated: "0 12px 32px -8px rgba(20, 35, 60, 0.16)",
220
+ shadowActive: "0 0 0 1px var(--accent-soft), 0 6px 20px -8px rgba(47, 127, 214, 0.28)"
221
+ },
222
+ dark: {
223
+ bg: "#0a0c10",
224
+ bgRaised: "#0f1218",
225
+ bgCard: "#12151c",
226
+ bgCardHover: "#181c25",
227
+ bgSubtle: "#1d2230",
228
+ text: "#e8ecf2",
229
+ textDim: "#8a9ab0",
230
+ textFaint: "#566173",
231
+ accent: "#5fa8e8",
232
+ accentSoft: "rgba(95, 168, 232, 0.16)",
233
+ onAccent: "#06090f",
234
+ line: "rgba(232, 236, 242, 0.08)",
235
+ border: "rgba(232, 236, 242, 0.09)",
236
+ positive: "#4dc596",
237
+ positiveSoft: "rgba(77, 197, 150, 0.16)",
238
+ warning: "#e3b256",
239
+ warningSoft: "rgba(227, 178, 86, 0.16)",
240
+ danger: "#e68086",
241
+ dangerSoft: "rgba(230, 128, 134, 0.16)",
242
+ info: "#5fa8e8",
243
+ infoSoft: "rgba(95, 168, 232, 0.16)",
244
+ shadowCard: "0 2px 12px -3px rgba(0, 0, 0, 0.6)",
245
+ shadowElevated: "0 16px 40px -12px rgba(0, 0, 0, 0.72)",
246
+ shadowActive: "0 0 0 1px var(--accent-soft), 0 6px 24px -8px rgba(95, 168, 232, 0.30)"
247
+ }
248
+ },
249
+ // Forest — muted green identity
250
+ forest: {
251
+ light: {
252
+ bg: "#edf1ec",
253
+ bgRaised: "#ffffff",
254
+ bgCard: "#ffffff",
255
+ bgCardHover: "#f3f7f2",
256
+ bgSubtle: "#e8eee7",
257
+ text: "#1b2620",
258
+ textDim: "#5f6f64",
259
+ textFaint: "#9aa89f",
260
+ accent: "#3f9a63",
261
+ accentSoft: "rgba(63, 154, 99, 0.13)",
262
+ onAccent: "#ffffff",
263
+ line: "rgba(24, 36, 28, 0.08)",
264
+ border: "#e0e8e1",
265
+ positive: "#2f9a5e",
266
+ positiveSoft: "rgba(47, 154, 94, 0.13)",
267
+ warning: "#cf9120",
268
+ warningSoft: "rgba(207, 145, 32, 0.13)",
269
+ danger: "#cf5746",
270
+ dangerSoft: "rgba(207, 87, 70, 0.11)",
271
+ info: "#3f86a0",
272
+ infoSoft: "rgba(63, 134, 160, 0.13)",
273
+ shadowCard: "0 1px 3px rgba(24, 45, 32, 0.07)",
274
+ shadowElevated: "0 12px 32px -8px rgba(24, 45, 32, 0.16)",
275
+ shadowActive: "0 0 0 1px var(--accent-soft), 0 6px 20px -8px rgba(63, 154, 99, 0.28)"
276
+ },
277
+ dark: {
278
+ bg: "#0c110d",
279
+ bgRaised: "#121812",
280
+ bgCard: "#161d17",
281
+ bgCardHover: "#1d261e",
282
+ bgSubtle: "#212c22",
283
+ text: "#e9efe9",
284
+ textDim: "#8ba091",
285
+ textFaint: "#586860",
286
+ accent: "#5cc486",
287
+ accentSoft: "rgba(92, 196, 134, 0.16)",
288
+ onAccent: "#06120a",
289
+ line: "rgba(233, 239, 233, 0.08)",
290
+ border: "rgba(233, 239, 233, 0.09)",
291
+ positive: "#5cc486",
292
+ positiveSoft: "rgba(92, 196, 134, 0.16)",
293
+ warning: "#e0b455",
294
+ warningSoft: "rgba(224, 180, 85, 0.16)",
295
+ danger: "#e6807a",
296
+ dangerSoft: "rgba(230, 128, 122, 0.16)",
297
+ info: "#62b0c4",
298
+ infoSoft: "rgba(98, 176, 196, 0.16)",
299
+ shadowCard: "0 2px 12px -3px rgba(0, 0, 0, 0.55)",
300
+ shadowElevated: "0 16px 40px -12px rgba(0, 0, 0, 0.7)",
301
+ shadowActive: "0 0 0 1px var(--accent-soft), 0 6px 24px -8px rgba(92, 196, 134, 0.30)"
302
+ }
303
+ }
304
+ };
305
+ function resolveThemeMode(mode, systemPrefersDark) {
306
+ if (mode === "light" || mode === "dark") return mode;
307
+ return systemPrefersDark ? "dark" : "light";
308
+ }
309
+ function accentOverride(hue, resolvedMode) {
310
+ const isDark = resolvedMode === "dark";
311
+ const l = isDark ? 60 : 50;
312
+ const s = 78;
313
+ return {
314
+ accent: `hsl(${hue}, ${s}%, ${l}%)`,
315
+ accentSoft: `hsla(${hue}, ${s}%, ${l}%, ${isDark ? 0.16 : 0.12})`,
316
+ onAccent: isDark ? "#140e04" : "#ffffff"
317
+ };
318
+ }
319
+
320
+ // src/ui/theme.ts
321
+ var TOKEN_TO_VAR = {
322
+ bg: "--bg",
323
+ bgRaised: "--bg-raised",
324
+ bgCard: "--bg-card",
325
+ bgCardHover: "--bg-card-hover",
326
+ bgSubtle: "--bg-subtle",
327
+ text: "--text",
328
+ textDim: "--text-dim",
329
+ textFaint: "--text-faint",
330
+ accent: "--accent",
331
+ accentSoft: "--accent-soft",
332
+ onAccent: "--on-accent",
333
+ line: "--line",
334
+ border: "--border",
335
+ positive: "--positive",
336
+ positiveSoft: "--positive-soft",
337
+ warning: "--warning",
338
+ warningSoft: "--warning-soft",
339
+ danger: "--danger",
340
+ dangerSoft: "--danger-soft",
341
+ info: "--info",
342
+ infoSoft: "--info-soft",
343
+ shadowCard: "--shadow-card",
344
+ shadowElevated: "--shadow-elevated",
345
+ shadowActive: "--shadow-active"
346
+ };
347
+ var darkMql = () => typeof window !== "undefined" && window.matchMedia ? window.matchMedia("(prefers-color-scheme: dark)") : null;
348
+ function resolveMode(mode) {
349
+ return resolveThemeMode(mode, darkMql()?.matches ?? false);
350
+ }
351
+ function isThemeName(name) {
352
+ return THEME_NAMES.includes(name);
353
+ }
354
+ function applyTheme(name, mode = "light", accentHue) {
355
+ const root = document.documentElement;
356
+ const theme = isThemeName(name) ? name : "aurora";
357
+ const resolved = resolveMode(mode);
358
+ const tokens = THEMES[theme][resolved];
359
+ for (const key of Object.keys(TOKEN_TO_VAR)) root.style.setProperty(TOKEN_TO_VAR[key], tokens[key]);
360
+ root.setAttribute("data-theme", theme);
361
+ root.setAttribute("data-mode", resolved);
362
+ root.style.setProperty("color-scheme", resolved);
363
+ if (accentHue !== void 0) {
364
+ const o = accentOverride(accentHue, resolved);
365
+ root.style.setProperty("--accent", o.accent);
366
+ root.style.setProperty("--accent-soft", o.accentSoft);
367
+ root.style.setProperty("--on-accent", o.onAccent);
368
+ }
369
+ return resolved;
370
+ }
371
+ function watchSystemMode(getState) {
372
+ const mql = darkMql();
373
+ if (!mql) return () => {
374
+ };
375
+ const on = () => {
376
+ const s = getState();
377
+ if (s.mode === "auto") applyTheme(s.theme, s.mode, s.accentHue);
378
+ };
379
+ mql.addEventListener("change", on);
380
+ return () => mql.removeEventListener("change", on);
381
+ }
382
+
383
+ // src/ui/format.tsx
384
+ function fmtRelative(ts, t, nowMs = Date.now()) {
385
+ const s = Math.max(0, (nowMs - ts) / 1e3);
386
+ if (s < 60) return t("nvr.time.justNow");
387
+ if (s < 3600) return t("nvr.time.minAgo", { n: Math.round(s / 60) });
388
+ if (s < 86400) return t("nvr.time.hAgo", { n: Math.round(s / 3600) });
389
+ return t("nvr.time.dAgo", { n: Math.round(s / 86400) });
390
+ }
391
+ function fmtDays(d, t) {
392
+ if (d < 1) return t("nvr.time.lessThanDay");
393
+ const n = Math.round(d);
394
+ return t("nvr.time.days", { count: n });
395
+ }
396
+ function humanBytes(b) {
397
+ const h = sentinelHumanBytes(b);
398
+ return `${h.value} ${h.unit}`;
399
+ }
400
+
401
+ // src/ui/components/ClassBadge.tsx
402
+ import { User, Car, Bike, PawPrint, Package, Activity } from "lucide-react";
403
+ import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
404
+ var ICONS = {
405
+ person: User,
406
+ car: Car,
407
+ bike: Bike,
408
+ animal: PawPrint,
409
+ package: Package,
410
+ motion: Activity
411
+ };
412
+ function classLabel(t, cls) {
413
+ return t(`nvr.class.${cls}`);
414
+ }
415
+ function eventLabel(t, ev) {
416
+ return sentinelClassesOf(ev).map((c) => classLabel(t, c)).join(", ");
417
+ }
418
+ function ClassBadge({ cls, size = 18, title }) {
419
+ const Icon = ICONS[cls];
420
+ return /* @__PURE__ */ jsx2("span", { className: `nvr-cbadge nvr-cbadge--${cls}`, style: { width: size, height: size }, title, "aria-hidden": title ? void 0 : true, children: /* @__PURE__ */ jsx2(Icon, { size: Math.round(size * 0.62), strokeWidth: 2.25 }) });
421
+ }
422
+ function EventBadges({ ev, size, t }) {
423
+ return /* @__PURE__ */ jsx2(Fragment, { children: sentinelClassesOf(ev).map((c) => /* @__PURE__ */ jsx2(ClassBadge, { cls: c, size, title: classLabel(t, c) }, c)) });
424
+ }
425
+
426
+ // src/ui/components/EventsStrip.tsx
427
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
428
+ function EventsStrip({ events }) {
429
+ const { client, t, locale, nav } = useSentinelUi();
430
+ if (!events.length) return null;
431
+ return /* @__PURE__ */ jsxs("section", { className: "nvr-section", children: [
432
+ /* @__PURE__ */ jsx3("h2", { className: "nvr-section__label", children: t("nvr.events.title") }),
433
+ /* @__PURE__ */ jsx3("ul", { className: "nvr-strip", children: events.map((e) => /* @__PURE__ */ jsx3("li", { children: /* @__PURE__ */ jsxs(
434
+ "button",
435
+ {
436
+ type: "button",
437
+ className: "nvr-strip__item",
438
+ onClick: () => nav.openCamera(e.camera, sentinelEventPlayTs(e), e.ts),
439
+ "aria-label": `${eventLabel(t, e)} \xB7 ${e.cameraName} \xB7 ${fmtTime(e.ts, locale)}`,
440
+ title: e.cameraName,
441
+ children: [
442
+ /* @__PURE__ */ jsxs("span", { className: "nvr-strip__img", children: [
443
+ /* @__PURE__ */ jsx3("img", { src: client.eventThumbUrl(e.camera, e.ts), alt: "", loading: "lazy" }),
444
+ /* @__PURE__ */ jsx3("span", { className: "nvr-strip__badges", children: /* @__PURE__ */ jsx3(EventBadges, { ev: e, t }) })
445
+ ] }),
446
+ /* @__PURE__ */ jsx3("span", { className: "nvr-strip__time nvr-data", children: fmtTime(e.ts, locale) })
447
+ ]
448
+ }
449
+ ) }, `${e.camera}-${e.ts}`)) })
450
+ ] });
451
+ }
452
+
453
+ // src/ui/components/CameraGrid.tsx
454
+ import { useEffect, useState } from "react";
455
+ import { Camera, WifiOff } from "lucide-react";
456
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
457
+ var SNAPSHOT_MS = 5e3;
458
+ var RETRY_EVERY = 6;
459
+ function CameraTile({ cam, tick, n }) {
460
+ const { client, t, nav } = useSentinelUi();
461
+ const [failed, setFailed] = useState(0);
462
+ useEffect(() => {
463
+ setFailed(0);
464
+ }, [client, cam.id]);
465
+ useEffect(() => {
466
+ if (n % RETRY_EVERY === 0) setFailed(0);
467
+ }, [n]);
468
+ const src = failed === 0 ? client.snapshotUrl(cam.id, tick) : failed === 1 && cam.latestThumbId ? client.segmentThumbUrl(cam.latestThumbId) : null;
469
+ const open = () => nav.openCamera(cam.id);
470
+ const meta = [t("nvr.cameras.eventsToday", { count: cam.eventsToday }), cam.lastEventTs ? fmtRelative(cam.lastEventTs, t) : null].filter(Boolean).join(" \xB7 ");
471
+ return /* @__PURE__ */ jsxs2(
472
+ "div",
473
+ {
474
+ className: "nvr-card nvr-camtile",
475
+ role: "button",
476
+ tabIndex: 0,
477
+ onClick: open,
478
+ onKeyDown: (e) => {
479
+ if (e.key === "Enter" || e.key === " ") {
480
+ e.preventDefault();
481
+ open();
482
+ }
483
+ },
484
+ "aria-label": cam.name,
485
+ children: [
486
+ src ? /* @__PURE__ */ jsx4("img", { className: "nvr-camtile__img", src, alt: "", onError: () => setFailed((f) => Math.min(2, f + 1)) }) : /* @__PURE__ */ jsx4("div", { className: "nvr-camtile__placeholder", "aria-hidden": "true", children: /* @__PURE__ */ jsx4(Camera, { size: 32, strokeWidth: 1.5 }) }),
487
+ /* @__PURE__ */ jsxs2("span", { className: "nvr-camtile__name", children: [
488
+ cam.name,
489
+ cam.recording && /* @__PURE__ */ jsx4("i", { className: `nvr-camtile__dot${cam.online ? "" : " nvr-camtile__dot--off"}`, "aria-hidden": "true" })
490
+ ] }),
491
+ cam.recording && !cam.online && /* @__PURE__ */ jsxs2("span", { className: "nvr-camtile__offline", children: [
492
+ /* @__PURE__ */ jsx4(WifiOff, { size: 12, strokeWidth: 2.25 }),
493
+ t("nvr.cameras.offline")
494
+ ] }),
495
+ /* @__PURE__ */ jsx4("span", { className: "nvr-camtile__meta nvr-data", children: meta })
496
+ ]
497
+ }
498
+ );
499
+ }
500
+ function CameraTiles({ cameras }) {
501
+ const { t } = useSentinelUi();
502
+ const [tick, setTick] = useState(() => Date.now());
503
+ const [n, setN] = useState(0);
504
+ useEffect(() => {
505
+ const id = setInterval(() => {
506
+ if (document.visibilityState === "visible") {
507
+ setTick(Date.now());
508
+ setN((x) => x + 1);
509
+ }
510
+ }, SNAPSHOT_MS);
511
+ return () => clearInterval(id);
512
+ }, []);
513
+ if (cameras.length === 0) return /* @__PURE__ */ jsx4("p", { className: "nvr-muted", children: t("nvr.cameras.none") });
514
+ return /* @__PURE__ */ jsx4("div", { className: "nvr-camgrid", children: cameras.map((c) => /* @__PURE__ */ jsx4(CameraTile, { cam: c, tick, n }, c.id)) });
515
+ }
516
+ function CameraGrid({ cameras }) {
517
+ const { t } = useSentinelUi();
518
+ return /* @__PURE__ */ jsxs2("section", { className: "nvr-section", children: [
519
+ /* @__PURE__ */ jsx4("h2", { className: "nvr-section__label", children: t("nvr.cameras.title") }),
520
+ /* @__PURE__ */ jsx4(CameraTiles, { cameras })
521
+ ] });
522
+ }
523
+
524
+ // src/ui/components/EventList.tsx
525
+ import { Fragment as Fragment2 } from "react";
526
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
527
+ function EventList({ camId, events, filterOff, onPick }) {
528
+ const { client, t, locale } = useSentinelUi();
529
+ const evs = events.filter((e) => !filterOff[sentinelClassOf(e)]).slice().sort((a, b) => b.timestamp - a.timestamp);
530
+ if (!evs.length) return /* @__PURE__ */ jsx5("p", { className: "nvr-muted nvr-evlist__empty", children: t("nvr.events.none") });
531
+ let lastDay = "";
532
+ return /* @__PURE__ */ jsx5("div", { className: "nvr-evlist", children: evs.map((ev) => {
533
+ const d = new Date(ev.timestamp).toDateString();
534
+ const head = d !== lastDay;
535
+ lastDay = d;
536
+ return /* @__PURE__ */ jsxs3(Fragment2, { children: [
537
+ head && /* @__PURE__ */ jsx5("div", { className: "nvr-evlist__day nvr-data", children: fmtDay(ev.timestamp, locale) }),
538
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: "nvr-evrow", onClick: () => onPick(ev), children: [
539
+ /* @__PURE__ */ jsx5("img", { className: "nvr-evrow__img", src: client.eventThumbUrl(camId, ev.timestamp), alt: "", loading: "lazy" }),
540
+ /* @__PURE__ */ jsxs3("span", { className: "nvr-evrow__text", children: [
541
+ /* @__PURE__ */ jsxs3("span", { className: "nvr-evrow__cls", children: [
542
+ /* @__PURE__ */ jsx5(EventBadges, { ev, size: 16, t }),
543
+ " ",
544
+ eventLabel(t, ev)
545
+ ] }),
546
+ /* @__PURE__ */ jsx5("span", { className: "nvr-evrow__t nvr-data", children: fmtTimeSec(ev.timestamp, locale) })
547
+ ] })
548
+ ] })
549
+ ] }, ev.id);
550
+ }) });
551
+ }
552
+
553
+ // src/ui/components/DatePickerPanel.tsx
554
+ import { useState as useState2 } from "react";
555
+ import { ChevronLeft, ChevronRight } from "lucide-react";
556
+ import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
557
+ function useDatePicker({ dayStart, timeTs, oldestAllowed = -Infinity, onGo }) {
558
+ const { t, locale } = useSentinelUi();
559
+ const base = new Date(dayStart);
560
+ const [view, setView] = useState2(new Date(base.getFullYear(), base.getMonth(), 1));
561
+ const [sel, setSel] = useState2(new Date(base.getFullYear(), base.getMonth(), base.getDate()));
562
+ const [time, setTime] = useState2(hhmmInput(timeTs));
563
+ const y = view.getFullYear(), m = view.getMonth();
564
+ const startIdx = (new Date(y, m, 1).getDay() + 6) % 7;
565
+ const dim = new Date(y, m + 1, 0).getDate();
566
+ const today = /* @__PURE__ */ new Date();
567
+ today.setHours(0, 0, 0, 0);
568
+ const cells = Array.from({ length: 42 }, (_, i) => {
569
+ const dnum = i - startIdx + 1;
570
+ const d = new Date(y, m, dnum);
571
+ return {
572
+ d,
573
+ out: dnum < 1 || dnum > dim,
574
+ off: d.getTime() > today.getTime() || d.getTime() < oldestAllowed,
575
+ isToday: d.getTime() === today.getTime(),
576
+ sel: d.getFullYear() === sel.getFullYear() && d.getMonth() === sel.getMonth() && d.getDate() === sel.getDate()
577
+ };
578
+ });
579
+ const submit = () => {
580
+ onGo(sel.getTime(), /^(\d{1,2}):(\d{2})$/.test(time) ? time : null);
581
+ };
582
+ const goToday = () => {
583
+ const n = /* @__PURE__ */ new Date();
584
+ setView(new Date(n.getFullYear(), n.getMonth(), 1));
585
+ setSel(new Date(n.getFullYear(), n.getMonth(), n.getDate()));
586
+ };
587
+ const grid = /* @__PURE__ */ jsxs4(Fragment3, { children: [
588
+ /* @__PURE__ */ jsxs4("div", { className: "nvr-dt__head", children: [
589
+ /* @__PURE__ */ jsx6("button", { type: "button", className: "nvr-dt__nav", onClick: () => setView(new Date(y, m - 1, 1)), "aria-label": t("nvr.date.prevMonth"), children: /* @__PURE__ */ jsx6(ChevronLeft, { size: 18 }) }),
590
+ /* @__PURE__ */ jsx6("span", { className: "nvr-dt__month", children: fmtMonthYear(view.getTime(), locale) }),
591
+ /* @__PURE__ */ jsx6("button", { type: "button", className: "nvr-dt__nav", onClick: () => setView(new Date(y, m + 1, 1)), "aria-label": t("nvr.date.nextMonth"), children: /* @__PURE__ */ jsx6(ChevronRight, { size: 18 }) })
592
+ ] }),
593
+ /* @__PURE__ */ jsxs4("div", { className: "nvr-dt__grid", children: [
594
+ weekdayShorts(locale).map((w) => /* @__PURE__ */ jsx6("span", { className: "nvr-dt__wd", children: w }, w)),
595
+ cells.map((c, i) => /* @__PURE__ */ jsx6(
596
+ "button",
597
+ {
598
+ type: "button",
599
+ disabled: c.out || c.off,
600
+ onClick: () => setSel(c.d),
601
+ className: "nvr-dt__d nvr-data" + (c.out ? " nvr-dt__d--dim" : "") + (c.off ? " nvr-dt__d--off" : "") + (c.isToday && !c.out ? " nvr-dt__d--today" : "") + (c.sel && !c.out ? " nvr-dt__d--sel" : ""),
602
+ children: c.d.getDate()
603
+ },
604
+ i
605
+ ))
606
+ ] })
607
+ ] });
608
+ const footer = /* @__PURE__ */ jsxs4("div", { className: "nvr-dt__foot", children: [
609
+ /* @__PURE__ */ jsx6("button", { type: "button", className: "nvr-btn nvr-btn--ghost", onClick: goToday, children: t("nvr.date.today") }),
610
+ /* @__PURE__ */ jsx6("input", { className: "nvr-input nvr-dt__time nvr-data", type: "time", value: time, onChange: (e) => setTime(e.target.value), onKeyDown: (e) => {
611
+ if (e.key === "Enter") submit();
612
+ }, "aria-label": t("nvr.date.time") }),
613
+ /* @__PURE__ */ jsx6("button", { type: "button", className: "nvr-btn nvr-btn--primary", onClick: submit, children: t("nvr.date.go") })
614
+ ] });
615
+ return { grid, footer, submit, goToday };
616
+ }
617
+ function DatePickerPanel(props) {
618
+ const { grid, footer } = useDatePicker(props);
619
+ return /* @__PURE__ */ jsxs4("div", { className: "nvr-dt", children: [
620
+ grid,
621
+ footer
622
+ ] });
623
+ }
624
+
625
+ // src/ui/components/Stats.tsx
626
+ import { Cctv, Video, Database, Clock, Zap, Gauge, BarChart3, HardDrive } from "lucide-react";
627
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
628
+ function StatTile({ icon, label, value, unit, tone = "neutral" }) {
629
+ return /* @__PURE__ */ jsxs5("div", { className: `nvr-stat nvr-stat--${tone}`, children: [
630
+ /* @__PURE__ */ jsx7("span", { className: "nvr-stat__icon", "aria-hidden": "true", children: icon }),
631
+ /* @__PURE__ */ jsxs5("div", { className: "nvr-stat__body", children: [
632
+ /* @__PURE__ */ jsx7("span", { className: "nvr-stat__label", children: label }),
633
+ /* @__PURE__ */ jsxs5("span", { className: "nvr-stat__value nvr-data", children: [
634
+ value,
635
+ unit && /* @__PURE__ */ jsxs5("span", { className: "nvr-stat__unit", children: [
636
+ " ",
637
+ unit
638
+ ] })
639
+ ] })
640
+ ] })
641
+ ] });
642
+ }
643
+ function CardTitle({ icon, title, sub, tone = "accent", action }) {
644
+ return /* @__PURE__ */ jsxs5("div", { className: "nvr-ctitle", children: [
645
+ /* @__PURE__ */ jsx7("span", { className: `nvr-ctitle__chip nvr-ctitle__chip--${tone}`, "aria-hidden": "true", children: icon }),
646
+ /* @__PURE__ */ jsxs5("div", { className: "nvr-ctitle__text", children: [
647
+ /* @__PURE__ */ jsx7("div", { className: "nvr-ctitle__title", children: title }),
648
+ sub && /* @__PURE__ */ jsx7("div", { className: "nvr-ctitle__sub", children: sub })
649
+ ] }),
650
+ action && /* @__PURE__ */ jsx7("div", { className: "nvr-ctitle__action", children: action })
651
+ ] });
652
+ }
653
+ function Hero({ cameras, stats }) {
654
+ const { t } = useSentinelUi();
655
+ const online = cameras.filter((c) => c.online).length;
656
+ const offline = Math.max(0, stats.cameras - online);
657
+ const fc = sentinelStorageForecast(stats);
658
+ const bytes = sentinelHumanBytes(stats.bytes);
659
+ const span = fc.spanDays ? fmtDays(fc.spanDays, t).split(" ") : ["\u2013"];
660
+ return /* @__PURE__ */ jsxs5("div", { className: "nvr-card nvr-hero", children: [
661
+ /* @__PURE__ */ jsxs5("div", { className: "nvr-hero__head", children: [
662
+ /* @__PURE__ */ jsx7(CardTitle, { icon: /* @__PURE__ */ jsx7(Gauge, { size: 16, strokeWidth: 1.75 }), title: t("nvr.hero.title"), sub: t("nvr.hero.sub") }),
663
+ /* @__PURE__ */ jsxs5("span", { className: `nvr-pill ${offline > 0 ? "nvr-pill--danger" : "nvr-pill--positive"}`, children: [
664
+ /* @__PURE__ */ jsx7("span", { className: "nvr-pill__dot", "aria-hidden": "true" }),
665
+ offline > 0 ? t("nvr.hero.offline", { count: offline }) : t("nvr.hero.allOnline")
666
+ ] })
667
+ ] }),
668
+ /* @__PURE__ */ jsxs5("div", { className: "nvr-hero__primary", children: [
669
+ /* @__PURE__ */ jsxs5("span", { className: "nvr-hero__primary-label", children: [
670
+ /* @__PURE__ */ jsx7(Zap, { size: 14, strokeWidth: 2 }),
671
+ t("nvr.hero.eventsToday")
672
+ ] }),
673
+ /* @__PURE__ */ jsx7("span", { className: "nvr-hero__primary-value nvr-data", children: stats.eventsToday })
674
+ ] }),
675
+ /* @__PURE__ */ jsxs5("div", { className: "nvr-hero__stats", children: [
676
+ /* @__PURE__ */ jsx7(StatTile, { icon: /* @__PURE__ */ jsx7(Cctv, { size: 16, strokeWidth: 1.75 }), label: t("nvr.hero.camerasOnline"), value: `${online}`, unit: `/ ${stats.cameras}`, tone: offline > 0 ? "danger" : "positive" }),
677
+ /* @__PURE__ */ jsx7(StatTile, { icon: /* @__PURE__ */ jsx7(Video, { size: 16, strokeWidth: 1.75 }), label: t("nvr.hero.recording"), value: `${stats.recording}`, unit: `/ ${stats.cameras}`, tone: "accent" }),
678
+ /* @__PURE__ */ jsx7(StatTile, { icon: /* @__PURE__ */ jsx7(Database, { size: 16, strokeWidth: 1.75 }), label: t("nvr.hero.storageUsed"), value: bytes.value, unit: bytes.unit, tone: "info" }),
679
+ /* @__PURE__ */ jsx7(StatTile, { icon: /* @__PURE__ */ jsx7(Clock, { size: 16, strokeWidth: 1.75 }), label: t("nvr.hero.retention"), value: span[0] ?? "\u2013", unit: span.slice(1).join(" ") || void 0 })
680
+ ] })
681
+ ] });
682
+ }
683
+ function HistogramCard({ histogram }) {
684
+ const { t } = useSentinelUi();
685
+ const buckets = histogram.length === 24 ? histogram : Array.from({ length: 24 }, (_, i) => histogram[i] ?? 0);
686
+ const max = Math.max(1, ...buckets);
687
+ const hour = (/* @__PURE__ */ new Date()).getHours();
688
+ return /* @__PURE__ */ jsxs5("div", { className: "nvr-card nvr-card--pad", children: [
689
+ /* @__PURE__ */ jsx7(CardTitle, { icon: /* @__PURE__ */ jsx7(BarChart3, { size: 16, strokeWidth: 1.75 }), title: t("nvr.histogram.title"), sub: t("nvr.histogram.sub") }),
690
+ /* @__PURE__ */ jsx7("div", { className: "nvr-chart", role: "img", "aria-label": t("nvr.histogram.title"), children: buckets.map((v, i) => /* @__PURE__ */ jsx7("div", { className: `nvr-chart__col${i === hour ? " nvr-chart__col--now" : ""}`, title: `${String(i).padStart(2, "0")}:00 \u2013 ${v}`, children: /* @__PURE__ */ jsx7("div", { className: "nvr-chart__bar", style: { height: `${v / max * 100}%` } }) }, i)) }),
691
+ /* @__PURE__ */ jsxs5("div", { className: "nvr-chart__axis nvr-data", children: [
692
+ /* @__PURE__ */ jsx7("span", { children: "00" }),
693
+ /* @__PURE__ */ jsx7("span", { children: "06" }),
694
+ /* @__PURE__ */ jsx7("span", { children: "12" }),
695
+ /* @__PURE__ */ jsx7("span", { children: "18" }),
696
+ /* @__PURE__ */ jsx7("span", { children: "24" })
697
+ ] })
698
+ ] });
699
+ }
700
+ function StorageCard({ stats }) {
701
+ const { t } = useSentinelUi();
702
+ const fc = sentinelStorageForecast(stats);
703
+ const pct = (v) => stats.diskTotal ? `${(v / stats.diskTotal * 100).toFixed(2)}%` : "0%";
704
+ const reserveShown = Math.min(fc.reserve, stats.diskFree);
705
+ let note;
706
+ switch (fc.status) {
707
+ case "unreachable":
708
+ note = t("nvr.storage.note.unreachable", { target: stats.retentionDays, fits: fmtDays(fc.fitsDays, t) }) + (fc.steady ? "" : " " + t("nvr.storage.note.fullIn", { days: fmtDays(fc.fillsInDays, t) }));
709
+ break;
710
+ case "reachable":
711
+ note = t(fc.spanDays >= stats.retentionDays ? "nvr.storage.note.reachableAge" : "nvr.storage.note.reachableEvict", { fits: fmtDays(fc.fitsDays, t) });
712
+ break;
713
+ case "filling":
714
+ note = t("nvr.storage.note.filling", { fillsIn: fmtDays(fc.fillsInDays, t), fits: fmtDays(fc.fitsDays, t) });
715
+ break;
716
+ default:
717
+ note = t("nvr.storage.note.unknown");
718
+ }
719
+ return /* @__PURE__ */ jsxs5("div", { className: "nvr-card nvr-card--pad", children: [
720
+ /* @__PURE__ */ jsx7(CardTitle, { icon: /* @__PURE__ */ jsx7(HardDrive, { size: 16, strokeWidth: 1.75 }), title: t("nvr.storage.title"), sub: t("nvr.storage.sub"), tone: "info" }),
721
+ /* @__PURE__ */ jsxs5("div", { className: "nvr-meter", role: "img", "aria-label": t("nvr.storage.title"), children: [
722
+ /* @__PURE__ */ jsx7("span", { className: "nvr-meter__rec", style: { width: pct(stats.bytes) } }),
723
+ /* @__PURE__ */ jsx7("span", { className: "nvr-meter__other", style: { left: pct(stats.bytes), width: pct(fc.other) } }),
724
+ /* @__PURE__ */ jsx7("span", { className: "nvr-meter__reserve", style: { width: pct(reserveShown) } })
725
+ ] }),
726
+ /* @__PURE__ */ jsxs5("div", { className: "nvr-legend", children: [
727
+ /* @__PURE__ */ jsxs5("span", { children: [
728
+ /* @__PURE__ */ jsx7("i", { className: "nvr-legend__sw nvr-legend__sw--rec" }),
729
+ t("nvr.storage.recordings"),
730
+ " ",
731
+ humanBytes(stats.bytes)
732
+ ] }),
733
+ /* @__PURE__ */ jsxs5("span", { children: [
734
+ /* @__PURE__ */ jsx7("i", { className: "nvr-legend__sw nvr-legend__sw--other" }),
735
+ t("nvr.storage.system"),
736
+ " ",
737
+ humanBytes(fc.other)
738
+ ] }),
739
+ /* @__PURE__ */ jsxs5("span", { children: [
740
+ /* @__PURE__ */ jsx7("i", { className: "nvr-legend__sw nvr-legend__sw--free" }),
741
+ t("nvr.storage.free"),
742
+ " ",
743
+ humanBytes(stats.diskFree)
744
+ ] }),
745
+ /* @__PURE__ */ jsxs5("span", { children: [
746
+ /* @__PURE__ */ jsx7("i", { className: "nvr-legend__sw nvr-legend__sw--reserve" }),
747
+ t("nvr.storage.reserve"),
748
+ " ",
749
+ humanBytes(fc.reserve)
750
+ ] })
751
+ ] }),
752
+ /* @__PURE__ */ jsxs5("ul", { className: "nvr-kv", children: [
753
+ /* @__PURE__ */ jsxs5("li", { children: [
754
+ /* @__PURE__ */ jsx7("span", { children: t("nvr.storage.rate") }),
755
+ /* @__PURE__ */ jsx7("b", { className: "nvr-data", children: fc.ratePerDay ? t("nvr.storage.perDay", { value: humanBytes(fc.ratePerDay) }) : "\u2013" })
756
+ ] }),
757
+ /* @__PURE__ */ jsxs5("li", { children: [
758
+ /* @__PURE__ */ jsx7("span", { children: t("nvr.storage.capacity") }),
759
+ /* @__PURE__ */ jsxs5("b", { className: "nvr-data", children: [
760
+ humanBytes(fc.capacity),
761
+ fc.ratePerDay ? /* @__PURE__ */ jsxs5("em", { children: [
762
+ " \u2248 ",
763
+ fmtDays(fc.fitsDays, t)
764
+ ] }) : null
765
+ ] })
766
+ ] }),
767
+ /* @__PURE__ */ jsxs5("li", { children: [
768
+ /* @__PURE__ */ jsx7("span", { children: t("nvr.storage.retention") }),
769
+ /* @__PURE__ */ jsxs5("b", { className: "nvr-data", children: [
770
+ fc.spanDays ? `~${fmtDays(fc.spanDays, t)}` : "\u2013",
771
+ /* @__PURE__ */ jsxs5("em", { children: [
772
+ " / ",
773
+ t("nvr.storage.target", { days: stats.retentionDays })
774
+ ] })
775
+ ] })
776
+ ] }),
777
+ /* @__PURE__ */ jsxs5("li", { children: [
778
+ /* @__PURE__ */ jsx7("span", { children: t("nvr.storage.segments") }),
779
+ /* @__PURE__ */ jsx7("b", { className: "nvr-data", children: stats.segments })
780
+ ] })
781
+ ] }),
782
+ /* @__PURE__ */ jsx7("p", { className: `nvr-note${fc.status === "unreachable" ? " nvr-note--warn" : ""}`, children: note })
783
+ ] });
784
+ }
785
+
786
+ // src/ui/components/VerticalTimeline.tsx
787
+ import { useEffect as useEffect2, useMemo, useRef, useState as useState3 } from "react";
788
+ import { Plus, Minus, ArrowUp } from "lucide-react";
789
+ import { Fragment as Fragment4, jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
790
+ function VerticalTimeline(p) {
791
+ const { client, t, locale } = useSentinelUi();
792
+ const hhmm = (ts) => fmtTime(ts, locale), hhmmss = (ts) => fmtTimeSec(ts, locale), dayLbl = (ts) => fmtDay(ts, locale);
793
+ const scroll = useRef(null);
794
+ const [vh, setVh] = useState3(600);
795
+ const [px, setPx] = useState3(0);
796
+ const [, tick] = useState3(0);
797
+ const VT = useRef({ user: 0, down: false, moved: false, previewing: false, vel: 0, smooth: null, lastC: null, holdT: 0, relT: 0, lastCenterCb: 0, selfAt: 0, lastJumpLog: 0, idleAt: 0, selfTop: -1, backoffUntil: 0, lastForeignLog: 0, touching: false });
798
+ useEffect2(() => {
799
+ const el = scroll.current;
800
+ const ro = new ResizeObserver(() => setVh(el.clientHeight || 600));
801
+ ro.observe(el);
802
+ setVh(el.clientHeight || 600);
803
+ return () => ro.disconnect();
804
+ }, []);
805
+ const minPx = vh / (3 * SENTINEL_DAY_MS), maxPx = vh / (2 * 60 * 1e3);
806
+ useEffect2(() => {
807
+ if (!px && vh) setPx(vh / (2 * 3600 * 1e3));
808
+ }, [vh, px]);
809
+ const HEAD = 0.35;
810
+ const PAD = Math.ceil(vh * HEAD), PAD_BOT = Math.ceil(vh * (1 - HEAD));
811
+ const span = p.rangeEnd - p.rangeStart;
812
+ const yFor = (ts) => PAD + (p.rangeEnd - ts) * px;
813
+ const tsForY = (y) => p.rangeEnd - (y - PAD) / px;
814
+ const centerTs = () => tsForY((scroll.current?.scrollTop || 0) + vh * HEAD);
815
+ const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
816
+ const setTop = (el, top2, why) => {
817
+ const v = VT.current;
818
+ v.selfAt = Date.now();
819
+ el.scrollTop = top2;
820
+ v.selfTop = el.scrollTop;
821
+ if (Math.abs(el.scrollTop - top2) > 1.5) {
822
+ v.backoffUntil = Date.now() + 400;
823
+ if (Date.now() - v.lastForeignLog > 2e3) {
824
+ v.lastForeignLog = Date.now();
825
+ rlog("follow-stuck", { why, want: Math.round(top2), got: Math.round(el.scrollTop), max: el.scrollHeight - el.clientHeight, ch: el.clientHeight, vh, touching: v.touching, vis: document.visibilityState });
826
+ }
827
+ }
828
+ };
829
+ const scrollCenter = (ts, why = "follow") => {
830
+ const el = scroll.current;
831
+ if (!el) return;
832
+ if (Date.now() < VT.current.backoffUntil) return;
833
+ const top2 = yFor(ts) - vh * HEAD;
834
+ if (Math.abs(el.scrollTop - top2) > 0.5) setTop(el, top2, why);
835
+ };
836
+ const init = useRef(false);
837
+ useEffect2(() => {
838
+ if (!px || init.current) return;
839
+ init.current = true;
840
+ scrollCenter(Date.now());
841
+ }, [px]);
842
+ const prevEnd = useRef(p.rangeEnd);
843
+ useEffect2(() => {
844
+ const d = p.rangeEnd - prevEnd.current;
845
+ prevEnd.current = p.rangeEnd;
846
+ const el = scroll.current;
847
+ if (d && el && px) setTop(el, el.scrollTop + d * px, "range");
848
+ }, [p.rangeEnd, px]);
849
+ useEffect2(() => {
850
+ if (p.jump && px) scrollCenter(p.jump.ts, "jump");
851
+ }, [p.jump?.n, px]);
852
+ useEffect2(() => {
853
+ const on = () => {
854
+ VT.current.touching = true;
855
+ };
856
+ const off = () => {
857
+ VT.current.touching = false;
858
+ };
859
+ document.addEventListener("touchstart", on, { passive: true });
860
+ document.addEventListener("touchend", off);
861
+ document.addEventListener("touchcancel", off);
862
+ return () => {
863
+ document.removeEventListener("touchstart", on);
864
+ document.removeEventListener("touchend", off);
865
+ document.removeEventListener("touchcancel", off);
866
+ };
867
+ }, []);
868
+ useEffect2(() => {
869
+ const t2 = setInterval(() => {
870
+ const v = VT.current;
871
+ if (!v.user) {
872
+ const ts = p.live ? Date.now() : p.following() ? p.playhead() : null;
873
+ if (ts != null) {
874
+ const cur = centerTs();
875
+ const d = ts - cur;
876
+ if (Math.abs(d) > 3e3 && Date.now() - v.lastJumpLog > 1e3) {
877
+ v.lastJumpLog = Date.now();
878
+ rlog("follow-jump", { dSec: Math.round(d / 100) / 10, live: p.live, sinceIdle: v.idleAt ? Date.now() - v.idleAt : -1, px: Math.round(px * 1e6) / 1e6 });
879
+ }
880
+ scrollCenter(ts);
881
+ }
882
+ }
883
+ notifyCenter();
884
+ tick((n) => n + 1);
885
+ }, 100);
886
+ return () => clearInterval(t2);
887
+ });
888
+ const notifyCenter = () => {
889
+ const v = VT.current;
890
+ if (Date.now() - v.lastCenterCb < 400) return;
891
+ v.lastCenterCb = Date.now();
892
+ p.onCenter(clamp(centerTs(), p.rangeStart, p.rangeEnd - 1));
893
+ };
894
+ const scrubSeek = (ts) => {
895
+ const v = VT.current;
896
+ v.previewing = true;
897
+ p.scrub.seek(clamp(ts ?? centerTs(), p.rangeStart, p.rangeEnd - 1));
898
+ };
899
+ const userIdle = () => {
900
+ VT.current.user = 0;
901
+ VT.current.idleAt = Date.now();
902
+ p.scrub.idle();
903
+ };
904
+ const markUser = () => {
905
+ const v = VT.current;
906
+ if (!v.user) {
907
+ v.vel = 0;
908
+ v.smooth = null;
909
+ v.lastC = null;
910
+ p.scrub.begin();
911
+ }
912
+ v.user = Date.now();
913
+ v.previewing = false;
914
+ v.moved = false;
915
+ };
916
+ const release = () => {
917
+ const v = VT.current;
918
+ if (!v.user) return;
919
+ v.down = false;
920
+ clearTimeout(v.holdT);
921
+ if (v.moved) scrubSeek();
922
+ clearTimeout(v.relT);
923
+ v.relT = window.setTimeout(userIdle, 250);
924
+ };
925
+ useEffect2(() => {
926
+ for (const n of ["pointerup", "pointercancel", "touchend"]) window.addEventListener(n, release);
927
+ return () => {
928
+ for (const n of ["pointerup", "pointercancel", "touchend"]) window.removeEventListener(n, release);
929
+ };
930
+ });
931
+ const onScroll = () => {
932
+ const v = VT.current;
933
+ const el = scroll.current;
934
+ if (!v.user) {
935
+ if (Math.abs(el.scrollTop - v.selfTop) <= 1.5 || Date.now() - v.selfAt < 80) return;
936
+ if (Date.now() - v.lastForeignLog > 2e3) {
937
+ v.lastForeignLog = Date.now();
938
+ rlog("foreign-scroll", { d: Math.round(el.scrollTop - v.selfTop), touching: v.touching, live: p.live, vis: document.visibilityState });
939
+ }
940
+ markUser();
941
+ v.down = v.touching;
942
+ } else if (Date.now() - v.selfAt < 80 && Math.abs(el.scrollTop - v.selfTop) <= 1.5) {
943
+ v.lastC = { ts: centerTs(), at: Date.now() };
944
+ return;
945
+ }
946
+ v.user = Date.now();
947
+ v.moved = true;
948
+ if (v.previewing) {
949
+ v.previewing = false;
950
+ p.scrub.begin();
951
+ }
952
+ const now2 = Date.now(), c = centerTs();
953
+ if (v.lastC) {
954
+ const dt = Math.max(16, now2 - v.lastC.at);
955
+ v.vel = 0.7 * v.vel + 0.3 * ((c - v.lastC.ts) / dt * 1e3);
956
+ }
957
+ v.lastC = { ts: c, at: now2 };
958
+ v.smooth = v.smooth == null ? c : v.smooth + 0.45 * (c - v.smooth);
959
+ p.scrub.move(c, v.vel, v.smooth);
960
+ notifyCenter();
961
+ tick((n) => n + 1);
962
+ clearTimeout(v.holdT);
963
+ v.holdT = window.setTimeout(() => scrubSeek(), 250);
964
+ clearTimeout(v.relT);
965
+ v.relT = window.setTimeout(() => {
966
+ if (!v.down) userIdle();
967
+ }, 700);
968
+ };
969
+ useEffect2(() => {
970
+ const el = scroll.current;
971
+ const onWheel = (e) => {
972
+ if (!e.ctrlKey) {
973
+ markUser();
974
+ return;
975
+ }
976
+ e.preventDefault();
977
+ const r = el.getBoundingClientRect();
978
+ const y = e.clientY - r.top;
979
+ applyZoom(px * Math.exp(-e.deltaY * 2e-3), tsForY(el.scrollTop + y), y);
980
+ };
981
+ el.addEventListener("wheel", onWheel, { passive: false });
982
+ return () => el.removeEventListener("wheel", onWheel);
983
+ });
984
+ const applyZoom = (npx, anchor, anchorY) => {
985
+ const c = clamp(npx, minPx, maxPx);
986
+ setPx(c);
987
+ requestAnimationFrame(() => {
988
+ const el = scroll.current;
989
+ if (el) setTop(el, PAD + (p.rangeEnd - anchor) * c - anchorY, "zoom");
990
+ });
991
+ };
992
+ const zoomStep = (f) => {
993
+ const a = p.live ? Date.now() : p.playhead() ?? centerTs();
994
+ applyZoom(px * f, a, vh * HEAD);
995
+ };
996
+ const runs = useMemo(() => sentinelClipRuns(p.clips), [p.clips]);
997
+ const vis = useMemo(() => p.events.filter((e) => !p.filterOff[sentinelClassOf(e)]).slice().sort((a, b) => b.timestamp - a.timestamp), [p.events, p.filterOff]);
998
+ const top = scroll.current?.scrollTop || 0;
999
+ const winStart = tsForY(top + 2 * vh), winEnd = tsForY(top - vh);
1000
+ const inWin = (a, b = a) => b >= winStart && a <= winEnd;
1001
+ const steps = [6e4, 3e5, 6e5, 9e5, 18e5, 36e5, 72e5, 108e5, 216e5];
1002
+ const step = steps.find((s) => s >= 70 / px) ?? steps[steps.length - 1];
1003
+ const axis = [];
1004
+ const a0 = Math.max(p.rangeStart, Math.floor(winStart / step) * step);
1005
+ for (let t2 = a0; t2 <= Math.min(p.rangeEnd, winEnd); t2 += step) axis.push(t2);
1006
+ const q = step / 4;
1007
+ const ticks = [];
1008
+ if (q * px >= 3) {
1009
+ const t0 = Math.max(p.rangeStart, Math.floor(winStart / q) * q);
1010
+ for (let t2 = t0; t2 <= Math.min(p.rangeEnd, winEnd); t2 += q) ticks.push(t2);
1011
+ }
1012
+ const midnights = [];
1013
+ for (let t2 = new Date(Math.max(p.rangeStart, winStart)).setHours(0, 0, 0, 0); t2 <= Math.min(p.rangeEnd, winEnd); t2 += SENTINEL_DAY_MS) if (t2 > p.rangeStart) midnights.push(t2);
1014
+ let lastThumbY = -1e9;
1015
+ const thumbGap = (window.innerWidth < 900 ? 63 : 77) + 6;
1016
+ const now = Date.now();
1017
+ const center = VT.current.user ? clamp(centerTs(), p.rangeStart, p.rangeEnd - 1) : p.live ? now : p.playhead() ?? clamp(centerTs(), p.rangeStart, p.rangeEnd - 1);
1018
+ const centerIsToday = new Date(center).toDateString() === (/* @__PURE__ */ new Date()).toDateString();
1019
+ const down = () => {
1020
+ VT.current.down = true;
1021
+ markUser();
1022
+ };
1023
+ return /* @__PURE__ */ jsxs6("div", { className: "nvr-vtl vtl-wrap", children: [
1024
+ /* @__PURE__ */ jsx8("div", { className: "vtl-scroll", ref: scroll, onScroll, onPointerDown: down, onTouchStart: down, children: /* @__PURE__ */ jsxs6("div", { className: "vtl-content", style: { height: span * px + PAD + PAD_BOT }, children: [
1025
+ /* @__PURE__ */ jsx8("div", { className: "vtl-daybg", style: { top: PAD, height: span * px } }),
1026
+ ticks.map((t2) => /* @__PURE__ */ jsx8("div", { className: "vtick" + (t2 % step === 0 ? " vtick--l" : t2 % (step / 2) === 0 ? " vtick--m" : ""), style: { top: yFor(t2) } }, "t" + t2)),
1027
+ axis.map((t2) => /* @__PURE__ */ jsx8("div", { className: "vaxis nvr-data", style: { top: yFor(t2) }, children: hhmm(t2) }, t2)),
1028
+ midnights.map((t2) => /* @__PURE__ */ jsx8("div", { className: "vday", style: { top: yFor(t2) }, children: /* @__PURE__ */ jsx8("span", { className: "nvr-data", children: dayLbl(t2) }) }, "d" + t2)),
1029
+ runs.map((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)),
1030
+ p.motion.map((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)),
1031
+ vis.map((ev) => {
1032
+ if (!inWin(ev.timestamp)) return null;
1033
+ const y = yFor(ev.timestamp);
1034
+ const k = sentinelClassOf(ev);
1035
+ const thumb = y - lastThumbY >= thumbGap && px > vh / (8 * 3600 * 1e3);
1036
+ if (thumb) lastThumbY = y;
1037
+ return /* @__PURE__ */ jsxs6("div", { children: [
1038
+ /* @__PURE__ */ jsx8("button", { className: "vev" + (thumb ? "" : " vev--minor"), style: { top: y, background: `var(--nvr-c-${k})` }, onClick: () => p.onEvent(ev), "aria-label": `${classLabel(t, k)} ${hhmmss(ev.timestamp)}`, title: hhmmss(sentinelEventPlayTs(ev)) }),
1039
+ thumb && /* @__PURE__ */ jsxs6(Fragment4, { children: [
1040
+ /* @__PURE__ */ jsxs6("div", { className: "vlink", style: { top: y }, children: [
1041
+ /* @__PURE__ */ jsx8("span", { className: "vlink-badges", children: /* @__PURE__ */ jsx8(EventBadges, { ev, t }) }),
1042
+ /* @__PURE__ */ jsx8("i", {})
1043
+ ] }),
1044
+ /* @__PURE__ */ jsxs6("button", { className: "vthumb", style: { top: y }, onClick: () => p.onEvent(ev), children: [
1045
+ /* @__PURE__ */ jsx8("img", { src: client.eventThumbUrl(p.camId, ev.timestamp), alt: "", loading: "lazy" }),
1046
+ /* @__PURE__ */ jsx8("span", { className: "tt nvr-data", children: hhmmss(ev.timestamp) })
1047
+ ] })
1048
+ ] })
1049
+ ] }, ev.id);
1050
+ }),
1051
+ inWin(now) && /* @__PURE__ */ jsxs6(Fragment4, { children: [
1052
+ /* @__PURE__ */ jsx8("div", { className: "vlive-line", style: { top: yFor(now) } }),
1053
+ /* @__PURE__ */ jsx8("button", { className: "vlive-chip", style: { top: yFor(now) }, onClick: p.onGoLive, children: t("nvr.live") })
1054
+ ] })
1055
+ ] }) }),
1056
+ /* @__PURE__ */ jsx8("div", { className: "vcenter", children: /* @__PURE__ */ jsxs6("span", { className: "vcenter-t nvr-data", "data-ts": Math.round(center), children: [
1057
+ centerIsToday ? "" : dayLbl(center) + " ",
1058
+ hhmmss(center)
1059
+ ] }) }),
1060
+ /* @__PURE__ */ jsxs6("div", { className: "vtl-zoom", children: [
1061
+ /* @__PURE__ */ jsx8("button", { type: "button", className: "tool", onClick: () => zoomStep(1.7), "aria-label": t("nvr.timeline.zoomIn"), children: /* @__PURE__ */ jsx8(Plus, { size: 16 }) }),
1062
+ /* @__PURE__ */ jsx8("button", { type: "button", className: "tool", onClick: () => zoomStep(1 / 1.7), "aria-label": t("nvr.timeline.zoomOut"), children: /* @__PURE__ */ jsx8(Minus, { size: 16 }) })
1063
+ ] }),
1064
+ !p.live && /* @__PURE__ */ jsxs6("button", { type: "button", className: "livejump", onClick: p.onGoLive, children: [
1065
+ /* @__PURE__ */ jsx8(ArrowUp, { size: 14 }),
1066
+ " ",
1067
+ t("nvr.live")
1068
+ ] })
1069
+ ] });
1070
+ }
1071
+ export {
1072
+ CameraGrid,
1073
+ CameraTiles,
1074
+ CardTitle,
1075
+ ClassBadge,
1076
+ DatePickerPanel,
1077
+ EventBadges,
1078
+ EventList,
1079
+ EventsStrip,
1080
+ Hero,
1081
+ HistogramCard,
1082
+ SentinelUiProvider,
1083
+ StatTile,
1084
+ StorageCard,
1085
+ THEMES,
1086
+ THEME_LABELS,
1087
+ THEME_NAMES,
1088
+ TOKEN_TO_VAR,
1089
+ UI_LOCALES,
1090
+ VerticalTimeline,
1091
+ accentOverride,
1092
+ applyTheme,
1093
+ classLabel,
1094
+ createT,
1095
+ eventLabel,
1096
+ fmtDays,
1097
+ fmtRelative,
1098
+ humanBytes,
1099
+ interpolate,
1100
+ isThemeName,
1101
+ pickLocale,
1102
+ resolveMode,
1103
+ resolveThemeMode,
1104
+ translate,
1105
+ useDatePicker,
1106
+ useSentinelUi,
1107
+ watchSystemMode
1108
+ };
1109
+ //# sourceMappingURL=index.js.map