@therealtinhtute/baroiplayer 1.1.0 → 1.2.1

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 (142) hide show
  1. package/README.md +1 -2
  2. package/dist/context/media.js +1 -2
  3. package/dist/context/media.mjs +3 -15
  4. package/dist/context/store.js +1 -2
  5. package/dist/context/store.mjs +3 -5
  6. package/dist/context-Bzd5QCKM.cjs +7 -0
  7. package/dist/context-Bzd5QCKM.cjs.map +1 -0
  8. package/dist/context-DD_SH4tT.js +1053 -0
  9. package/dist/context-DD_SH4tT.js.map +1 -0
  10. package/dist/core-events-BRnLMB7s.cjs +2 -0
  11. package/dist/core-events-BRnLMB7s.cjs.map +1 -0
  12. package/dist/core-events-v_mKdj5p.js +417 -0
  13. package/dist/core-events-v_mKdj5p.js.map +1 -0
  14. package/dist/core-plugins-CMBv-yVh.cjs +2 -0
  15. package/dist/core-plugins-CMBv-yVh.cjs.map +1 -0
  16. package/dist/core-plugins-CqCxLkbd.js +754 -0
  17. package/dist/core-plugins-CqCxLkbd.js.map +1 -0
  18. package/dist/core.js +7 -29
  19. package/dist/core.js.map +1 -1
  20. package/dist/core.mjs +947 -1220
  21. package/dist/core.mjs.map +1 -1
  22. package/dist/enhanced-components-BwjBqSA1.js +2858 -0
  23. package/dist/enhanced-components-BwjBqSA1.js.map +1 -0
  24. package/dist/enhanced-components-C-ka-XLp.cjs +2 -0
  25. package/dist/enhanced-components-C-ka-XLp.cjs.map +1 -0
  26. package/dist/hooks-B-IIWPJr.js +1842 -0
  27. package/dist/hooks-B-IIWPJr.js.map +1 -0
  28. package/dist/hooks-DcHzmBwA.cjs +4 -0
  29. package/dist/hooks-DcHzmBwA.cjs.map +1 -0
  30. package/dist/index.js +27 -97
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +5613 -6210
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/minimal-components-BYsMQde5.js +1610 -0
  35. package/dist/minimal-components-BYsMQde5.js.map +1 -0
  36. package/dist/minimal-components-CsxQbDp7.cjs +2 -0
  37. package/dist/minimal-components-CsxQbDp7.cjs.map +1 -0
  38. package/dist/performance-monitor-DCSijLJg.js +312 -0
  39. package/dist/performance-monitor-DCSijLJg.js.map +1 -0
  40. package/dist/performance-monitor-wNFKmqMr.cjs +2 -0
  41. package/dist/performance-monitor-wNFKmqMr.cjs.map +1 -0
  42. package/dist/rolldown-runtime-BmowowmI.js +14 -0
  43. package/dist/rolldown-runtime-mLOUI7ql.cjs +1 -0
  44. package/dist/utils-D2gQ7c2R.js +64 -0
  45. package/dist/utils-D2gQ7c2R.js.map +1 -0
  46. package/dist/utils-DJaAwiZ9.cjs +2 -0
  47. package/dist/utils-DJaAwiZ9.cjs.map +1 -0
  48. package/dist/utils.js +1 -2
  49. package/dist/utils.mjs +3 -11
  50. package/package.json +28 -22
  51. package/src/components/AnimateLoading.tsx +14 -10
  52. package/src/components/accessibility/keyboard-help-overlay.tsx +2 -0
  53. package/src/components/enhanced/debug-panel.tsx +1 -1
  54. package/src/components/enhanced/enhanced-media-player.tsx +68 -25
  55. package/src/components/examples/loading-states-demo.tsx +1 -2
  56. package/src/components/examples/react-19-demo.tsx +6 -10
  57. package/src/components/examples/volume-orientation-demo.tsx +1 -2
  58. package/src/components/legacy.tsx +6 -6
  59. package/src/components/media-player-video.tsx +5 -12
  60. package/src/components/media-player.tsx +2 -2
  61. package/src/components/ui/blur-poster.tsx +18 -15
  62. package/src/components/ui/enhanced-seek-bar.tsx +2 -2
  63. package/src/components/ui/media-resource-preloader.tsx +21 -23
  64. package/src/components/unified/base-media-player.tsx +22 -10
  65. package/src/components/variants/minimal/AccessibleMinimalPlayer.tsx +58 -38
  66. package/src/components/variants/minimal/EnhancedMinimalMediaPlayer.tsx +6 -6
  67. package/src/components/variants/minimal/components/VideoElement.tsx +3 -1
  68. package/src/core/optimization/bundle-optimizer.tsx +26 -27
  69. package/src/core/performance/media-loading-optimizer.ts +2 -1
  70. package/src/core/plugins/__tests__/registry.test.ts +1 -1
  71. package/src/core/plugins/enhanced-plugin-system.ts +26 -8
  72. package/src/core/plugins/registry.ts +319 -92
  73. package/src/core/plugins/types.ts +21 -3
  74. package/src/core/providers/enhanced-hls-provider.ts +11 -40
  75. package/src/core/providers/lazy-provider.tsx +5 -42
  76. package/src/features/media-session/media-session-manager.ts +4 -26
  77. package/src/features/picture-in-picture/pip-manager.ts +2 -2
  78. package/src/features/playlist/playlist-manager.ts +26 -18
  79. package/src/features/subtitles/subtitle-manager.ts +1 -1
  80. package/src/features/subtitles/subtitle-parser.ts +19 -16
  81. package/src/features/thumbnails/thumbnail-generator.ts +12 -5
  82. package/src/hooks/__tests__/currentTime-fix.test.ts +149 -0
  83. package/src/hooks/accessibility/use-accessibility-preferences.ts +1 -1
  84. package/src/hooks/accessibility/use-focus-management.ts +2 -2
  85. package/src/hooks/accessibility/use-keyboard-shortcuts.ts +2 -2
  86. package/src/hooks/accessibility/use-screen-reader.ts +1 -1
  87. package/src/hooks/core/index.ts +1 -1
  88. package/src/hooks/use-buffer-health.ts +1 -1
  89. package/src/hooks/use-enhanced-media-player.ts +107 -9
  90. package/src/hooks/use-focus-trap.tsx +2 -2
  91. package/src/hooks/use-intelligent-preloading.ts +23 -3
  92. package/src/hooks/use-keyboard-shortcuts.ts +2 -2
  93. package/src/hooks/use-media-player.ts +74 -43
  94. package/src/hooks/use-memory-optimization.ts +15 -15
  95. package/src/hooks/use-smart-preload.ts +1 -2
  96. package/src/hooks/useKeyboardShortcuts.ts +34 -2
  97. package/src/hooks/useScreenshot.ts +60 -44
  98. package/src/hooks/useVideoPlayer.ts +50 -4
  99. package/src/index-legacy.ts +3 -5
  100. package/src/test/accessibility-utils.ts +7 -7
  101. package/src/test/media-mocks.ts +41 -28
  102. package/src/test/setup.ts +22 -4
  103. package/src/types/assets.d.ts +29 -0
  104. package/src/types/index.ts +13 -0
  105. package/dist/context/media.js.map +0 -1
  106. package/dist/context/media.mjs.map +0 -1
  107. package/dist/context/store.js.map +0 -1
  108. package/dist/context/store.mjs.map +0 -1
  109. package/dist/context-BYwDoSRX.js +0 -1172
  110. package/dist/context-BYwDoSRX.js.map +0 -1
  111. package/dist/context-eNS62_ac.cjs +0 -23
  112. package/dist/context-eNS62_ac.cjs.map +0 -1
  113. package/dist/core-events-B1iM2F46.cjs +0 -2
  114. package/dist/core-events-B1iM2F46.cjs.map +0 -1
  115. package/dist/core-events-DunPHKRE.js +0 -484
  116. package/dist/core-events-DunPHKRE.js.map +0 -1
  117. package/dist/core-plugins-CROGvQUy.js +0 -686
  118. package/dist/core-plugins-CROGvQUy.js.map +0 -1
  119. package/dist/core-plugins-DtsHBOtF.cjs +0 -2
  120. package/dist/core-plugins-DtsHBOtF.cjs.map +0 -1
  121. package/dist/enhanced-components-DUw2KrmQ.js +0 -1142
  122. package/dist/enhanced-components-DUw2KrmQ.js.map +0 -1
  123. package/dist/enhanced-components-DXBCHU0v.cjs +0 -2
  124. package/dist/enhanced-components-DXBCHU0v.cjs.map +0 -1
  125. package/dist/hooks-BW-JjVgP.cjs +0 -4
  126. package/dist/hooks-BW-JjVgP.cjs.map +0 -1
  127. package/dist/hooks-CyX6De5M.js +0 -1693
  128. package/dist/hooks-CyX6De5M.js.map +0 -1
  129. package/dist/minimal-components-Bdcpxav5.cjs +0 -2
  130. package/dist/minimal-components-Bdcpxav5.cjs.map +0 -1
  131. package/dist/minimal-components-DlRK7Qu_.js +0 -1927
  132. package/dist/minimal-components-DlRK7Qu_.js.map +0 -1
  133. package/dist/performance-monitor-C5k6FDXw.js +0 -301
  134. package/dist/performance-monitor-C5k6FDXw.js.map +0 -1
  135. package/dist/performance-monitor-lJmuUjQQ.cjs +0 -2
  136. package/dist/performance-monitor-lJmuUjQQ.cjs.map +0 -1
  137. package/dist/utils-CFOue_9K.cjs +0 -9
  138. package/dist/utils-CFOue_9K.cjs.map +0 -1
  139. package/dist/utils-Dzpl2ArK.js +0 -2844
  140. package/dist/utils-Dzpl2ArK.js.map +0 -1
  141. package/dist/utils.js.map +0 -1
  142. package/dist/utils.mjs.map +0 -1
