@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 CHANGED
@@ -206,6 +206,10 @@ ninety seconds in each half of the runtime is the opening and the ending. Nothin
206
206
  fifteen seconds is ever offered, and a disc that is mostly themes offers nothing, because there the
207
207
  themes are what is being watched.
208
208
 
209
+ The same guess is published on its own, for a page that has to know what a chapter is without loading the player:
210
+ `classifyChapters(chapters)` from `@banou/media-player/chapters`, which imports nothing else of the player, gives
211
+ `'opening'`, `'ending'` or undefined for each chapter.
212
+
209
213
  ### Picture in picture keeps the subtitles
210
214
 
211
215
  Subtitles are painted by jassub onto a canvas over the video, and picture in picture takes a video
@@ -254,6 +258,29 @@ A finger never rests on the control before it presses, so a tap cannot arm it. T
254
258
  only where the primary pointer hovers (`(hover: hover) and (pointer: fine)`), and a touch hides it
255
259
  until a pointer that hovers moves again.
256
260
 
261
+ ### Fullscreen kept by the host page
262
+
263
+ A page that fullscreens an element of its own around the player, so that fullscreen outlasts the player in it, passes
264
+ `fullscreen`:
265
+
266
+ ```tsx
267
+ <div ref={stage}>
268
+ <MediaPlayer
269
+ {...source}
270
+ fullscreen={{
271
+ active: stageIsFullscreen,
272
+ request: () => document.fullscreenElement ? document.exitFullscreen() : stage.current!.requestFullscreen(),
273
+ }}
274
+ />
275
+ </div>
276
+ ```
277
+
278
+ The player then calls no `requestFullscreen`. The button, `f` and a double click each call `request` once, during the
279
+ press's own event, so the page's `requestFullscreen` has the press's activation, and the button and
280
+ `shortcuts="player"` follow `active`, which the page keeps up to date from its `fullscreenchange`. Without the prop
281
+ the player fullscreens itself. A player in another document hands its fullscreen over through
282
+ [`<MediaPlayer expose>`](#layout), to a mirror that asks for it.
283
+
257
284
  ### The volume normalizer
258
285
 
259
286
  A "Normalize volume" switch in the settings menu keeps the file's own normal level and turns down what goes well over
@@ -319,7 +346,9 @@ it has one.
319
346
 
320
347
  A media the player does not own reports picks the same way, by the option's label once the source's `select`
321
348
  resolves, and its host applies the preference to its own tracks: `preferredSelection(selection, preference)`, from
322
- `@banou/media-player/language`, names the option to select, and imports nothing else of the player.
349
+ `@banou/media-player/language`, names the option to select, and imports nothing else of the player. `languageTag(pick)`
350
+ from the same module gives a pick's BCP 47 tag (`jpn` gives `ja`, `Português (Brasil)` gives `pt-BR`), or undefined for
351
+ one naming no language, for code that reads tags.
323
352
 
324
353
  ## Layout
325
354
 
@@ -388,6 +417,18 @@ its published name so it stays an honest consumer.
388
417
  `emptied` and then the new state, the way an element would. Hand a remote player to a second
389
418
  `<MediaPlayer media={player}>` after `ready`. A document served with no frame around it serves
390
419
  nobody; `exposePlayer(media)` does the same without React.
420
+
421
+ A `<MediaPlayer expose>` also carries its chapters, as `player.chapters` with a `chapterschange` event after each
422
+ change (a bare element has none), and hands its fullscreen to a mirror made with `fullscreen: true`: the far
423
+ player's button, `f` and double click then fire one `fullscreenrequest` on the mirror each, within the press's
424
+ activation, and show `player.fullscreen` as this page sets it, until `destroy()` gives the fullscreen back.
425
+
426
+ ```ts
427
+ const player = mediaPlayer(iframe, { origin, fullscreen: true })
428
+ player.addEventListener('fullscreenrequest', () => document.fullscreenElement ? document.exitFullscreen() : stage.requestFullscreen())
429
+ document.addEventListener('fullscreenchange', () => { player.fullscreen = !!document.fullscreenElement })
430
+ player.addEventListener('chapterschange', () => console.log(player.chapters))
431
+ ```
391
432
  - `src/lib/react/` the player component, its chrome, and the hooks.
392
433
 
393
434
  Built by `vite.lib.config.ts` into `dist/`, which is what npm publishes.
@@ -0,0 +1,3 @@
1
+ export { classifyChapters } from '../utils/chapters';
2
+ export type { ChapterKind } from '../utils/chapters';
3
+ export type { MediaChapter } from '../engine';
@@ -0,0 +1,2 @@
1
+ import { t as e } from "../chapters-EBYXcEml.js";
2
+ export { e as classifyChapters };
@@ -0,0 +1,115 @@
1
+ //#region src/lib/utils/chapters.ts
2
+ var e = "#0000", t = (e, t) => {
3
+ if (!t) return [];
4
+ let n = /* @__PURE__ */ new Set();
5
+ for (let { start: r, end: i } of e) for (let e of [r, i]) {
6
+ let r = e / t;
7
+ r <= .005 || r >= .995 || n.add(Number((r * 100).toFixed(4)));
8
+ }
9
+ return n.size ? [
10
+ 0,
11
+ ...[...n].sort((e, t) => e - t),
12
+ 100
13
+ ] : [];
14
+ }, n = (t, n) => {
15
+ let r = t.length - 2, i = [];
16
+ for (let a = 0; a <= r; a += 1) {
17
+ let o = t[a], s = t[a + 1], c = a === 0 ? "0%" : `calc(${o}% + 1px)`, l = a === r ? "100%" : `calc(${s}% - 1px)`;
18
+ i.push(`${n(a) ? "#000" : e} ${c} ${l}`), a !== r && i.push(`${e} calc(${s}% - 1px) calc(${s}% + 1px)`);
19
+ }
20
+ return `linear-gradient(90deg, ${i.join(", ")})`;
21
+ }, r = /* @__PURE__ */ new Set([
22
+ "op",
23
+ "ops",
24
+ "opening",
25
+ "openings",
26
+ "ncop",
27
+ "オープニング",
28
+ "op主題歌"
29
+ ]), i = /* @__PURE__ */ new Set([
30
+ "ed",
31
+ "eds",
32
+ "ending",
33
+ "endings",
34
+ "nced",
35
+ "credits",
36
+ "endcard",
37
+ "endroll",
38
+ "エンディング",
39
+ "エンドカード",
40
+ "エンドロール",
41
+ "ed主題歌"
42
+ ]), a = /* @__PURE__ */ new Set(["intro", "イントロ"]), o = /* @__PURE__ */ new Set(["outro", "アウトロ"]), s = {
43
+ "credits start": "ending",
44
+ "credits end": null,
45
+ "preview end": null,
46
+ "end credits": "ending",
47
+ "closing credits": "ending"
48
+ }, c = /* @__PURE__ */ new Set([
49
+ "theme",
50
+ "themes",
51
+ "song",
52
+ "sequence",
53
+ "nc",
54
+ "non",
55
+ "credit",
56
+ "creditless",
57
+ "textless",
58
+ "clean",
59
+ "tv",
60
+ "size",
61
+ "version",
62
+ "ver",
63
+ "full",
64
+ "the",
65
+ "主題歌",
66
+ "ノンクレジット"
67
+ ]), l = /* @__PURE__ */ new Set([
68
+ "post",
69
+ "pre",
70
+ "after",
71
+ "before",
72
+ "non"
73
+ ]), u = /[-:|~/\\[\]()「」『』【】,.!?"'’]|\s+by\s+/u, d = (e) => !e.trim() || /^chapter\s*\d+$/i.test(e.trim()) || /^\d{1,2}:\d{2}:\d{2}([.,]\d+)?$/.test(e.trim()), f = (e) => e.replace(/([a-z぀-ヿ一-鿿])\s*\d+\s*$/u, "$1").split(/[\s_]+/u).map((e) => e.replace(/^[^\w぀-ヿ一-鿿]+|[^\w぀-ヿ一-鿿]+$/gu, "")).filter((e) => e && !/^\d+$/.test(e) && !c.has(e)), p = (e, t) => {
74
+ if (r.has(e)) return "opening";
75
+ if (i.has(e)) return "ending";
76
+ if (t) {
77
+ if (a.has(e)) return "opening";
78
+ if (o.has(e)) return "ending";
79
+ }
80
+ }, m = (e, t) => {
81
+ if (d(e)) return;
82
+ let n = e.trim().toLowerCase().replace(/\s+/gu, " ");
83
+ if (n in s) return s[n] ?? void 0;
84
+ let r = n.split(u).map((e) => e.trim()).filter(Boolean);
85
+ if (r.some((e) => e.split(/[\s_]+/u).some((e) => l.has(e)))) return;
86
+ let i = r.length > 1 ? [r[0], r.at(-1)] : r;
87
+ for (let e of i) {
88
+ let n = f(e);
89
+ if (n.length !== 1) continue;
90
+ let r = p(n[0], t);
91
+ if (r) return r;
92
+ }
93
+ }, h = 15, g = 87, _ = 93, v = (e) => {
94
+ let t = e.map(() => void 0), n = e.at(-1)?.end ?? 0;
95
+ if (!n) return t;
96
+ let r = e.map((e, t) => ({
97
+ index: t,
98
+ start: e.start,
99
+ length: e.end - e.start
100
+ })).filter(({ length: e }) => e >= g && e <= _), i = n / 2, a = r.filter(({ start: e }) => e < i), o = r.filter(({ start: e }) => e >= i);
101
+ return a.length === 1 && (t[a[0].index] = "opening"), o.length === 1 && (t[o[0].index] = "ending"), t;
102
+ }, y = (e) => {
103
+ let t = e.map(({ title: e }) => m(e, !1)), n = e.reduce((e, n, r) => e + (t[r] ? n.end - n.start : 0), 0), r = e.reduce((e, t) => e + (t.end - t.start), 0);
104
+ if (r > 0 && n * 2 > r) return e.map(() => void 0);
105
+ let i = e.map((e, n) => {
106
+ if (e.end - e.start < h) return;
107
+ let r = t[n];
108
+ if (r) return r;
109
+ let i = m(e.title, !0);
110
+ return i && !t.includes(i) ? i : void 0;
111
+ });
112
+ return e.every(({ title: e }) => d(e)) ? v(e) : i;
113
+ };
114
+ //#endregion
115
+ export { t as n, n as r, y as t };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { MediaPlayer, default } from './react/video-player';
2
- export type { MediaPlayerOptions, MediaPlayerLocalOptions, MediaPlayerRemoteOptions, MediaPlayerSource, } from './react/video-player';
2
+ export type { HostFullscreen, MediaPlayerOptions, MediaPlayerLocalOptions, MediaPlayerRemoteOptions, MediaPlayerSource, } from './react/video-player';
3
3
  export { isDelegatedTracks, isExternalThumbnails } from './react/media';
4
4
  export type { DelegatedSelection, DelegatedTracks, ExternalThumbnails, PassThroughPictureInPicture, PlayerMedia, TimeRangesLike, } from './react/media';
5
5
  export { Player, usePlayer } from './react/player';