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