@mattebox/player 0.5.0 → 0.7.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 (264) hide show
  1. package/README.md +9 -6
  2. package/dist/cdn/mattebox-player.min.js +3 -444
  3. package/dist/controls/airplay.js +28 -44
  4. package/dist/controls/airplay.js.map +1 -1
  5. package/dist/controls/chapters.d.ts +22 -11
  6. package/dist/controls/chapters.d.ts.map +1 -1
  7. package/dist/controls/chapters.js +87 -73
  8. package/dist/controls/chapters.js.map +1 -1
  9. package/dist/controls/cues.d.ts +0 -22
  10. package/dist/controls/cues.d.ts.map +1 -1
  11. package/dist/controls/cues.js +161 -191
  12. package/dist/controls/cues.js.map +1 -1
  13. package/dist/controls/fullscreen.js +52 -70
  14. package/dist/controls/fullscreen.js.map +1 -1
  15. package/dist/controls/icons.d.ts +1 -1
  16. package/dist/controls/icons.d.ts.map +1 -1
  17. package/dist/controls/icons.js +46 -70
  18. package/dist/controls/icons.js.map +1 -1
  19. package/dist/controls/menu.d.ts +7 -4
  20. package/dist/controls/menu.d.ts.map +1 -1
  21. package/dist/controls/menu.js +241 -223
  22. package/dist/controls/menu.js.map +1 -1
  23. package/dist/controls/pip.js +35 -49
  24. package/dist/controls/pip.js.map +1 -1
  25. package/dist/controls/ranges.js +42 -37
  26. package/dist/controls/ranges.js.map +1 -1
  27. package/dist/controls/session.d.ts +6 -1
  28. package/dist/controls/session.d.ts.map +1 -1
  29. package/dist/controls/session.js +41 -26
  30. package/dist/controls/session.js.map +1 -1
  31. package/dist/controls/slider.d.ts +2 -2
  32. package/dist/controls/slider.d.ts.map +1 -1
  33. package/dist/controls/slider.js +151 -159
  34. package/dist/controls/slider.js.map +1 -1
  35. package/dist/controls/time.js +17 -17
  36. package/dist/controls/time.js.map +1 -1
  37. package/dist/dom.d.ts +6 -0
  38. package/dist/dom.d.ts.map +1 -1
  39. package/dist/dom.js +28 -19
  40. package/dist/dom.js.map +1 -1
  41. package/dist/element-entry.js +9 -6
  42. package/dist/element-entry.js.map +1 -1
  43. package/dist/element.d.ts +15 -24
  44. package/dist/element.d.ts.map +1 -1
  45. package/dist/element.js +385 -454
  46. package/dist/element.js.map +1 -1
  47. package/dist/elements/airplay-button.js +51 -53
  48. package/dist/elements/airplay-button.js.map +1 -1
  49. package/dist/elements/audio-menu.js +62 -63
  50. package/dist/elements/audio-menu.js.map +1 -1
  51. package/dist/elements/chapters-menu.d.ts.map +1 -1
  52. package/dist/elements/chapters-menu.js +75 -65
  53. package/dist/elements/chapters-menu.js.map +1 -1
  54. package/dist/elements/component.d.ts +1 -1
  55. package/dist/elements/component.d.ts.map +1 -1
  56. package/dist/elements/component.js +86 -89
  57. package/dist/elements/component.js.map +1 -1
  58. package/dist/elements/control-bar.d.ts +18 -5
  59. package/dist/elements/control-bar.d.ts.map +1 -1
  60. package/dist/elements/control-bar.js +282 -319
  61. package/dist/elements/control-bar.js.map +1 -1
  62. package/dist/elements/current-time.js +26 -25
  63. package/dist/elements/current-time.js.map +1 -1
  64. package/dist/elements/drm-badge.d.ts.map +1 -1
  65. package/dist/elements/drm-badge.js +107 -141
  66. package/dist/elements/drm-badge.js.map +1 -1
  67. package/dist/elements/duration.d.ts.map +1 -1
  68. package/dist/elements/duration.js +24 -21
  69. package/dist/elements/duration.js.map +1 -1
  70. package/dist/elements/error-screen.d.ts.map +1 -1
  71. package/dist/elements/error-screen.js +68 -102
  72. package/dist/elements/error-screen.js.map +1 -1
  73. package/dist/elements/fullscreen-button.js +48 -54
  74. package/dist/elements/fullscreen-button.js.map +1 -1
  75. package/dist/elements/live-button.d.ts.map +1 -1
  76. package/dist/elements/live-button.js +67 -94
  77. package/dist/elements/live-button.js.map +1 -1
  78. package/dist/elements/menu-element.js +31 -28
  79. package/dist/elements/menu-element.js.map +1 -1
  80. package/dist/elements/mute-button.js +58 -59
  81. package/dist/elements/mute-button.js.map +1 -1
  82. package/dist/elements/pip-button.js +54 -54
  83. package/dist/elements/pip-button.js.map +1 -1
  84. package/dist/elements/play-button.d.ts.map +1 -1
  85. package/dist/elements/play-button.js +73 -58
  86. package/dist/elements/play-button.js.map +1 -1
  87. package/dist/elements/quality-menu.js +66 -69
  88. package/dist/elements/quality-menu.js.map +1 -1
  89. package/dist/elements/remaining-time.d.ts.map +1 -1
  90. package/dist/elements/remaining-time.js +27 -24
  91. package/dist/elements/remaining-time.js.map +1 -1
  92. package/dist/elements/scan-button.d.ts +17 -0
  93. package/dist/elements/scan-button.d.ts.map +1 -0
  94. package/dist/elements/scan-button.js +117 -0
  95. package/dist/elements/scan-button.js.map +1 -0
  96. package/dist/elements/seek-bar.d.ts +93 -14
  97. package/dist/elements/seek-bar.d.ts.map +1 -1
  98. package/dist/elements/seek-bar.js +475 -335
  99. package/dist/elements/seek-bar.js.map +1 -1
  100. package/dist/elements/shared.d.ts +3 -11
  101. package/dist/elements/shared.d.ts.map +1 -1
  102. package/dist/elements/shared.js +44 -144
  103. package/dist/elements/shared.js.map +1 -1
  104. package/dist/elements/skip-button.d.ts.map +1 -1
  105. package/dist/elements/skip-button.js +54 -55
  106. package/dist/elements/skip-button.js.map +1 -1
  107. package/dist/elements/spacer.d.ts.map +1 -1
  108. package/dist/elements/spacer.js +12 -7
  109. package/dist/elements/spacer.js.map +1 -1
  110. package/dist/elements/speed-menu.js +60 -55
  111. package/dist/elements/speed-menu.js.map +1 -1
  112. package/dist/elements/spinner.d.ts.map +1 -1
  113. package/dist/elements/spinner.js +52 -78
  114. package/dist/elements/spinner.js.map +1 -1
  115. package/dist/elements/start-button.d.ts.map +1 -1
  116. package/dist/elements/start-button.js +107 -120
  117. package/dist/elements/start-button.js.map +1 -1
  118. package/dist/elements/subtitles-menu.js +95 -103
  119. package/dist/elements/subtitles-menu.js.map +1 -1
  120. package/dist/elements/time-element.d.ts.map +1 -1
  121. package/dist/elements/time-element.js +36 -28
  122. package/dist/elements/time-element.js.map +1 -1
  123. package/dist/elements/title.d.ts.map +1 -1
  124. package/dist/elements/title.js +105 -137
  125. package/dist/elements/title.js.map +1 -1
  126. package/dist/elements/volume-slider.d.ts.map +1 -1
  127. package/dist/elements/volume-slider.js +47 -45
  128. package/dist/elements/volume-slider.js.map +1 -1
  129. package/dist/elements/volume.d.ts.map +1 -1
  130. package/dist/elements/volume.js +42 -50
  131. package/dist/elements/volume.js.map +1 -1
  132. package/dist/entries/airplay-button.js +7 -7
  133. package/dist/entries/airplay-button.js.map +1 -1
  134. package/dist/entries/audio-menu.js +7 -6
  135. package/dist/entries/audio-menu.js.map +1 -1
  136. package/dist/entries/chapters-menu.js +7 -7
  137. package/dist/entries/chapters-menu.js.map +1 -1
  138. package/dist/entries/control-bar.js +7 -6
  139. package/dist/entries/control-bar.js.map +1 -1
  140. package/dist/entries/current-time.js +7 -6
  141. package/dist/entries/current-time.js.map +1 -1
  142. package/dist/entries/drm-badge.js +7 -6
  143. package/dist/entries/drm-badge.js.map +1 -1
  144. package/dist/entries/duration.js +7 -6
  145. package/dist/entries/duration.js.map +1 -1
  146. package/dist/entries/error-screen.js +7 -6
  147. package/dist/entries/error-screen.js.map +1 -1
  148. package/dist/entries/fullscreen-button.js +7 -6
  149. package/dist/entries/fullscreen-button.js.map +1 -1
  150. package/dist/entries/live-button.js +7 -6
  151. package/dist/entries/live-button.js.map +1 -1
  152. package/dist/entries/mute-button.js +7 -6
  153. package/dist/entries/mute-button.js.map +1 -1
  154. package/dist/entries/pip-button.js +7 -6
  155. package/dist/entries/pip-button.js.map +1 -1
  156. package/dist/entries/play-button.js +7 -6
  157. package/dist/entries/play-button.js.map +1 -1
  158. package/dist/entries/quality-menu.js +7 -6
  159. package/dist/entries/quality-menu.js.map +1 -1
  160. package/dist/entries/remaining-time.js +7 -7
  161. package/dist/entries/remaining-time.js.map +1 -1
  162. package/dist/entries/scan-button.d.ts +5 -0
  163. package/dist/entries/scan-button.d.ts.map +1 -0
  164. package/dist/entries/scan-button.js +9 -0
  165. package/dist/entries/scan-button.js.map +1 -0
  166. package/dist/entries/seek-bar.js +7 -6
  167. package/dist/entries/seek-bar.js.map +1 -1
  168. package/dist/entries/skip-button.js +7 -6
  169. package/dist/entries/skip-button.js.map +1 -1
  170. package/dist/entries/spacer.js +7 -6
  171. package/dist/entries/spacer.js.map +1 -1
  172. package/dist/entries/speed-menu.js +7 -6
  173. package/dist/entries/speed-menu.js.map +1 -1
  174. package/dist/entries/spinner.js +7 -7
  175. package/dist/entries/spinner.js.map +1 -1
  176. package/dist/entries/start-button.js +7 -6
  177. package/dist/entries/start-button.js.map +1 -1
  178. package/dist/entries/subtitles-menu.js +7 -6
  179. package/dist/entries/subtitles-menu.js.map +1 -1
  180. package/dist/entries/title.js +7 -7
  181. package/dist/entries/title.js.map +1 -1
  182. package/dist/entries/volume-slider.js +7 -6
  183. package/dist/entries/volume-slider.js.map +1 -1
  184. package/dist/entries/volume.js +9 -8
  185. package/dist/entries/volume.js.map +1 -1
  186. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/asyncToGenerator.js +1 -1
  187. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/defineProperty.js +1 -1
  188. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/objectSpread2.js +1 -1
  189. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPrimitive.js +1 -1
  190. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/toPropertyKey.js +1 -1
  191. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.149.0 → _@oxc-project_runtime@0.150.0}/helpers/esm/typeof.js +1 -1
  192. package/dist/es2015/controls/chapters.js +40 -7
  193. package/dist/es2015/controls/cues.js +1 -8
  194. package/dist/es2015/controls/icons.js +3 -1
  195. package/dist/es2015/controls/menu.js +28 -9
  196. package/dist/es2015/controls/session.js +16 -4
  197. package/dist/es2015/controls/slider.js +5 -4
  198. package/dist/es2015/dom.js +10 -1
  199. package/dist/es2015/element.js +49 -40
  200. package/dist/es2015/elements/chapters-menu.js +18 -10
  201. package/dist/es2015/elements/control-bar.js +41 -35
  202. package/dist/es2015/elements/drm-badge.js +1 -25
  203. package/dist/es2015/elements/duration.js +2 -1
  204. package/dist/es2015/elements/error-screen.js +1 -30
  205. package/dist/es2015/elements/live-button.js +1 -29
  206. package/dist/es2015/elements/menu-element.js +2 -2
  207. package/dist/es2015/elements/play-button.js +10 -3
  208. package/dist/es2015/elements/remaining-time.js +2 -1
  209. package/dist/es2015/elements/scan-button.js +118 -0
  210. package/dist/es2015/elements/seek-bar.js +264 -71
  211. package/dist/es2015/elements/shared.js +5 -106
  212. package/dist/es2015/elements/skip-button.js +2 -1
  213. package/dist/es2015/elements/spacer.js +2 -1
  214. package/dist/es2015/elements/spinner.js +1 -32
  215. package/dist/es2015/elements/start-button.js +8 -26
  216. package/dist/es2015/elements/time-element.js +1 -4
  217. package/dist/es2015/elements/title.js +1 -45
  218. package/dist/es2015/elements/volume-slider.js +2 -1
  219. package/dist/es2015/elements/volume.js +1 -11
  220. package/dist/es2015/entries/scan-button.js +7 -0
  221. package/dist/es2015/index.js +3 -3
  222. package/dist/es2015/presets.js +1 -1
  223. package/dist/es2015/style.js +1 -98
  224. package/dist/es2015/tags.js +2 -2
  225. package/dist/host.js +19 -17
  226. package/dist/host.js.map +1 -1
  227. package/dist/index.d.ts +3 -3
  228. package/dist/index.d.ts.map +1 -1
  229. package/dist/index.js +55 -28
  230. package/dist/labels.js +13 -9
  231. package/dist/labels.js.map +1 -1
  232. package/dist/namespaces.d.ts +9 -26
  233. package/dist/namespaces.d.ts.map +1 -1
  234. package/dist/namespaces.js +6 -2
  235. package/dist/namespaces.js.map +1 -1
  236. package/dist/presets.js +33 -28
  237. package/dist/presets.js.map +1 -1
  238. package/dist/style.d.ts +1 -20
  239. package/dist/style.d.ts.map +1 -1
  240. package/dist/style.js +4 -97
  241. package/dist/style.js.map +1 -1
  242. package/dist/surface.js +25 -21
  243. package/dist/surface.js.map +1 -1
  244. package/dist/tags.d.ts +1 -1
  245. package/dist/tags.d.ts.map +1 -1
  246. package/dist/tags.js +31 -27
  247. package/dist/tags.js.map +1 -1
  248. package/package.json +4 -4
  249. package/dist/compose.d.ts +0 -5
  250. package/dist/compose.d.ts.map +0 -1
  251. package/dist/compose.js +0 -31
  252. package/dist/compose.js.map +0 -1
  253. package/dist/elements/panels.d.ts +0 -15
  254. package/dist/elements/panels.d.ts.map +0 -1
  255. package/dist/elements/panels.js +0 -55
  256. package/dist/elements/panels.js.map +0 -1
  257. package/dist/entries/panels.d.ts +0 -5
  258. package/dist/entries/panels.d.ts.map +0 -1
  259. package/dist/entries/panels.js +0 -8
  260. package/dist/entries/panels.js.map +0 -1
  261. package/dist/es2015/compose.js +0 -33
  262. package/dist/es2015/elements/panels.js +0 -52
  263. package/dist/es2015/entries/panels.js +0 -7
  264. package/dist/index.js.map +0 -1
