@videojs/html 10.0.0-beta.1 → 10.0.0-beta.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/cdn/audio-minimal.css +1 -0
- package/cdn/audio-minimal.dev.js +5360 -0
- package/cdn/audio-minimal.dev.js.map +1 -0
- package/cdn/audio-minimal.js +25 -0
- package/cdn/audio-minimal.js.map +1 -0
- package/cdn/audio.css +1 -0
- package/cdn/audio.dev.js +5351 -0
- package/cdn/audio.dev.js.map +1 -0
- package/cdn/audio.js +25 -0
- package/cdn/audio.js.map +1 -0
- package/cdn/background.css +1 -0
- package/cdn/background.dev.js +2057 -0
- package/cdn/background.dev.js.map +1 -0
- package/cdn/background.js +19 -0
- package/cdn/background.js.map +1 -0
- package/cdn/media/hls-video.dev.js +28728 -0
- package/cdn/media/hls-video.dev.js.map +1 -0
- package/cdn/media/hls-video.js +83 -0
- package/cdn/media/hls-video.js.map +1 -0
- package/cdn/media/simple-hls-video.dev.js +3796 -0
- package/cdn/media/simple-hls-video.dev.js.map +1 -0
- package/cdn/media/simple-hls-video.js +44 -0
- package/cdn/media/simple-hls-video.js.map +1 -0
- package/cdn/video-minimal.css +1 -0
- package/cdn/video-minimal.dev.js +5714 -0
- package/cdn/video-minimal.dev.js.map +1 -0
- package/cdn/video-minimal.js +25 -0
- package/cdn/video-minimal.js.map +1 -0
- package/cdn/video.css +1 -0
- package/cdn/video.dev.js +5782 -0
- package/cdn/video.dev.js.map +1 -0
- package/cdn/video.js +25 -0
- package/cdn/video.js.map +1 -0
- package/dist/default/_virtual/inline-css_src/define/audio/minimal-skin.js +1 -1
- package/dist/default/_virtual/inline-css_src/define/audio/minimal-skin.js.map +1 -1
- package/dist/default/_virtual/inline-css_src/define/audio/skin.js +1 -1
- package/dist/default/_virtual/inline-css_src/define/audio/skin.js.map +1 -1
- package/dist/default/_virtual/inline-css_src/define/video/minimal-skin.js +1 -1
- package/dist/default/_virtual/inline-css_src/define/video/minimal-skin.js.map +1 -1
- package/dist/default/_virtual/inline-css_src/define/video/skin.js +1 -1
- package/dist/default/_virtual/inline-css_src/define/video/skin.js.map +1 -1
- package/dist/default/define/audio/minimal-skin.js +1 -79
- package/dist/default/define/audio/minimal-skin.js.map +1 -1
- package/dist/default/define/audio/minimal-skin.tailwind.js +1 -81
- package/dist/default/define/audio/minimal-skin.tailwind.js.map +1 -1
- package/dist/default/define/audio/skin.js +1 -70
- package/dist/default/define/audio/skin.js.map +1 -1
- package/dist/default/define/audio/skin.tailwind.js +1 -72
- package/dist/default/define/audio/skin.tailwind.js.map +1 -1
- package/dist/default/define/background/skin.js +1 -5
- package/dist/default/define/background/skin.js.map +1 -1
- package/dist/default/define/skin-mixin.js +1 -15
- package/dist/default/define/skin-mixin.js.map +1 -1
- package/dist/default/define/video/minimal-skin.js +1 -121
- package/dist/default/define/video/minimal-skin.js.map +1 -1
- package/dist/default/define/video/minimal-skin.tailwind.js +1 -131
- package/dist/default/define/video/minimal-skin.tailwind.js.map +1 -1
- package/dist/default/define/video/skin.js +1 -116
- package/dist/default/define/video/skin.js.map +1 -1
- package/dist/default/define/video/skin.tailwind.js +1 -124
- package/dist/default/define/video/skin.tailwind.js.map +1 -1
- package/dist/default/media/background-video/index.js +1 -18
- package/dist/default/media/background-video/index.js.map +1 -1
- package/package.json +12 -10
|
@@ -0,0 +1,2057 @@
|
|
|
1
|
+
//#region ../store/dist/dev/core/abort-controller-registry.js
|
|
2
|
+
var AbortControllerRegistry = class {
|
|
3
|
+
#base = new AbortController();
|
|
4
|
+
#keys = /* @__PURE__ */ new Map();
|
|
5
|
+
/** The attach-scoped signal. Aborts on detach or reattach. */
|
|
6
|
+
get base() {
|
|
7
|
+
return this.#base.signal;
|
|
8
|
+
}
|
|
9
|
+
/** Clears all keyed signals, leaving base intact. */
|
|
10
|
+
clear() {
|
|
11
|
+
for (const controller of this.#keys.values()) controller.abort();
|
|
12
|
+
this.#keys.clear();
|
|
13
|
+
}
|
|
14
|
+
/** Resets base and clears all keyed signals. */
|
|
15
|
+
reset() {
|
|
16
|
+
this.clear();
|
|
17
|
+
this.#base.abort();
|
|
18
|
+
this.#base = new AbortController();
|
|
19
|
+
}
|
|
20
|
+
/** Creates a new signal for the key, superseding any previous signal. */
|
|
21
|
+
supersede(key) {
|
|
22
|
+
this.#keys.get(key)?.abort();
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
this.#keys.set(key, controller);
|
|
25
|
+
return AbortSignal.any([this.#base.signal, controller.signal]);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region ../store/dist/dev/core/combine.js
|
|
31
|
+
/**
|
|
32
|
+
* Combines multiple slices into a single slice.
|
|
33
|
+
*
|
|
34
|
+
* @param slices - The slices to combine.
|
|
35
|
+
* @returns A new slice that represents the combination of the input slices.
|
|
36
|
+
*/
|
|
37
|
+
function combine(...slices) {
|
|
38
|
+
return {
|
|
39
|
+
state: (ctx) => {
|
|
40
|
+
const states = slices.map((slice) => slice.state(ctx));
|
|
41
|
+
return Object.assign({}, ...states);
|
|
42
|
+
},
|
|
43
|
+
attach: (ctx) => {
|
|
44
|
+
for (const slice of slices) try {
|
|
45
|
+
slice.attach?.(ctx);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
ctx.reportError(err);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region ../store/dist/dev/core/errors.js
|
|
55
|
+
var StoreError = class extends Error {
|
|
56
|
+
code;
|
|
57
|
+
cause;
|
|
58
|
+
constructor(code, options) {
|
|
59
|
+
super(options?.message ?? code);
|
|
60
|
+
this.name = "StoreError";
|
|
61
|
+
this.code = code;
|
|
62
|
+
this.cause = options?.cause;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
function throwNoTargetError() {
|
|
66
|
+
throw new StoreError("NO_TARGET");
|
|
67
|
+
}
|
|
68
|
+
function throwDestroyedError() {
|
|
69
|
+
throw new StoreError("DESTROYED");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region ../utils/dist/predicate/predicate.js
|
|
74
|
+
function isFunction(value) {
|
|
75
|
+
return typeof value === "function";
|
|
76
|
+
}
|
|
77
|
+
function isNull(value) {
|
|
78
|
+
return value === null;
|
|
79
|
+
}
|
|
80
|
+
function isUndefined(value) {
|
|
81
|
+
return typeof value === "undefined";
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if a value is an object, excluding null.
|
|
85
|
+
*/
|
|
86
|
+
function isObject(value) {
|
|
87
|
+
return value !== null && typeof value === "object";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region ../utils/dist/object/pick.js
|
|
92
|
+
/**
|
|
93
|
+
* Creates a new object with only the specified keys.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
97
|
+
* pick(obj, ['a', 'c']); // { a: 1, c: 3 }
|
|
98
|
+
*/
|
|
99
|
+
function pick(obj, keys) {
|
|
100
|
+
const result = {};
|
|
101
|
+
for (const key of keys) result[key] = obj[key];
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region ../store/dist/dev/core/selector.js
|
|
107
|
+
const stateContext = {
|
|
108
|
+
target: throwNoTargetError,
|
|
109
|
+
signals: new AbortControllerRegistry(),
|
|
110
|
+
set: throwNoTargetError
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Create a type-safe selector for a slice's state.
|
|
114
|
+
*
|
|
115
|
+
* The selector returns the slice's state, or `undefined` if the slice
|
|
116
|
+
* is not configured in the store.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const selectPlayback = createSelector(playbackSlice);
|
|
121
|
+
* selectPlayback(store.state); // { paused, play, pause, ... } | undefined
|
|
122
|
+
* selectPlayback.displayName; // 'playback' (from slice name)
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @param slice - The slice to create a selector for.
|
|
126
|
+
*/
|
|
127
|
+
function createSelector(slice) {
|
|
128
|
+
const initialState = slice.state(stateContext);
|
|
129
|
+
const keys = Object.keys(initialState);
|
|
130
|
+
const firstKey = keys[0];
|
|
131
|
+
if (!firstKey) return Object.assign(() => void 0, { displayName: slice.name });
|
|
132
|
+
return Object.assign((state) => {
|
|
133
|
+
if (!(firstKey in state)) return void 0;
|
|
134
|
+
return pick(state, keys);
|
|
135
|
+
}, { displayName: slice.name });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region ../store/dist/dev/core/shallow-equal.js
|
|
140
|
+
const hasOwn = Object.prototype.hasOwnProperty;
|
|
141
|
+
function shallowEqual(a, b) {
|
|
142
|
+
if (Object.is(a, b)) return true;
|
|
143
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) return false;
|
|
144
|
+
const keysA = Object.keys(a);
|
|
145
|
+
const keysB = Object.keys(b);
|
|
146
|
+
if (keysA.length !== keysB.length) return false;
|
|
147
|
+
for (const key of keysA) if (!hasOwn.call(b, key) || !Object.is(a[key], b[key])) return false;
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region ../store/dist/dev/core/slice.js
|
|
153
|
+
function defineSlice() {
|
|
154
|
+
return (config) => config;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region ../utils/dist/function/noop.js
|
|
159
|
+
function noop(..._args) {}
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region ../store/dist/dev/core/state.js
|
|
163
|
+
let isFlushScheduled = false;
|
|
164
|
+
function scheduleFlush() {
|
|
165
|
+
if (isFlushScheduled) return;
|
|
166
|
+
isFlushScheduled = true;
|
|
167
|
+
queueMicrotask(flush);
|
|
168
|
+
}
|
|
169
|
+
const pendingContainers = /* @__PURE__ */ new Set();
|
|
170
|
+
function flush() {
|
|
171
|
+
isFlushScheduled = false;
|
|
172
|
+
for (const container of pendingContainers) container.flush();
|
|
173
|
+
pendingContainers.clear();
|
|
174
|
+
}
|
|
175
|
+
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
176
|
+
var StateContainer = class {
|
|
177
|
+
#current;
|
|
178
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
179
|
+
#pending = false;
|
|
180
|
+
constructor(initial) {
|
|
181
|
+
this.#current = Object.freeze({ ...initial });
|
|
182
|
+
}
|
|
183
|
+
get current() {
|
|
184
|
+
return this.#current;
|
|
185
|
+
}
|
|
186
|
+
patch(partial) {
|
|
187
|
+
const next = { ...this.#current };
|
|
188
|
+
let changed = false;
|
|
189
|
+
for (const key in partial) {
|
|
190
|
+
if (!hasOwnProp.call(partial, key)) continue;
|
|
191
|
+
const value = partial[key];
|
|
192
|
+
if (!Object.is(this.#current[key], value)) {
|
|
193
|
+
next[key] = value;
|
|
194
|
+
changed = true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (changed) {
|
|
198
|
+
this.#current = Object.freeze(next);
|
|
199
|
+
this.#markPending();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
subscribe(callback, options) {
|
|
203
|
+
const signal = options?.signal;
|
|
204
|
+
if (signal?.aborted) return noop;
|
|
205
|
+
this.#listeners.add(callback);
|
|
206
|
+
if (!signal) return () => this.#listeners.delete(callback);
|
|
207
|
+
const onAbort = () => this.#listeners.delete(callback);
|
|
208
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
209
|
+
return () => {
|
|
210
|
+
signal.removeEventListener("abort", onAbort);
|
|
211
|
+
this.#listeners.delete(callback);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
flush() {
|
|
215
|
+
if (!this.#pending) return;
|
|
216
|
+
this.#pending = false;
|
|
217
|
+
for (const fn of this.#listeners) fn();
|
|
218
|
+
}
|
|
219
|
+
#markPending() {
|
|
220
|
+
this.#pending = true;
|
|
221
|
+
pendingContainers.add(this);
|
|
222
|
+
scheduleFlush();
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
function createState(initial) {
|
|
226
|
+
return new StateContainer(initial);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region ../store/dist/dev/core/store.js
|
|
231
|
+
const STORE_SYMBOL = Symbol("@videojs/store");
|
|
232
|
+
function createStore() {
|
|
233
|
+
return (slice, options = {}) => {
|
|
234
|
+
let target = null;
|
|
235
|
+
let destroyed = false;
|
|
236
|
+
const setupAbort = new AbortController();
|
|
237
|
+
const signals = new AbortControllerRegistry();
|
|
238
|
+
let state;
|
|
239
|
+
function validate() {
|
|
240
|
+
if (destroyed) throwDestroyedError();
|
|
241
|
+
if (!target) throwNoTargetError();
|
|
242
|
+
}
|
|
243
|
+
const initialState = slice.state({
|
|
244
|
+
target: () => {
|
|
245
|
+
validate();
|
|
246
|
+
return target;
|
|
247
|
+
},
|
|
248
|
+
signals,
|
|
249
|
+
set: (partial) => state.patch(partial)
|
|
250
|
+
});
|
|
251
|
+
state = createState(initialState);
|
|
252
|
+
const store = {
|
|
253
|
+
[STORE_SYMBOL]: true,
|
|
254
|
+
get $state() {
|
|
255
|
+
return state;
|
|
256
|
+
},
|
|
257
|
+
get target() {
|
|
258
|
+
return target;
|
|
259
|
+
},
|
|
260
|
+
get destroyed() {
|
|
261
|
+
return destroyed;
|
|
262
|
+
},
|
|
263
|
+
get state() {
|
|
264
|
+
return state.current;
|
|
265
|
+
},
|
|
266
|
+
attach,
|
|
267
|
+
destroy,
|
|
268
|
+
subscribe
|
|
269
|
+
};
|
|
270
|
+
for (const key of Object.keys(initialState)) Object.defineProperty(store, key, {
|
|
271
|
+
get: () => state.current[key],
|
|
272
|
+
enumerable: true
|
|
273
|
+
});
|
|
274
|
+
try {
|
|
275
|
+
options.onSetup?.({
|
|
276
|
+
store,
|
|
277
|
+
signal: setupAbort.signal
|
|
278
|
+
});
|
|
279
|
+
} catch (error) {
|
|
280
|
+
reportError(error);
|
|
281
|
+
}
|
|
282
|
+
return store;
|
|
283
|
+
function attach(newTarget) {
|
|
284
|
+
if (destroyed) throwDestroyedError();
|
|
285
|
+
signals.reset();
|
|
286
|
+
target = newTarget;
|
|
287
|
+
const attachContext = {
|
|
288
|
+
target: newTarget,
|
|
289
|
+
signal: signals.base,
|
|
290
|
+
get: () => state.current,
|
|
291
|
+
set: (partial) => state.patch(partial),
|
|
292
|
+
reportError,
|
|
293
|
+
store: {
|
|
294
|
+
get state() {
|
|
295
|
+
return state.current;
|
|
296
|
+
},
|
|
297
|
+
subscribe
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
try {
|
|
301
|
+
slice.attach?.(attachContext);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
reportError(error);
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
options.onAttach?.({
|
|
307
|
+
store,
|
|
308
|
+
target: newTarget,
|
|
309
|
+
signal: signals.base
|
|
310
|
+
});
|
|
311
|
+
} catch (error) {
|
|
312
|
+
reportError(error);
|
|
313
|
+
}
|
|
314
|
+
return detach;
|
|
315
|
+
}
|
|
316
|
+
function detach() {
|
|
317
|
+
if (isNull(target)) return;
|
|
318
|
+
signals.reset();
|
|
319
|
+
target = null;
|
|
320
|
+
state.patch(initialState);
|
|
321
|
+
}
|
|
322
|
+
function destroy() {
|
|
323
|
+
if (destroyed) return;
|
|
324
|
+
destroyed = true;
|
|
325
|
+
detach();
|
|
326
|
+
setupAbort.abort();
|
|
327
|
+
}
|
|
328
|
+
function subscribe(callback, options) {
|
|
329
|
+
return state.subscribe(callback, options);
|
|
330
|
+
}
|
|
331
|
+
function reportError(error) {
|
|
332
|
+
if (options.onError) options.onError({
|
|
333
|
+
store,
|
|
334
|
+
error
|
|
335
|
+
});
|
|
336
|
+
else console.error("[vjs-store]", error);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function isStore(value) {
|
|
341
|
+
return isObject(value) && STORE_SYMBOL in value;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region ../core/dist/dev/dom/feature.js
|
|
346
|
+
const definePlayerFeature = defineSlice();
|
|
347
|
+
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region ../utils/dist/dom/attributes.js
|
|
350
|
+
function namedNodeMapToObject(namedNodeMap) {
|
|
351
|
+
const obj = {};
|
|
352
|
+
for (const attr of namedNodeMap) obj[attr.name] = attr.value;
|
|
353
|
+
return obj;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region ../utils/dist/dom/event.js
|
|
358
|
+
function onEvent(target, type, options) {
|
|
359
|
+
return new Promise((resolve, reject) => {
|
|
360
|
+
const handleAbort = () => {
|
|
361
|
+
reject(options?.signal?.reason ?? "Aborted");
|
|
362
|
+
};
|
|
363
|
+
if (options?.signal?.aborted) {
|
|
364
|
+
handleAbort();
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
options?.signal?.addEventListener("abort", handleAbort, { once: true });
|
|
368
|
+
target.addEventListener(type, (event) => {
|
|
369
|
+
options?.signal?.removeEventListener("abort", handleAbort);
|
|
370
|
+
resolve(event);
|
|
371
|
+
}, {
|
|
372
|
+
...options,
|
|
373
|
+
once: true
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region ../utils/dist/dom/listen.js
|
|
380
|
+
function listen(target, type, listener, options) {
|
|
381
|
+
target.addEventListener(type, listener, options);
|
|
382
|
+
return () => target.removeEventListener(type, listener, options);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region ../utils/dist/dom/text-track.js
|
|
387
|
+
/** Find the `<track>` element that owns the given `TextTrack`. */
|
|
388
|
+
function findTrackElement(media, track) {
|
|
389
|
+
for (const el of media.querySelectorAll("track")) if (el.track === track) return el;
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
function getTextTrackList(media, filterPred) {
|
|
393
|
+
if (!media?.textTracks) return [];
|
|
394
|
+
return Array.from(media.textTracks).filter(filterPred).sort(sortByTextTrackKind);
|
|
395
|
+
}
|
|
396
|
+
function sortByTextTrackKind(a, b) {
|
|
397
|
+
return a.kind >= b.kind ? 1 : -1;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region ../utils/dist/dom/time-ranges.js
|
|
402
|
+
/** Converts a TimeRanges object to an array of [start, end] tuples. */
|
|
403
|
+
function serializeTimeRanges(ranges) {
|
|
404
|
+
const result = [];
|
|
405
|
+
for (let i = 0; i < ranges.length; i++) result.push([ranges.start(i), ranges.end(i)]);
|
|
406
|
+
return result;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region ../core/dist/dev/dom/store/features/buffer.js
|
|
411
|
+
const bufferFeature = definePlayerFeature({
|
|
412
|
+
name: "buffer",
|
|
413
|
+
state: () => ({
|
|
414
|
+
buffered: [],
|
|
415
|
+
seekable: []
|
|
416
|
+
}),
|
|
417
|
+
attach({ target, signal, set }) {
|
|
418
|
+
const { media } = target;
|
|
419
|
+
const sync = () => set({
|
|
420
|
+
buffered: serializeTimeRanges(media.buffered),
|
|
421
|
+
seekable: serializeTimeRanges(media.seekable)
|
|
422
|
+
});
|
|
423
|
+
sync();
|
|
424
|
+
listen(media, "progress", sync, { signal });
|
|
425
|
+
listen(media, "emptied", sync, { signal });
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region ../core/dist/dev/dom/store/features/controls.js
|
|
431
|
+
const IDLE_DELAY = 2e3;
|
|
432
|
+
const TAP_THRESHOLD = 250;
|
|
433
|
+
const controlsFeature = definePlayerFeature({
|
|
434
|
+
name: "controls",
|
|
435
|
+
state: () => ({
|
|
436
|
+
userActive: true,
|
|
437
|
+
controlsVisible: true
|
|
438
|
+
}),
|
|
439
|
+
attach({ target, signal, get, set }) {
|
|
440
|
+
const { media, container } = target;
|
|
441
|
+
if (isNull(container)) {
|
|
442
|
+
console.warn("[vjs] controlsFeature requires a container element for activity tracking.");
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
function computeVisible(userActive) {
|
|
446
|
+
return userActive || media.paused;
|
|
447
|
+
}
|
|
448
|
+
let idleTimer;
|
|
449
|
+
function clearIdle() {
|
|
450
|
+
clearTimeout(idleTimer);
|
|
451
|
+
idleTimer = void 0;
|
|
452
|
+
}
|
|
453
|
+
function scheduleIdle() {
|
|
454
|
+
clearIdle();
|
|
455
|
+
idleTimer = setTimeout(setInactive, IDLE_DELAY);
|
|
456
|
+
}
|
|
457
|
+
function setActive() {
|
|
458
|
+
if (!get().userActive) set({
|
|
459
|
+
userActive: true,
|
|
460
|
+
controlsVisible: true
|
|
461
|
+
});
|
|
462
|
+
scheduleIdle();
|
|
463
|
+
}
|
|
464
|
+
function setInactive() {
|
|
465
|
+
clearIdle();
|
|
466
|
+
set({
|
|
467
|
+
userActive: false,
|
|
468
|
+
controlsVisible: computeVisible(false)
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
let pointerDownTime = 0;
|
|
472
|
+
function onPointerDown() {
|
|
473
|
+
pointerDownTime = Date.now();
|
|
474
|
+
}
|
|
475
|
+
function onPointerUp(event) {
|
|
476
|
+
if (event.pointerType === "touch" && Date.now() - pointerDownTime < TAP_THRESHOLD) if (get().controlsVisible) {
|
|
477
|
+
clearIdle();
|
|
478
|
+
set({
|
|
479
|
+
userActive: false,
|
|
480
|
+
controlsVisible: computeVisible(false)
|
|
481
|
+
});
|
|
482
|
+
} else setActive();
|
|
483
|
+
else setActive();
|
|
484
|
+
}
|
|
485
|
+
function onPlaybackChange() {
|
|
486
|
+
const { userActive } = get();
|
|
487
|
+
set({ controlsVisible: computeVisible(userActive) });
|
|
488
|
+
if (!media.paused && userActive) scheduleIdle();
|
|
489
|
+
}
|
|
490
|
+
listen(container, "pointermove", setActive, { signal });
|
|
491
|
+
listen(container, "pointerdown", onPointerDown, { signal });
|
|
492
|
+
listen(container, "pointerup", onPointerUp, { signal });
|
|
493
|
+
listen(container, "keyup", setActive, { signal });
|
|
494
|
+
listen(container, "focusin", setActive, { signal });
|
|
495
|
+
listen(container, "pointerleave", setInactive, { signal });
|
|
496
|
+
listen(media, "play", onPlaybackChange, { signal });
|
|
497
|
+
listen(media, "pause", onPlaybackChange, { signal });
|
|
498
|
+
listen(media, "ended", onPlaybackChange, { signal });
|
|
499
|
+
signal.addEventListener("abort", clearIdle, { once: true });
|
|
500
|
+
scheduleIdle();
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region ../core/dist/dev/dom/store/features/error.js
|
|
506
|
+
const errorFeature = definePlayerFeature({
|
|
507
|
+
name: "error",
|
|
508
|
+
state: ({ set }) => ({
|
|
509
|
+
error: null,
|
|
510
|
+
dismissError() {
|
|
511
|
+
set({ error: null });
|
|
512
|
+
}
|
|
513
|
+
}),
|
|
514
|
+
attach({ target, signal, set }) {
|
|
515
|
+
const { media } = target;
|
|
516
|
+
const syncError = () => set({ error: media.error });
|
|
517
|
+
listen(media, "error", syncError, { signal });
|
|
518
|
+
listen(media, "emptied", () => set({ error: null }), { signal });
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region ../core/dist/dev/dom/presentation/fullscreen.js
|
|
524
|
+
/** Check if the Fullscreen API is supported on this platform. */
|
|
525
|
+
function isFullscreenEnabled() {
|
|
526
|
+
const doc = document;
|
|
527
|
+
if (doc.fullscreenEnabled || doc.webkitFullscreenEnabled) return true;
|
|
528
|
+
return document.createElement("video").webkitSupportsFullscreen === true;
|
|
529
|
+
}
|
|
530
|
+
/** Get the current fullscreen element from the document. */
|
|
531
|
+
function getFullscreenElement() {
|
|
532
|
+
const doc = document;
|
|
533
|
+
return doc.fullscreenElement ?? doc.webkitFullscreenElement ?? null;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Check if a specific element (or its media) is currently in fullscreen.
|
|
537
|
+
*
|
|
538
|
+
* Uses `:fullscreen` pseudo-class which works across Shadow DOM boundaries.
|
|
539
|
+
*/
|
|
540
|
+
function isFullscreenElement(container, media) {
|
|
541
|
+
const video = media;
|
|
542
|
+
if (video.webkitDisplayingFullscreen && video.webkitPresentationMode === "fullscreen") return true;
|
|
543
|
+
const target = container ?? media;
|
|
544
|
+
if (getFullscreenElement() === target) return true;
|
|
545
|
+
try {
|
|
546
|
+
return target.matches(":fullscreen");
|
|
547
|
+
} catch {
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Request fullscreen mode.
|
|
553
|
+
*
|
|
554
|
+
* Tries container first (to show custom UI), falls back to media element
|
|
555
|
+
* for platforms that only support video fullscreen (iOS Safari).
|
|
556
|
+
*/
|
|
557
|
+
async function requestFullscreen(container, media) {
|
|
558
|
+
const video = media;
|
|
559
|
+
if (container) {
|
|
560
|
+
const el = container;
|
|
561
|
+
if (isFunction(el.requestFullscreen)) return el.requestFullscreen();
|
|
562
|
+
if (isFunction(el.webkitRequestFullscreen)) return el.webkitRequestFullscreen();
|
|
563
|
+
if (isFunction(el.webkitRequestFullScreen)) return el.webkitRequestFullScreen();
|
|
564
|
+
}
|
|
565
|
+
if (isFunction(video.webkitEnterFullscreen)) {
|
|
566
|
+
video.webkitEnterFullscreen();
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (isFunction(media.requestFullscreen)) return media.requestFullscreen();
|
|
570
|
+
throw new DOMException("Fullscreen not supported", "NotSupportedError");
|
|
571
|
+
}
|
|
572
|
+
/** Exit fullscreen mode. */
|
|
573
|
+
async function exitFullscreen() {
|
|
574
|
+
const doc = document;
|
|
575
|
+
const video = getFullscreenElement();
|
|
576
|
+
if (isFunction(doc.exitFullscreen)) return doc.exitFullscreen();
|
|
577
|
+
if (isFunction(doc.webkitExitFullscreen)) return doc.webkitExitFullscreen();
|
|
578
|
+
if (isFunction(doc.webkitCancelFullScreen)) return doc.webkitCancelFullScreen();
|
|
579
|
+
if (video && isFunction(video.webkitExitFullscreen)) {
|
|
580
|
+
video.webkitExitFullscreen();
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
//#endregion
|
|
586
|
+
//#region ../core/dist/dev/dom/presentation/pip.js
|
|
587
|
+
/**
|
|
588
|
+
* Check if Picture-in-Picture is supported on this platform.
|
|
589
|
+
*
|
|
590
|
+
* Note: Safari PWAs don't support PiP even though the API exists.
|
|
591
|
+
*/
|
|
592
|
+
function isPictureInPictureEnabled() {
|
|
593
|
+
if (document.pictureInPictureEnabled) {
|
|
594
|
+
const isSafari = /.*Version\/.*Safari\/.*/.test(navigator.userAgent);
|
|
595
|
+
const isPWA = typeof matchMedia === "function" && matchMedia("(display-mode: standalone)").matches;
|
|
596
|
+
return !isSafari || !isPWA;
|
|
597
|
+
}
|
|
598
|
+
return isFunction(document.createElement("video").webkitSetPresentationMode);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Check if Picture-in-Picture is currently active for a media element.
|
|
602
|
+
*/
|
|
603
|
+
function isPictureInPictureElement(media) {
|
|
604
|
+
if (document.pictureInPictureElement === media) return true;
|
|
605
|
+
return media.webkitPresentationMode === "picture-in-picture";
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Request Picture-in-Picture mode.
|
|
609
|
+
*
|
|
610
|
+
* Uses standard API where available, falls back to iOS Safari's
|
|
611
|
+
* WebKit presentation mode.
|
|
612
|
+
*/
|
|
613
|
+
async function requestPictureInPicture(media) {
|
|
614
|
+
const video = media;
|
|
615
|
+
if (isFunction(video.requestPictureInPicture)) {
|
|
616
|
+
await video.requestPictureInPicture();
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
if (isFunction(video.webkitSetPresentationMode)) {
|
|
620
|
+
video.webkitSetPresentationMode("picture-in-picture");
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
throw new DOMException("Picture-in-Picture not supported", "NotSupportedError");
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Exit Picture-in-Picture mode.
|
|
627
|
+
*
|
|
628
|
+
* Uses standard API where available, falls back to iOS Safari's
|
|
629
|
+
* WebKit presentation mode.
|
|
630
|
+
*/
|
|
631
|
+
async function exitPictureInPicture(media) {
|
|
632
|
+
if (document.pictureInPictureElement && isFunction(document.exitPictureInPicture)) {
|
|
633
|
+
await document.exitPictureInPicture();
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
if (media) {
|
|
637
|
+
const video = media;
|
|
638
|
+
if (video.webkitPresentationMode === "picture-in-picture" && isFunction(video.webkitSetPresentationMode)) {
|
|
639
|
+
video.webkitSetPresentationMode("inline");
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
//#endregion
|
|
646
|
+
//#region ../core/dist/dev/dom/store/features/fullscreen.js
|
|
647
|
+
const fullscreenFeature = definePlayerFeature({
|
|
648
|
+
name: "fullscreen",
|
|
649
|
+
state: ({ target }) => ({
|
|
650
|
+
fullscreen: false,
|
|
651
|
+
fullscreenAvailability: "unavailable",
|
|
652
|
+
async requestFullscreen() {
|
|
653
|
+
const { media, container } = target();
|
|
654
|
+
if (isPictureInPictureElement(media)) await exitPictureInPicture(media);
|
|
655
|
+
return requestFullscreen(container, media);
|
|
656
|
+
},
|
|
657
|
+
async exitFullscreen() {
|
|
658
|
+
return exitFullscreen();
|
|
659
|
+
}
|
|
660
|
+
}),
|
|
661
|
+
attach({ target, signal, set }) {
|
|
662
|
+
const { media, container } = target;
|
|
663
|
+
set({ fullscreenAvailability: isFullscreenEnabled() ? "available" : "unsupported" });
|
|
664
|
+
const sync = () => set({ fullscreen: isFullscreenElement(container, media) });
|
|
665
|
+
sync();
|
|
666
|
+
listen(document, "fullscreenchange", sync, { signal });
|
|
667
|
+
listen(document, "webkitfullscreenchange", sync, { signal });
|
|
668
|
+
if ("webkitPresentationMode" in media) listen(media, "webkitpresentationmodechanged", sync, { signal });
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
//#endregion
|
|
673
|
+
//#region ../core/dist/dev/dom/store/features/pip.js
|
|
674
|
+
const pipFeature = definePlayerFeature({
|
|
675
|
+
name: "pip",
|
|
676
|
+
state: ({ target }) => ({
|
|
677
|
+
pip: false,
|
|
678
|
+
pipAvailability: "unavailable",
|
|
679
|
+
async requestPictureInPicture() {
|
|
680
|
+
const { media, container } = target();
|
|
681
|
+
if (isFullscreenElement(container, media)) await exitFullscreen();
|
|
682
|
+
return requestPictureInPicture(media);
|
|
683
|
+
},
|
|
684
|
+
async exitPictureInPicture() {
|
|
685
|
+
const { media } = target();
|
|
686
|
+
return exitPictureInPicture(media);
|
|
687
|
+
}
|
|
688
|
+
}),
|
|
689
|
+
attach({ target, signal, set }) {
|
|
690
|
+
const { media } = target;
|
|
691
|
+
set({ pipAvailability: isPictureInPictureEnabled() ? "available" : "unsupported" });
|
|
692
|
+
const sync = () => set({ pip: isPictureInPictureElement(media) });
|
|
693
|
+
sync();
|
|
694
|
+
listen(media, "enterpictureinpicture", sync, { signal });
|
|
695
|
+
listen(media, "leavepictureinpicture", sync, { signal });
|
|
696
|
+
if ("webkitPresentationMode" in media) listen(media, "webkitpresentationmodechanged", sync, { signal });
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region ../core/dist/dev/dom/store/features/playback.js
|
|
702
|
+
const playbackFeature = definePlayerFeature({
|
|
703
|
+
name: "playback",
|
|
704
|
+
state: ({ target }) => ({
|
|
705
|
+
paused: true,
|
|
706
|
+
ended: false,
|
|
707
|
+
started: false,
|
|
708
|
+
waiting: false,
|
|
709
|
+
play() {
|
|
710
|
+
return target().media.play();
|
|
711
|
+
},
|
|
712
|
+
pause() {
|
|
713
|
+
target().media.pause();
|
|
714
|
+
}
|
|
715
|
+
}),
|
|
716
|
+
attach({ target, signal, set }) {
|
|
717
|
+
const { media } = target;
|
|
718
|
+
const sync = () => set({
|
|
719
|
+
paused: media.paused,
|
|
720
|
+
ended: media.ended,
|
|
721
|
+
started: !media.paused || media.currentTime > 0,
|
|
722
|
+
waiting: media.readyState < HTMLMediaElement.HAVE_FUTURE_DATA && !media.paused
|
|
723
|
+
});
|
|
724
|
+
sync();
|
|
725
|
+
listen(media, "emptied", sync, { signal });
|
|
726
|
+
listen(media, "play", sync, { signal });
|
|
727
|
+
listen(media, "pause", sync, { signal });
|
|
728
|
+
listen(media, "ended", sync, { signal });
|
|
729
|
+
listen(media, "playing", sync, { signal });
|
|
730
|
+
listen(media, "waiting", sync, { signal });
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region ../core/dist/dev/dom/store/features/playback-rate.js
|
|
736
|
+
const DEFAULT_RATES = [
|
|
737
|
+
1,
|
|
738
|
+
1.2,
|
|
739
|
+
1.5,
|
|
740
|
+
1.7,
|
|
741
|
+
2
|
|
742
|
+
];
|
|
743
|
+
const playbackRateFeature = definePlayerFeature({
|
|
744
|
+
name: "playbackRate",
|
|
745
|
+
state: ({ target }) => ({
|
|
746
|
+
playbackRates: DEFAULT_RATES,
|
|
747
|
+
playbackRate: 1,
|
|
748
|
+
setPlaybackRate(rate) {
|
|
749
|
+
target().media.playbackRate = rate;
|
|
750
|
+
}
|
|
751
|
+
}),
|
|
752
|
+
attach({ target, signal, set }) {
|
|
753
|
+
const { media } = target;
|
|
754
|
+
const sync = () => set({ playbackRate: media.playbackRate });
|
|
755
|
+
sync();
|
|
756
|
+
listen(media, "ratechange", sync, { signal });
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
//#endregion
|
|
761
|
+
//#region ../core/dist/dev/dom/store/features/source.js
|
|
762
|
+
const sourceFeature = definePlayerFeature({
|
|
763
|
+
name: "source",
|
|
764
|
+
state: ({ target, signals }) => ({
|
|
765
|
+
source: null,
|
|
766
|
+
canPlay: false,
|
|
767
|
+
loadSource(src) {
|
|
768
|
+
signals.clear();
|
|
769
|
+
const { media } = target();
|
|
770
|
+
media.src = src;
|
|
771
|
+
media.load();
|
|
772
|
+
return src;
|
|
773
|
+
}
|
|
774
|
+
}),
|
|
775
|
+
attach({ target, signal, set }) {
|
|
776
|
+
const { media } = target;
|
|
777
|
+
const sync = () => set({
|
|
778
|
+
source: media.currentSrc || media.src || null,
|
|
779
|
+
canPlay: media.readyState >= HTMLMediaElement.HAVE_ENOUGH_DATA
|
|
780
|
+
});
|
|
781
|
+
sync();
|
|
782
|
+
listen(media, "canplay", sync, { signal });
|
|
783
|
+
listen(media, "canplaythrough", sync, { signal });
|
|
784
|
+
listen(media, "loadstart", sync, { signal });
|
|
785
|
+
listen(media, "emptied", sync, { signal });
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
//#endregion
|
|
790
|
+
//#region ../core/dist/dev/dom/store/features/text-track.js
|
|
791
|
+
const textTrackFeature = definePlayerFeature({
|
|
792
|
+
name: "textTrack",
|
|
793
|
+
state: ({ target }) => ({
|
|
794
|
+
chaptersCues: [],
|
|
795
|
+
thumbnailCues: [],
|
|
796
|
+
thumbnailTrackSrc: null,
|
|
797
|
+
textTrackList: [],
|
|
798
|
+
subtitlesShowing: false,
|
|
799
|
+
toggleSubtitles(forceShow) {
|
|
800
|
+
const subtitlesTracks = getTextTrackList(target().media, (track) => track.kind === "subtitles" || track.kind === "captions");
|
|
801
|
+
if (!subtitlesTracks.length) return false;
|
|
802
|
+
const showing = subtitlesTracks.some((track) => track.mode === "showing");
|
|
803
|
+
const nextShowing = forceShow ?? !showing;
|
|
804
|
+
for (const track of subtitlesTracks) track.mode = nextShowing ? "showing" : "disabled";
|
|
805
|
+
return nextShowing;
|
|
806
|
+
}
|
|
807
|
+
}),
|
|
808
|
+
attach({ target, signal, set }) {
|
|
809
|
+
const { media } = target;
|
|
810
|
+
let trackCleanup = null;
|
|
811
|
+
function sync() {
|
|
812
|
+
trackCleanup?.abort();
|
|
813
|
+
trackCleanup = new AbortController();
|
|
814
|
+
let chaptersTrack = null;
|
|
815
|
+
let thumbnailTrack = null;
|
|
816
|
+
const textTrackList = [];
|
|
817
|
+
let subtitlesShowing = false;
|
|
818
|
+
for (let i = 0; i < media.textTracks.length; i++) {
|
|
819
|
+
const track = media.textTracks[i];
|
|
820
|
+
if (!chaptersTrack && track.kind === "chapters") chaptersTrack = track;
|
|
821
|
+
if (!thumbnailTrack && track.kind === "metadata" && track.label === "thumbnails") thumbnailTrack = track;
|
|
822
|
+
textTrackList.push({
|
|
823
|
+
kind: track.kind,
|
|
824
|
+
label: track.label,
|
|
825
|
+
language: track.language,
|
|
826
|
+
mode: track.mode
|
|
827
|
+
});
|
|
828
|
+
if ((track.kind === "captions" || track.kind === "subtitles") && track.mode === "showing") subtitlesShowing = true;
|
|
829
|
+
}
|
|
830
|
+
const chaptersCues = chaptersTrack?.cues ? Array.from(chaptersTrack.cues) : [];
|
|
831
|
+
const thumbnailCues = thumbnailTrack?.cues ? Array.from(thumbnailTrack.cues) : [];
|
|
832
|
+
let thumbnailTrackSrc = null;
|
|
833
|
+
if (thumbnailTrack) thumbnailTrackSrc = findTrackElement(media, thumbnailTrack)?.src ?? null;
|
|
834
|
+
for (const trackEl of media.querySelectorAll?.("track") ?? []) if (!trackEl.track?.cues?.length) listen(trackEl, "load", sync, { signal: trackCleanup.signal });
|
|
835
|
+
set({
|
|
836
|
+
chaptersCues,
|
|
837
|
+
thumbnailCues,
|
|
838
|
+
thumbnailTrackSrc,
|
|
839
|
+
textTrackList,
|
|
840
|
+
subtitlesShowing
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
sync();
|
|
844
|
+
listen(media.textTracks, "addtrack", sync, { signal });
|
|
845
|
+
listen(media.textTracks, "removetrack", sync, { signal });
|
|
846
|
+
listen(media.textTracks, "change", sync, { signal });
|
|
847
|
+
listen(media, "loadstart", sync, { signal });
|
|
848
|
+
signal.addEventListener("abort", () => trackCleanup?.abort(), { once: true });
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region ../core/dist/dev/dom/media/predicate.js
|
|
854
|
+
function hasMetadata(media) {
|
|
855
|
+
return media.readyState >= HTMLMediaElement.HAVE_METADATA;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
//#endregion
|
|
859
|
+
//#region ../core/dist/dev/dom/store/signal-keys.js
|
|
860
|
+
const signalKeys = { seek: Symbol.for("@videojs/seek") };
|
|
861
|
+
|
|
862
|
+
//#endregion
|
|
863
|
+
//#region ../core/dist/dev/dom/store/features/time.js
|
|
864
|
+
const timeFeature = definePlayerFeature({
|
|
865
|
+
name: "time",
|
|
866
|
+
state: ({ target, signals, set }) => ({
|
|
867
|
+
currentTime: 0,
|
|
868
|
+
duration: 0,
|
|
869
|
+
seeking: false,
|
|
870
|
+
async seek(time) {
|
|
871
|
+
const { media } = target(), signal = signals.supersede(signalKeys.seek);
|
|
872
|
+
if (!hasMetadata(media)) {
|
|
873
|
+
if (!await onEvent(media, "loadedmetadata", { signal }).catch(() => false)) return media.currentTime;
|
|
874
|
+
}
|
|
875
|
+
const clampedTime = Math.max(0, Math.min(time, media.duration || Infinity));
|
|
876
|
+
set({
|
|
877
|
+
currentTime: clampedTime,
|
|
878
|
+
seeking: true
|
|
879
|
+
});
|
|
880
|
+
media.currentTime = clampedTime;
|
|
881
|
+
await onEvent(media, "seeked", { signal }).catch(noop);
|
|
882
|
+
return media.currentTime;
|
|
883
|
+
}
|
|
884
|
+
}),
|
|
885
|
+
attach({ target, signal, set }) {
|
|
886
|
+
const { media } = target;
|
|
887
|
+
const sync = () => set({
|
|
888
|
+
currentTime: media.currentTime,
|
|
889
|
+
duration: Number.isFinite(media.duration) ? media.duration : 0,
|
|
890
|
+
seeking: media.seeking
|
|
891
|
+
});
|
|
892
|
+
sync();
|
|
893
|
+
listen(media, "timeupdate", sync, { signal });
|
|
894
|
+
listen(media, "durationchange", sync, { signal });
|
|
895
|
+
listen(media, "seeking", sync, { signal });
|
|
896
|
+
listen(media, "seeked", sync, { signal });
|
|
897
|
+
listen(media, "loadedmetadata", sync, { signal });
|
|
898
|
+
listen(media, "emptied", sync, { signal });
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
//#endregion
|
|
903
|
+
//#region ../core/dist/dev/dom/store/features/volume.js
|
|
904
|
+
/** Volume to restore when unmuting at zero. */
|
|
905
|
+
const UNMUTE_VOLUME = .25;
|
|
906
|
+
const volumeFeature = definePlayerFeature({
|
|
907
|
+
name: "volume",
|
|
908
|
+
state: ({ target }) => ({
|
|
909
|
+
volume: 1,
|
|
910
|
+
muted: false,
|
|
911
|
+
volumeAvailability: "unavailable",
|
|
912
|
+
setVolume(volume) {
|
|
913
|
+
const { media } = target();
|
|
914
|
+
const clamped = Math.max(0, Math.min(1, volume));
|
|
915
|
+
if (clamped > 0 && media.muted) media.muted = false;
|
|
916
|
+
media.volume = clamped;
|
|
917
|
+
return media.volume;
|
|
918
|
+
},
|
|
919
|
+
toggleMuted() {
|
|
920
|
+
const { media } = target();
|
|
921
|
+
if (media.muted || media.volume === 0) {
|
|
922
|
+
media.muted = false;
|
|
923
|
+
if (media.volume === 0) media.volume = UNMUTE_VOLUME;
|
|
924
|
+
} else media.muted = true;
|
|
925
|
+
return media.muted;
|
|
926
|
+
}
|
|
927
|
+
}),
|
|
928
|
+
attach({ target, signal, set }) {
|
|
929
|
+
const { media } = target;
|
|
930
|
+
set({ volumeAvailability: canSetVolume() });
|
|
931
|
+
const sync = () => set({
|
|
932
|
+
volume: media.volume,
|
|
933
|
+
muted: media.muted
|
|
934
|
+
});
|
|
935
|
+
sync();
|
|
936
|
+
listen(media, "volumechange", sync, { signal });
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
/** Check if volume can be programmatically set (fails on iOS Safari). */
|
|
940
|
+
function canSetVolume() {
|
|
941
|
+
const video = document.createElement("video");
|
|
942
|
+
try {
|
|
943
|
+
video.volume = .5;
|
|
944
|
+
return video.volume === .5 ? "available" : "unsupported";
|
|
945
|
+
} catch {
|
|
946
|
+
return "unsupported";
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
//#endregion
|
|
951
|
+
//#region ../core/dist/dev/dom/store/features/presets.js
|
|
952
|
+
const backgroundFeatures = [];
|
|
953
|
+
|
|
954
|
+
//#endregion
|
|
955
|
+
//#region ../core/dist/dev/dom/store/selectors.js
|
|
956
|
+
/** Select the buffer state (buffered ranges, percent buffered). */
|
|
957
|
+
const selectBuffer = createSelector(bufferFeature);
|
|
958
|
+
/** Select the controls state (controls visible, user-active). */
|
|
959
|
+
const selectControls = createSelector(controlsFeature);
|
|
960
|
+
/** Select the error state (error, dismissed, dismissError). */
|
|
961
|
+
const selectError = createSelector(errorFeature);
|
|
962
|
+
/** Select the fullscreen state (fullscreen active, availability). */
|
|
963
|
+
const selectFullscreen = createSelector(fullscreenFeature);
|
|
964
|
+
/** Select the PiP state (picture-in-picture active, availability). */
|
|
965
|
+
const selectPiP = createSelector(pipFeature);
|
|
966
|
+
/** Select the playback state (paused, ended, play, pause, toggle). */
|
|
967
|
+
const selectPlayback = createSelector(playbackFeature);
|
|
968
|
+
/** Select the playback rate state (playbackRate, playbackRates, setPlaybackRate). */
|
|
969
|
+
const selectPlaybackRate = createSelector(playbackRateFeature);
|
|
970
|
+
/** Select the source state (src, type). */
|
|
971
|
+
const selectSource = createSelector(sourceFeature);
|
|
972
|
+
/** Select the text track state (chapters cues, thumbnail cues). */
|
|
973
|
+
const selectTextTrack = createSelector(textTrackFeature);
|
|
974
|
+
/** Select the time state (currentTime, duration, seek). */
|
|
975
|
+
const selectTime = createSelector(timeFeature);
|
|
976
|
+
/** Select the volume state (volume, muted, setVolume, setMuted). */
|
|
977
|
+
const selectVolume = createSelector(volumeFeature);
|
|
978
|
+
|
|
979
|
+
//#endregion
|
|
980
|
+
//#region ../../node_modules/.pnpm/@lit+context@1.1.6/node_modules/@lit/context/development/lib/context-request-event.js
|
|
981
|
+
/**
|
|
982
|
+
* @license
|
|
983
|
+
* Copyright 2021 Google LLC
|
|
984
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
985
|
+
*/
|
|
986
|
+
/**
|
|
987
|
+
* An event fired by a context requester to signal it desires a specified context with the given key.
|
|
988
|
+
*
|
|
989
|
+
* A provider should inspect the `context` property of the event to determine if it has a value that can
|
|
990
|
+
* satisfy the request, calling the `callback` with the requested value if so.
|
|
991
|
+
*
|
|
992
|
+
* If the requested context event contains a truthy `subscribe` value, then a provider can call the callback
|
|
993
|
+
* multiple times if the value is changed, if this is the case the provider should pass an `unsubscribe`
|
|
994
|
+
* method to the callback which consumers can invoke to indicate they no longer wish to receive these updates.
|
|
995
|
+
*
|
|
996
|
+
* If no `subscribe` value is present in the event, then the provider can assume that this is a 'one time'
|
|
997
|
+
* request for the context and can therefore not track the consumer.
|
|
998
|
+
*/
|
|
999
|
+
var ContextRequestEvent = class extends Event {
|
|
1000
|
+
/**
|
|
1001
|
+
*
|
|
1002
|
+
* @param context the context key to request
|
|
1003
|
+
* @param contextTarget the original context target of the requester
|
|
1004
|
+
* @param callback the callback that should be invoked when the context with the specified key is available
|
|
1005
|
+
* @param subscribe when, true indicates we want to subscribe to future updates
|
|
1006
|
+
*/
|
|
1007
|
+
constructor(context, contextTarget, callback, subscribe) {
|
|
1008
|
+
super("context-request", {
|
|
1009
|
+
bubbles: true,
|
|
1010
|
+
composed: true
|
|
1011
|
+
});
|
|
1012
|
+
this.context = context;
|
|
1013
|
+
this.contextTarget = contextTarget;
|
|
1014
|
+
this.callback = callback;
|
|
1015
|
+
this.subscribe = subscribe ?? false;
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
//#endregion
|
|
1020
|
+
//#region ../../node_modules/.pnpm/@lit+context@1.1.6/node_modules/@lit/context/development/lib/create-context.js
|
|
1021
|
+
/**
|
|
1022
|
+
* @license
|
|
1023
|
+
* Copyright 2021 Google LLC
|
|
1024
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
1025
|
+
*/
|
|
1026
|
+
/**
|
|
1027
|
+
* Creates a typed Context.
|
|
1028
|
+
*
|
|
1029
|
+
* Contexts are compared with strict equality.
|
|
1030
|
+
*
|
|
1031
|
+
* If you want two separate `createContext()` calls to referer to the same
|
|
1032
|
+
* context, then use a key that will by equal under strict equality like a
|
|
1033
|
+
* string for `Symbol.for()`:
|
|
1034
|
+
*
|
|
1035
|
+
* ```ts
|
|
1036
|
+
* // true
|
|
1037
|
+
* createContext('my-context') === createContext('my-context')
|
|
1038
|
+
* // true
|
|
1039
|
+
* createContext(Symbol.for('my-context')) === createContext(Symbol.for('my-context'))
|
|
1040
|
+
* ```
|
|
1041
|
+
*
|
|
1042
|
+
* If you want a context to be unique so that it's guaranteed to not collide
|
|
1043
|
+
* with other contexts, use a key that's unique under strict equality, like
|
|
1044
|
+
* a `Symbol()` or object.:
|
|
1045
|
+
*
|
|
1046
|
+
* ```
|
|
1047
|
+
* // false
|
|
1048
|
+
* createContext({}) === createContext({})
|
|
1049
|
+
* // false
|
|
1050
|
+
* createContext(Symbol('my-context')) === createContext(Symbol('my-context'))
|
|
1051
|
+
* ```
|
|
1052
|
+
*
|
|
1053
|
+
* @param key a context key value
|
|
1054
|
+
* @template ValueType the type of value that can be provided by this context.
|
|
1055
|
+
* @returns the context key value cast to `Context<K, ValueType>`
|
|
1056
|
+
*/
|
|
1057
|
+
function createContext(key) {
|
|
1058
|
+
return key;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
//#endregion
|
|
1062
|
+
//#region ../../node_modules/.pnpm/@lit+context@1.1.6/node_modules/@lit/context/development/lib/controllers/context-consumer.js
|
|
1063
|
+
/**
|
|
1064
|
+
* @license
|
|
1065
|
+
* Copyright 2021 Google LLC
|
|
1066
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
1067
|
+
*/
|
|
1068
|
+
/**
|
|
1069
|
+
* A ReactiveController which adds context consuming behavior to a custom
|
|
1070
|
+
* element by dispatching `context-request` events.
|
|
1071
|
+
*
|
|
1072
|
+
* When the host element is connected to the document it will emit a
|
|
1073
|
+
* `context-request` event with its context key. When the context request
|
|
1074
|
+
* is satisfied the controller will invoke the callback, if present, and
|
|
1075
|
+
* trigger a host update so it can respond to the new value.
|
|
1076
|
+
*
|
|
1077
|
+
* It will also call the dispose method given by the provider when the
|
|
1078
|
+
* host element is disconnected.
|
|
1079
|
+
*/
|
|
1080
|
+
var ContextConsumer = class {
|
|
1081
|
+
constructor(host, contextOrOptions, callback, subscribe) {
|
|
1082
|
+
this.subscribe = false;
|
|
1083
|
+
this.provided = false;
|
|
1084
|
+
this.value = void 0;
|
|
1085
|
+
this._callback = (value, unsubscribe) => {
|
|
1086
|
+
if (this.unsubscribe) {
|
|
1087
|
+
if (this.unsubscribe !== unsubscribe) {
|
|
1088
|
+
this.provided = false;
|
|
1089
|
+
this.unsubscribe();
|
|
1090
|
+
}
|
|
1091
|
+
if (!this.subscribe) this.unsubscribe();
|
|
1092
|
+
}
|
|
1093
|
+
this.value = value;
|
|
1094
|
+
this.host.requestUpdate();
|
|
1095
|
+
if (!this.provided || this.subscribe) {
|
|
1096
|
+
this.provided = true;
|
|
1097
|
+
if (this.callback) this.callback(value, unsubscribe);
|
|
1098
|
+
}
|
|
1099
|
+
this.unsubscribe = unsubscribe;
|
|
1100
|
+
};
|
|
1101
|
+
this.host = host;
|
|
1102
|
+
if (contextOrOptions.context !== void 0) {
|
|
1103
|
+
const options = contextOrOptions;
|
|
1104
|
+
this.context = options.context;
|
|
1105
|
+
this.callback = options.callback;
|
|
1106
|
+
this.subscribe = options.subscribe ?? false;
|
|
1107
|
+
} else {
|
|
1108
|
+
this.context = contextOrOptions;
|
|
1109
|
+
this.callback = callback;
|
|
1110
|
+
this.subscribe = subscribe ?? false;
|
|
1111
|
+
}
|
|
1112
|
+
this.host.addController(this);
|
|
1113
|
+
}
|
|
1114
|
+
hostConnected() {
|
|
1115
|
+
this.dispatchRequest();
|
|
1116
|
+
}
|
|
1117
|
+
hostDisconnected() {
|
|
1118
|
+
if (this.unsubscribe) {
|
|
1119
|
+
this.unsubscribe();
|
|
1120
|
+
this.unsubscribe = void 0;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
dispatchRequest() {
|
|
1124
|
+
this.host.dispatchEvent(new ContextRequestEvent(this.context, this.host, this._callback, this.subscribe));
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
//#endregion
|
|
1129
|
+
//#region ../../node_modules/.pnpm/@lit+context@1.1.6/node_modules/@lit/context/development/lib/value-notifier.js
|
|
1130
|
+
/**
|
|
1131
|
+
* @license
|
|
1132
|
+
* Copyright 2021 Google LLC
|
|
1133
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
1134
|
+
*/
|
|
1135
|
+
/**
|
|
1136
|
+
* A simple class which stores a value, and triggers registered callbacks when
|
|
1137
|
+
* the value is changed via its setter.
|
|
1138
|
+
*
|
|
1139
|
+
* An implementor might use other observable patterns such as MobX or Redux to
|
|
1140
|
+
* get behavior like this. But this is a pretty minimal approach that will
|
|
1141
|
+
* likely work for a number of use cases.
|
|
1142
|
+
*/
|
|
1143
|
+
var ValueNotifier = class {
|
|
1144
|
+
get value() {
|
|
1145
|
+
return this._value;
|
|
1146
|
+
}
|
|
1147
|
+
set value(v) {
|
|
1148
|
+
this.setValue(v);
|
|
1149
|
+
}
|
|
1150
|
+
setValue(v, force = false) {
|
|
1151
|
+
const update = force || !Object.is(v, this._value);
|
|
1152
|
+
this._value = v;
|
|
1153
|
+
if (update) this.updateObservers();
|
|
1154
|
+
}
|
|
1155
|
+
constructor(defaultValue) {
|
|
1156
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
1157
|
+
this.updateObservers = () => {
|
|
1158
|
+
for (const [callback, { disposer }] of this.subscriptions) callback(this._value, disposer);
|
|
1159
|
+
};
|
|
1160
|
+
if (defaultValue !== void 0) this.value = defaultValue;
|
|
1161
|
+
}
|
|
1162
|
+
addCallback(callback, consumerHost, subscribe) {
|
|
1163
|
+
if (!subscribe) {
|
|
1164
|
+
callback(this.value);
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
if (!this.subscriptions.has(callback)) this.subscriptions.set(callback, {
|
|
1168
|
+
disposer: () => {
|
|
1169
|
+
this.subscriptions.delete(callback);
|
|
1170
|
+
},
|
|
1171
|
+
consumerHost
|
|
1172
|
+
});
|
|
1173
|
+
const { disposer } = this.subscriptions.get(callback);
|
|
1174
|
+
callback(this.value, disposer);
|
|
1175
|
+
}
|
|
1176
|
+
clearCallbacks() {
|
|
1177
|
+
this.subscriptions.clear();
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
//#endregion
|
|
1182
|
+
//#region ../../node_modules/.pnpm/@lit+context@1.1.6/node_modules/@lit/context/development/lib/controllers/context-provider.js
|
|
1183
|
+
/**
|
|
1184
|
+
* @license
|
|
1185
|
+
* Copyright 2021 Google LLC
|
|
1186
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
1187
|
+
*/
|
|
1188
|
+
var ContextProviderEvent = class extends Event {
|
|
1189
|
+
/**
|
|
1190
|
+
*
|
|
1191
|
+
* @param context the context which this provider can provide
|
|
1192
|
+
* @param contextTarget the original context target of the provider
|
|
1193
|
+
*/
|
|
1194
|
+
constructor(context, contextTarget) {
|
|
1195
|
+
super("context-provider", {
|
|
1196
|
+
bubbles: true,
|
|
1197
|
+
composed: true
|
|
1198
|
+
});
|
|
1199
|
+
this.context = context;
|
|
1200
|
+
this.contextTarget = contextTarget;
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
/**
|
|
1204
|
+
* A ReactiveController which adds context provider behavior to a
|
|
1205
|
+
* custom element.
|
|
1206
|
+
*
|
|
1207
|
+
* This controller simply listens to the `context-request` event when
|
|
1208
|
+
* the host is connected to the DOM and registers the received callbacks
|
|
1209
|
+
* against its observable Context implementation.
|
|
1210
|
+
*
|
|
1211
|
+
* The controller may also be attached to any HTML element in which case it's
|
|
1212
|
+
* up to the user to call hostConnected() when attached to the DOM. This is
|
|
1213
|
+
* done automatically for any custom elements implementing
|
|
1214
|
+
* ReactiveControllerHost.
|
|
1215
|
+
*/
|
|
1216
|
+
var ContextProvider = class extends ValueNotifier {
|
|
1217
|
+
constructor(host, contextOrOptions, initialValue) {
|
|
1218
|
+
super(contextOrOptions.context !== void 0 ? contextOrOptions.initialValue : initialValue);
|
|
1219
|
+
this.onContextRequest = (ev) => {
|
|
1220
|
+
if (ev.context !== this.context) return;
|
|
1221
|
+
const consumerHost = ev.contextTarget ?? ev.composedPath()[0];
|
|
1222
|
+
if (consumerHost === this.host) return;
|
|
1223
|
+
ev.stopPropagation();
|
|
1224
|
+
this.addCallback(ev.callback, consumerHost, ev.subscribe);
|
|
1225
|
+
};
|
|
1226
|
+
/**
|
|
1227
|
+
* When we get a provider request event, that means a child of this element
|
|
1228
|
+
* has just woken up. If it's a provider of our context, then we may need to
|
|
1229
|
+
* re-parent our subscriptions, because is a more specific provider than us
|
|
1230
|
+
* for its subtree.
|
|
1231
|
+
*/
|
|
1232
|
+
this.onProviderRequest = (ev) => {
|
|
1233
|
+
if (ev.context !== this.context) return;
|
|
1234
|
+
if ((ev.contextTarget ?? ev.composedPath()[0]) === this.host) return;
|
|
1235
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1236
|
+
for (const [callback, { consumerHost }] of this.subscriptions) {
|
|
1237
|
+
if (seen.has(callback)) continue;
|
|
1238
|
+
seen.add(callback);
|
|
1239
|
+
consumerHost.dispatchEvent(new ContextRequestEvent(this.context, consumerHost, callback, true));
|
|
1240
|
+
}
|
|
1241
|
+
ev.stopPropagation();
|
|
1242
|
+
};
|
|
1243
|
+
this.host = host;
|
|
1244
|
+
if (contextOrOptions.context !== void 0) this.context = contextOrOptions.context;
|
|
1245
|
+
else this.context = contextOrOptions;
|
|
1246
|
+
this.attachListeners();
|
|
1247
|
+
this.host.addController?.(this);
|
|
1248
|
+
}
|
|
1249
|
+
attachListeners() {
|
|
1250
|
+
this.host.addEventListener("context-request", this.onContextRequest);
|
|
1251
|
+
this.host.addEventListener("context-provider", this.onProviderRequest);
|
|
1252
|
+
}
|
|
1253
|
+
hostConnected() {
|
|
1254
|
+
this.host.dispatchEvent(new ContextProviderEvent(this.context, this.host));
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
//#endregion
|
|
1259
|
+
//#region src/player/context.ts
|
|
1260
|
+
const PLAYER_CONTEXT_KEY = Symbol("@videojs/player");
|
|
1261
|
+
/**
|
|
1262
|
+
* The default player context instance for consuming the player store in controllers.
|
|
1263
|
+
*
|
|
1264
|
+
* @public
|
|
1265
|
+
*/
|
|
1266
|
+
const playerContext = createContext(PLAYER_CONTEXT_KEY);
|
|
1267
|
+
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/store/container-mixin.ts
|
|
1270
|
+
/**
|
|
1271
|
+
* Create a mixin that consumes player context and auto-attaches media elements.
|
|
1272
|
+
*
|
|
1273
|
+
* @param context - Player context to consume from an ancestor provider.
|
|
1274
|
+
*/
|
|
1275
|
+
function createContainerMixin(context) {
|
|
1276
|
+
return (BaseClass) => {
|
|
1277
|
+
class PlayerContainerElement extends BaseClass {
|
|
1278
|
+
#detach = noop;
|
|
1279
|
+
#observer = null;
|
|
1280
|
+
#contextStore = null;
|
|
1281
|
+
constructor(...args) {
|
|
1282
|
+
super(...args);
|
|
1283
|
+
new ContextConsumer(this, {
|
|
1284
|
+
context,
|
|
1285
|
+
callback: (value) => {
|
|
1286
|
+
this.#contextStore = value ?? null;
|
|
1287
|
+
this.#attachMedia();
|
|
1288
|
+
},
|
|
1289
|
+
subscribe: true
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
get store() {
|
|
1293
|
+
return this.#contextStore;
|
|
1294
|
+
}
|
|
1295
|
+
connectedCallback() {
|
|
1296
|
+
super.connectedCallback();
|
|
1297
|
+
this.#observer = new MutationObserver((records) => {
|
|
1298
|
+
if (records.some(hasMediaNode)) this.#attachMedia();
|
|
1299
|
+
});
|
|
1300
|
+
this.#observer.observe(this, {
|
|
1301
|
+
childList: true,
|
|
1302
|
+
subtree: true,
|
|
1303
|
+
attributes: true,
|
|
1304
|
+
attributeFilter: ["data-media-element"]
|
|
1305
|
+
});
|
|
1306
|
+
this.addEventListener("slotchange", this.#onSlotChange);
|
|
1307
|
+
this.#attachMedia();
|
|
1308
|
+
}
|
|
1309
|
+
disconnectedCallback() {
|
|
1310
|
+
super.disconnectedCallback();
|
|
1311
|
+
this.#observer?.disconnect();
|
|
1312
|
+
this.#observer = null;
|
|
1313
|
+
this.removeEventListener("slotchange", this.#onSlotChange);
|
|
1314
|
+
this.#detach();
|
|
1315
|
+
}
|
|
1316
|
+
#onSlotChange = () => {
|
|
1317
|
+
this.#attachMedia();
|
|
1318
|
+
};
|
|
1319
|
+
#getSlottedMedia() {
|
|
1320
|
+
const slot = this.querySelector("slot[name=\"media\"]");
|
|
1321
|
+
if (!slot) return null;
|
|
1322
|
+
for (const el of slot.assignedElements({ flatten: true })) if (el instanceof HTMLMediaElement) return el;
|
|
1323
|
+
return null;
|
|
1324
|
+
}
|
|
1325
|
+
#attachMedia() {
|
|
1326
|
+
const store = this.#contextStore ?? this.store;
|
|
1327
|
+
if (!store) return;
|
|
1328
|
+
const media = this.querySelector("video, audio, [data-media-element]") ?? this.#getSlottedMedia();
|
|
1329
|
+
if (!media) {
|
|
1330
|
+
this.#detach();
|
|
1331
|
+
this.#detach = noop;
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
const target = {
|
|
1335
|
+
media,
|
|
1336
|
+
container: this
|
|
1337
|
+
};
|
|
1338
|
+
const hasMediaChanged = store.target?.media !== target.media, hasContainerChanged = store.target?.container !== target.container;
|
|
1339
|
+
if (hasMediaChanged || hasContainerChanged) {
|
|
1340
|
+
this.#detach();
|
|
1341
|
+
this.#detach = store.attach(target);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
return PlayerContainerElement;
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
function isMediaNode(node) {
|
|
1349
|
+
return node instanceof HTMLMediaElement || node instanceof Element && node.hasAttribute("data-media-element");
|
|
1350
|
+
}
|
|
1351
|
+
function hasMediaNode(record) {
|
|
1352
|
+
if (record.type === "attributes" && record.target instanceof Element) return record.target.hasAttribute("data-media-element");
|
|
1353
|
+
for (const node of record.addedNodes) if (isMediaNode(node)) return true;
|
|
1354
|
+
for (const node of record.removedNodes) if (isMediaNode(node)) return true;
|
|
1355
|
+
return false;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
//#endregion
|
|
1359
|
+
//#region ../element/dist/dev/destroy-mixin.js
|
|
1360
|
+
/**
|
|
1361
|
+
* Mixin that adds a deferred destruction lifecycle to a `ReactiveElement`.
|
|
1362
|
+
*
|
|
1363
|
+
* On disconnect, schedules destruction after two animation frames.
|
|
1364
|
+
* If the element reconnects before the frames fire (e.g. DOM shuffling,
|
|
1365
|
+
* framework reconciliation), the `isConnected` check prevents destruction.
|
|
1366
|
+
*
|
|
1367
|
+
* The `keep-alive` attribute prevents automatic destruction entirely —
|
|
1368
|
+
* call `destroy()` manually when done.
|
|
1369
|
+
*
|
|
1370
|
+
* Subclasses override `destroyCallback()` (calling `super.destroyCallback()`)
|
|
1371
|
+
* to release heavy resources like stores or imperative APIs.
|
|
1372
|
+
*
|
|
1373
|
+
* Mirrors `addController`/`removeController` to track controllers
|
|
1374
|
+
* (needed because `ReactiveElement.#controllers` is hard-private),
|
|
1375
|
+
* calls `hostDestroyed()` on all tracked controllers in `destroyCallback`,
|
|
1376
|
+
* and guards `performUpdate()` so no updates run after destruction.
|
|
1377
|
+
*/
|
|
1378
|
+
function DestroyMixin(SuperClass) {
|
|
1379
|
+
class DestroyableElement extends SuperClass {
|
|
1380
|
+
#destroyed = false;
|
|
1381
|
+
#trackedControllers = /* @__PURE__ */ new Set();
|
|
1382
|
+
get destroyed() {
|
|
1383
|
+
return this.#destroyed;
|
|
1384
|
+
}
|
|
1385
|
+
destroy() {
|
|
1386
|
+
if (this.#destroyed) return;
|
|
1387
|
+
this.#destroyed = true;
|
|
1388
|
+
this.destroyCallback();
|
|
1389
|
+
}
|
|
1390
|
+
destroyCallback() {
|
|
1391
|
+
for (const c of this.#trackedControllers) c.hostDestroyed?.();
|
|
1392
|
+
}
|
|
1393
|
+
addController(controller) {
|
|
1394
|
+
super.addController(controller);
|
|
1395
|
+
this.#trackedControllers.add(controller);
|
|
1396
|
+
}
|
|
1397
|
+
removeController(controller) {
|
|
1398
|
+
super.removeController(controller);
|
|
1399
|
+
this.#trackedControllers.delete(controller);
|
|
1400
|
+
}
|
|
1401
|
+
connectedCallback() {
|
|
1402
|
+
if (this.#destroyed) return;
|
|
1403
|
+
super.connectedCallback();
|
|
1404
|
+
}
|
|
1405
|
+
disconnectedCallback() {
|
|
1406
|
+
super.disconnectedCallback();
|
|
1407
|
+
if (!this.#destroyed && !this.hasAttribute("keep-alive")) requestAnimationFrame(() => {
|
|
1408
|
+
requestAnimationFrame(() => {
|
|
1409
|
+
if (!this.isConnected) this.destroy();
|
|
1410
|
+
});
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
performUpdate() {
|
|
1414
|
+
if (this.#destroyed) return;
|
|
1415
|
+
super.performUpdate();
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
return DestroyableElement;
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
//#endregion
|
|
1422
|
+
//#region ../element/dist/dev/reactive-element.js
|
|
1423
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
1424
|
+
const propertyKeys = /* @__PURE__ */ new Map();
|
|
1425
|
+
/**
|
|
1426
|
+
* Lightweight reactive custom element base class.
|
|
1427
|
+
*
|
|
1428
|
+
* Drop-in subset of Lit's `ReactiveElement` — supports `static properties`,
|
|
1429
|
+
* attribute reflection, batched async updates, and reactive controllers.
|
|
1430
|
+
* No Shadow DOM, no `static styles`, no decorators.
|
|
1431
|
+
*
|
|
1432
|
+
* Updates are batched using the same Promise-based scheduling as Lit:
|
|
1433
|
+
* property changes enqueue a microtask, and the update is gated behind
|
|
1434
|
+
* `connectedCallback` so the first update only runs once the element
|
|
1435
|
+
* is in the document.
|
|
1436
|
+
*
|
|
1437
|
+
* Subclasses that extend another element with properties must spread them:
|
|
1438
|
+
*
|
|
1439
|
+
* @example
|
|
1440
|
+
* ```ts
|
|
1441
|
+
* class MyButton extends ReactiveElement {
|
|
1442
|
+
* static override properties = {
|
|
1443
|
+
* label: { type: String },
|
|
1444
|
+
* disabled: { type: Boolean },
|
|
1445
|
+
* };
|
|
1446
|
+
*
|
|
1447
|
+
* label = 'Click me';
|
|
1448
|
+
* disabled = false;
|
|
1449
|
+
*
|
|
1450
|
+
* protected override update(changed: PropertyValues): void {
|
|
1451
|
+
* super.update(changed);
|
|
1452
|
+
* this.textContent = this.label;
|
|
1453
|
+
* }
|
|
1454
|
+
* }
|
|
1455
|
+
*
|
|
1456
|
+
* // Inheritance — spread parent properties
|
|
1457
|
+
* class FancyButton extends MyButton {
|
|
1458
|
+
* static override properties = {
|
|
1459
|
+
* ...MyButton.properties,
|
|
1460
|
+
* variant: { type: String },
|
|
1461
|
+
* };
|
|
1462
|
+
*
|
|
1463
|
+
* variant = 'primary';
|
|
1464
|
+
* }
|
|
1465
|
+
* ```
|
|
1466
|
+
*/
|
|
1467
|
+
var ReactiveElement = class extends HTMLElement {
|
|
1468
|
+
static {
|
|
1469
|
+
this.properties = {};
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Returns a list of attributes corresponding to the registered properties.
|
|
1473
|
+
*/
|
|
1474
|
+
static get observedAttributes() {
|
|
1475
|
+
return [...resolve(this).attrToProp.keys()];
|
|
1476
|
+
}
|
|
1477
|
+
#controllers = /* @__PURE__ */ new Set();
|
|
1478
|
+
#changedProperties = /* @__PURE__ */ new Map();
|
|
1479
|
+
#instanceProperties;
|
|
1480
|
+
/**
|
|
1481
|
+
* Promise that gates the first update until `connectedCallback`. Also
|
|
1482
|
+
* used to serialize updates — each `#enqueueUpdate` awaits the previous
|
|
1483
|
+
* `#updatePromise`, so property changes are batched and updates never
|
|
1484
|
+
* overlap. Matches Lit's scheduling model.
|
|
1485
|
+
*/
|
|
1486
|
+
#updatePromise;
|
|
1487
|
+
constructor() {
|
|
1488
|
+
super();
|
|
1489
|
+
this.isUpdatePending = false;
|
|
1490
|
+
this.hasUpdated = false;
|
|
1491
|
+
this.#updatePromise = new Promise((res) => this.enableUpdating = res);
|
|
1492
|
+
const { props } = resolve(this.constructor);
|
|
1493
|
+
for (const name of props.keys()) if (Object.hasOwn(this, name)) {
|
|
1494
|
+
(this.#instanceProperties ??= /* @__PURE__ */ new Map()).set(name, this[name]);
|
|
1495
|
+
delete this[name];
|
|
1496
|
+
}
|
|
1497
|
+
this.requestUpdate();
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Note, this method should be considered final and not overridden. It is
|
|
1501
|
+
* overridden on the element instance with a function that triggers the
|
|
1502
|
+
* first update.
|
|
1503
|
+
*/
|
|
1504
|
+
enableUpdating(_requestedUpdate) {}
|
|
1505
|
+
/**
|
|
1506
|
+
* Registers a {@linkcode ReactiveController} to participate in the
|
|
1507
|
+
* element's reactive update cycle. The element automatically calls into
|
|
1508
|
+
* any registered controllers during its lifecycle callbacks.
|
|
1509
|
+
*
|
|
1510
|
+
* If the element is connected when `addController()` is called, the
|
|
1511
|
+
* controller's `hostConnected()` callback will be immediately called.
|
|
1512
|
+
*/
|
|
1513
|
+
addController(controller) {
|
|
1514
|
+
this.#controllers.add(controller);
|
|
1515
|
+
if (this.isConnected) controller.hostConnected?.();
|
|
1516
|
+
}
|
|
1517
|
+
/** Removes a {@linkcode ReactiveController} from the element. */
|
|
1518
|
+
removeController(controller) {
|
|
1519
|
+
this.#controllers.delete(controller);
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* On first connection, enables updating and notifies controllers.
|
|
1523
|
+
*/
|
|
1524
|
+
connectedCallback() {
|
|
1525
|
+
this.enableUpdating(true);
|
|
1526
|
+
for (const c of this.#controllers) c.hostConnected?.();
|
|
1527
|
+
}
|
|
1528
|
+
disconnectedCallback() {
|
|
1529
|
+
for (const c of this.#controllers) c.hostDisconnected?.();
|
|
1530
|
+
}
|
|
1531
|
+
/**
|
|
1532
|
+
* Synchronizes property values when attributes change.
|
|
1533
|
+
*
|
|
1534
|
+
* Specifically, when an attribute is set, the corresponding property is
|
|
1535
|
+
* set. You should rarely need to implement this callback. If this method
|
|
1536
|
+
* is overridden, `super.attributeChangedCallback(name, _old, value)` must
|
|
1537
|
+
* be called.
|
|
1538
|
+
*/
|
|
1539
|
+
attributeChangedCallback(attr, oldValue, newValue) {
|
|
1540
|
+
if (oldValue === newValue) return;
|
|
1541
|
+
const { props, attrToProp } = resolve(this.constructor);
|
|
1542
|
+
const propName = attrToProp.get(attr);
|
|
1543
|
+
if (!propName) return;
|
|
1544
|
+
const decl = props.get(propName);
|
|
1545
|
+
if (!decl) return;
|
|
1546
|
+
let value = newValue;
|
|
1547
|
+
if (decl.type === Boolean) value = newValue !== null;
|
|
1548
|
+
else if (decl.type === Number) value = newValue === null ? null : Number(newValue);
|
|
1549
|
+
this[propName] = value;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Requests an update which is processed asynchronously. This should be
|
|
1553
|
+
* called when an element should update based on some state not triggered
|
|
1554
|
+
* by setting a reactive property. In this case, pass no arguments. It
|
|
1555
|
+
* should also be called when manually implementing a property setter. In
|
|
1556
|
+
* this case, pass the property `name` and `oldValue` to ensure that any
|
|
1557
|
+
* configured property options are honored.
|
|
1558
|
+
*/
|
|
1559
|
+
requestUpdate(name, oldValue) {
|
|
1560
|
+
if (name !== void 0) this.#changedProperties.set(name, oldValue);
|
|
1561
|
+
if (this.isUpdatePending) return;
|
|
1562
|
+
this.#updatePromise = this.#enqueueUpdate();
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Sets up the element to asynchronously update. Awaits the previous
|
|
1566
|
+
* `#updatePromise` which both serializes updates and (on first update)
|
|
1567
|
+
* waits for `connectedCallback` to resolve the gate.
|
|
1568
|
+
*/
|
|
1569
|
+
async #enqueueUpdate() {
|
|
1570
|
+
this.isUpdatePending = true;
|
|
1571
|
+
try {
|
|
1572
|
+
await this.#updatePromise;
|
|
1573
|
+
} catch (e) {
|
|
1574
|
+
Promise.reject(e);
|
|
1575
|
+
}
|
|
1576
|
+
const result = this.scheduleUpdate();
|
|
1577
|
+
if (result != null) await result;
|
|
1578
|
+
return !this.isUpdatePending;
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Schedules an element update. You can override this method to change the
|
|
1582
|
+
* timing of updates by returning a Promise. The update will await the
|
|
1583
|
+
* returned Promise, and you should resolve the Promise to allow the update
|
|
1584
|
+
* to proceed. If this method is overridden, `super.scheduleUpdate()` must
|
|
1585
|
+
* be called.
|
|
1586
|
+
*
|
|
1587
|
+
* For instance, to schedule updates to occur just before the next frame:
|
|
1588
|
+
*
|
|
1589
|
+
* ```ts
|
|
1590
|
+
* override protected async scheduleUpdate(): Promise<unknown> {
|
|
1591
|
+
* await new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
1592
|
+
* super.scheduleUpdate();
|
|
1593
|
+
* }
|
|
1594
|
+
* ```
|
|
1595
|
+
*/
|
|
1596
|
+
scheduleUpdate() {
|
|
1597
|
+
this.performUpdate();
|
|
1598
|
+
}
|
|
1599
|
+
/**
|
|
1600
|
+
* Performs an element update. Note, if an exception is thrown during the
|
|
1601
|
+
* update, `firstUpdated` and `updated` will not be called.
|
|
1602
|
+
*
|
|
1603
|
+
* Call `performUpdate()` to immediately process a pending update. This
|
|
1604
|
+
* should generally not be needed, but it can be done in rare cases when
|
|
1605
|
+
* you need to update synchronously.
|
|
1606
|
+
*/
|
|
1607
|
+
performUpdate() {
|
|
1608
|
+
if (!this.isUpdatePending) return;
|
|
1609
|
+
if (!this.hasUpdated && this.#instanceProperties) {
|
|
1610
|
+
for (const [name, value] of this.#instanceProperties) this[name] = value;
|
|
1611
|
+
this.#instanceProperties = void 0;
|
|
1612
|
+
}
|
|
1613
|
+
const changed = this.#changedProperties;
|
|
1614
|
+
this.willUpdate(changed);
|
|
1615
|
+
for (const c of this.#controllers) c.hostUpdate?.();
|
|
1616
|
+
this.update(changed);
|
|
1617
|
+
this.#changedProperties = /* @__PURE__ */ new Map();
|
|
1618
|
+
this.isUpdatePending = false;
|
|
1619
|
+
for (const c of this.#controllers) c.hostUpdated?.();
|
|
1620
|
+
if (!this.hasUpdated) {
|
|
1621
|
+
this.hasUpdated = true;
|
|
1622
|
+
this.firstUpdated(changed);
|
|
1623
|
+
}
|
|
1624
|
+
this.updated(changed);
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Invoked before `update()` to compute values needed during the update.
|
|
1628
|
+
*
|
|
1629
|
+
* Implement `willUpdate` to compute property values that depend on other
|
|
1630
|
+
* properties and are used in the rest of the update process.
|
|
1631
|
+
*
|
|
1632
|
+
* ```ts
|
|
1633
|
+
* willUpdate(changed) {
|
|
1634
|
+
* if (changed.has('firstName') || changed.has('lastName')) {
|
|
1635
|
+
* this.sha = computeSHA(`${this.firstName} ${this.lastName}`);
|
|
1636
|
+
* }
|
|
1637
|
+
* }
|
|
1638
|
+
* ```
|
|
1639
|
+
*/
|
|
1640
|
+
willUpdate(_changed) {}
|
|
1641
|
+
/**
|
|
1642
|
+
* Updates the element. This method reflects property values to attributes
|
|
1643
|
+
* and can be overridden to render and keep updated element DOM. Setting
|
|
1644
|
+
* properties inside this method will *not* trigger another update.
|
|
1645
|
+
*/
|
|
1646
|
+
update(_changed) {}
|
|
1647
|
+
/**
|
|
1648
|
+
* Invoked when the element is first updated. Implement to perform one
|
|
1649
|
+
* time work on the element after update.
|
|
1650
|
+
*
|
|
1651
|
+
* Setting properties inside this method will trigger the element to
|
|
1652
|
+
* update again after this update cycle completes.
|
|
1653
|
+
*/
|
|
1654
|
+
firstUpdated(_changed) {}
|
|
1655
|
+
/**
|
|
1656
|
+
* Invoked whenever the element is updated. Implement to perform
|
|
1657
|
+
* post-updating tasks via DOM APIs, for example, focusing an element.
|
|
1658
|
+
*
|
|
1659
|
+
* Setting properties inside this method will trigger the element to
|
|
1660
|
+
* update again after this update cycle completes.
|
|
1661
|
+
*/
|
|
1662
|
+
updated(_changed) {}
|
|
1663
|
+
/**
|
|
1664
|
+
* Returns a Promise that resolves when the element has completed updating.
|
|
1665
|
+
* The Promise value is a boolean that is `true` if the element completed
|
|
1666
|
+
* the update without triggering another update. The Promise result is
|
|
1667
|
+
* `false` if a property was set inside `updated()`.
|
|
1668
|
+
*/
|
|
1669
|
+
get updateComplete() {
|
|
1670
|
+
return this.#updatePromise;
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
/**
|
|
1674
|
+
* Resolve `ctor.properties` into lookup Maps and install reactive accessors
|
|
1675
|
+
* on the prototype. Runs once per class, result is cached.
|
|
1676
|
+
*
|
|
1677
|
+
* Subclasses that need parent properties must spread them:
|
|
1678
|
+
* `static override properties = { ...Parent.properties, ... }`.
|
|
1679
|
+
*/
|
|
1680
|
+
function resolve(ctor) {
|
|
1681
|
+
const existing = cache.get(ctor);
|
|
1682
|
+
if (existing) return existing;
|
|
1683
|
+
const props = /* @__PURE__ */ new Map();
|
|
1684
|
+
const attrToProp = /* @__PURE__ */ new Map();
|
|
1685
|
+
for (const [name, decl] of Object.entries(ctor.properties)) {
|
|
1686
|
+
props.set(name, decl);
|
|
1687
|
+
attrToProp.set(decl.attribute ?? name, name);
|
|
1688
|
+
if (!Object.getOwnPropertyDescriptor(ctor.prototype, name)?.get) {
|
|
1689
|
+
let key = propertyKeys.get(name);
|
|
1690
|
+
if (!key) {
|
|
1691
|
+
key = Symbol(name);
|
|
1692
|
+
propertyKeys.set(name, key);
|
|
1693
|
+
}
|
|
1694
|
+
Object.defineProperty(ctor.prototype, name, {
|
|
1695
|
+
get() {
|
|
1696
|
+
return this[key];
|
|
1697
|
+
},
|
|
1698
|
+
set(value) {
|
|
1699
|
+
const old = this[key];
|
|
1700
|
+
this[key] = value;
|
|
1701
|
+
if (!Object.is(old, value)) this.requestUpdate(name, old);
|
|
1702
|
+
},
|
|
1703
|
+
configurable: true,
|
|
1704
|
+
enumerable: true
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
const meta = {
|
|
1709
|
+
props,
|
|
1710
|
+
attrToProp
|
|
1711
|
+
};
|
|
1712
|
+
cache.set(ctor, meta);
|
|
1713
|
+
return meta;
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
//#endregion
|
|
1717
|
+
//#region src/ui/media-element.ts
|
|
1718
|
+
/** Base class for interactive media UI elements. */
|
|
1719
|
+
var MediaElement = class extends DestroyMixin(ReactiveElement) {};
|
|
1720
|
+
|
|
1721
|
+
//#endregion
|
|
1722
|
+
//#region src/media/container-element.ts
|
|
1723
|
+
const ContainerMixin = createContainerMixin(playerContext);
|
|
1724
|
+
var MediaContainerElement = class extends ContainerMixin(MediaElement) {
|
|
1725
|
+
static {
|
|
1726
|
+
this.tagName = "media-container";
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
//#endregion
|
|
1731
|
+
//#region src/store/provider-mixin.ts
|
|
1732
|
+
/**
|
|
1733
|
+
* Create a mixin that provides player context to descendant elements.
|
|
1734
|
+
*
|
|
1735
|
+
* @param context - Player context to provide to descendants.
|
|
1736
|
+
* @param factory - Factory function that creates a store instance.
|
|
1737
|
+
*/
|
|
1738
|
+
function createProviderMixin(context, factory) {
|
|
1739
|
+
return (BaseClass) => {
|
|
1740
|
+
class PlayerProviderElement extends BaseClass {
|
|
1741
|
+
#store = factory();
|
|
1742
|
+
#provider = new ContextProvider(this, {
|
|
1743
|
+
context,
|
|
1744
|
+
initialValue: this.store
|
|
1745
|
+
});
|
|
1746
|
+
get store() {
|
|
1747
|
+
if (isNull(this.#store)) this.#store = factory();
|
|
1748
|
+
return this.#store;
|
|
1749
|
+
}
|
|
1750
|
+
connectedCallback() {
|
|
1751
|
+
super.connectedCallback();
|
|
1752
|
+
this.#provider.setValue(this.store);
|
|
1753
|
+
}
|
|
1754
|
+
destroyCallback() {
|
|
1755
|
+
this.#store?.destroy();
|
|
1756
|
+
this.#store = null;
|
|
1757
|
+
super.destroyCallback();
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
return PlayerProviderElement;
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
//#endregion
|
|
1765
|
+
//#region ../store/dist/dev/html/controllers/snapshot-controller.js
|
|
1766
|
+
/**
|
|
1767
|
+
* Subscribe to a `State<T>` container with optional selector.
|
|
1768
|
+
*
|
|
1769
|
+
* Without selector: returns full state, re-renders on any state change.
|
|
1770
|
+
* With selector: returns selected slice, re-renders only when the slice changes (shallowEqual).
|
|
1771
|
+
*
|
|
1772
|
+
* @example
|
|
1773
|
+
* ```ts
|
|
1774
|
+
* #state = new SnapshotController(this, sliderState, (s) => s.value);
|
|
1775
|
+
* ```
|
|
1776
|
+
*/
|
|
1777
|
+
var SnapshotController = class {
|
|
1778
|
+
#host;
|
|
1779
|
+
#selector;
|
|
1780
|
+
#state;
|
|
1781
|
+
#cached;
|
|
1782
|
+
#unsubscribe = noop;
|
|
1783
|
+
constructor(host, state, selector) {
|
|
1784
|
+
this.#host = host;
|
|
1785
|
+
this.#state = state;
|
|
1786
|
+
this.#selector = selector;
|
|
1787
|
+
host.addController(this);
|
|
1788
|
+
}
|
|
1789
|
+
get value() {
|
|
1790
|
+
if (!this.#selector) return this.#state.current;
|
|
1791
|
+
this.#cached ??= this.#selector(this.#state.current);
|
|
1792
|
+
return this.#cached;
|
|
1793
|
+
}
|
|
1794
|
+
/** Switch to tracking a different state container. */
|
|
1795
|
+
track(state) {
|
|
1796
|
+
this.#state = state;
|
|
1797
|
+
this.#subscribe();
|
|
1798
|
+
}
|
|
1799
|
+
hostConnected() {
|
|
1800
|
+
this.#subscribe();
|
|
1801
|
+
}
|
|
1802
|
+
hostDisconnected() {
|
|
1803
|
+
this.#unsubscribe();
|
|
1804
|
+
this.#unsubscribe = noop;
|
|
1805
|
+
this.#cached = void 0;
|
|
1806
|
+
}
|
|
1807
|
+
#subscribe() {
|
|
1808
|
+
this.#unsubscribe();
|
|
1809
|
+
if (!this.#selector) {
|
|
1810
|
+
this.#unsubscribe = this.#state.subscribe(() => this.#host.requestUpdate());
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
const selector = this.#selector;
|
|
1814
|
+
this.#cached = selector(this.#state.current);
|
|
1815
|
+
this.#unsubscribe = this.#state.subscribe(() => {
|
|
1816
|
+
const next = selector(this.#state.current);
|
|
1817
|
+
if (!shallowEqual(this.#cached, next)) {
|
|
1818
|
+
this.#cached = next;
|
|
1819
|
+
this.#host.requestUpdate();
|
|
1820
|
+
}
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
|
|
1825
|
+
//#endregion
|
|
1826
|
+
//#region ../store/dist/dev/html/store-accessor.js
|
|
1827
|
+
/**
|
|
1828
|
+
* Resolves a store from either a direct instance or context.
|
|
1829
|
+
*
|
|
1830
|
+
* When given a direct store, provides immediate access.
|
|
1831
|
+
* When given a context, sets up a ContextConsumer to receive the store.
|
|
1832
|
+
*
|
|
1833
|
+
* @example Direct store
|
|
1834
|
+
* ```ts
|
|
1835
|
+
* const accessor = new StoreAccessor(host, store, (s) => console.log('available', s));
|
|
1836
|
+
* accessor.value; // Store (immediately available)
|
|
1837
|
+
* ```
|
|
1838
|
+
*
|
|
1839
|
+
* @example Context source
|
|
1840
|
+
* ```ts
|
|
1841
|
+
* const accessor = new StoreAccessor(host, context, (s) => console.log('available', s));
|
|
1842
|
+
* accessor.value; // null until context provides store
|
|
1843
|
+
* ```
|
|
1844
|
+
*/
|
|
1845
|
+
var StoreAccessor = class {
|
|
1846
|
+
#onAvailable;
|
|
1847
|
+
#consumer;
|
|
1848
|
+
#directStore;
|
|
1849
|
+
constructor(host, source, onAvailable) {
|
|
1850
|
+
this.#onAvailable = onAvailable ?? noop;
|
|
1851
|
+
if (isStore(source)) {
|
|
1852
|
+
this.#directStore = source;
|
|
1853
|
+
this.#consumer = null;
|
|
1854
|
+
} else {
|
|
1855
|
+
this.#directStore = null;
|
|
1856
|
+
this.#consumer = new ContextConsumer(host, {
|
|
1857
|
+
context: source,
|
|
1858
|
+
callback: (store) => this.#onAvailable(store),
|
|
1859
|
+
subscribe: false
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
host.addController(this);
|
|
1863
|
+
}
|
|
1864
|
+
/** Returns the store, or null if not yet available from context. */
|
|
1865
|
+
get value() {
|
|
1866
|
+
if (this.#consumer) return this.#consumer.value ?? null;
|
|
1867
|
+
return this.#directStore;
|
|
1868
|
+
}
|
|
1869
|
+
hostConnected() {
|
|
1870
|
+
if (this.#directStore) this.#onAvailable(this.#directStore);
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1874
|
+
//#endregion
|
|
1875
|
+
//#region ../store/dist/dev/html/controllers/store-controller.js
|
|
1876
|
+
/**
|
|
1877
|
+
* Access store state and actions.
|
|
1878
|
+
*
|
|
1879
|
+
* Without selector: Returns the store, does NOT subscribe to changes.
|
|
1880
|
+
* With selector: Returns selected state, triggers update when selected state changes (shallowEqual).
|
|
1881
|
+
*
|
|
1882
|
+
* @example
|
|
1883
|
+
* ```ts
|
|
1884
|
+
* // Store access (no subscription) - access actions
|
|
1885
|
+
* class Controls extends LitElement {
|
|
1886
|
+
* #store = new StoreController(this, storeSource);
|
|
1887
|
+
*
|
|
1888
|
+
* handleClick() {
|
|
1889
|
+
* this.#store.value.setVolume(0.5);
|
|
1890
|
+
* }
|
|
1891
|
+
* }
|
|
1892
|
+
*
|
|
1893
|
+
* // Selector-based subscription - re-renders when playback changes
|
|
1894
|
+
* class PlayButton extends LitElement {
|
|
1895
|
+
* #playback = new StoreController(this, storeSource, selectPlayback);
|
|
1896
|
+
*
|
|
1897
|
+
* render() {
|
|
1898
|
+
* const playback = this.#playback.value;
|
|
1899
|
+
* if (!playback) return nothing;
|
|
1900
|
+
* return html`<button @click=${playback.toggle}>
|
|
1901
|
+
* ${playback.paused ? 'Play' : 'Pause'}
|
|
1902
|
+
* </button>`;
|
|
1903
|
+
* }
|
|
1904
|
+
* }
|
|
1905
|
+
* ```
|
|
1906
|
+
*/
|
|
1907
|
+
var StoreController = class {
|
|
1908
|
+
#host;
|
|
1909
|
+
#selector;
|
|
1910
|
+
#accessor;
|
|
1911
|
+
#snapshot = null;
|
|
1912
|
+
constructor(host, source, selector) {
|
|
1913
|
+
this.#host = host;
|
|
1914
|
+
this.#selector = selector;
|
|
1915
|
+
this.#accessor = new StoreAccessor(host, source, (store) => this.#connect(store));
|
|
1916
|
+
host.addController(this);
|
|
1917
|
+
}
|
|
1918
|
+
get value() {
|
|
1919
|
+
const store = this.#accessor.value;
|
|
1920
|
+
if (isNull(store)) throw new Error("Store not available");
|
|
1921
|
+
if (isUndefined(this.#selector)) return store;
|
|
1922
|
+
return this.#snapshot.value;
|
|
1923
|
+
}
|
|
1924
|
+
hostConnected() {}
|
|
1925
|
+
#connect(store) {
|
|
1926
|
+
if (isUndefined(this.#selector)) return;
|
|
1927
|
+
if (!this.#snapshot) this.#snapshot = new SnapshotController(this.#host, store.$state, this.#selector);
|
|
1928
|
+
else this.#snapshot.track(store.$state);
|
|
1929
|
+
}
|
|
1930
|
+
};
|
|
1931
|
+
|
|
1932
|
+
//#endregion
|
|
1933
|
+
//#region src/player/player-controller.ts
|
|
1934
|
+
/**
|
|
1935
|
+
* Reactive controller for accessing player store state.
|
|
1936
|
+
*
|
|
1937
|
+
* Without selector: Returns the store, does NOT subscribe to changes.
|
|
1938
|
+
* With selector: Returns selected state, subscribes with shallowEqual comparison.
|
|
1939
|
+
*
|
|
1940
|
+
* @example
|
|
1941
|
+
* ```ts
|
|
1942
|
+
* // Store access (no subscription)
|
|
1943
|
+
* class Controls extends MediaElement {
|
|
1944
|
+
* #player = new PlayerController(this, playerContext);
|
|
1945
|
+
*
|
|
1946
|
+
* handleClick() {
|
|
1947
|
+
* this.#player.value.setVolume(0.5);
|
|
1948
|
+
* }
|
|
1949
|
+
* }
|
|
1950
|
+
*
|
|
1951
|
+
* // Selector-based subscription
|
|
1952
|
+
* class PlayButton extends MediaElement {
|
|
1953
|
+
* #playback = new PlayerController(this, playerContext, selectPlayback);
|
|
1954
|
+
* }
|
|
1955
|
+
* ```
|
|
1956
|
+
*/
|
|
1957
|
+
var PlayerController = class {
|
|
1958
|
+
#host;
|
|
1959
|
+
#selector;
|
|
1960
|
+
#consumer;
|
|
1961
|
+
#store = null;
|
|
1962
|
+
constructor(host, context, selector) {
|
|
1963
|
+
this.#host = host;
|
|
1964
|
+
this.#selector = selector;
|
|
1965
|
+
this.#consumer = new ContextConsumer(host, {
|
|
1966
|
+
context,
|
|
1967
|
+
callback: (ctx) => this.#connect(ctx),
|
|
1968
|
+
subscribe: true
|
|
1969
|
+
});
|
|
1970
|
+
host.addController(this);
|
|
1971
|
+
}
|
|
1972
|
+
get value() {
|
|
1973
|
+
const store = this.#consumer.value;
|
|
1974
|
+
if (!store) return void 0;
|
|
1975
|
+
if (!this.#selector) return store;
|
|
1976
|
+
return this.#store?.value;
|
|
1977
|
+
}
|
|
1978
|
+
get displayName() {
|
|
1979
|
+
return this.#selector?.displayName;
|
|
1980
|
+
}
|
|
1981
|
+
hostConnected() {
|
|
1982
|
+
const store = this.#consumer.value;
|
|
1983
|
+
if (store) this.#connect(store);
|
|
1984
|
+
}
|
|
1985
|
+
hostDisconnected() {
|
|
1986
|
+
this.#store = null;
|
|
1987
|
+
}
|
|
1988
|
+
#connect(store) {
|
|
1989
|
+
if (!this.#store && this.#selector) this.#store = new StoreController(this.#host, store, this.#selector);
|
|
1990
|
+
}
|
|
1991
|
+
};
|
|
1992
|
+
|
|
1993
|
+
//#endregion
|
|
1994
|
+
//#region src/player/create-player.ts
|
|
1995
|
+
function createPlayer(config) {
|
|
1996
|
+
const slice = combine(...config.features);
|
|
1997
|
+
function create() {
|
|
1998
|
+
return createStore()(slice);
|
|
1999
|
+
}
|
|
2000
|
+
return {
|
|
2001
|
+
context: playerContext,
|
|
2002
|
+
create,
|
|
2003
|
+
PlayerController,
|
|
2004
|
+
ProviderMixin: createProviderMixin(playerContext, create),
|
|
2005
|
+
ContainerMixin: createContainerMixin(playerContext)
|
|
2006
|
+
};
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
//#endregion
|
|
2010
|
+
//#region src/define/safe-define.ts
|
|
2011
|
+
/** Define a custom element only if not already registered. */
|
|
2012
|
+
function safeDefine(element) {
|
|
2013
|
+
if (!customElements.get(element.tagName)) customElements.define(element.tagName, element);
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
//#endregion
|
|
2017
|
+
//#region src/define/background/player.ts
|
|
2018
|
+
const { ProviderMixin } = createPlayer({ features: backgroundFeatures });
|
|
2019
|
+
var BackgroundVideoPlayerElement = class extends ProviderMixin(MediaElement) {
|
|
2020
|
+
static {
|
|
2021
|
+
this.tagName = "background-video-player";
|
|
2022
|
+
}
|
|
2023
|
+
};
|
|
2024
|
+
safeDefine(BackgroundVideoPlayerElement);
|
|
2025
|
+
safeDefine(MediaContainerElement);
|
|
2026
|
+
|
|
2027
|
+
//#endregion
|
|
2028
|
+
//#region src/define/background/skin.ts
|
|
2029
|
+
function getTemplateHTML(_attrs) {
|
|
2030
|
+
return `
|
|
2031
|
+
<media-container>
|
|
2032
|
+
<slot name="media" slot="media"></slot>
|
|
2033
|
+
</media-container>
|
|
2034
|
+
`;
|
|
2035
|
+
}
|
|
2036
|
+
var BackgroundVideoSkinElement = class extends ReactiveElement {
|
|
2037
|
+
static {
|
|
2038
|
+
this.tagName = "background-video-skin";
|
|
2039
|
+
}
|
|
2040
|
+
static {
|
|
2041
|
+
this.shadowRootOptions = { mode: "open" };
|
|
2042
|
+
}
|
|
2043
|
+
static {
|
|
2044
|
+
this.getTemplateHTML = getTemplateHTML;
|
|
2045
|
+
}
|
|
2046
|
+
constructor() {
|
|
2047
|
+
super();
|
|
2048
|
+
if (!this.shadowRoot) {
|
|
2049
|
+
this.attachShadow(this.constructor.shadowRootOptions);
|
|
2050
|
+
this.shadowRoot.innerHTML = getTemplateHTML(namedNodeMapToObject(this.attributes));
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
safeDefine(BackgroundVideoSkinElement);
|
|
2055
|
+
|
|
2056
|
+
//#endregion
|
|
2057
|
+
//# sourceMappingURL=background.dev.js.map
|