@mattebox/player 0.14.0 → 0.15.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 (279) hide show
  1. package/dist/cdn/mattebox-player.min.js +3 -3
  2. package/dist/controls/chapters.js +1 -1
  3. package/dist/controls/chapters.js.map +1 -1
  4. package/dist/controls/cues.js.map +1 -1
  5. package/dist/controls/native-tracks.js +1 -1
  6. package/dist/controls/native-tracks.js.map +1 -1
  7. package/dist/element-entry.d.ts +1 -0
  8. package/dist/element-entry.d.ts.map +1 -1
  9. package/dist/element-entry.js.map +1 -1
  10. package/dist/element.d.ts +49 -3
  11. package/dist/element.d.ts.map +1 -1
  12. package/dist/element.js +196 -36
  13. package/dist/element.js.map +1 -1
  14. package/dist/elements/airplay-button.js +1 -1
  15. package/dist/elements/airplay-button.js.map +1 -1
  16. package/dist/elements/audio-menu.d.ts.map +1 -1
  17. package/dist/elements/audio-menu.js +4 -3
  18. package/dist/elements/audio-menu.js.map +1 -1
  19. package/dist/elements/casting.d.ts +12 -0
  20. package/dist/elements/casting.d.ts.map +1 -0
  21. package/dist/elements/casting.js +58 -0
  22. package/dist/elements/casting.js.map +1 -0
  23. package/dist/elements/chapters-menu.js +5 -5
  24. package/dist/elements/chapters-menu.js.map +1 -1
  25. package/dist/elements/component.d.ts +13 -0
  26. package/dist/elements/component.d.ts.map +1 -1
  27. package/dist/elements/component.js +21 -3
  28. package/dist/elements/component.js.map +1 -1
  29. package/dist/elements/control-bar.d.ts.map +1 -1
  30. package/dist/elements/control-bar.js +7 -6
  31. package/dist/elements/control-bar.js.map +1 -1
  32. package/dist/elements/current-time.js +2 -2
  33. package/dist/elements/current-time.js.map +1 -1
  34. package/dist/elements/drm-badge.js +1 -1
  35. package/dist/elements/drm-badge.js.map +1 -1
  36. package/dist/elements/duration.js +3 -3
  37. package/dist/elements/duration.js.map +1 -1
  38. package/dist/elements/error-screen.js +1 -1
  39. package/dist/elements/error-screen.js.map +1 -1
  40. package/dist/elements/fullscreen-button.d.ts.map +1 -1
  41. package/dist/elements/fullscreen-button.js +3 -2
  42. package/dist/elements/fullscreen-button.js.map +1 -1
  43. package/dist/elements/live-button.js +2 -2
  44. package/dist/elements/live-button.js.map +1 -1
  45. package/dist/elements/marker-button.js +3 -3
  46. package/dist/elements/marker-button.js.map +1 -1
  47. package/dist/elements/menu-element.js +3 -3
  48. package/dist/elements/menu-element.js.map +1 -1
  49. package/dist/elements/mute-button.js +3 -3
  50. package/dist/elements/mute-button.js.map +1 -1
  51. package/dist/elements/pip-button.d.ts.map +1 -1
  52. package/dist/elements/pip-button.js +6 -2
  53. package/dist/elements/pip-button.js.map +1 -1
  54. package/dist/elements/play-button.js +3 -3
  55. package/dist/elements/play-button.js.map +1 -1
  56. package/dist/elements/quality-menu.d.ts.map +1 -1
  57. package/dist/elements/quality-menu.js +5 -4
  58. package/dist/elements/quality-menu.js.map +1 -1
  59. package/dist/elements/remaining-time.js +2 -2
  60. package/dist/elements/remaining-time.js.map +1 -1
  61. package/dist/elements/scan-button.d.ts.map +1 -1
  62. package/dist/elements/scan-button.js +4 -3
  63. package/dist/elements/scan-button.js.map +1 -1
  64. package/dist/elements/seek-bar.d.ts.map +1 -1
  65. package/dist/elements/seek-bar.js +20 -16
  66. package/dist/elements/seek-bar.js.map +1 -1
  67. package/dist/elements/shared.js +3 -3
  68. package/dist/elements/shared.js.map +1 -1
  69. package/dist/elements/skip-button.js +2 -2
  70. package/dist/elements/skip-button.js.map +1 -1
  71. package/dist/elements/spacer.js.map +1 -1
  72. package/dist/elements/speed-menu.d.ts.map +1 -1
  73. package/dist/elements/speed-menu.js +4 -3
  74. package/dist/elements/speed-menu.js.map +1 -1
  75. package/dist/elements/spinner.js +1 -1
  76. package/dist/elements/spinner.js.map +1 -1
  77. package/dist/elements/start-button.js +3 -3
  78. package/dist/elements/start-button.js.map +1 -1
  79. package/dist/elements/subtitles-menu.d.ts.map +1 -1
  80. package/dist/elements/subtitles-menu.js +5 -4
  81. package/dist/elements/subtitles-menu.js.map +1 -1
  82. package/dist/elements/time-element.js +1 -1
  83. package/dist/elements/time-element.js.map +1 -1
  84. package/dist/elements/title.js +1 -1
  85. package/dist/elements/title.js.map +1 -1
  86. package/dist/elements/video-menu.d.ts.map +1 -1
  87. package/dist/elements/video-menu.js +5 -4
  88. package/dist/elements/video-menu.js.map +1 -1
  89. package/dist/elements/volume-slider.js +4 -4
  90. package/dist/elements/volume-slider.js.map +1 -1
  91. package/dist/elements/volume.js.map +1 -1
  92. package/dist/entries/airplay-button.js +1 -1
  93. package/dist/entries/audio-menu.js +1 -1
  94. package/dist/entries/casting.d.ts +5 -0
  95. package/dist/entries/casting.d.ts.map +1 -0
  96. package/dist/entries/casting.js +8 -0
  97. package/dist/entries/casting.js.map +1 -0
  98. package/dist/entries/chapters-menu.js +1 -1
  99. package/dist/entries/control-bar.js +1 -1
  100. package/dist/entries/current-time.js +1 -1
  101. package/dist/entries/drm-badge.js +1 -1
  102. package/dist/entries/duration.js +1 -1
  103. package/dist/entries/error-screen.js +1 -1
  104. package/dist/entries/fullscreen-button.js +1 -1
  105. package/dist/entries/live-button.js +1 -1
  106. package/dist/entries/marker-button.js +1 -1
  107. package/dist/entries/mute-button.js +1 -1
  108. package/dist/entries/pip-button.js +1 -1
  109. package/dist/entries/play-button.js +1 -1
  110. package/dist/entries/quality-menu.js +1 -1
  111. package/dist/entries/remaining-time.js +1 -1
  112. package/dist/entries/scan-button.js +1 -1
  113. package/dist/entries/seek-bar.js +1 -1
  114. package/dist/entries/skip-button.js +1 -1
  115. package/dist/entries/spacer.js +1 -1
  116. package/dist/entries/speed-menu.js +1 -1
  117. package/dist/entries/spinner.js +1 -1
  118. package/dist/entries/start-button.js +1 -1
  119. package/dist/entries/subtitles-menu.js +1 -1
  120. package/dist/entries/title.js +1 -1
  121. package/dist/entries/video-menu.js +1 -1
  122. package/dist/entries/volume-slider.js +1 -1
  123. package/dist/entries/volume.js +1 -1
  124. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/asyncToGenerator.js +1 -1
  125. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/defineProperty.js +1 -1
  126. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/objectSpread2.js +1 -1
  127. package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
  128. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/toPropertyKey.js +1 -1
  129. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/typeof.js +1 -1
  130. package/dist/es2015/controls/chapters.js +2 -2
  131. package/dist/es2015/controls/menu.js +1 -1
  132. package/dist/es2015/controls/native-tracks.js +1 -1
  133. package/dist/es2015/element.js +213 -44
  134. package/dist/es2015/elements/airplay-button.js +1 -1
  135. package/dist/es2015/elements/audio-menu.js +4 -3
  136. package/dist/es2015/elements/casting.js +57 -0
  137. package/dist/es2015/elements/chapters-menu.js +5 -5
  138. package/dist/es2015/elements/component.js +26 -7
  139. package/dist/es2015/elements/control-bar.js +7 -6
  140. package/dist/es2015/elements/current-time.js +2 -2
  141. package/dist/es2015/elements/drm-badge.js +1 -1
  142. package/dist/es2015/elements/duration.js +3 -3
  143. package/dist/es2015/elements/error-screen.js +1 -1
  144. package/dist/es2015/elements/fullscreen-button.js +3 -2
  145. package/dist/es2015/elements/live-button.js +2 -2
  146. package/dist/es2015/elements/marker-button.js +3 -3
  147. package/dist/es2015/elements/menu-element.js +4 -4
  148. package/dist/es2015/elements/mute-button.js +3 -3
  149. package/dist/es2015/elements/pip-button.js +6 -2
  150. package/dist/es2015/elements/play-button.js +3 -3
  151. package/dist/es2015/elements/quality-menu.js +5 -4
  152. package/dist/es2015/elements/remaining-time.js +2 -2
  153. package/dist/es2015/elements/scan-button.js +4 -3
  154. package/dist/es2015/elements/seek-bar.js +20 -16
  155. package/dist/es2015/elements/shared.js +3 -3
  156. package/dist/es2015/elements/skip-button.js +2 -2
  157. package/dist/es2015/elements/speed-menu.js +4 -3
  158. package/dist/es2015/elements/spinner.js +1 -1
  159. package/dist/es2015/elements/start-button.js +3 -3
  160. package/dist/es2015/elements/subtitles-menu.js +5 -4
  161. package/dist/es2015/elements/time-element.js +1 -1
  162. package/dist/es2015/elements/title.js +1 -1
  163. package/dist/es2015/elements/video-menu.js +5 -4
  164. package/dist/es2015/elements/volume-slider.js +4 -4
  165. package/dist/es2015/entries/airplay-button.js +1 -1
  166. package/dist/es2015/entries/audio-menu.js +1 -1
  167. package/dist/es2015/entries/casting.js +6 -0
  168. package/dist/es2015/entries/chapters-menu.js +1 -1
  169. package/dist/es2015/entries/control-bar.js +1 -1
  170. package/dist/es2015/entries/current-time.js +1 -1
  171. package/dist/es2015/entries/drm-badge.js +1 -1
  172. package/dist/es2015/entries/duration.js +1 -1
  173. package/dist/es2015/entries/error-screen.js +1 -1
  174. package/dist/es2015/entries/fullscreen-button.js +1 -1
  175. package/dist/es2015/entries/live-button.js +1 -1
  176. package/dist/es2015/entries/marker-button.js +1 -1
  177. package/dist/es2015/entries/mute-button.js +1 -1
  178. package/dist/es2015/entries/pip-button.js +1 -1
  179. package/dist/es2015/entries/play-button.js +1 -1
  180. package/dist/es2015/entries/quality-menu.js +1 -1
  181. package/dist/es2015/entries/remaining-time.js +1 -1
  182. package/dist/es2015/entries/scan-button.js +1 -1
  183. package/dist/es2015/entries/seek-bar.js +1 -1
  184. package/dist/es2015/entries/skip-button.js +1 -1
  185. package/dist/es2015/entries/spacer.js +1 -1
  186. package/dist/es2015/entries/speed-menu.js +1 -1
  187. package/dist/es2015/entries/spinner.js +1 -1
  188. package/dist/es2015/entries/start-button.js +1 -1
  189. package/dist/es2015/entries/subtitles-menu.js +1 -1
  190. package/dist/es2015/entries/title.js +1 -1
  191. package/dist/es2015/entries/video-menu.js +1 -1
  192. package/dist/es2015/entries/volume-slider.js +1 -1
  193. package/dist/es2015/entries/volume.js +1 -1
  194. package/dist/es2015/host.js +9 -1
  195. package/dist/es2015/index.js +5 -3
  196. package/dist/es2015/locales/ar.js +2 -1
  197. package/dist/es2015/locales/ca.js +2 -1
  198. package/dist/es2015/locales/de.js +2 -1
  199. package/dist/es2015/locales/es.js +2 -1
  200. package/dist/es2015/locales/fr.js +2 -1
  201. package/dist/es2015/locales/hi.js +2 -1
  202. package/dist/es2015/locales/it.js +2 -1
  203. package/dist/es2015/locales/ja.js +2 -1
  204. package/dist/es2015/locales/ko.js +2 -1
  205. package/dist/es2015/locales/pt.js +2 -1
  206. package/dist/es2015/locales/zh.js +2 -1
  207. package/dist/es2015/locales.js +1 -1
  208. package/dist/es2015/media.js +136 -0
  209. package/dist/es2015/presets.js +1 -1
  210. package/dist/es2015/style.js +1 -1
  211. package/dist/es2015/tags.js +2 -1
  212. package/dist/es2015/video-sources.js +1 -1
  213. package/dist/host.d.ts +19 -1
  214. package/dist/host.d.ts.map +1 -1
  215. package/dist/host.js +9 -1
  216. package/dist/host.js.map +1 -1
  217. package/dist/index.d.ts +4 -0
  218. package/dist/index.d.ts.map +1 -1
  219. package/dist/index.js +5 -3
  220. package/dist/locales/ar.d.ts +1 -0
  221. package/dist/locales/ar.d.ts.map +1 -1
  222. package/dist/locales/ar.js +2 -1
  223. package/dist/locales/ar.js.map +1 -1
  224. package/dist/locales/ca.d.ts +1 -0
  225. package/dist/locales/ca.d.ts.map +1 -1
  226. package/dist/locales/ca.js +2 -1
  227. package/dist/locales/ca.js.map +1 -1
  228. package/dist/locales/de.d.ts +1 -0
  229. package/dist/locales/de.d.ts.map +1 -1
  230. package/dist/locales/de.js +2 -1
  231. package/dist/locales/de.js.map +1 -1
  232. package/dist/locales/es.d.ts +1 -0
  233. package/dist/locales/es.d.ts.map +1 -1
  234. package/dist/locales/es.js +2 -1
  235. package/dist/locales/es.js.map +1 -1
  236. package/dist/locales/fr.d.ts +1 -0
  237. package/dist/locales/fr.d.ts.map +1 -1
  238. package/dist/locales/fr.js +2 -1
  239. package/dist/locales/fr.js.map +1 -1
  240. package/dist/locales/hi.d.ts +1 -0
  241. package/dist/locales/hi.d.ts.map +1 -1
  242. package/dist/locales/hi.js +2 -1
  243. package/dist/locales/hi.js.map +1 -1
  244. package/dist/locales/it.d.ts +1 -0
  245. package/dist/locales/it.d.ts.map +1 -1
  246. package/dist/locales/it.js +2 -1
  247. package/dist/locales/it.js.map +1 -1
  248. package/dist/locales/ja.d.ts +1 -0
  249. package/dist/locales/ja.d.ts.map +1 -1
  250. package/dist/locales/ja.js +2 -1
  251. package/dist/locales/ja.js.map +1 -1
  252. package/dist/locales/ko.d.ts +1 -0
  253. package/dist/locales/ko.d.ts.map +1 -1
  254. package/dist/locales/ko.js +2 -1
  255. package/dist/locales/ko.js.map +1 -1
  256. package/dist/locales/pt.d.ts +1 -0
  257. package/dist/locales/pt.d.ts.map +1 -1
  258. package/dist/locales/pt.js +2 -1
  259. package/dist/locales/pt.js.map +1 -1
  260. package/dist/locales/zh.d.ts +1 -0
  261. package/dist/locales/zh.d.ts.map +1 -1
  262. package/dist/locales/zh.js +2 -1
  263. package/dist/locales/zh.js.map +1 -1
  264. package/dist/media.d.ts +22 -0
  265. package/dist/media.d.ts.map +1 -0
  266. package/dist/media.js +136 -0
  267. package/dist/media.js.map +1 -0
  268. package/dist/messages.d.ts +2 -0
  269. package/dist/messages.d.ts.map +1 -1
  270. package/dist/remote.d.ts +80 -0
  271. package/dist/remote.d.ts.map +1 -0
  272. package/dist/style.js +1 -1
  273. package/dist/style.js.map +1 -1
  274. package/dist/tags.d.ts +1 -0
  275. package/dist/tags.d.ts.map +1 -1
  276. package/dist/tags.js +2 -1
  277. package/dist/tags.js.map +1 -1
  278. package/package.json +2 -2
  279. package/dist/es2015/_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/toPrimitive.js +0 -13
