@therealtinhtute/baroiplayer 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/core-plugins-By-4-kGs.cjs +2 -0
  2. package/dist/core-plugins-By-4-kGs.cjs.map +1 -0
  3. package/dist/{core-plugins-CROGvQUy.js → core-plugins-DSBWcTuX.js} +444 -309
  4. package/dist/core-plugins-DSBWcTuX.js.map +1 -0
  5. package/dist/core.js +2 -2
  6. package/dist/core.mjs +19 -19
  7. package/dist/{enhanced-components-DUw2KrmQ.js → enhanced-components-B_l3cist.js} +2 -2
  8. package/dist/{enhanced-components-DUw2KrmQ.js.map → enhanced-components-B_l3cist.js.map} +1 -1
  9. package/dist/{enhanced-components-DXBCHU0v.cjs → enhanced-components-BspFs9OO.cjs} +2 -2
  10. package/dist/{enhanced-components-DXBCHU0v.cjs.map → enhanced-components-BspFs9OO.cjs.map} +1 -1
  11. package/dist/hooks-BXwI8QG6.cjs +4 -0
  12. package/dist/hooks-BXwI8QG6.cjs.map +1 -0
  13. package/dist/hooks-Bpi-jDiO.js +1816 -0
  14. package/dist/hooks-Bpi-jDiO.js.map +1 -0
  15. package/dist/index.js +2 -2
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +18 -20
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/{minimal-components-DlRK7Qu_.js → minimal-components-C4z900Ro.js} +297 -298
  20. package/dist/minimal-components-C4z900Ro.js.map +1 -0
  21. package/dist/minimal-components-v4qBp6jv.cjs +2 -0
  22. package/dist/minimal-components-v4qBp6jv.cjs.map +1 -0
  23. package/package.json +1 -1
  24. package/src/components/accessibility/keyboard-help-overlay.tsx +2 -0
  25. package/src/components/enhanced/debug-panel.tsx +1 -1
  26. package/src/components/enhanced/enhanced-media-player.tsx +68 -25
  27. package/src/components/legacy.tsx +6 -6
  28. package/src/components/media-player-video.tsx +5 -12
  29. package/src/components/media-player.tsx +2 -2
  30. package/src/components/ui/enhanced-seek-bar.tsx +2 -2
  31. package/src/components/ui/media-resource-preloader.tsx +21 -23
  32. package/src/components/unified/base-media-player.tsx +22 -10
  33. package/src/components/variants/minimal/AccessibleMinimalPlayer.tsx +58 -38
  34. package/src/components/variants/minimal/EnhancedMinimalMediaPlayer.tsx +6 -6
  35. package/src/core/optimization/bundle-optimizer.tsx +26 -27
  36. package/src/core/plugins/__tests__/registry.test.ts +1 -1
  37. package/src/core/plugins/enhanced-plugin-system.ts +26 -8
  38. package/src/core/plugins/registry.ts +319 -92
  39. package/src/core/plugins/types.ts +21 -3
  40. package/src/core/providers/enhanced-hls-provider.ts +11 -40
  41. package/src/core/providers/lazy-provider.tsx +5 -42
  42. package/src/features/media-session/media-session-manager.ts +4 -26
  43. package/src/features/picture-in-picture/pip-manager.ts +2 -2
  44. package/src/features/playlist/playlist-manager.ts +26 -18
  45. package/src/features/subtitles/subtitle-manager.ts +1 -1
  46. package/src/features/subtitles/subtitle-parser.ts +19 -16
  47. package/src/features/thumbnails/thumbnail-generator.ts +12 -5
  48. package/src/hooks/__tests__/currentTime-fix.test.ts +149 -0
  49. package/src/hooks/accessibility/use-accessibility-preferences.ts +1 -1
  50. package/src/hooks/accessibility/use-focus-management.ts +2 -2
  51. package/src/hooks/accessibility/use-keyboard-shortcuts.ts +2 -2
  52. package/src/hooks/accessibility/use-screen-reader.ts +1 -1
  53. package/src/hooks/core/index.ts +1 -1
  54. package/src/hooks/use-buffer-health.ts +1 -1
  55. package/src/hooks/use-enhanced-media-player.ts +107 -9
  56. package/src/hooks/use-focus-trap.tsx +2 -2
  57. package/src/hooks/use-intelligent-preloading.ts +23 -3
  58. package/src/hooks/use-keyboard-shortcuts.ts +2 -2
  59. package/src/hooks/use-media-player.ts +74 -43
  60. package/src/hooks/use-memory-optimization.ts +15 -15
  61. package/src/hooks/use-smart-preload.ts +1 -2
  62. package/src/hooks/useKeyboardShortcuts.ts +34 -2
  63. package/src/hooks/useVideoPlayer.ts +50 -4
  64. package/src/index-legacy.ts +3 -5
  65. package/src/test/accessibility-utils.ts +7 -7
  66. package/src/test/media-mocks.ts +41 -28
  67. package/src/test/setup.ts +22 -4
  68. package/src/types/index.ts +13 -0
  69. package/dist/core-plugins-CROGvQUy.js.map +0 -1
  70. package/dist/core-plugins-DtsHBOtF.cjs +0 -2
  71. package/dist/core-plugins-DtsHBOtF.cjs.map +0 -1
  72. package/dist/hooks-BW-JjVgP.cjs +0 -4
  73. package/dist/hooks-BW-JjVgP.cjs.map +0 -1
  74. package/dist/hooks-CyX6De5M.js +0 -1693
  75. package/dist/hooks-CyX6De5M.js.map +0 -1
  76. package/dist/minimal-components-Bdcpxav5.cjs +0 -2
  77. package/dist/minimal-components-Bdcpxav5.cjs.map +0 -1
  78. package/dist/minimal-components-DlRK7Qu_.js.map +0 -1