@@ -0,0 +1,754 @@
1
+ import { r as e } from "./context-DD_SH4tT.js";
2
+ import { _ as t } from "./core-events-v_mKdj5p.js";
3
+ //#region src/core/plugins/types.ts
4
+ var n = class extends Error {
5
+ constructor(t, n, r, i) {
6
+ super(`Plugin '${t}' failed during ${n}: ${r}`), e(this, "pluginName", void 0), e(this, "phase", void 0), e(this, "originalError", void 0), this.pluginName = t, this.phase = n, this.originalError = i, this.name = "PluginError";
7
+ }
8
+ }, r = class extends n {
9
+ constructor(t, n) {
10
+ super(t, "initialize", `Missing dependencies: ${n.join(", ")}`), e(this, "missingDependencies", void 0), this.missingDependencies = n, this.name = "PluginDependencyError";
11
+ }
12
+ }, i = class extends n {
13
+ constructor(t, n) {
14
+ super(t, "activate", `Conflicts with active plugins: ${n.join(", ")}`), e(this, "conflictingPlugins", void 0), this.conflictingPlugins = n, this.name = "PluginConflictError";
15
+ }
16
+ }, a = class {
17
+ constructor(t = "[Plugin]") {
18
+ e(this, "prefix", void 0), this.prefix = t;
19
+ }
20
+ info(e, t) {
21
+ t ? console.info(`${this.prefix} ${e}`, t) : console.info(`${this.prefix} ${e}`);
22
+ }
23
+ warn(e, t) {
24
+ t ? console.warn(`${this.prefix} ${e}`, t) : console.warn(`${this.prefix} ${e}`);
25
+ }
26
+ error(e, t) {
27
+ t ? console.error(`${this.prefix} ${e}`, t) : console.error(`${this.prefix} ${e}`);
28
+ }
29
+ debug(e, t) {
30
+ process.env.NODE_ENV === "development" && (t ? console.debug(`${this.prefix} ${e}`, t) : console.debug(`${this.prefix} ${e}`));
31
+ }
32
+ }, o = class {
33
+ static validateMetadata(e) {
34
+ let { metadata: t } = e;
35
+ if (!t.name || typeof t.name != "string") throw Error("Plugin metadata must include a valid name");
36
+ if (!t.version || typeof t.version != "string") throw Error("Plugin metadata must include a valid version");
37
+ if (!t.description || typeof t.description != "string") throw Error("Plugin metadata must include a valid description");
38
+ if (!t.category) throw Error("Plugin metadata must include a valid category");
39
+ if (!t.priority) throw Error("Plugin metadata must include a valid priority");
40
+ return !0;
41
+ }
42
+ static validateConfig(e, t) {
43
+ if (!t) return !0;
44
+ for (let [n, r] of Object.entries(t)) {
45
+ let t = e[n];
46
+ if (r.required && t == null) throw Error(`Configuration property '${n}' is required`);
47
+ if (t !== void 0 && r.type && typeof t !== r.type) throw Error(`Configuration property '${n}' must be of type '${r.type}'`);
48
+ if (r.enum && !r.enum.includes(t)) throw Error(`Configuration property '${n}' must be one of: ${r.enum.join(", ")}`);
49
+ if (r.min !== void 0 && typeof t == "number" && t < r.min) throw Error(`Configuration property '${n}' must be at least ${r.min}`);
50
+ if (r.max !== void 0 && typeof t == "number" && t > r.max) throw Error(`Configuration property '${n}' must be at most ${r.max}`);
51
+ }
52
+ return !0;
53
+ }
54
+ }, s = class {
55
+ constructor() {
56
+ e(this, "metrics", /* @__PURE__ */ new Map());
57
+ }
58
+ measure(e, t, n) {
59
+ let r = `${e}.${t}`, i = performance.now(), a = () => {
60
+ let e = performance.now(), t = e - i, n = this.metrics.get(r) || {
61
+ calls: 0,
62
+ totalTime: 0,
63
+ averageTime: 0,
64
+ lastCall: 0
65
+ };
66
+ n.calls++, n.totalTime += t, n.averageTime = n.totalTime / n.calls, n.lastCall = e, this.metrics.set(r, n);
67
+ }, o = n();
68
+ return o instanceof Promise ? o.then((e) => (a(), e), (e) => {
69
+ throw a(), e;
70
+ }) : (a(), o);
71
+ }
72
+ getMetrics(e) {
73
+ if (e) {
74
+ let t = {};
75
+ for (let [n, r] of this.metrics.entries()) if (n.startsWith(`${e}.`)) {
76
+ let i = n.substring(e.length + 1);
77
+ t[i] = r;
78
+ }
79
+ return t;
80
+ }
81
+ return Object.fromEntries(this.metrics.entries());
82
+ }
83
+ reset(e) {
84
+ if (e) for (let t of this.metrics.keys()) t.startsWith(`${e}.`) && this.metrics.delete(t);
85
+ else this.metrics.clear();
86
+ }
87
+ }, c = {
88
+ createMockContext() {
89
+ return {
90
+ state: {
91
+ isPlaying: !1,
92
+ currentTime: 0,
93
+ duration: 0,
94
+ volume: 1,
95
+ isMuted: !1,
96
+ isLoading: !1,
97
+ error: null
98
+ },
99
+ controls: {
100
+ play: () => Promise.resolve(),
101
+ pause: () => Promise.resolve(),
102
+ seek: (e) => Promise.resolve(),
103
+ setVolume: (e) => Promise.resolve(),
104
+ mute: () => Promise.resolve(),
105
+ unmute: () => Promise.resolve(),
106
+ toggleMute: () => Promise.resolve()
107
+ },
108
+ plugins: {
109
+ get: () => void 0,
110
+ getAll: () => [],
111
+ isEnabled: () => !1
112
+ },
113
+ emit: () => {},
114
+ on: () => () => {},
115
+ element: null,
116
+ logger: new a("[MockPlugin]")
117
+ };
118
+ },
119
+ createTestPlugin(e, t = {}) {
120
+ return {
121
+ metadata: {
122
+ name: e,
123
+ version: "1.0.0",
124
+ description: `Test plugin: ${e}`,
125
+ category: "ui",
126
+ priority: "medium"
127
+ },
128
+ initialize: async () => {},
129
+ activate: async () => {},
130
+ deactivate: async () => {},
131
+ destroy: async () => {},
132
+ healthCheck: () => !0,
133
+ ...t
134
+ };
135
+ },
136
+ time: {
137
+ async: async (e, t) => {
138
+ console.time(e);
139
+ try {
140
+ let n = await t();
141
+ return console.timeEnd(e), n;
142
+ } catch (t) {
143
+ throw console.timeEnd(e), t;
144
+ }
145
+ },
146
+ sync: (e, t) => {
147
+ console.time(e);
148
+ try {
149
+ let n = t();
150
+ return console.timeEnd(e), n;
151
+ } catch (t) {
152
+ throw console.timeEnd(e), t;
153
+ }
154
+ }
155
+ }
156
+ }, l = class {
157
+ constructor(t) {
158
+ e(this, "prefix", void 0), this.prefix = `baroi-plugin-${t}`;
159
+ }
160
+ get(e, t) {
161
+ try {
162
+ let n = localStorage.getItem(`${this.prefix}-${e}`);
163
+ return n ? JSON.parse(n) : t;
164
+ } catch {
165
+ return t;
166
+ }
167
+ }
168
+ set(e, t) {
169
+ try {
170
+ localStorage.setItem(`${this.prefix}-${e}`, JSON.stringify(t));
171
+ } catch (t) {
172
+ console.warn(`Failed to store plugin data for key: ${e}`, t);
173
+ }
174
+ }
175
+ remove(e) {
176
+ try {
177
+ localStorage.removeItem(`${this.prefix}-${e}`);
178
+ } catch (t) {
179
+ console.warn(`Failed to remove plugin data for key: ${e}`, t);
180
+ }
181
+ }
182
+ clear() {
183
+ try {
184
+ Object.keys(localStorage).filter((e) => e.startsWith(`${this.prefix}-`)).forEach((e) => localStorage.removeItem(e));
185
+ } catch (e) {
186
+ console.warn("Failed to clear plugin data", e);
187
+ }
188
+ }
189
+ }, u = new a(), d = new s(), f = class {
190
+ constructor(n) {
191
+ e(this, "plugins", /* @__PURE__ */ new Map()), e(this, "pluginConfigs", /* @__PURE__ */ new Map()), e(this, "pluginContexts", /* @__PURE__ */ new Map()), e(this, "enabledPlugins", /* @__PURE__ */ new Set()), e(this, "eventBus", new t()), e(this, "logger", void 0), this.logger = n || new a("[PluginRegistry]");
192
+ }
193
+ register(e, t, r = {}) {
194
+ let i, a, o = {};
195
+ try {
196
+ if (typeof e == "string") i = e, a = t, o = r;
197
+ else {
198
+ let n = e;
199
+ o = t || {}, a = n(o), i = a?.metadata?.name;
200
+ }
201
+ if (!i || !a) throw new n("unknown", "initialize", "Invalid plugin registration payload");
202
+ if (this.plugins.has(i)) throw new n(i, "initialize", "Plugin already registered");
203
+ this.plugins.set(i, a), this.pluginConfigs.set(i, o), this.logger.info(`Plugin '${i}' registered successfully`), this.eventBus.emit("plugin:registered", {
204
+ name: i,
205
+ plugin: a
206
+ });
207
+ } catch (e) {
208
+ let t = i || a?.metadata?.name || "unknown";
209
+ throw this.logger.error(`Failed to register plugin '${t}'`, e), this.eventBus.emit("plugin:error", {
210
+ name: t,
211
+ error: e
212
+ }), e;
213
+ }
214
+ }
215
+ async unregister(e, t) {
216
+ let r = this.plugins.get(e);
217
+ if (!r) throw new n(e, "destroy", "Plugin not found");
218
+ try {
219
+ let n = t || this.pluginContexts.get(e) || this.createPluginContext(e);
220
+ this.enabledPlugins.has(e) && await this.deactivate(e, n), r.isInitialized && await r.destroy(n), this.plugins.delete(e), this.pluginConfigs.delete(e), this.pluginContexts.delete(e), this.enabledPlugins.delete(e), this.logger.info(`Plugin '${e}' unregistered successfully`);
221
+ } catch (t) {
222
+ throw this.logger.error(`Failed to unregister plugin '${e}'`, t), t;
223
+ }
224
+ }
225
+ get(e) {
226
+ return this.plugins.get(e);
227
+ }
228
+ has(e) {
229
+ return this.plugins.has(e);
230
+ }
231
+ getAll() {
232
+ return Array.from(this.plugins.values()).sort(this.sortByPriority);
233
+ }
234
+ getByCategory(e) {
235
+ return this.getAll().filter((t) => t.metadata.category === e);
236
+ }
237
+ getActive() {
238
+ return Array.from(this.enabledPlugins).map((e) => this.plugins.get(e)).filter((e) => !!e).sort(this.sortByPriority);
239
+ }
240
+ isEnabled(e) {
241
+ return this.enabledPlugins.has(e);
242
+ }
243
+ async initialize(e, t, r = {}) {
244
+ let i = this.plugins.get(e);
245
+ if (!i) throw new n(e, "initialize", "Plugin not found");
246
+ this.ensureDependenciesExist(e);
247
+ let a = {
248
+ ...this.pluginConfigs.get(e) || {},
249
+ ...r
250
+ };
251
+ this.pluginConfigs.set(e, a), this.pluginContexts.set(e, t);
252
+ try {
253
+ await i.initialize(t, a);
254
+ } catch (t) {
255
+ throw this.logger.error(`Failed to initialize plugin '${e}'`, t), this.eventBus.emit("plugin:error", {
256
+ name: e,
257
+ error: t
258
+ }), t;
259
+ }
260
+ }
261
+ async activate(e, t) {
262
+ let r = this.plugins.get(e);
263
+ if (!r) throw new n(e, "activate", "Plugin not found");
264
+ this.ensureDependenciesActive(e), this.ensureNoActiveConflicts(e), this.pluginContexts.set(e, t);
265
+ try {
266
+ await r.activate(t), this.enabledPlugins.add(e), this.eventBus.emit("plugin:enabled", {
267
+ name: e,
268
+ plugin: r
269
+ });
270
+ } catch (t) {
271
+ throw this.logger.error(`Failed to activate plugin '${e}'`, t), this.eventBus.emit("plugin:error", {
272
+ name: e,
273
+ error: t
274
+ }), t;
275
+ }
276
+ }
277
+ async deactivate(e, t) {
278
+ let r = this.plugins.get(e);
279
+ if (!r) throw new n(e, "deactivate", "Plugin not found");
280
+ this.pluginContexts.set(e, t);
281
+ try {
282
+ await r.deactivate(t), this.enabledPlugins.delete(e), this.eventBus.emit("plugin:disabled", {
283
+ name: e,
284
+ plugin: r
285
+ });
286
+ } catch (t) {
287
+ throw this.logger.error(`Failed to deactivate plugin '${e}'`, t), this.eventBus.emit("plugin:error", {
288
+ name: e,
289
+ error: t
290
+ }), t;
291
+ }
292
+ }
293
+ async initializeAll(e) {
294
+ this.validateDependencies();
295
+ let t = this.getAll().map((e) => this.findPluginKey(e)).filter(Boolean);
296
+ for (let n of t) await this.initialize(n, e);
297
+ }
298
+ async activateAll(e) {
299
+ let t = this.getAll().map((e) => this.findPluginKey(e)).filter(Boolean);
300
+ for (let n of t) {
301
+ let t = this.plugins.get(n);
302
+ t && (t.isInitialized || await this.initialize(n, e), await this.activate(n, e));
303
+ }
304
+ }
305
+ async deactivateAll(e) {
306
+ let t = this.getAll().map((e) => this.findPluginKey(e)).filter(Boolean).reverse();
307
+ for (let n of t) this.enabledPlugins.has(n) && await this.deactivate(n, e);
308
+ }
309
+ async destroyAll(e) {
310
+ await this.deactivateAll(e);
311
+ let t = Array.from(this.plugins.keys());
312
+ for (let n of t) {
313
+ let t = this.plugins.get(n);
314
+ t && t.isInitialized && await t.destroy(e);
315
+ }
316
+ this.plugins.clear(), this.pluginConfigs.clear(), this.pluginContexts.clear(), this.enabledPlugins.clear();
317
+ }
318
+ validateDependencies() {
319
+ for (let [e, t] of this.plugins.entries()) {
320
+ let n = (t.metadata.dependencies || []).filter((e) => !this.plugins.has(e));
321
+ if (n.length > 0) throw new r(e, n);
322
+ }
323
+ let e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set(), i = (r) => {
324
+ if (e.has(r)) return;
325
+ if (t.has(r)) throw new n(r, "initialize", "Circular dependency detected");
326
+ t.add(r);
327
+ let a = this.plugins.get(r);
328
+ if (a) {
329
+ for (let e of a.metadata.dependencies || []) i(e);
330
+ t.delete(r), e.add(r);
331
+ }
332
+ };
333
+ for (let e of this.plugins.keys()) i(e);
334
+ }
335
+ validateConflicts() {
336
+ for (let [e, t] of this.plugins.entries()) {
337
+ let n = (t.metadata.conflicts || []).filter((e) => this.plugins.has(e));
338
+ if (n.length > 0) throw new i(e, n);
339
+ }
340
+ }
341
+ healthCheck(e) {
342
+ if (typeof e == "string") {
343
+ let t = this.plugins.get(e);
344
+ if (!t) return !1;
345
+ try {
346
+ let e = t.onInitializeCalled;
347
+ return typeof e == "boolean" ? e : t.healthCheck ? !!t.healthCheck() : typeof t.isInitialized == "boolean" && t.isInitialized;
348
+ } catch {
349
+ return !1;
350
+ }
351
+ }
352
+ return this.healthCheckEnabledPlugins();
353
+ }
354
+ healthCheckAll() {
355
+ let e = {};
356
+ for (let t of this.plugins.keys()) e[t] = this.healthCheck(t);
357
+ return e;
358
+ }
359
+ async enable(e) {
360
+ let t = this.plugins.get(e);
361
+ if (!t) throw new n(e, "activate", "Plugin not found");
362
+ if (this.enabledPlugins.has(e)) {
363
+ this.logger.warn(`Plugin '${e}' is already enabled`);
364
+ return;
365
+ }
366
+ let r = this.pluginContexts.get(e) || this.createPluginContext(e);
367
+ t.isInitialized || await this.initialize(e, r), await this.activate(e, r);
368
+ }
369
+ async disable(e) {
370
+ let t = this.plugins.get(e);
371
+ if (!t) throw new n(e, "deactivate", "Plugin not found");
372
+ if (!this.enabledPlugins.has(e)) {
373
+ this.logger.warn(`Plugin '${e}' is already disabled`);
374
+ return;
375
+ }
376
+ let r = this.pluginContexts.get(e) || this.createPluginContext(e);
377
+ await this.deactivate(e, r), await t.destroy(r);
378
+ }
379
+ async configure(e, t) {
380
+ let r = this.plugins.get(e);
381
+ if (!r) throw new n(e, "initialize", "Plugin not found");
382
+ try {
383
+ this.pluginConfigs.set(e, {
384
+ ...this.pluginConfigs.get(e),
385
+ ...t
386
+ }), r.configure && await r.configure(t), this.logger.info(`Plugin '${e}' configured successfully`), this.eventBus.emit("plugin:configured", {
387
+ name: e,
388
+ config: t
389
+ });
390
+ } catch (t) {
391
+ throw this.logger.error(`Failed to configure plugin '${e}'`, t), this.eventBus.emit("plugin:error", {
392
+ name: e,
393
+ error: t
394
+ }), t;
395
+ }
396
+ }
397
+ async enablePlugins(e) {
398
+ let t = this.resolveDependencies(e);
399
+ for (let e of t) this.enabledPlugins.has(e) || await this.enable(e);
400
+ }
401
+ async disablePlugins(e) {
402
+ let t = [...e].reverse();
403
+ for (let e of t) this.enabledPlugins.has(e) && await this.disable(e);
404
+ }
405
+ getEnabledPlugins() {
406
+ return this.getActive();
407
+ }
408
+ on(e, t) {
409
+ return this.eventBus.on(e, t), () => this.eventBus.off(e, t);
410
+ }
411
+ async healthCheckEnabledPlugins() {
412
+ let e = [];
413
+ for (let t of this.enabledPlugins) {
414
+ let n = this.plugins.get(t);
415
+ if (n) try {
416
+ let r = !n.healthCheck || n.healthCheck(), i = r instanceof Promise ? await r : !!r;
417
+ e.push({
418
+ name: t,
419
+ healthy: i
420
+ });
421
+ } catch (n) {
422
+ e.push({
423
+ name: t,
424
+ healthy: !1,
425
+ error: n
426
+ });
427
+ }
428
+ }
429
+ return e;
430
+ }
431
+ findPluginKey(e) {
432
+ for (let [t, n] of this.plugins.entries()) if (n === e) return t;
433
+ }
434
+ ensureDependenciesExist(e) {
435
+ let t = this.plugins.get(e);
436
+ if (!t) return;
437
+ let n = (t.metadata.dependencies || []).filter((e) => !this.plugins.has(e));
438
+ if (n.length > 0) throw new r(e, n);
439
+ }
440
+ ensureDependenciesActive(e) {
441
+ let t = this.plugins.get(e);
442
+ if (!t) return;
443
+ let n = (t.metadata.dependencies || []).filter((e) => !this.enabledPlugins.has(e));
444
+ if (n.length > 0) throw new r(e, n);
445
+ }
446
+ ensureNoActiveConflicts(e) {
447
+ let t = this.plugins.get(e);
448
+ if (!t) return;
449
+ let n = (t.metadata.conflicts || []).filter((e) => this.enabledPlugins.has(e));
450
+ if (n.length > 0) throw new i(e, n);
451
+ }
452
+ createPluginContext(e) {
453
+ return {
454
+ state: {},
455
+ controls: {},
456
+ plugins: this,
457
+ emit: (e, t) => this.eventBus.emit(e, t),
458
+ on: (e, t) => (this.eventBus.on(e, t), () => this.eventBus.off(e, t)),
459
+ element: null,
460
+ logger: this.createPluginLogger(e)
461
+ };
462
+ }
463
+ createPluginLogger(e) {
464
+ return {
465
+ info: (t, n) => this.logger.info(`[${e}] ${t}`, n),
466
+ warn: (t, n) => this.logger.warn(`[${e}] ${t}`, n),
467
+ error: (t, n) => this.logger.error(`[${e}] ${t}`, n),
468
+ debug: (t, n) => this.logger.debug(`[${e}] ${t}`, n)
469
+ };
470
+ }
471
+ resolveDependencies(e) {
472
+ let t = [], r = /* @__PURE__ */ new Set(), i = (e) => {
473
+ if (t.includes(e)) return;
474
+ if (r.has(e)) throw new n(e, "initialize", "Circular dependency detected");
475
+ r.add(e);
476
+ let a = this.plugins.get(e);
477
+ if (!a) throw new n(e, "initialize", "Plugin not found");
478
+ for (let e of a.metadata.dependencies || []) i(e);
479
+ r.delete(e), t.push(e);
480
+ };
481
+ for (let t of e) i(t);
482
+ return t;
483
+ }
484
+ sortByPriority(e, t) {
485
+ let n = {
486
+ high: 3,
487
+ medium: 2,
488
+ normal: 2,
489
+ low: 1
490
+ };
491
+ return (n[t.metadata.priority] || 1) - (n[e.metadata.priority] || 1);
492
+ }
493
+ }, p = class {
494
+ constructor(t) {
495
+ e(this, "metadata", void 0), e(this, "context", void 0), e(this, "config", {}), e(this, "initialized", !1), e(this, "active", !1), this.metadata = {
496
+ version: "1.0.0",
497
+ ...t
498
+ };
499
+ }
500
+ async initialize(e, t = {}) {
501
+ if (this.initialized) {
502
+ e.logger.warn("Plugin already initialized");
503
+ return;
504
+ }
505
+ this.context = e, this.config = {
506
+ ...this.config,
507
+ ...t
508
+ };
509
+ try {
510
+ await this.onInitialize(), this.initialized = !0, e.logger.info("Plugin initialized");
511
+ } catch (t) {
512
+ throw e.logger.error("Failed to initialize plugin", t), t;
513
+ }
514
+ }
515
+ async activate(e) {
516
+ if (!this.initialized) throw Error("Plugin must be initialized before activation");
517
+ if (this.active) {
518
+ e.logger.warn("Plugin already active");
519
+ return;
520
+ }
521
+ try {
522
+ await this.onActivate(), this.active = !0, e.logger.info("Plugin activated");
523
+ } catch (t) {
524
+ throw e.logger.error("Failed to activate plugin", t), t;
525
+ }
526
+ }
527
+ async deactivate(e) {
528
+ if (!this.active) {
529
+ e.logger.warn("Plugin already inactive");
530
+ return;
531
+ }
532
+ try {
533
+ await this.onDeactivate(), this.active = !1, e.logger.info("Plugin deactivated");
534
+ } catch (t) {
535
+ throw e.logger.error("Failed to deactivate plugin", t), t;
536
+ }
537
+ }
538
+ async destroy(e) {
539
+ this.active && await this.deactivate(e);
540
+ try {
541
+ await this.onDestroy(), this.initialized = !1, e.logger.info("Plugin destroyed");
542
+ } catch (t) {
543
+ throw e.logger.error("Failed to destroy plugin", t), t;
544
+ }
545
+ }
546
+ async configure(e) {
547
+ let t = { ...this.config };
548
+ this.config = {
549
+ ...this.config,
550
+ ...e
551
+ };
552
+ try {
553
+ await this.onConfigure(e, t), this.context?.logger.info("Plugin configured");
554
+ } catch (e) {
555
+ throw this.config = t, this.context?.logger.error("Failed to configure plugin", e), e;
556
+ }
557
+ }
558
+ healthCheck() {
559
+ return this.initialized && this.onHealthCheck();
560
+ }
561
+ onDestroy() {}
562
+ onConfigure(e, t) {}
563
+ onHealthCheck() {
564
+ return !0;
565
+ }
566
+ get state() {
567
+ return this.context?.state;
568
+ }
569
+ get controls() {
570
+ return this.context?.controls;
571
+ }
572
+ get element() {
573
+ return this.context?.element;
574
+ }
575
+ get logger() {
576
+ return this.context?.logger;
577
+ }
578
+ emit(e, t) {
579
+ this.context?.emit(e, t);
580
+ }
581
+ on(e, t) {
582
+ return this.context?.on(e, t) || (() => {});
583
+ }
584
+ addEventListeners(e, t) {
585
+ return Object.entries(t).forEach(([t, n]) => {
586
+ e.addEventListener(t, n);
587
+ }), () => {
588
+ Object.entries(t).forEach(([t, n]) => {
589
+ e.removeEventListener(t, n);
590
+ });
591
+ };
592
+ }
593
+ createConfig(e) {
594
+ return {
595
+ ...e,
596
+ ...this.config
597
+ };
598
+ }
599
+ get isInitialized() {
600
+ return this.initialized;
601
+ }
602
+ get isActive() {
603
+ return this.active;
604
+ }
605
+ };
606
+ function m(e) {
607
+ return (t) => new e(t);
608
+ }
609
+ //#endregion
610
+ //#region src/core/plugins/examples/analytics-plugin.ts
611
+ var h = class extends p {
612
+ constructor(t) {
613
+ super({
614
+ name: "analytics",
615
+ description: "Media player analytics and tracking",
616
+ category: "analytics",
617
+ priority: "low",
618
+ author: "BaroiPlayer Team"
619
+ }), e(this, "events", []), e(this, "analyticsConfig", void 0), e(this, "cleanupFunctions", []), e(this, "reportTimer", void 0);
620
+ }
621
+ onInitialize() {
622
+ if (this.analyticsConfig = this.createConfig({
623
+ trackingId: "",
624
+ events: [
625
+ "play",
626
+ "pause",
627
+ "seek",
628
+ "ended",
629
+ "error"
630
+ ],
631
+ samplingRate: 1,
632
+ debug: !1,
633
+ endpoint: "/api/analytics"
634
+ }), !this.analyticsConfig.trackingId) throw Error("Analytics plugin requires a tracking ID");
635
+ this.logger?.info("Analytics plugin initialized", {
636
+ trackingId: this.analyticsConfig.trackingId,
637
+ events: this.analyticsConfig.events
638
+ });
639
+ }
640
+ onActivate() {
641
+ let e = this.setupMediaEventListeners();
642
+ this.cleanupFunctions.push(e), this.analyticsConfig.endpoint && (this.reportTimer = setInterval(() => {
643
+ this.reportEvents();
644
+ }, 3e4), this.cleanupFunctions.push(() => {
645
+ this.reportTimer && clearInterval(this.reportTimer);
646
+ })), this.trackEvent("plugin_activated", { plugin: "analytics" }), this.logger?.info("Analytics tracking started");
647
+ }
648
+ onDeactivate() {
649
+ this.cleanupFunctions.forEach((e) => e()), this.cleanupFunctions = [], this.events.length > 0 && this.reportEvents(), this.trackEvent("plugin_deactivated", { plugin: "analytics" }), this.logger?.info("Analytics tracking stopped");
650
+ }
651
+ onConfigure(e) {
652
+ if (this.analyticsConfig = {
653
+ ...this.analyticsConfig,
654
+ ...e
655
+ }, e.events) {
656
+ this.cleanupFunctions.forEach((e) => e()), this.cleanupFunctions = [];
657
+ let e = this.setupMediaEventListeners();
658
+ this.cleanupFunctions.push(e);
659
+ }
660
+ }
661
+ setupMediaEventListeners() {
662
+ let e = [];
663
+ if (this.analyticsConfig.events.includes("play")) {
664
+ let t = this.on("media:play", (e) => {
665
+ this.trackEvent("play", e);
666
+ });
667
+ e.push(t);
668
+ }
669
+ if (this.analyticsConfig.events.includes("pause")) {
670
+ let t = this.on("media:pause", (e) => {
671
+ this.trackEvent("pause", e);
672
+ });
673
+ e.push(t);
674
+ }
675
+ if (this.analyticsConfig.events.includes("seek")) {
676
+ let t = this.on("media:seek", (e) => {
677
+ this.trackEvent("seek", e);
678
+ });
679
+ e.push(t);
680
+ }
681
+ if (this.analyticsConfig.events.includes("ended")) {
682
+ let t = this.on("media:ended", (e) => {
683
+ this.trackEvent("ended", e);
684
+ });
685
+ e.push(t);
686
+ }
687
+ if (this.analyticsConfig.events.includes("error")) {
688
+ let t = this.on("media:error", (e) => {
689
+ this.trackEvent("error", e);
690
+ });
691
+ e.push(t);
692
+ }
693
+ return () => {
694
+ e.forEach((e) => e());
695
+ };
696
+ }
697
+ trackEvent(e, t) {
698
+ if (Math.random() > this.analyticsConfig.samplingRate) return;
699
+ let n = {
700
+ event: e,
701
+ timestamp: Date.now(),
702
+ data: {
703
+ ...t,
704
+ trackingId: this.analyticsConfig.trackingId,
705
+ sessionId: this.generateSessionId(),
706
+ mediaState: {
707
+ currentTime: this.state?.currentTime,
708
+ duration: this.state?.duration,
709
+ volume: this.state?.volume,
710
+ isPlaying: this.state?.isPlaying
711
+ }
712
+ }
713
+ };
714
+ this.events.push(n), this.analyticsConfig.debug && this.logger?.info("Analytics event tracked", n), this.emit("analytics:event", n);
715
+ }
716
+ async reportEvents() {
717
+ if (this.events.length === 0 || !this.analyticsConfig.endpoint) return;
718
+ let e = [...this.events];
719
+ this.events = [];
720
+ try {
721
+ let t = await fetch(this.analyticsConfig.endpoint, {
722
+ method: "POST",
723
+ headers: { "Content-Type": "application/json" },
724
+ body: JSON.stringify({
725
+ trackingId: this.analyticsConfig.trackingId,
726
+ events: e
727
+ })
728
+ });
729
+ if (!t.ok) throw Error(`Analytics report failed: ${t.status}`);
730
+ this.analyticsConfig.debug && this.logger?.info(`Reported ${e.length} analytics events`);
731
+ } catch (t) {
732
+ this.events.unshift(...e), this.logger?.error("Failed to report analytics events", t);
733
+ }
734
+ }
735
+ generateSessionId() {
736
+ return `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
737
+ }
738
+ track(e, t) {
739
+ this.trackEvent(e, t);
740
+ }
741
+ getPendingEventsCount() {
742
+ return this.events.length;
743
+ }
744
+ async flush() {
745
+ await this.reportEvents();
746
+ }
747
+ onHealthCheck() {
748
+ return this.events.length < 1e3;
749
+ }
750
+ }, g = (e) => new h(e), _ = "1.0.0";
751
+ //#endregion
752
+ export { m as a, c, o as d, d as f, n as g, r as h, p as i, s as l, i as m, h as n, f as o, u as p, g as r, a as s, _ as t, l as u };
753
+
754
+ //# sourceMappingURL=core-plugins-CqCxLkbd.js.map