@mattebox/player 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/cdn/mattebox-player.min.js +3 -3
  2. package/dist/controls/icons.d.ts +1 -1
  3. package/dist/controls/icons.d.ts.map +1 -1
  4. package/dist/controls/icons.js +1 -0
  5. package/dist/controls/icons.js.map +1 -1
  6. package/dist/controls/native-tracks.d.ts +8 -7
  7. package/dist/controls/native-tracks.d.ts.map +1 -1
  8. package/dist/controls/native-tracks.js.map +1 -1
  9. package/dist/element.d.ts +46 -1
  10. package/dist/element.d.ts.map +1 -1
  11. package/dist/element.js +142 -13
  12. package/dist/element.js.map +1 -1
  13. package/dist/elements/control-bar.d.ts.map +1 -1
  14. package/dist/elements/control-bar.js +8 -6
  15. package/dist/elements/control-bar.js.map +1 -1
  16. package/dist/elements/error-screen.d.ts.map +1 -1
  17. package/dist/elements/error-screen.js +1 -3
  18. package/dist/elements/error-screen.js.map +1 -1
  19. package/dist/elements/play-button.d.ts.map +1 -1
  20. package/dist/elements/play-button.js +7 -9
  21. package/dist/elements/play-button.js.map +1 -1
  22. package/dist/elements/shared.d.ts +18 -0
  23. package/dist/elements/shared.d.ts.map +1 -1
  24. package/dist/elements/shared.js +16 -9
  25. package/dist/elements/shared.js.map +1 -1
  26. package/dist/elements/start-button.d.ts.map +1 -1
  27. package/dist/elements/start-button.js +3 -3
  28. package/dist/elements/start-button.js.map +1 -1
  29. package/dist/elements/title.d.ts.map +1 -1
  30. package/dist/elements/title.js +5 -2
  31. package/dist/elements/title.js.map +1 -1
  32. package/dist/elements/video-menu.d.ts +23 -0
  33. package/dist/elements/video-menu.d.ts.map +1 -0
  34. package/dist/elements/video-menu.js +146 -0
  35. package/dist/elements/video-menu.js.map +1 -0
  36. package/dist/entries/video-menu.d.ts +5 -0
  37. package/dist/entries/video-menu.d.ts.map +1 -0
  38. package/dist/entries/video-menu.js +9 -0
  39. package/dist/entries/video-menu.js.map +1 -0
  40. package/dist/es2015/controls/icons.js +1 -0
  41. package/dist/es2015/element.js +187 -60
  42. package/dist/es2015/elements/control-bar.js +8 -6
  43. package/dist/es2015/elements/error-screen.js +2 -3
  44. package/dist/es2015/elements/play-button.js +8 -10
  45. package/dist/es2015/elements/shared.js +16 -9
  46. package/dist/es2015/elements/start-button.js +3 -3
  47. package/dist/es2015/elements/title.js +5 -2
  48. package/dist/es2015/elements/video-menu.js +152 -0
  49. package/dist/es2015/entries/video-menu.js +7 -0
  50. package/dist/es2015/index.js +3 -1
  51. package/dist/es2015/tags.js +2 -1
  52. package/dist/es2015/video-sources.js +128 -0
  53. package/dist/host.d.ts +10 -1
  54. package/dist/host.d.ts.map +1 -1
  55. package/dist/host.js.map +1 -1
  56. package/dist/index.d.ts +3 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +3 -1
  59. package/dist/tags.d.ts +1 -0
  60. package/dist/tags.d.ts.map +1 -1
  61. package/dist/tags.js +2 -1
  62. package/dist/tags.js.map +1 -1
  63. package/dist/video-sources.d.ts +48 -0
  64. package/dist/video-sources.d.ts.map +1 -0
  65. package/dist/video-sources.js +134 -0
  66. package/dist/video-sources.js.map +1 -0
  67. package/package.json +3 -3