@@ -1,72 +1,401 @@
1
- var f = Object.defineProperty;
2
- var p = (r, t, e) => t in r ? f(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var o = (r, t, e) => p(r, typeof t != "symbol" ? t + "" : t, e);
4
- import { E as y } from "./core-events-DunPHKRE.js";
1
+ var y = Object.defineProperty;
2
+ var v = (r, t, e) => t in r ? y(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var a = (r, t, e) => v(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import { E as w } from "./core-events-DunPHKRE.js";
5
5
  class l extends Error {
6
6
  constructor(t, e, i, n) {
7
7
  super(`Plugin '${t}' failed during ${e}: ${i}`), this.pluginName = t, this.phase = e, this.originalError = n, this.name = "PluginError";
8
8
  }
9
9
  }
10
- class v extends l {
10
+ class h extends l {
11
11
  constructor(t, e) {
12
12
  super(t, "initialize", `Missing dependencies: ${e.join(", ")}`), this.missingDependencies = e, this.name = "PluginDependencyError";
13
13
  }
14
14
  }
15
- class w extends l {
15
+ class f extends l {
16
16
  constructor(t, e) {
17
17
  super(t, "activate", `Conflicts with active plugins: ${e.join(", ")}`), this.conflictingPlugins = e, this.name = "PluginConflictError";
18
18
  }
19
19
  }
20
+ class d {
21
+ constructor(t = "[Plugin]") {
22
+ a(this, "prefix");
23
+ this.prefix = t;
24
+ }
25
+ info(t, e) {
26
+ e ? console.info(`${this.prefix} ${t}`, e) : console.info(`${this.prefix} ${t}`);
27
+ }
28
+ warn(t, e) {
29
+ e ? console.warn(`${this.prefix} ${t}`, e) : console.warn(`${this.prefix} ${t}`);
30
+ }
31
+ error(t, e) {
32
+ e ? console.error(`${this.prefix} ${t}`, e) : console.error(`${this.prefix} ${t}`);
33
+ }
34
+ debug(t, e) {
35
+ process.env.NODE_ENV === "development" && (e ? console.debug(`${this.prefix} ${t}`, e) : console.debug(`${this.prefix} ${t}`));
36
+ }
37
+ }
20
38
  class b {
39
+ static validateMetadata(t) {
40
+ const { metadata: e } = t;
41
+ if (!e.name || typeof e.name != "string")
42
+ throw new Error("Plugin metadata must include a valid name");
43
+ if (!e.version || typeof e.version != "string")
44
+ throw new Error("Plugin metadata must include a valid version");
45
+ if (!e.description || typeof e.description != "string")
46
+ throw new Error("Plugin metadata must include a valid description");
47
+ if (!e.category)
48
+ throw new Error("Plugin metadata must include a valid category");
49
+ if (!e.priority)
50
+ throw new Error("Plugin metadata must include a valid priority");
51
+ return !0;
52
+ }
53
+ static validateConfig(t, e) {
54
+ if (!e) return !0;
55
+ for (const [i, n] of Object.entries(e)) {
56
+ const s = t[i];
57
+ if (n.required && s == null)
58
+ throw new Error(`Configuration property '${i}' is required`);
59
+ if (s !== void 0 && n.type && typeof s !== n.type)
60
+ throw new Error(`Configuration property '${i}' must be of type '${n.type}'`);
61
+ if (n.enum && !n.enum.includes(s))
62
+ throw new Error(`Configuration property '${i}' must be one of: ${n.enum.join(", ")}`);
63
+ if (n.min !== void 0 && typeof s == "number" && s < n.min)
64
+ throw new Error(`Configuration property '${i}' must be at least ${n.min}`);
65
+ if (n.max !== void 0 && typeof s == "number" && s > n.max)
66
+ throw new Error(`Configuration property '${i}' must be at most ${n.max}`);
67
+ }
68
+ return !0;
69
+ }
70
+ }
71
+ class P {
72
+ constructor() {
73
+ a(this, "metrics", /* @__PURE__ */ new Map());
74
+ }
75
+ measure(t, e, i) {
76
+ const n = `${t}.${e}`, s = performance.now(), o = () => {
77
+ const u = performance.now(), p = u - s, g = this.metrics.get(n) || {
78
+ calls: 0,
79
+ totalTime: 0,
80
+ averageTime: 0,
81
+ lastCall: 0
82
+ };
83
+ g.calls++, g.totalTime += p, g.averageTime = g.totalTime / g.calls, g.lastCall = u, this.metrics.set(n, g);
84
+ }, c = i();
85
+ return c instanceof Promise ? c.then(
86
+ (u) => (o(), u),
87
+ (u) => {
88
+ throw o(), u;
89
+ }
90
+ ) : (o(), c);
91
+ }
92
+ getMetrics(t) {
93
+ if (t) {
94
+ const e = {};
95
+ for (const [i, n] of this.metrics.entries())
96
+ if (i.startsWith(`${t}.`)) {
97
+ const s = i.substring(t.length + 1);
98
+ e[s] = n;
99
+ }
100
+ return e;
101
+ }
102
+ return Object.fromEntries(this.metrics.entries());
103
+ }
104
+ reset(t) {
105
+ if (t)
106
+ for (const e of this.metrics.keys())
107
+ e.startsWith(`${t}.`) && this.metrics.delete(e);
108
+ else
109
+ this.metrics.clear();
110
+ }
111
+ }
112
+ const k = {
113
+ // Create a mock plugin context for testing
114
+ createMockContext() {
115
+ return {
116
+ state: {
117
+ isPlaying: !1,
118
+ currentTime: 0,
119
+ duration: 0,
120
+ volume: 1,
121
+ isMuted: !1,
122
+ isLoading: !1,
123
+ error: null
124
+ },
125
+ controls: {
126
+ play: () => Promise.resolve(),
127
+ pause: () => Promise.resolve(),
128
+ seek: (r) => Promise.resolve(),
129
+ setVolume: (r) => Promise.resolve(),
130
+ mute: () => Promise.resolve(),
131
+ unmute: () => Promise.resolve(),
132
+ toggleMute: () => Promise.resolve()
133
+ },
134
+ plugins: {
135
+ get: () => {
136
+ },
137
+ getAll: () => [],
138
+ isEnabled: () => !1
139
+ },
140
+ emit: () => {
141
+ },
142
+ on: () => () => {
143
+ },
144
+ element: null,
145
+ logger: new d("[MockPlugin]")
146
+ };
147
+ },
148
+ // Create a test plugin for development
149
+ createTestPlugin(r, t = {}) {
150
+ return {
151
+ metadata: {
152
+ name: r,
153
+ version: "1.0.0",
154
+ description: `Test plugin: ${r}`,
155
+ category: "ui",
156
+ priority: "medium"
157
+ },
158
+ initialize: async () => {
159
+ },
160
+ activate: async () => {
161
+ },
162
+ deactivate: async () => {
163
+ },
164
+ destroy: async () => {
165
+ },
166
+ healthCheck: () => !0,
167
+ ...t
168
+ };
169
+ },
170
+ // Plugin timing utilities
171
+ time: {
172
+ async: async (r, t) => {
173
+ console.time(r);
174
+ try {
175
+ const e = await t();
176
+ return console.timeEnd(r), e;
177
+ } catch (e) {
178
+ throw console.timeEnd(r), e;
179
+ }
180
+ },
181
+ sync: (r, t) => {
182
+ console.time(r);
183
+ try {
184
+ const e = t();
185
+ return console.timeEnd(r), e;
186
+ } catch (e) {
187
+ throw console.timeEnd(r), e;
188
+ }
189
+ }
190
+ }
191
+ };
192
+ class x {
193
+ constructor(t) {
194
+ a(this, "prefix");
195
+ this.prefix = `baroi-plugin-${t}`;
196
+ }
197
+ get(t, e) {
198
+ try {
199
+ const i = localStorage.getItem(`${this.prefix}-${t}`);
200
+ return i ? JSON.parse(i) : e;
201
+ } catch {
202
+ return e;
203
+ }
204
+ }
205
+ set(t, e) {
206
+ try {
207
+ localStorage.setItem(`${this.prefix}-${t}`, JSON.stringify(e));
208
+ } catch (i) {
209
+ console.warn(`Failed to store plugin data for key: ${t}`, i);
210
+ }
211
+ }
212
+ remove(t) {
213
+ try {
214
+ localStorage.removeItem(`${this.prefix}-${t}`);
215
+ } catch (e) {
216
+ console.warn(`Failed to remove plugin data for key: ${t}`, e);
217
+ }
218
+ }
219
+ clear() {
220
+ try {
221
+ Object.keys(localStorage).filter((e) => e.startsWith(`${this.prefix}-`)).forEach((e) => localStorage.removeItem(e));
222
+ } catch (t) {
223
+ console.warn("Failed to clear plugin data", t);
224
+ }
225
+ }
226
+ }
227
+ const z = new d(), A = new P();
228
+ class I {
21
229
  constructor(t) {
22
- o(this, "plugins", /* @__PURE__ */ new Map());
23
- o(this, "pluginConfigs", /* @__PURE__ */ new Map());
24
- o(this, "enabledPlugins", /* @__PURE__ */ new Set());
25
- o(this, "eventBus", new y());
26
- o(this, "logger");
27
- this.logger = t;
28
- }
29
- // Register a plugin factory
30
- async register(t, e = {}) {
230
+ a(this, "plugins", /* @__PURE__ */ new Map());
231
+ a(this, "pluginConfigs", /* @__PURE__ */ new Map());
232
+ a(this, "pluginContexts", /* @__PURE__ */ new Map());
233
+ a(this, "enabledPlugins", /* @__PURE__ */ new Set());
234
+ a(this, "eventBus", new w());
235
+ a(this, "logger");
236
+ this.logger = t || new d("[PluginRegistry]");
237
+ }
238
+ register(t, e, i = {}) {
239
+ let n, s, o = {};
31
240
  try {
32
- const i = t(e), { name: n, dependencies: s = [], conflicts: c = [] } = i.metadata;
241
+ if (typeof t == "string")
242
+ n = t, s = e, o = i;
243
+ else {
244
+ const c = t;
245
+ o = e || {}, s = c(o), n = s?.metadata?.name;
246
+ }
247
+ if (!n || !s)
248
+ throw new l("unknown", "initialize", "Invalid plugin registration payload");
33
249
  if (this.plugins.has(n))
34
250
  throw new l(n, "initialize", "Plugin already registered");
35
- const u = s.filter((h) => !this.plugins.has(h));
36
- if (u.length > 0)
37
- throw new v(n, u);
38
- const a = c.filter((h) => this.enabledPlugins.has(h));
39
- if (a.length > 0)
40
- throw new w(n, a);
41
- this.plugins.set(n, i), this.pluginConfigs.set(n, e), this.logger.info(`Plugin '${n}' registered successfully`), this.eventBus.emit("plugin:registered", { name: n, plugin: i });
42
- } catch (i) {
43
- const n = t({}).metadata.name;
44
- throw this.logger.error(`Failed to register plugin '${n}'`, i), this.eventBus.emit("plugin:error", { name: n, error: i }), i;
251
+ this.plugins.set(n, s), this.pluginConfigs.set(n, o), this.logger.info(`Plugin '${n}' registered successfully`), this.eventBus.emit("plugin:registered", { name: n, plugin: s });
252
+ } catch (c) {
253
+ const u = n || s?.metadata?.name || "unknown";
254
+ throw this.logger.error(`Failed to register plugin '${u}'`, c), this.eventBus.emit("plugin:error", { name: u, error: c }), c;
45
255
  }
46
256
  }
47
- // Unregister a plugin
48
- async unregister(t) {
49
- if (!this.plugins.get(t))
257
+ async unregister(t, e) {
258
+ const i = this.plugins.get(t);
259
+ if (!i)
50
260
  throw new l(t, "destroy", "Plugin not found");
51
261
  try {
52
- this.enabledPlugins.has(t) && await this.disable(t), this.plugins.delete(t), this.pluginConfigs.delete(t), this.logger.info(`Plugin '${t}' unregistered successfully`);
53
- } catch (i) {
54
- throw this.logger.error(`Failed to unregister plugin '${t}'`, i), i;
262
+ const n = e || this.pluginContexts.get(t) || this.createPluginContext(t);
263
+ this.enabledPlugins.has(t) && await this.deactivate(t, n), i.isInitialized && await i.destroy(n), this.plugins.delete(t), this.pluginConfigs.delete(t), this.pluginContexts.delete(t), this.enabledPlugins.delete(t), this.logger.info(`Plugin '${t}' unregistered successfully`);
264
+ } catch (n) {
265
+ throw this.logger.error(`Failed to unregister plugin '${t}'`, n), n;
55
266
  }
56
267
  }
57
- // Get a plugin by name
58
268
  get(t) {
59
269
  return this.plugins.get(t);
60
270
  }
61
- // Get all plugins sorted by priority
271
+ has(t) {
272
+ return this.plugins.has(t);
273
+ }
62
274
  getAll() {
63
275
  return Array.from(this.plugins.values()).sort(this.sortByPriority);
64
276
  }
65
- // Check if plugin is enabled
277
+ getByCategory(t) {
278
+ return this.getAll().filter((e) => e.metadata.category === t);
279
+ }
280
+ getActive() {
281
+ return Array.from(this.enabledPlugins).map((t) => this.plugins.get(t)).filter((t) => !!t).sort(this.sortByPriority);
282
+ }
66
283
  isEnabled(t) {
67
284
  return this.enabledPlugins.has(t);
68
285
  }
69
- // Enable a plugin
286
+ async initialize(t, e, i = {}) {
287
+ const n = this.plugins.get(t);
288
+ if (!n)
289
+ throw new l(t, "initialize", "Plugin not found");
290
+ this.ensureDependenciesExist(t);
291
+ const s = { ...this.pluginConfigs.get(t) || {}, ...i };
292
+ this.pluginConfigs.set(t, s), this.pluginContexts.set(t, e);
293
+ try {
294
+ await n.initialize(e, s);
295
+ } catch (o) {
296
+ throw this.logger.error(`Failed to initialize plugin '${t}'`, o), this.eventBus.emit("plugin:error", { name: t, error: o }), o;
297
+ }
298
+ }
299
+ async activate(t, e) {
300
+ const i = this.plugins.get(t);
301
+ if (!i)
302
+ throw new l(t, "activate", "Plugin not found");
303
+ this.ensureDependenciesActive(t), this.ensureNoActiveConflicts(t), this.pluginContexts.set(t, e);
304
+ try {
305
+ await i.activate(e), this.enabledPlugins.add(t), this.eventBus.emit("plugin:enabled", { name: t, plugin: i });
306
+ } catch (n) {
307
+ throw this.logger.error(`Failed to activate plugin '${t}'`, n), this.eventBus.emit("plugin:error", { name: t, error: n }), n;
308
+ }
309
+ }
310
+ async deactivate(t, e) {
311
+ const i = this.plugins.get(t);
312
+ if (!i)
313
+ throw new l(t, "deactivate", "Plugin not found");
314
+ this.pluginContexts.set(t, e);
315
+ try {
316
+ await i.deactivate(e), this.enabledPlugins.delete(t), this.eventBus.emit("plugin:disabled", { name: t, plugin: i });
317
+ } catch (n) {
318
+ throw this.logger.error(`Failed to deactivate plugin '${t}'`, n), this.eventBus.emit("plugin:error", { name: t, error: n }), n;
319
+ }
320
+ }
321
+ async initializeAll(t) {
322
+ this.validateDependencies();
323
+ const e = this.getAll().map((i) => this.findPluginKey(i)).filter(Boolean);
324
+ for (const i of e)
325
+ await this.initialize(i, t);
326
+ }
327
+ async activateAll(t) {
328
+ const e = this.getAll().map((i) => this.findPluginKey(i)).filter(Boolean);
329
+ for (const i of e) {
330
+ const n = this.plugins.get(i);
331
+ n && (n.isInitialized || await this.initialize(i, t), await this.activate(i, t));
332
+ }
333
+ }
334
+ async deactivateAll(t) {
335
+ const e = this.getAll().map((i) => this.findPluginKey(i)).filter(Boolean).reverse();
336
+ for (const i of e)
337
+ this.enabledPlugins.has(i) && await this.deactivate(i, t);
338
+ }
339
+ async destroyAll(t) {
340
+ await this.deactivateAll(t);
341
+ const e = Array.from(this.plugins.keys());
342
+ for (const i of e) {
343
+ const n = this.plugins.get(i);
344
+ n && n.isInitialized && await n.destroy(t);
345
+ }
346
+ this.plugins.clear(), this.pluginConfigs.clear(), this.pluginContexts.clear(), this.enabledPlugins.clear();
347
+ }
348
+ validateDependencies() {
349
+ for (const [n, s] of this.plugins.entries()) {
350
+ const o = (s.metadata.dependencies || []).filter(
351
+ (c) => !this.plugins.has(c)
352
+ );
353
+ if (o.length > 0)
354
+ throw new h(n, o);
355
+ }
356
+ const t = /* @__PURE__ */ new Set(), e = /* @__PURE__ */ new Set(), i = (n) => {
357
+ if (t.has(n)) return;
358
+ if (e.has(n))
359
+ throw new l(n, "initialize", "Circular dependency detected");
360
+ e.add(n);
361
+ const s = this.plugins.get(n);
362
+ if (s) {
363
+ for (const o of s.metadata.dependencies || [])
364
+ i(o);
365
+ e.delete(n), t.add(n);
366
+ }
367
+ };
368
+ for (const n of this.plugins.keys())
369
+ i(n);
370
+ }
371
+ validateConflicts() {
372
+ for (const [t, e] of this.plugins.entries()) {
373
+ const i = (e.metadata.conflicts || []).filter(
374
+ (n) => this.plugins.has(n)
375
+ );
376
+ if (i.length > 0)
377
+ throw new f(t, i);
378
+ }
379
+ }
380
+ healthCheck(t) {
381
+ if (typeof t == "string") {
382
+ const e = this.plugins.get(t);
383
+ if (!e) return !1;
384
+ try {
385
+ const i = e.onInitializeCalled;
386
+ return typeof i == "boolean" ? i : e.healthCheck ? !!e.healthCheck() : typeof e.isInitialized == "boolean" ? e.isInitialized : !1;
387
+ } catch {
388
+ return !1;
389
+ }
390
+ }
391
+ return this.healthCheckEnabledPlugins();
392
+ }
393
+ healthCheckAll() {
394
+ const t = {};
395
+ for (const e of this.plugins.keys())
396
+ t[e] = this.healthCheck(e);
397
+ return t;
398
+ }
70
399
  async enable(t) {
71
400
  const e = this.plugins.get(t);
72
401
  if (!e)
@@ -75,14 +404,9 @@ class b {
75
404
  this.logger.warn(`Plugin '${t}' is already enabled`);
76
405
  return;
77
406
  }
78
- try {
79
- const i = this.createPluginContext(t), n = this.pluginConfigs.get(t);
80
- await e.initialize(i, n), await e.activate(i), this.enabledPlugins.add(t), this.logger.info(`Plugin '${t}' enabled successfully`), this.eventBus.emit("plugin:enabled", { name: t, plugin: e });
81
- } catch (i) {
82
- throw this.logger.error(`Failed to enable plugin '${t}'`, i), this.eventBus.emit("plugin:error", { name: t, error: i }), i;
83
- }
407
+ const i = this.pluginContexts.get(t) || this.createPluginContext(t);
408
+ e.isInitialized || await this.initialize(t, i), await this.activate(t, i);
84
409
  }
85
- // Disable a plugin
86
410
  async disable(t) {
87
411
  const e = this.plugins.get(t);
88
412
  if (!e)
@@ -91,14 +415,9 @@ class b {
91
415
  this.logger.warn(`Plugin '${t}' is already disabled`);
92
416
  return;
93
417
  }
94
- try {
95
- const i = this.createPluginContext(t);
96
- await e.deactivate(i), await e.destroy(i), this.enabledPlugins.delete(t), this.logger.info(`Plugin '${t}' disabled successfully`), this.eventBus.emit("plugin:disabled", { name: t, plugin: e });
97
- } catch (i) {
98
- throw this.logger.error(`Failed to disable plugin '${t}'`, i), this.eventBus.emit("plugin:error", { name: t, error: i }), i;
99
- }
418
+ const i = this.pluginContexts.get(t) || this.createPluginContext(t);
419
+ await this.deactivate(t, i), await e.destroy(i);
100
420
  }
101
- // Configure a plugin
102
421
  async configure(t, e) {
103
422
  const i = this.plugins.get(t);
104
423
  if (!i)
@@ -109,41 +428,67 @@ class b {
109
428
  throw this.logger.error(`Failed to configure plugin '${t}'`, n), this.eventBus.emit("plugin:error", { name: t, error: n }), n;
110
429
  }
111
430
  }
112
- // Enable multiple plugins with dependency resolution
113
431
  async enablePlugins(t) {
114
432
  const e = this.resolveDependencies(t);
115
433
  for (const i of e)
116
434
  this.enabledPlugins.has(i) || await this.enable(i);
117
435
  }
118
- // Disable multiple plugins
119
436
  async disablePlugins(t) {
120
437
  const e = [...t].reverse();
121
438
  for (const i of e)
122
439
  this.enabledPlugins.has(i) && await this.disable(i);
123
440
  }
124
- // Get enabled plugins
125
441
  getEnabledPlugins() {
126
- return Array.from(this.enabledPlugins).map((t) => this.plugins.get(t)).filter(Boolean).sort(this.sortByPriority);
442
+ return this.getActive();
443
+ }
444
+ on(t, e) {
445
+ return this.eventBus.on(t, e), () => this.eventBus.off(t, e);
127
446
  }
128
- // Health check for all enabled plugins
129
- async healthCheck() {
447
+ async healthCheckEnabledPlugins() {
130
448
  const t = [];
131
449
  for (const e of this.enabledPlugins) {
132
450
  const i = this.plugins.get(e);
133
- try {
134
- const n = i.healthCheck ? await i.healthCheck() : !0;
135
- t.push({ name: e, healthy: n });
136
- } catch (n) {
137
- t.push({ name: e, healthy: !1, error: n });
138
- }
451
+ if (i)
452
+ try {
453
+ const n = i.healthCheck ? i.healthCheck() : !0, s = n instanceof Promise ? await n : !!n;
454
+ t.push({ name: e, healthy: s });
455
+ } catch (n) {
456
+ t.push({ name: e, healthy: !1, error: n });
457
+ }
139
458
  }
140
459
  return t;
141
460
  }
142
- // Event handling
143
- on(t, e) {
144
- return this.eventBus.on(t, e), () => this.eventBus.off(t, e);
461
+ findPluginKey(t) {
462
+ for (const [e, i] of this.plugins.entries())
463
+ if (i === t) return e;
464
+ }
465
+ ensureDependenciesExist(t) {
466
+ const e = this.plugins.get(t);
467
+ if (!e) return;
468
+ const i = (e.metadata.dependencies || []).filter(
469
+ (n) => !this.plugins.has(n)
470
+ );
471
+ if (i.length > 0)
472
+ throw new h(t, i);
473
+ }
474
+ ensureDependenciesActive(t) {
475
+ const e = this.plugins.get(t);
476
+ if (!e) return;
477
+ const i = (e.metadata.dependencies || []).filter(
478
+ (n) => !this.enabledPlugins.has(n)
479
+ );
480
+ if (i.length > 0)
481
+ throw new h(t, i);
482
+ }
483
+ ensureNoActiveConflicts(t) {
484
+ const e = this.plugins.get(t);
485
+ if (!e) return;
486
+ const i = (e.metadata.conflicts || []).filter(
487
+ (n) => this.enabledPlugins.has(n)
488
+ );
489
+ if (i.length > 0)
490
+ throw new f(t, i);
145
491
  }
146
- // Create plugin context (will be implemented when we have the full context)
147
492
  createPluginContext(t) {
148
493
  return {
149
494
  state: {},
@@ -155,7 +500,6 @@ class b {
155
500
  logger: this.createPluginLogger(t)
156
501
  };
157
502
  }
158
- // Create plugin-specific logger
159
503
  createPluginLogger(t) {
160
504
  return {
161
505
  info: (e, i) => this.logger.info(`[${t}] ${e}`, i),
@@ -164,41 +508,40 @@ class b {
164
508
  debug: (e, i) => this.logger.debug(`[${t}] ${e}`, i)
165
509
  };
166
510
  }
167
- // Resolve plugin dependencies
168
511
  resolveDependencies(t) {
169
512
  const e = [], i = /* @__PURE__ */ new Set(), n = (s) => {
170
513
  if (e.includes(s)) return;
171
514
  if (i.has(s))
172
515
  throw new l(s, "initialize", "Circular dependency detected");
173
516
  i.add(s);
174
- const c = this.plugins.get(s);
175
- if (!c)
517
+ const o = this.plugins.get(s);
518
+ if (!o)
176
519
  throw new l(s, "initialize", "Plugin not found");
177
- for (const u of c.metadata.dependencies || [])
178
- n(u);
520
+ for (const c of o.metadata.dependencies || [])
521
+ n(c);
179
522
  i.delete(s), e.push(s);
180
523
  };
181
524
  for (const s of t)
182
525
  n(s);
183
526
  return e;
184
527
  }
185
- // Sort plugins by priority
186
528
  sortByPriority(t, e) {
187
529
  const i = {
188
530
  high: 3,
189
531
  medium: 2,
532
+ normal: 2,
190
533
  low: 1
191
- };
192
- return i[e.metadata.priority] - i[t.metadata.priority];
534
+ }, n = i[t.metadata.priority] || 1;
535
+ return (i[e.metadata.priority] || 1) - n;
193
536
  }
194
537
  }
195
538
  class m {
196
539
  constructor(t) {
197
- o(this, "metadata");
198
- o(this, "context");
199
- o(this, "config", {});
200
- o(this, "initialized", !1);
201
- o(this, "active", !1);
540
+ a(this, "metadata");
541
+ a(this, "context");
542
+ a(this, "config", {});
543
+ a(this, "initialized", !1);
544
+ a(this, "active", !1);
202
545
  this.metadata = {
203
546
  version: "1.0.0",
204
547
  ...t
@@ -309,10 +652,10 @@ class m {
309
652
  return this.active;
310
653
  }
311
654
  }
312
- function k(r) {
655
+ function B(r) {
313
656
  return (t) => new r(t);
314
657
  }
315
- class P extends m {
658
+ class C extends m {
316
659
  constructor(e) {
317
660
  super({
318
661
  name: "analytics",
@@ -321,10 +664,10 @@ class P extends m {
321
664
  priority: "low",
322
665
  author: "BaroiPlayer Team"
323
666
  });
324
- o(this, "events", []);
325
- o(this, "analyticsConfig");
326
- o(this, "cleanupFunctions", []);
327
- o(this, "reportTimer");
667
+ a(this, "events", []);
668
+ a(this, "analyticsConfig");
669
+ a(this, "cleanupFunctions", []);
670
+ a(this, "reportTimer");
328
671
  }
329
672
  onInitialize() {
330
673
  if (this.analyticsConfig = this.createConfig({
@@ -456,231 +799,23 @@ class P extends m {
456
799
  return this.events.length < 1e3;
457
800
  }
458
801
  }
459
- const x = (r) => new P(r);
460
- class d {
461
- constructor(t = "[Plugin]") {
462
- o(this, "prefix");
463
- this.prefix = t;
464
- }
465
- info(t, e) {
466
- e ? console.info(`${this.prefix} ${t}`, e) : console.info(`${this.prefix} ${t}`);
467
- }
468
- warn(t, e) {
469
- e ? console.warn(`${this.prefix} ${t}`, e) : console.warn(`${this.prefix} ${t}`);
470
- }
471
- error(t, e) {
472
- e ? console.error(`${this.prefix} ${t}`, e) : console.error(`${this.prefix} ${t}`);
473
- }
474
- debug(t, e) {
475
- process.env.NODE_ENV === "development" && (e ? console.debug(`${this.prefix} ${t}`, e) : console.debug(`${this.prefix} ${t}`));
476
- }
477
- }
478
- class z {
479
- static validateMetadata(t) {
480
- const { metadata: e } = t;
481
- if (!e.name || typeof e.name != "string")
482
- throw new Error("Plugin metadata must include a valid name");
483
- if (!e.version || typeof e.version != "string")
484
- throw new Error("Plugin metadata must include a valid version");
485
- if (!e.description || typeof e.description != "string")
486
- throw new Error("Plugin metadata must include a valid description");
487
- if (!e.category)
488
- throw new Error("Plugin metadata must include a valid category");
489
- if (!e.priority)
490
- throw new Error("Plugin metadata must include a valid priority");
491
- return !0;
492
- }
493
- static validateConfig(t, e) {
494
- if (!e) return !0;
495
- for (const [i, n] of Object.entries(e)) {
496
- const s = t[i];
497
- if (n.required && s == null)
498
- throw new Error(`Configuration property '${i}' is required`);
499
- if (s !== void 0 && n.type && typeof s !== n.type)
500
- throw new Error(`Configuration property '${i}' must be of type '${n.type}'`);
501
- if (n.enum && !n.enum.includes(s))
502
- throw new Error(`Configuration property '${i}' must be one of: ${n.enum.join(", ")}`);
503
- if (n.min !== void 0 && typeof s == "number" && s < n.min)
504
- throw new Error(`Configuration property '${i}' must be at least ${n.min}`);
505
- if (n.max !== void 0 && typeof s == "number" && s > n.max)
506
- throw new Error(`Configuration property '${i}' must be at most ${n.max}`);
507
- }
508
- return !0;
509
- }
510
- }
511
- class $ {
512
- constructor() {
513
- o(this, "metrics", /* @__PURE__ */ new Map());
514
- }
515
- measure(t, e, i) {
516
- const n = `${t}.${e}`, s = performance.now(), c = () => {
517
- const a = performance.now(), h = a - s, g = this.metrics.get(n) || {
518
- calls: 0,
519
- totalTime: 0,
520
- averageTime: 0,
521
- lastCall: 0
522
- };
523
- g.calls++, g.totalTime += h, g.averageTime = g.totalTime / g.calls, g.lastCall = a, this.metrics.set(n, g);
524
- }, u = i();
525
- return u instanceof Promise ? u.then(
526
- (a) => (c(), a),
527
- (a) => {
528
- throw c(), a;
529
- }
530
- ) : (c(), u);
531
- }
532
- getMetrics(t) {
533
- if (t) {
534
- const e = {};
535
- for (const [i, n] of this.metrics.entries())
536
- if (i.startsWith(`${t}.`)) {
537
- const s = i.substring(t.length + 1);
538
- e[s] = n;
539
- }
540
- return e;
541
- }
542
- return Object.fromEntries(this.metrics.entries());
543
- }
544
- reset(t) {
545
- if (t)
546
- for (const e of this.metrics.keys())
547
- e.startsWith(`${t}.`) && this.metrics.delete(e);
548
- else
549
- this.metrics.clear();
550
- }
551
- }
552
- const F = {
553
- // Create a mock plugin context for testing
554
- createMockContext() {
555
- return {
556
- state: {
557
- isPlaying: !1,
558
- currentTime: 0,
559
- duration: 0,
560
- volume: 1,
561
- isMuted: !1,
562
- isLoading: !1,
563
- error: null
564
- },
565
- controls: {
566
- play: () => Promise.resolve(),
567
- pause: () => Promise.resolve(),
568
- seek: (r) => Promise.resolve(),
569
- setVolume: (r) => Promise.resolve(),
570
- mute: () => Promise.resolve(),
571
- unmute: () => Promise.resolve(),
572
- toggleMute: () => Promise.resolve()
573
- },
574
- plugins: {
575
- get: () => {
576
- },
577
- getAll: () => [],
578
- isEnabled: () => !1
579
- },
580
- emit: () => {
581
- },
582
- on: () => () => {
583
- },
584
- element: null,
585
- logger: new d("[MockPlugin]")
586
- };
587
- },
588
- // Create a test plugin for development
589
- createTestPlugin(r, t = {}) {
590
- return {
591
- metadata: {
592
- name: r,
593
- version: "1.0.0",
594
- description: `Test plugin: ${r}`,
595
- category: "ui",
596
- priority: "medium"
597
- },
598
- initialize: async () => {
599
- },
600
- activate: async () => {
601
- },
602
- deactivate: async () => {
603
- },
604
- destroy: async () => {
605
- },
606
- healthCheck: () => !0,
607
- ...t
608
- };
609
- },
610
- // Plugin timing utilities
611
- time: {
612
- async: async (r, t) => {
613
- console.time(r);
614
- try {
615
- const e = await t();
616
- return console.timeEnd(r), e;
617
- } catch (e) {
618
- throw console.timeEnd(r), e;
619
- }
620
- },
621
- sync: (r, t) => {
622
- console.time(r);
623
- try {
624
- const e = t();
625
- return console.timeEnd(r), e;
626
- } catch (e) {
627
- throw console.timeEnd(r), e;
628
- }
629
- }
630
- }
631
- };
632
- class I {
633
- constructor(t) {
634
- o(this, "prefix");
635
- this.prefix = `baroi-plugin-${t}`;
636
- }
637
- get(t, e) {
638
- try {
639
- const i = localStorage.getItem(`${this.prefix}-${t}`);
640
- return i ? JSON.parse(i) : e;
641
- } catch {
642
- return e;
643
- }
644
- }
645
- set(t, e) {
646
- try {
647
- localStorage.setItem(`${this.prefix}-${t}`, JSON.stringify(e));
648
- } catch (i) {
649
- console.warn(`Failed to store plugin data for key: ${t}`, i);
650
- }
651
- }
652
- remove(t) {
653
- try {
654
- localStorage.removeItem(`${this.prefix}-${t}`);
655
- } catch (e) {
656
- console.warn(`Failed to remove plugin data for key: ${t}`, e);
657
- }
658
- }
659
- clear() {
660
- try {
661
- Object.keys(localStorage).filter((e) => e.startsWith(`${this.prefix}-`)).forEach((e) => localStorage.removeItem(e));
662
- } catch (t) {
663
- console.warn("Failed to clear plugin data", t);
664
- }
665
- }
666
- }
667
- const B = new d(), M = new $(), T = "1.0.0";
802
+ const F = (r) => new C(r), D = "1.0.0";
668
803
  export {
669
- P as A,
804
+ C as A,
670
805
  m as B,
671
806
  d as C,
672
- b as P,
673
- T as a,
807
+ I as P,
808
+ D as a,
674
809
  l as b,
675
- v as c,
676
- w as d,
677
- k as e,
678
- x as f,
679
- z as g,
680
- $ as h,
681
- F as i,
682
- I as j,
683
- B as k,
684
- M as l
810
+ h as c,
811
+ f as d,
812
+ B as e,
813
+ F as f,
814
+ b as g,
815
+ P as h,
816
+ k as i,
817
+ x as j,
818
+ z as k,
819
+ A as l
685
820
  };
686
- //# sourceMappingURL=core-plugins-CROGvQUy.js.map
821
+ //# sourceMappingURL=core-plugins-DSBWcTuX.js.map