napp-wallet-post-feed-test 1.0.47

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.
Files changed (56) hide show
  1. package/README.md +157 -0
  2. package/dist/0ae4e6254fc19607c79e.woff2 +0 -0
  3. package/dist/1f38a564cd9eae27ebc3.woff2 +0 -0
  4. package/dist/432.napp.bundle.js +1 -0
  5. package/dist/661bd6b7245d5205d3e1.woff2 +0 -0
  6. package/dist/Post.browser.js +24 -0
  7. package/dist/Post.js +606 -0
  8. package/dist/components/CodeSplitting.js +88 -0
  9. package/dist/components/Deeplink/Deeplink.js +813 -0
  10. package/dist/components/EditPostModal.js +916 -0
  11. package/dist/components/ErrorBoundary.js +74 -0
  12. package/dist/components/ExpandedTest/ExpandableText.js +38 -0
  13. package/dist/components/FilterDropdown.js +71 -0
  14. package/dist/components/ImagePreloader.js +1194 -0
  15. package/dist/components/Loader.js +42 -0
  16. package/dist/components/LoadingSkeletons.js +978 -0
  17. package/dist/components/MediaRenderer.js +759 -0
  18. package/dist/components/MemoryManager.js +302 -0
  19. package/dist/components/PostCard.js +446 -0
  20. package/dist/components/PostViews.js +247 -0
  21. package/dist/components/Postfeed.js +251 -0
  22. package/dist/components/Svgloader.js +231 -0
  23. package/dist/components/UploadPostModal.js +1352 -0
  24. package/dist/components/VideoPlayer.js +1304 -0
  25. package/dist/components/ViewPostModal/MediaPreloadManager.js +379 -0
  26. package/dist/components/ViewPostModal/README.md +164 -0
  27. package/dist/components/ViewPostModal/ShareModal.js +96 -0
  28. package/dist/components/ViewPostModal/VirtualPost.js +248 -0
  29. package/dist/components/ViewPostModal/useBodyScrollLock.js +42 -0
  30. package/dist/components/ViewPostModal/useDeviceDetection.js +38 -0
  31. package/dist/components/ViewPostModal/useFullscreenManager.js +43 -0
  32. package/dist/components/ViewPostModal/useNavigationManager.js +185 -0
  33. package/dist/components/ViewPostModal/usePostDataManager.js +143 -0
  34. package/dist/components/ViewPostModal/usePreloadManager.js +97 -0
  35. package/dist/components/ViewPostModal/useShareManager.js +76 -0
  36. package/dist/components/ViewPostModal.js +552 -0
  37. package/dist/components/VirtualPostFeed.js +475 -0
  38. package/dist/components/hooks/useFeedVisibility.js +72 -0
  39. package/dist/components/hooks/useIntersectionObserver.js +54 -0
  40. package/dist/components/hooks/usePerformanceMonitor.js +159 -0
  41. package/dist/components/hooks/usePostApi.js +381 -0
  42. package/dist/components/hooks/usePostState.js +116 -0
  43. package/dist/components/useImagePreloading.js +231 -0
  44. package/dist/e7461d69dbbff1310a5c.woff2 +0 -0
  45. package/dist/helper/Helper.js +504 -0
  46. package/dist/index.browser.js +5 -0
  47. package/dist/index.js +3 -0
  48. package/dist/napp.bundle.js +2 -0
  49. package/dist/napp.bundle.js.LICENSE.txt +733 -0
  50. package/dist/style/post.css +5751 -0
  51. package/dist/style/post.css.map +1 -0
  52. package/dist/style/post.purged.css +3236 -0
  53. package/dist/style/post.scss +5910 -0
  54. package/dist/utils/bootstrap.js +4 -0
  55. package/dist/utils/ffmpegLoader.js +40 -0
  56. package/package.json +70 -0
