@banou/media-player 0.10.28 → 0.10.30
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/README.md +42 -1
- package/dist/chapters/index.d.ts +3 -0
- package/dist/chapters/index.js +2 -0
- package/dist/chapters-EBYXcEml.js +115 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +728 -814
- package/dist/language/index.d.ts +6 -0
- package/dist/language/index.js +34 -27
- package/dist/react/components/chrome.d.ts +4 -1
- package/dist/react/components/control-bar.d.ts +3 -1
- package/dist/react/components/tooltip-display.d.ts +2 -0
- package/dist/react/video-player.d.ts +19 -0
- package/dist/remote/index.d.ts +27 -1
- package/dist/remote/index.js +163 -139
- package/dist/remote/protocol.d.ts +16 -4
- package/package.json +5 -1
- package/src/lib/chapters/index.ts +5 -0
- package/src/lib/index.tsx +1 -0
- package/src/lib/language/index.ts +13 -1
- package/src/lib/react/components/chrome.tsx +12 -3
- package/src/lib/react/components/control-bar.tsx +21 -6
- package/src/lib/react/components/tooltip-display.tsx +14 -2
- package/src/lib/react/video-player.tsx +43 -2
- package/src/lib/remote/index.ts +99 -18
- package/src/lib/remote/protocol.ts +16 -5
package/dist/language/index.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export type LanguageTrack = {
|
|
|
9
9
|
* neither names a language.
|
|
10
10
|
*/
|
|
11
11
|
export declare const languageOf: (track: LanguageTrack | undefined) => string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The BCP 47 tag of the language `text` names, as a tag (`jpn`, `en_US`) or a name (`Japanese`, `Português (Brasil)`),
|
|
14
|
+
* with its region or script when it names one: `ja`, `en-US`, `pt-BR`. Undefined for a text naming no language (`und`,
|
|
15
|
+
* `Signs & Songs`), so a preference `languageOf` saved can be handed to code that reads tags.
|
|
16
|
+
*/
|
|
17
|
+
export declare const languageTag: (text: string | undefined) => string | undefined;
|
|
12
18
|
/**
|
|
13
19
|
* The index of the track to play for a preferred language (a tag or a name, as `languageOf` gives it), else of the
|
|
14
20
|
* track titled exactly as the preference, or -1 when there is neither. A full track wins over a signs, songs, forced
|
package/dist/language/index.js
CHANGED
|
@@ -14,21 +14,25 @@ var e = "aa ab ae af ak am an ar as av ay az ba be bg bi bm bn bo br bs ca ce ch
|
|
|
14
14
|
"zxx",
|
|
15
15
|
"mul",
|
|
16
16
|
"mis"
|
|
17
|
-
]), r = /sign|song|forced|commentary|karaoke|descri/i, i = /full|dialog/i, a =
|
|
17
|
+
]), r = /sign|song|forced|commentary|karaoke|descri/i, i = /full|dialog/i, a = /* @__PURE__ */ new Set([
|
|
18
|
+
"CC",
|
|
19
|
+
"HI",
|
|
20
|
+
"AD"
|
|
21
|
+
]), o = (e) => e.normalize("NFKC").toLowerCase().replace(/\s+/g, " ").trim(), s = new Intl.DisplayNames(["en"], {
|
|
18
22
|
type: "language",
|
|
19
23
|
fallback: "none"
|
|
20
|
-
}),
|
|
24
|
+
}), c = (e) => {
|
|
21
25
|
if (/^[a-z]{2,3}(?:[-_][a-z\d]{2,8})*$/i.test(e)) try {
|
|
22
26
|
let t = new Intl.Locale(e.replace(/_/g, "-"));
|
|
23
|
-
return n.has(t.language) || !
|
|
27
|
+
return n.has(t.language) || !s.of(t.language) ? void 0 : {
|
|
24
28
|
language: t.language,
|
|
25
29
|
variant: t.region ?? t.script
|
|
26
30
|
};
|
|
27
31
|
} catch {
|
|
28
32
|
return;
|
|
29
33
|
}
|
|
30
|
-
},
|
|
31
|
-
if (
|
|
34
|
+
}, l, u = () => {
|
|
35
|
+
if (l) return l;
|
|
32
36
|
let n = /* @__PURE__ */ new Map(), r = [...new Set(["en", globalThis.navigator?.language].filter((e) => !!e))], i = (e, t, r) => {
|
|
33
37
|
try {
|
|
34
38
|
let i = new Intl.DisplayNames([t], {
|
|
@@ -36,40 +40,43 @@ var e = "aa ab ae af ak am an ar as av ay az ba be bg bi bm bn bo br bs ca ce ch
|
|
|
36
40
|
languageDisplay: r,
|
|
37
41
|
fallback: "none"
|
|
38
42
|
}).of(e);
|
|
39
|
-
i && !n.has(
|
|
43
|
+
i && !n.has(o(i)) && n.set(o(i), e);
|
|
40
44
|
} catch {}
|
|
41
45
|
};
|
|
42
46
|
for (let e of t) for (let t of [...r, e]) for (let n of ["dialect", "standard"]) i(e, t, n);
|
|
43
47
|
for (let t of e) for (let e of [...r, t]) i(t, e, "dialect");
|
|
44
|
-
return
|
|
45
|
-
},
|
|
48
|
+
return l = n;
|
|
49
|
+
}, d = (e) => {
|
|
46
50
|
let t = e?.trim();
|
|
47
51
|
if (!t) return;
|
|
48
|
-
let n =
|
|
49
|
-
if (r) return
|
|
50
|
-
let [, i,
|
|
51
|
-
if (!
|
|
52
|
-
let
|
|
53
|
-
return (
|
|
54
|
-
},
|
|
52
|
+
let n = u(), r = n.get(o(t));
|
|
53
|
+
if (r) return c(r);
|
|
54
|
+
let [, i, s] = /^([^([]+)(?:\(([^)]*)\))?/.exec(t.normalize("NFKC")) ?? [], l = i ? n.get(o(i)) : void 0;
|
|
55
|
+
if (!l) return;
|
|
56
|
+
let d = s?.trim();
|
|
57
|
+
return (d && /^(?:[A-Z]{2}|\d{3})$/.test(d) && !a.has(d) ? c(`${l}-${d}`) : void 0) ?? c(l);
|
|
58
|
+
}, f = (e) => {
|
|
55
59
|
let t = e?.trim();
|
|
56
|
-
return t ?
|
|
57
|
-
},
|
|
60
|
+
return t ? c(t) ?? d(t) : void 0;
|
|
61
|
+
}, p = (e) => f(e?.language) ? e.language.trim() : d(e?.title) ? e.title.trim() : void 0, m = (e) => {
|
|
62
|
+
let t = f(e);
|
|
63
|
+
return t && (t.variant ? `${t.language}-${t.variant}` : t.language);
|
|
64
|
+
}, h = ({ language: e = "", title: t = "" }) => {
|
|
58
65
|
let n = `${e} ${t}`;
|
|
59
66
|
return r.test(n) && !i.test(n);
|
|
60
|
-
},
|
|
61
|
-
let n =
|
|
62
|
-
return n && t.forEach((t,
|
|
63
|
-
let s =
|
|
67
|
+
}, g = (e, t) => {
|
|
68
|
+
let n = f(e), r = -1, i = 0;
|
|
69
|
+
return n && t.forEach((t, a) => {
|
|
70
|
+
let s = f(t.language) ?? d(t.title);
|
|
64
71
|
if (s?.language !== n.language) return;
|
|
65
|
-
let c =
|
|
66
|
-
l > i && (r =
|
|
67
|
-
}), r === -1 ? t.findIndex(({ title: t }) => !!t?.trim() &&
|
|
68
|
-
},
|
|
72
|
+
let c = p(t), l = 1 + +(s.variant === n.variant) + (c && o(c) === o(e) ? 2 : 0) + (h(t) ? 0 : 4);
|
|
73
|
+
l > i && (r = a, i = l);
|
|
74
|
+
}), r === -1 ? t.findIndex(({ title: t }) => !!t?.trim() && o(t) === o(e)) : r;
|
|
75
|
+
}, _ = (e, t) => {
|
|
69
76
|
if (t === void 0) return;
|
|
70
77
|
if (t === null) return e.offLabel && e.selectedId !== null ? null : void 0;
|
|
71
|
-
let n = e.options.filter((e) => !e.disabled), r = n[
|
|
78
|
+
let n = e.options.filter((e) => !e.disabled), r = n[g(t, n.map(({ label: e }) => ({ title: e })))]?.id;
|
|
72
79
|
return r !== void 0 && r !== e.selectedId ? r : void 0;
|
|
73
80
|
};
|
|
74
81
|
//#endregion
|
|
75
|
-
export {
|
|
82
|
+
export { p as languageOf, m as languageTag, _ as preferredSelection, g as preferredTrack };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode, Ref } from 'react';
|
|
2
|
+
import type { HostFullscreen } from '../video-player';
|
|
2
3
|
export type ChromeProps = {
|
|
3
4
|
ref?: Ref<HTMLDivElement> | ((element: HTMLDivElement | null) => void);
|
|
4
5
|
/** Absent means render no video element: the media belongs to someone else and arrives as children. */
|
|
@@ -9,7 +10,9 @@ export type ChromeProps = {
|
|
|
9
10
|
/** False draws no control bar at all, leaving the picture, the title and the overlay. */
|
|
10
11
|
controls?: boolean;
|
|
11
12
|
shortcuts?: 'window' | 'player';
|
|
13
|
+
/** Fullscreen kept by the host: a press calls its `request` instead of fullscreening the player. */
|
|
14
|
+
fullscreen?: HostFullscreen;
|
|
12
15
|
children?: ReactNode;
|
|
13
16
|
};
|
|
14
|
-
export declare const Chrome: ({ ref, onVideoRef, onSubtitleRef, overlay, controls, shortcuts, children }: ChromeProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare const Chrome: ({ ref, onVideoRef, onSubtitleRef, overlay, controls, shortcuts, fullscreen, children }: ChromeProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
15
18
|
export default Chrome;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { RefObject } from 'react';
|
|
2
|
-
|
|
2
|
+
import type { HostFullscreen } from '../video-player';
|
|
3
|
+
export declare const ControlBar: ({ shortcuts, root, fullscreen: host }: {
|
|
3
4
|
shortcuts?: 'window' | 'player';
|
|
4
5
|
root: RefObject<HTMLDivElement | null>;
|
|
6
|
+
fullscreen?: HostFullscreen;
|
|
5
7
|
}) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
6
8
|
export default ControlBar;
|
|
@@ -5,6 +5,8 @@ export declare enum buttonSize {
|
|
|
5
5
|
md = "md",
|
|
6
6
|
lg = "lg"
|
|
7
7
|
}
|
|
8
|
+
/** Whether the host page keeps the player's fullscreen: the `fullscreen` prop, or a mirror that took it over. */
|
|
9
|
+
export declare const HostKeepsFullscreen: import("react").Context<boolean>;
|
|
8
10
|
interface TooltipDisplayProps {
|
|
9
11
|
id: string;
|
|
10
12
|
toolTipText: ReactNode;
|
|
@@ -20,6 +20,19 @@ export type MediaPlayerSource = {
|
|
|
20
20
|
size?: undefined;
|
|
21
21
|
readsDownload?: undefined;
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Fullscreen kept by the host page rather than by the player, for a page that fullscreens an element of its own around
|
|
25
|
+
* the player, so that fullscreen outlasts the player in it.
|
|
26
|
+
*/
|
|
27
|
+
export type HostFullscreen = {
|
|
28
|
+
/** Whether the host shows the player fullscreen: the button shows it, and the `'player'` shortcuts follow it. */
|
|
29
|
+
active: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The viewer pressed fullscreen (the button, `f` or a double click): the host enters or leaves it. Called once per
|
|
32
|
+
* press, during that press's event, so the host's own `requestFullscreen` has the press's activation.
|
|
33
|
+
*/
|
|
34
|
+
request: () => void;
|
|
35
|
+
};
|
|
23
36
|
/** Shared by both arms: nothing here depends on who owns the media. */
|
|
24
37
|
type CommonOptions = {
|
|
25
38
|
/**
|
|
@@ -72,6 +85,12 @@ type CommonOptions = {
|
|
|
72
85
|
* is fullscreen, so Space and the arrow keys keep scrolling the page and pressing its buttons everywhere else.
|
|
73
86
|
*/
|
|
74
87
|
shortcuts?: 'window' | 'player';
|
|
88
|
+
/**
|
|
89
|
+
* Hand fullscreen to the host page: the player then never calls `requestFullscreen`, each press of its fullscreen
|
|
90
|
+
* calls `request` once, and the button and the `'player'` shortcuts follow `active`. Read by value, so it may be
|
|
91
|
+
* written inline. Without it the player fullscreens itself.
|
|
92
|
+
*/
|
|
93
|
+
fullscreen?: HostFullscreen;
|
|
75
94
|
/**
|
|
76
95
|
* The app's own content over the video: a download readout, a badge, a logo, anything the player
|
|
77
96
|
* itself has no opinion about.
|
package/dist/remote/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Transport } from 'osra';
|
|
2
|
+
import type { MediaChapter } from '../engine';
|
|
2
3
|
import type { PlayerMedia } from '../react/media';
|
|
3
4
|
import type { Writable } from './protocol';
|
|
4
5
|
export type { PlayerEvent, PlayerSnapshot, PlayerUpdate } from './protocol';
|
|
5
|
-
export { DEFAULT_PLAYER_ID, PLAYER_CHANNEL, PLAYER_EVENTS } from './protocol';
|
|
6
|
+
export { DEFAULT_PLAYER_ID, PLAYER_CHANNEL, PLAYER_EVENTS, SERVED_EVENTS } from './protocol';
|
|
6
7
|
/**
|
|
7
8
|
* Where a player serves from, and to whom.
|
|
8
9
|
*
|
|
@@ -41,6 +42,18 @@ export type ExposePlayerOptions = {
|
|
|
41
42
|
* and a channel that closed in between would drop every embedder listening to the others.
|
|
42
43
|
*/
|
|
43
44
|
signal?: AbortSignal;
|
|
45
|
+
/** What `<MediaPlayer expose>` serves beside its media. A document serving a bare element leaves it out. */
|
|
46
|
+
player?: ServedPlayer;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The player around a served media, as `<MediaPlayer expose>` passes it: its chapters, sent with every snapshot and
|
|
50
|
+
* announced on its `chapterschange`, and its fullscreen, which a mirror made with `fullscreen: true` takes over. While
|
|
51
|
+
* one has it, `onHostFullscreen` is told the state that mirror sets, and null once none has it; the player then
|
|
52
|
+
* dispatches `fullscreenrequest` for each press of its fullscreen, which reaches the mirror.
|
|
53
|
+
*/
|
|
54
|
+
export type ServedPlayer = EventTarget & {
|
|
55
|
+
readonly chapters: MediaChapter[];
|
|
56
|
+
onHostFullscreen: (active: boolean | null) => void;
|
|
44
57
|
};
|
|
45
58
|
/**
|
|
46
59
|
* Serve `media` to this document's embedder. Returns the teardown for THIS media.
|
|
@@ -72,6 +85,13 @@ type Mirrored = Omit<PlayerMedia, Writable>;
|
|
|
72
85
|
export type MediaPlayerHandle = {
|
|
73
86
|
readonly [K in keyof Mirrored]: Mirrored[K];
|
|
74
87
|
} & Readonly<Required<Pick<PlayerMedia, 'src' | 'currentSrc' | 'ended' | 'buffered' | 'seekable' | 'error' | 'videoWidth' | 'videoHeight'>>> & Required<Pick<PlayerMedia, Writable>> & {
|
|
88
|
+
/** The far player's chapters, empty for a bare element. A `chapterschange` event follows each change. */
|
|
89
|
+
readonly chapters: MediaChapter[];
|
|
90
|
+
/**
|
|
91
|
+
* With the `fullscreen` option, whether this page shows the far player fullscreen: its button and its `'player'`
|
|
92
|
+
* shortcuts follow it. Set it on every change. Without the option it stays here.
|
|
93
|
+
*/
|
|
94
|
+
fullscreen: boolean;
|
|
75
95
|
/**
|
|
76
96
|
* Settles once the far side has first answered with its state; reads before that answer the
|
|
77
97
|
* empty defaults. Stays pending for as long as nobody answers, and rejects with an AbortError on
|
|
@@ -129,6 +149,12 @@ export type MediaPlayerHandleOptions = {
|
|
|
129
149
|
channel?: string;
|
|
130
150
|
/** closes the mirror: `ready` rejects with an AbortError and nothing more is heard */
|
|
131
151
|
signal?: AbortSignal;
|
|
152
|
+
/**
|
|
153
|
+
* Take the far player's fullscreen over, when it is a `<MediaPlayer expose>`: its button, `f` and double click then
|
|
154
|
+
* call no `requestFullscreen` and fire one `fullscreenrequest` on the handle each, inside the press's activation,
|
|
155
|
+
* and show the handle's `fullscreen`. Released on `destroy()`. A bare element ignores it.
|
|
156
|
+
*/
|
|
157
|
+
fullscreen?: boolean;
|
|
132
158
|
};
|
|
133
159
|
/**
|
|
134
160
|
* Mirror a player another document is serving, as a media of this one.
|