@@ -1,340 +1,303 @@
1
- /**
2
- * <mbx-control-bar>: an overlay over the bottom of the video that lays its
3
- * children out in two rows, the seek row over the buttons row. A child
4
- * with `slot="seek"` sits in the seek row; everything else in the buttons
5
- * row, in its order, and an <mbx-spacer> pushes what follows to the right.
6
- *
7
- * The bar owns what no one control can: the idle fade, the shortcuts, the
8
- * click on the video, and the subtitles lifted above it. It sets `idle` on
9
- * itself and on the player while it hides.
10
- *
11
- * The fade is one timer. Any activity, a pointer moving or pressing, a
12
- * key, playback starting, re-arms it for `idle-ms`, and when it fires the
13
- * bar hides unless something it can know for certain holds it: the video
14
- * is paused, a descendant carries `open`, or keyboard focus is inside it,
15
- * where keyboard means the last input was a key and not a pointer.
16
- * Whether the pointer is over the player is never tracked: that goes
17
- * stale when the pointer leaves without a move the player sees.
18
- *
19
- * The shortcuts listen on the player, so they hear every key pressed
20
- * inside it, and only there: Space and `k` toggle play, `m` mutes, `f`
21
- * toggles fullscreen, the arrows seek by `seek-step`. Space is left to a
22
- * focused button, which is its own. A click on the video toggles play.
23
- * Fullscreen goes on the player itself, so the bar comes along.
24
- *
25
- * A narrow bar collapses the buttons row by `priority`: each child carries
26
- * a number, its own attribute or the default for its tag, and the bar
27
- * marks the highest numbers `collapsed` one at a time until the row fits
28
- * with a little slack, from the right among equals. Zero, the default for
29
- * anything unlisted, never collapses: play and fullscreen stay whatever
30
- * the width. The mark is an attribute and the hiding is one `::slotted`
31
- * rule here, so a page styles or overrides it by the tag. The volume's
32
- * slider is a candidate of its own, and counts at its unfolded width, so
33
- * the row is sized for what the pointer will make of it.
34
- */
35
- import { cueLift, cueStyle } from '../controls/cues.js';
36
- import { fullscreen } from '../controls/fullscreen.js';
37
- import { AIRPLAY_BUTTON, AUDIO_MENU, CHAPTERS_MENU, DRM_BADGE, MUTE_BUTTON, PIP_BUTTON, QUALITY_MENU, SKIP_BUTTON, SPACER, SPEED_MENU, SUBTITLES_MENU, VOLUME, VOLUME_SLIDER, } from '../tags.js';
38
- import { Component } from './component.js';
39
- import { number, style } from './shared.js';
40
- const IDLE_MS = 3000;
1
+ import { AIRPLAY_BUTTON, AUDIO_MENU, CHAPTERS_MENU, DRM_BADGE, MUTE_BUTTON, PIP_BUTTON, QUALITY_MENU, SCAN_BUTTON, SKIP_BUTTON, SPEED_MENU, SUBTITLES_MENU, VOLUME, VOLUME_SLIDER } from "../tags.js";
2
+ import { Component } from "./component.js";
3
+ import { number, style } from "./shared.js";
4
+ import { cueLift, cueStyle } from "../controls/cues.js";
5
+ import { fullscreen } from "../controls/fullscreen.js";
6
+ //#region src/elements/control-bar.ts
7
+ const STYLE = ":host{box-sizing:border-box;color:var(--mbx-text);font:500 16px / 1.2 var(--mbx-font);background:linear-gradient(#0000,#0009);flex-direction:column;padding:40px 16px 12px;transition:opacity .2s;display:flex;position:absolute;bottom:0;left:0;right:0}:host([idle]){opacity:0;pointer-events:none}[part~=row]{align-items:center;margin:0 -4px;display:flex}[part~=buttons-row]{margin-top:4px}[part~=seek-row]{margin:0 -8px}slot:not([name])::slotted(*){margin:0 4px}slot[name=seek]::slotted(*){margin:0 8px}::slotted([collapsed]){display:none}@media (prefers-reduced-motion:reduce){:host{transition:none}}";
8
+ const IDLE_MS = 3e3;
41
9
  const SEEK_STEP = 5;
