@codenkay/video-nsgplayer-ui 2.0.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1380 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AudioTrackSelector: () => AudioTrackSelector,
24
+ LiveBadgeButton: () => LiveBadgeButton,
25
+ NsgVideoPlayerWithControls: () => NsgVideoPlayerWithControls,
26
+ PlayIconPreset: () => PlayIconPreset,
27
+ PlaybackSpeedSelector: () => PlaybackSpeedSelector,
28
+ PlayerCenterOverlay: () => PlayerCenterOverlay,
29
+ PlayerChrome: () => PlayerChrome,
30
+ PlayerControlBar: () => PlayerControlBar,
31
+ PlayerMenu: () => PlayerMenu,
32
+ PlayerMenuItem: () => PlayerMenuItem,
33
+ PlayerSkipCue: () => PlayerSkipCue,
34
+ QualitySelector: () => QualitySelector,
35
+ SeekBar: () => SeekBar,
36
+ TextTrackSelector: () => TextTrackSelector,
37
+ ZOOM_STEPS: () => ZOOM_STEPS,
38
+ formatPlaybackTime: () => formatPlaybackTime,
39
+ nextZoom: () => nextZoom,
40
+ resolvePlayerOverlay: () => resolvePlayerOverlay,
41
+ resolveVisiblePlaybackRates: () => resolveVisiblePlaybackRates,
42
+ snapPlaybackRate: () => snapPlaybackRate,
43
+ usePlayerControls: () => usePlayerControls
44
+ });
45
+ module.exports = __toCommonJS(index_exports);
46
+
47
+ // src/NsgVideoPlayerWithControls.tsx
48
+ var import_react7 = require("react");
49
+ var import_video_nsgplayer_core2 = require("@codenkay/video-nsgplayer-core");
50
+ var import_video_nsgplayer_react = require("@codenkay/video-nsgplayer-react");
51
+
52
+ // src/components/PlayerChrome.tsx
53
+ var import_react6 = require("react");
54
+
55
+ // src/hooks/usePlayerControls.ts
56
+ var import_react = require("react");
57
+
58
+ // src/utils/playback.ts
59
+ var import_video_nsgplayer_core = require("@codenkay/video-nsgplayer-core");
60
+ function formatPlaybackTime(seconds) {
61
+ if (!Number.isFinite(seconds) || seconds < 0) {
62
+ return "0:00";
63
+ }
64
+ const total = Math.floor(seconds);
65
+ const hours = Math.floor(total / 3600);
66
+ const minutes = Math.floor(total % 3600 / 60);
67
+ const secs = total % 60;
68
+ if (hours > 0) {
69
+ return `${hours}:${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
70
+ }
71
+ return `${minutes}:${String(secs).padStart(2, "0")}`;
72
+ }
73
+ function resolveVisiblePlaybackRates(count) {
74
+ const max = import_video_nsgplayer_core.PLAYBACK_RATES.length;
75
+ const clamped = Math.min(max, Math.max(2, Math.floor(count)));
76
+ if (clamped >= max) {
77
+ return [...import_video_nsgplayer_core.PLAYBACK_RATES];
78
+ }
79
+ const ranked = [...import_video_nsgplayer_core.PLAYBACK_RATES].sort((a, b) => {
80
+ const da = Math.abs(a - 1);
81
+ const db = Math.abs(b - 1);
82
+ if (da !== db) return da - db;
83
+ return a - b;
84
+ });
85
+ return ranked.slice(0, clamped).sort((a, b) => a - b);
86
+ }
87
+ function snapPlaybackRate(rate, visible) {
88
+ if (visible.includes(rate)) {
89
+ return rate;
90
+ }
91
+ if (visible.includes(1)) return 1;
92
+ let best = visible[0] ?? 1;
93
+ let bestDist = Math.abs(best - rate);
94
+ for (const item of visible) {
95
+ const dist = Math.abs(item - rate);
96
+ if (dist < bestDist) {
97
+ best = item;
98
+ bestDist = dist;
99
+ }
100
+ }
101
+ return best;
102
+ }
103
+ function resolvePlayerOverlay(input) {
104
+ if (!input.showControls) return "none";
105
+ if (!input.isPlaying) return "play";
106
+ if (input.muted || input.volume <= 0) return "unmute";
107
+ return "none";
108
+ }
109
+ var ZOOM_STEPS = [1, 1.25, 1.5, 2];
110
+ function nextZoom(current, direction) {
111
+ const index = ZOOM_STEPS.indexOf(current);
112
+ const next = Math.min(
113
+ ZOOM_STEPS.length - 1,
114
+ Math.max(0, index + direction)
115
+ );
116
+ return ZOOM_STEPS[next] ?? 1;
117
+ }
118
+
119
+ // src/hooks/usePlayerControls.ts
120
+ function usePlayerControls(options) {
121
+ const { player, config, containerRef } = options;
122
+ const [isPlaying, setIsPlaying] = (0, import_react.useState)(false);
123
+ const [currentTime, setCurrentTime] = (0, import_react.useState)(0);
124
+ const [duration, setDuration] = (0, import_react.useState)(0);
125
+ const [bufferedEnd, setBufferedEnd] = (0, import_react.useState)(0);
126
+ const [volume, setVolumeState] = (0, import_react.useState)(config.player.volume);
127
+ const [muted, setMuted] = (0, import_react.useState)(config.player.startMuted);
128
+ const [playbackRate, setPlaybackRateState] = (0, import_react.useState)(1);
129
+ const [isFullscreen, setIsFullscreen] = (0, import_react.useState)(false);
130
+ const [zoom, setZoom] = (0, import_react.useState)(
131
+ config.player.defaultZoom || 1
132
+ );
133
+ const [qualities, setQualities] = (0, import_react.useState)([]);
134
+ const [qualitySelection, setQualitySelection] = (0, import_react.useState)("auto");
135
+ const [activeLevel, setActiveLevel] = (0, import_react.useState)(-1);
136
+ const [textTracks, setTextTracks] = (0, import_react.useState)([]);
137
+ const [selectedTextTrack, setSelectedTextTrack] = (0, import_react.useState)("off");
138
+ const [audioTracks, setAudioTracks] = (0, import_react.useState)([]);
139
+ const [selectedAudioTrack, setSelectedAudioTrack] = (0, import_react.useState)(0);
140
+ const [isLive, setIsLive] = (0, import_react.useState)(false);
141
+ const [atLiveEdge, setAtLiveEdge] = (0, import_react.useState)(true);
142
+ const [showControls, setShowControls] = (0, import_react.useState)(false);
143
+ (0, import_react.useEffect)(() => {
144
+ setZoom(config.player.defaultZoom || 1);
145
+ }, [config.player.defaultZoom]);
146
+ (0, import_react.useEffect)(() => {
147
+ if (!player) return;
148
+ if (containerRef?.current) {
149
+ player.setFullscreenElement(containerRef.current);
150
+ }
151
+ const syncTracks = () => {
152
+ setQualities(player.getAvailableQualities());
153
+ setQualitySelection(player.getQuality());
154
+ const q = player.getQuality();
155
+ setActiveLevel(typeof q === "number" ? q : -1);
156
+ setTextTracks(player.getTextTracks());
157
+ setSelectedTextTrack(player.getSelectedTextTrack());
158
+ setAudioTracks(player.getAudioTracks());
159
+ setSelectedAudioTrack(player.getSelectedAudioTrack());
160
+ setIsLive(player.isLive());
161
+ setAtLiveEdge(player.isAtLiveEdge());
162
+ setVolumeState(player.getVolume());
163
+ setMuted(player.isMuted());
164
+ setPlaybackRateState(player.getPlaybackRate());
165
+ setIsFullscreen(player.isFullscreen());
166
+ };
167
+ const offs = [
168
+ player.on("ready", () => {
169
+ setShowControls(true);
170
+ syncTracks();
171
+ }),
172
+ player.on("statechange", ({ state: state2 }) => {
173
+ setIsPlaying(state2 === "playing");
174
+ if (state2 === "ready" || state2 === "playing" || state2 === "paused" || state2 === "buffering" || state2 === "renewing") {
175
+ setShowControls(true);
176
+ }
177
+ if (state2 === "idle" || state2 === "loading" || state2 === "destroyed") {
178
+ setShowControls(false);
179
+ }
180
+ setIsLive(player.isLive());
181
+ setAtLiveEdge(player.isAtLiveEdge());
182
+ }),
183
+ player.on("timeupdate", ({ currentTime: t, duration: d }) => {
184
+ setCurrentTime(t);
185
+ setDuration(d);
186
+ setAtLiveEdge(player.isAtLiveEdge());
187
+ }),
188
+ player.on("progress", ({ bufferedEnd: end }) => {
189
+ setBufferedEnd(end);
190
+ }),
191
+ player.on("volumechange", ({ volume: v, muted: m }) => {
192
+ setVolumeState(v);
193
+ setMuted(m);
194
+ }),
195
+ player.on("qualitychange", ({ selection }) => {
196
+ setQualitySelection(selection);
197
+ setActiveLevel(typeof selection === "number" ? selection : -1);
198
+ setQualities(player.getAvailableQualities());
199
+ }),
200
+ player.on("texttrackchange", ({ tracks, selection }) => {
201
+ setTextTracks(tracks);
202
+ setSelectedTextTrack(selection);
203
+ }),
204
+ player.on("audiotrackchange", ({ tracks, selection }) => {
205
+ setAudioTracks(tracks);
206
+ setSelectedAudioTrack(selection);
207
+ }),
208
+ player.on("fullscreenchange", ({ isFullscreen: fs }) => {
209
+ setIsFullscreen(fs);
210
+ }),
211
+ player.on("play", () => setIsPlaying(true)),
212
+ player.on("pause", () => setIsPlaying(false)),
213
+ player.on("ended", () => setIsPlaying(false))
214
+ ];
215
+ const onFs = () => setIsFullscreen(Boolean(document.fullscreenElement));
216
+ document.addEventListener("fullscreenchange", onFs);
217
+ const state = player.getState();
218
+ if (state === "ready" || state === "playing" || state === "paused" || state === "buffering") {
219
+ setShowControls(true);
220
+ syncTracks();
221
+ setIsPlaying(state === "playing");
222
+ setCurrentTime(player.getCurrentTime());
223
+ setDuration(player.getDuration());
224
+ }
225
+ return () => {
226
+ for (const off of offs) off();
227
+ document.removeEventListener("fullscreenchange", onFs);
228
+ };
229
+ }, [player, containerRef]);
230
+ const togglePlay = (0, import_react.useCallback)(() => {
231
+ if (!player) return;
232
+ if (player.getState() === "playing") {
233
+ player.pause();
234
+ } else {
235
+ void player.play();
236
+ }
237
+ }, [player]);
238
+ const seekTo = (0, import_react.useCallback)(
239
+ (time) => {
240
+ player?.seek(time);
241
+ },
242
+ [player]
243
+ );
244
+ const skipBy = (0, import_react.useCallback)(
245
+ (deltaSeconds) => {
246
+ if (!player) return;
247
+ player.seek(player.getCurrentTime() + deltaSeconds);
248
+ },
249
+ [player]
250
+ );
251
+ const setVolume = (0, import_react.useCallback)(
252
+ (v) => {
253
+ player?.setVolume(v);
254
+ if (v > 0 && player?.isMuted()) player.unmute();
255
+ },
256
+ [player]
257
+ );
258
+ const toggleMute = (0, import_react.useCallback)(() => {
259
+ if (!player) return;
260
+ if (player.isMuted()) player.unmute();
261
+ else player.mute();
262
+ }, [player]);
263
+ const enableAudio = (0, import_react.useCallback)(() => {
264
+ if (!player) return;
265
+ player.unmute();
266
+ if (player.getVolume() <= 0) player.setVolume(1);
267
+ }, [player]);
268
+ const setPlaybackRate = (0, import_react.useCallback)(
269
+ (rate) => {
270
+ player?.setPlaybackRate(rate);
271
+ setPlaybackRateState(rate);
272
+ },
273
+ [player]
274
+ );
275
+ const setQuality = (0, import_react.useCallback)(
276
+ (selection) => {
277
+ player?.setQuality(selection);
278
+ },
279
+ [player]
280
+ );
281
+ const setTextTrack = (0, import_react.useCallback)(
282
+ (selection) => {
283
+ player?.setTextTrack(selection);
284
+ },
285
+ [player]
286
+ );
287
+ const setAudioTrack = (0, import_react.useCallback)(
288
+ (index) => {
289
+ player?.setAudioTrack(index);
290
+ },
291
+ [player]
292
+ );
293
+ const toggleFullscreen = (0, import_react.useCallback)(async () => {
294
+ if (!player) return;
295
+ if (player.isFullscreen()) await player.exitFullscreen();
296
+ else await player.enterFullscreen();
297
+ }, [player]);
298
+ const goToLive = (0, import_react.useCallback)(() => {
299
+ if (!player) return false;
300
+ const result = player.goToLive();
301
+ setAtLiveEdge(player.isAtLiveEdge());
302
+ return Boolean(result?.moved);
303
+ }, [player]);
304
+ const zoomIn = (0, import_react.useCallback)(() => {
305
+ setZoom((prev) => nextZoom(prev, 1));
306
+ }, []);
307
+ const zoomOut = (0, import_react.useCallback)(() => {
308
+ setZoom((prev) => nextZoom(prev, -1));
309
+ }, []);
310
+ return {
311
+ isPlaying,
312
+ currentTime,
313
+ duration,
314
+ bufferedEnd,
315
+ volume,
316
+ muted,
317
+ playbackRate,
318
+ isFullscreen,
319
+ zoom,
320
+ qualities,
321
+ qualitySelection,
322
+ activeLevel,
323
+ textTracks,
324
+ selectedTextTrack,
325
+ audioTracks,
326
+ selectedAudioTrack,
327
+ isLive,
328
+ atLiveEdge,
329
+ showControls,
330
+ togglePlay,
331
+ seekTo,
332
+ skipBy,
333
+ setVolume,
334
+ toggleMute,
335
+ enableAudio,
336
+ setPlaybackRate,
337
+ setQuality,
338
+ setTextTrack,
339
+ setAudioTrack,
340
+ toggleFullscreen,
341
+ goToLive,
342
+ zoomIn,
343
+ zoomOut
344
+ };
345
+ }
346
+
347
+ // src/components/PlayIconPreset.tsx
348
+ var import_jsx_runtime = require("react/jsx-runtime");
349
+ function PlayIconPreset({
350
+ preset,
351
+ size = 36
352
+ }) {
353
+ if (preset === "circle") {
354
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: [
355
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "10", opacity: "0.35" }),
356
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 8.5v7l6-3.5-6-3.5z" })
357
+ ] });
358
+ }
359
+ if (preset === "roundedSquare") {
360
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: [
361
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "4", opacity: "0.35" }),
362
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 8.5v7l6-3.5-6-3.5z" })
363
+ ] });
364
+ }
365
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 5.5v13l11-6.5-11-6.5z" }) });
366
+ }
367
+
368
+ // src/components/PlayerCenterOverlay.tsx
369
+ var import_jsx_runtime2 = require("react/jsx-runtime");
370
+ var ENABLE_AUDIO_PROMPT = "Tap to enable audio";
371
+ function PlayerCenterOverlay({
372
+ kind,
373
+ playIconPreset,
374
+ onPlay,
375
+ onEnableAudio
376
+ }) {
377
+ if (kind === "none") return null;
378
+ const isPlay = kind === "play";
379
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
380
+ "div",
381
+ {
382
+ className: "nsg-player-center-overlay",
383
+ onClick: (event) => {
384
+ event.stopPropagation();
385
+ if (isPlay) onPlay();
386
+ else onEnableAudio();
387
+ },
388
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
389
+ "button",
390
+ {
391
+ type: "button",
392
+ className: "nsg-player-center-btn",
393
+ "aria-label": isPlay ? "Play" : ENABLE_AUDIO_PROMPT,
394
+ onClick: (event) => {
395
+ event.stopPropagation();
396
+ if (isPlay) onPlay();
397
+ else onEnableAudio();
398
+ },
399
+ children: [
400
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "nsg-player-center-disc", children: isPlay ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PlayIconPreset, { preset: playIconPreset, size: 36 }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "34", height: "34", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M3 10v4h3.2L11 19V5L6.2 10H3zm11.5 2A4.5 4.5 0 0 0 12 8.2v7.6A4.5 4.5 0 0 0 14.5 12zm3.5 0a8 8 0 0 0-3.2-6.4v2.3a5.7 5.7 0 0 1 0 8.2v2.3A8 8 0 0 0 18 12z" }) }) }),
401
+ isPlay ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "nsg-player-center-label", children: ENABLE_AUDIO_PROMPT })
402
+ ]
403
+ }
404
+ )
405
+ }
406
+ );
407
+ }
408
+
409
+ // src/components/PlayerMenu.tsx
410
+ var import_react2 = require("react");
411
+ var import_jsx_runtime3 = require("react/jsx-runtime");
412
+ function menuVars(kind) {
413
+ if (kind === "speed") {
414
+ return {
415
+ text: "var(--player-speed-text)",
416
+ bg: "var(--player-speed-bg)",
417
+ activeBg: "var(--player-speed-active-bg)",
418
+ activeText: "var(--player-speed-active-text)"
419
+ };
420
+ }
421
+ return {
422
+ text: "var(--player-quality-text)",
423
+ bg: "var(--player-quality-bg)",
424
+ activeBg: "var(--player-quality-active-bg)",
425
+ activeText: "var(--player-quality-active-text)"
426
+ };
427
+ }
428
+ function PlayerMenu({
429
+ label,
430
+ buttonLabel,
431
+ children,
432
+ menuKind = "generic"
433
+ }) {
434
+ const [open, setOpen] = (0, import_react2.useState)(false);
435
+ const rootRef = (0, import_react2.useRef)(null);
436
+ const menuId = (0, import_react2.useId)();
437
+ const vars = menuVars(menuKind);
438
+ (0, import_react2.useEffect)(() => {
439
+ if (!open) return;
440
+ const onPointerDown = (event) => {
441
+ if (!rootRef.current?.contains(event.target)) setOpen(false);
442
+ };
443
+ const onKeyDown = (event) => {
444
+ if (event.key === "Escape") setOpen(false);
445
+ };
446
+ document.addEventListener("mousedown", onPointerDown);
447
+ document.addEventListener("keydown", onKeyDown);
448
+ return () => {
449
+ document.removeEventListener("mousedown", onPointerDown);
450
+ document.removeEventListener("keydown", onKeyDown);
451
+ };
452
+ }, [open]);
453
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { ref: rootRef, className: "nsg-player-menu", children: [
454
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
455
+ "button",
456
+ {
457
+ type: "button",
458
+ className: "nsg-player-menu__trigger",
459
+ "aria-label": label,
460
+ "aria-haspopup": "menu",
461
+ "aria-expanded": open,
462
+ "aria-controls": menuId,
463
+ onClick: (event) => {
464
+ event.stopPropagation();
465
+ setOpen((prev) => !prev);
466
+ },
467
+ children: buttonLabel
468
+ }
469
+ ),
470
+ open ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
471
+ "div",
472
+ {
473
+ id: menuId,
474
+ role: "menu",
475
+ "aria-label": label,
476
+ className: "nsg-player-menu__panel",
477
+ style: { backgroundColor: vars.bg, color: vars.text },
478
+ onClick: (event) => event.stopPropagation(),
479
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { onClick: () => setOpen(false), children })
480
+ }
481
+ ) : null
482
+ ] });
483
+ }
484
+ function PlayerMenuItem({
485
+ active,
486
+ children,
487
+ onSelect,
488
+ menuKind = "generic"
489
+ }) {
490
+ const vars = menuVars(menuKind);
491
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
492
+ "button",
493
+ {
494
+ type: "button",
495
+ role: "menuitemradio",
496
+ "aria-checked": active,
497
+ className: "nsg-player-menu__item",
498
+ style: {
499
+ color: active ? vars.activeText : vars.text,
500
+ backgroundColor: active ? vars.activeBg : void 0
501
+ },
502
+ onClick: (event) => {
503
+ event.stopPropagation();
504
+ onSelect();
505
+ },
506
+ children
507
+ }
508
+ );
509
+ }
510
+
511
+ // src/components/AudioTrackSelector.tsx
512
+ var import_jsx_runtime4 = require("react/jsx-runtime");
513
+ function AudioTrackSelector({
514
+ tracks,
515
+ selection,
516
+ onSelect
517
+ }) {
518
+ if (tracks.length <= 1) return null;
519
+ const buttonLabel = tracks.find((t) => t.index === selection)?.label ?? "Audio";
520
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PlayerMenu, { label: "Audio track", buttonLabel, children: tracks.map((track) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
521
+ PlayerMenuItem,
522
+ {
523
+ active: selection === track.index,
524
+ onSelect: () => onSelect(track.index),
525
+ children: track.label
526
+ },
527
+ track.id
528
+ )) });
529
+ }
530
+
531
+ // src/components/LiveBadgeButton.tsx
532
+ var import_react3 = require("react");
533
+ var import_jsx_runtime5 = require("react/jsx-runtime");
534
+ var ALREADY_AT_LIVE_MESSAGE = "Already at the live edge";
535
+ function LiveBadgeButton({
536
+ atLiveEdge,
537
+ onGoToLive
538
+ }) {
539
+ const tooltipId = (0, import_react3.useId)();
540
+ const [tooltipVisible, setTooltipVisible] = (0, import_react3.useState)(false);
541
+ const hideTimerRef = (0, import_react3.useRef)(null);
542
+ (0, import_react3.useEffect)(() => {
543
+ return () => {
544
+ if (hideTimerRef.current) window.clearTimeout(hideTimerRef.current);
545
+ };
546
+ }, []);
547
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "nsg-player-live", children: [
548
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
549
+ "button",
550
+ {
551
+ type: "button",
552
+ className: "nsg-player-live__btn",
553
+ "aria-label": atLiveEdge ? "Live \u2014 already on the latest feed" : "Go to live \u2014 jump to the latest feed",
554
+ "aria-describedby": tooltipVisible ? tooltipId : void 0,
555
+ title: atLiveEdge ? ALREADY_AT_LIVE_MESSAGE : "Go to live",
556
+ onClick: (event) => {
557
+ event.stopPropagation();
558
+ const moved = onGoToLive();
559
+ if (!moved) {
560
+ setTooltipVisible(true);
561
+ if (hideTimerRef.current) window.clearTimeout(hideTimerRef.current);
562
+ hideTimerRef.current = window.setTimeout(() => {
563
+ setTooltipVisible(false);
564
+ hideTimerRef.current = null;
565
+ }, 2200);
566
+ }
567
+ },
568
+ children: [
569
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
570
+ "span",
571
+ {
572
+ className: "nsg-player-live__dot",
573
+ style: atLiveEdge ? {
574
+ backgroundColor: "var(--player-live-dot)",
575
+ boxShadow: "0 0 0 1px color-mix(in srgb, var(--player-live-dot) 40%, transparent)"
576
+ } : {
577
+ backgroundColor: "transparent",
578
+ boxShadow: "inset 0 0 0 1.5px var(--player-live-dot)",
579
+ opacity: 0.85
580
+ },
581
+ "aria-hidden": true
582
+ }
583
+ ),
584
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
585
+ "span",
586
+ {
587
+ style: {
588
+ color: atLiveEdge ? "var(--player-live-dot)" : "color-mix(in srgb, var(--player-live-dot) 70%, white)"
589
+ },
590
+ children: "Live"
591
+ }
592
+ )
593
+ ]
594
+ }
595
+ ),
596
+ tooltipVisible ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { id: tooltipId, role: "status", className: "nsg-player-live__tooltip", children: ALREADY_AT_LIVE_MESSAGE }) : null
597
+ ] });
598
+ }
599
+
600
+ // src/components/PlaybackSpeedSelector.tsx
601
+ var import_react4 = require("react");
602
+ var import_jsx_runtime6 = require("react/jsx-runtime");
603
+ function PlaybackSpeedSelector({
604
+ rate,
605
+ speedOptionCount,
606
+ onSelect
607
+ }) {
608
+ const rates = (0, import_react4.useMemo)(
609
+ () => resolveVisiblePlaybackRates(speedOptionCount),
610
+ [speedOptionCount]
611
+ );
612
+ (0, import_react4.useEffect)(() => {
613
+ const snapped = snapPlaybackRate(rate, rates);
614
+ if (snapped !== rate) onSelect(snapped);
615
+ }, [rate, rates, onSelect]);
616
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PlayerMenu, { label: "Playback speed", buttonLabel: `${rate}x`, menuKind: "speed", children: rates.map((item) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
617
+ PlayerMenuItem,
618
+ {
619
+ active: rate === item,
620
+ menuKind: "speed",
621
+ onSelect: () => onSelect(item),
622
+ children: item === 1 ? "Normal" : `${item}x`
623
+ },
624
+ item
625
+ )) });
626
+ }
627
+
628
+ // src/components/QualitySelector.tsx
629
+ var import_jsx_runtime7 = require("react/jsx-runtime");
630
+ function QualitySelector({
631
+ qualities,
632
+ selection,
633
+ activeLevel,
634
+ onSelect
635
+ }) {
636
+ if (qualities.length <= 1) return null;
637
+ const sorted = [...qualities].sort(
638
+ (a, b) => b.height - a.height || b.bitrate - a.bitrate
639
+ );
640
+ const activeLabel = activeLevel >= 0 ? qualities.find((q) => q.index === activeLevel)?.label : void 0;
641
+ const buttonLabel = selection === "auto" ? activeLabel ? `Auto (${activeLabel})` : "Auto" : qualities.find((q) => q.index === selection)?.label ?? "Quality";
642
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(PlayerMenu, { label: "Quality", buttonLabel, menuKind: "quality", children: [
643
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
644
+ PlayerMenuItem,
645
+ {
646
+ active: selection === "auto",
647
+ menuKind: "quality",
648
+ onSelect: () => onSelect("auto"),
649
+ children: [
650
+ "Auto",
651
+ activeLabel ? ` (${activeLabel})` : ""
652
+ ]
653
+ }
654
+ ),
655
+ sorted.map((level) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
656
+ PlayerMenuItem,
657
+ {
658
+ active: selection === level.index,
659
+ menuKind: "quality",
660
+ onSelect: () => onSelect(level.index),
661
+ children: level.label
662
+ },
663
+ level.index
664
+ ))
665
+ ] });
666
+ }
667
+
668
+ // src/components/SeekBar.tsx
669
+ var import_react5 = require("react");
670
+ var import_jsx_runtime8 = require("react/jsx-runtime");
671
+ var INITIAL_HOVER = {
672
+ visible: false,
673
+ time: 0,
674
+ percent: 0
675
+ };
676
+ function seekFromPointer(clientX, left, width, duration) {
677
+ const ratio = width > 0 ? Math.min(1, Math.max(0, (clientX - left) / width)) : 0;
678
+ return { time: ratio * duration, percent: ratio * 100 };
679
+ }
680
+ function SeekBar({
681
+ currentTime,
682
+ duration,
683
+ bufferedEnd,
684
+ onSeek,
685
+ seekInputRef
686
+ }) {
687
+ const trackRef = (0, import_react5.useRef)(null);
688
+ const [hover, setHover] = (0, import_react5.useState)(INITIAL_HOVER);
689
+ const max = duration > 0 ? duration : 0;
690
+ const bufferedPct = max > 0 ? Math.min(100, bufferedEnd / max * 100) : 0;
691
+ const playedPct = max > 0 ? Math.min(100, currentTime / max * 100) : 0;
692
+ const updateHover = (0, import_react5.useCallback)(
693
+ (clientX) => {
694
+ const track = trackRef.current;
695
+ if (!track || max <= 0) return;
696
+ const rect = track.getBoundingClientRect();
697
+ const next = seekFromPointer(clientX, rect.left, rect.width, max);
698
+ setHover({ visible: true, time: next.time, percent: next.percent });
699
+ },
700
+ [max]
701
+ );
702
+ const onPointerDown = (event) => {
703
+ if (max <= 0) return;
704
+ const track = trackRef.current;
705
+ if (!track) return;
706
+ const rect = track.getBoundingClientRect();
707
+ const { time } = seekFromPointer(event.clientX, rect.left, rect.width, max);
708
+ onSeek(time);
709
+ updateHover(event.clientX);
710
+ };
711
+ const onKeyDown = (event) => {
712
+ if (max <= 0) return;
713
+ const step = event.shiftKey ? 10 : 5;
714
+ if (event.key === "ArrowLeft") {
715
+ event.preventDefault();
716
+ onSeek(Math.max(0, currentTime - step));
717
+ } else if (event.key === "ArrowRight") {
718
+ event.preventDefault();
719
+ onSeek(Math.min(max, currentTime + step));
720
+ } else if (event.key === "Home") {
721
+ event.preventDefault();
722
+ onSeek(0);
723
+ } else if (event.key === "End") {
724
+ event.preventDefault();
725
+ onSeek(max);
726
+ }
727
+ };
728
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
729
+ "div",
730
+ {
731
+ ref: trackRef,
732
+ className: "nsg-player-seek",
733
+ onPointerEnter: (e) => updateHover(e.clientX),
734
+ onPointerMove: (e) => updateHover(e.clientX),
735
+ onPointerLeave: () => setHover(INITIAL_HOVER),
736
+ onPointerDown,
737
+ role: "presentation",
738
+ children: [
739
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
740
+ "div",
741
+ {
742
+ className: "nsg-player-seek__buffered",
743
+ style: { width: `${bufferedPct}%` }
744
+ }
745
+ ),
746
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
747
+ "div",
748
+ {
749
+ className: "nsg-player-seek__played",
750
+ style: { width: `${playedPct}%` }
751
+ }
752
+ ),
753
+ hover.visible && max > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
754
+ "div",
755
+ {
756
+ className: "nsg-player-seek__tooltip",
757
+ style: { left: `${hover.percent}%` },
758
+ role: "tooltip",
759
+ children: formatPlaybackTime(hover.time)
760
+ }
761
+ ) : null,
762
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
763
+ "input",
764
+ {
765
+ ref: seekInputRef,
766
+ type: "range",
767
+ min: 0,
768
+ max: max || 0,
769
+ step: 0.1,
770
+ value: Number.isFinite(currentTime) ? currentTime : 0,
771
+ "aria-label": "Seek",
772
+ "aria-valuetext": formatPlaybackTime(currentTime),
773
+ className: "nsg-player-seek__input",
774
+ onChange: (event) => onSeek(Number(event.target.value)),
775
+ onKeyDown
776
+ }
777
+ )
778
+ ]
779
+ }
780
+ );
781
+ }
782
+
783
+ // src/components/TextTrackSelector.tsx
784
+ var import_jsx_runtime9 = require("react/jsx-runtime");
785
+ function TextTrackSelector({
786
+ tracks,
787
+ selection,
788
+ onSelect
789
+ }) {
790
+ if (tracks.length === 0) return null;
791
+ const buttonLabel = selection === "off" ? "CC" : tracks.find((t) => t.index === selection)?.label ?? "CC";
792
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(PlayerMenu, { label: "Captions", buttonLabel, children: [
793
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
794
+ PlayerMenuItem,
795
+ {
796
+ active: selection === "off",
797
+ onSelect: () => onSelect("off"),
798
+ children: "Off"
799
+ }
800
+ ),
801
+ tracks.map((track) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
802
+ PlayerMenuItem,
803
+ {
804
+ active: selection === track.index,
805
+ onSelect: () => onSelect(track.index),
806
+ children: track.label
807
+ },
808
+ track.id
809
+ ))
810
+ ] });
811
+ }
812
+
813
+ // src/components/PlayerControlBar.tsx
814
+ var import_jsx_runtime10 = require("react/jsx-runtime");
815
+ function PlayerControlBar(props) {
816
+ const {
817
+ config,
818
+ isPlaying,
819
+ currentTime,
820
+ duration,
821
+ bufferedEnd,
822
+ volume,
823
+ muted,
824
+ playbackRate,
825
+ isFullscreen,
826
+ zoom,
827
+ qualities,
828
+ qualitySelection,
829
+ activeLevel,
830
+ textTracks,
831
+ selectedTextTrack,
832
+ audioTracks,
833
+ selectedAudioTrack,
834
+ onTogglePlay,
835
+ onSeek,
836
+ onSkip,
837
+ isLive,
838
+ atLiveEdge,
839
+ onGoToLive,
840
+ onVolumeChange,
841
+ onToggleMute,
842
+ onPlaybackRateChange,
843
+ onQualityChange,
844
+ onTextTrackChange,
845
+ onAudioTrackChange,
846
+ onToggleFullscreen,
847
+ onZoomIn,
848
+ onZoomOut,
849
+ seekBarRef
850
+ } = props;
851
+ const controls = config.controls;
852
+ const showZoom = config.player.zoomEnabled && controls.showZoom;
853
+ const skipSeconds = config.player.skipSeconds;
854
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
855
+ "div",
856
+ {
857
+ className: "nsg-player-control-bar",
858
+ onClick: (event) => event.stopPropagation(),
859
+ onKeyDown: (event) => event.stopPropagation(),
860
+ children: [
861
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
862
+ SeekBar,
863
+ {
864
+ currentTime,
865
+ duration,
866
+ bufferedEnd,
867
+ onSeek,
868
+ seekInputRef: seekBarRef
869
+ }
870
+ ),
871
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "nsg-player-control-row", children: [
872
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
873
+ "button",
874
+ {
875
+ type: "button",
876
+ className: "nsg-player-btn",
877
+ "aria-label": isPlaying ? "Pause" : "Play",
878
+ onClick: onTogglePlay,
879
+ children: isPlaying ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PauseIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PlayIcon, {})
880
+ }
881
+ ),
882
+ controls.showSkip ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
883
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
884
+ "button",
885
+ {
886
+ type: "button",
887
+ className: "nsg-player-btn",
888
+ style: { color: "var(--player-skip-icon)" },
889
+ "aria-label": `Back ${skipSeconds} seconds`,
890
+ onClick: () => onSkip("backward"),
891
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SkipIcon, { label: String(skipSeconds), forward: false })
892
+ }
893
+ ),
894
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
895
+ "button",
896
+ {
897
+ type: "button",
898
+ className: "nsg-player-btn",
899
+ style: { color: "var(--player-skip-icon)" },
900
+ "aria-label": `Forward ${skipSeconds} seconds`,
901
+ onClick: () => onSkip("forward"),
902
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SkipIcon, { label: String(skipSeconds), forward: true })
903
+ }
904
+ )
905
+ ] }) : null,
906
+ controls.showVolume ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "nsg-player-volume", children: [
907
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
908
+ "button",
909
+ {
910
+ type: "button",
911
+ className: "nsg-player-btn",
912
+ style: { color: "var(--player-volume-icon)" },
913
+ "aria-label": muted || volume === 0 ? "Unmute" : "Mute",
914
+ onClick: onToggleMute,
915
+ children: muted || volume === 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(MuteIcon, {}) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(VolumeIcon, {})
916
+ }
917
+ ),
918
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
919
+ "input",
920
+ {
921
+ type: "range",
922
+ min: 0,
923
+ max: 1,
924
+ step: 0.05,
925
+ value: muted ? 0 : volume,
926
+ "aria-label": "Volume",
927
+ className: "nsg-player-volume__slider",
928
+ onChange: (event) => onVolumeChange(Number(event.target.value))
929
+ }
930
+ )
931
+ ] }) : null,
932
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "nsg-player-time", children: [
933
+ formatPlaybackTime(currentTime),
934
+ " / ",
935
+ formatPlaybackTime(duration)
936
+ ] }),
937
+ controls.showLive && isLive ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LiveBadgeButton, { atLiveEdge, onGoToLive }) : null,
938
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "nsg-player-control-row-end", children: [
939
+ showZoom ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
940
+ "div",
941
+ {
942
+ className: "nsg-player-zoom",
943
+ role: "group",
944
+ "aria-label": `Zoom ${zoom}\xD7`,
945
+ children: [
946
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "nsg-player-zoom__label", children: [
947
+ "Zoom ",
948
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { style: { fontVariantNumeric: "tabular-nums" }, children: [
949
+ zoom,
950
+ "\xD7"
951
+ ] })
952
+ ] }),
953
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
954
+ "button",
955
+ {
956
+ type: "button",
957
+ className: "nsg-player-btn",
958
+ "aria-label": `Zoom out (current ${zoom}\xD7)`,
959
+ disabled: zoom <= 1,
960
+ onClick: onZoomOut,
961
+ children: "\u2212"
962
+ }
963
+ ),
964
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
965
+ "button",
966
+ {
967
+ type: "button",
968
+ className: "nsg-player-btn",
969
+ "aria-label": `Zoom in (current ${zoom}\xD7)`,
970
+ disabled: zoom >= 2,
971
+ onClick: onZoomIn,
972
+ children: "+"
973
+ }
974
+ )
975
+ ]
976
+ }
977
+ ) : null,
978
+ controls.showSpeed ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
979
+ PlaybackSpeedSelector,
980
+ {
981
+ rate: playbackRate,
982
+ speedOptionCount: config.player.speedOptionCount,
983
+ onSelect: onPlaybackRateChange
984
+ }
985
+ ) : null,
986
+ controls.showQuality ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
987
+ QualitySelector,
988
+ {
989
+ qualities,
990
+ selection: qualitySelection,
991
+ activeLevel,
992
+ onSelect: onQualityChange
993
+ }
994
+ ) : null,
995
+ controls.showCaptions ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
996
+ TextTrackSelector,
997
+ {
998
+ tracks: textTracks,
999
+ selection: selectedTextTrack,
1000
+ onSelect: onTextTrackChange
1001
+ }
1002
+ ) : null,
1003
+ controls.showAudio ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1004
+ AudioTrackSelector,
1005
+ {
1006
+ tracks: audioTracks,
1007
+ selection: selectedAudioTrack,
1008
+ onSelect: onAudioTrackChange
1009
+ }
1010
+ ) : null,
1011
+ controls.showFullscreen ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1012
+ "button",
1013
+ {
1014
+ type: "button",
1015
+ className: "nsg-player-btn",
1016
+ "aria-label": isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
1017
+ onClick: () => void onToggleFullscreen(),
1018
+ children: isFullscreen ? "\u26F6" : "\u26F6"
1019
+ }
1020
+ ) : null
1021
+ ] })
1022
+ ] })
1023
+ ]
1024
+ }
1025
+ );
1026
+ }
1027
+ function PlayIcon() {
1028
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "M8 5v14l11-7z" }) });
1029
+ }
1030
+ function PauseIcon() {
1031
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "M6 5h4v14H6zm8 0h4v14h-4z" }) });
1032
+ }
1033
+ function SkipIcon({ label, forward }) {
1034
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { style: { display: "flex", flexDirection: "column", alignItems: "center", lineHeight: 1 }, children: [
1035
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("svg", { width: "16", height: "14", viewBox: "0 0 24 16", fill: "currentColor", "aria-hidden": true, children: forward ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "M3 2v12l9-6-9-6zm9 0v12l9-6-9-6z" }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "M12 2v12L3 8l9-6zm9 0v12l-9-6 9-6z" }) }),
1036
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { style: { fontSize: 9, fontWeight: 700 }, children: label })
1037
+ ] });
1038
+ }
1039
+ function VolumeIcon() {
1040
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "M3 10v4h4l5 5V5L7 10H3zm13.5 2a4.5 4.5 0 0 0-2.5-4v8a4.5 4.5 0 0 0 2.5-4z" }) });
1041
+ }
1042
+ function MuteIcon() {
1043
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "M16.5 12a4.5 4.5 0 0 0-2.5-4v2.2l2.5 2.5V12zm3.5 0c0 .9-.2 1.7-.5 2.5l1.5 1.5c.6-1.2 1-2.6 1-4 0-3.2-1.8-5.9-4.5-7.2v2.2c1.8 1.1 3 3 3 5.2zM3.3 2 2 3.3 7.7 9H3v6h4l5 5v-6.7l6.7 6.7 1.3-1.3L3.3 2zM14 5l-2.1 2.1L14 9.2V5z" }) });
1044
+ }
1045
+
1046
+ // src/components/PlayerSkipCue.tsx
1047
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1048
+ function PlayerSkipCue({
1049
+ direction,
1050
+ cueId,
1051
+ seconds
1052
+ }) {
1053
+ if (!direction) return null;
1054
+ const isForward = direction === "forward";
1055
+ const label = isForward ? `+${seconds}` : `-${seconds}`;
1056
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1057
+ "div",
1058
+ {
1059
+ className: `nsg-player-skip-cue ${isForward ? "nsg-player-skip-cue--forward" : "nsg-player-skip-cue--backward"}`,
1060
+ "aria-hidden": true,
1061
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "nsg-player-skip-cue-badge", children: [
1062
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "nsg-player-skip-cue-disc", children: isForward ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("path", { d: "M3 6v12l8.5-6L3 6zm9 0v12l8.5-6L12 6z" }) }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("path", { d: "M11.5 12 20 6v12l-8.5-6zm-8.5 0L11 6v12L3 12z" }) }) }),
1063
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { style: { fontSize: "1.125rem", fontWeight: 600 }, children: label })
1064
+ ] })
1065
+ },
1066
+ cueId
1067
+ );
1068
+ }
1069
+
1070
+ // src/components/PlayerChrome.tsx
1071
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1072
+ function PlayerChrome({
1073
+ player,
1074
+ config,
1075
+ containerRef,
1076
+ videoSlot,
1077
+ className
1078
+ }) {
1079
+ const rootRef = (0, import_react6.useRef)(null);
1080
+ const seekBarRef = (0, import_react6.useRef)(null);
1081
+ const skipCueTimerRef = (0, import_react6.useRef)(null);
1082
+ const [skipCue, setSkipCue] = (0, import_react6.useState)(null);
1083
+ const controls = usePlayerControls({
1084
+ player,
1085
+ config,
1086
+ containerRef
1087
+ });
1088
+ const overlay = resolvePlayerOverlay({
1089
+ showControls: controls.showControls,
1090
+ isPlaying: controls.isPlaying,
1091
+ muted: controls.muted,
1092
+ volume: controls.volume
1093
+ });
1094
+ const flashSkipCue = (0, import_react6.useCallback)(
1095
+ (direction) => {
1096
+ setSkipCue({ direction, id: Date.now() });
1097
+ if (skipCueTimerRef.current) window.clearTimeout(skipCueTimerRef.current);
1098
+ skipCueTimerRef.current = window.setTimeout(() => {
1099
+ setSkipCue(null);
1100
+ skipCueTimerRef.current = null;
1101
+ }, config.controls.seekCueDurationMs);
1102
+ },
1103
+ [config.controls.seekCueDurationMs]
1104
+ );
1105
+ const skip = (0, import_react6.useCallback)(
1106
+ (direction) => {
1107
+ if (!config.controls.showSkip) return;
1108
+ const delta = direction === "forward" ? config.player.skipSeconds : -config.player.skipSeconds;
1109
+ controls.skipBy(delta);
1110
+ flashSkipCue(direction);
1111
+ },
1112
+ [
1113
+ config.controls.showSkip,
1114
+ config.player.skipSeconds,
1115
+ controls,
1116
+ flashSkipCue
1117
+ ]
1118
+ );
1119
+ (0, import_react6.useEffect)(() => {
1120
+ return () => {
1121
+ if (skipCueTimerRef.current) window.clearTimeout(skipCueTimerRef.current);
1122
+ };
1123
+ }, []);
1124
+ (0, import_react6.useEffect)(() => {
1125
+ const root = rootRef.current;
1126
+ if (!root || !controls.showControls || !config.controls.keyboardShortcuts) {
1127
+ return;
1128
+ }
1129
+ const onKeyDown = (event) => {
1130
+ const target = event.target;
1131
+ if (target && (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable)) {
1132
+ return;
1133
+ }
1134
+ switch (event.key) {
1135
+ case " ":
1136
+ case "k":
1137
+ case "K":
1138
+ event.preventDefault();
1139
+ controls.togglePlay();
1140
+ break;
1141
+ case "ArrowLeft":
1142
+ case "j":
1143
+ case "J":
1144
+ event.preventDefault();
1145
+ skip("backward");
1146
+ break;
1147
+ case "ArrowRight":
1148
+ case "l":
1149
+ case "L":
1150
+ event.preventDefault();
1151
+ skip("forward");
1152
+ break;
1153
+ case "m":
1154
+ case "M":
1155
+ event.preventDefault();
1156
+ controls.toggleMute();
1157
+ break;
1158
+ case "End":
1159
+ if (controls.isLive && config.controls.showLive) {
1160
+ event.preventDefault();
1161
+ controls.goToLive();
1162
+ }
1163
+ break;
1164
+ case "f":
1165
+ case "F":
1166
+ event.preventDefault();
1167
+ void controls.toggleFullscreen();
1168
+ break;
1169
+ case "+":
1170
+ case "=":
1171
+ if (config.player.zoomEnabled && config.controls.showZoom) {
1172
+ event.preventDefault();
1173
+ controls.zoomIn();
1174
+ }
1175
+ break;
1176
+ case "-":
1177
+ case "_":
1178
+ if (config.player.zoomEnabled && config.controls.showZoom) {
1179
+ event.preventDefault();
1180
+ controls.zoomOut();
1181
+ }
1182
+ break;
1183
+ default:
1184
+ break;
1185
+ }
1186
+ };
1187
+ root.tabIndex = 0;
1188
+ root.addEventListener("keydown", onKeyDown);
1189
+ return () => root.removeEventListener("keydown", onKeyDown);
1190
+ }, [controls, config, skip]);
1191
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1192
+ "div",
1193
+ {
1194
+ ref: rootRef,
1195
+ className: ["nsg-player-root", className].filter(Boolean).join(" "),
1196
+ role: "region",
1197
+ "aria-label": "Video player",
1198
+ onClick: controls.showControls ? controls.togglePlay : void 0,
1199
+ children: [
1200
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1201
+ "div",
1202
+ {
1203
+ className: "nsg-player-video-wrap",
1204
+ style: { transform: `scale(${controls.zoom})` },
1205
+ children: videoSlot
1206
+ }
1207
+ ),
1208
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1209
+ PlayerCenterOverlay,
1210
+ {
1211
+ kind: overlay,
1212
+ playIconPreset: config.theme.playIconPreset,
1213
+ onPlay: controls.togglePlay,
1214
+ onEnableAudio: controls.enableAudio
1215
+ }
1216
+ ),
1217
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1218
+ PlayerSkipCue,
1219
+ {
1220
+ direction: skipCue?.direction ?? null,
1221
+ cueId: skipCue?.id ?? 0,
1222
+ seconds: config.player.skipSeconds
1223
+ },
1224
+ skipCue?.id ?? "idle"
1225
+ ),
1226
+ controls.showControls ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1227
+ PlayerControlBar,
1228
+ {
1229
+ config,
1230
+ isPlaying: controls.isPlaying,
1231
+ currentTime: controls.currentTime,
1232
+ duration: controls.duration,
1233
+ bufferedEnd: controls.bufferedEnd,
1234
+ volume: controls.volume,
1235
+ muted: controls.muted,
1236
+ playbackRate: controls.playbackRate,
1237
+ isFullscreen: controls.isFullscreen,
1238
+ zoom: controls.zoom,
1239
+ qualities: controls.qualities,
1240
+ qualitySelection: controls.qualitySelection,
1241
+ activeLevel: controls.activeLevel,
1242
+ textTracks: controls.textTracks,
1243
+ selectedTextTrack: controls.selectedTextTrack,
1244
+ audioTracks: controls.audioTracks,
1245
+ selectedAudioTrack: controls.selectedAudioTrack,
1246
+ onTogglePlay: controls.togglePlay,
1247
+ onSeek: controls.seekTo,
1248
+ onSkip: skip,
1249
+ isLive: controls.isLive,
1250
+ atLiveEdge: controls.atLiveEdge,
1251
+ onGoToLive: controls.goToLive,
1252
+ onVolumeChange: controls.setVolume,
1253
+ onToggleMute: controls.toggleMute,
1254
+ onPlaybackRateChange: controls.setPlaybackRate,
1255
+ onQualityChange: controls.setQuality,
1256
+ onTextTrackChange: controls.setTextTrack,
1257
+ onAudioTrackChange: controls.setAudioTrack,
1258
+ onToggleFullscreen: () => void controls.toggleFullscreen(),
1259
+ onZoomIn: controls.zoomIn,
1260
+ onZoomOut: controls.zoomOut,
1261
+ seekBarRef
1262
+ }
1263
+ ) : null
1264
+ ]
1265
+ }
1266
+ );
1267
+ }
1268
+
1269
+ // src/NsgVideoPlayerWithControls.tsx
1270
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1271
+ function NsgVideoPlayerWithControls(props) {
1272
+ const containerRef = (0, import_react7.useRef)(null);
1273
+ const onWatchTimeRef = (0, import_react7.useRef)(props.onWatchTime);
1274
+ onWatchTimeRef.current = props.onWatchTime;
1275
+ const resolvedConfig = (0, import_react7.useMemo)(
1276
+ () => (0, import_video_nsgplayer_core2.mergePlayerConfig)({
1277
+ ...props.config,
1278
+ controls: {
1279
+ enabled: true,
1280
+ ...props.config?.controls
1281
+ }
1282
+ }),
1283
+ [props.config]
1284
+ );
1285
+ const { videoRef, player, state, error } = (0, import_video_nsgplayer_react.useVideoPlayer)({
1286
+ videoId: props.videoId,
1287
+ auth: props.auth,
1288
+ playback: props.playback,
1289
+ sourceUrl: props.sourceUrl,
1290
+ config: resolvedConfig,
1291
+ onReady: props.onReady,
1292
+ onError: props.onError
1293
+ });
1294
+ (0, import_react7.useEffect)(() => {
1295
+ if (!player) return;
1296
+ const report = () => {
1297
+ const t = player.getCurrentTime();
1298
+ if (typeof t === "number" && t > 0) onWatchTimeRef.current?.(t);
1299
+ };
1300
+ const offs = [
1301
+ player.on("pause", report),
1302
+ player.on("ended", report),
1303
+ player.on("play", () => props.onPlay?.()),
1304
+ player.on("pause", () => props.onPause?.())
1305
+ ];
1306
+ const onBeforeUnload = () => report();
1307
+ window.addEventListener("beforeunload", onBeforeUnload);
1308
+ return () => {
1309
+ for (const off of offs) off();
1310
+ window.removeEventListener("beforeunload", onBeforeUnload);
1311
+ };
1312
+ }, [player, props]);
1313
+ const cssVars = (0, import_video_nsgplayer_core2.themeToCssVars)(resolvedConfig.theme);
1314
+ const showBootstrap = state === "loading" || state === "idle";
1315
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
1316
+ "div",
1317
+ {
1318
+ ref: containerRef,
1319
+ "data-player-theme": true,
1320
+ "data-player-state": state,
1321
+ className: props.className,
1322
+ style: {
1323
+ position: "relative",
1324
+ width: "100%",
1325
+ height: "100%",
1326
+ minHeight: 0,
1327
+ background: "#000",
1328
+ ...cssVars,
1329
+ ...props.style
1330
+ },
1331
+ children: [
1332
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1333
+ PlayerChrome,
1334
+ {
1335
+ player,
1336
+ config: resolvedConfig,
1337
+ containerRef,
1338
+ videoSlot: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1339
+ "video",
1340
+ {
1341
+ ref: videoRef,
1342
+ playsInline: true,
1343
+ preload: "metadata",
1344
+ style: { width: "100%", height: "100%", display: "block" }
1345
+ }
1346
+ )
1347
+ }
1348
+ ),
1349
+ resolvedConfig.watermark.enabled && resolvedConfig.watermark.text ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "nsg-player-watermark", "aria-hidden": true, children: resolvedConfig.watermark.text }) : null,
1350
+ error ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "nsg-player-error", role: "alert", children: error.message || "Unable to play this video." }) : null,
1351
+ showBootstrap && !error ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "nsg-player-status", children: "Loading video\u2026" }) : null
1352
+ ]
1353
+ }
1354
+ );
1355
+ }
1356
+ // Annotate the CommonJS export names for ESM import in node:
1357
+ 0 && (module.exports = {
1358
+ AudioTrackSelector,
1359
+ LiveBadgeButton,
1360
+ NsgVideoPlayerWithControls,
1361
+ PlayIconPreset,
1362
+ PlaybackSpeedSelector,
1363
+ PlayerCenterOverlay,
1364
+ PlayerChrome,
1365
+ PlayerControlBar,
1366
+ PlayerMenu,
1367
+ PlayerMenuItem,
1368
+ PlayerSkipCue,
1369
+ QualitySelector,
1370
+ SeekBar,
1371
+ TextTrackSelector,
1372
+ ZOOM_STEPS,
1373
+ formatPlaybackTime,
1374
+ nextZoom,
1375
+ resolvePlayerOverlay,
1376
+ resolveVisiblePlaybackRates,
1377
+ snapPlaybackRate,
1378
+ usePlayerControls
1379
+ });
1380
+ //# sourceMappingURL=index.cjs.map