@@ -0,0 +1,134 @@
1
+ import { isAudioDescription, isSdh } from "mattebox";
2
+ //#region src/video-sources.ts
3
+ /** The child element that declares a version in markup, as `<track>` declares text. */
4
+ const VIDEO_TRACK = "mbx-video-track";
5
+ /** The versions the `<mbx-video-track>` children of `element` declare, in their order. */
6
+ function markupVideoTracks(element) {
7
+ const found = [];
8
+ for (const child of Array.from(element.children)) {
9
+ const url = child.localName === "mbx-video-track" ? child.getAttribute("src") : null;
10
+ if (url === null) continue;
11
+ const type = child.getAttribute("type");
12
+ const label = child.getAttribute("label");
13
+ const language = child.getAttribute("srclang");
14
+ found.push({
15
+ url,
16
+ kind: child.getAttribute("kind") ?? "alternative",
17
+ ...type === null ? {} : { type },
18
+ ...label === null ? {} : { label },
19
+ ...language === null ? {} : { language }
20
+ });
21
+ }
22
+ return found;
23
+ }
24
+ /** The source a version loads as. Without EME it brings no DRM, as a source does not. */
25
+ function versionSource(track, eme) {
26
+ return {
27
+ url: track.url,
28
+ ...track.type === void 0 ? {} : { type: track.type },
29
+ ...eme && track.drm !== void 0 ? { drm: track.drm } : {}
30
+ };
31
+ }
32
+ /**
33
+ * Puts the new load where the old one was: the same position, and playing
34
+ * when it played. A position on a live source means nothing on another
35
+ * stream's timeline, so `at` is null there and the load joins at its edge.
36
+ * A load that empties the video before its metadata drops the wait.
37
+ */
38
+ function resume(media, at, playing) {
39
+ const go = () => {
40
+ media.removeEventListener("emptied", drop);
41
+ if (at !== null) media.currentTime = at;
42
+ if (playing) media.play().catch(() => void 0);
43
+ };
44
+ const drop = () => {
45
+ media.removeEventListener("loadedmetadata", go);
46
+ };
47
+ if (media.readyState >= 1) {
48
+ go();
49
+ return;
50
+ }
51
+ media.addEventListener("loadedmetadata", go, { once: true });
52
+ media.addEventListener("emptied", drop, { once: true });
53
+ }
54
+ function chosen(engine) {
55
+ if (engine === null) return null;
56
+ return {
57
+ audio: engine.tracks.active("audio"),
58
+ text: engine.tracks.active("text")
59
+ };
60
+ }
61
+ /** The same language, and the same audio description or SDH flag. */
62
+ function same(a, b) {
63
+ return a.lang === b.lang && isAudioDescription(a) === isAudioDescription(b) && isSdh(a) === isSdh(b) && a.forced === b.forced;
64
+ }
65
+ /**
66
+ * Selects on `engine` the tracks that match what the viewer had, once its
67
+ * manifest lists them. A track with no match keeps the engine's default.
68
+ */
69
+ function restore(engine, had) {
70
+ if (engine === null || had === null) return;
71
+ const apply = () => {
72
+ const { available } = engine.tracks;
73
+ for (const [contentType, track] of [["audio", had.audio], ["text", had.text]]) {
74
+ if (track === null) {
75
+ if (contentType === "text") engine.tracks.deselect("text");
76
+ continue;
77
+ }
78
+ const match = available.find((t) => t.contentType === contentType && engine.tracks.selectable(t.id) && same(t, track));
79
+ if (match !== void 0) engine.tracks.select(match.id);
80
+ }
81
+ };
82
+ if (engine.tracks.available.length > 0) {
83
+ apply();
84
+ return;
85
+ }
86
+ const off = engine.on("tracks:changed", () => {
87
+ off();
88
+ apply();
89
+ });
90
+ }
91
+ /**
92
+ * Shows the frame on screen as the poster of `media` while the next load has
93
+ * none: a new load empties the video, which then shows its poster, so the
94
+ * picture would flash to the poster and back. Returns the function that puts
95
+ * the poster back, or null when there is no frame to hold or the canvas
96
+ * cannot export it, as for a video from another origin without CORS.
97
+ */
98
+ function holdFrame(media) {
99
+ if (media.readyState < 2 || media.videoWidth === 0) return null;
100
+ const canvas = document.createElement("canvas");
101
+ canvas.width = media.videoWidth;
102
+ canvas.height = media.videoHeight;
103
+ let frame;
104
+ try {
105
+ canvas.getContext("2d")?.drawImage(media, 0, 0);
106
+ frame = canvas.toDataURL("image/jpeg", .9);
107
+ } catch {
108
+ return null;
109
+ }
110
+ const poster = media.getAttribute("poster");
111
+ media.setAttribute("poster", frame);
112
+ return () => {
113
+ if (media.getAttribute("poster") !== frame) return;
114
+ if (poster === null) media.removeAttribute("poster");
115
+ else media.setAttribute("poster", poster);
116
+ };
117
+ }
118
+ /**
119
+ * Calls `release` once the new load shows a frame where `resume` put it:
120
+ * after the seek to `at`, or on the first frame when it joins a live edge,
121
+ * or when playback starts.
122
+ */
123
+ function onNextFrame(media, at, release) {
124
+ const events = ["playing", at === null ? "loadeddata" : "seeked"];
125
+ const done = () => {
126
+ for (const type of events) media.removeEventListener(type, done);
127
+ release();
128
+ };
129
+ for (const type of events) media.addEventListener(type, done);
130
+ }
131
+ //#endregion
132
+ export { VIDEO_TRACK, chosen, holdFrame, markupVideoTracks, onNextFrame, restore, resume, versionSource };
133
+
134
+ //# sourceMappingURL=video-sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-sources.js","names":[],"sources":["../src/video-sources.ts"],"sourcesContent":["/**\n * Versions of the picture at their own URLs, such as a sign-language\n * version. A switch is a new load, so the element carries over what the\n * viewer had: the position, the play state, and the audio and subtitle\n * choice. A track inside the manifest needs none of this: the engine\n * switches it in the same session.\n */\nimport type { Source, SourceVideoTrack } from '@mattebox/player-core';\nimport type { Mattebox, Track } from 'mattebox';\nimport { isAudioDescription, isSdh } from 'mattebox';\n\n/** The child element that declares a version in markup, as `<track>` declares text. */\nexport const VIDEO_TRACK = 'mbx-video-track';\n\n/** The versions the `<mbx-video-track>` children of `element` declare, in their order. */\nexport function markupVideoTracks(element: Element): SourceVideoTrack[] {\n const found: SourceVideoTrack[] = [];\n for (const child of Array.from(element.children)) {\n const url = child.localName === VIDEO_TRACK ? child.getAttribute('src') : null;\n if (url === null) continue;\n const type = child.getAttribute('type');\n const label = child.getAttribute('label');\n const language = child.getAttribute('srclang');\n found.push({\n url,\n kind: child.getAttribute('kind') ?? 'alternative',\n ...(type === null ? {} : { type }),\n ...(label === null ? {} : { label }),\n ...(language === null ? {} : { language }),\n });\n }\n return found;\n}\n\n/** The source a version loads as. Without EME it brings no DRM, as a source does not. */\nexport function versionSource(track: SourceVideoTrack, eme: boolean): Source {\n return {\n url: track.url,\n ...(track.type === undefined ? {} : { type: track.type }),\n ...(eme && track.drm !== undefined ? { drm: track.drm } : {}),\n };\n}\n\n/**\n * Puts the new load where the old one was: the same position, and playing\n * when it played. A position on a live source means nothing on another\n * stream's timeline, so `at` is null there and the load joins at its edge.\n * A load that empties the video before its metadata drops the wait.\n */\nexport function resume(media: HTMLMediaElement, at: number | null, playing: boolean): void {\n const go = (): void => {\n media.removeEventListener('emptied', drop);\n if (at !== null) media.currentTime = at;\n if (playing) media.play().catch(() => undefined);\n };\n const drop = (): void => {\n media.removeEventListener('loadedmetadata', go);\n };\n if (media.readyState >= 1) {\n go();\n return;\n }\n media.addEventListener('loadedmetadata', go, { once: true });\n media.addEventListener('emptied', drop, { once: true });\n}\n\n/** The audio and subtitle tracks a viewer had; text is null when subtitles were off. */\nexport interface Chosen {\n readonly audio: Track | null;\n readonly text: Track | null;\n}\n\nexport function chosen(engine: Mattebox | null): Chosen | null {\n if (engine === null) return null;\n return { audio: engine.tracks.active('audio'), text: engine.tracks.active('text') };\n}\n\n/** The same language, and the same audio description or SDH flag. */\nfunction same(a: Track, b: Track): boolean {\n return (\n a.lang === b.lang &&\n isAudioDescription(a) === isAudioDescription(b) &&\n isSdh(a) === isSdh(b) &&\n a.forced === b.forced\n );\n}\n\n/**\n * Selects on `engine` the tracks that match what the viewer had, once its\n * manifest lists them. A track with no match keeps the engine's default.\n */\nexport function restore(engine: Mattebox | null, had: Chosen | null): void {\n if (engine === null || had === null) return;\n const apply = (): void => {\n const { available } = engine.tracks;\n for (const [contentType, track] of [\n ['audio', had.audio],\n ['text', had.text],\n ] as const) {\n if (track === null) {\n if (contentType === 'text') engine.tracks.deselect('text');\n continue;\n }\n const match = available.find(\n (t) => t.contentType === contentType && engine.tracks.selectable(t.id) && same(t, track),\n );\n if (match !== undefined) engine.tracks.select(match.id);\n }\n };\n if (engine.tracks.available.length > 0) {\n apply();\n return;\n }\n const off = engine.on('tracks:changed', () => {\n off();\n apply();\n });\n}\n\n/**\n * Shows the frame on screen as the poster of `media` while the next load has\n * none: a new load empties the video, which then shows its poster, so the\n * picture would flash to the poster and back. Returns the function that puts\n * the poster back, or null when there is no frame to hold or the canvas\n * cannot export it, as for a video from another origin without CORS.\n */\nexport function holdFrame(media: HTMLVideoElement): (() => void) | null {\n if (media.readyState < 2 || media.videoWidth === 0) return null;\n const canvas = document.createElement('canvas');\n canvas.width = media.videoWidth;\n canvas.height = media.videoHeight;\n let frame: string;\n try {\n canvas.getContext('2d')?.drawImage(media, 0, 0);\n frame = canvas.toDataURL('image/jpeg', 0.9);\n } catch {\n return null;\n }\n const poster = media.getAttribute('poster');\n media.setAttribute('poster', frame);\n return () => {\n // A poster the page set meanwhile stays.\n if (media.getAttribute('poster') !== frame) return;\n if (poster === null) media.removeAttribute('poster');\n else media.setAttribute('poster', poster);\n };\n}\n\n/**\n * Calls `release` once the new load shows a frame where `resume` put it:\n * after the seek to `at`, or on the first frame when it joins a live edge,\n * or when playback starts.\n */\nexport function onNextFrame(media: HTMLMediaElement, at: number | null, release: () => void): void {\n const events = ['playing', at === null ? 'loadeddata' : 'seeked'];\n const done = (): void => {\n for (const type of events) media.removeEventListener(type, done);\n release();\n };\n for (const type of events) media.addEventListener(type, done);\n}\n"],"mappings":";;;AAYA,MAAa,cAAc;;AAG3B,SAAgB,kBAAkB,SAAsC;CACtE,MAAM,QAA4B,CAAC;CACnC,KAAK,MAAM,SAAS,MAAM,KAAK,QAAQ,QAAQ,GAAG;EAChD,MAAM,MAAM,MAAM,cAAA,oBAA4B,MAAM,aAAa,KAAK,IAAI;EAC1E,IAAI,QAAQ,MAAM;EAClB,MAAM,OAAO,MAAM,aAAa,MAAM;EACtC,MAAM,QAAQ,MAAM,aAAa,OAAO;EACxC,MAAM,WAAW,MAAM,aAAa,SAAS;EAC7C,MAAM,KAAK;GACT;GACA,MAAM,MAAM,aAAa,MAAM,KAAK;GACpC,GAAI,SAAS,OAAO,CAAC,IAAI,EAAE,KAAK;GAChC,GAAI,UAAU,OAAO,CAAC,IAAI,EAAE,MAAM;GAClC,GAAI,aAAa,OAAO,CAAC,IAAI,EAAE,SAAS;EAC1C,CAAC;CACH;CACA,OAAO;AACT;;AAGA,SAAgB,cAAc,OAAyB,KAAsB;CAC3E,OAAO;EACL,KAAK,MAAM;EACX,GAAI,MAAM,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,MAAM,KAAK;EACvD,GAAI,OAAO,MAAM,QAAQ,KAAA,IAAY,EAAE,KAAK,MAAM,IAAI,IAAI,CAAC;CAC7D;AACF;;;;;;;AAQA,SAAgB,OAAO,OAAyB,IAAmB,SAAwB;CACzF,MAAM,WAAiB;EACrB,MAAM,oBAAoB,WAAW,IAAI;EACzC,IAAI,OAAO,MAAM,MAAM,cAAc;EACrC,IAAI,SAAS,MAAM,KAAK,CAAC,CAAC,YAAY,KAAA,CAAS;CACjD;CACA,MAAM,aAAmB;E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,MAAM,aAAa,KAAK,MAAM,eAAe,GAAG,OAAO;CAC3D,MAAM,SAAS,SAAS,cAAc,QAAQ;CAC9C,OAAO,QAAQ,MAAM;CACrB,OAAO,SAAS,MAAM;CACtB,IAAI;CACJ,IAAI;EACF,OAAO,WAAW,IAAI,CAAC,EAAE,UAAU,OAAO,GAAG,CAAC;EAC9C,QAAQ,OAAO,UAAU,cAAc,EAAG;CAC5C,QAAQ;EACN,OAAO;CACT;CACA,MAAM,SAAS,MAAM,aAAa,QAAQ;CAC1C,MAAM,aAAa,UAAU,KAAK;CAClC,aAAa;EAEX,IAAI,MAAM,aAAa,QAAQ,MAAM,OAAO;EAC5C,IAAI,WAAW,MAAM,MAAM,gBAAgB,QAAQ;OAC9C,MAAM,aAAa,UAAU,MAAM;CAC1C;AACF;;;;;;AAOA,SAAgB,YAAY,OAAyB,IAAmB,SAA2B;CACjG,MAAM,SAAS,CAAC,WAAW,OAAO,OAAO,eAAe,QAAQ;CAChE,MAAM,aAAmB;EACvB,KAAK,MAAM,QAAQ,QAAQ,MAAM,oBAAoB,MAAM,IAAI;EAC/D,QAAQ;CACV;CACA,KAAK,MAAM,QAAQ,QAAQ,MAAM,iBAAiB,MAAM,IAAI;AAC9D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mattebox/player",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "A <mattebox-player> custom element over @mattebox/player-core.",
5
5
  "author": "Josep Boix Requesens",
6
6
  "repository": {
@@ -69,9 +69,9 @@
69
69
  "release:ci": "semantic-release"
70
70
  },
71
71
  "dependencies": {
72
- "@mattebox/player-core": "^0.6.1"
72
+ "@mattebox/player-core": "^0.7.0"
73
73
  },
74
74
  "peerDependencies": {
75
- "mattebox": "^0.15.0"
75
+ "mattebox": "^0.16.0"
76
76
  }
77
77
  }