42
10
  /**
43
- * What goes first when the row is too narrow, by tag: the slider, which
44
- * takes the most room for the least; then the diagnostics, the lock and
45
- * the menus a viewer rarely opens; then the menus for the picture and the
46
- * sound; then the skips; then the mute and the subtitles. The subtitles
47
- * menu goes last of the menus because it is the one a viewer may need.
48
- * The diagnostics is another package's, named here as a string. A
49
- * `priority` attribute on the control replaces its default.
50
- */
11
+ * What goes first when the row is too narrow, by tag: the scans, which
12
+ * suit a TV remote more than a small screen; then the slider, which takes
13
+ * the most room for the least; then the diagnostics, the lock and the
14
+ * menus a viewer rarely opens; then the menus for the picture and the
15
+ * sound; then the skips; then the mute and the subtitles. The subtitles
16
+ * menu goes last of the menus because it is the one a viewer may need.
17
+ * The diagnostics is another package's, named here as a string. A
18
+ * `priority` attribute on the control replaces its default.
19
+ */
51
20
  const PRIORITY = {
52
- [VOLUME_SLIDER]: 5,
53
- 'mbx-diagnostics': 4,
54
- [DRM_BADGE]: 4,
55
- [SPEED_MENU]: 4,
56
- [CHAPTERS_MENU]: 4,
57
- [AUDIO_MENU]: 3,
58
- [QUALITY_MENU]: 3,
59
- [PIP_BUTTON]: 3,
60
- [AIRPLAY_BUTTON]: 2,
61
- [SKIP_BUTTON]: 2,
62
- [SUBTITLES_MENU]: 1,
63
- [VOLUME]: 1,
64
- [MUTE_BUTTON]: 1,
21
+ [SCAN_BUTTON]: 6,
22
+ [VOLUME_SLIDER]: 5,
23
+ "mbx-diagnostics": 4,
24
+ [DRM_BADGE]: 4,
25
+ [SPEED_MENU]: 4,
26
+ [CHAPTERS_MENU]: 4,
27
+ [AUDIO_MENU]: 3,
28
+ [QUALITY_MENU]: 3,
29
+ [PIP_BUTTON]: 3,
30
+ [AIRPLAY_BUTTON]: 2,
31
+ [SKIP_BUTTON]: 2,
32
+ [SUBTITLES_MENU]: 1,
33
+ [VOLUME]: 1,
34
+ [MUTE_BUTTON]: 1
65
35
  };
