@codenkay/video-nsgplayer-ui 3.0.0 → 3.0.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Preserve "use client" in React/UI builds, forward analytics, intermittent watermark, Angular Ivy packaging, and packaging metadata.
8
+ - Updated dependencies
9
+ - @codenkay/video-nsgplayer-core@3.0.4
10
+ - @codenkay/video-nsgplayer-react@3.0.4
11
+
3
12
  ## 3.0.0
4
13
 
5
14
  ### Patch Changes
package/README.md CHANGED
@@ -32,3 +32,5 @@ import "@codenkay/video-nsgplayer-ui/styles.css";
32
32
  | `@codenkay/video-nsgplayer-ui` | Full control bar (this package) |
33
33
 
34
34
  Zoom is UI-only (CSS `scale`). Import `styles.css` once in the host app.
35
+
36
+ Published bundles include a `"use client";` banner for Next.js App Router. Pass `analytics`, use `ref` for `getDiagnostics()` / runtime API, and set `watermark.durationMs` / `intervalMaxMs` for intermittent anti-leak watermarks.
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  "use strict";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -31,21 +32,30 @@ __export(index_exports, {
31
32
  PlayerMenu: () => PlayerMenu,
32
33
  PlayerMenuItem: () => PlayerMenuItem,
33
34
  PlayerSkipCue: () => PlayerSkipCue,
35
+ QUALITY_PREFERENCE_STORAGE_KEY: () => QUALITY_PREFERENCE_STORAGE_KEY,
34
36
  QualitySelector: () => QualitySelector,
35
37
  SeekBar: () => SeekBar,
36
38
  TextTrackSelector: () => TextTrackSelector,
37
39
  ZOOM_STEPS: () => ZOOM_STEPS,
38
40
  formatPlaybackTime: () => formatPlaybackTime,
41
+ matchQualityPreference: () => matchQualityPreference,
39
42
  nextZoom: () => nextZoom,
43
+ preferenceFromSelection: () => preferenceFromSelection,
44
+ randomFirstShowDelay: () => randomFirstShowDelay,
45
+ randomWatermarkDelay: () => randomWatermarkDelay,
46
+ randomWatermarkPosition: () => randomWatermarkPosition,
47
+ readQualityPreference: () => readQualityPreference,
40
48
  resolvePlayerOverlay: () => resolvePlayerOverlay,
41
49
  resolveVisiblePlaybackRates: () => resolveVisiblePlaybackRates,
42
50
  snapPlaybackRate: () => snapPlaybackRate,
43
- usePlayerControls: () => usePlayerControls
51
+ usePlaybackWatermark: () => usePlaybackWatermark,
52
+ usePlayerControls: () => usePlayerControls,
53
+ writeQualityPreference: () => writeQualityPreference
44
54
  });
45
55
  module.exports = __toCommonJS(index_exports);
46
56
 
47
57
  // src/NsgVideoPlayerWithControls.tsx
48
- var import_react7 = require("react");
58
+ var import_react8 = require("react");
49
59
  var import_video_nsgplayer_core2 = require("@codenkay/video-nsgplayer-core");
50
60
  var import_video_nsgplayer_react = require("@codenkay/video-nsgplayer-react");
51
61
 
@@ -116,6 +126,62 @@ function nextZoom(current, direction) {
116
126
  return ZOOM_STEPS[next] ?? 1;
117
127
  }
118
128
 