@@ -0,0 +1 @@
1
+ {"version":3,"file":"casting.js","names":[],"sources":["../../src/elements/casting.ts"],"sourcesContent":["/**\n * <mbx-casting>: what the picture shows while a device plays in the\n * video's place. The programme's poster, or its image, covers the paused\n * video, with a line that names the device: \"Casting to Living room\". The\n * controls stay as they are and drive the device.\n *\n * Shown while the player carries `casting`, for a Chromecast and for\n * AirPlay alike, and hidden otherwise. The element carries `casting` too,\n * with the device's kind, so a page styles one kind in CSS. Safari names no AirPlay device, so\n * the line is \"AirPlay\" there. The `label` attribute gives the line its\n * words, with `{device}` for the name. Placed first among the screens, so\n * the title, the start button and the bar paint over it.\n */\nimport { el } from '../dom.js';\nimport type { PlayerHost } from '../host.js';\nimport { fill } from '../labels.js';\nimport STYLE from './casting.css?inline';\nimport { Component } from './component.js';\nimport { style } from './shared.js';\n\nexport class MbxCasting extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label'];\n }\n\n declare private readonly poster: HTMLImageElement;\n declare private readonly label: HTMLElement;\n\n constructor() {\n super();\n const root = this.attachShadow({ mode: 'open' });\n this.poster = el('img', 'poster');\n this.poster.alt = '';\n this.poster.hidden = true;\n this.label = el('div', 'label');\n // Said once when the device takes over.\n this.label.setAttribute('role', 'status');\n root.append(style(STYLE), this.poster, this.label);\n }\n\n protected override attach(player: PlayerHost): void {\n this.listen(player, ['programmechange'], () => {\n this.render();\n });\n this.render();\n }\n\n protected override detach(): void {\n this.removeAttribute('casting');\n }\n\n protected override render(): void {\n const player = this.player;\n const target = player?.casting ?? null;\n // The device's kind on the element, for its own stylesheet and the page's.\n if (target === null) this.removeAttribute('casting');\n else this.setAttribute('casting', target.kind);\n if (player === null || target === null) return;\n const metadata = player.programme?.metadata;\n const poster = metadata?.poster ?? metadata?.image ?? player.getAttribute('poster');\n this.poster.hidden = poster === null || poster === undefined;\n if (poster !== null && poster !== undefined && this.poster.getAttribute('src') !== poster) {\n this.poster.src = poster;\n }\n this.label.textContent =\n target.name === ''\n ? target.kind === 'airplay'\n ? this.word('label', 'airplay', 'AirPlay')\n : ''\n : fill(this.word('label', 'castingTo', 'Casting to {device}'), { device: target.name });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,MAAA,QAAA;AAIA,IAAa,aAAb,cAAgC,UAAU;CACxC,WAAW,qBAAwC;EACjD,OAAO,CAAC,OAAO;CACjB;CAKA,cAAc;EACZ,MAAM;EACN,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,KAAK,SAAS,GAAG,OAAO,QAAQ;EAChC,KAAK,OAAO,MAAM;EAClB,KAAK,OAAO,SAAS;EACrB,KAAK,QAAQ,GAAG,OAAO,OAAO;EAE9B,KAAK,MAAM,aAAa,QAAQ,QAAQ;EACxC,KAAK,OAAO,MAAM,KAAK,GAAG,KAAK,QAAQ,KAAK,KAAK;CACnD;CAEmB,OAAO,QAA0B;EAClD,KAAK,OAAO,QAAQ,CAAC,iBAAiB,SAAS;GAC7C,KAAK,OAAO;EACd,CAAC;EACD,KAAK,OAAO;CACd;CAEmB,SAAe;EAChC,KAAK,gBAAgB,SAAS;CAChC;CAEmB,SAAe;EAChC,MAAM,SAAS,KAAK;EACpB,MAAM,SAAS,QAAQ,WAAW;EAElC,IAAI,WAAW,MAAM,KAAK,gBAAgB,SAAS;OAC9C,KAAK,aAAa,WAAW,OAAO,IAAI;EAC7C,IAAI,WAAW,QAAQ,WAAW,MAAM;EACxC,MAAM,WAAW,OAAO,WAAW;EACnC,MAAM,SAAS,UAAU,UAAU,UAAU,SAAS,OAAO,aAAa,QAAQ;EAClF,KAAK,OAAO,SAAS,WAAW,QAAQ,WAAW,KAAA;EACnD,IAAI,WAAW,QAAQ,WAAW,KAAA,KAAa,KAAK,OAAO,aAAa,KAAK,MAAM,QACjF,KAAK,OAAO,MAAM;EAEpB,KAAK,MAAM,cACT,OAAO,SAAS,KACZ,OAAO,SAAS,YACd,KAAK,KAAK,SAAS,WAAW,SAAS,IACvC,KACF,KAAK,KAAK,KAAK,SAAS,aAAa,qBAAqB,GAAG,EAAE,QAAQ,OAAO,KAAK,CAAC;CAC5F;AACF"}
@@ -1,7 +1,7 @@
1
- import { show } from "./shared.js";
2
- import { MenuElement, single } from "./menu-element.js";
3
- import { format } from "../controls/time.js";
4
1
  import { chapterAt, chapters, followChapters } from "../controls/chapters.js";
2
+ import { format } from "../controls/time.js";
3
+ import { MenuElement, single } from "./menu-element.js";
4
+ import { show } from "./shared.js";
5
5
  // src/elements/chapters-menu.ts
6
6
  /**
7
7
  * <mbx-chapters-menu>: the chapters of the video as a list, each with its
@@ -30,7 +30,7 @@ var MbxChaptersMenu = class extends MenuElement {
30
30
  this.render();
31
31
  };
32
32
  this.keep(followChapters(player, tick));
33
- this.listen(player.video, [
33
+ this.listen(player.media, [
34
34
  "timeupdate",
35
35
  "seeked",
36
36
  "emptied",
@@ -41,7 +41,7 @@ var MbxChaptersMenu = class extends MenuElement {
41
41
  }
42
42
  render() {
43
43
  super.render();
44
- const video = this.player?.video;
44
+ const video = this.player?.media;
45
45
  if (video === void 0) return;
46
46
  const list = chapters(video, this.player?.engine ?? null);
47
47
  this.hidden = list.length === 0;
@@ -1 +1 @@
1
- {"version":3,"file":"chapters-menu.js","names":[],"sources":["../../src/elements/chapters-menu.ts"],"sourcesContent":["/**\n * <mbx-chapters-menu>: the chapters of the video as a list, each with its\n * start time, the one the playhead is in checked; choosing one seeks to its\n * start. The chapters are the engine's when the session holds some, and\n * the video's own chapters text track otherwise, see `controls/chapters.ts`,\n * so the menu works for every session, native included, and hides while\n * there are none. Each item shows the chapter's picture when every chapter\n * has one: a list where some rows have a picture and some do not reads as\n * broken. The name comes from `label`.\n */\nimport { chapterAt, chapters, followChapters } from '../controls/chapters.js';\nimport { format } from '../controls/time.js';\nimport type { PlayerHost } from '../host.js';\nimport type { Messages } from '../messages.js';\nimport { MenuElement, single } from './menu-element.js';\nimport { show } from './shared.js';\n\nexport class MbxChaptersMenu extends MenuElement {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-back'];\n }\n\n /** What the last fill drew, so a cue change inside the same chapter leaves the popup alone. */\n declare private drawn: string;\n\n constructor() {\n super(...single('chapters'));\n this.drawn = '';\n show(this.slots, 'default');\n }\n\n protected override name(): readonly [keyof Messages, string] {\n return ['chapters', 'Chapters'];\n }\n\n protected override attach(player: PlayerHost): void {\n const tick = (): void => {\n this.render();\n };\n this.keep(followChapters(player, tick));\n // The clock too: WebKit fires no `cuechange` for a hidden track, and the\n // render is a no-op while the chapter is the same.\n this.listen(player.video, ['timeupdate', 'seeked', 'emptied', 'loadedmetadata'], tick);\n this.listen(player, ['sourcechange'], tick);\n this.render();\n }\n\n protected override render(): void {\n super.render();\n const video = this.player?.video;\n if (video === undefined) return;\n const list = chapters(video, this.player?.engine ?? null);\n this.hidden = list.length === 0;\n const current = String(chapterAt(list, video.currentTime));\n const pictured = list.every((chapter) => chapter.image !== undefined);\n const items = list.map((chapter, i): readonly [string, string, string, string?] =>\n pictured && chapter.image !== undefined\n ? [String(i), chapter.title, format(chapter.start), chapter.image]\n : [String(i), chapter.title, format(chapter.start)],\n );\n const key = `${current}|${items.map((item) => item.slice(1).join(' ')).join('\\n')}`;\n if (key === this.drawn) return;\n this.drawn = key;\n this.menu.fill([\n {\n name: 'chapter',\n items,\n value: current,\n onSelect: (value) => {\n const chapter = list[Number(value)];\n if (chapter !== undefined) video.currentTime = chapter.start;\n },\n },\n ]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,IAAa,kBAAb,cAAqC,YAAY;CAC/C,WAAW,qBAAwC;EACjD,OAAO,CAAC,SAAS,YAAY;CAC/B;CAKA,cAAc;EACZ,MAAM,GAAG,OAAO,UAAU,CAAC;EAC3B,KAAK,QAAQ;EACb,KAAK,KAAK,OAAO,SAAS;CAC5B;CAEA,OAA6D;EAC3D,OAAO,CAAC,YAAY,UAAU;CAChC;CAEA,OAA0B,QAA0B;EAClD,MAAM,aAAmB;GACvB,KAAK,OAAO;EACd;EACA,KAAK,KAAK,eAAe,QAAQ,IAAI,CAAC;EAGtC,KAAK,OAAO,OAAO,OAAO;GAAC;GAAc;GAAU;GAAW;EAAgB,GAAG,IAAI;EACrF,KAAK,OAAO,QAAQ,CAAC,cAAc,GAAG,IAAI;EAC1C,KAAK,OAAO;CACd;CAEA,SAAkC;EAChC,MAAM,OAAO;EACb,MAAM,QAAQ,KAAK,QAAQ;EAC3B,IAAI,UAAU,KAAA,GAAW;EACzB,MAAM,OAAO,SAAS,OAAO,KAAK,QAAQ,UAAU,IAAI;EACxD,KAAK,SAAS,KAAK,WAAW;EAC9B,MAAM,UAAU,OAAO,UAAU,MAAM,MAAM,WAAW,CAAC;EACzD,MAAM,WAAW,KAAK,OAAO,YAAY,QAAQ,UAAU,KAAA,CAAS;EACpE,MAAM,QAAQ,KAAK,KAAK,SAAS,MAC/B,YAAY,QAAQ,UAAU,KAAA,IAC1B;GAAC,OAAO,CAAC;GAAG,QAAQ;GAAO,OAAO,QAAQ,KAAK;GAAG,QAAQ;EAAK,IAC/D;GAAC,OAAO,CAAC;GAAG,QAAQ;GAAO,OAAO,QAAQ,KAAK;EAAC,CACtD;EACA,MAAM,MAAM,GAAG,QAAQ,GAAG,MAAM,KAAK,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI;EAChF,IAAI,QAAQ,KAAK,OAAO;EACxB,KAAK,QAAQ;EACb,KAAK,KAAK,KAAK,CACb;GACE,MAAM;GACN;GACA,OAAO;GACP,WAAW,UAAU;IACnB,MAAM,UAAU,KAAK,OAAO,KAAK;IACjC,IAAI,YAAY,KAAA,GAAW,MAAM,cAAc,QAAQ;GACzD;EACF,CACF,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"chapters-menu.js","names":[],"sources":["../../src/elements/chapters-menu.ts"],"sourcesContent":["/**\n * <mbx-chapters-menu>: the chapters of the video as a list, each with its\n * start time, the one the playhead is in checked; choosing one seeks to its\n * start. The chapters are the engine's when the session holds some, and\n * the video's own chapters text track otherwise, see `controls/chapters.ts`,\n * so the menu works for every session, native included, and hides while\n * there are none. Each item shows the chapter's picture when every chapter\n * has one: a list where some rows have a picture and some do not reads as\n * broken. The name comes from `label`.\n */\nimport { chapterAt, chapters, followChapters } from '../controls/chapters.js';\nimport { format } from '../controls/time.js';\nimport type { PlayerHost } from '../host.js';\nimport type { Messages } from '../messages.js';\nimport { MenuElement, single } from './menu-element.js';\nimport { show } from './shared.js';\n\nexport class MbxChaptersMenu extends MenuElement {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-back'];\n }\n\n /** What the last fill drew, so a cue change inside the same chapter leaves the popup alone. */\n declare private drawn: string;\n\n constructor() {\n super(...single('chapters'));\n this.drawn = '';\n show(this.slots, 'default');\n }\n\n protected override name(): readonly [keyof Messages, string] {\n return ['chapters', 'Chapters'];\n }\n\n protected override attach(player: PlayerHost): void {\n const tick = (): void => {\n this.render();\n };\n this.keep(followChapters(player, tick));\n // The clock too: WebKit fires no `cuechange` for a hidden track, and the\n // render is a no-op while the chapter is the same.\n this.listen(player.media, ['timeupdate', 'seeked', 'emptied', 'loadedmetadata'], tick);\n this.listen(player, ['sourcechange'], tick);\n this.render();\n }\n\n protected override render(): void {\n super.render();\n const video = this.player?.media;\n if (video === undefined) return;\n const list = chapters(video, this.player?.engine ?? null);\n this.hidden = list.length === 0;\n const current = String(chapterAt(list, video.currentTime));\n const pictured = list.every((chapter) => chapter.image !== undefined);\n const items = list.map((chapter, i): readonly [string, string, string, string?] =>\n pictured && chapter.image !== undefined\n ? [String(i), chapter.title, format(chapter.start), chapter.image]\n : [String(i), chapter.title, format(chapter.start)],\n );\n const key = `${current}|${items.map((item) => item.slice(1).join(' ')).join('\\n')}`;\n if (key === this.drawn) return;\n this.drawn = key;\n this.menu.fill([\n {\n name: 'chapter',\n items,\n value: current,\n onSelect: (value) => {\n const chapter = list[Number(value)];\n if (chapter !== undefined) video.currentTime = chapter.start;\n },\n },\n ]);\n }\n}\n"],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KAAK,KAAK,KAAK,CACb;GACE,MAAM;GACN;GACA,OAAO;GACP,WAAW,UAAU;IACnB,MAAM,UAAU,KAAK,OAAO,KAAK;IACjC,IAAI,YAAY,KAAA,GAAW,MAAM,cAAc,QAAQ;GACzD;EACF,CACF,CAAC;CACH;AACF"}
@@ -18,6 +18,14 @@ import type { Messages } from '../messages.js';
18
18
  import type { Text } from '../text.js';
19
19
  export declare abstract class Component extends HTMLElement {
20
20
  protected player: PlayerHost | null;
21
+ /**
22
+ * When the control has nothing to act on while a device plays in the
23
+ * video's place: `device` for any device, since the control acts on the
24
+ * picture of the page or on its quality, and `remote` for a device that
25
+ * is not the video itself, as AirPlay is. The control then carries
26
+ * `away`, and its stylesheet hides it. Null for a control that stays.
27
+ */
28
+ protected leaves: 'device' | 'remote' | null;
21
29
  private offs;
22
30
  /** Bumped on every connect and disconnect, so a late upgrade attaches only to the current connection. */
23
31
  private epoch;
@@ -27,6 +35,11 @@ export declare abstract class Component extends HTMLElement {
27
35
  attributeChangedCallback(): void;
28
36
  /** Adds `fn` for every name on `target`, to be removed on detach. */
29
37
  protected listen(target: EventTarget, names: readonly string[], fn: (event: Event) => void): void;
38
+ /**
39
+ * Whether a device plays that is not the video itself. Under AirPlay the
40
+ * video still plays the source and answers every member.
41
+ */
42
+ protected remote(): boolean;
30
43
  /**
31
44
  * A word the control shows: its `attribute` when the page set one, else
32
45
  * the player's language's `id`, else `english`.
@@ -1 +1 @@
1
- {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/elements/component.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGvC,8BAAsB,SA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,GAAG,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,GACxD,IAAI;IAcP,mGAAmG;IACnG,SAAS,CAAC,OAAO,CACf,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,EAAE,EAAE,MAAM,IAAI,EACd,OAAO,UAAQ,GACd,IAAI;IAQP,gFAAgF;IAChF,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAEnD,mFAAmF;IACnF,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAE3C,yFAAyF;IACzF,SAAS,CAAC,MAAM,IAAI,IAAI;CACzB"}
@@ -1,11 +1,12 @@
1
+ import { findPlayer } from "../host.js";
1
2
  import { PLAYER } from "../tags.js";
2
3
  import { textIn } from "../text.js";
3
- import { findPlayer } from "../host.js";
4
4
  // src/elements/component.ts
5
5
  var Component = class extends HTMLElement {
6
6
  constructor() {
7
7
  super();
8
8
  this.player = null;
9
+ this.leaves = null;
9
10
  this.offs = [];
10
11
  this.epoch = 0;
11
12
  }
@@ -17,7 +18,7 @@ var Component = class extends HTMLElement {
17
18
  const attach = () => {
18
19
  if (epoch !== this.epoch || !this.isConnected) return;
19
20
  customElements.upgrade(found);
20
- if (!("video" in found)) return;
21
+ if (!("media" in found)) return;
21
22
  this.player = found;
22
23
  const tier = () => {
23
24
  const layout = found.getAttribute("layout");
@@ -31,10 +32,19 @@ var Component = class extends HTMLElement {
31
32
  this.listen(found, ["localechange"], () => {
32
33
  this.render();
33
34
  });
35
+ const cast = () => {
36
+ const gone = this.leaves !== null && found.hasAttribute("casting") && (this.leaves === "device" || this.remote());
37
+ this.toggleAttribute("away", gone);
38
+ };
39
+ this.listen(found, ["castingchange"], () => {
40
+ cast();
41
+ this.render();
42
+ });
34
43
  tier();
44
+ cast();
35
45
  this.attach(this.player);
36
46
  };
37
- if ("video" in found) attach();
47
+ if ("media" in found) attach();
38
48
  else customElements.whenDefined(PLAYER).then(attach);
39
49
  }
40
50
  disconnectedCallback() {
@@ -57,6 +67,14 @@ var Component = class extends HTMLElement {
57
67
  });
58
68
  }
59
69
  /**
70
+ * Whether a device plays that is not the video itself. Under AirPlay the
71
+ * video still plays the source and answers every member.
72
+ */
73
+ remote() {
74
+ const target = this.player?.casting ?? null;
75
+ return target !== null && target.kind !== "airplay";
76
+ }
77
+ /**
60
78
  * A word the control shows: its `attribute` when the page set one, else
61
79
  * the player's language's `id`, else `english`.
62
80
  */
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","names":[],"sources":["../../src/elements/component.ts"],"sourcesContent":["/**\n * What every control shares: finding its player, and letting go of it.\n *\n * A control attaches when it is connected inside a player, once the player\n * is defined and upgraded, and detaches when it is removed. Every listener\n * a control adds goes through `listen`, so detaching drops them all. A\n * control connected outside a player is inert. Moving one to another\n * player detaches and attaches again, so a framework that reorders\n * children is safe.\n *\n * No class fields: the ES2015 build would lower them into helpers, and the\n * emit check bans helpers. State is declared, then assigned in the\n * constructor.\n */\nimport type { Mattebox } from 'mattebox';\nimport type { PlayerHost } from '../host.js';\nimport { findPlayer } from '../host.js';\nimport type { Messages } from '../messages.js';\nimport { PLAYER } from '../tags.js';\nimport type { Text } from '../text.js';\nimport { textIn } from '../text.js';\n\nexport abstract class Component extends HTMLElement {\n declare protected player: PlayerHost | null;\n declare private offs: Array<() => void>;\n /** Bumped on every connect and disconnect, so a late upgrade attaches only to the current connection. */\n declare private epoch: number;\n\n constructor() {\n super();\n this.player = null;\n this.offs = [];\n this.epoch = 0;\n }\n\n connectedCallback(): void {\n const found = findPlayer(this);\n if (found === null) return;\n this.epoch += 1;\n const epoch = this.epoch;\n const attach = (): void => {\n if (epoch !== this.epoch || !this.isConnected) return;\n // Defined, and this instance upgraded: `video` is on the prototype.\n customElements.upgrade(found);\n if (!('video' in found)) return;\n this.player = found as PlayerHost;\n // The player's size tier, on the control itself: a shadow tree cannot\n // match an attribute of an ancestor in every browser, and with it\n // here a control's stylesheet says `:host([layout=\"compact\"])`.\n const tier = (): void => {\n const layout = found.getAttribute('layout');\n if (layout === null) this.removeAttribute('layout');\n else this.setAttribute('layout', layout);\n };\n this.listen(found, ['layoutchange'], () => {\n tier();\n this.render();\n });\n this.listen(found, ['localechange'], () => {\n this.render();\n });\n tier();\n this.attach(this.player);\n };\n if ('video' in found) attach();\n else void customElements.whenDefined(PLAYER).then(attach);\n }\n\n disconnectedCallback(): void {\n this.epoch += 1;\n for (const off of this.offs) off();\n this.offs = [];\n const player = this.player;\n if (player === null) return;\n this.player = null;\n this.detach(player);\n }\n\n attributeChangedCallback(): void {\n if (this.player !== null) this.render();\n }\n\n /** Adds `fn` for every name on `target`, to be removed on detach. */\n protected listen(\n target: EventTarget,\n names: readonly string[],\n fn: (event: Event) => void,\n ): void {\n for (const name of names) target.addEventListener(name, fn);\n this.offs.push(() => {\n for (const name of names) target.removeEventListener(name, fn);\n });\n }\n\n /**\n * A word the control shows: its `attribute` when the page set one, else\n * the player's language's `id`, else `english`.\n */\n protected word(attribute: string, id: keyof Messages, english: string): string {\n return this.getAttribute(attribute) ?? this.player?.message(id) ?? english;\n }\n\n /** Words the page gave, in the player's language. */\n protected pageText(text: Text): string {\n return textIn(text, this.player?.locale ?? '');\n }\n\n /** Keeps `off` to run on detach. */\n protected keep(off: () => void): void {\n this.offs.push(off);\n }\n\n /**\n * Runs `fn` over the current engine now and on every session change,\n * running what the last call returned first, so a control's engine\n * subscriptions live exactly as long as the session. Detach runs it too.\n */\n protected follow(\n player: PlayerHost,\n fn: (engine: Mattebox | null) => (() => void) | undefined,\n ): void {\n let off: (() => void) | undefined;\n const run = (): void => {\n off?.();\n off = fn(player.engine);\n };\n this.listen(player, ['sourcechange'], run);\n this.offs.push(() => {\n off?.();\n off = undefined;\n });\n run();\n }\n\n /** Runs `fn` when any of `names` changes on `target`, or under it with `subtree`, until detach. */\n protected observe(\n target: Element,\n names: readonly string[],\n fn: () => void,\n subtree = false,\n ): void {\n const observer = new MutationObserver(fn);\n observer.observe(target, { attributes: true, attributeFilter: [...names], subtree });\n this.offs.push(() => {\n observer.disconnect();\n });\n }\n\n /** The control is connected inside an upgraded player. Subscribe and render. */\n protected abstract attach(player: PlayerHost): void;\n\n /** The control left its player. Listeners are already gone; undo anything else. */\n protected detach(_player: PlayerHost): void {}\n\n /** Draws the current state. Called on every observed attribute change while attached. */\n protected render(): void {}\n}\n"],"mappings":";;;;AAsBA,IAAsB,YAAtB,cAAwC,YAAY;CAMlD,cAAc;EACZ,MAAM;EACN,KAAK,SAAS;EACd,KAAK,OAAO,CAAC;EACb,KAAK,QAAQ;CACf;CAEA,oBAA0B;EACxB,MAAM,QAAQ,WAAW,IAAI;EAC7B,IAAI,UAAU,MAAM;EACpB,KAAK,SAAS;EACd,MAAM,QAAQ,KAAK;EACnB,MAAM,eAAqB;GACzB,IAAI,UAAU,KAAK,SAAS,CAAC,KAAK,aAAa;GAE/C,eAAe,QAAQ,KAAK;GAC5B,IAAI,EAAE,WAAW,QAAQ;GACzB,KAAK,SAAS;GAId,MAAM,aAAmB;IACvB,MAAM,SAAS,MAAM,aAAa,QAAQ;IAC1C,IAAI,WAAW,MAAM,KAAK,gBAAgB,QAAQ;SAC7C,KAAK,aAAa,UAAU,MAAM;GACzC;GACA,KAAK,OAAO,OAAO,CAAC,cAAc,SAAS;IACzC,KAAK;IACL,KAAK,OAAO;GACd,CAAC;GACD,KAAK,OAAO,OAAO,CAAC,cAAc,SAAS;IACzC,KAAK,OAAO;GACd,CAAC;GACD,KAAK;GACL,KAAK,OAAO,KAAK,MAAM;EACzB;EACA,IAAI,WAAW,OAAO,OAAO;OACxB,eAAoB,YAAY,MAAM,CAAC,CAAC,KAAK,MAAM;CAC1D;CAEA,uBAA6B;EAC3B,KAAK,SAAS;EACd,KAAK,MAAM,OAAO,KAAK,MAAM,IAAI;EACjC,KAAK,OAAO,CAAC;EACb,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,KAAK,SAAS;EACd,KAAK,OAAO,MAAM;CACpB;CAEA,2BAAiC;EAC/B,IAAI,KAAK,WAAW,MAAM,KAAK,OAAO;CACxC;;CAGA,OACE,QACA,OACA,IACM;EACN,KAAK,MAAM,QAAQ,OAAO,OAAO,iBAAiB,MAAM,EAAE;EAC1D,KAAK,KAAK,WAAW;GACnB,KAAK,MAAM,QAAQ,OAAO,OAAO,oBAAoB,MAAM,EAAE;EAC/D,CAAC;CACH;;;;;CAMA,KAAe,WAAmB,IAAoB,SAAyB;EAC7E,OAAO,KAAK,aAAa,SAAS,KAAK,KAAK,QAAQ,QAAQ,EAAE,KAAK;CACrE;;CAGA,SAAmB,MAAoB;EACrC,OAAO,OAAO,MAAM,KAAK,QAAQ,UAAU,EAAE;CAC/C;;CAGA,KAAe,KAAuB;EACpC,KAAK,KAAK,KAAK,GAAG;CACpB;;;;;;CAOA,OACE,QACA,IACM;EACN,IAAI;EACJ,MAAM,YAAkB;GACtB,MAAM;GACN,MAAM,GAAG,OAAO,MAAM;EACxB;EACA,KAAK,OAAO,QAAQ,CAAC,cAAc,GAAG,GAAG;EACzC,KAAK,KAAK,WAAW;GACnB,MAAM;GACN,MAAM,KAAA;EACR,CAAC;EACD,IAAI;CACN;;CAGA,QACE,QACA,OACA,IACA,UAAU,OACJ;EACN,MAAM,WAAW,IAAI,iBAAiB,EAAE;EACxC,SAAS,QAAQ,QAAQ;GAAE,YAAY;GAAM,iBAAiB,CAAC,GAAG,KAAK;GAAG;EAAQ,CAAC;EACnF,KAAK,KAAK,WAAW;GACnB,SAAS,WAAW;EACtB,CAAC;CACH;;CAMA,OAAiB,SAA2B,CAAC;;CAG7C,SAAyB,CAAC;AAC5B"}
1
+ {"version":3,"file":"component.js","names":[],"sources":["../../src/elements/component.ts"],"sourcesContent":["/**\n * What every control shares: finding its player, and letting go of it.\n *\n * A control attaches when it is connected inside a player, once the player\n * is defined and upgraded, and detaches when it is removed. Every listener\n * a control adds goes through `listen`, so detaching drops them all. A\n * control connected outside a player is inert. Moving one to another\n * player detaches and attaches again, so a framework that reorders\n * children is safe.\n *\n * No class fields: the ES2015 build would lower them into helpers, and the\n * emit check bans helpers. State is declared, then assigned in the\n * constructor.\n */\nimport type { Mattebox } from 'mattebox';\nimport type { PlayerHost } from '../host.js';\nimport { findPlayer } from '../host.js';\nimport type { Messages } from '../messages.js';\nimport { PLAYER } from '../tags.js';\nimport type { Text } from '../text.js';\nimport { textIn } from '../text.js';\n\nexport abstract class Component extends HTMLElement {\n declare protected player: PlayerHost | null;\n /**\n * When the control has nothing to act on while a device plays in the\n * video's place: `device` for any device, since the control acts on the\n * picture of the page or on its quality, and `remote` for a device that\n * is not the video itself, as AirPlay is. The control then carries\n * `away`, and its stylesheet hides it. Null for a control that stays.\n */\n declare protected leaves: 'device' | 'remote' | null;\n declare private offs: Array<() => void>;\n /** Bumped on every connect and disconnect, so a late upgrade attaches only to the current connection. */\n declare private epoch: number;\n\n constructor() {\n super();\n this.player = null;\n this.leaves = null;\n this.offs = [];\n this.epoch = 0;\n }\n\n connectedCallback(): void {\n const found = findPlayer(this);\n if (found === null) return;\n this.epoch += 1;\n const epoch = this.epoch;\n const attach = (): void => {\n if (epoch !== this.epoch || !this.isConnected) return;\n // Defined, and this instance upgraded: `media` is on the prototype.\n customElements.upgrade(found);\n if (!('media' in found)) return;\n this.player = found as PlayerHost;\n // The player's size tier, on the control itself: a shadow tree cannot\n // match an attribute of an ancestor in every browser, and with it\n // here a control's stylesheet says `:host([layout=\"compact\"])`.\n const tier = (): void => {\n const layout = found.getAttribute('layout');\n if (layout === null) this.removeAttribute('layout');\n else this.setAttribute('layout', layout);\n };\n this.listen(found, ['layoutchange'], () => {\n tier();\n this.render();\n });\n this.listen(found, ['localechange'], () => {\n this.render();\n });\n const cast = (): void => {\n const gone =\n this.leaves !== null &&\n found.hasAttribute('casting') &&\n (this.leaves === 'device' || this.remote());\n this.toggleAttribute('away', gone);\n };\n this.listen(found, ['castingchange'], () => {\n cast();\n this.render();\n });\n tier();\n cast();\n this.attach(this.player);\n };\n if ('media' in found) attach();\n else void customElements.whenDefined(PLAYER).then(attach);\n }\n\n disconnectedCallback(): void {\n this.epoch += 1;\n for (const off of this.offs) off();\n this.offs = [];\n const player = this.player;\n if (player === null) return;\n this.player = null;\n this.detach(player);\n }\n\n attributeChangedCallback(): void {\n if (this.player !== null) this.render();\n }\n\n /** Adds `fn` for every name on `target`, to be removed on detach. */\n protected listen(\n target: EventTarget,\n names: readonly string[],\n fn: (event: Event) => void,\n ): void {\n for (const name of names) target.addEventListener(name, fn);\n this.offs.push(() => {\n for (const name of names) target.removeEventListener(name, fn);\n });\n }\n\n /**\n * Whether a device plays that is not the video itself. Under AirPlay the\n * video still plays the source and answers every member.\n */\n protected remote(): boolean {\n const target = this.player?.casting ?? null;\n return target !== null && target.kind !== 'airplay';\n }\n\n /**\n * A word the control shows: its `attribute` when the page set one, else\n * the player's language's `id`, else `english`.\n */\n protected word(attribute: string, id: keyof Messages, english: string): string {\n return this.getAttribute(attribute) ?? this.player?.message(id) ?? english;\n }\n\n /** Words the page gave, in the player's language. */\n protected pageText(text: Text): string {\n return textIn(text, this.player?.locale ?? '');\n }\n\n /** Keeps `off` to run on detach. */\n protected keep(off: () => void): void {\n this.offs.push(off);\n }\n\n /**\n * Runs `fn` over the current engine now and on every session change,\n * running what the last call returned first, so a control's engine\n * subscriptions live exactly as long as the session. Detach runs it too.\n */\n protected follow(\n player: PlayerHost,\n fn: (engine: Mattebox | null) => (() => void) | undefined,\n ): void {\n let off: (() => void) | undefined;\n const run = (): void => {\n off?.();\n off = fn(player.engine);\n };\n this.listen(player, ['sourcechange'], run);\n this.offs.push(() => {\n off?.();\n off = undefined;\n });\n run();\n }\n\n /** Runs `fn` when any of `names` changes on `target`, or under it with `subtree`, until detach. */\n protected observe(\n target: Element,\n names: readonly string[],\n fn: () => void,\n subtree = false,\n ): void {\n const observer = new MutationObserver(fn);\n observer.observe(target, { attributes: true, attributeFilter: [...names], subtree });\n this.offs.push(() => {\n observer.disconnect();\n });\n }\n\n /** The control is connected inside an upgraded player. Subscribe and render. */\n protected abstract attach(player: PlayerHost): void;\n\n /** The control left its player. Listeners are already gone; undo anything else. */\n protected detach(_player: PlayerHost): void {}\n\n /** Draws the current state. Called on every observed attribute change while attached. */\n protected render(): void {}\n}\n"],"mappings":";;;;AAsBA,IAAsB,YAAtB,cAAwC,YAAY;CAclD,cAAc;EACZ,MAAM;EACN,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,OAAO,CAAC;EACb,KAAK,QAAQ;CACf;CAEA,oBAA0B;EACxB,MAAM,QAAQ,WAAW,IAAI;EAC7B,IAAI,UAAU,MAAM;EACpB,KAAK,SAAS;EACd,MAAM,QAAQ,KAAK;EACnB,MAAM,eAAqB;GACzB,IAAI,UAAU,KAAK,SAAS,CAAC,KAAK,aAAa;GAE/C,eAAe,QAAQ,KAAK;GAC5B,IAAI,EAAE,WAAW,QAAQ;GACzB,KAAK,SAAS;GAId,MAAM,aAAmB;IACvB,MAAM,SAAS,MAAM,aAAa,QAAQ;IAC1C,IAAI,WAAW,MAAM,KAAK,gBAAgB,QAAQ;SAC7C,KAAK,aAAa,UAAU,MAAM;GACzC;GACA,KAAK,OAAO,OAAO,CAAC,cAAc,SAAS;IACzC,KAAK;IACL,KAAK,OAAO;GACd,CAAC;GACD,KAAK,OAAO,OAAO,CAAC,cAAc,SAAS;IACzC,KAAK,OAAO;GACd,CAAC;GACD,MAAM,aAAmB;IACvB,MAAM,OACJ,KAAK,WAAW,QAChB,MAAM,aAAa,SAAS,MAC3B,KAAK,WAAW,YAAY,KAAK,OAAO;IAC3C,KAAK,gBAAgB,QAAQ,IAAI;GACnC;GACA,KAAK,OAAO,OAAO,CAAC,eAAe,SAAS;IAC1C,KAAK;IACL,KAAK,OAAO;GACd,CAAC;GACD,KAAK;GACL,KAAK;GACL,KAAK,OAAO,KAAK,MAAM;EACzB;EACA,IAAI,WAAW,OAAO,OAAO;OACnB,eAAe,YAAY,MAA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KAAK,WAAW;GACnB,SAAS,WAAW;EACtB,CAAC;CACH;;CAMU,OAAO,SAA2B,CAAC;;CAGnC,SAAe,CAAC;AAC5B"}
@@ -1 +1 @@
1
- {"version":3,"file":"control-bar.d.ts","sourceRoot":"","sources":["../../src/elements/control-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAkB7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA+E3C,qBAAa,aAAc,SAAQ,SAAS;IAC1C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,OAAO,CAAiB;IACjD,iBAAyB,UAAU,CAAiB;IACpD,iBAAyB,OAAO,CAAkB;IAClD,QAAgB,KAAK,CAA4C;IACjE,6FAA6F;IAC7F,QAAgB,OAAO,CAAwB;IAC/C,uEAAuE;IACvE,QAAgB,QAAQ,CAAU;IAClC,QAAgB,IAAI,CAAiB;IACrC,QAAgB,MAAM,CAAoB;;IAsB1C;;;;;OAKG;IACH,uEAAuE;IACvE,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,MAAM;IAed;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAyBhB,wFAAwF;IACxF,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,KAAK;IAWb,OAAO,CAAC,IAAI;IAMZ;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,GAAG;cAkDQ,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cA8DhC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;CAgBpD"}
1
+ {"version":3,"file":"control-bar.d.ts","sourceRoot":"","sources":["../../src/elements/control-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAmB7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA+E3C,qBAAa,aAAc,SAAQ,SAAS;IAC1C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,OAAO,CAAiB;IACjD,iBAAyB,UAAU,CAAiB;IACpD,iBAAyB,OAAO,CAAkB;IAClD,QAAgB,KAAK,CAA4C;IACjE,6FAA6F;IAC7F,QAAgB,OAAO,CAAwB;IAC/C,uEAAuE;IACvE,QAAgB,QAAQ,CAAU;IAClC,QAAgB,IAAI,CAAiB;IACrC,QAAgB,MAAM,CAAoB;;IAsB1C;;;;;OAKG;IACH,uEAAuE;IACvE,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,MAAM;IAed;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAyBhB,wFAAwF;IACxF,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,KAAK;IAWb,OAAO,CAAC,IAAI;IAMZ;;;;OAIG;IACH,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,GAAG;cAkDQ,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cA8DhC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;CAgBpD"}
@@ -1,8 +1,9 @@
1
+ import { cueLift, cueStyle } from "../controls/cues.js";
2
+ import { fullscreen } from "../controls/fullscreen.js";
3
+ import { videoOf } from "../host.js";
1
4
  import { AIRPLAY_BUTTON, AUDIO_MENU, CHAPTERS_MENU, DRM_BADGE, MUTE_BUTTON, PIP_BUTTON, QUALITY_MENU, SCAN_BUTTON, SKIP_BUTTON, SPEED_MENU, SUBTITLES_MENU, VIDEO_MENU, VOLUME, VOLUME_SLIDER } from "../tags.js";
2
5
  import { Component } from "./component.js";
3
6
  import { number, shownPaused, style } from "./shared.js";
4
- import { cueLift, cueStyle } from "../controls/cues.js";
5
- import { fullscreen } from "../controls/fullscreen.js";
6
7
  // src/elements/control-bar.ts
7
8
  const STYLE = ":host{box-sizing:border-box;color:var(--mbx-text);font:500 1em / 1.2 var(--mbx-font);background:linear-gradient(#0000,#0009);flex-direction:column;padding:2.5em 1em .75em;transition:opacity .2s;display:flex;position:absolute;bottom:0;left:0;right:0}:host([menu]){z-index:2;--mbx-tooltip:none}:host([idle]){opacity:0;pointer-events:none}[part~=row]{align-items:center;margin:0 -.25em;display:flex}[part~=buttons-row]{margin-top:.25em}[part~=seek-row]{margin:0 -.5em}slot:not([name])::slotted(*){margin:0 .25em}slot[name=seek]::slotted(*){margin:0 .5em}::slotted([collapsed]){display:none}@media (prefers-reduced-motion:reduce){:host{transition:none}}:host([layout=compact]){padding:1.5em .5em .25em}";
8
9
  const IDLE_MS = 3e3;
@@ -186,14 +187,14 @@ var MbxControlBar = class extends Component {
186
187
  cancelable: true
187
188
  });
188
189
  if (!player.dispatchEvent(asked)) return;
189
- const video = player.video;
190
+ const video = player.media;
190
191
  video.currentTime = Math.min(end(video), Math.max(0, video.currentTime + by));
191
192
  }
192
193
  key(player, event) {
193
194
  this.keyboard = true;
194
195
  this.wake(player);
195
196
  if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;
196
- const video = player.video;
197
+ const video = player.media;
197
198
  const onButton = event.composedPath()[0] instanceof HTMLButtonElement;
198
199
  switch (event.key) {
199
200
  case " ":
@@ -235,7 +236,7 @@ var MbxControlBar = class extends Component {
235
236
  event.preventDefault();
236
237
  }
237
238
  attach(player) {
238
- const video = player.video;
239
+ const video = player.media;
239
240
  cueStyle();
240
241
  this.cues = cueLift(video, player, () => this.covered());
241
242
  const screen = fullscreen(player, video);
@@ -265,7 +266,7 @@ var MbxControlBar = class extends Component {
265
266
  this.key(player, event);
266
267
  };
267
268
  const click = (event) => {
268
- if (event.composedPath()[0] === video) toggle(video);
269
+ if (event.composedPath()[0] === videoOf(player)) toggle(video);
269
270
  };
270
271
  this.listen(player, ["pointermove", "pointerdown"], pointer);
271
272
  player.addEventListener("keydown", key);
@@ -1 +1 @@
1
- {"version":3,"file":"control-bar.js","names":[],"sources":["../../src/elements/control-bar.ts"],"sourcesContent":["/**\n * <mbx-control-bar>: an overlay over the bottom of the video that lays its\n * children out in two rows, the seek row over the buttons row. A child\n * with `slot=\"seek\"` sits in the seek row; everything else in the buttons\n * row, in its order, and an <mbx-spacer> pushes what follows to the right.\n *\n * The bar owns what no one control can: the idle fade, the shortcuts, the\n * click on the video, and the subtitles lifted above it. It sets `idle` on\n * itself and on the player while it hides.\n *\n * The fade is one timer. Any activity, a pointer moving or pressing, a\n * key, playback starting, re-arms it for `idle-ms`, and when it fires the\n * bar hides unless something it can know for certain holds it: the video\n * is paused, a descendant carries `open`, or keyboard focus is inside it,\n * where keyboard means the last input was a key and not a pointer.\n * Whether the pointer is over the player is never tracked: that goes\n * stale when the pointer leaves without a move the player sees.\n *\n * The shortcuts listen on the player, so they hear every key pressed\n * inside it, and only there: Space and `k` toggle play, `m` mutes, `f`\n * toggles fullscreen, the arrows seek by `seek-step`. The media keys a\n * remote or a keyboard sends do the same: play and pause, Stop pauses,\n * fast forward and rewind seek by `seek-step`. A seeking key fires\n * `seekkey` on the player first, which a seek bar may take to aim instead.\n * The bar is the one owner of the keys that work anywhere in the player:\n * it listens last, so the focused control, and a spatial navigation in\n * the capture phase, decide before it. Space is left to a\n * focused button, which is its own. A key another handler prevented is\n * left alone. A click on the video toggles play.\n * Fullscreen goes on the player itself, so the bar comes along.\n *\n * A narrow bar collapses the buttons row by `priority`: each child carries\n * a number, its own attribute or the default for its tag, and the bar\n * marks the highest numbers `collapsed` one at a time until the row fits\n * with a little slack, from the right among equals. Zero, the default for\n * anything unlisted, never collapses: play and fullscreen stay whatever\n * the width. The mark is an attribute and the hiding is one `::slotted`\n * rule here, so a page styles or overrides it by the tag. The volume's\n * slider is a candidate of its own, and counts at its unfolded width, so\n * the row is sized for what the pointer will make of it.\n */\n\nimport type { CueLift } from '../controls/cues.js';\nimport { cueLift, cueStyle } from '../controls/cues.js';\nimport type { Fullscreen } from '../controls/fullscreen.js';\nimport { fullscreen } from '../controls/fullscreen.js';\nimport type { PlayerHost } from '../host.js';\nimport {\n AIRPLAY_BUTTON,\n AUDIO_MENU,\n CHAPTERS_MENU,\n DRM_BADGE,\n MUTE_BUTTON,\n PIP_BUTTON,\n QUALITY_MENU,\n SCAN_BUTTON,\n SKIP_BUTTON,\n SPACER,\n SPEED_MENU,\n SUBTITLES_MENU,\n VIDEO_MENU,\n VOLUME,\n VOLUME_SLIDER,\n} from '../tags.js';\nimport { Component } from './component.js';\nimport STYLE from './control-bar.css?inline';\nimport { number, shownPaused, style } from './shared.js';\n\nconst IDLE_MS = 3000;\nconst SEEK_STEP = 5;\n\n/**\n * What goes first when the row is too narrow, by tag: the scans, which\n * suit a TV remote more than a small screen; then the slider, which takes\n * the most room for the least; then the diagnostics, the lock and the\n * menus a viewer rarely opens; then the menus for the picture and the\n * sound; then the skips; then the mute, the subtitles and the video\n * menu. The subtitles and video menus go last of the menus because a\n * viewer may need them: the video menu holds the sign-language version.\n * The diagnostics is another package's, named here as a string. A\n * `priority` attribute on the control replaces its default.\n */\nconst PRIORITY: Readonly<Record<string, number>> = {\n [SCAN_BUTTON]: 6,\n [VOLUME_SLIDER]: 5,\n 'mbx-diagnostics': 4,\n [DRM_BADGE]: 4,\n [SPEED_MENU]: 4,\n [CHAPTERS_MENU]: 4,\n [AUDIO_MENU]: 3,\n [QUALITY_MENU]: 3,\n [PIP_BUTTON]: 3,\n [AIRPLAY_BUTTON]: 2,\n [SKIP_BUTTON]: 2,\n [SUBTITLES_MENU]: 1,\n [VIDEO_MENU]: 1,\n [VOLUME]: 1,\n [MUTE_BUTTON]: 1,\n};\n\n/** The width the volume group unfolds its slider to, in em, from volume.css: what a folded slider is counted at. */\nconst SLIDER_WIDTH = 5;\n\n/** Room kept between the last button and the edge, in em, so nothing sits flush against it. */\nconst SLACK = 0.5;\n\ninterface Candidate {\n readonly node: Element;\n /** The bar child it sits in, for the order among equals. */\n readonly index: number;\n readonly priority: number;\n}\n\nfunction shown(node: Element): boolean {\n return node.getClientRects().length > 0;\n}\n\n/** The slider inside a volume group child, when it has one. */\nfunction slider(child: Element): Element | null {\n return child.localName === VOLUME ? child.querySelector(VOLUME_SLIDER) : null;\n}\n\n/** A child's priority: its attribute, else its tag's default, else zero. */\nfunction priority(child: Element): number {\n const own = child.getAttribute('priority');\n if (own !== null) {\n const value = Number(own);\n return Number.isFinite(value) && value > 0 ? value : 0;\n }\n return PRIORITY[child.localName] ?? 0;\n}\n\nfunction end(video: HTMLVideoElement): number {\n if (Number.isFinite(video.duration)) return video.duration;\n const ranges = video.seekable;\n return ranges.length > 0 ? ranges.end(ranges.length - 1) : video.currentTime;\n}\n\nfunction toggle(video: HTMLVideoElement): void {\n if (video.paused) video.play().catch(() => undefined);\n else video.pause();\n}\n\nexport class MbxControlBar extends Component {\n static get observedAttributes(): readonly string[] {\n return ['idle-ms', 'seek-step'];\n }\n\n declare private readonly seekRow: HTMLDivElement;\n declare private readonly buttonsRow: HTMLDivElement;\n declare private readonly buttons: HTMLSlotElement;\n declare private timer: ReturnType<typeof setTimeout> | undefined;\n /** Fires on a width change of the buttons row, so the collapse follows the page's layout. */\n declare private resizer: ResizeObserver | null;\n /** Whether the last input was a key, so focus inside holds the bar. */\n declare private keyboard: boolean;\n declare private cues: CueLift | null;\n declare private screen: Fullscreen | null;\n\n constructor() {\n super();\n this.timer = undefined;\n this.keyboard = false;\n this.cues = null;\n this.screen = null;\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.seekRow = document.createElement('div');\n this.seekRow.setAttribute('part', 'row seek-row');\n const seek = document.createElement('slot');\n seek.name = 'seek';\n this.seekRow.append(seek);\n this.buttonsRow = document.createElement('div');\n this.buttonsRow.setAttribute('part', 'row buttons-row');\n this.buttons = document.createElement('slot');\n this.buttonsRow.append(this.buttons);\n root.append(style(STYLE), this.seekRow, this.buttonsRow);\n }\n\n /**\n * What the buttons need: their widths and their margins, which are the\n * gaps between them, the spacer aside since it takes what is left, and a\n * folded slider at the width it unfolds to. The row's own width says nothing, because the\n * spacer fills it whatever the buttons take.\n */\n /** The bar's em in pixels: its sizes follow the player's font size. */\n private em(): number {\n return Number.parseFloat(getComputedStyle(this).fontSize) || 16;\n }\n\n private needed(children: readonly Element[]): number {\n let sum = 0;\n for (const child of children) {\n if (child.localName === SPACER || !shown(child)) continue;\n const margins = getComputedStyle(child);\n sum += child.getBoundingClientRect().width;\n sum += Number.parseFloat(margins.marginLeft) + Number.parseFloat(margins.marginRight);\n const folded = slider(child);\n if (folded !== null && shown(folded)) {\n sum += Math.max(0, SLIDER_WIDTH * this.em() - folded.getBoundingClientRect().width);\n }\n }\n return sum;\n }\n\n /**\n * Collapses the buttons row to its width. Everything is shown first, so\n * a wider bar gets its controls back, then the highest priorities go one\n * at a time while the buttons need more than the row has, less the\n * slack. Each step lays the row out again; a bar carries a dozen\n * controls, so that is cheap.\n */\n private collapse(): void {\n const children = this.buttons.assignedElements();\n const candidates: Candidate[] = [];\n for (const [index, child] of children.entries()) {\n child.removeAttribute('collapsed');\n const inner = slider(child);\n inner?.removeAttribute('collapsed');\n // A nested slider goes before its group, so it sorts as if it sat\n // after it. What is not shown, by its own `hidden` or a page's rule,\n // takes no room, so marking it would hide nothing and say something\n // false.\n if (inner !== null && shown(inner)) {\n candidates.push({ node: inner, index: index + 0.5, priority: priority(inner) });\n }\n if (shown(child)) candidates.push({ node: child, index, priority: priority(child) });\n }\n candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);\n const room = this.buttonsRow.clientWidth - SLACK * this.em();\n for (const { node, priority: level } of candidates) {\n if (level === 0) return;\n if (this.needed(children) <= room) return;\n node.setAttribute('collapsed', '');\n }\n }\n\n /** From the first row's top to the bar's bottom: what the bar covers of the picture. */\n private covered(): { top: number; bottom: number } {\n return {\n top: this.seekRow.getBoundingClientRect().top,\n bottom: this.getBoundingClientRect().bottom,\n };\n }\n\n private held(player: PlayerHost): boolean {\n if (shownPaused(player, ['switching'])) return true;\n if (this.querySelector('[open]') !== null) return true;\n if (!this.keyboard) return false;\n const active = (this.getRootNode() as Document | ShadowRoot).activeElement;\n return active !== null && this.contains(active);\n }\n\n private idle(player: PlayerHost, on: boolean): void {\n if (this.hasAttribute('idle') === on) return;\n this.toggleAttribute('idle', on);\n player.toggleAttribute('idle', on);\n this.cues?.lifted(!on);\n }\n\n private sleep(player: PlayerHost): void {\n this.timer = undefined;\n // A hold is checked again later: a menu closes and a pause ends without\n // an event the bar hears.\n if (this.held(player)) {\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n return;\n }\n this.idle(player, true);\n }\n\n private wake(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.idle(player, false);\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n }\n\n /**\n * A seeking key: `seekkey` on the player first, cancellable, with the\n * seconds in `detail.by`. A seek bar under `key-mode=\"preview\"` takes it\n * to aim instead. Nobody took it: the playhead moves now.\n */\n private seekBy(player: PlayerHost, by: number): void {\n const asked = new CustomEvent('seekkey', { detail: { by }, cancelable: true });\n if (!player.dispatchEvent(asked)) return;\n const video = player.video;\n video.currentTime = Math.min(end(video), Math.max(0, video.currentTime + by));\n }\n\n private key(player: PlayerHost, event: KeyboardEvent): void {\n this.keyboard = true;\n this.wake(player);\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const video = player.video;\n const onButton = event.composedPath()[0] instanceof HTMLButtonElement;\n switch (event.key) {\n case ' ':\n if (onButton) return;\n toggle(video);\n break;\n case 'k':\n case 'K':\n toggle(video);\n break;\n case 'm':\n case 'M':\n video.muted = !video.muted;\n break;\n case 'f':\n case 'F':\n this.screen?.toggle();\n break;\n // The media keys, which remotes and many keyboards send. UI Events\n // KeyboardEvent key values, Multimedia keys.\n case 'MediaPlayPause':\n toggle(video);\n break;\n case 'MediaPlay':\n void video.play().catch(() => undefined);\n break;\n // Stop pauses: the source stays, as a viewer expects on a remote.\n case 'MediaPause':\n case 'MediaStop':\n video.pause();\n break;\n case 'ArrowLeft':\n case 'MediaRewind':\n this.seekBy(player, -number(this, 'seek-step', SEEK_STEP));\n break;\n case 'ArrowRight':\n case 'MediaFastForward':\n this.seekBy(player, number(this, 'seek-step', SEEK_STEP));\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.video;\n cueStyle();\n this.cues = cueLift(video, player, () => this.covered());\n const screen = fullscreen(player, video);\n this.screen = screen;\n const reflect = (): void => {\n player.toggleAttribute('fullscreen', screen.active());\n };\n this.keep(screen.watch(reflect));\n reflect();\n // `menu` while one of the bar's menus is open, by its `open` attribute:\n // the bar then stacks above the screens and hides its tooltips.\n const menus = new MutationObserver(() => {\n this.toggleAttribute('menu', this.querySelector('[open]') !== null);\n });\n menus.observe(this, { subtree: true, attributes: true, attributeFilter: ['open'] });\n this.keep(() => {\n menus.disconnect();\n this.removeAttribute('menu');\n });\n\n const pointer = (): void => {\n this.keyboard = false;\n this.wake(player);\n };\n const key = (event: Event): void => {\n this.key(player, event as KeyboardEvent);\n };\n const click = (event: Event): void => {\n // The video and nothing else: a control handles its own click.\n if (event.composedPath()[0] === video) toggle(video);\n };\n this.listen(player, ['pointermove', 'pointerdown'], pointer);\n player.addEventListener('keydown', key);\n player.addEventListener('click', click);\n this.keep(() => {\n player.removeEventListener('keydown', key);\n player.removeEventListener('click', click);\n });\n this.listen(video, ['play', 'pause', 'ended'], () => {\n // The load of a switch pauses and plays the video, and the viewer did neither.\n if (!player.hasAttribute('switching')) this.wake(player);\n });\n this.wake(player);\n this.cues.lifted(true);\n\n // The row's width, its children, and what they hide or reprioritise on\n // their own: each can change what fits. `collapsed` is left out of the\n // filter, since the bar writes it.\n const collapse = (): void => {\n this.collapse();\n };\n this.listen(this.buttons, ['slotchange'], collapse);\n this.observe(this, ['hidden', 'priority', 'slot'], collapse, true);\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(collapse);\n this.resizer.observe(this.buttonsRow);\n }\n collapse();\n }\n\n protected override detach(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.timer = undefined;\n this.resizer?.disconnect();\n this.resizer = null;\n for (const child of this.buttons.assignedElements()) {\n child.removeAttribute('collapsed');\n slider(child)?.removeAttribute('collapsed');\n }\n this.cues?.dispose();\n this.cues = null;\n this.screen = null;\n this.removeAttribute('idle');\n player.removeAttribute('idle');\n player.removeAttribute('fullscreen');\n }\n}\n"],"mappings":";;;;;;AAiEA,MAAA,QAAA;AAGA,MAAA,UAAA;AACA,MAAA,YAAA;;;;;;;;;;;;AAaA,MAAA,WAAA;EACA,cAAA;EACA,gBAAA;CACA,mBAAA;EACA,YAAA;EACA,aAAA;EACA,gBAAA;EACA,aAAA;EACA,eAAA;EACA,aAAA;EACA,iBAAA;EACA,cAAA;EACA,iBAAA;EACA,aAAA;EACA,SAAA;EACA,cAAA;AACA;;AAGA,MAAA,eAAA;;AAGA,MAAA,QAAA;AASA,SAAA,MAAA,MAAA;CACA,OAAA,KAAA,eAAA,CAAA,CAAA,SAAA;AACA;;AAGA,SAAA,OAAA,OAAA;CACA,OAAA,MAAA,cAAA,eAAA,MAAA,cAAA,aAAA,IAAA;AACA;;AAGA,SAAA,SAAA,OAAA;CACA,MAAA,MAAA,MAAA,aAAA,UAAA;CACA,IAAA,QAAA,MAAA;EACA,MAAA,QAAA,OAAA,GAAA;EACA,OAAA,OAAA,SAAA,KAAA,KAAA,QAAA,IAAA,QAAA;CACA;CACA,OAAA,SAAA,MAAA,cAAA;AACA;AAEA,SAAA,IAAA,OAAA;CACA,IAAA,OAAA,SAAA,MAAA,QAAA,GAAA,OAAA,MAAA;CACA,MAAA,SAAA,MAAA;CACA,OAAA,OAAA,SAAA,IAA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KAAA,KAAA,MAAA;EACA,KAAA,KAAA,OAAA,IAAA;EAKA,MAAA,iBAAA;GACA,KAAA,SAAA;EACA;EACA,KAAA,OAAA,KAAA,SAAA,CAAA,YAAA,GAAA,QAAA;EACA,KAAA,QAAA,MAAA;GAAA;GAAA;GAAA;EAAA,GAAA,UAAA,IAAA;EACA,IAAA,OAAA,mBAAA,aAAA;GACA,KAAA,UAAA,IAAA,eAAA,QAAA;GACA,KAAA,QAAA,QAAA,KAAA,UAAA;EACA;EACA,SAAA;CACA;CAEA,OAAA,QAAA;EACA,aAAA,KAAA,KAAA;EACA,KAAA,QAAA,KAAA;EACA,KAAA,SAAA,WAAA;EACA,KAAA,UAAA;EACA,KAAA,MAAA,SAAA,KAAA,QAAA,iBAAA,GAAA;GACA,MAAA,gBAAA,WAAA;GACA,OAAA,KAAA,CAAA,EAAA,gBAAA,WAAA;EACA;EACA,KAAA,MAAA,QAAA;EACA,KAAA,OAAA;EACA,KAAA,SAAA;EACA,KAAA,gBAAA,MAAA;EACA,OAAA,gBAAA,MAAA;EACA,OAAA,gBAAA,YAAA;CACA;AACA"}
1
+ {"version":3,"file":"control-bar.js","names":[],"sources":["../../src/elements/control-bar.ts"],"sourcesContent":["/**\n * <mbx-control-bar>: an overlay over the bottom of the video that lays its\n * children out in two rows, the seek row over the buttons row. A child\n * with `slot=\"seek\"` sits in the seek row; everything else in the buttons\n * row, in its order, and an <mbx-spacer> pushes what follows to the right.\n *\n * The bar owns what no one control can: the idle fade, the shortcuts, the\n * click on the video, and the subtitles lifted above it. It sets `idle` on\n * itself and on the player while it hides.\n *\n * The fade is one timer. Any activity, a pointer moving or pressing, a\n * key, playback starting, re-arms it for `idle-ms`, and when it fires the\n * bar hides unless something it can know for certain holds it: the video\n * is paused, a descendant carries `open`, or keyboard focus is inside it,\n * where keyboard means the last input was a key and not a pointer.\n * Whether the pointer is over the player is never tracked: that goes\n * stale when the pointer leaves without a move the player sees.\n *\n * The shortcuts listen on the player, so they hear every key pressed\n * inside it, and only there: Space and `k` toggle play, `m` mutes, `f`\n * toggles fullscreen, the arrows seek by `seek-step`. The media keys a\n * remote or a keyboard sends do the same: play and pause, Stop pauses,\n * fast forward and rewind seek by `seek-step`. A seeking key fires\n * `seekkey` on the player first, which a seek bar may take to aim instead.\n * The bar is the one owner of the keys that work anywhere in the player:\n * it listens last, so the focused control, and a spatial navigation in\n * the capture phase, decide before it. Space is left to a\n * focused button, which is its own. A key another handler prevented is\n * left alone. A click on the video toggles play.\n * Fullscreen goes on the player itself, so the bar comes along.\n *\n * A narrow bar collapses the buttons row by `priority`: each child carries\n * a number, its own attribute or the default for its tag, and the bar\n * marks the highest numbers `collapsed` one at a time until the row fits\n * with a little slack, from the right among equals. Zero, the default for\n * anything unlisted, never collapses: play and fullscreen stay whatever\n * the width. The mark is an attribute and the hiding is one `::slotted`\n * rule here, so a page styles or overrides it by the tag. The volume's\n * slider is a candidate of its own, and counts at its unfolded width, so\n * the row is sized for what the pointer will make of it.\n */\n\nimport type { CueLift } from '../controls/cues.js';\nimport { cueLift, cueStyle } from '../controls/cues.js';\nimport type { Fullscreen } from '../controls/fullscreen.js';\nimport { fullscreen } from '../controls/fullscreen.js';\nimport type { PlayerHost } from '../host.js';\nimport { videoOf } from '../host.js';\nimport {\n AIRPLAY_BUTTON,\n AUDIO_MENU,\n CHAPTERS_MENU,\n DRM_BADGE,\n MUTE_BUTTON,\n PIP_BUTTON,\n QUALITY_MENU,\n SCAN_BUTTON,\n SKIP_BUTTON,\n SPACER,\n SPEED_MENU,\n SUBTITLES_MENU,\n VIDEO_MENU,\n VOLUME,\n VOLUME_SLIDER,\n} from '../tags.js';\nimport { Component } from './component.js';\nimport STYLE from './control-bar.css?inline';\nimport { number, shownPaused, style } from './shared.js';\n\nconst IDLE_MS = 3000;\nconst SEEK_STEP = 5;\n\n/**\n * What goes first when the row is too narrow, by tag: the scans, which\n * suit a TV remote more than a small screen; then the slider, which takes\n * the most room for the least; then the diagnostics, the lock and the\n * menus a viewer rarely opens; then the menus for the picture and the\n * sound; then the skips; then the mute, the subtitles and the video\n * menu. The subtitles and video menus go last of the menus because a\n * viewer may need them: the video menu holds the sign-language version.\n * The diagnostics is another package's, named here as a string. A\n * `priority` attribute on the control replaces its default.\n */\nconst PRIORITY: Readonly<Record<string, number>> = {\n [SCAN_BUTTON]: 6,\n [VOLUME_SLIDER]: 5,\n 'mbx-diagnostics': 4,\n [DRM_BADGE]: 4,\n [SPEED_MENU]: 4,\n [CHAPTERS_MENU]: 4,\n [AUDIO_MENU]: 3,\n [QUALITY_MENU]: 3,\n [PIP_BUTTON]: 3,\n [AIRPLAY_BUTTON]: 2,\n [SKIP_BUTTON]: 2,\n [SUBTITLES_MENU]: 1,\n [VIDEO_MENU]: 1,\n [VOLUME]: 1,\n [MUTE_BUTTON]: 1,\n};\n\n/** The width the volume group unfolds its slider to, in em, from volume.css: what a folded slider is counted at. */\nconst SLIDER_WIDTH = 5;\n\n/** Room kept between the last button and the edge, in em, so nothing sits flush against it. */\nconst SLACK = 0.5;\n\ninterface Candidate {\n readonly node: Element;\n /** The bar child it sits in, for the order among equals. */\n readonly index: number;\n readonly priority: number;\n}\n\nfunction shown(node: Element): boolean {\n return node.getClientRects().length > 0;\n}\n\n/** The slider inside a volume group child, when it has one. */\nfunction slider(child: Element): Element | null {\n return child.localName === VOLUME ? child.querySelector(VOLUME_SLIDER) : null;\n}\n\n/** A child's priority: its attribute, else its tag's default, else zero. */\nfunction priority(child: Element): number {\n const own = child.getAttribute('priority');\n if (own !== null) {\n const value = Number(own);\n return Number.isFinite(value) && value > 0 ? value : 0;\n }\n return PRIORITY[child.localName] ?? 0;\n}\n\nfunction end(video: HTMLVideoElement): number {\n if (Number.isFinite(video.duration)) return video.duration;\n const ranges = video.seekable;\n return ranges.length > 0 ? ranges.end(ranges.length - 1) : video.currentTime;\n}\n\nfunction toggle(video: HTMLVideoElement): void {\n if (video.paused) video.play().catch(() => undefined);\n else video.pause();\n}\n\nexport class MbxControlBar extends Component {\n static get observedAttributes(): readonly string[] {\n return ['idle-ms', 'seek-step'];\n }\n\n declare private readonly seekRow: HTMLDivElement;\n declare private readonly buttonsRow: HTMLDivElement;\n declare private readonly buttons: HTMLSlotElement;\n declare private timer: ReturnType<typeof setTimeout> | undefined;\n /** Fires on a width change of the buttons row, so the collapse follows the page's layout. */\n declare private resizer: ResizeObserver | null;\n /** Whether the last input was a key, so focus inside holds the bar. */\n declare private keyboard: boolean;\n declare private cues: CueLift | null;\n declare private screen: Fullscreen | null;\n\n constructor() {\n super();\n this.timer = undefined;\n this.keyboard = false;\n this.cues = null;\n this.screen = null;\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.seekRow = document.createElement('div');\n this.seekRow.setAttribute('part', 'row seek-row');\n const seek = document.createElement('slot');\n seek.name = 'seek';\n this.seekRow.append(seek);\n this.buttonsRow = document.createElement('div');\n this.buttonsRow.setAttribute('part', 'row buttons-row');\n this.buttons = document.createElement('slot');\n this.buttonsRow.append(this.buttons);\n root.append(style(STYLE), this.seekRow, this.buttonsRow);\n }\n\n /**\n * What the buttons need: their widths and their margins, which are the\n * gaps between them, the spacer aside since it takes what is left, and a\n * folded slider at the width it unfolds to. The row's own width says nothing, because the\n * spacer fills it whatever the buttons take.\n */\n /** The bar's em in pixels: its sizes follow the player's font size. */\n private em(): number {\n return Number.parseFloat(getComputedStyle(this).fontSize) || 16;\n }\n\n private needed(children: readonly Element[]): number {\n let sum = 0;\n for (const child of children) {\n if (child.localName === SPACER || !shown(child)) continue;\n const margins = getComputedStyle(child);\n sum += child.getBoundingClientRect().width;\n sum += Number.parseFloat(margins.marginLeft) + Number.parseFloat(margins.marginRight);\n const folded = slider(child);\n if (folded !== null && shown(folded)) {\n sum += Math.max(0, SLIDER_WIDTH * this.em() - folded.getBoundingClientRect().width);\n }\n }\n return sum;\n }\n\n /**\n * Collapses the buttons row to its width. Everything is shown first, so\n * a wider bar gets its controls back, then the highest priorities go one\n * at a time while the buttons need more than the row has, less the\n * slack. Each step lays the row out again; a bar carries a dozen\n * controls, so that is cheap.\n */\n private collapse(): void {\n const children = this.buttons.assignedElements();\n const candidates: Candidate[] = [];\n for (const [index, child] of children.entries()) {\n child.removeAttribute('collapsed');\n const inner = slider(child);\n inner?.removeAttribute('collapsed');\n // A nested slider goes before its group, so it sorts as if it sat\n // after it. What is not shown, by its own `hidden` or a page's rule,\n // takes no room, so marking it would hide nothing and say something\n // false.\n if (inner !== null && shown(inner)) {\n candidates.push({ node: inner, index: index + 0.5, priority: priority(inner) });\n }\n if (shown(child)) candidates.push({ node: child, index, priority: priority(child) });\n }\n candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);\n const room = this.buttonsRow.clientWidth - SLACK * this.em();\n for (const { node, priority: level } of candidates) {\n if (level === 0) return;\n if (this.needed(children) <= room) return;\n node.setAttribute('collapsed', '');\n }\n }\n\n /** From the first row's top to the bar's bottom: what the bar covers of the picture. */\n private covered(): { top: number; bottom: number } {\n return {\n top: this.seekRow.getBoundingClientRect().top,\n bottom: this.getBoundingClientRect().bottom,\n };\n }\n\n private held(player: PlayerHost): boolean {\n if (shownPaused(player, ['switching'])) return true;\n if (this.querySelector('[open]') !== null) return true;\n if (!this.keyboard) return false;\n const active = (this.getRootNode() as Document | ShadowRoot).activeElement;\n return active !== null && this.contains(active);\n }\n\n private idle(player: PlayerHost, on: boolean): void {\n if (this.hasAttribute('idle') === on) return;\n this.toggleAttribute('idle', on);\n player.toggleAttribute('idle', on);\n this.cues?.lifted(!on);\n }\n\n private sleep(player: PlayerHost): void {\n this.timer = undefined;\n // A hold is checked again later: a menu closes and a pause ends without\n // an event the bar hears.\n if (this.held(player)) {\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n return;\n }\n this.idle(player, true);\n }\n\n private wake(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.idle(player, false);\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n }\n\n /**\n * A seeking key: `seekkey` on the player first, cancellable, with the\n * seconds in `detail.by`. A seek bar under `key-mode=\"preview\"` takes it\n * to aim instead. Nobody took it: the playhead moves now.\n */\n private seekBy(player: PlayerHost, by: number): void {\n const asked = new CustomEvent('seekkey', { detail: { by }, cancelable: true });\n if (!player.dispatchEvent(asked)) return;\n const video = player.media;\n video.currentTime = Math.min(end(video), Math.max(0, video.currentTime + by));\n }\n\n private key(player: PlayerHost, event: KeyboardEvent): void {\n this.keyboard = true;\n this.wake(player);\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const video = player.media;\n const onButton = event.composedPath()[0] instanceof HTMLButtonElement;\n switch (event.key) {\n case ' ':\n if (onButton) return;\n toggle(video);\n break;\n case 'k':\n case 'K':\n toggle(video);\n break;\n case 'm':\n case 'M':\n video.muted = !video.muted;\n break;\n case 'f':\n case 'F':\n this.screen?.toggle();\n break;\n // The media keys, which remotes and many keyboards send. UI Events\n // KeyboardEvent key values, Multimedia keys.\n case 'MediaPlayPause':\n toggle(video);\n break;\n case 'MediaPlay':\n void video.play().catch(() => undefined);\n break;\n // Stop pauses: the source stays, as a viewer expects on a remote.\n case 'MediaPause':\n case 'MediaStop':\n video.pause();\n break;\n case 'ArrowLeft':\n case 'MediaRewind':\n this.seekBy(player, -number(this, 'seek-step', SEEK_STEP));\n break;\n case 'ArrowRight':\n case 'MediaFastForward':\n this.seekBy(player, number(this, 'seek-step', SEEK_STEP));\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.media;\n cueStyle();\n this.cues = cueLift(video, player, () => this.covered());\n const screen = fullscreen(player, video);\n this.screen = screen;\n const reflect = (): void => {\n player.toggleAttribute('fullscreen', screen.active());\n };\n this.keep(screen.watch(reflect));\n reflect();\n // `menu` while one of the bar's menus is open, by its `open` attribute:\n // the bar then stacks above the screens and hides its tooltips.\n const menus = new MutationObserver(() => {\n this.toggleAttribute('menu', this.querySelector('[open]') !== null);\n });\n menus.observe(this, { subtree: true, attributes: true, attributeFilter: ['open'] });\n this.keep(() => {\n menus.disconnect();\n this.removeAttribute('menu');\n });\n\n const pointer = (): void => {\n this.keyboard = false;\n this.wake(player);\n };\n const key = (event: Event): void => {\n this.key(player, event as KeyboardEvent);\n };\n const click = (event: Event): void => {\n // The video and nothing else: a control handles its own click.\n if (event.composedPath()[0] === videoOf(player)) toggle(video);\n };\n this.listen(player, ['pointermove', 'pointerdown'], pointer);\n player.addEventListener('keydown', key);\n player.addEventListener('click', click);\n this.keep(() => {\n player.removeEventListener('keydown', key);\n player.removeEventListener('click', click);\n });\n this.listen(video, ['play', 'pause', 'ended'], () => {\n // The load of a switch pauses and plays the video, and the viewer did neither.\n if (!player.hasAttribute('switching')) this.wake(player);\n });\n this.wake(player);\n this.cues.lifted(true);\n\n // The row's width, its children, and what they hide or reprioritise on\n // their own: each can change what fits. `collapsed` is left out of the\n // filter, since the bar writes it.\n const collapse = (): void => {\n this.collapse();\n };\n this.listen(this.buttons, ['slotchange'], collapse);\n this.observe(this, ['hidden', 'priority', 'slot'], collapse, true);\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(collapse);\n this.resizer.observe(this.buttonsRow);\n }\n collapse();\n }\n\n protected override detach(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.timer = undefined;\n this.resizer?.disconnect();\n this.resizer = null;\n for (const child of this.buttons.assignedElements()) {\n child.removeAttribute('collapsed');\n slider(child)?.removeAttribute('collapsed');\n }\n this.cues?.dispose();\n this.cues = null;\n this.screen = null;\n this.removeAttribute('idle');\n player.removeAttribute('idle');\n player.removeAttribute('fullscreen');\n }\n}\n"],"mappings":";;;;;;;AAkEA,MAAA,QAAA;AAGA,MAAM,UAAU;AAChB,MAAM,YAAY;;;;;;;;;;;;AAalB,MAAM,WAA6C;EAChD,cAAc;EACd,gBAAgB;CACjB,mBAAmB;EAClB,YAAY;EACZ,aAAa;EACb,gBAAgB;EAChB,aAAa;EACb,eAAe;EACf,aAAa;EACb,iBAAi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GAC1C,KAAK,QAAQ,QAAQ,KAAK,UAAU;EACtC;EACA,SAAS;CACX;CAEmB,OAAO,QAA0B;EAClD,aAAa,KAAK,KAAK;EACvB,KAAK,QAAQ,KAAA;EACb,KAAK,SAAS,WAAW;EACzB,KAAK,UAAU;EACf,KAAK,MAAM,SAAS,KAAK,QAAQ,iBAAiB,GAAG;GACnD,MAAM,gBAAgB,WAAW;GACjC,OAAO,KAAK,CAAC,EAAE,gBAAgB,WAAW;EAC5C;EACA,KAAK,MAAM,QAAQ;EACnB,KAAK,OAAO;EACZ,KAAK,SAAS;EACd,KAAK,gBAAgB,MAAM;EAC3B,OAAO,gBAAgB,MAAM;EAC7B,OAAO,gBAAgB,YAAY;CACrC;AACF"}
@@ -1,5 +1,5 @@
1
- import { format } from "../controls/time.js";
2
1
  import { live, span, wall } from "../controls/session.js";
2
+ import { format } from "../controls/time.js";
3
3
  import { TimeElement } from "./time-element.js";
4
4
  // src/elements/current-time.ts
5
5
  /**
@@ -14,7 +14,7 @@ var MbxCurrentTime = class extends TimeElement {
14
14
  render() {
15
15
  const player = this.player;
16
16
  if (player === null) return;
17
- const video = player.video;
17
+ const video = player.media;
18
18
  const engine = player.engine;
19
19
  const on = live(engine) !== void 0;
20
20
  const time = video.currentTime;
@@ -1 +1 @@
1
- {"version":3,"file":"current-time.js","names":[],"sources":["../../src/elements/current-time.ts"],"sourcesContent":["/**\n * <mbx-current-time>: the position, \"1:23\". On a live stream it reads the\n * wall clock when `engine.pdt` can say it, \"14:23:05\", which is what a\n * viewer of a broadcast wants to know, and the distance behind the edge\n * otherwise, \"-0:10\". While the player says the stream is live but not\n * seekable, which the seek bar decides, there is no position to show and\n * the element hides.\n */\nimport { live, span, wall } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\n\nexport class MbxCurrentTime extends TimeElement {\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const video = player.video;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n const time = video.currentTime;\n this.text.data = on\n ? (wall(engine, time) ?? `-${format(span(video, engine).end - time)}`)\n : format(time);\n // A compact player keeps one readout, the time left, which the duration shows.\n this.hidden =\n (on && player.hasAttribute('live') && !player.hasAttribute('seekable')) ||\n (!on && this.getAttribute('layout') === 'compact');\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,YAAY;CAC9C,SAAkC;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,MAAM,QAAQ,OAAO;EACrB,MAAM,SAAS,OAAO;EACtB,MAAM,KAAK,KAAK,MAAM,MAAM,KAAA;EAC5B,MAAM,OAAO,MAAM;EACnB,KAAK,KAAK,OAAO,KACZ,KAAK,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,OAAO,MAAM,CAAC,CAAC,MAAM,IAAI,MAChE,OAAO,IAAI;EAEf,KAAK,SACF,MAAM,OAAO,aAAa,MAAM,KAAK,CAAC,OAAO,aAAa,UAAU,KACpE,CAAC,MAAM,KAAK,aAAa,QAAQ,MAAM;CAC5C;AACF"}
1
+ {"version":3,"file":"current-time.js","names":[],"sources":["../../src/elements/current-time.ts"],"sourcesContent":["/**\n * <mbx-current-time>: the position, \"1:23\". On a live stream it reads the\n * wall clock when `engine.pdt` can say it, \"14:23:05\", which is what a\n * viewer of a broadcast wants to know, and the distance behind the edge\n * otherwise, \"-0:10\". While the player says the stream is live but not\n * seekable, which the seek bar decides, there is no position to show and\n * the element hides.\n */\nimport { live, span, wall } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\n\nexport class MbxCurrentTime extends TimeElement {\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const video = player.media;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n const time = video.currentTime;\n this.text.data = on\n ? (wall(engine, time) ?? `-${format(span(video, engine).end - time)}`)\n : format(time);\n // A compact player keeps one readout, the time left, which the duration shows.\n this.hidden =\n (on && player.hasAttribute('live') && !player.hasAttribute('seekable')) ||\n (!on && this.getAttribute('layout') === 'compact');\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,YAAY;CAC3B,SAAe;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,MAAM,QAAQ,OAAO;EACrB,MAAM,SAAS,OAAO;EACtB,MAAM,KAAK,KAAK,MAAM,MAAM,KAAA;EAC5B,MAAM,OAAO,MAAM;EACnB,KAAK,KAAK,OAAO,KACZ,KAAK,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,OAAO,MAAM,CAAC,CAAC,MAAM,IAAI,MAChE,OAAO,IAAI;EAEf,KAAK,SACF,MAAM,OAAO,aAAa,MAAM,KAAK,CAAC,OAAO,aAAa,UAAU,KACpE,CAAC,MAAM,KAAK,aAAa,QAAQ,MAAM;CAC5C;AACF"}
@@ -1,7 +1,7 @@
1
+ import { icon } from "../controls/icons.js";
1
2
  import { el } from "../dom.js";
2
3
  import { fill } from "../labels.js";
3
4
  import { namespaces } from "../namespaces.js";
4
- import { icon } from "../controls/icons.js";
5
5
  import { Component } from "./component.js";
6
6
  import { style } from "./shared.js";
7
7
  // src/elements/drm-badge.ts
@@ -1 +1 @@
1
- {"version":3,"file":"drm-badge.js","names":[],"sources":["../../src/elements/drm-badge.ts"],"sourcesContent":["/**\n * <mbx-drm-badge>: a lock over `engine.drm`, or over `session.eme.drm`\n * for a native session that attached DRM, hidden until a key system is\n * known and for a session without the EME stages. Hover or focus shows\n * what it knows: the key system, and the key sessions with their\n * statuses. The glyph is `icon`; the name comes from `label`, where\n * `{system}` is the key system's name and `{keys}` the sessions:\n * \"Protected by {system}, {keys}\". The sessions read from `label-keys`\n * with `{count}` and `{statuses}`, `label-key` for one, `label-no-key`\n * for none.\n */\n\nimport type { DrmApi } from 'mattebox/eme';\nimport { icon } from '../controls/icons.js';\nimport { el } from '../dom.js';\nimport type { PlayerHost } from '../host.js';\nimport { fill } from '../labels.js';\nimport { namespaces } from '../namespaces.js';\nimport { Component } from './component.js';\nimport STYLE from './drm-badge.css?inline';\nimport { style } from './shared.js';\n\n/** The name a viewer knows a key system by. */\nfunction keySystemName(id: string): string {\n if (id.startsWith('com.widevine')) return 'Widevine';\n if (id.startsWith('com.microsoft.playready')) return 'PlayReady';\n if (id.startsWith('com.apple.fps')) return 'FairPlay';\n return id;\n}\n\nexport class MbxDrmBadge extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-key', 'label-keys', 'label-no-key'];\n }\n\n declare private readonly tooltip: HTMLElement;\n declare private readonly system: HTMLElement;\n declare private readonly system_id: HTMLElement;\n declare private readonly keys: HTMLElement;\n declare private drm: DrmApi | undefined;\n\n constructor() {\n super();\n this.drm = undefined;\n const root = this.attachShadow({ mode: 'open' });\n const slot = document.createElement('slot');\n slot.name = 'icon';\n slot.append(icon('lock-closed'));\n this.tooltip = el('div', 'tooltip');\n this.tooltip.setAttribute('role', 'tooltip');\n this.system = el('div', 'tooltip-title');\n this.system_id = el('div', 'tooltip-text');\n this.keys = el('div', 'tooltip-text');\n this.tooltip.append(this.system, this.system_id, this.keys);\n this.tooltip.hidden = true;\n root.append(style(STYLE), slot, this.tooltip);\n const show = (): void => {\n this.tooltip.hidden = false;\n };\n const hide = (): void => {\n this.tooltip.hidden = true;\n };\n this.addEventListener('pointerenter', show);\n this.addEventListener('pointerleave', hide);\n this.addEventListener('focus', show);\n this.addEventListener('blur', hide);\n }\n\n /** Named and focusable before attaching: a constructor must not add attributes. */\n override connectedCallback(): void {\n if (!this.hasAttribute('role')) this.setAttribute('role', 'img');\n if (!this.hasAttribute('tabindex')) this.tabIndex = 0;\n if (this.player === null) this.hidden = true;\n super.connectedCallback();\n }\n\n /** \"3 keys: usable ×2, expired\", or \"no key yet\". */\n private sessionsText(sessions: ReadonlyArray<{ readonly status: string }>): string {\n if (sessions.length === 0) return this.word('label-no-key', 'drmNoKey', 'no key yet');\n const counts = new Map<string, number>();\n for (const session of sessions) {\n counts.set(session.status, (counts.get(session.status) ?? 0) + 1);\n }\n const parts: string[] = [];\n for (const [status, count] of counts) parts.push(count > 1 ? `${status} ×${count}` : status);\n const template =\n sessions.length === 1\n ? this.word('label-key', 'drmKey', '{count} key: {statuses}')\n : this.word('label-keys', 'drmKeys', '{count} keys: {statuses}');\n return fill(template, { count: sessions.length, statuses: parts.join(', ') });\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n // The engine's DRM, or the attachment a native session made: one API, the same events.\n const eme = player.player?.session?.eme;\n const source = engine ?? eme;\n this.drm = engine === null ? eme?.drm : namespaces(engine).drm;\n this.render();\n if (source === undefined || this.drm === undefined) return undefined;\n const tick = (): void => {\n this.render();\n };\n const offs = ['drm:keysystem', 'drm:keystatus', 'drm:encrypted'].map((event) =>\n source.on(event, tick),\n );\n return () => {\n for (const off of offs) off();\n };\n });\n }\n\n protected override detach(): void {\n this.tooltip.hidden = true;\n }\n\n protected override render(): void {\n const drm = this.drm;\n const name = drm?.keySystem ?? null;\n this.hidden = name === null;\n if (drm === undefined || name === null) return;\n const keys = this.sessionsText(drm.sessions);\n const system = keySystemName(name);\n this.system.textContent = system;\n this.system_id.textContent = name;\n this.keys.textContent = keys;\n this.setAttribute(\n 'aria-label',\n fill(this.word('label', 'drmProtected', 'Protected by {system}, {keys}'), { system, keys }),\n );\n }\n}\n"],"mappings":";;;;;;;AAmBA,MAAA,QAAA;;AAIA,SAAA,cAAA,IAAA;CACA,IAAA,GAAA,WAAA,cAAA,GAAA,OAAA;CACA,IAAA,GAAA,WAAA,yBAAA,GAAA,OAAA;CACA,IAAA,GAAA,WAAA,eAAA,GAAA,OAAA;CACA,OAAA;AACA;AAEA,IAAA,cAAA,cAAA,UAAA;CACA,WAAA,qBAAA;EACA,OAAA;GAAA;GAAA;GAAA;GAAA;EAAA;CACA;CAQA,cAAA;EACA,MAAA;EACA,KAAA,MAAA,KAAA;EACA,MAAA,OAAA,KAAA,aAAA,EAAA,MAAA,OA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,WAAA,0BAAA;EACA,OAAA,KAAA,UAAA;GAAA,OAAA,SAAA;GAAA,UAAA,MAAA,KAAA,IAAA;EAAA,CAAA;CACA;CAEA,OAAA,QAAA;EACA,KAAA,OAAA,SAAA,WAAA;GAEA,MAAA,MAAA,OAAA,QAAA,SAAA;GACA,MAAA,SAAA,UAAA;GACA,KAAA,MAAA,WAAA,OAAA,KAAA,MAAA,WAAA,MAAA,CAAA,CAAA;GACA,KAAA,OAAA;GACA,IAAA,WAAA,KAAA,KAAA,KAAA,QAAA,KAAA,GAAA,OAAA,KAAA;GACA,MAAA,aAAA;IACA,KAAA,OAAA;GACA;GACA,MAAA,OAAA;IAAA;IAAA;IAAA;GAAA,CAAA,CAAA,KAAA,UACA,OAAA,GAAA,OAAA,IAAA,CACA;GACA,aAAA;IACA,KAAA,MAAA,OAAA,MAAA,IAAA;GACA;EACA,CAAA;CACA;CAEA,SAAA;EACA,KAAA,QAAA,SAAA;CACA;CAEA,SAAA;EACA,MAAA,MAAA,KAAA;EACA,MAAA,OAAA,KAAA,aAAA;EACA,KAAA,SAAA,SAAA;EACA,IAAA,QAAA,KAAA,KAAA,SAAA,MAAA;EACA,MAAA,OAAA,KAAA,aAAA,IAAA,QAAA;EACA,MAAA,SAAA,cAAA,IAAA;EACA,KAAA,OAAA,cAAA;EACA,KAAA,UAAA,cAAA;EACA,KAAA,KAAA,cAAA;EACA,KAAA,aACA,cACA,KAAA,KAAA,KAAA,SAAA,gBAAA,+BAAA,GAAA;GAAA;GAAA;EAAA,CAAA,CACA;CACA;AACA"}
1
+ {"version":3,"file":"drm-badge.js","names":[],"sources":["../../src/elements/drm-badge.ts"],"sourcesContent":["/**\n * <mbx-drm-badge>: a lock over `engine.drm`, or over `session.eme.drm`\n * for a native session that attached DRM, hidden until a key system is\n * known and for a session without the EME stages. Hover or focus shows\n * what it knows: the key system, and the key sessions with their\n * statuses. The glyph is `icon`; the name comes from `label`, where\n * `{system}` is the key system's name and `{keys}` the sessions:\n * \"Protected by {system}, {keys}\". The sessions read from `label-keys`\n * with `{count}` and `{statuses}`, `label-key` for one, `label-no-key`\n * for none.\n */\n\nimport type { DrmApi } from 'mattebox/eme';\nimport { icon } from '../controls/icons.js';\nimport { el } from '../dom.js';\nimport type { PlayerHost } from '../host.js';\nimport { fill } from '../labels.js';\nimport { namespaces } from '../namespaces.js';\nimport { Component } from './component.js';\nimport STYLE from './drm-badge.css?inline';\nimport { style } from './shared.js';\n\n/** The name a viewer knows a key system by. */\nfunction keySystemName(id: string): string {\n if (id.startsWith('com.widevine')) return 'Widevine';\n if (id.startsWith('com.microsoft.playready')) return 'PlayReady';\n if (id.startsWith('com.apple.fps')) return 'FairPlay';\n return id;\n}\n\nexport class MbxDrmBadge extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-key', 'label-keys', 'label-no-key'];\n }\n\n declare private readonly tooltip: HTMLElement;\n declare private readonly system: HTMLElement;\n declare private readonly system_id: HTMLElement;\n declare private readonly keys: HTMLElement;\n declare private drm: DrmApi | undefined;\n\n constructor() {\n super();\n this.drm = undefined;\n const root = this.attachShadow({ mode: 'open' });\n const slot = document.createElement('slot');\n slot.name = 'icon';\n slot.append(icon('lock-closed'));\n this.tooltip = el('div', 'tooltip');\n this.tooltip.setAttribute('role', 'tooltip');\n this.system = el('div', 'tooltip-title');\n this.system_id = el('div', 'tooltip-text');\n this.keys = el('div', 'tooltip-text');\n this.tooltip.append(this.system, this.system_id, this.keys);\n this.tooltip.hidden = true;\n root.append(style(STYLE), slot, this.tooltip);\n const show = (): void => {\n this.tooltip.hidden = false;\n };\n const hide = (): void => {\n this.tooltip.hidden = true;\n };\n this.addEventListener('pointerenter', show);\n this.addEventListener('pointerleave', hide);\n this.addEventListener('focus', show);\n this.addEventListener('blur', hide);\n }\n\n /** Named and focusable before attaching: a constructor must not add attributes. */\n override connectedCallback(): void {\n if (!this.hasAttribute('role')) this.setAttribute('role', 'img');\n if (!this.hasAttribute('tabindex')) this.tabIndex = 0;\n if (this.player === null) this.hidden = true;\n super.connectedCallback();\n }\n\n /** \"3 keys: usable ×2, expired\", or \"no key yet\". */\n private sessionsText(sessions: ReadonlyArray<{ readonly status: string }>): string {\n if (sessions.length === 0) return this.word('label-no-key', 'drmNoKey', 'no key yet');\n const counts = new Map<string, number>();\n for (const session of sessions) {\n counts.set(session.status, (counts.get(session.status) ?? 0) + 1);\n }\n const parts: string[] = [];\n for (const [status, count] of counts) parts.push(count > 1 ? `${status} ×${count}` : status);\n const template =\n sessions.length === 1\n ? this.word('label-key', 'drmKey', '{count} key: {statuses}')\n : this.word('label-keys', 'drmKeys', '{count} keys: {statuses}');\n return fill(template, { count: sessions.length, statuses: parts.join(', ') });\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n // The engine's DRM, or the attachment a native session made: one API, the same events.\n const eme = player.player?.session?.eme;\n const source = engine ?? eme;\n this.drm = engine === null ? eme?.drm : namespaces(engine).drm;\n this.render();\n if (source === undefined || this.drm === undefined) return undefined;\n const tick = (): void => {\n this.render();\n };\n const offs = ['drm:keysystem', 'drm:keystatus', 'drm:encrypted'].map((event) =>\n source.on(event, tick),\n );\n return () => {\n for (const off of offs) off();\n };\n });\n }\n\n protected override detach(): void {\n this.tooltip.hidden = true;\n }\n\n protected override render(): void {\n const drm = this.drm;\n const name = drm?.keySystem ?? null;\n this.hidden = name === null;\n if (drm === undefined || name === null) return;\n const keys = this.sessionsText(drm.sessions);\n const system = keySystemName(name);\n this.system.textContent = system;\n this.system_id.textContent = name;\n this.keys.textContent = keys;\n this.setAttribute(\n 'aria-label',\n fill(this.word('label', 'drmProtected', 'Protected by {system}, {keys}'), { system, keys }),\n );\n }\n}\n"],"mappings":";;;;;;;AAmBA,MAAA,QAAA;;AAIA,SAAS,cAAc,IAAoB;CACzC,IAAI,GAAG,WAAW,cAAc,GAAG,OAAO;CAC1C,IAAI,GAAG,WAAW,yBAAyB,GAAG,OAAO;CACrD,IAAI,GAAG,WAAW,eAAe,GAAG,OAAO;CA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,KAAK,KAAK,KAAK,SAAS,gBAAgB,+BAA+B,GAAG;GAAE;GAAQ;EAAK,CAAC,CAC5F;CACF;AACF"}
@@ -1,5 +1,5 @@
1
- import { format } from "../controls/time.js";
2
1
  import { live, span } from "../controls/session.js";
2
+ import { format } from "../controls/time.js";
3
3
  import { TimeElement } from "./time-element.js";
4
4
  // src/elements/duration.ts
5
5
  /**
@@ -20,8 +20,8 @@ var MbxDuration = class extends TimeElement {
20
20
  const on = live(engine) !== void 0;
21
21
  this.hidden = on;
22
22
  if (on) return;
23
- const end = span(player.video, engine).end;
24
- this.text.data = this.getAttribute("layout") === "compact" ? `-${format(Math.max(0, end - player.video.currentTime))}` : format(end);
23
+ const end = span(player.media, engine).end;
24
+ this.text.data = this.getAttribute("layout") === "compact" ? `-${format(Math.max(0, end - player.media.currentTime))}` : format(end);
25
25
  }
26
26
  };
27
27
  export { MbxDuration };
@@ -1 +1 @@
1
- {"version":3,"file":"duration.js","names":[],"sources":["../../src/elements/duration.ts"],"sourcesContent":["/**\n * <mbx-duration>: the duration, \"4:56\", once the metadata is in. A live\n * stream has none, so the element hides while the stream is live. On a\n * compact player it shows the time left, \"-3:12\", in place of the current\n * time, which hides there.\n */\nimport { live, span } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\nimport TRAILING from './trailing-time.css?inline';\n\nexport class MbxDuration extends TimeElement {\n constructor() {\n super(TRAILING);\n }\n\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n this.hidden = on;\n if (on) return;\n const end = span(player.video, engine).end;\n // A compact player has one readout, so this one counts down.\n this.text.data =\n this.getAttribute('layout') === 'compact'\n ? `-${format(Math.max(0, end - player.video.currentTime))}`\n : format(end);\n }\n}\n"],"mappings":";;;;;;;;;;AASA,MAAA,WAAA;AAEA,IAAA,cAAA,cAAA,YAAA;CACA,cAAA;EACA,MAAA,QAAA;CACA;CAEA,SAAA;EACA,MAAA,SAAA,KAAA;EACA,IAAA,WAAA,MAAA;EACA,MAAA,SAAA,OAAA;EACA,MAAA,KAAA,KAAA,MAAA,MAAA,KAAA;EACA,KAAA,SAAA;EACA,IAAA,IAAA;EACA,MAAA,MAAA,KAAA,OAAA,OAAA,MAAA,CAAA,CAAA;EAEA,KAAA,KAAA,OACA,KAAA,aAAA,QAAA,MAAA,YACA,IAAA,OAAA,KAAA,IAAA,GAAA,MAAA,OAAA,MAAA,WAAA,CAAA,MACA,OAAA,GAAA;CACA;AACA"}
1
+ {"version":3,"file":"duration.js","names":[],"sources":["../../src/elements/duration.ts"],"sourcesContent":["/**\n * <mbx-duration>: the duration, \"4:56\", once the metadata is in. A live\n * stream has none, so the element hides while the stream is live. On a\n * compact player it shows the time left, \"-3:12\", in place of the current\n * time, which hides there.\n */\nimport { live, span } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\nimport TRAILING from './trailing-time.css?inline';\n\nexport class MbxDuration extends TimeElement {\n constructor() {\n super(TRAILING);\n }\n\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n this.hidden = on;\n if (on) return;\n const end = span(player.media, engine).end;\n // A compact player has one readout, so this one counts down.\n this.text.data =\n this.getAttribute('layout') === 'compact'\n ? `-${format(Math.max(0, end - player.media.currentTime))}`\n : format(end);\n }\n}\n"],"mappings":";;;;;;;;;;AASA,MAAA,WAAA;AAEA,IAAa,cAAb,cAAiC,YAAY;CAC3C,cAAc;EACZ,MAAM,QAAQ;CAChB;CAEmB,SAAe;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,MAAM,SAAS,OAAO;EACtB,MAAM,KAAK,KAAK,MAAM,MAAM,KAAA;EAC5B,KAAK,SAAS;EACd,IAAI,IAAI;EACR,MAAM,MAAM,KAAK,OAAO,OAAO,MAAM,CAAC,CAAC;EAEvC,KAAK,KAAK,OACR,KAAK,aAAa,QAAQ,MAAM,YAC5B,IAAI,OAAO,KAAK,IAAI,GAAG,MAAM,OAAO,MAAM,WAAW,CAAC,MACtD,OAAO,GAAG;CAClB;AACF"}
@@ -68,7 +68,7 @@ var MbxErrorScreen = class extends Component {
68
68
  this.keep(() => {
69
69
  player.removeEventListener("error", failure);
70
70
  });
71
- this.listen(player.video, ["playing", "loadstart"], () => {
71
+ this.listen(player.media, ["playing", "loadstart"], () => {
72
72
  if (this.block === null) this.hidden = true;
73
73
  });
74
74
  this.listen(player, ["sourcechange"], () => {
@@ -1 +1 @@
1
- {"version":3,"file":"error-screen.js","names":[],"sources":["../../src/elements/error-screen.ts"],"sourcesContent":["/**\n * <mbx-error-screen>: a fatal error over the picture, with the category,\n * the code and a retry. It sits in the player beside the video, hidden\n * until the player reports a fatal error, and clears when a session\n * arrives, a resource starts loading, or playback resumes: an error over\n * a picture that then plays is wrong by definition. The title comes from `label-title`, the button's text\n * from `label-retry`.\n *\n * Retry calls the player's `retry()`, which loads the sources again from\n * the first, whether they came from `src`, `sources` or `<source>` children.\n *\n * With an `<mbx-diagnostics>` in the player, a second button opens its\n * panel, so the report of the error can be read and copied. Its text is\n * the diagnostics' own word, or `label-diagnostics`.\n *\n * It also shows the page's `block()`: its title, else `label-blocked`, and\n * its message, with no retry, since a retry cannot lift a block.\n */\nimport type { PlayerError } from '@mattebox/player-core';\nimport { el } from '../dom.js';\nimport type { Block, PlayerHost } from '../host.js';\nimport type { Messages } from '../messages.js';\nimport { Component } from './component.js';\nimport STYLE from './error-screen.css?inline';\n\n/** The diagnostics element, another package's, named here as a string. */\nconst DIAGNOSTICS = 'mbx-diagnostics';\n\nimport { style } from './shared.js';\n\nexport class MbxErrorScreen extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label-title', 'label-retry', 'label-blocked', 'label-diagnostics'];\n }\n\n declare private readonly title_: HTMLElement;\n declare private readonly category: HTMLElement;\n declare private readonly code: HTMLElement;\n declare private readonly detail: HTMLElement;\n declare private readonly message: HTMLElement;\n declare private readonly retry: HTMLButtonElement;\n declare private readonly inspect: HTMLButtonElement;\n /** The block shown, or null for an error. */\n declare private block: Block | null;\n\n constructor() {\n super();\n const root = this.attachShadow({ mode: 'open' });\n const box = el('div', 'box');\n this.title_ = el('div', 'title');\n this.category = el('span', 'category');\n this.code = el('span', 'code');\n this.detail = el('div', 'detail');\n this.detail.append(this.category, el('span', 'separator', ' · '), this.code);\n this.message = el('div', 'message');\n this.block = null;\n this.retry = el('button', 'action retry');\n this.retry.type = 'button';\n this.retry.addEventListener('click', () => {\n this.player?.retry();\n });\n this.inspect = el('button', 'action diagnostics');\n this.inspect.type = 'button';\n this.inspect.addEventListener('click', () => {\n this.diagnostics()?.show();\n });\n const actions = el('div', 'actions');\n actions.append(this.retry, this.inspect);\n box.append(this.title_, this.detail, this.message, actions);\n root.append(style(STYLE), box);\n }\n\n /** Hidden and named before attaching: a constructor must not add attributes. */\n override connectedCallback(): void {\n if (this.player === null) this.hidden = true;\n if (!this.hasAttribute('role')) this.setAttribute('role', 'alert');\n super.connectedCallback();\n }\n\n private show(error: PlayerError): void {\n this.block = null;\n this.category.textContent = error.category;\n this.code.textContent = error.code;\n this.render();\n this.hidden = false;\n }\n\n /** Shows `block`, or hides the screen for null. */\n private showBlock(block: Block | null): void {\n this.block = block;\n this.render();\n this.hidden = block === null;\n }\n\n protected override attach(player: PlayerHost): void {\n const failure = (event: Event): void => {\n const error = (event as CustomEvent<PlayerError>).detail;\n if (error.fatal) this.show(error);\n };\n player.addEventListener('error', failure);\n this.keep(() => {\n player.removeEventListener('error', failure);\n });\n // Not `emptied`: the old session's teardown fires it after the new\n // source's error, and would hide the error it should leave.\n this.listen(player.video, ['playing', 'loadstart'], () => {\n if (this.block === null) this.hidden = true;\n });\n this.listen(player, ['sourcechange'], () => {\n if (this.block === null) this.hidden = true;\n });\n this.listen(player, ['blockchange'], () => {\n this.showBlock(player.blocked);\n });\n // The error or the block may have come before this element did.\n if (player.error !== null) this.show(player.error);\n if (player.blocked !== null) this.showBlock(player.blocked);\n this.render();\n }\n\n protected override detach(): void {\n this.hidden = true;\n }\n\n /** The player's diagnostics panel, when the page put one in it. */\n private diagnostics(): { show(): void } | null {\n return this.player?.querySelector(DIAGNOSTICS) as { show(): void } | null;\n }\n\n protected override render(): void {\n const block = this.block;\n this.detail.hidden = block !== null;\n this.retry.hidden = block !== null;\n this.inspect.hidden = block !== null || this.diagnostics() === null;\n // The diagnostics package adds its word to the player's; without the package there is no button.\n this.inspect.textContent = this.word(\n 'label-diagnostics',\n 'diagnostics' as keyof Messages,\n 'Diagnostics',\n );\n this.message.hidden = block?.message === undefined;\n if (block === null) {\n this.title_.textContent = this.word('label-title', 'playbackFailed', 'Playback failed');\n this.retry.textContent = this.word('label-retry', 'retry', 'Retry');\n return;\n }\n this.title_.textContent =\n block.title === undefined\n ? this.word('label-blocked', 'blocked', 'Not available')\n : this.pageText(block.title);\n this.message.textContent = block.message === undefined ? '' : this.pageText(block.message);\n }\n}\n"],"mappings":";;;;AAuBA,MAAA,QAAA;;AAGA,MAAA,cAAA;AAIA,IAAA,iBAAA,cAAA,UAAA;CACA,WAAA,qBAAA;EACA,OAAA;GAAA;GAAA;GAAA;GAAA;EAAA;CACA;CAYA,cAAA;EACA,MAAA;EACA,MAAA,OAAA,KAAA,aAAA,EAAA,MAAA,OAAA,CAAA;EACA,MAAA,MAAA,GAAA,OAAA,KAAA;EACA,KAAA,SAAA,GAAA,OAAA,OAAA;EACA,KAAA,WAAA,GAAA,QAAA,UAAA;EACA,KAAA,OAAA,GAAA,QAAA,MAAA;EACA,KAAA,SAAA,GAAA,OAAA,QAAA;EACA,KAAA,OAAA,OAAA,KAAA,UAAA,GAAA,QAAA,aAAA,KAAA,GAAA,KAAA,IAAA;EACA,KAAA,UAAA,GAAA,OAAA,SAAA;EACA,KAAA,QAAA;EACA,KAAA,QAAA,GAAA,UAAA,cAAA;EACA,KAAA,MAAA,OAAA;EACA,KAAA,MAAA,iBAAA,eAAA;GACA,KAAA,QAAA,MAA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AAA,MAAA,KAAA,UAAA,OAAA,OAAA;EACA,KAAA,OAAA;CACA;CAEA,SAAA;EACA,KAAA,SAAA;CACA;;CAGA,cAAA;EACA,OAAA,KAAA,QAAA,cAAA,WAAA;CACA;CAEA,SAAA;EACA,MAAA,QAAA,KAAA;EACA,KAAA,OAAA,SAAA,UAAA;EACA,KAAA,MAAA,SAAA,UAAA;EACA,KAAA,QAAA,SAAA,UAAA,QAAA,KAAA,YAAA,MAAA;EAEA,KAAA,QAAA,cAAA,KAAA,KACA,qBACA,eACA,aACA;EACA,KAAA,QAAA,SAAA,OAAA,YAAA,KAAA;EACA,IAAA,UAAA,MAAA;GACA,KAAA,OAAA,cAAA,KAAA,KAAA,eAAA,kBAAA,iBAAA;GACA,KAAA,MAAA,cAAA,KAAA,KAAA,eAAA,SAAA,OAAA;GACA;EACA;EACA,KAAA,OAAA,cACA,MAAA,UAAA,KAAA,IACA,KAAA,KAAA,iBAAA,WAAA,eAAA,IACA,KAAA,SAAA,MAAA,KAAA;EACA,KAAA,QAAA,cAAA,MAAA,YAAA,KAAA,IAAA,KAAA,KAAA,SAAA,MAAA,OAAA;CACA;AACA"}
1
+ {"version":3,"file":"error-screen.js","names":[],"sources":["../../src/elements/error-screen.ts"],"sourcesContent":["/**\n * <mbx-error-screen>: a fatal error over the picture, with the category,\n * the code and a retry. It sits in the player beside the video, hidden\n * until the player reports a fatal error, and clears when a session\n * arrives, a resource starts loading, or playback resumes: an error over\n * a picture that then plays is wrong by definition. The title comes from `label-title`, the button's text\n * from `label-retry`.\n *\n * Retry calls the player's `retry()`, which loads the sources again from\n * the first, whether they came from `src`, `sources` or `<source>` children.\n *\n * With an `<mbx-diagnostics>` in the player, a second button opens its\n * panel, so the report of the error can be read and copied. Its text is\n * the diagnostics' own word, or `label-diagnostics`.\n *\n * It also shows the page's `block()`: its title, else `label-blocked`, and\n * its message, with no retry, since a retry cannot lift a block.\n */\nimport type { PlayerError } from '@mattebox/player-core';\nimport { el } from '../dom.js';\nimport type { Block, PlayerHost } from '../host.js';\nimport type { Messages } from '../messages.js';\nimport { Component } from './component.js';\nimport STYLE from './error-screen.css?inline';\n\n/** The diagnostics element, another package's, named here as a string. */\nconst DIAGNOSTICS = 'mbx-diagnostics';\n\nimport { style } from './shared.js';\n\nexport class MbxErrorScreen extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label-title', 'label-retry', 'label-blocked', 'label-diagnostics'];\n }\n\n declare private readonly title_: HTMLElement;\n declare private readonly category: HTMLElement;\n declare private readonly code: HTMLElement;\n declare private readonly detail: HTMLElement;\n declare private readonly message: HTMLElement;\n declare private readonly retry: HTMLButtonElement;\n declare private readonly inspect: HTMLButtonElement;\n /** The block shown, or null for an error. */\n declare private block: Block | null;\n\n constructor() {\n super();\n const root = this.attachShadow({ mode: 'open' });\n const box = el('div', 'box');\n this.title_ = el('div', 'title');\n this.category = el('span', 'category');\n this.code = el('span', 'code');\n this.detail = el('div', 'detail');\n this.detail.append(this.category, el('span', 'separator', ' · '), this.code);\n this.message = el('div', 'message');\n this.block = null;\n this.retry = el('button', 'action retry');\n this.retry.type = 'button';\n this.retry.addEventListener('click', () => {\n this.player?.retry();\n });\n this.inspect = el('button', 'action diagnostics');\n this.inspect.type = 'button';\n this.inspect.addEventListener('click', () => {\n this.diagnostics()?.show();\n });\n const actions = el('div', 'actions');\n actions.append(this.retry, this.inspect);\n box.append(this.title_, this.detail, this.message, actions);\n root.append(style(STYLE), box);\n }\n\n /** Hidden and named before attaching: a constructor must not add attributes. */\n override connectedCallback(): void {\n if (this.player === null) this.hidden = true;\n if (!this.hasAttribute('role')) this.setAttribute('role', 'alert');\n super.connectedCallback();\n }\n\n private show(error: PlayerError): void {\n this.block = null;\n this.category.textContent = error.category;\n this.code.textContent = error.code;\n this.render();\n this.hidden = false;\n }\n\n /** Shows `block`, or hides the screen for null. */\n private showBlock(block: Block | null): void {\n this.block = block;\n this.render();\n this.hidden = block === null;\n }\n\n protected override attach(player: PlayerHost): void {\n const failure = (event: Event): void => {\n const error = (event as CustomEvent<PlayerError>).detail;\n if (error.fatal) this.show(error);\n };\n player.addEventListener('error', failure);\n this.keep(() => {\n player.removeEventListener('error', failure);\n });\n // Not `emptied`: the old session's teardown fires it after the new\n // source's error, and would hide the error it should leave.\n this.listen(player.media, ['playing', 'loadstart'], () => {\n if (this.block === null) this.hidden = true;\n });\n this.listen(player, ['sourcechange'], () => {\n if (this.block === null) this.hidden = true;\n });\n this.listen(player, ['blockchange'], () => {\n this.showBlock(player.blocked);\n });\n // The error or the block may have come before this element did.\n if (player.error !== null) this.show(player.error);\n if (player.blocked !== null) this.showBlock(player.blocked);\n this.render();\n }\n\n protected override detach(): void {\n this.hidden = true;\n }\n\n /** The player's diagnostics panel, when the page put one in it. */\n private diagnostics(): { show(): void } | null {\n return this.player?.querySelector(DIAGNOSTICS) as { show(): void } | null;\n }\n\n protected override render(): void {\n const block = this.block;\n this.detail.hidden = block !== null;\n this.retry.hidden = block !== null;\n this.inspect.hidden = block !== null || this.diagnostics() === null;\n // The diagnostics package adds its word to the player's; without the package there is no button.\n this.inspect.textContent = this.word(\n 'label-diagnostics',\n 'diagnostics' as keyof Messages,\n 'Diagnostics',\n );\n this.message.hidden = block?.message === undefined;\n if (block === null) {\n this.title_.textContent = this.word('label-title', 'playbackFailed', 'Playback failed');\n this.retry.textContent = this.word('label-retry', 'retry', 'Retry');\n return;\n }\n this.title_.textContent =\n block.title === undefined\n ? this.word('label-blocked', 'blocked', 'Not available')\n : this.pageText(block.title);\n this.message.textContent = block.message === undefined ? '' : this.pageText(block.message);\n }\n}\n"],"mappings":";;;;AAuBA,MAAA,QAAA;;AAGA,MAAM,cAAc;AAIpB,IAAa,iBAAb,cAAoC,UAAU;CAC5C,WAAW,qBAAwC;EACjD,OAAO;GAAC;GAAe;GAAe;GAAiB;EAAmB;CAC5E;CAYA,cAAc;EACZ,MAAM;EACN,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,MAAM,MAAM,GAA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AAS,MAAM,OAAO;CAC3F;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"fullscreen-button.d.ts","sourceRoot":"","sources":["../../src/elements/fullscreen-button.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAM3C,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,MAAM,CAAoB;IACnD,iBAAyB,KAAK,CAAiC;IAC/D,QAAgB,GAAG,CAAoB;;cAmBpB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAYhC,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAalC"}
1
+ {"version":3,"file":"fullscreen-button.d.ts","sourceRoot":"","sources":["../../src/elements/fullscreen-button.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAM3C,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,MAAM,CAAoB;IACnD,iBAAyB,KAAK,CAAiC;IAC/D,QAAgB,GAAG,CAAoB;;cAqBpB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAYhC,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAalC"}