66
36
  /** The width the volume group unfolds its slider to, from volume.ts: what a folded slider is counted at. */
67
37
  const SLIDER_WIDTH = 80;
68
38
  /** Room kept between the last button and the edge, so nothing sits flush against it. */
69
39
  const SLACK = 8;
70
40
  function shown(node) {
71
- return node.getClientRects().length > 0;
41
+ return node.getClientRects().length > 0;
72
42
  }
73
43
  /** The slider inside a volume group child, when it has one. */
74
44
  function slider(child) {
75
- return child.localName === VOLUME ? child.querySelector(VOLUME_SLIDER) : null;
45
+ return child.localName === "mbx-volume" ? child.querySelector(VOLUME_SLIDER) : null;
76
46
  }
77
47
  /** A child's priority: its attribute, else its tag's default, else zero. */
78
48
  function priority(child) {
79
- const own = child.getAttribute('priority');
80
- if (own !== null) {
81
- const value = Number(own);
82
- return Number.isFinite(value) && value > 0 ? value : 0;
83
- }
84
- return PRIORITY[child.localName] ?? 0;
85
- }
86
- const STYLE = `
87
- :host {
88
- position: absolute;
89
- inset: auto 0 0 0;
90
- box-sizing: border-box;
91
- display: flex;
92
- flex-direction: column;
93
- gap: 4px;
94
- padding: 40px 16px 12px;
95
- color: var(--mbx-text);
96
- background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
97
- font: 500 16px/1.2 var(--mbx-font);
98
- transition: opacity 0.2s;
99
- }
100
- :host([idle]) { opacity: 0; pointer-events: none; }
101
- [part~="row"] { display: flex; align-items: center; gap: 8px; }
102
- [part~="seek-row"] { gap: 16px; }
103
- ::slotted([collapsed]) { display: none; }
104
- @media (prefers-reduced-motion: reduce) {
105
- :host { transition: none; }
49
+ const own = child.getAttribute("priority");
50
+ if (own !== null) {
51
+ const value = Number(own);
52
+ return Number.isFinite(value) && value > 0 ? value : 0;
53
+ }
54
+ return PRIORITY[child.localName] ?? 0;
106
55
  }
107
- `;
108
56
  function end(video) {
109
- if (Number.isFinite(video.duration))
110
- return video.duration;
111
- const ranges = video.seekable;
112
- return ranges.length > 0 ? ranges.end(ranges.length - 1) : video.currentTime;
57
+ if (Number.isFinite(video.duration)) return video.duration;
58
+ const ranges = video.seekable;
59
+ return ranges.length > 0 ? ranges.end(ranges.length - 1) : video.currentTime;
113
60
  }
