@therealtinhtute/baroiplayer 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/media.js +2 -0
- package/dist/context/media.js.map +1 -0
- package/dist/context/media.mjs +15 -0
- package/dist/context/media.mjs.map +1 -0
- package/dist/context/store.js +2 -0
- package/dist/context/store.js.map +1 -0
- package/dist/context/store.mjs +5 -0
- package/dist/context/store.mjs.map +1 -0
- package/dist/context-Af84FynT.js +1179 -0
- package/dist/context-Af84FynT.js.map +1 -0
- package/dist/context-CwZnPdz0.cjs +23 -0
- package/dist/context-CwZnPdz0.cjs.map +1 -0
- package/dist/core-events-B5W_j8yU.js +480 -0
- package/dist/core-events-B5W_j8yU.js.map +1 -0
- package/dist/core-events-CN0-Vhhq.cjs +2 -0
- package/dist/core-events-CN0-Vhhq.cjs.map +1 -0
- package/dist/core-plugins-Bq9KLany.js +696 -0
- package/dist/core-plugins-Bq9KLany.js.map +1 -0
- package/dist/core-plugins-CPDSHMiQ.cjs +2 -0
- package/dist/core-plugins-CPDSHMiQ.cjs.map +1 -0
- package/dist/core.js +37 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +1217 -0
- package/dist/core.mjs.map +1 -0
- package/dist/enhanced-components-CXnYiOt6.cjs +2 -0
- package/dist/enhanced-components-CXnYiOt6.cjs.map +1 -0
- package/dist/enhanced-components-Da0TSvKe.js +1073 -0
- package/dist/enhanced-components-Da0TSvKe.js.map +1 -0
- package/dist/hooks-BhW_i-9L.js +2013 -0
- package/dist/hooks-BhW_i-9L.js.map +1 -0
- package/dist/hooks-DTXeB5Z-.cjs +4 -0
- package/dist/hooks-DTXeB5Z-.cjs.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -0
- package/dist/index.mjs.map +1 -0
- package/dist/minimal-components-B0bILe18.js +2002 -0
- package/dist/minimal-components-B0bILe18.js.map +1 -0
- package/dist/minimal-components-BsqodtY8.cjs +2 -0
- package/dist/minimal-components-BsqodtY8.cjs.map +1 -0
- package/dist/minimal-components.css +589 -0
- package/dist/mona-loading.gif +0 -0
- package/dist/performance-monitor--rzKTlbj.js +302 -0
- package/dist/performance-monitor--rzKTlbj.js.map +1 -0
- package/dist/performance-monitor-cjIvZE2D.cjs +2 -0
- package/dist/performance-monitor-cjIvZE2D.cjs.map +1 -0
- package/dist/src/components/AnimateLoading.tsx +1 -1
- package/dist/src/components/enhanced/debug-panel.tsx +1 -1
- package/dist/src/components/media-player.tsx +2 -2
- package/dist/src/components/ui/media-resource-preloader.tsx +9 -11
- package/dist/src/components/ui/seek-bar.tsx +1 -1
- package/dist/src/core/plugins/enhanced-plugin-system.ts +14 -8
- package/dist/src/core/providers/enhanced-hls-provider.ts +22 -53
- package/dist/src/hooks/use-enhanced-media-player.ts +19 -2
- package/dist/src/types/index.ts +40 -5
- package/dist/styles/minimal-player.css +589 -0
- package/dist/utils-Db13763z.cjs +9 -0
- package/dist/utils-Db13763z.cjs.map +1 -0
- package/dist/utils-nTO4AnHo.js +2809 -0
- package/dist/utils-nTO4AnHo.js.map +1 -0
- package/dist/utils.js +2 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +7 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +1 -1
- package/src/components/AnimateLoading.tsx +1 -1
- package/src/components/enhanced/debug-panel.tsx +1 -1
- package/src/components/media-player.tsx +2 -2
- package/src/components/ui/media-resource-preloader.tsx +9 -11
- package/src/components/ui/seek-bar.tsx +1 -1
- package/src/core/plugins/enhanced-plugin-system.ts +14 -8
- package/src/core/providers/enhanced-hls-provider.ts +22 -53
- package/src/hooks/use-enhanced-media-player.ts +19 -2
- package/src/types/index.ts +40 -5
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
var v = Object.defineProperty;
|
|
2
|
+
var T = (s, e, t) => e in s ? v(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var a = (s, e, t) => T(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { useRef as m, useEffect as d, useCallback as p, useMemo as H, useState as x } from "react";
|
|
5
|
+
class E {
|
|
6
|
+
constructor() {
|
|
7
|
+
a(this, "listeners", /* @__PURE__ */ new Map());
|
|
8
|
+
a(this, "eventQueue", []);
|
|
9
|
+
a(this, "isProcessing", !1);
|
|
10
|
+
a(this, "middlewares", []);
|
|
11
|
+
a(this, "eventHistory", []);
|
|
12
|
+
a(this, "maxHistorySize", 1e3);
|
|
13
|
+
}
|
|
14
|
+
// Subscribe to events
|
|
15
|
+
on(e, t, r = {}) {
|
|
16
|
+
return this.addEventListener(e, t, r);
|
|
17
|
+
}
|
|
18
|
+
// Subscribe to events (one-time)
|
|
19
|
+
once(e, t, r = {}) {
|
|
20
|
+
return this.addEventListener(e, t, { ...r, once: !0 });
|
|
21
|
+
}
|
|
22
|
+
// Subscribe to events with wildcard support
|
|
23
|
+
addEventListener(e, t, r = {}) {
|
|
24
|
+
const n = this.generateId(), o = { handler: t, options: r, id: n };
|
|
25
|
+
this.listeners.has(e) || this.listeners.set(e, []);
|
|
26
|
+
const i = this.listeners.get(e), u = r.priority || "normal", l = { high: 2, normal: 1, low: 0 }[u];
|
|
27
|
+
let h = i.length;
|
|
28
|
+
for (let c = 0; c < i.length; c++) {
|
|
29
|
+
const g = i[c];
|
|
30
|
+
if (!g) continue;
|
|
31
|
+
const w = g.options.priority || "normal";
|
|
32
|
+
if (l > { high: 2, normal: 1, low: 0 }[w]) {
|
|
33
|
+
h = c;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return i.splice(h, 0, o), () => {
|
|
38
|
+
const c = i.findIndex((g) => g.id === n);
|
|
39
|
+
c !== -1 && i.splice(c, 1), i.length === 0 && this.listeners.delete(e);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// Remove event listener
|
|
43
|
+
removeEventListener(e, t) {
|
|
44
|
+
const r = this.listeners.get(e);
|
|
45
|
+
if (r) {
|
|
46
|
+
if (t) {
|
|
47
|
+
const n = r.findIndex((o) => o.handler === t);
|
|
48
|
+
n !== -1 && r.splice(n, 1);
|
|
49
|
+
} else
|
|
50
|
+
this.listeners.delete(e);
|
|
51
|
+
r && r.length === 0 && this.listeners.delete(e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Emit events
|
|
55
|
+
emit(e, t, r) {
|
|
56
|
+
const n = {
|
|
57
|
+
type: e,
|
|
58
|
+
timestamp: Date.now(),
|
|
59
|
+
detail: t,
|
|
60
|
+
bubbles: !0,
|
|
61
|
+
cancelable: !0,
|
|
62
|
+
defaultPrevented: !1,
|
|
63
|
+
...r
|
|
64
|
+
};
|
|
65
|
+
return this.dispatchEvent(n);
|
|
66
|
+
}
|
|
67
|
+
// Dispatch event
|
|
68
|
+
dispatchEvent(e) {
|
|
69
|
+
let t = e;
|
|
70
|
+
for (const r of this.middlewares)
|
|
71
|
+
if (t = r(t), !t)
|
|
72
|
+
return !1;
|
|
73
|
+
return this.addToHistory(t), this.eventQueue.push(t), this.isProcessing || this.processEventQueue(), !t.defaultPrevented;
|
|
74
|
+
}
|
|
75
|
+
// Process event queue with React 19 concurrent scheduling
|
|
76
|
+
processEventQueue() {
|
|
77
|
+
if (this.isProcessing) return;
|
|
78
|
+
this.isProcessing = !0;
|
|
79
|
+
const e = typeof window < "u" && "scheduler" in window ? window.scheduler.postTask : (r) => setTimeout(r, 0), t = () => {
|
|
80
|
+
if (this.eventQueue.length === 0) {
|
|
81
|
+
this.isProcessing = !1;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const r = Math.min(this.eventQueue.length, 5), n = this.eventQueue.splice(0, r);
|
|
85
|
+
Promise.all(n.map((o) => this.processEvent(o).catch(console.error))).then(() => {
|
|
86
|
+
e(t);
|
|
87
|
+
}).catch(() => {
|
|
88
|
+
this.isProcessing = !1;
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
e(t);
|
|
92
|
+
}
|
|
93
|
+
// Process individual event
|
|
94
|
+
async processEvent(e) {
|
|
95
|
+
const { type: t } = e, r = this.listeners.get(t) || [], n = [];
|
|
96
|
+
for (const [u, l] of this.listeners.entries())
|
|
97
|
+
u.includes("*") && this.matchPattern(t, u) && n.push(...l);
|
|
98
|
+
const o = [...r, ...n].sort((u, l) => {
|
|
99
|
+
const h = { high: 2, normal: 1, low: 0 }[u.options.priority || "normal"];
|
|
100
|
+
return { high: 2, normal: 1, low: 0 }[l.options.priority || "normal"] - h;
|
|
101
|
+
}), i = [];
|
|
102
|
+
for (const u of o)
|
|
103
|
+
if (!(u.options.filter && !u.options.filter(e)))
|
|
104
|
+
try {
|
|
105
|
+
if (await Promise.resolve(u.handler(e)), u.options.once && i.push(u.id), e.defaultPrevented && !e.bubbles)
|
|
106
|
+
break;
|
|
107
|
+
} catch (l) {
|
|
108
|
+
console.error(`Error in event handler for ${t}:`, l), console.error(`Event handler error for ${t}:`, l);
|
|
109
|
+
}
|
|
110
|
+
for (const u of i)
|
|
111
|
+
for (const [l, h] of this.listeners.entries()) {
|
|
112
|
+
const c = h.findIndex((g) => g.id === u);
|
|
113
|
+
if (c !== -1) {
|
|
114
|
+
h.splice(c, 1), h.length === 0 && this.listeners.delete(l);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Add middleware
|
|
120
|
+
use(e) {
|
|
121
|
+
return this.middlewares.push(e), () => {
|
|
122
|
+
const t = this.middlewares.indexOf(e);
|
|
123
|
+
t !== -1 && this.middlewares.splice(t, 1);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// Event history management
|
|
127
|
+
addToHistory(e) {
|
|
128
|
+
this.eventHistory.push(e), this.eventHistory.length > this.maxHistorySize && this.eventHistory.shift();
|
|
129
|
+
}
|
|
130
|
+
// Get event history
|
|
131
|
+
getHistory(e) {
|
|
132
|
+
return e ? this.eventHistory.filter(e) : [...this.eventHistory];
|
|
133
|
+
}
|
|
134
|
+
// Clear event history
|
|
135
|
+
clearHistory() {
|
|
136
|
+
this.eventHistory = [];
|
|
137
|
+
}
|
|
138
|
+
// Pattern matching for wildcards
|
|
139
|
+
matchPattern(e, t) {
|
|
140
|
+
return new RegExp(
|
|
141
|
+
"^" + t.replace(/\*/g, ".*").replace(/\?/g, ".") + "$"
|
|
142
|
+
).test(e);
|
|
143
|
+
}
|
|
144
|
+
// Generate unique ID
|
|
145
|
+
generateId() {
|
|
146
|
+
return `event_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
147
|
+
}
|
|
148
|
+
// Get listener count
|
|
149
|
+
getListenerCount(e) {
|
|
150
|
+
return e ? this.listeners.get(e)?.length || 0 : Array.from(this.listeners.values()).reduce((t, r) => t + r.length, 0);
|
|
151
|
+
}
|
|
152
|
+
// Get all event types
|
|
153
|
+
getEventTypes() {
|
|
154
|
+
return Array.from(this.listeners.keys());
|
|
155
|
+
}
|
|
156
|
+
// Clear all listeners
|
|
157
|
+
removeAllListeners(e) {
|
|
158
|
+
e ? this.listeners.delete(e) : this.listeners.clear();
|
|
159
|
+
}
|
|
160
|
+
// Destroy event bus
|
|
161
|
+
destroy() {
|
|
162
|
+
this.listeners.clear(), this.eventQueue = [], this.middlewares = [], this.eventHistory = [], this.isProcessing = !1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const k = new E();
|
|
166
|
+
class S {
|
|
167
|
+
constructor(e, t) {
|
|
168
|
+
a(this, "eventBus");
|
|
169
|
+
a(this, "element");
|
|
170
|
+
a(this, "delegatedEvents", /* @__PURE__ */ new Set());
|
|
171
|
+
this.eventBus = e, this.element = t;
|
|
172
|
+
}
|
|
173
|
+
// Delegate DOM events to event bus
|
|
174
|
+
delegate(e, t) {
|
|
175
|
+
if (this.delegatedEvents.has(e)) return;
|
|
176
|
+
const r = (n) => {
|
|
177
|
+
this.eventBus.emit(t || `dom:${e}`, {
|
|
178
|
+
originalEvent: n,
|
|
179
|
+
target: n.target?.tagName.toLowerCase(),
|
|
180
|
+
currentTarget: n.currentTarget?.tagName.toLowerCase()
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
this.element.addEventListener(e, r, { passive: !0 }), this.delegatedEvents.add(e);
|
|
184
|
+
}
|
|
185
|
+
// Setup common delegations
|
|
186
|
+
setupCommonDelegations() {
|
|
187
|
+
this.delegate("click", "user:click"), this.delegate("mouseenter", "user:hover"), this.delegate("mouseleave", "user:hover"), this.delegate("focus", "user:focus"), this.delegate("blur", "user:focus"), this.delegate("keydown", "user:keyboard"), this.delegate("keyup", "user:keyboard");
|
|
188
|
+
}
|
|
189
|
+
destroy() {
|
|
190
|
+
this.delegatedEvents.clear();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const f = {
|
|
194
|
+
// Logging middleware
|
|
195
|
+
logger: (s = "[Event]") => (e) => (process.env.NODE_ENV === "development" && console.log(`${s} ${e.type}`, e.detail), e),
|
|
196
|
+
// Throttling middleware
|
|
197
|
+
throttle: (s, e = 100) => {
|
|
198
|
+
const t = /* @__PURE__ */ new Map();
|
|
199
|
+
return (r) => {
|
|
200
|
+
if (s.includes(r.type)) {
|
|
201
|
+
const n = t.get(r.type) || 0, o = r.timestamp;
|
|
202
|
+
if (o - n < e)
|
|
203
|
+
return null;
|
|
204
|
+
t.set(r.type, o);
|
|
205
|
+
}
|
|
206
|
+
return r;
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
// Debouncing middleware
|
|
210
|
+
debounce: (s, e = 100) => {
|
|
211
|
+
const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
|
|
212
|
+
return (n) => {
|
|
213
|
+
if (s.includes(n.type)) {
|
|
214
|
+
const o = t.get(n.type);
|
|
215
|
+
o && clearTimeout(o), r.set(n.type, n);
|
|
216
|
+
const i = setTimeout(() => {
|
|
217
|
+
r.get(n.type) && (r.delete(n.type), t.delete(n.type));
|
|
218
|
+
}, e);
|
|
219
|
+
return t.set(n.type, i), null;
|
|
220
|
+
}
|
|
221
|
+
return n;
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
// Filtering middleware
|
|
225
|
+
filter: (s) => (e) => s(e) ? e : null,
|
|
226
|
+
// Event transformation middleware
|
|
227
|
+
transform: (s) => (e) => {
|
|
228
|
+
try {
|
|
229
|
+
return s(e);
|
|
230
|
+
} catch (t) {
|
|
231
|
+
return console.error("Error in event transformer:", t), e;
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
// Performance monitoring middleware
|
|
235
|
+
performance: () => {
|
|
236
|
+
const s = /* @__PURE__ */ new Map();
|
|
237
|
+
return (e) => {
|
|
238
|
+
const t = performance.now(), r = s.get(e.type) || { count: 0, totalTime: 0 };
|
|
239
|
+
if (r.count++, r.totalTime += performance.now() - t, s.set(e.type, r), r.count % 100 === 0) {
|
|
240
|
+
const n = r.totalTime / r.count;
|
|
241
|
+
console.log(`Event ${e.type}: ${r.count} calls, avg ${n.toFixed(2)}ms`);
|
|
242
|
+
}
|
|
243
|
+
return e;
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
// Error handling middleware
|
|
247
|
+
errorHandler: (s) => (e) => {
|
|
248
|
+
try {
|
|
249
|
+
if (!e.type || typeof e.type != "string")
|
|
250
|
+
throw new Error("Invalid event: missing or invalid type");
|
|
251
|
+
if (!e.timestamp || typeof e.timestamp != "number")
|
|
252
|
+
throw new Error("Invalid event: missing or invalid timestamp");
|
|
253
|
+
return e;
|
|
254
|
+
} catch (t) {
|
|
255
|
+
return s ? s(t, e) : console.error("Event validation error:", t), null;
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
// Security middleware (prevent certain events or sanitize data)
|
|
259
|
+
security: (s = {}) => (e) => {
|
|
260
|
+
const { blockedEventTypes: t = [], sanitizeDetail: r = !0, maxDetailSize: n = 1e4 } = s;
|
|
261
|
+
if (t.includes(e.type))
|
|
262
|
+
return console.warn(`Blocked event type: ${e.type}`), null;
|
|
263
|
+
if (r && e.detail)
|
|
264
|
+
try {
|
|
265
|
+
JSON.stringify(e.detail).length > n && (console.warn(`Event detail too large, truncating: ${e.type}`), e.detail = { ...e.detail, _truncated: !0 });
|
|
266
|
+
} catch {
|
|
267
|
+
console.warn(`Failed to serialize event detail: ${e.type}`), e.detail = { _serializationError: !0 };
|
|
268
|
+
}
|
|
269
|
+
return e;
|
|
270
|
+
},
|
|
271
|
+
// Conditional middleware
|
|
272
|
+
when: (s, e) => (t) => s(t) ? e(t) : t,
|
|
273
|
+
// Chain multiple middleware
|
|
274
|
+
chain: (...s) => (e) => {
|
|
275
|
+
let t = e;
|
|
276
|
+
for (const r of s) {
|
|
277
|
+
if (t === null) break;
|
|
278
|
+
t = r(t);
|
|
279
|
+
}
|
|
280
|
+
return t;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
class L {
|
|
284
|
+
constructor() {
|
|
285
|
+
a(this, "middlewares", []);
|
|
286
|
+
}
|
|
287
|
+
// Add middleware
|
|
288
|
+
use(e) {
|
|
289
|
+
return this.middlewares.push(e), this;
|
|
290
|
+
}
|
|
291
|
+
// Add logging
|
|
292
|
+
log(e) {
|
|
293
|
+
return this.use(f.logger(e));
|
|
294
|
+
}
|
|
295
|
+
// Add throttling
|
|
296
|
+
throttle(e, t) {
|
|
297
|
+
return this.use(f.throttle(e, t));
|
|
298
|
+
}
|
|
299
|
+
// Add debouncing
|
|
300
|
+
debounce(e, t) {
|
|
301
|
+
return this.use(f.debounce(e, t));
|
|
302
|
+
}
|
|
303
|
+
// Add filtering
|
|
304
|
+
filter(e) {
|
|
305
|
+
return this.use(f.filter(e));
|
|
306
|
+
}
|
|
307
|
+
// Add transformation
|
|
308
|
+
transform(e) {
|
|
309
|
+
return this.use(f.transform(e));
|
|
310
|
+
}
|
|
311
|
+
// Add performance monitoring
|
|
312
|
+
performance() {
|
|
313
|
+
return this.use(f.performance());
|
|
314
|
+
}
|
|
315
|
+
// Add error handling
|
|
316
|
+
errorHandler(e) {
|
|
317
|
+
return this.use(f.errorHandler(e));
|
|
318
|
+
}
|
|
319
|
+
// Add security
|
|
320
|
+
security(e) {
|
|
321
|
+
return this.use(f.security(e));
|
|
322
|
+
}
|
|
323
|
+
// Add conditional middleware
|
|
324
|
+
when(e, t) {
|
|
325
|
+
return this.use(f.when(e, t));
|
|
326
|
+
}
|
|
327
|
+
// Build the final middleware
|
|
328
|
+
build() {
|
|
329
|
+
return f.chain(...this.middlewares);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const y = () => new L(), P = {
|
|
333
|
+
// Development middleware stack
|
|
334
|
+
development: () => y().log("[Dev Event]").performance().errorHandler().build(),
|
|
335
|
+
// Production middleware stack
|
|
336
|
+
production: () => y().security().errorHandler().throttle(["media:timeupdate", "user:mousemove"], 16).build(),
|
|
337
|
+
// Testing middleware stack
|
|
338
|
+
testing: () => y().errorHandler((s, e) => {
|
|
339
|
+
throw new Error(`Event error in test: ${s.message} for event ${e.type}`);
|
|
340
|
+
}).build()
|
|
341
|
+
};
|
|
342
|
+
function D(s) {
|
|
343
|
+
const e = m(null);
|
|
344
|
+
return e.current || (e.current = s || new E()), d(() => {
|
|
345
|
+
const t = e.current;
|
|
346
|
+
return () => {
|
|
347
|
+
t.destroy();
|
|
348
|
+
};
|
|
349
|
+
}, []), e.current;
|
|
350
|
+
}
|
|
351
|
+
function b(s, e, t, r, n) {
|
|
352
|
+
const o = m(t), i = m(r);
|
|
353
|
+
d(() => {
|
|
354
|
+
o.current = t, i.current = r;
|
|
355
|
+
}), d(() => s.on(e, o.current, i.current), [s, e, ...n || []]);
|
|
356
|
+
}
|
|
357
|
+
function I(s) {
|
|
358
|
+
return p((e, t, r) => s.emit(e, t, r), [s]);
|
|
359
|
+
}
|
|
360
|
+
function R(s, e, t, r) {
|
|
361
|
+
b(s, e, t, { once: !0 }, r);
|
|
362
|
+
}
|
|
363
|
+
function C(s) {
|
|
364
|
+
const e = m([]), t = p((n, o, i) => {
|
|
365
|
+
const u = s.on(n, o, i);
|
|
366
|
+
return e.current.push(u), u;
|
|
367
|
+
}, [s]), r = p(() => {
|
|
368
|
+
e.current.forEach((n) => n()), e.current = [];
|
|
369
|
+
}, []);
|
|
370
|
+
return d(() => r, [r]), {
|
|
371
|
+
on: t,
|
|
372
|
+
removeAll: r
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function Q(s, e, t = 100) {
|
|
376
|
+
const r = m([]);
|
|
377
|
+
d(() => s.addEventListener("*", (i) => {
|
|
378
|
+
(!e || e(i)) && (r.current.push(i), r.current.length > t && r.current.shift());
|
|
379
|
+
}), [s, e, t]);
|
|
380
|
+
const n = p(() => {
|
|
381
|
+
r.current = [];
|
|
382
|
+
}, []);
|
|
383
|
+
return {
|
|
384
|
+
history: r.current,
|
|
385
|
+
clearHistory: n
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function N(s) {
|
|
389
|
+
const e = m(/* @__PURE__ */ new Map());
|
|
390
|
+
d(() => {
|
|
391
|
+
const n = (i) => {
|
|
392
|
+
const u = e.current.get(i.type) || {
|
|
393
|
+
count: 0,
|
|
394
|
+
lastTimestamp: 0,
|
|
395
|
+
frequency: 0
|
|
396
|
+
};
|
|
397
|
+
if (u.count++, u.lastTimestamp > 0) {
|
|
398
|
+
const l = (i.timestamp - u.lastTimestamp) / 1e3;
|
|
399
|
+
u.frequency = l > 0 ? 1 / l : 0;
|
|
400
|
+
}
|
|
401
|
+
u.lastTimestamp = i.timestamp, e.current.set(i.type, u);
|
|
402
|
+
};
|
|
403
|
+
return s.addEventListener("*", n);
|
|
404
|
+
}, [s]);
|
|
405
|
+
const t = p(() => Object.fromEntries(e.current.entries()), []), r = p(() => {
|
|
406
|
+
e.current.clear();
|
|
407
|
+
}, []);
|
|
408
|
+
return {
|
|
409
|
+
getMetrics: t,
|
|
410
|
+
resetMetrics: r
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function O(s, e = {}) {
|
|
414
|
+
const { logEvents: t = !0, logMetrics: r = !1, filterEventTypes: n } = e;
|
|
415
|
+
d(() => t ? s.addEventListener("*", (i) => {
|
|
416
|
+
n && !n.includes(i.type) || (console.group(`🎯 Event: ${i.type}`), console.log("Timestamp:", new Date(i.timestamp).toISOString()), console.log("Detail:", i.detail), console.log("Bubbles:", i.bubbles), console.log("Cancelable:", i.cancelable), console.groupEnd());
|
|
417
|
+
}) : void 0, [s, t, n]), d(() => {
|
|
418
|
+
if (!r) return;
|
|
419
|
+
const o = setInterval(() => {
|
|
420
|
+
const i = s.getListenerCount(), u = s.getEventTypes();
|
|
421
|
+
console.group("📊 Event Metrics"), console.log("Total Listeners:", i), console.log("Event Types:", u.length), console.log("Active Types:", u), console.groupEnd();
|
|
422
|
+
}, 5e3);
|
|
423
|
+
return () => clearInterval(o);
|
|
424
|
+
}, [s, r]);
|
|
425
|
+
}
|
|
426
|
+
function A(s, e, t, r, n, o) {
|
|
427
|
+
const i = H(() => typeof r == "function" ? r() : r, [r, ...o || []]);
|
|
428
|
+
d(() => i ? s.on(e, t, n) : void 0, [s, e, i, ...o || []]);
|
|
429
|
+
}
|
|
430
|
+
function _(s, e, t) {
|
|
431
|
+
const [r, n] = x(e);
|
|
432
|
+
return d(() => {
|
|
433
|
+
const o = [];
|
|
434
|
+
return Object.entries(t).forEach(([i, u]) => {
|
|
435
|
+
const l = s.addEventListener(i, (h) => {
|
|
436
|
+
n((c) => u(h.detail, c));
|
|
437
|
+
});
|
|
438
|
+
o.push(l);
|
|
439
|
+
}), () => {
|
|
440
|
+
o.forEach((i) => i());
|
|
441
|
+
};
|
|
442
|
+
}, [s, t]), r;
|
|
443
|
+
}
|
|
444
|
+
function z(s, e, t, r) {
|
|
445
|
+
const n = m(void 0);
|
|
446
|
+
b(
|
|
447
|
+
s,
|
|
448
|
+
e,
|
|
449
|
+
p((o) => {
|
|
450
|
+
typeof n.current == "function" && n.current(), n.current = t(o.detail);
|
|
451
|
+
}, r || []),
|
|
452
|
+
void 0,
|
|
453
|
+
r
|
|
454
|
+
), d(() => () => {
|
|
455
|
+
typeof n.current == "function" && n.current();
|
|
456
|
+
}, []);
|
|
457
|
+
}
|
|
458
|
+
const q = "1.0.0";
|
|
459
|
+
export {
|
|
460
|
+
E,
|
|
461
|
+
L as M,
|
|
462
|
+
q as a,
|
|
463
|
+
S as b,
|
|
464
|
+
y as c,
|
|
465
|
+
k as d,
|
|
466
|
+
f as e,
|
|
467
|
+
P as f,
|
|
468
|
+
b as g,
|
|
469
|
+
I as h,
|
|
470
|
+
R as i,
|
|
471
|
+
C as j,
|
|
472
|
+
Q as k,
|
|
473
|
+
N as l,
|
|
474
|
+
O as m,
|
|
475
|
+
A as n,
|
|
476
|
+
_ as o,
|
|
477
|
+
z as p,
|
|
478
|
+
D as u
|
|
479
|
+
};
|
|
480
|
+
//# sourceMappingURL=core-events-B5W_j8yU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-events-B5W_j8yU.js","sources":["../src/core/events/event-system.ts","../src/core/events/middleware.ts","../src/core/events/hooks.ts","../src/core/events/index.ts"],"sourcesContent":["// Event system types\nexport interface MediaPlayerEvent {\n type: string\n timestamp: number\n target?: string\n detail?: any\n bubbles?: boolean\n cancelable?: boolean\n defaultPrevented?: boolean\n}\n\nexport type EventHandler<T = any> = (event: MediaPlayerEvent & { detail: T }) => void\nexport type EventUnsubscriber = () => void\n\nexport interface EventOptions {\n once?: boolean\n passive?: boolean\n priority?: 'high' | 'normal' | 'low'\n filter?: (event: MediaPlayerEvent) => boolean\n}\n\n// Event categories for organization\nexport type EventCategory = \n | 'media' // Media playback events\n | 'user' // User interaction events \n | 'system' // System/internal events\n | 'plugin' // Plugin events\n | 'error' // Error events\n | 'performance' // Performance events\n\n// Standard media events\nexport interface MediaEvents {\n // Playback events\n 'media:loadstart': { src: string }\n 'media:loadeddata': { duration: number }\n 'media:canplay': {}\n 'media:canplaythrough': {}\n 'media:play': { currentTime: number }\n 'media:pause': { currentTime: number }\n 'media:ended': { duration: number }\n 'media:seeking': { currentTime: number, targetTime: number }\n 'media:seeked': { currentTime: number, previousTime: number }\n 'media:timeupdate': { currentTime: number, duration: number }\n 'media:durationchange': { duration: number }\n 'media:volumechange': { volume: number, muted: boolean }\n 'media:ratechange': { playbackRate: number }\n \n // Loading events\n 'media:loadedmetadata': { src: string }\n 'media:progress': { buffered: TimeRanges }\n 'media:suspend': {}\n 'media:abort': {}\n 'media:error': { error: Error }\n 'media:stalled': {}\n 'media:waiting': {}\n \n // User interaction events \n 'user:click': { x: number, y: number, element: string }\n 'user:hover': { element: string }\n 'user:focus': { element: string }\n 'user:keyboard': { key: string, code: string, altKey: boolean, ctrlKey: boolean, shiftKey: boolean }\n 'user:gesture': { type: string, data: any }\n \n // System events\n 'system:ready': {}\n 'system:resize': { width: number, height: number }\n 'system:fullscreen': { isFullscreen: boolean }\n 'system:pip': { isPictureInPicture: boolean }\n 'system:visibility': { isVisible: boolean }\n \n // Plugin events\n 'plugin:loaded': { name: string }\n 'plugin:enabled': { name: string }\n 'plugin:disabled': { name: string }\n 'plugin:error': { name: string, error: Error }\n \n // Performance events\n 'performance:fps': { fps: number }\n 'performance:memory': { used: number, total: number }\n 'performance:load': { loadTime: number }\n}\n\n// Event bus implementation\nexport class EventBus {\n private listeners = new Map<string, Array<{\n handler: EventHandler\n options: EventOptions\n id: string\n }>>()\n \n private eventQueue: MediaPlayerEvent[] = []\n private isProcessing = false\n private middlewares: Array<(event: MediaPlayerEvent) => MediaPlayerEvent | null> = []\n private eventHistory: MediaPlayerEvent[] = []\n private maxHistorySize = 1000\n\n // Subscribe to events\n on<K extends keyof MediaEvents>(\n type: K,\n handler: EventHandler<MediaEvents[K]>,\n options: EventOptions = {}\n ): EventUnsubscriber {\n return this.addEventListener(type, handler as EventHandler, options)\n }\n\n // Subscribe to events (one-time)\n once<K extends keyof MediaEvents>(\n type: K,\n handler: EventHandler<MediaEvents[K]>,\n options: EventOptions = {}\n ): EventUnsubscriber {\n return this.addEventListener(type, handler as EventHandler, { ...options, once: true })\n }\n\n // Subscribe to events with wildcard support\n addEventListener(\n type: string,\n handler: EventHandler,\n options: EventOptions = {}\n ): EventUnsubscriber {\n const id = this.generateId()\n const listener = { handler, options, id }\n\n if (!this.listeners.has(type)) {\n this.listeners.set(type, [])\n }\n\n const listeners = this.listeners.get(type)!\n \n // Insert based on priority\n const priority = options.priority || 'normal'\n const priorityValue = { high: 2, normal: 1, low: 0 }[priority]\n \n let insertIndex = listeners.length\n for (let i = 0; i < listeners.length; i++) {\n const listener = listeners[i]\n if (!listener) continue\n const listenerPriority = listener.options.priority || 'normal'\n if (priorityValue > { high: 2, normal: 1, low: 0 }[listenerPriority]) {\n insertIndex = i\n break\n }\n }\n \n listeners.splice(insertIndex, 0, listener)\n\n // Return unsubscriber\n return () => {\n const index = listeners.findIndex(l => l.id === id)\n if (index !== -1) {\n listeners.splice(index, 1)\n }\n if (listeners.length === 0) {\n this.listeners.delete(type)\n }\n }\n }\n\n // Remove event listener\n removeEventListener(type: string, handler?: EventHandler): void {\n const listeners = this.listeners.get(type)\n if (!listeners) return\n\n if (handler) {\n const index = listeners.findIndex(l => l.handler === handler)\n if (index !== -1) {\n listeners.splice(index, 1)\n }\n } else {\n this.listeners.delete(type)\n }\n\n if (listeners && listeners.length === 0) {\n this.listeners.delete(type)\n }\n }\n\n // Emit events\n emit<K extends keyof MediaEvents>(\n type: K,\n detail?: MediaEvents[K],\n options?: Partial<MediaPlayerEvent>\n ): boolean {\n const event: MediaPlayerEvent = {\n type,\n timestamp: Date.now(),\n detail,\n bubbles: true,\n cancelable: true,\n defaultPrevented: false,\n ...options\n }\n\n return this.dispatchEvent(event)\n }\n\n // Dispatch event\n dispatchEvent(event: MediaPlayerEvent): boolean {\n // Apply middlewares\n let processedEvent: MediaPlayerEvent | null = event\n for (const middleware of this.middlewares) {\n processedEvent = middleware(processedEvent)\n if (!processedEvent) {\n return false // Event was cancelled by middleware\n }\n }\n\n // Add to history\n this.addToHistory(processedEvent)\n\n // Queue event for processing\n this.eventQueue.push(processedEvent)\n \n if (!this.isProcessing) {\n this.processEventQueue()\n }\n\n return !processedEvent.defaultPrevented\n }\n\n // Process event queue with React 19 concurrent scheduling\n private processEventQueue(): void {\n if (this.isProcessing) return\n\n this.isProcessing = true\n\n // Use scheduler for non-blocking event processing\n const schedule = (typeof window !== 'undefined' && 'scheduler' in window)\n ? (window as any).scheduler.postTask\n : (cb: () => void) => setTimeout(cb, 0)\n\n const processNext = () => {\n if (this.eventQueue.length === 0) {\n this.isProcessing = false\n return\n }\n\n const batchSize = Math.min(this.eventQueue.length, 5) // Process max 5 events per frame\n const events = this.eventQueue.splice(0, batchSize)\n\n // Process events in parallel using Promise.all\n Promise.all(events.map(event => this.processEvent(event).catch(console.error)))\n .then(() => {\n // Schedule next batch in next frame\n schedule(processNext)\n })\n .catch(() => {\n this.isProcessing = false\n })\n }\n\n schedule(processNext)\n }\n\n // Process individual event\n private async processEvent(event: MediaPlayerEvent): Promise<void> {\n const { type } = event\n\n // Get exact matches\n const exactListeners = this.listeners.get(type) || []\n \n // Get wildcard matches\n const wildcardListeners: typeof exactListeners = []\n for (const [pattern, listeners] of this.listeners.entries()) {\n if (pattern.includes('*') && this.matchPattern(type, pattern)) {\n wildcardListeners.push(...listeners)\n }\n }\n\n // Combine and sort by priority\n const allListeners = [...exactListeners, ...wildcardListeners]\n .sort((a, b) => {\n const priorityA = { high: 2, normal: 1, low: 0 }[a.options.priority || 'normal']\n const priorityB = { high: 2, normal: 1, low: 0 }[b.options.priority || 'normal']\n return priorityB - priorityA\n })\n\n // Execute listeners\n const listenersToRemove: string[] = []\n\n for (const listener of allListeners) {\n // Apply filter if present\n if (listener.options.filter && !listener.options.filter(event)) {\n continue\n }\n\n try {\n // Execute handler\n await Promise.resolve(listener.handler(event as any))\n\n // Mark for removal if once\n if (listener.options.once) {\n listenersToRemove.push(listener.id)\n }\n\n // Stop propagation if event was cancelled\n if (event.defaultPrevented && !event.bubbles) {\n break\n }\n } catch (error) {\n console.error(`Error in event handler for ${type}:`, error)\n \n // Log error instead\n console.error(`Event handler error for ${type}:`, error)\n }\n }\n\n // Remove one-time listeners\n for (const id of listenersToRemove) {\n for (const [eventType, listeners] of this.listeners.entries()) {\n const index = listeners.findIndex(l => l.id === id)\n if (index !== -1) {\n listeners.splice(index, 1)\n if (listeners.length === 0) {\n this.listeners.delete(eventType)\n }\n break\n }\n }\n }\n }\n\n // Add middleware\n use(middleware: (event: MediaPlayerEvent) => MediaPlayerEvent | null): () => void {\n this.middlewares.push(middleware)\n return () => {\n const index = this.middlewares.indexOf(middleware)\n if (index !== -1) {\n this.middlewares.splice(index, 1)\n }\n }\n }\n\n // Event history management\n private addToHistory(event: MediaPlayerEvent): void {\n this.eventHistory.push(event)\n if (this.eventHistory.length > this.maxHistorySize) {\n this.eventHistory.shift()\n }\n }\n\n // Get event history\n getHistory(filter?: (event: MediaPlayerEvent) => boolean): MediaPlayerEvent[] {\n return filter ? this.eventHistory.filter(filter) : [...this.eventHistory]\n }\n\n // Clear event history\n clearHistory(): void {\n this.eventHistory = []\n }\n\n // Pattern matching for wildcards\n private matchPattern(eventType: string, pattern: string): boolean {\n const regex = new RegExp(\n '^' + pattern.replace(/\\*/g, '.*').replace(/\\?/g, '.') + '$'\n )\n return regex.test(eventType)\n }\n\n // Generate unique ID\n private generateId(): string {\n return `event_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`\n }\n\n // Get listener count\n getListenerCount(type?: string): number {\n if (type) {\n return this.listeners.get(type)?.length || 0\n }\n return Array.from(this.listeners.values()).reduce((sum, listeners) => sum + listeners.length, 0)\n }\n\n // Get all event types\n getEventTypes(): string[] {\n return Array.from(this.listeners.keys())\n }\n\n // Clear all listeners\n removeAllListeners(type?: string): void {\n if (type) {\n this.listeners.delete(type)\n } else {\n this.listeners.clear()\n }\n }\n\n // Destroy event bus\n destroy(): void {\n this.listeners.clear()\n this.eventQueue = []\n this.middlewares = []\n this.eventHistory = []\n this.isProcessing = false\n }\n}\n\n// Default event bus instance\nexport const defaultEventBus = new EventBus()\n\n// Event delegation helper\nexport class EventDelegator {\n private eventBus: EventBus\n private element: HTMLElement\n private delegatedEvents = new Set<string>()\n\n constructor(eventBus: EventBus, element: HTMLElement) {\n this.eventBus = eventBus\n this.element = element\n }\n\n // Delegate DOM events to event bus\n delegate(domEvent: string, mediaEvent?: string): void {\n if (this.delegatedEvents.has(domEvent)) return\n\n const handler = (e: Event) => {\n this.eventBus.emit(mediaEvent || `dom:${domEvent}` as any, {\n originalEvent: e,\n target: (e.target as HTMLElement)?.tagName.toLowerCase(),\n currentTarget: (e.currentTarget as HTMLElement)?.tagName.toLowerCase()\n })\n }\n\n this.element.addEventListener(domEvent, handler, { passive: true })\n this.delegatedEvents.add(domEvent)\n }\n\n // Setup common delegations\n setupCommonDelegations(): void {\n this.delegate('click', 'user:click')\n this.delegate('mouseenter', 'user:hover')\n this.delegate('mouseleave', 'user:hover')\n this.delegate('focus', 'user:focus')\n this.delegate('blur', 'user:focus')\n this.delegate('keydown', 'user:keyboard')\n this.delegate('keyup', 'user:keyboard')\n }\n\n destroy(): void {\n this.delegatedEvents.clear()\n }\n}\n\n","import type { MediaPlayerEvent } from './event-system'\n\n// Middleware function type\nexport type EventMiddleware = (event: MediaPlayerEvent) => MediaPlayerEvent | null\n\n// Common middleware implementations\nexport const eventMiddlewares = {\n // Logging middleware\n logger: (prefix = '[Event]'): EventMiddleware => (event) => {\n if (process.env.NODE_ENV === 'development') {\n console.log(`${prefix} ${event.type}`, event.detail)\n }\n return event\n },\n\n // Throttling middleware\n throttle: (eventTypes: string[], delay = 100): EventMiddleware => {\n const lastTimes = new Map<string, number>()\n \n return (event) => {\n if (eventTypes.includes(event.type)) {\n const lastTime = lastTimes.get(event.type) || 0\n const now = event.timestamp\n \n if (now - lastTime < delay) {\n return null // Throttle this event\n }\n \n lastTimes.set(event.type, now)\n }\n \n return event\n }\n },\n\n // Debouncing middleware\n debounce: (eventTypes: string[], delay = 100): EventMiddleware => {\n const timeouts = new Map<string, NodeJS.Timeout>()\n const eventQueue = new Map<string, MediaPlayerEvent>()\n \n return (event) => {\n if (eventTypes.includes(event.type)) {\n // Clear existing timeout\n const existingTimeout = timeouts.get(event.type)\n if (existingTimeout) {\n clearTimeout(existingTimeout)\n }\n \n // Store the latest event\n eventQueue.set(event.type, event)\n \n // Set new timeout\n const timeout = setTimeout(() => {\n const queuedEvent = eventQueue.get(event.type)\n if (queuedEvent) {\n // Process the debounced event\n // Note: This is a simplified approach - in a real implementation,\n // you'd need to re-inject the event into the processing pipeline\n eventQueue.delete(event.type)\n timeouts.delete(event.type)\n }\n }, delay)\n \n timeouts.set(event.type, timeout)\n \n return null // Don't process immediately\n }\n \n return event\n }\n },\n\n // Filtering middleware\n filter: (predicate: (event: MediaPlayerEvent) => boolean): EventMiddleware => (event) => {\n return predicate(event) ? event : null\n },\n\n // Event transformation middleware\n transform: (transformer: (event: MediaPlayerEvent) => MediaPlayerEvent): EventMiddleware => (event) => {\n try {\n return transformer(event)\n } catch (error) {\n console.error('Error in event transformer:', error)\n return event\n }\n },\n\n // Performance monitoring middleware\n performance: (): EventMiddleware => {\n const metrics = new Map<string, { count: number; totalTime: number }>()\n \n return (event) => {\n const startTime = performance.now()\n \n // Update metrics\n const existing = metrics.get(event.type) || { count: 0, totalTime: 0 }\n existing.count++\n existing.totalTime += performance.now() - startTime\n metrics.set(event.type, existing)\n \n // Log metrics periodically (every 100 events)\n if (existing.count % 100 === 0) {\n const avgTime = existing.totalTime / existing.count\n console.log(`Event ${event.type}: ${existing.count} calls, avg ${avgTime.toFixed(2)}ms`)\n }\n \n return event\n }\n },\n\n // Error handling middleware\n errorHandler: (onError?: (error: Error, event: MediaPlayerEvent) => void): EventMiddleware => (event) => {\n try {\n // Validate event structure\n if (!event.type || typeof event.type !== 'string') {\n throw new Error('Invalid event: missing or invalid type')\n }\n \n if (!event.timestamp || typeof event.timestamp !== 'number') {\n throw new Error('Invalid event: missing or invalid timestamp')\n }\n \n return event\n } catch (error) {\n if (onError) {\n onError(error as Error, event)\n } else {\n console.error('Event validation error:', error)\n }\n return null\n }\n },\n\n // Security middleware (prevent certain events or sanitize data)\n security: (options: {\n blockedEventTypes?: string[]\n sanitizeDetail?: boolean\n maxDetailSize?: number\n } = {}): EventMiddleware => (event) => {\n const { blockedEventTypes = [], sanitizeDetail = true, maxDetailSize = 10000 } = options\n \n // Block certain event types\n if (blockedEventTypes.includes(event.type)) {\n console.warn(`Blocked event type: ${event.type}`)\n return null\n }\n \n // Sanitize detail if needed\n if (sanitizeDetail && event.detail) {\n try {\n const detailStr = JSON.stringify(event.detail)\n if (detailStr.length > maxDetailSize) {\n console.warn(`Event detail too large, truncating: ${event.type}`)\n event.detail = { ...event.detail, _truncated: true }\n }\n } catch (error) {\n console.warn(`Failed to serialize event detail: ${event.type}`)\n event.detail = { _serializationError: true }\n }\n }\n \n return event\n },\n\n // Conditional middleware\n when: (condition: (event: MediaPlayerEvent) => boolean, middleware: EventMiddleware): EventMiddleware => (event) => {\n return condition(event) ? middleware(event) : event\n },\n\n // Chain multiple middleware\n chain: (...middlewares: EventMiddleware[]): EventMiddleware => (event) => {\n let currentEvent: MediaPlayerEvent | null = event\n \n for (const middleware of middlewares) {\n if (currentEvent === null) break\n currentEvent = middleware(currentEvent)\n }\n \n return currentEvent\n }\n}\n\n// Middleware builder class\nexport class MiddlewareBuilder {\n private middlewares: EventMiddleware[] = []\n\n // Add middleware\n use(middleware: EventMiddleware): this {\n this.middlewares.push(middleware)\n return this\n }\n\n // Add logging\n log(prefix?: string): this {\n return this.use(eventMiddlewares.logger(prefix))\n }\n\n // Add throttling\n throttle(eventTypes: string[], delay?: number): this {\n return this.use(eventMiddlewares.throttle(eventTypes, delay))\n }\n\n // Add debouncing\n debounce(eventTypes: string[], delay?: number): this {\n return this.use(eventMiddlewares.debounce(eventTypes, delay))\n }\n\n // Add filtering\n filter(predicate: (event: MediaPlayerEvent) => boolean): this {\n return this.use(eventMiddlewares.filter(predicate))\n }\n\n // Add transformation\n transform(transformer: (event: MediaPlayerEvent) => MediaPlayerEvent): this {\n return this.use(eventMiddlewares.transform(transformer))\n }\n\n // Add performance monitoring\n performance(): this {\n return this.use(eventMiddlewares.performance())\n }\n\n // Add error handling\n errorHandler(onError?: (error: Error, event: MediaPlayerEvent) => void): this {\n return this.use(eventMiddlewares.errorHandler(onError))\n }\n\n // Add security\n security(options?: Parameters<typeof eventMiddlewares.security>[0]): this {\n return this.use(eventMiddlewares.security(options))\n }\n\n // Add conditional middleware\n when(condition: (event: MediaPlayerEvent) => boolean, middleware: EventMiddleware): this {\n return this.use(eventMiddlewares.when(condition, middleware))\n }\n\n // Build the final middleware\n build(): EventMiddleware {\n return eventMiddlewares.chain(...this.middlewares)\n }\n}\n\n// Helper to create middleware builder\nexport const createMiddleware = () => new MiddlewareBuilder()\n\n// Export commonly used middleware combinations\nexport const commonMiddlewares = {\n // Development middleware stack\n development: () => createMiddleware()\n .log('[Dev Event]')\n .performance()\n .errorHandler()\n .build(),\n\n // Production middleware stack\n production: () => createMiddleware()\n .security()\n .errorHandler()\n .throttle(['media:timeupdate', 'user:mousemove'], 16) // ~60fps\n .build(),\n\n // Testing middleware stack\n testing: () => createMiddleware()\n .errorHandler((error, event) => {\n throw new Error(`Event error in test: ${error.message} for event ${event.type}`)\n })\n .build()\n}","import React, { useEffect, useRef, useCallback, useMemo, useState } from 'react'\nimport { EventBus, type EventHandler, type EventUnsubscriber, type EventOptions, type MediaEvents } from './event-system'\n\n// Hook to use event bus with React\nexport function useEventBus(eventBus?: EventBus): EventBus {\n const eventBusRef = useRef<EventBus | null>(null)\n \n if (!eventBusRef.current) {\n eventBusRef.current = eventBus || new EventBus()\n }\n \n useEffect(() => {\n const currentEventBus = eventBusRef.current!\n \n return () => {\n // Cleanup on unmount\n currentEventBus.destroy()\n }\n }, [])\n \n return eventBusRef.current\n}\n\n// Hook to listen to events\nexport function useEventListener<K extends keyof MediaEvents>(\n eventBus: EventBus,\n type: K,\n handler: EventHandler<MediaEvents[K]>,\n options?: EventOptions,\n deps?: React.DependencyList\n): void {\n const handlerRef = useRef(handler)\n const optionsRef = useRef(options)\n \n // Update refs when dependencies change\n useEffect(() => {\n handlerRef.current = handler\n optionsRef.current = options\n })\n \n useEffect(() => {\n const unsubscribe = eventBus.on(type, handlerRef.current, optionsRef.current)\n return unsubscribe\n }, [eventBus, type, ...(deps || [])])\n}\n\n// Hook to emit events\nexport function useEventEmitter(eventBus: EventBus) {\n return useCallback(<K extends keyof MediaEvents>(\n type: K,\n detail?: MediaEvents[K],\n options?: Partial<MediaEvents[K]>\n ) => {\n return eventBus.emit(type, detail, options)\n }, [eventBus])\n}\n\n// Hook for one-time event listeners\nexport function useEventOnce<K extends keyof MediaEvents>(\n eventBus: EventBus,\n type: K,\n handler: EventHandler<MediaEvents[K]>,\n deps?: React.DependencyList\n): void {\n useEventListener(eventBus, type, handler, { once: true }, deps)\n}\n\n// Hook to create event handlers with automatic cleanup\nexport function useEventHandlers(eventBus: EventBus) {\n const handlersRef = useRef<EventUnsubscriber[]>([])\n \n const addHandler = useCallback(<K extends keyof MediaEvents>(\n type: K,\n handler: EventHandler<MediaEvents[K]>,\n options?: EventOptions\n ) => {\n const unsubscribe = eventBus.on(type, handler, options)\n handlersRef.current.push(unsubscribe)\n return unsubscribe\n }, [eventBus])\n \n const removeAllHandlers = useCallback(() => {\n handlersRef.current.forEach(unsubscribe => unsubscribe())\n handlersRef.current = []\n }, [])\n \n useEffect(() => {\n return removeAllHandlers\n }, [removeAllHandlers])\n \n return {\n on: addHandler,\n removeAll: removeAllHandlers\n }\n}\n\n// Hook for event history\nexport function useEventHistory(\n eventBus: EventBus,\n filter?: (event: any) => boolean,\n maxSize = 100\n) {\n const historyRef = useRef<any[]>([])\n \n useEffect(() => {\n const unsubscribe = eventBus.addEventListener('*', (event) => {\n if (!filter || filter(event)) {\n historyRef.current.push(event)\n \n // Limit history size\n if (historyRef.current.length > maxSize) {\n historyRef.current.shift()\n }\n }\n })\n \n return unsubscribe\n }, [eventBus, filter, maxSize])\n \n const clearHistory = useCallback(() => {\n historyRef.current = []\n }, [])\n \n return {\n history: historyRef.current,\n clearHistory\n }\n}\n\n// Hook for event metrics/analytics\nexport function useEventMetrics(eventBus: EventBus) {\n const metricsRef = useRef<Map<string, {\n count: number\n lastTimestamp: number\n frequency: number // events per second\n }>>(new Map())\n \n useEffect(() => {\n const updateMetrics = (event: any) => {\n const existing = metricsRef.current.get(event.type) || {\n count: 0,\n lastTimestamp: 0,\n frequency: 0\n }\n \n existing.count++\n \n if (existing.lastTimestamp > 0) {\n const timeDiff = (event.timestamp - existing.lastTimestamp) / 1000 // seconds\n existing.frequency = timeDiff > 0 ? 1 / timeDiff : 0\n }\n \n existing.lastTimestamp = event.timestamp\n metricsRef.current.set(event.type, existing)\n }\n \n const unsubscribe = eventBus.addEventListener('*', updateMetrics)\n return unsubscribe\n }, [eventBus])\n \n const getMetrics = useCallback(() => {\n return Object.fromEntries(metricsRef.current.entries())\n }, [])\n \n const resetMetrics = useCallback(() => {\n metricsRef.current.clear()\n }, [])\n \n return {\n getMetrics,\n resetMetrics\n }\n}\n\n// Hook for event debugging\nexport function useEventDebugger(\n eventBus: EventBus, \n options: {\n logEvents?: boolean\n logMetrics?: boolean\n filterEventTypes?: string[]\n } = {}\n) {\n const { logEvents = true, logMetrics = false, filterEventTypes } = options\n \n useEffect(() => {\n if (!logEvents) return\n \n const unsubscribe = eventBus.addEventListener('*', (event) => {\n if (filterEventTypes && !filterEventTypes.includes(event.type)) {\n return\n }\n \n console.group(`🎯 Event: ${event.type}`)\n console.log('Timestamp:', new Date(event.timestamp).toISOString())\n console.log('Detail:', event.detail)\n console.log('Bubbles:', event.bubbles)\n console.log('Cancelable:', event.cancelable)\n console.groupEnd()\n })\n \n return unsubscribe\n }, [eventBus, logEvents, filterEventTypes])\n \n useEffect(() => {\n if (!logMetrics) return\n \n const interval = setInterval(() => {\n const listenerCount = eventBus.getListenerCount()\n const eventTypes = eventBus.getEventTypes()\n \n console.group('📊 Event Metrics')\n console.log('Total Listeners:', listenerCount)\n console.log('Event Types:', eventTypes.length)\n console.log('Active Types:', eventTypes)\n console.groupEnd()\n }, 5000)\n \n return () => clearInterval(interval)\n }, [eventBus, logMetrics])\n}\n\n// Hook for conditional event handling\nexport function useConditionalEventListener<K extends keyof MediaEvents>(\n eventBus: EventBus,\n type: K,\n handler: EventHandler<MediaEvents[K]>,\n condition: boolean | (() => boolean),\n options?: EventOptions,\n deps?: React.DependencyList\n): void {\n const shouldListen = useMemo(() => {\n return typeof condition === 'function' ? condition() : condition\n }, [condition, ...(deps || [])])\n \n useEffect(() => {\n if (!shouldListen) return\n \n const unsubscribe = eventBus.on(type, handler, options)\n return unsubscribe\n }, [eventBus, type, shouldListen, ...(deps || [])])\n}\n\n// Hook for event state synchronization\nexport function useEventState<T>(\n eventBus: EventBus,\n initialValue: T,\n eventMapping: Record<string, (detail: any, currentValue: T) => T>\n) {\n const [state, setState] = useState<T>(initialValue)\n \n useEffect(() => {\n const unsubscribers: EventUnsubscriber[] = []\n \n Object.entries(eventMapping).forEach(([eventType, updater]) => {\n const unsubscribe = eventBus.addEventListener(eventType, (event) => {\n setState(current => updater(event.detail, current))\n })\n unsubscribers.push(unsubscribe)\n })\n \n return () => {\n unsubscribers.forEach(unsubscribe => unsubscribe())\n }\n }, [eventBus, eventMapping])\n \n return state\n}\n\n// Hook for creating event-driven effects\nexport function useEventEffect<K extends keyof MediaEvents>(\n eventBus: EventBus,\n type: K,\n effect: (detail: MediaEvents[K]) => void | (() => void),\n deps?: React.DependencyList\n): void {\n const cleanupRef = useRef<(() => void) | void>(undefined)\n \n useEventListener(\n eventBus,\n type,\n useCallback((event) => {\n // Clean up previous effect\n if (typeof cleanupRef.current === 'function') {\n cleanupRef.current()\n }\n \n // Run new effect\n cleanupRef.current = effect(event.detail)\n }, deps || []),\n undefined,\n deps\n )\n \n useEffect(() => {\n return () => {\n if (typeof cleanupRef.current === 'function') {\n cleanupRef.current()\n }\n }\n }, [])\n}","// Event system exports\nexport {\n EventBus,\n EventDelegator,\n defaultEventBus\n} from './event-system'\n\nexport type {\n MediaPlayerEvent,\n EventHandler,\n EventUnsubscriber,\n EventOptions,\n EventCategory,\n MediaEvents\n} from './event-system'\n\n// Event utilities\nexport * from './middleware'\nexport * from './hooks'\n\n// Version\nexport const EVENT_SYSTEM_VERSION = '1.0.0'"],"names":["EventBus","__publicField","type","handler","options","id","listener","listeners","priority","priorityValue","insertIndex","i","listenerPriority","index","l","detail","event","processedEvent","middleware","schedule","cb","processNext","batchSize","events","exactListeners","wildcardListeners","pattern","allListeners","a","b","priorityA","listenersToRemove","error","eventType","filter","sum","defaultEventBus","EventDelegator","eventBus","element","domEvent","mediaEvent","e","eventMiddlewares","prefix","eventTypes","delay","lastTimes","lastTime","now","timeouts","eventQueue","existingTimeout","timeout","predicate","transformer","metrics","startTime","existing","avgTime","onError","blockedEventTypes","sanitizeDetail","maxDetailSize","condition","middlewares","currentEvent","MiddlewareBuilder","createMiddleware","commonMiddlewares","useEventBus","eventBusRef","useRef","useEffect","currentEventBus","useEventListener","deps","handlerRef","optionsRef","useEventEmitter","useCallback","useEventOnce","useEventHandlers","handlersRef","addHandler","unsubscribe","removeAllHandlers","useEventHistory","maxSize","historyRef","clearHistory","useEventMetrics","metricsRef","updateMetrics","timeDiff","getMetrics","resetMetrics","useEventDebugger","logEvents","logMetrics","filterEventTypes","interval","listenerCount","useConditionalEventListener","shouldListen","useMemo","useEventState","initialValue","eventMapping","state","setState","useState","unsubscribers","updater","current","useEventEffect","effect","cleanupRef","EVENT_SYSTEM_VERSION"],"mappings":";;;;AAmFO,MAAMA,EAAS;AAAA,EAAf;AACG,IAAAC,EAAA,uCAAgB,IAAA;AAMhB,IAAAA,EAAA,oBAAiC,CAAA;AACjC,IAAAA,EAAA,sBAAe;AACf,IAAAA,EAAA,qBAA2E,CAAA;AAC3E,IAAAA,EAAA,sBAAmC,CAAA;AACnC,IAAAA,EAAA,wBAAiB;AAAA;AAAA;AAAA,EA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AUD,EAAOpG,EAAM,MAAM;AAAA,IAC1C,GAAG4D,KAAQ,EAAE;AAAA,IACb;AAAA,IACAA;AAAA,EAAA,GAGFH,EAAU,MACD,MAAM;AACX,IAAI,OAAO4C,EAAW,WAAY,cAChCA,EAAW,QAAA;AAAA,EAEf,GACC,CAAA,CAAE;AACP;ACxRO,MAAMC,IAAuB;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var b=Object.defineProperty;var w=(s,e,t)=>e in s?b(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var d=(s,e,t)=>w(s,typeof e!="symbol"?e+"":e,t);const c=require("react");class g{constructor(){d(this,"listeners",new Map);d(this,"eventQueue",[]);d(this,"isProcessing",!1);d(this,"middlewares",[]);d(this,"eventHistory",[]);d(this,"maxHistorySize",1e3)}on(e,t,r={}){return this.addEventListener(e,t,r)}once(e,t,r={}){return this.addEventListener(e,t,{...r,once:!0})}addEventListener(e,t,r={}){const n=this.generateId(),o={handler:t,options:r,id:n};this.listeners.has(e)||this.listeners.set(e,[]);const i=this.listeners.get(e),u=r.priority||"normal",l={high:2,normal:1,low:0}[u];let h=i.length;for(let a=0;a<i.length;a++){const m=i[a];if(!m)continue;const v=m.options.priority||"normal";if(l>{high:2,normal:1,low:0}[v]){h=a;break}}return i.splice(h,0,o),()=>{const a=i.findIndex(m=>m.id===n);a!==-1&&i.splice(a,1),i.length===0&&this.listeners.delete(e)}}removeEventListener(e,t){const r=this.listeners.get(e);if(r){if(t){const n=r.findIndex(o=>o.handler===t);n!==-1&&r.splice(n,1)}else this.listeners.delete(e);r&&r.length===0&&this.listeners.delete(e)}}emit(e,t,r){const n={type:e,timestamp:Date.now(),detail:t,bubbles:!0,cancelable:!0,defaultPrevented:!1,...r};return this.dispatchEvent(n)}dispatchEvent(e){let t=e;for(const r of this.middlewares)if(t=r(t),!t)return!1;return this.addToHistory(t),this.eventQueue.push(t),this.isProcessing||this.processEventQueue(),!t.defaultPrevented}processEventQueue(){if(this.isProcessing)return;this.isProcessing=!0;const e=typeof window<"u"&&"scheduler"in window?window.scheduler.postTask:r=>setTimeout(r,0),t=()=>{if(this.eventQueue.length===0){this.isProcessing=!1;return}const r=Math.min(this.eventQueue.length,5),n=this.eventQueue.splice(0,r);Promise.all(n.map(o=>this.processEvent(o).catch(console.error))).then(()=>{e(t)}).catch(()=>{this.isProcessing=!1})};e(t)}async processEvent(e){const{type:t}=e,r=this.listeners.get(t)||[],n=[];for(const[u,l]of this.listeners.entries())u.includes("*")&&this.matchPattern(t,u)&&n.push(...l);const o=[...r,...n].sort((u,l)=>{const h={high:2,normal:1,low:0}[u.options.priority||"normal"];return{high:2,normal:1,low:0}[l.options.priority||"normal"]-h}),i=[];for(const u of o)if(!(u.options.filter&&!u.options.filter(e)))try{if(await Promise.resolve(u.handler(e)),u.options.once&&i.push(u.id),e.defaultPrevented&&!e.bubbles)break}catch(l){console.error(`Error in event handler for ${t}:`,l),console.error(`Event handler error for ${t}:`,l)}for(const u of i)for(const[l,h]of this.listeners.entries()){const a=h.findIndex(m=>m.id===u);if(a!==-1){h.splice(a,1),h.length===0&&this.listeners.delete(l);break}}}use(e){return this.middlewares.push(e),()=>{const t=this.middlewares.indexOf(e);t!==-1&&this.middlewares.splice(t,1)}}addToHistory(e){this.eventHistory.push(e),this.eventHistory.length>this.maxHistorySize&&this.eventHistory.shift()}getHistory(e){return e?this.eventHistory.filter(e):[...this.eventHistory]}clearHistory(){this.eventHistory=[]}matchPattern(e,t){return new RegExp("^"+t.replace(/\*/g,".*").replace(/\?/g,".")+"$").test(e)}generateId(){return`event_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}getListenerCount(e){return e?this.listeners.get(e)?.length||0:Array.from(this.listeners.values()).reduce((t,r)=>t+r.length,0)}getEventTypes(){return Array.from(this.listeners.keys())}removeAllListeners(e){e?this.listeners.delete(e):this.listeners.clear()}destroy(){this.listeners.clear(),this.eventQueue=[],this.middlewares=[],this.eventHistory=[],this.isProcessing=!1}}const T=new g;class H{constructor(e,t){d(this,"eventBus");d(this,"element");d(this,"delegatedEvents",new Set);this.eventBus=e,this.element=t}delegate(e,t){if(this.delegatedEvents.has(e))return;const r=n=>{this.eventBus.emit(t||`dom:${e}`,{originalEvent:n,target:n.target?.tagName.toLowerCase(),currentTarget:n.currentTarget?.tagName.toLowerCase()})};this.element.addEventListener(e,r,{passive:!0}),this.delegatedEvents.add(e)}setupCommonDelegations(){this.delegate("click","user:click"),this.delegate("mouseenter","user:hover"),this.delegate("mouseleave","user:hover"),this.delegate("focus","user:focus"),this.delegate("blur","user:focus"),this.delegate("keydown","user:keyboard"),this.delegate("keyup","user:keyboard")}destroy(){this.delegatedEvents.clear()}}const f={logger:(s="[Event]")=>e=>(process.env.NODE_ENV==="development"&&console.log(`${s} ${e.type}`,e.detail),e),throttle:(s,e=100)=>{const t=new Map;return r=>{if(s.includes(r.type)){const n=t.get(r.type)||0,o=r.timestamp;if(o-n<e)return null;t.set(r.type,o)}return r}},debounce:(s,e=100)=>{const t=new Map,r=new Map;return n=>{if(s.includes(n.type)){const o=t.get(n.type);o&&clearTimeout(o),r.set(n.type,n);const i=setTimeout(()=>{r.get(n.type)&&(r.delete(n.type),t.delete(n.type))},e);return t.set(n.type,i),null}return n}},filter:s=>e=>s(e)?e:null,transform:s=>e=>{try{return s(e)}catch(t){return console.error("Error in event transformer:",t),e}},performance:()=>{const s=new Map;return e=>{const t=performance.now(),r=s.get(e.type)||{count:0,totalTime:0};if(r.count++,r.totalTime+=performance.now()-t,s.set(e.type,r),r.count%100===0){const n=r.totalTime/r.count;console.log(`Event ${e.type}: ${r.count} calls, avg ${n.toFixed(2)}ms`)}return e}},errorHandler:s=>e=>{try{if(!e.type||typeof e.type!="string")throw new Error("Invalid event: missing or invalid type");if(!e.timestamp||typeof e.timestamp!="number")throw new Error("Invalid event: missing or invalid timestamp");return e}catch(t){return s?s(t,e):console.error("Event validation error:",t),null}},security:(s={})=>e=>{const{blockedEventTypes:t=[],sanitizeDetail:r=!0,maxDetailSize:n=1e4}=s;if(t.includes(e.type))return console.warn(`Blocked event type: ${e.type}`),null;if(r&&e.detail)try{JSON.stringify(e.detail).length>n&&(console.warn(`Event detail too large, truncating: ${e.type}`),e.detail={...e.detail,_truncated:!0})}catch{console.warn(`Failed to serialize event detail: ${e.type}`),e.detail={_serializationError:!0}}return e},when:(s,e)=>t=>s(t)?e(t):t,chain:(...s)=>e=>{let t=e;for(const r of s){if(t===null)break;t=r(t)}return t}};class y{constructor(){d(this,"middlewares",[])}use(e){return this.middlewares.push(e),this}log(e){return this.use(f.logger(e))}throttle(e,t){return this.use(f.throttle(e,t))}debounce(e,t){return this.use(f.debounce(e,t))}filter(e){return this.use(f.filter(e))}transform(e){return this.use(f.transform(e))}performance(){return this.use(f.performance())}errorHandler(e){return this.use(f.errorHandler(e))}security(e){return this.use(f.security(e))}when(e,t){return this.use(f.when(e,t))}build(){return f.chain(...this.middlewares)}}const p=()=>new y,M={development:()=>p().log("[Dev Event]").performance().errorHandler().build(),production:()=>p().security().errorHandler().throttle(["media:timeupdate","user:mousemove"],16).build(),testing:()=>p().errorHandler((s,e)=>{throw new Error(`Event error in test: ${s.message} for event ${e.type}`)}).build()};function L(s){const e=c.useRef(null);return e.current||(e.current=s||new g),c.useEffect(()=>{const t=e.current;return()=>{t.destroy()}},[]),e.current}function E(s,e,t,r,n){const o=c.useRef(t),i=c.useRef(r);c.useEffect(()=>{o.current=t,i.current=r}),c.useEffect(()=>s.on(e,o.current,i.current),[s,e,...n||[]])}function k(s){return c.useCallback((e,t,r)=>s.emit(e,t,r),[s])}function x(s,e,t,r){E(s,e,t,{once:!0},r)}function S(s){const e=c.useRef([]),t=c.useCallback((n,o,i)=>{const u=s.on(n,o,i);return e.current.push(u),u},[s]),r=c.useCallback(()=>{e.current.forEach(n=>n()),e.current=[]},[]);return c.useEffect(()=>r,[r]),{on:t,removeAll:r}}function R(s,e,t=100){const r=c.useRef([]);c.useEffect(()=>s.addEventListener("*",i=>{(!e||e(i))&&(r.current.push(i),r.current.length>t&&r.current.shift())}),[s,e,t]);const n=c.useCallback(()=>{r.current=[]},[]);return{history:r.current,clearHistory:n}}function $(s){const e=c.useRef(new Map);c.useEffect(()=>{const n=i=>{const u=e.current.get(i.type)||{count:0,lastTimestamp:0,frequency:0};if(u.count++,u.lastTimestamp>0){const l=(i.timestamp-u.lastTimestamp)/1e3;u.frequency=l>0?1/l:0}u.lastTimestamp=i.timestamp,e.current.set(i.type,u)};return s.addEventListener("*",n)},[s]);const t=c.useCallback(()=>Object.fromEntries(e.current.entries()),[]),r=c.useCallback(()=>{e.current.clear()},[]);return{getMetrics:t,resetMetrics:r}}function C(s,e={}){const{logEvents:t=!0,logMetrics:r=!1,filterEventTypes:n}=e;c.useEffect(()=>t?s.addEventListener("*",i=>{n&&!n.includes(i.type)||(console.group(`🎯 Event: ${i.type}`),console.log("Timestamp:",new Date(i.timestamp).toISOString()),console.log("Detail:",i.detail),console.log("Bubbles:",i.bubbles),console.log("Cancelable:",i.cancelable),console.groupEnd())}):void 0,[s,t,n]),c.useEffect(()=>{if(!r)return;const o=setInterval(()=>{const i=s.getListenerCount(),u=s.getEventTypes();console.group("📊 Event Metrics"),console.log("Total Listeners:",i),console.log("Event Types:",u.length),console.log("Active Types:",u),console.groupEnd()},5e3);return()=>clearInterval(o)},[s,r])}function P(s,e,t,r,n,o){const i=c.useMemo(()=>typeof r=="function"?r():r,[r,...o||[]]);c.useEffect(()=>i?s.on(e,t,n):void 0,[s,e,i,...o||[]])}function D(s,e,t){const[r,n]=c.useState(e);return c.useEffect(()=>{const o=[];return Object.entries(t).forEach(([i,u])=>{const l=s.addEventListener(i,h=>{n(a=>u(h.detail,a))});o.push(l)}),()=>{o.forEach(i=>i())}},[s,t]),r}function I(s,e,t,r){const n=c.useRef(void 0);E(s,e,c.useCallback(o=>{typeof n.current=="function"&&n.current(),n.current=t(o.detail)},r||[]),void 0,r),c.useEffect(()=>()=>{typeof n.current=="function"&&n.current()},[])}const N="1.0.0";exports.EVENT_SYSTEM_VERSION=N;exports.EventBus=g;exports.EventDelegator=H;exports.MiddlewareBuilder=y;exports.commonMiddlewares=M;exports.createMiddleware=p;exports.defaultEventBus=T;exports.eventMiddlewares=f;exports.useConditionalEventListener=P;exports.useEventBus=L;exports.useEventDebugger=C;exports.useEventEffect=I;exports.useEventEmitter=k;exports.useEventHandlers=S;exports.useEventHistory=R;exports.useEventListener=E;exports.useEventMetrics=$;exports.useEventOnce=x;exports.useEventState=D;
|
|
2
|
+
//# sourceMappingURL=core-events-CN0-Vhhq.cjs.map
|