@@ -0,0 +1,1304 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
4
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
5
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
7
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
8
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
9
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
10
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
12
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
13
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
14
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
15
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
16
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
17
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
+ import React from "react";
21
+ import useEffect from "react";
22
+ import useRef from "react";
23
+ import useState from "react";
24
+ import useCallback from "react";
25
+ import useMemo from "react";
26
+ import PropTypes from "prop-types";
27
+ import Hls from "hls.js";
28
+ import '@fortawesome/fontawesome-free/css/all.min.css';
29
+
30
+ // ============================================================================
31
+ // VIDEO PRELOADING UTILITIES
32
+ // ============================================================================
33
+
34
+ // Utility function to check if video is ready to play
35
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
36
+ var isVideoReady = function isVideoReady(video) {
37
+ if (!video) return false;
38
+ return video.readyState >= 2 && video.networkState !== 3 && video.duration > 0;
39
+ };
40
+
41
+ // Check if URL is a video (exclude audio files)
42
+ var isVideoUrl = function isVideoUrl(url) {
43
+ if (!url) return false;
44
+ var audioExtensions = /\.(mp3|wav|ogg|aac|m4a|flac)$/i;
45
+ if (audioExtensions.test(url)) return false;
46
+ var videoExtensions = /\.(mp4|webm|ogg|mov|avi|mkv|m3u8)$/i;
47
+ return videoExtensions.test(url) || url.includes('.m3u8') || url.includes('hls');
48
+ };
49
+
50
+ // Video preloader class for faster loading
51
+ var VideoPreloader = /*#__PURE__*/function () {
52
+ function VideoPreloader() {
53
+ _classCallCheck(this, VideoPreloader);
54
+ this.preloadedVideos = new Map();
55
+ this.preloadQueue = [];
56
+ this.isProcessing = false;
57
+ this.maxConcurrent = 2; // Limit concurrent preloads
58
+ this.activePreloads = 0;
59
+ }
60
+
61
+ // Preload video metadata and first few seconds
62
+ return _createClass(VideoPreloader, [{
63
+ key: "preloadVideo",
64
+ value: function () {
65
+ var _preloadVideo = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url) {
66
+ var _this = this;
67
+ var options,
68
+ _options$preloadMetad,
69
+ preloadMetadata,
70
+ _options$preloadFirst,
71
+ preloadFirstChunk,
72
+ _options$quality,
73
+ quality,
74
+ _options$timeout,
75
+ timeout,
76
+ preloadData,
77
+ _args = arguments,
78
+ _t;
79
+ return _regenerator().w(function (_context) {
80
+ while (1) switch (_context.n) {
81
+ case 0:
82
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
83
+ _options$preloadMetad = options.preloadMetadata, preloadMetadata = _options$preloadMetad === void 0 ? true : _options$preloadMetad, _options$preloadFirst = options.preloadFirstChunk, preloadFirstChunk = _options$preloadFirst === void 0 ? true : _options$preloadFirst, _options$quality = options.quality, quality = _options$quality === void 0 ? 'auto' : _options$quality, _options$timeout = options.timeout, timeout = _options$timeout === void 0 ? 10000 : _options$timeout;
84
+ if (!this.preloadedVideos.has(url)) {
85
+ _context.n = 1;
86
+ break;
87
+ }
88
+ return _context.a(2, this.preloadedVideos.get(url));
89
+ case 1:
90
+ if (!(this.activePreloads >= this.maxConcurrent)) {
91
+ _context.n = 2;
92
+ break;
93
+ }
94
+ return _context.a(2, new Promise(function (resolve, reject) {
95
+ _this.preloadQueue.push({
96
+ url: url,
97
+ options: options,
98
+ resolve: resolve,
99
+ reject: reject
100
+ });
101
+ }));
102
+ case 2:
103
+ this.activePreloads++;
104
+ _context.p = 3;
105
+ _context.n = 4;
106
+ return this._executePreload(url, options, timeout);
107
+ case 4:
108
+ preloadData = _context.v;
109
+ this.preloadedVideos.set(url, preloadData);
110
+ this.activePreloads--;
111
+ this._processQueue();
112
+ return _context.a(2, preloadData);
113
+ case 5:
114
+ _context.p = 5;
115
+ _t = _context.v;
116
+ this.activePreloads--;
117
+ this._processQueue();
118
+ throw _t;
119
+ case 6:
120
+ return _context.a(2);
121
+ }
122
+ }, _callee, this, [[3, 5]]);
123
+ }));
124
+ function preloadVideo(_x) {
125
+ return _preloadVideo.apply(this, arguments);
126
+ }
127
+ return preloadVideo;
128
+ }()
129
+ }, {
130
+ key: "_executePreload",
131
+ value: function () {
132
+ var _executePreload2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(url, options, timeout) {
133
+ var _this2 = this;
134
+ return _regenerator().w(function (_context2) {
135
+ while (1) switch (_context2.n) {
136
+ case 0:
137
+ return _context2.a(2, new Promise(function (resolve, reject) {
138
+ var timeoutId = setTimeout(function () {
139
+ reject(new Error('Preload timeout'));
140
+ }, timeout);
141
+ if (url.includes('.m3u8') || url.includes('application/vnd.apple.mpegurl')) {
142
+ // HLS stream preloading
143
+ _this2._preloadHLS(url, options, resolve, reject, timeoutId);
144
+ } else {
145
+ // Regular video preloading
146
+ _this2._preloadRegularVideo(url, options, resolve, reject, timeoutId);
147
+ }
148
+ }));
149
+ }
150
+ }, _callee2);
151
+ }));
152
+ function _executePreload(_x2, _x3, _x4) {
153
+ return _executePreload2.apply(this, arguments);
154
+ }
155
+ return _executePreload;
156
+ }()
157
+ }, {
158
+ key: "_preloadHLS",
159
+ value: function _preloadHLS(url, options, resolve, reject, timeoutId) {
160
+ if (!Hls.isSupported()) {
161
+ clearTimeout(timeoutId);
162
+ reject(new Error('HLS not supported'));
163
+ return;
164
+ }
165
+ var hls = new Hls({
166
+ enableWorker: false,
167
+ startLevel: 0,
168
+ maxBufferLength: 10,
169
+ maxMaxBufferLength: 20,
170
+ maxBufferSize: 10 * 1000 * 1000,
171
+ fragLoadingTimeOut: 5000,
172
+ manifestLoadingTimeOut: 5000,
173
+ levelLoadingTimeOut: 5000
174
+ });
175
+ hls.on(Hls.Events.MANIFEST_PARSED, function () {
176
+ clearTimeout(timeoutId);
177
+ resolve({
178
+ type: 'hls',
179
+ url: url,
180
+ preloaded: true,
181
+ hlsInstance: hls,
182
+ levels: hls.levels,
183
+ currentLevel: 0
184
+ });
185
+ });
186
+ hls.on(Hls.Events.ERROR, function () {
187
+ clearTimeout(timeoutId);
188
+ hls.destroy();
189
+ reject(new Error('HLS preload failed'));
190
+ });
191
+ hls.loadSource(url);
192
+ }
193
+ }, {
194
+ key: "_preloadRegularVideo",
195
+ value: function _preloadRegularVideo(url, options, resolve, reject, timeoutId) {
196
+ var video = document.createElement('video');
197
+ video.muted = true;
198
+ video.preload = 'metadata';
199
+ video.style.display = 'none';
200
+ var _handleLoadedMetadata = function handleLoadedMetadata() {
201
+ clearTimeout(timeoutId);
202
+ var data = {
203
+ type: 'video',
204
+ url: url,
205
+ preloaded: true,
206
+ duration: video.duration,
207
+ videoWidth: video.videoWidth,
208
+ videoHeight: video.videoHeight,
209
+ readyState: video.readyState
210
+ };
211
+
212
+ // Clean up
213
+ video.removeEventListener('loadedmetadata', _handleLoadedMetadata);
214
+ video.removeEventListener('error', _handleError);
215
+ document.body.removeChild(video);
216
+ resolve(data);
217
+ };
218
+ var _handleError = function handleError() {
219
+ clearTimeout(timeoutId);
220
+ video.removeEventListener('loadedmetadata', _handleLoadedMetadata);
221
+ video.removeEventListener('error', _handleError);
222
+ document.body.removeChild(video);
223
+ reject(new Error('Video preload failed'));
224
+ };
225
+ video.addEventListener('loadedmetadata', _handleLoadedMetadata);
226
+ video.addEventListener('error', _handleError);
227
+
228
+ // Add to DOM temporarily for preloading
229
+ document.body.appendChild(video);
230
+ video.src = url;
231
+ }
232
+ }, {
233
+ key: "_processQueue",
234
+ value: function _processQueue() {
235
+ if (this.preloadQueue.length === 0 || this.activePreloads >= this.maxConcurrent) {
236
+ return;
237
+ }
238
+ var _this$preloadQueue$sh = this.preloadQueue.shift(),
239
+ url = _this$preloadQueue$sh.url,
240
+ options = _this$preloadQueue$sh.options,
241
+ resolve = _this$preloadQueue$sh.resolve,
242
+ reject = _this$preloadQueue$sh.reject;
243
+ this.preloadVideo(url, options).then(resolve).catch(reject);
244
+ }
245
+
246
+ // Get preloaded video data
247
+ }, {
248
+ key: "getPreloadedVideo",
249
+ value: function getPreloadedVideo(url) {
250
+ return this.preloadedVideos.get(url);
251
+ }
252
+
253
+ // Clear preloaded videos to free memory
254
+ }, {
255
+ key: "clearPreloadedVideos",
256
+ value: function clearPreloadedVideos() {
257
+ this.preloadedVideos.forEach(function (data) {
258
+ if (data.hlsInstance) {
259
+ data.hlsInstance.destroy();
260
+ }
261
+ });
262
+ this.preloadedVideos.clear();
263
+ }
264
+ }]);
265
+ }(); // Global video preloader instance
266
+ var videoPreloader = new VideoPreloader();
267
+
268
+ // ============================================================================
269
+ // MAIN VIDEO PLAYER COMPONENT
270
+ // ============================================================================
271
+
272
+ var VideoPlayer = function VideoPlayer(_ref) {
273
+ var src = _ref.src,
274
+ id = _ref.id,
275
+ _ref$autoPlay = _ref.autoPlay,
276
+ autoPlay = _ref$autoPlay === void 0 ? true : _ref$autoPlay,
277
+ _ref$muted = _ref.muted,
278
+ muted = _ref$muted === void 0 ? true : _ref$muted,
279
+ _ref$controls = _ref.controls,
280
+ controls = _ref$controls === void 0 ? true : _ref$controls,
281
+ _ref$loop = _ref.loop,
282
+ loop = _ref$loop === void 0 ? true : _ref$loop,
283
+ onLoadedData = _ref.onLoadedData,
284
+ _ref$lowQualityFirst = _ref.lowQualityFirst,
285
+ lowQualityFirst = _ref$lowQualityFirst === void 0 ? true : _ref$lowQualityFirst,
286
+ _ref$className = _ref.className,
287
+ className = _ref$className === void 0 ? "" : _ref$className,
288
+ _ref$style = _ref.style,
289
+ style = _ref$style === void 0 ? {} : _ref$style,
290
+ _ref$preloadStrategy = _ref.preloadStrategy,
291
+ preloadStrategy = _ref$preloadStrategy === void 0 ? 'balanced' : _ref$preloadStrategy;
292
+ var videoRef = useRef(null);
293
+ var hlsRef = useRef(null);
294
+ var controlsRef = useRef(null);
295
+ var progressRef = useRef(null);
296
+ var bufferRef = useRef(null);
297
+ var playPromiseRef = useRef(null);
298
+ var preloadDataRef = useRef(null);
299
+
300
+ // State management
301
+ var _useState = useState(false),
302
+ _useState2 = _slicedToArray(_useState, 2),
303
+ isPlaying = _useState2[0],
304
+ setIsPlaying = _useState2[1];
305
+ var _useState3 = useState(0),
306
+ _useState4 = _slicedToArray(_useState3, 2),
307
+ duration = _useState4[0],
308
+ setDuration = _useState4[1];
309
+ var _useState5 = useState(0),
310
+ _useState6 = _slicedToArray(_useState5, 2),
311
+ currentTime = _useState6[0],
312
+ setCurrentTime = _useState6[1];
313
+ var _useState7 = useState(muted),
314
+ _useState8 = _slicedToArray(_useState7, 2),
315
+ isMuted = _useState8[0],
316
+ setIsMuted = _useState8[1];
317
+ var _useState9 = useState(false),
318
+ _useState0 = _slicedToArray(_useState9, 2),
319
+ isFullscreen = _useState0[0],
320
+ setIsFullscreen = _useState0[1];
321
+ var _useState1 = useState(controls),
322
+ _useState10 = _slicedToArray(_useState1, 2),
323
+ showControls = _useState10[0],
324
+ setShowControls = _useState10[1];
325
+ var _useState11 = useState(null),
326
+ _useState12 = _slicedToArray(_useState11, 2),
327
+ error = _useState12[0],
328
+ setError = _useState12[1];
329
+ var _useState13 = useState(false),
330
+ _useState14 = _slicedToArray(_useState13, 2),
331
+ isPreloading = _useState14[0],
332
+ setIsPreloading = _useState14[1];
333
+ var _useState15 = useState(0),
334
+ _useState16 = _slicedToArray(_useState15, 2),
335
+ preloadProgress = _useState16[0],
336
+ setPreloadProgress = _useState16[1];
337
+ var _useState17 = useState(false),
338
+ _useState18 = _slicedToArray(_useState17, 2),
339
+ hasLoaded = _useState18[0],
340
+ setHasLoaded = _useState18[1]; // Track if video has been fully loaded
341
+
342
+ var controlsTimeoutRef = useRef(null);
343
+ var _useState19 = useState(false),
344
+ _useState20 = _slicedToArray(_useState19, 2),
345
+ isMobileDevice = _useState20[0],
346
+ setIsMobileDevice = _useState20[1];
347
+ var _useState21 = useState(false),
348
+ _useState22 = _slicedToArray(_useState21, 2),
349
+ isIOSDevice = _useState22[0],
350
+ setIsIOSDevice = _useState22[1];
351
+
352
+ // Device detection
353
+ useEffect(function () {
354
+ var checkIfMobile = function checkIfMobile() {
355
+ return typeof window !== "undefined" && (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth <= 768);
356
+ };
357
+ var checkIfIOS = function checkIfIOS() {
358
+ return typeof window !== "undefined" && /iPad|iPhone|iPod/.test(navigator.userAgent);
359
+ };
360
+ setIsMobileDevice(checkIfMobile());
361
+ setIsIOSDevice(checkIfIOS());
362
+ if (typeof window !== "undefined") {
363
+ window.isIOSDevice = checkIfIOS();
364
+ }
365
+ }, []);
366
+
367
+ // Ensure video element is properly initialized with correct attributes
368
+ useEffect(function () {
369
+ if (videoRef.current) {
370
+ var video = videoRef.current;
371
+
372
+ // Set attributes directly on the DOM element
373
+ if (autoPlay) {
374
+ video.setAttribute('autoPlay', '');
375
+ video.autoPlay = true;
376
+ }
377
+ if (loop) {
378
+ video.setAttribute('loop', '');
379
+ video.loop = true;
380
+ }
381
+ if (muted) {
382
+ video.setAttribute('muted', '');
383
+ video.muted = true;
384
+ }
385
+ }
386
+ }, [autoPlay, loop, muted]);
387
+
388
+ // Additional check to ensure video element is properly initialized
389
+ useEffect(function () {
390
+ var checkVideoElement = function checkVideoElement() {
391
+ if (videoRef.current) {
392
+ var video = videoRef.current;
393
+ }
394
+ };
395
+
396
+ // Check immediately
397
+ checkVideoElement();
398
+
399
+ // Check after a short delay to ensure DOM is ready
400
+ var timeoutId = setTimeout(checkVideoElement, 100);
401
+ return function () {
402
+ return clearTimeout(timeoutId);
403
+ };
404
+ }, []);
405
+
406
+ // Preload strategy configuration
407
+ var preloadConfig = useMemo(function () {
408
+ var baseConfig = {
409
+ preloadMetadata: true,
410
+ preloadFirstChunk: true,
411
+ quality: 'auto',
412
+ timeout: 10000
413
+ };
414
+ switch (preloadStrategy) {
415
+ case 'aggressive':
416
+ return _objectSpread(_objectSpread({}, baseConfig), {}, {
417
+ preloadMetadata: true,
418
+ preloadFirstChunk: true,
419
+ quality: 'auto',
420
+ timeout: 15000,
421
+ maxConcurrent: 3
422
+ });
423
+ case 'balanced':
424
+ return _objectSpread(_objectSpread({}, baseConfig), {}, {
425
+ preloadMetadata: true,
426
+ preloadFirstChunk: false,
427
+ quality: 'auto',
428
+ timeout: 10000,
429
+ maxConcurrent: 2
430
+ });
431
+ case 'conservative':
432
+ return _objectSpread(_objectSpread({}, baseConfig), {}, {
433
+ preloadMetadata: false,
434
+ preloadFirstChunk: false,
435
+ quality: 'low',
436
+ timeout: 5000,
437
+ maxConcurrent: 1
438
+ });
439
+ default:
440
+ return baseConfig;
441
+ }
442
+ }, [preloadStrategy]);
443
+
444
+ // HLS configuration optimized for fast loading
445
+ var getHlsConfig = useCallback(function () {
446
+ var baseConfig = {
447
+ enableWorker: !isMobileDevice,
448
+ enableSoftwareAES: true,
449
+ lowLatencyMode: false,
450
+ stretchShortVideoTrack: true,
451
+ startLevel: lowQualityFirst ? 0 : -1,
452
+ debug: false,
453
+ // Fast loading optimizations
454
+ maxBufferLength: 10,
455
+ maxMaxBufferLength: 20,
456
+ maxBufferSize: 20 * 1000 * 1000,
457
+ maxBufferHole: 0.5,
458
+ maxFragLookUpTolerance: 0.25,
459
+ // Faster fragment loading
460
+ fragLoadingTimeOut: 3000,
461
+ manifestLoadingTimeOut: 5000,
462
+ levelLoadingTimeOut: 5000,
463
+ fragLoadingMaxRetry: 2,
464
+ levelLoadingMaxRetry: 2,
465
+ manifestLoadingMaxRetry: 2,
466
+ // Adaptive bitrate for faster start
467
+ abrEwmaDefaultEstimate: 500000,
468
+ abrBandWidthFactor: 0.8,
469
+ abrBandWidthUpFactor: 0.6,
470
+ // Live sync for faster playback
471
+ liveSyncDurationCount: 2,
472
+ liveMaxLatencyDurationCount: 4,
473
+ maxLiveSyncPlaybackRate: 1.1
474
+ };
475
+ if (isMobileDevice) {
476
+ return _objectSpread(_objectSpread({}, baseConfig), {}, {
477
+ maxBufferLength: 5,
478
+ maxMaxBufferLength: 10,
479
+ maxBufferSize: 10 * 1000 * 1000,
480
+ fragLoadingTimeOut: 5000,
481
+ manifestLoadingTimeOut: 8000,
482
+ levelLoadingTimeOut: 8000
483
+ });
484
+ }
485
+ return baseConfig;
486
+ }, [isMobileDevice, lowQualityFirst]);
487
+
488
+ // Enhanced video preloading
489
+ var preloadVideo = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
490
+ var video, preloadPromise, progressInterval, preloadData, _t2;
491
+ return _regenerator().w(function (_context3) {
492
+ while (1) switch (_context3.n) {
493
+ case 0:
494
+ if (!(!src || isPreloading || hasLoaded)) {
495
+ _context3.n = 1;
496
+ break;
497
+ }
498
+ return _context3.a(2);
499
+ case 1:
500
+ if (isVideoUrl(src)) {
501
+ _context3.n = 2;
502
+ break;
503
+ }
504
+ return _context3.a(2);
505
+ case 2:
506
+ // Check if video is already loaded or ready
507
+ video = videoRef.current;
508
+ if (!(video && isVideoReady(video))) {
509
+ _context3.n = 3;
510
+ break;
511
+ }
512
+ setHasLoaded(true);
513
+ return _context3.a(2);
514
+ case 3:
515
+ setIsPreloading(true);
516
+ setPreloadProgress(0);
517
+ _context3.p = 4;
518
+ // Start preloading immediately
519
+ preloadPromise = videoPreloader.preloadVideo(src, preloadConfig); // Update progress
520
+ progressInterval = setInterval(function () {
521
+ setPreloadProgress(function (prev) {
522
+ return Math.min(prev + 10, 90);
523
+ });
524
+ }, 100);
525
+ _context3.n = 5;
526
+ return preloadPromise;
527
+ case 5:
528
+ preloadData = _context3.v;
529
+ preloadDataRef.current = preloadData;
530
+ clearInterval(progressInterval);
531
+ setPreloadProgress(100);
532
+
533
+ // Small delay to show completion
534
+ setTimeout(function () {
535
+ setIsPreloading(false);
536
+ setPreloadProgress(0);
537
+ setHasLoaded(true); // Mark as loaded
538
+ }, 200);
539
+ _context3.n = 7;
540
+ break;
541
+ case 6:
542
+ _context3.p = 6;
543
+ _t2 = _context3.v;
544
+ setIsPreloading(false);
545
+ setPreloadProgress(0);
546
+ // Continue without preload data
547
+ case 7:
548
+ return _context3.a(2);
549
+ }
550
+ }, _callee3, null, [[4, 6]]);
551
+ })), [src, preloadConfig, isPreloading, hasLoaded]);
552
+
553
+ // Start preloading when component mounts
554
+ useEffect(function () {
555
+ if (src && preloadStrategy !== 'conservative' && !hasLoaded) {
556
+ // Only preload if not already loaded
557
+ var video = videoRef.current;
558
+ if (!video || !isVideoReady(video)) {
559
+ preloadVideo();
560
+ } else {
561
+ setHasLoaded(true);
562
+ }
563
+ }
564
+ }, [src, preloadStrategy, preloadVideo, hasLoaded]);
565
+
566
+ // Safe play function with preload optimization
567
+ var safePlay = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
568
+ var video, _t3, _t4;
569
+ return _regenerator().w(function (_context4) {
570
+ while (1) switch (_context4.n) {
571
+ case 0:
572
+ video = videoRef.current;
573
+ if (video) {
574
+ _context4.n = 1;
575
+ break;
576
+ }
577
+ return _context4.a(2);
578
+ case 1:
579
+ _context4.p = 1;
580
+ if (!playPromiseRef.current) {
581
+ _context4.n = 2;
582
+ break;
583
+ }
584
+ _context4.n = 2;
585
+ return playPromiseRef.current.catch(function () {});
586
+ case 2:
587
+ // iOS-specific optimizations
588
+ if (isIOSDevice) {
589
+ video.setAttribute('playsinline', 'true');
590
+ video.setAttribute('webkit-playsinline', 'true');
591
+ video.setAttribute('x5-playsinline', 'true');
592
+ if (!video.muted) {
593
+ video.muted = true;
594
+ setIsMuted(true);
595
+ }
596
+ }
597
+
598
+ // Use preload data if available for faster start
599
+ if (!(preloadDataRef.current && preloadDataRef.current.type === 'hls')) {
600
+ _context4.n = 4;
601
+ break;
602
+ }
603
+ // HLS is already preloaded, start immediately
604
+ playPromiseRef.current = video.play();
605
+ _context4.n = 3;
606
+ return playPromiseRef.current;
607
+ case 3:
608
+ _context4.n = 5;
609
+ break;
610
+ case 4:
611
+ // Regular play
612
+ playPromiseRef.current = video.play();
613
+ _context4.n = 5;
614
+ return playPromiseRef.current;
615
+ case 5:
616
+ playPromiseRef.current = null;
617
+ _context4.n = 10;
618
+ break;
619
+ case 6:
620
+ _context4.p = 6;
621
+ _t3 = _context4.v;
622
+ playPromiseRef.current = null;
623
+ if (!(_t3.name === "NotAllowedError")) {
624
+ _context4.n = 10;
625
+ break;
626
+ }
627
+ _context4.p = 7;
628
+ video.muted = true;
629
+ setIsMuted(true);
630
+ playPromiseRef.current = video.play();
631
+ _context4.n = 8;
632
+ return playPromiseRef.current;
633
+ case 8:
634
+ playPromiseRef.current = null;
635
+ _context4.n = 10;
636
+ break;
637
+ case 9:
638
+ _context4.p = 9;
639
+ _t4 = _context4.v;
640
+ playPromiseRef.current = null;
641
+ case 10:
642
+ return _context4.a(2);
643
+ }
644
+ }, _callee4, null, [[7, 9], [1, 6]]);
645
+ })), [isIOSDevice]);
646
+
647
+ // Safe pause function
648
+ var safePause = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
649
+ var video, _t5;
650
+ return _regenerator().w(function (_context5) {
651
+ while (1) switch (_context5.n) {
652
+ case 0:
653
+ video = videoRef.current;
654
+ if (video) {
655
+ _context5.n = 1;
656
+ break;
657
+ }
658
+ return _context5.a(2);
659
+ case 1:
660
+ _context5.p = 1;
661
+ if (!playPromiseRef.current) {
662
+ _context5.n = 3;
663
+ break;
664
+ }
665
+ _context5.n = 2;
666
+ return playPromiseRef.current.catch(function () {});
667
+ case 2:
668
+ playPromiseRef.current = null;
669
+ case 3:
670
+ if (!video.paused) {
671
+ video.pause();
672
+ }
673
+ _context5.n = 5;
674
+ break;
675
+ case 4:
676
+ _context5.p = 4;
677
+ _t5 = _context5.v;
678
+ case 5:
679
+ return _context5.a(2);
680
+ }
681
+ }, _callee5, null, [[1, 4]]);
682
+ })), []);
683
+
684
+ // Player control functions
685
+ var togglePlay = function togglePlay() {
686
+ if (isPlaying) {
687
+ safePause();
688
+ } else {
689
+ safePlay();
690
+ }
691
+ };
692
+ var toggleMute = function toggleMute() {
693
+ var video = videoRef.current;
694
+ if (video) {
695
+ video.muted = !video.muted;
696
+ setIsMuted(video.muted);
697
+ }
698
+ };
699
+ var toggleFullscreen = /*#__PURE__*/function () {
700
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
701
+ var video, _t6;
702
+ return _regenerator().w(function (_context6) {
703
+ while (1) switch (_context6.n) {
704
+ case 0:
705
+ _context6.p = 0;
706
+ video = videoRef.current;
707
+ if (video) {
708
+ _context6.n = 1;
709
+ break;
710
+ }
711
+ return _context6.a(2);
712
+ case 1:
713
+ if (isFullscreen) {
714
+ _context6.n = 6;
715
+ break;
716
+ }
717
+ if (!(isMobileDevice && video.webkitEnterFullscreen)) {
718
+ _context6.n = 2;
719
+ break;
720
+ }
721
+ video.webkitEnterFullscreen();
722
+ _context6.n = 5;
723
+ break;
724
+ case 2:
725
+ if (!video.requestFullscreen) {
726
+ _context6.n = 4;
727
+ break;
728
+ }
729
+ _context6.n = 3;
730
+ return video.requestFullscreen();
731
+ case 3:
732
+ _context6.n = 5;
733
+ break;
734
+ case 4:
735
+ if (!video.webkitRequestFullscreen) {
736
+ _context6.n = 5;
737
+ break;
738
+ }
739
+ _context6.n = 5;
740
+ return video.webkitRequestFullscreen();
741
+ case 5:
742
+ _context6.n = 9;
743
+ break;
744
+ case 6:
745
+ if (!document.exitFullscreen) {
746
+ _context6.n = 8;
747
+ break;
748
+ }
749
+ _context6.n = 7;
750
+ return document.exitFullscreen();
751
+ case 7:
752
+ _context6.n = 9;
753
+ break;
754
+ case 8:
755
+ if (!document.webkitExitFullscreen) {
756
+ _context6.n = 9;
757
+ break;
758
+ }
759
+ _context6.n = 9;
760
+ return document.webkitExitFullscreen();
761
+ case 9:
762
+ _context6.n = 11;
763
+ break;
764
+ case 10:
765
+ _context6.p = 10;
766
+ _t6 = _context6.v;
767
+ case 11:
768
+ return _context6.a(2);
769
+ }
770
+ }, _callee6, null, [[0, 10]]);
771
+ }));
772
+ return function toggleFullscreen() {
773
+ return _ref5.apply(this, arguments);
774
+ };
775
+ }();
776
+ var handleProgressClick = function handleProgressClick(e) {
777
+ if (!videoRef.current || !progressRef.current) return;
778
+ var rect = progressRef.current.getBoundingClientRect();
779
+ var pos = (e.clientX - rect.left) / rect.width;
780
+ videoRef.current.currentTime = pos * videoRef.current.duration;
781
+ };
782
+
783
+ // Enhanced HLS initialization with preload data
784
+ var initHlsJs = useCallback(function () {
785
+ try {
786
+ var hls = new Hls(getHlsConfig());
787
+ hlsRef.current = hls;
788
+ hls.on(Hls.Events.MEDIA_ATTACHED, function () {
789
+ hls.loadSource(src);
790
+ hls.on(Hls.Events.MANIFEST_PARSED, function () {
791
+ if (autoPlay) {
792
+ setTimeout(function () {
793
+ safePlay();
794
+ }, isMobileDevice ? 200 : 100);
795
+ }
796
+ });
797
+
798
+ // Handle loop functionality for HLS streams
799
+ if (loop) {
800
+ hls.on(Hls.Events.ENDED, function () {
801
+ hls.stopLoad();
802
+ hls.startLoad();
803
+ if (autoPlay) {
804
+ setTimeout(function () {
805
+ safePlay();
806
+ }, 100);
807
+ }
808
+ });
809
+ }
810
+ });
811
+ hls.on(Hls.Events.ERROR, function (event, data) {
812
+ if (data.fatal) {
813
+ switch (data.type) {
814
+ case Hls.ErrorTypes.NETWORK_ERROR:
815
+ setTimeout(function () {
816
+ if (hlsRef.current) {
817
+ hlsRef.current.startLoad();
818
+ }
819
+ }, 1000);
820
+ break;
821
+ case Hls.ErrorTypes.MEDIA_ERROR:
822
+ setTimeout(function () {
823
+ if (hlsRef.current) {
824
+ hlsRef.current.recoverMediaError();
825
+ }
826
+ }, 1000);
827
+ break;
828
+ default:
829
+ setTimeout(function () {
830
+ if (hlsRef.current) {
831
+ hlsRef.current.destroy();
832
+ hlsRef.current = null;
833
+ }
834
+ if (!isMobileDevice) {
835
+ initPlayer();
836
+ } else {
837
+ setError('Video playback error. Please try refreshing.');
838
+ }
839
+ }, 2000);
840
+ break;
841
+ }
842
+ }
843
+ });
844
+ hls.attachMedia(videoRef.current);
845
+ } catch (error) {
846
+ setError('Video player initialization failed');
847
+ }
848
+ }, [src, autoPlay, loop, isMobileDevice, safePlay, getHlsConfig]);
849
+
850
+ // Enhanced player initialization with preload optimization
851
+ var initPlayer = useCallback(function () {
852
+ if (!src || !videoRef.current) return;
853
+ var video = videoRef.current;
854
+
855
+ // Check if video is already loaded with the same source
856
+ if (video.src === src && video.readyState >= 2) {
857
+ // Video is already loaded and ready, just handle autoPlay
858
+ if (autoPlay && video.paused) {
859
+ var playDelay = isIOSDevice ? 100 : isMobileDevice ? 150 : 50;
860
+ setTimeout(function () {
861
+ safePlay();
862
+ }, playDelay);
863
+ }
864
+ // Don't return early - continue to ensure proper initialization
865
+ }
866
+ var isHlsStream = src.includes('.m3u8') || src.includes('application/vnd.apple.mpegurl');
867
+ var isPotentialHls = !src.match(/\.(mp4|webm|ogg|mov|avi|mkv)(\?|$)/i);
868
+ if (isHlsStream || isPotentialHls) {
869
+ video.src = '';
870
+ video.load();
871
+ var nativeHlsSupport = video.canPlayType('application/vnd.apple.mpegurl');
872
+ if (nativeHlsSupport || isMobileDevice) {
873
+ try {
874
+ video.src = src;
875
+ if (isIOSDevice) {
876
+ video.setAttribute('playsinline', 'true');
877
+ video.setAttribute('webkit-playsinline', 'true');
878
+ video.setAttribute('x5-playsinline', 'true');
879
+ video.muted = true;
880
+ video.preload = 'metadata';
881
+ }
882
+ var _handleCanPlay = function handleCanPlay() {
883
+ if (autoPlay) {
884
+ var _playDelay = isIOSDevice ? 100 : isMobileDevice ? 150 : 50;
885
+ setTimeout(function () {
886
+ safePlay();
887
+ }, _playDelay);
888
+ }
889
+ video.removeEventListener('canplay', _handleCanPlay);
890
+ };
891
+ video.addEventListener('canplay', _handleCanPlay);
892
+ setTimeout(function () {
893
+ video.removeEventListener('canplay', _handleCanPlay);
894
+ if (video.readyState === 0 && Hls.isSupported()) {
895
+ initHlsJs();
896
+ }
897
+ }, 3000);
898
+ return;
899
+ } catch (error) {
900
+ // Native HLS failed
901
+ }
902
+ }
903
+ if (Hls.isSupported()) {
904
+ initHlsJs();
905
+ } else {
906
+ setError("Video playback is not supported in your browser");
907
+ }
908
+ } else {
909
+ // Regular video file
910
+ try {
911
+ video.src = '';
912
+ video.load();
913
+ if (isIOSDevice) {
914
+ video.setAttribute('playsinline', 'true');
915
+ video.setAttribute('webkit-playsinline', 'true');
916
+ video.setAttribute('x5-playsinline', 'true');
917
+ video.muted = true;
918
+ video.preload = 'metadata';
919
+ } else {
920
+ video.preload = "auto";
921
+ }
922
+ video.src = src;
923
+ if (autoPlay) {
924
+ var _playDelay2 = isIOSDevice ? 100 : isMobileDevice ? 150 : 50;
925
+ setTimeout(function () {
926
+ safePlay();
927
+ }, _playDelay2);
928
+ }
929
+ } catch (error) {
930
+ setError('Failed to load video');
931
+ }
932
+ }
933
+ }, [src, isMobileDevice, isIOSDevice, autoPlay, loop, safePlay, initHlsJs]);
934
+
935
+ // Event handlers
936
+ useEffect(function () {
937
+ var video = videoRef.current;
938
+ if (!video) return;
939
+ var handleLoadedData = function handleLoadedData() {
940
+ setDuration(video.duration);
941
+ if (onLoadedData) onLoadedData();
942
+ };
943
+ var handleTimeUpdate = function handleTimeUpdate() {
944
+ setCurrentTime(video.currentTime);
945
+ if (bufferRef.current && video.buffered.length > 0) {
946
+ var bufferedEnd = video.buffered.end(video.buffered.length - 1);
947
+ var bufferPercentage = bufferedEnd / video.duration * 100;
948
+ bufferRef.current.style.width = "".concat(bufferPercentage, "%");
949
+ }
950
+ };
951
+ var handlePlay = function handlePlay() {
952
+ return setIsPlaying(true);
953
+ };
954
+ var handlePause = function handlePause() {
955
+ return setIsPlaying(false);
956
+ };
957
+ var handleVolumeChange = function handleVolumeChange() {
958
+ return setIsMuted(video.muted);
959
+ };
960
+ var handleEnded = function handleEnded() {
961
+ if (loop) {
962
+ // For regular video files, just seek to beginning
963
+ video.currentTime = 0;
964
+ if (autoPlay) {
965
+ setTimeout(function () {
966
+ safePlay();
967
+ }, 100);
968
+ }
969
+ }
970
+ };
971
+ var handleFullscreenChange = function handleFullscreenChange() {
972
+ try {
973
+ var isInFullscreen = !!(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || video.webkitDisplayingFullscreen);
974
+ setIsFullscreen(isInFullscreen);
975
+ } catch (error) {
976
+ setIsFullscreen(false);
977
+ }
978
+ };
979
+ var handleMouseMove = function handleMouseMove() {
980
+ setShowControls(true);
981
+ clearTimeout(controlsTimeoutRef.current);
982
+ controlsTimeoutRef.current = setTimeout(function () {
983
+ if (isPlaying) {
984
+ setShowControls(false);
985
+ }
986
+ }, 3000);
987
+ };
988
+ var handleTouchStart = function handleTouchStart() {
989
+ setShowControls(true);
990
+ clearTimeout(controlsTimeoutRef.current);
991
+ controlsTimeoutRef.current = setTimeout(function () {
992
+ if (isPlaying) {
993
+ setShowControls(false);
994
+ }
995
+ }, 3000);
996
+ };
997
+ video.addEventListener("loadedmetadata", handleLoadedData);
998
+ video.addEventListener("timeupdate", handleTimeUpdate);
999
+ video.addEventListener("play", handlePlay);
1000
+ video.addEventListener("pause", handlePause);
1001
+ video.addEventListener("volumechange", handleVolumeChange);
1002
+ video.addEventListener("ended", handleEnded);
1003
+ video.addEventListener("mousemove", handleMouseMove);
1004
+ video.addEventListener("touchstart", handleTouchStart);
1005
+ document.addEventListener("fullscreenchange", handleFullscreenChange);
1006
+ document.addEventListener("webkitfullscreenchange", handleFullscreenChange);
1007
+ document.addEventListener("mozfullscreenchange", handleFullscreenChange);
1008
+ document.addEventListener("MSFullscreenChange", handleFullscreenChange);
1009
+ if (video.webkitSupportsFullscreen) {
1010
+ video.addEventListener("webkitbeginfullscreen", function () {
1011
+ return setIsFullscreen(true);
1012
+ });
1013
+ video.addEventListener("webkitendfullscreen", function () {
1014
+ return setIsFullscreen(false);
1015
+ });
1016
+ }
1017
+ return function () {
1018
+ video.removeEventListener("loadedmetadata", handleLoadedData);
1019
+ video.removeEventListener("timeupdate", handleTimeUpdate);
1020
+ video.removeEventListener("play", handlePlay);
1021
+ video.removeEventListener("pause", handlePause);
1022
+ video.removeEventListener("volumechange", handleVolumeChange);
1023
+ video.removeEventListener("ended", handleEnded);
1024
+ video.removeEventListener("mousemove", handleMouseMove);
1025
+ video.removeEventListener("touchstart", handleTouchStart);
1026
+ document.removeEventListener("fullscreenchange", handleFullscreenChange);
1027
+ document.removeEventListener("webkitfullscreenchange", handleFullscreenChange);
1028
+ document.removeEventListener("mozfullscreenchange", handleFullscreenChange);
1029
+ document.removeEventListener("MSFullscreenChange", handleFullscreenChange);
1030
+ if (video.webkitSupportsFullscreen) {
1031
+ video.removeEventListener("webkitbeginfullscreen", function () {
1032
+ return setIsFullscreen(true);
1033
+ });
1034
+ video.removeEventListener("webkitendfullscreen", function () {
1035
+ return setIsFullscreen(false);
1036
+ });
1037
+ }
1038
+ clearTimeout(controlsTimeoutRef.current);
1039
+ };
1040
+ }, [onLoadedData, isPlaying]);
1041
+
1042
+ // Initialize/destroy player
1043
+ useEffect(function () {
1044
+ // Only initialize if we have a source and the video element exists
1045
+ if (src && videoRef.current) {
1046
+ // Ensure video element has correct attributes for autoPlay to work
1047
+ var video = videoRef.current;
1048
+ if (autoPlay) {
1049
+ // For autoPlay to work, video must be muted in modern browsers
1050
+ video.muted = true;
1051
+ setIsMuted(true);
1052
+ }
1053
+
1054
+ // Check if we need to initialize or if video is already ready
1055
+ if (video.src !== src || video.readyState < 2) {
1056
+ initPlayer();
1057
+ } else if (autoPlay && video.paused) {
1058
+ // Video is already loaded, just handle autoPlay
1059
+
1060
+ var playDelay = isIOSDevice ? 100 : isMobileDevice ? 150 : 50;
1061
+ setTimeout(function () {
1062
+ safePlay();
1063
+ }, playDelay);
1064
+ }
1065
+ }
1066
+ return function () {
1067
+ if (playPromiseRef.current) {
1068
+ playPromiseRef.current.catch(function () {});
1069
+ playPromiseRef.current = null;
1070
+ }
1071
+ try {
1072
+ if (hlsRef.current) {
1073
+ hlsRef.current.destroy();
1074
+ hlsRef.current = null;
1075
+ }
1076
+ if (videoRef.current && isMobileDevice) {
1077
+ var _video = videoRef.current;
1078
+ _video.pause();
1079
+ _video.removeAttribute('src');
1080
+ _video.load();
1081
+ }
1082
+ } catch (error) {
1083
+ // Cleanup error
1084
+ }
1085
+ };
1086
+ }, [src, autoPlay, loop, muted, isMobileDevice, isIOSDevice, initPlayer, safePlay]);
1087
+
1088
+ // Format time utility
1089
+ var formatTime = function formatTime(time) {
1090
+ var minutes = Math.floor(time / 60);
1091
+ var seconds = Math.floor(time % 60);
1092
+ return "".concat(minutes, ":").concat(seconds < 10 ? "0" : "").concat(seconds);
1093
+ };
1094
+ return /*#__PURE__*/_jsxs("div", {
1095
+ className: "video-player-container ".concat(className),
1096
+ style: _objectSpread({
1097
+ position: "relative",
1098
+ width: "100%",
1099
+ height: "100%"
1100
+ }, style),
1101
+ children: [isPreloading && /*#__PURE__*/_jsxs("div", {
1102
+ style: {
1103
+ position: "absolute",
1104
+ top: 0,
1105
+ left: 0,
1106
+ right: 0,
1107
+ bottom: 0,
1108
+ backgroundColor: "rgba(0,0,0,0.8)",
1109
+ display: "flex",
1110
+ flexDirection: "column",
1111
+ alignItems: "center",
1112
+ justifyContent: "center",
1113
+ color: "white",
1114
+ zIndex: 30
1115
+ },
1116
+ children: [/*#__PURE__*/_jsx("div", {
1117
+ style: {
1118
+ marginBottom: "15px"
1119
+ },
1120
+ children: /*#__PURE__*/_jsx("i", {
1121
+ className: "fas fa-spinner fa-spin",
1122
+ style: {
1123
+ fontSize: "24px",
1124
+ color: "#4285f4"
1125
+ }
1126
+ })
1127
+ }), /*#__PURE__*/_jsx("div", {
1128
+ style: {
1129
+ marginBottom: "10px"
1130
+ },
1131
+ children: "Preloading video..."
1132
+ }), /*#__PURE__*/_jsx("div", {
1133
+ style: {
1134
+ width: "200px",
1135
+ height: "4px",
1136
+ backgroundColor: "rgba(255,255,255,0.3)",
1137
+ borderRadius: "2px"
1138
+ },
1139
+ children: /*#__PURE__*/_jsx("div", {
1140
+ style: {
1141
+ width: "".concat(preloadProgress, "%"),
1142
+ height: "100%",
1143
+ backgroundColor: "#00a8ff",
1144
+ borderRadius: "2px",
1145
+ transition: "width 0.3s ease"
1146
+ }
1147
+ })
1148
+ }), /*#__PURE__*/_jsxs("div", {
1149
+ style: {
1150
+ fontSize: "12px",
1151
+ marginTop: "5px"
1152
+ },
1153
+ children: [preloadProgress, "%"]
1154
+ })]
1155
+ }), /*#__PURE__*/_jsx("video", {
1156
+ ref: videoRef,
1157
+ playsInline: true,
1158
+ "webkit-playsinline": "true",
1159
+ preload: "auto",
1160
+ autoPlay: autoPlay,
1161
+ muted: isMuted,
1162
+ loop: loop,
1163
+ style: {
1164
+ width: "100%",
1165
+ height: "100%",
1166
+ display: "block",
1167
+ objectFit: "cover"
1168
+ },
1169
+ onLoadStart: function onLoadStart() {},
1170
+ onCanPlay: function onCanPlay() {},
1171
+ onPlay: function onPlay() {},
1172
+ onPause: function onPause() {},
1173
+ onEnded: function onEnded() {}
1174
+ }), controls && /*#__PURE__*/_jsx("div", {
1175
+ ref: controlsRef,
1176
+ className: "video-controls-overlay",
1177
+ style: {
1178
+ display: showControls ? "block" : "none"
1179
+ },
1180
+ onMouseMove: function onMouseMove() {
1181
+ return setShowControls(true);
1182
+ },
1183
+ onTouchStart: function onTouchStart() {
1184
+ return setShowControls(true);
1185
+ },
1186
+ children: /*#__PURE__*/_jsxs("div", {
1187
+ className: "video-controls-bar",
1188
+ children: [/*#__PURE__*/_jsx("div", {
1189
+ className: "video-progress-container",
1190
+ children: /*#__PURE__*/_jsxs("div", {
1191
+ className: "video-progress-track",
1192
+ ref: progressRef,
1193
+ onClick: handleProgressClick,
1194
+ children: [/*#__PURE__*/_jsx("div", {
1195
+ className: "video-progress-buffer",
1196
+ ref: bufferRef
1197
+ }), /*#__PURE__*/_jsx("div", {
1198
+ className: "video-progress-played",
1199
+ style: {
1200
+ width: "".concat(currentTime / duration * 100, "%")
1201
+ }
1202
+ }), /*#__PURE__*/_jsx("div", {
1203
+ className: "video-progress-thumb",
1204
+ style: {
1205
+ left: "".concat(currentTime / duration * 100, "%")
1206
+ }
1207
+ })]
1208
+ })
1209
+ }), /*#__PURE__*/_jsxs("div", {
1210
+ className: "video-controls-row",
1211
+ children: [/*#__PURE__*/_jsxs("div", {
1212
+ className: "video-controls-left",
1213
+ children: [/*#__PURE__*/_jsx("button", {
1214
+ className: "video-control-btn video-play-btn",
1215
+ onClick: togglePlay,
1216
+ "aria-label": isPlaying ? "Pause" : "Play",
1217
+ children: /*#__PURE__*/_jsx("i", {
1218
+ className: "fas ".concat(isPlaying ? 'fa-pause' : 'fa-play')
1219
+ })
1220
+ }), /*#__PURE__*/_jsx("button", {
1221
+ className: "video-control-btn video-mute-btn",
1222
+ onClick: toggleMute,
1223
+ "aria-label": isMuted ? "Unmute" : "Mute",
1224
+ children: /*#__PURE__*/_jsx("i", {
1225
+ className: "fas ".concat(isMuted ? 'fa-volume-mute' : 'fa-volume-up')
1226
+ })
1227
+ }), /*#__PURE__*/_jsxs("div", {
1228
+ className: "video-time-display",
1229
+ children: [/*#__PURE__*/_jsx("span", {
1230
+ className: "video-current-time",
1231
+ children: formatTime(currentTime)
1232
+ }), /*#__PURE__*/_jsx("span", {
1233
+ className: "video-time-separator",
1234
+ children: "/"
1235
+ }), /*#__PURE__*/_jsx("span", {
1236
+ className: "video-duration",
1237
+ children: formatTime(duration)
1238
+ })]
1239
+ })]
1240
+ }), /*#__PURE__*/_jsx("div", {
1241
+ className: "video-controls-right",
1242
+ children: /*#__PURE__*/_jsx("button", {
1243
+ className: "video-control-btn video-fullscreen-btn",
1244
+ onClick: toggleFullscreen,
1245
+ "aria-label": isFullscreen ? "Exit fullscreen" : "Enter fullscreen",
1246
+ children: /*#__PURE__*/_jsx("i", {
1247
+ className: "fas ".concat(isFullscreen ? 'fa-compress' : 'fa-expand')
1248
+ })
1249
+ })
1250
+ })]
1251
+ })]
1252
+ })
1253
+ }), error && /*#__PURE__*/_jsxs("div", {
1254
+ style: {
1255
+ position: "absolute",
1256
+ top: 0,
1257
+ left: 0,
1258
+ right: 0,
1259
+ bottom: 0,
1260
+ backgroundColor: "rgba(0,0,0,0.7)",
1261
+ display: "flex",
1262
+ flexDirection: "column",
1263
+ alignItems: "center",
1264
+ justifyContent: "center",
1265
+ color: "white",
1266
+ zIndex: 20
1267
+ },
1268
+ children: [/*#__PURE__*/_jsx("p", {
1269
+ style: {
1270
+ marginBottom: "15px"
1271
+ },
1272
+ children: error
1273
+ }), /*#__PURE__*/_jsx("button", {
1274
+ onClick: function onClick() {
1275
+ setError(null);
1276
+ initPlayer();
1277
+ },
1278
+ style: {
1279
+ padding: "8px 16px",
1280
+ backgroundColor: "#00a8ff",
1281
+ color: "white",
1282
+ border: "none",
1283
+ borderRadius: "4px",
1284
+ cursor: "pointer"
1285
+ },
1286
+ children: "Retry"
1287
+ })]
1288
+ })]
1289
+ });
1290
+ };
1291
+ VideoPlayer.propTypes = {
1292
+ src: PropTypes.string.isRequired,
1293
+ id: PropTypes.string.isRequired,
1294
+ autoPlay: PropTypes.bool,
1295
+ muted: PropTypes.bool,
1296
+ controls: PropTypes.bool,
1297
+ loop: PropTypes.bool,
1298
+ onLoadedData: PropTypes.func,
1299
+ lowQualityFirst: PropTypes.bool,
1300
+ className: PropTypes.string,
1301
+ style: PropTypes.object,
1302
+ preloadStrategy: PropTypes.oneOf(['aggressive', 'balanced', 'conservative'])
1303
+ };
1304
+ export default VideoPlayer;