114
61
  function toggle(video) {
115
- if (video.paused)
116
- video.play().catch(() => undefined);
117
- else
118
- video.pause();
119
- }
120
- export class MbxControlBar extends Component {
121
- static get observedAttributes() {
122
- return ['idle-ms', 'seek-step'];
123
- }
124
- constructor() {
125
- super();
126
- this.timer = undefined;
127
- this.keyboard = false;
128
- this.cues = null;
129
- this.screen = null;
130
- this.resizer = null;
131
- const root = this.attachShadow({ mode: 'open' });
132
- this.seekRow = document.createElement('div');
133
- this.seekRow.setAttribute('part', 'row seek-row');
134
- const seek = document.createElement('slot');
135
- seek.name = 'seek';
136
- this.seekRow.append(seek);
137
- this.buttonsRow = document.createElement('div');
138
- this.buttonsRow.setAttribute('part', 'row buttons-row');
139
- this.buttons = document.createElement('slot');
140
- this.buttonsRow.append(this.buttons);
141
- root.append(style(STYLE), this.seekRow, this.buttonsRow);
142
- }
143
- /**
144
- * What the buttons need: their widths and the gaps between them, the
145
- * spacer aside since it takes what is left, and a folded slider at the
146
- * width it unfolds to. The row's own width says nothing, because the
147
- * spacer fills it whatever the buttons take.
148
- */
149
- needed(children) {
150
- const gap = Number.parseFloat(getComputedStyle(this.buttonsRow).columnGap) || 0;
151
- let sum = 0;
152
- let count = 0;
153
- for (const child of children) {
154
- if (child.localName === SPACER || !shown(child))
155
- continue;
156
- sum += child.getBoundingClientRect().width;
157
- count += 1;
158
- const folded = slider(child);
159
- if (folded !== null && shown(folded)) {
160
- sum += Math.max(0, SLIDER_WIDTH - folded.getBoundingClientRect().width);
161
- }
162
- }
163
- return sum + gap * Math.max(0, count - 1);
164
- }
165
- /**
166
- * Collapses the buttons row to its width. Everything is shown first, so
167
- * a wider bar gets its controls back, then the highest priorities go one
168
- * at a time while the buttons need more than the row has, less the
169
- * slack. Each step lays the row out again; a bar carries a dozen
170
- * controls, so that is cheap.
171
- */
172
- collapse() {
173
- const children = this.buttons.assignedElements();
174
- const candidates = [];
175
- for (const [index, child] of children.entries()) {
176
- child.removeAttribute('collapsed');
177
- const inner = slider(child);
178
- inner?.removeAttribute('collapsed');
179
- // A nested slider goes before its group, so it sorts as if it sat
180
- // after it. What is not shown, by its own `hidden` or a page's rule,
181
- // takes no room, so marking it would hide nothing and say something
182
- // false.
183
- if (inner !== null && shown(inner)) {
184
- candidates.push({ node: inner, index: index + 0.5, priority: priority(inner) });
185
- }
186
- if (shown(child))
187
- candidates.push({ node: child, index, priority: priority(child) });
188
- }
189
- candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);
190
- const room = this.buttonsRow.clientWidth - SLACK;
191
- for (const { node, priority: level } of candidates) {
192
- if (level === 0)
193
- return;
194
- if (this.needed(children) <= room)
195
- return;
196
- node.setAttribute('collapsed', '');
197
- }
198
- }
199
- /** From the first row's top to the bar's bottom: what the bar covers of the picture. */
200
- covered() {
201
- return {
202
- top: this.seekRow.getBoundingClientRect().top,
203
- bottom: this.getBoundingClientRect().bottom,
204
- };
205
- }
206
- held(player) {
207
- if (player.video.paused)
208
- return true;
209
- if (this.querySelector('[open]') !== null)
210
- return true;
211
- if (!this.keyboard)
212
- return false;
213
- const active = this.getRootNode().activeElement;
214
- return active !== null && this.contains(active);
215
- }
216
- idle(player, on) {
217
- if (this.hasAttribute('idle') === on)
218
- return;
219
- this.toggleAttribute('idle', on);
220
- player.toggleAttribute('idle', on);
221
- this.cues?.lifted(!on);
222
- }
223
- sleep(player) {
224
- this.timer = undefined;
225
- // A hold is checked again later: a menu closes and a pause ends without
226
- // an event the bar hears.
227
- if (this.held(player)) {
228
- this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));
229
- return;
230
- }
231
- this.idle(player, true);
232
- }
233
- wake(player) {
234
- clearTimeout(this.timer);
235
- this.idle(player, false);
236
- this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));
237
- }
238
- key(player, event) {
239
- this.keyboard = true;
240
- this.wake(player);
241
- if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey)
242
- return;
243
- const video = player.video;
244
- const onButton = event.composedPath()[0] instanceof HTMLButtonElement;
245
- switch (event.key) {
246
- case ' ':
247
- if (onButton)
248
- return;
249
- toggle(video);
250
- break;
251
- case 'k':
252
- case 'K':
253
- toggle(video);
254
- break;
255
- case 'm':
256
- case 'M':
257
- video.muted = !video.muted;
258
- break;
259
- case 'f':
260
- case 'F':
261
- this.screen?.toggle();
262
- break;
263
- case 'ArrowLeft':
264
- video.currentTime = Math.max(0, video.currentTime - number(this, 'seek-step', SEEK_STEP));
265
- break;
266
- case 'ArrowRight':
267
- video.currentTime = Math.min(end(video), video.currentTime + number(this, 'seek-step', SEEK_STEP));
268
- break;
269
- default:
270
- return;
271
- }
272
- event.preventDefault();
273
- }
274
- attach(player) {
275
- const video = player.video;
276
- cueStyle();
277
- this.cues = cueLift(video, player, () => this.covered());
278
- const screen = fullscreen(player, video);
279
- this.screen = screen;
280
- const reflect = () => {
281
- player.toggleAttribute('fullscreen', screen.active());
282
- };
283
- this.keep(screen.watch(reflect));
284
- reflect();
285
- const pointer = () => {
286
- this.keyboard = false;
287
- this.wake(player);
288
- };
289
- const key = (event) => {
290
- this.key(player, event);
291
- };
292
- const click = (event) => {
293
- // The video and nothing else: a control handles its own click.
294
- if (event.composedPath()[0] === video)
295
- toggle(video);
296
- };
297
- this.listen(player, ['pointermove', 'pointerdown'], pointer);
298
- player.addEventListener('keydown', key);
299
- player.addEventListener('click', click);
300
- this.keep(() => {
301
- player.removeEventListener('keydown', key);
302
- player.removeEventListener('click', click);
303
- });
304
- this.listen(video, ['play', 'pause', 'ended'], () => {
305
- this.wake(player);
306
- });
307
- this.wake(player);
308
- this.cues.lifted(true);
309
- // The row's width, its children, and what they hide or reprioritise on
310
- // their own: each can change what fits. `collapsed` is left out of the
311
- // filter, since the bar writes it.
312
- const collapse = () => {
313
- this.collapse();
314
- };
315
- this.listen(this.buttons, ['slotchange'], collapse);
316
- this.observe(this, ['hidden', 'priority', 'slot'], collapse, true);
317
- if (typeof ResizeObserver !== 'undefined') {
318
- this.resizer = new ResizeObserver(collapse);
319
- this.resizer.observe(this.buttonsRow);
320
- }
321
- collapse();
322
- }
323
- detach(player) {
324
- clearTimeout(this.timer);
325
- this.timer = undefined;
326
- this.resizer?.disconnect();
327
- this.resizer = null;
328
- for (const child of this.buttons.assignedElements()) {
329
- child.removeAttribute('collapsed');
330
- slider(child)?.removeAttribute('collapsed');
331
- }
332
- this.cues?.dispose();
333
- this.cues = null;
334
- this.screen = null;
335
- this.removeAttribute('idle');
336
- player.removeAttribute('idle');
337
- player.removeAttribute('fullscreen');
338
- }
62
+ if (video.paused) video.play().catch(() => void 0);
63
+ else video.pause();
339
64
  }