129
+ // src/utils/qualityPreference.ts
130
+ var QUALITY_PREFERENCE_STORAGE_KEY = "nsg-player:quality-preference";
131
+ function readQualityPreference() {
132
+ if (typeof window === "undefined" || !window.localStorage) {
133
+ return "auto";
134
+ }
135
+ try {
136
+ const raw = window.localStorage.getItem(QUALITY_PREFERENCE_STORAGE_KEY);
137
+ if (!raw) {
138
+ return "auto";
139
+ }
140
+ if (raw === "auto") {
141
+ return "auto";
142
+ }
143
+ const parsed = JSON.parse(raw);
144
+ if (parsed && typeof parsed === "object" && "height" in parsed && typeof parsed.height === "number" && Number.isFinite(parsed.height) && parsed.height > 0) {
145
+ return { height: parsed.height };
146
+ }
147
+ } catch {
148
+ }
149
+ return "auto";
150
+ }
151
+ function writeQualityPreference(preference) {
152
+ if (typeof window === "undefined" || !window.localStorage) {
153
+ return;
154
+ }
155
+ try {
156
+ if (preference === "auto") {
157
+ window.localStorage.setItem(QUALITY_PREFERENCE_STORAGE_KEY, "auto");
158
+ return;
159
+ }
160
+ window.localStorage.setItem(
161
+ QUALITY_PREFERENCE_STORAGE_KEY,
162
+ JSON.stringify({ height: preference.height })
163
+ );
164
+ } catch {
165
+ }
166
+ }
167
+ function matchQualityPreference(preference, levels) {
168
+ if (preference === "auto" || levels.length === 0) {
169
+ return "auto";
170
+ }
171
+ const match = levels.find((level) => level.height === preference.height);
172
+ return match ? match.index : "auto";
173
+ }
174
+ function preferenceFromSelection(selection, levels) {
175
+ if (selection === "auto") {
176
+ return "auto";
177
+ }
178
+ const level = levels.find((item) => item.index === selection);
179
+ if (!level || level.height <= 0) {
180
+ return "auto";
181
+ }
182
+ return { height: level.height };
183
+ }
184
+
119
185
  // src/hooks/usePlayerControls.ts
120
186
  function usePlayerControls(options) {
121
187
  const { player, config, containerRef } = options;
@@ -149,10 +215,21 @@ function usePlayerControls(options) {
149
215
  player.setFullscreenElement(containerRef.current);
150
216
  }
151
217
  const syncTracks = () => {
152
- setQualities(player.getAvailableQualities());
153
- setQualitySelection(player.getQuality());
154
- const q = player.getQuality();
155
- setActiveLevel(typeof q === "number" ? q : -1);
218
+ const levels = player.getAvailableQualities();
219
+ setQualities(levels);
220
+ let selection = player.getQuality();
221
+ if (config.controls.persistQualityPreference && levels.length > 0) {
222
+ const preferred = matchQualityPreference(
223
+ readQualityPreference(),
224
+ levels
225
+ );
226
+ if (preferred !== selection) {
227
+ player.setQuality(preferred);
228
+ selection = preferred;
229
+ }
230
+ }
231
+ setQualitySelection(selection);
232
+ setActiveLevel(typeof selection === "number" ? selection : -1);
156
233
  setTextTracks(player.getTextTracks());
157
234
  setSelectedTextTrack(player.getSelectedTextTrack());
158
235
  setAudioTracks(player.getAudioTracks());
@@ -226,7 +303,7 @@ function usePlayerControls(options) {
226
303
  for (const off of offs) off();
227
304
  document.removeEventListener("fullscreenchange", onFs);
228
305
  };
229
- }, [player, containerRef]);
306
+ }, [player, containerRef, config.controls.persistQualityPreference]);
230
307
  const togglePlay = (0, import_react.useCallback)(() => {
231
308
  if (!player) return;
232
309
  if (player.getState() === "playing") {
@@ -275,8 +352,16 @@ function usePlayerControls(options) {
275
352
  const setQuality = (0, import_react.useCallback)(
276
353
  (selection) => {
277
354
  player?.setQuality(selection);
355
+ if (config.controls.persistQualityPreference) {
356
+ writeQualityPreference(
357
+ preferenceFromSelection(
358
+ selection,
359
+ player?.getAvailableQualities() ?? []
360
+ )
361
+ );
362
+ }
278
363
  },
279
- [player]
364
+ [player, config.controls.persistQualityPreference]
280
365
  );
281
366
  const setTextTrack = (0, import_react.useCallback)(
282
367
  (selection) => {
@@ -682,13 +767,15 @@ function SeekBar({
682
767
  duration,
683
768
  bufferedEnd,
684
769
  onSeek,
685
- seekInputRef
770
+ seekInputRef,
771
+ getSeekPreview
686
772
  }) {
687
773
  const trackRef = (0, import_react5.useRef)(null);
688
774
  const [hover, setHover] = (0, import_react5.useState)(INITIAL_HOVER);
689
775
  const max = duration > 0 ? duration : 0;
690
776
  const bufferedPct = max > 0 ? Math.min(100, bufferedEnd / max * 100) : 0;
691
777
  const playedPct = max > 0 ? Math.min(100, currentTime / max * 100) : 0;
778
+ const previewUrl = hover.visible && getSeekPreview ? getSeekPreview(hover.time) : null;
692
779
  const updateHover = (0, import_react5.useCallback)(
693
780
  (clientX) => {
694
781
  const track = trackRef.current;
@@ -750,13 +837,24 @@ function SeekBar({
750
837
  style: { width: `${playedPct}%` }
751
838
  }
752
839
  ),
753
- hover.visible && max > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
840
+ hover.visible && max > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
754
841
  "div",
755
842
  {
756
843
  className: "nsg-player-seek__tooltip",
757
844
  style: { left: `${hover.percent}%` },
758
845
  role: "tooltip",
759
- children: formatPlaybackTime(hover.time)
846
+ children: [
847
+ previewUrl ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
848
+ "img",
849
+ {
850
+ className: "nsg-player-seek__preview",
851
+ src: previewUrl,
852
+ alt: "",
853
+ draggable: false
854
+ }
855
+ ) : null,
856
+ formatPlaybackTime(hover.time)
857
+ ]
760
858
  }
761
859
  ) : null,
762
860
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
@@ -846,7 +944,8 @@ function PlayerControlBar(props) {
846
944
  onToggleFullscreen,
847
945
  onZoomIn,
848
946
  onZoomOut,
849
- seekBarRef
947
+ seekBarRef,
948
+ getSeekPreview
850
949
  } = props;
851
950
  const controls = config.controls;
852
951
  const showZoom = config.player.zoomEnabled && controls.showZoom;
@@ -865,7 +964,8 @@ function PlayerControlBar(props) {
865
964
  duration,
866
965
  bufferedEnd,
867
966
  onSeek,
868
- seekInputRef: seekBarRef
967
+ seekInputRef: seekBarRef,
968
+ getSeekPreview
869
969
  }
870
970
  ),
871
971
  /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "nsg-player-control-row", children: [
@@ -1074,7 +1174,8 @@ function PlayerChrome({
1074
1174
  config,
1075
1175
  containerRef,
1076
1176
  videoSlot,
1077
- className
1177
+ className,
1178
+ getSeekPreview
1078
1179
  }) {
1079
1180
  const rootRef = (0, import_react6.useRef)(null);
1080
1181
  const seekBarRef = (0, import_react6.useRef)(null);
@@ -1258,7 +1359,8 @@ function PlayerChrome({
1258
1359
  onToggleFullscreen: () => void controls.toggleFullscreen(),
1259
1360
  onZoomIn: controls.zoomIn,
1260
1361
  onZoomOut: controls.zoomOut,
1261
- seekBarRef
1362
+ seekBarRef,
1363
+ getSeekPreview
1262
1364
  }
1263
1365
  ) : null
1264
1366
  ]
@@ -1266,13 +1368,119 @@ function PlayerChrome({
1266
1368
  );
1267
1369
  }
1268
1370
 
1371
+ // src/hooks/usePlaybackWatermark.ts
1372
+ var import_react7 = require("react");
1373
+
1374
+ // src/utils/watermarkSchedule.ts
1375
+ var WATERMARK_TOP_MIN_PCT = 8;
1376
+ var WATERMARK_TOP_MAX_PCT = 70;
1377
+ var WATERMARK_LEFT_MIN_PCT = 5;
1378
+ var WATERMARK_LEFT_MAX_PCT = 70;
1379
+ var WATERMARK_FIRST_SHOW_MIN_MS = 3e3;
1380
+ var WATERMARK_FIRST_SHOW_MAX_MS = 8e3;
1381
+ function randomInRange(min, max, random = Math.random) {
1382
+ if (max <= min) {
1383
+ return min;
1384
+ }
1385
+ return min + random() * (max - min);
1386
+ }
1387
+ function randomWatermarkPosition(random = Math.random) {
1388
+ const topPct = WATERMARK_TOP_MIN_PCT + random() * (WATERMARK_TOP_MAX_PCT - WATERMARK_TOP_MIN_PCT);
1389
+ const leftPct = WATERMARK_LEFT_MIN_PCT + random() * (WATERMARK_LEFT_MAX_PCT - WATERMARK_LEFT_MIN_PCT);
1390
+ return { topPct, leftPct };
1391
+ }
1392
+ function randomWatermarkDelay(maxMs, random = Math.random) {
1393
+ if (!Number.isFinite(maxMs) || maxMs <= 0) {
1394
+ return 0;
1395
+ }
1396
+ return Math.min(maxMs, Math.floor(random() * (maxMs + 1)));
1397
+ }
1398
+ function randomFirstShowDelay(random = Math.random) {
1399
+ return Math.floor(
1400
+ randomInRange(
1401
+ WATERMARK_FIRST_SHOW_MIN_MS,
1402
+ WATERMARK_FIRST_SHOW_MAX_MS,
1403
+ random
1404
+ )
1405
+ );
1406
+ }
1407
+
1408
+ // src/hooks/usePlaybackWatermark.ts
1409
+ var HIDDEN = {
1410
+ visible: false,
1411
+ topPct: 0,
1412
+ leftPct: 0
1413
+ };
1414
+ function usePlaybackWatermark({
1415
+ enabled,
1416
+ label,
1417
+ active,
1418
+ durationMs,
1419
+ intervalMaxMs,
1420
+ reducedMotion = false
1421
+ }) {
1422
+ const [state, setState] = (0, import_react7.useState)(HIDDEN);
1423
+ const showTimerRef = (0, import_react7.useRef)(null);
1424
+ const hideTimerRef = (0, import_react7.useRef)(null);
1425
+ const generationRef = (0, import_react7.useRef)(0);
1426
+ (0, import_react7.useEffect)(() => {
1427
+ const clearTimers = () => {
1428
+ if (showTimerRef.current !== null) {
1429
+ window.clearTimeout(showTimerRef.current);
1430
+ showTimerRef.current = null;
1431
+ }
1432
+ if (hideTimerRef.current !== null) {
1433
+ window.clearTimeout(hideTimerRef.current);
1434
+ hideTimerRef.current = null;
1435
+ }
1436
+ };
1437
+ generationRef.current += 1;
1438
+ const generation = generationRef.current;
1439
+ clearTimers();
1440
+ setState(HIDDEN);
1441
+ if (!enabled || !label || !active) {
1442
+ return () => {
1443
+ clearTimers();
1444
+ };
1445
+ }
1446
+ if (reducedMotion) {
1447
+ setState({ visible: true, topPct: 12, leftPct: 8 });
1448
+ return () => {
1449
+ clearTimers();
1450
+ };
1451
+ }
1452
+ const scheduleShow = (delayMs) => {
1453
+ showTimerRef.current = window.setTimeout(() => {
1454
+ if (generation !== generationRef.current) {
1455
+ return;
1456
+ }
1457
+ const position = randomWatermarkPosition();
1458
+ setState({ visible: true, ...position });
1459
+ hideTimerRef.current = window.setTimeout(() => {
1460
+ if (generation !== generationRef.current) {
1461
+ return;
1462
+ }
1463
+ setState(HIDDEN);
1464
+ scheduleShow(randomWatermarkDelay(intervalMaxMs));
1465
+ }, durationMs);
1466
+ }, delayMs);
1467
+ };
1468
+ scheduleShow(randomFirstShowDelay());
1469
+ return () => {
1470
+ generationRef.current += 1;
1471
+ clearTimers();
1472
+ };
1473
+ }, [enabled, label, active, durationMs, intervalMaxMs, reducedMotion]);
1474
+ return state;
1475
+ }
1476
+
1269
1477
  // src/NsgVideoPlayerWithControls.tsx
1270
1478
  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);
1479
+ var NsgVideoPlayerWithControls = (0, import_react8.forwardRef)(function NsgVideoPlayerWithControls2(props, ref) {
1480
+ const containerRef = (0, import_react8.useRef)(null);
1481
+ const onWatchTimeRef = (0, import_react8.useRef)(props.onWatchTime);
1274
1482
  onWatchTimeRef.current = props.onWatchTime;
1275
- const resolvedConfig = (0, import_react7.useMemo)(
1483
+ const resolvedConfig = (0, import_react8.useMemo)(
1276
1484
  () => (0, import_video_nsgplayer_core2.mergePlayerConfig)({
1277
1485
  ...props.config,
1278
1486
  controls: {
@@ -1288,10 +1496,15 @@ function NsgVideoPlayerWithControls(props) {
1288
1496
  playback: props.playback,
1289
1497
  sourceUrl: props.sourceUrl,
1290
1498
  config: resolvedConfig,
1499
+ analytics: props.analytics,
1291
1500
  onReady: props.onReady,
1292
- onError: props.onError
1501
+ onError: props.onError,
1502
+ onPlay: props.onPlay,
1503
+ onPause: props.onPause,
1504
+ onAuthError: props.onAuthError
1293
1505
  });
1294
- (0, import_react7.useEffect)(() => {
1506
+ (0, import_react8.useImperativeHandle)(ref, () => player, [player]);
1507
+ (0, import_react8.useEffect)(() => {
1295
1508
  if (!player) return;
1296
1509
  const report = () => {
1297
1510
  const t = player.getCurrentTime();
@@ -1299,9 +1512,7 @@ function NsgVideoPlayerWithControls(props) {
1299
1512
  };
1300
1513
  const offs = [
1301
1514
  player.on("pause", report),
1302
- player.on("ended", report),
1303
- player.on("play", () => props.onPlay?.()),
1304
- player.on("pause", () => props.onPause?.())
1515
+ player.on("ended", report)
1305
1516
  ];
1306
1517
  const onBeforeUnload = () => report();
1307
1518
  window.addEventListener("beforeunload", onBeforeUnload);
@@ -1309,7 +1520,16 @@ function NsgVideoPlayerWithControls(props) {
1309
1520
  for (const off of offs) off();
1310
1521
  window.removeEventListener("beforeunload", onBeforeUnload);
1311
1522
  };
1312
- }, [player, props]);
1523
+ }, [player]);
1524
+ const watermarkActive = state === "playing" || state === "paused" || state === "buffering";
1525
+ const watermark = usePlaybackWatermark({
1526
+ enabled: resolvedConfig.watermark.enabled,
1527
+ label: resolvedConfig.watermark.text?.trim() || null,
1528
+ active: watermarkActive,
1529
+ durationMs: resolvedConfig.watermark.durationMs,
1530
+ intervalMaxMs: resolvedConfig.watermark.intervalMaxMs,
1531
+ reducedMotion: resolvedConfig.accessibility.reducedMotion
1532
+ });
1313
1533
  const cssVars = (0, import_video_nsgplayer_core2.themeToCssVars)(resolvedConfig.theme);
1314
1534
  const showBootstrap = state === "loading" || state === "idle";
1315
1535
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
@@ -1335,6 +1555,7 @@ function NsgVideoPlayerWithControls(props) {
1335
1555
  player,
1336
1556
  config: resolvedConfig,
1337
1557
  containerRef,
1558
+ getSeekPreview: props.getSeekPreview,
1338
1559
  videoSlot: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1339
1560
  "video",
1340
1561
  {
@@ -1346,13 +1567,24 @@ function NsgVideoPlayerWithControls(props) {
1346
1567
  )
1347
1568
  }
1348
1569
  ),
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,
1570
+ watermark.visible ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1571
+ "div",
1572
+ {
1573
+ className: "nsg-player-watermark",
1574
+ "aria-hidden": true,
1575
+ style: {
1576
+ top: `${watermark.topPct}%`,
1577
+ left: `${watermark.leftPct}%`
1578
+ },
1579
+ children: resolvedConfig.watermark.text
1580
+ }
1581
+ ) : null,
1350
1582
  error ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "nsg-player-error", role: "alert", children: error.message || "Unable to play this video." }) : null,
1351
1583
  showBootstrap && !error ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "nsg-player-status", children: "Loading video\u2026" }) : null
1352
1584
  ]
1353
1585
  }
1354
1586
  );
1355
- }
1587
+ });
1356
1588
  // Annotate the CommonJS export names for ESM import in node:
1357
1589
  0 && (module.exports = {
1358
1590
  AudioTrackSelector,
@@ -1366,15 +1598,24 @@ function NsgVideoPlayerWithControls(props) {
1366
1598
  PlayerMenu,
1367
1599
  PlayerMenuItem,
1368
1600
  PlayerSkipCue,
1601
+ QUALITY_PREFERENCE_STORAGE_KEY,
1369
1602
  QualitySelector,
1370
1603
  SeekBar,
1371
1604
  TextTrackSelector,
1372
1605
  ZOOM_STEPS,
1373
1606
  formatPlaybackTime,
1607
+ matchQualityPreference,
1374
1608
  nextZoom,
1609
+ preferenceFromSelection,
1610
+ randomFirstShowDelay,
1611
+ randomWatermarkDelay,
1612
+ randomWatermarkPosition,
1613
+ readQualityPreference,
1375
1614
  resolvePlayerOverlay,
1376
1615
  resolveVisiblePlaybackRates,
1377
1616
  snapPlaybackRate,
1378
- usePlayerControls
1617
+ usePlaybackWatermark,
1618
+ usePlayerControls,
1619
+ writeQualityPreference
1379
1620
  });
1380
1621
  //# sourceMappingURL=index.cjs.map