65
+ var MbxControlBar = class extends Component {
66
+ static get observedAttributes() {
67
+ return ["idle-ms", "seek-step"];
68
+ }
69
+ constructor() {
70
+ super();
71
+ this.timer = void 0;
72
+ this.keyboard = false;
73
+ this.cues = null;
74
+ this.screen = null;
75
+ this.resizer = null;
76
+ const root = this.attachShadow({ mode: "open" });
77
+ this.seekRow = document.createElement("div");
78
+ this.seekRow.setAttribute("part", "row seek-row");
79
+ const seek = document.createElement("slot");
80
+ seek.name = "seek";
81
+ this.seekRow.append(seek);
82
+ this.buttonsRow = document.createElement("div");
83
+ this.buttonsRow.setAttribute("part", "row buttons-row");
84
+ this.buttons = document.createElement("slot");
85
+ this.buttonsRow.append(this.buttons);
86
+ root.append(style(STYLE), this.seekRow, this.buttonsRow);
87
+ }
88
+ /**
89
+ * What the buttons need: their widths and their margins, which are the
90
+ * gaps between them, the spacer aside since it takes what is left, and a
91
+ * folded slider at the width it unfolds to. The row's own width says nothing, because the
92
+ * spacer fills it whatever the buttons take.
93
+ */
94
+ needed(children) {
95
+ let sum = 0;
96
+ for (const child of children) {
97
+ if (child.localName === "mbx-spacer" || !shown(child)) continue;
98
+ const margins = getComputedStyle(child);
99
+ sum += child.getBoundingClientRect().width;
100
+ sum += Number.parseFloat(margins.marginLeft) + Number.parseFloat(margins.marginRight);
101
+ const folded = slider(child);
102
+ if (folded !== null && shown(folded)) sum += Math.max(0, SLIDER_WIDTH - folded.getBoundingClientRect().width);
103
+ }
104
+ return sum;
105
+ }
106
+ /**
107
+ * Collapses the buttons row to its width. Everything is shown first, so
108
+ * a wider bar gets its controls back, then the highest priorities go one
109
+ * at a time while the buttons need more than the row has, less the
110
+ * slack. Each step lays the row out again; a bar carries a dozen
111
+ * controls, so that is cheap.
112
+ */
113
+ collapse() {
114
+ const children = this.buttons.assignedElements();
115
+ const candidates = [];
116
+ for (const [index, child] of children.entries()) {
117
+ child.removeAttribute("collapsed");
118
+ const inner = slider(child);
119
+ inner?.removeAttribute("collapsed");
120
+ if (inner !== null && shown(inner)) candidates.push({
121
+ node: inner,
122
+ index: index + .5,
123
+ priority: priority(inner)
124
+ });
125
+ if (shown(child)) candidates.push({
126
+ node: child,
127
+ index,
128
+ priority: priority(child)
129
+ });
130
+ }
131
+ candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);
132
+ const room = this.buttonsRow.clientWidth - SLACK;
133
+ for (const { node, priority: level } of candidates) {
134
+ if (level === 0) return;
135
+ if (this.needed(children) <= room) return;
136
+ node.setAttribute("collapsed", "");
137
+ }
138
+ }
139
+ /** From the first row's top to the bar's bottom: what the bar covers of the picture. */
140
+ covered() {
141
+ return {
142
+ top: this.seekRow.getBoundingClientRect().top,
143
+ bottom: this.getBoundingClientRect().bottom
144
+ };
145
+ }
146
+ held(player) {
147
+ if (player.video.paused) return true;
148
+ if (this.querySelector("[open]") !== null) return true;
149
+ if (!this.keyboard) return false;
150
+ const active = this.getRootNode().activeElement;
151
+ return active !== null && this.contains(active);
152
+ }
153
+ idle(player, on) {
154
+ if (this.hasAttribute("idle") === on) return;
155
+ this.toggleAttribute("idle", on);
156
+ player.toggleAttribute("idle", on);
157
+ this.cues?.lifted(!on);
158
+ }
159
+ sleep(player) {
160
+ this.timer = void 0;
161
+ if (this.held(player)) {
162
+ this.timer = setTimeout(() => this.sleep(player), number(this, "idle-ms", IDLE_MS));
163
+ return;
164
+ }
165
+ this.idle(player, true);
166
+ }
167
+ wake(player) {
168
+ clearTimeout(this.timer);
169
+ this.idle(player, false);
170
+ this.timer = setTimeout(() => this.sleep(player), number(this, "idle-ms", IDLE_MS));
171
+ }
172
+ /**
173
+ * A seeking key: `seekkey` on the player first, cancellable, with the
174
+ * seconds in `detail.by`. A seek bar under `key-mode="preview"` takes it
175
+ * to aim instead. Nobody took it: the playhead moves now.
176
+ */
177
+ seekBy(player, by) {
178
+ const asked = new CustomEvent("seekkey", {
179
+ detail: { by },
180
+ cancelable: true
181
+ });
182
+ if (!player.dispatchEvent(asked)) return;
183
+ const video = player.video;
184
+ video.currentTime = Math.min(end(video), Math.max(0, video.currentTime + by));
185
+ }
186
+ key(player, event) {
187
+ this.keyboard = true;
188
+ this.wake(player);
189
+ if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
190
+ const video = player.video;
191
+ const onButton = event.composedPath()[0] instanceof HTMLButtonElement;
192
+ switch (event.key) {
193
+ case " ":
194
+ if (onButton) return;
195
+ toggle(video);
196
+ break;
197
+ case "k":
198
+ case "K":
199
+ toggle(video);
200
+ break;
201
+ case "m":
202
+ case "M":
203
+ video.muted = !video.muted;
204
+ break;
205
+ case "f":
206
+ case "F":
207
+ this.screen?.toggle();
208
+ break;
209
+ case "MediaPlayPause":
210
+ toggle(video);
211
+ break;
212
+ case "MediaPlay":
213
+ video.play().catch(() => void 0);
214
+ break;
215
+ case "MediaPause":
216
+ case "MediaStop":
217
+ video.pause();
218
+ break;
219
+ case "ArrowLeft":
220
+ case "MediaRewind":
221
+ this.seekBy(player, -number(this, "seek-step", SEEK_STEP));
222
+ break;
223
+ case "ArrowRight":
224
+ case "MediaFastForward":
225
+ this.seekBy(player, number(this, "seek-step", SEEK_STEP));
226
+ break;
227
+ default: return;
228
+ }
229
+ event.preventDefault();
230
+ }
231
+ attach(player) {
232
+ const video = player.video;
233
+ cueStyle();
234
+ this.cues = cueLift(video, player, () => this.covered());
235
+ const screen = fullscreen(player, video);
236
+ this.screen = screen;
237
+ const reflect = () => {
238
+ player.toggleAttribute("fullscreen", screen.active());
239
+ };
240
+ this.keep(screen.watch(reflect));
241
+ reflect();
242
+ const pointer = () => {
243
+ this.keyboard = false;
244
+ this.wake(player);
245
+ };
246
+ const key = (event) => {
247
+ this.key(player, event);
248
+ };
249
+ const click = (event) => {
250
+ if (event.composedPath()[0] === video) toggle(video);
251
+ };
252
+ this.listen(player, ["pointermove", "pointerdown"], pointer);
253
+ player.addEventListener("keydown", key);
254
+ player.addEventListener("click", click);
255
+ this.keep(() => {
256
+ player.removeEventListener("keydown", key);
257
+ player.removeEventListener("click", click);
258
+ });
259
+ this.listen(video, [
260
+ "play",
261
+ "pause",
262
+ "ended"
263
+ ], () => {
264
+ this.wake(player);
265
+ });
266
+ this.wake(player);
267
+ this.cues.lifted(true);
268
+ const collapse = () => {
269
+ this.collapse();
270
+ };
271
+ this.listen(this.buttons, ["slotchange"], collapse);
272
+ this.observe(this, [
273
+ "hidden",
274
+ "priority",
275
+ "slot"
276
+ ], collapse, true);
277
+ if (typeof ResizeObserver !== "undefined") {
278
+ this.resizer = new ResizeObserver(collapse);
279
+ this.resizer.observe(this.buttonsRow);
280
+ }
281
+ collapse();
282
+ }
283
+ detach(player) {
284
+ clearTimeout(this.timer);
285
+ this.timer = void 0;
286
+ this.resizer?.disconnect();
287
+ this.resizer = null;
288
+ for (const child of this.buttons.assignedElements()) {
289
+ child.removeAttribute("collapsed");
290
+ slider(child)?.removeAttribute("collapsed");
291
+ }
292
+ this.cues?.dispose();
293
+ this.cues = null;
294
+ this.screen = null;
295
+ this.removeAttribute("idle");
296
+ player.removeAttribute("idle");
297
+ player.removeAttribute("fullscreen");
298
+ }
299
+ };
300
+ //#endregion
301
+ export { MbxControlBar };
302
+
340
303
  //# sourceMappingURL=control-bar.js.map