@mattebox/player 0.14.0 → 0.16.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 (292) hide show
  1. package/dist/cdn/mattebox-player.min.js +3 -3
  2. package/dist/controls/chapters.d.ts +2 -8
  3. package/dist/controls/chapters.d.ts.map +1 -1
  4. package/dist/controls/chapters.js +1 -1
  5. package/dist/controls/chapters.js.map +1 -1
  6. package/dist/controls/cues.d.ts.map +1 -1
  7. package/dist/controls/cues.js +2 -2
  8. package/dist/controls/cues.js.map +1 -1
  9. package/dist/controls/icons.d.ts +1 -1
  10. package/dist/controls/icons.d.ts.map +1 -1
  11. package/dist/controls/icons.js +2 -0
  12. package/dist/controls/icons.js.map +1 -1
  13. package/dist/controls/native-tracks.js +1 -1
  14. package/dist/controls/native-tracks.js.map +1 -1
  15. package/dist/element-entry.d.ts +1 -0
  16. package/dist/element-entry.d.ts.map +1 -1
  17. package/dist/element-entry.js.map +1 -1
  18. package/dist/element.d.ts +68 -5
  19. package/dist/element.d.ts.map +1 -1
  20. package/dist/element.js +242 -42
  21. package/dist/element.js.map +1 -1
  22. package/dist/elements/airplay-button.js +1 -1
  23. package/dist/elements/airplay-button.js.map +1 -1
  24. package/dist/elements/audio-menu.d.ts.map +1 -1
  25. package/dist/elements/audio-menu.js +4 -3
  26. package/dist/elements/audio-menu.js.map +1 -1
  27. package/dist/elements/casting.d.ts +15 -0
  28. package/dist/elements/casting.d.ts.map +1 -0
  29. package/dist/elements/casting.js +55 -0
  30. package/dist/elements/casting.js.map +1 -0
  31. package/dist/elements/chapters-menu.js +5 -5
  32. package/dist/elements/chapters-menu.js.map +1 -1
  33. package/dist/elements/component.d.ts +13 -0
  34. package/dist/elements/component.d.ts.map +1 -1
  35. package/dist/elements/component.js +21 -3
  36. package/dist/elements/component.js.map +1 -1
  37. package/dist/elements/control-bar.d.ts +16 -2
  38. package/dist/elements/control-bar.d.ts.map +1 -1
  39. package/dist/elements/control-bar.js +29 -7
  40. package/dist/elements/control-bar.js.map +1 -1
  41. package/dist/elements/current-time.js +2 -2
  42. package/dist/elements/current-time.js.map +1 -1
  43. package/dist/elements/drm-badge.js +2 -2
  44. package/dist/elements/drm-badge.js.map +1 -1
  45. package/dist/elements/duration.js +3 -3
  46. package/dist/elements/duration.js.map +1 -1
  47. package/dist/elements/error-screen.js +2 -2
  48. package/dist/elements/error-screen.js.map +1 -1
  49. package/dist/elements/fullscreen-button.d.ts.map +1 -1
  50. package/dist/elements/fullscreen-button.js +3 -2
  51. package/dist/elements/fullscreen-button.js.map +1 -1
  52. package/dist/elements/live-button.js +3 -3
  53. package/dist/elements/live-button.js.map +1 -1
  54. package/dist/elements/marker-button.js +3 -3
  55. package/dist/elements/marker-button.js.map +1 -1
  56. package/dist/elements/menu-element.js +3 -3
  57. package/dist/elements/menu-element.js.map +1 -1
  58. package/dist/elements/mute-button.js +3 -3
  59. package/dist/elements/mute-button.js.map +1 -1
  60. package/dist/elements/pip-button.d.ts.map +1 -1
  61. package/dist/elements/pip-button.js +6 -2
  62. package/dist/elements/pip-button.js.map +1 -1
  63. package/dist/elements/play-button.js +3 -3
  64. package/dist/elements/play-button.js.map +1 -1
  65. package/dist/elements/quality-menu.d.ts.map +1 -1
  66. package/dist/elements/quality-menu.js +5 -4
  67. package/dist/elements/quality-menu.js.map +1 -1
  68. package/dist/elements/remaining-time.js +2 -2
  69. package/dist/elements/remaining-time.js.map +1 -1
  70. package/dist/elements/scan-button.d.ts.map +1 -1
  71. package/dist/elements/scan-button.js +4 -3
  72. package/dist/elements/scan-button.js.map +1 -1
  73. package/dist/elements/seek-bar.d.ts.map +1 -1
  74. package/dist/elements/seek-bar.js +20 -16
  75. package/dist/elements/seek-bar.js.map +1 -1
  76. package/dist/elements/shared.js +4 -4
  77. package/dist/elements/shared.js.map +1 -1
  78. package/dist/elements/skip-button.js +2 -2
  79. package/dist/elements/skip-button.js.map +1 -1
  80. package/dist/elements/spacer.js.map +1 -1
  81. package/dist/elements/speed-menu.d.ts.map +1 -1
  82. package/dist/elements/speed-menu.js +4 -3
  83. package/dist/elements/speed-menu.js.map +1 -1
  84. package/dist/elements/spinner.js +1 -1
  85. package/dist/elements/spinner.js.map +1 -1
  86. package/dist/elements/start-button.js +3 -3
  87. package/dist/elements/start-button.js.map +1 -1
  88. package/dist/elements/subtitles-menu.d.ts.map +1 -1
  89. package/dist/elements/subtitles-menu.js +34 -10
  90. package/dist/elements/subtitles-menu.js.map +1 -1
  91. package/dist/elements/time-element.js +1 -1
  92. package/dist/elements/time-element.js.map +1 -1
  93. package/dist/elements/title.js +1 -1
  94. package/dist/elements/title.js.map +1 -1
  95. package/dist/elements/video-menu.d.ts.map +1 -1
  96. package/dist/elements/video-menu.js +5 -4
  97. package/dist/elements/video-menu.js.map +1 -1
  98. package/dist/elements/volume-slider.js +4 -4
  99. package/dist/elements/volume-slider.js.map +1 -1
  100. package/dist/elements/volume.js.map +1 -1
  101. package/dist/entries/airplay-button.js +1 -1
  102. package/dist/entries/audio-menu.js +1 -1
  103. package/dist/entries/casting.d.ts +5 -0
  104. package/dist/entries/casting.d.ts.map +1 -0
  105. package/dist/entries/casting.js +8 -0
  106. package/dist/entries/casting.js.map +1 -0
  107. package/dist/entries/chapters-menu.js +1 -1
  108. package/dist/entries/control-bar.js +1 -1
  109. package/dist/entries/current-time.js +1 -1
  110. package/dist/entries/drm-badge.js +1 -1
  111. package/dist/entries/duration.js +1 -1
  112. package/dist/entries/error-screen.js +1 -1
  113. package/dist/entries/fullscreen-button.js +1 -1
  114. package/dist/entries/live-button.js +1 -1
  115. package/dist/entries/marker-button.js +1 -1
  116. package/dist/entries/mute-button.js +1 -1
  117. package/dist/entries/pip-button.js +1 -1
  118. package/dist/entries/play-button.js +1 -1
  119. package/dist/entries/quality-menu.js +1 -1
  120. package/dist/entries/remaining-time.js +1 -1
  121. package/dist/entries/scan-button.js +1 -1
  122. package/dist/entries/seek-bar.js +1 -1
  123. package/dist/entries/skip-button.js +1 -1
  124. package/dist/entries/spacer.js +1 -1
  125. package/dist/entries/speed-menu.js +1 -1
  126. package/dist/entries/spinner.js +1 -1
  127. package/dist/entries/start-button.js +1 -1
  128. package/dist/entries/subtitles-menu.js +1 -1
  129. package/dist/entries/title.js +1 -1
  130. package/dist/entries/video-menu.js +1 -1
  131. package/dist/entries/volume-slider.js +1 -1
  132. package/dist/entries/volume.js +1 -1
  133. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/asyncToGenerator.js +1 -1
  134. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/defineProperty.js +1 -1
  135. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/objectSpread2.js +1 -1
  136. package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
  137. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/toPropertyKey.js +1 -1
  138. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.158.0}/helpers/esm/typeof.js +1 -1
  139. package/dist/es2015/controls/chapters.js +2 -2
  140. package/dist/es2015/controls/cues.js +2 -2
  141. package/dist/es2015/controls/icons.js +2 -0
  142. package/dist/es2015/controls/menu.js +1 -1
  143. package/dist/es2015/controls/native-tracks.js +1 -1
  144. package/dist/es2015/element.js +262 -55
  145. package/dist/es2015/elements/airplay-button.js +1 -1
  146. package/dist/es2015/elements/audio-menu.js +4 -3
  147. package/dist/es2015/elements/casting.js +55 -0
  148. package/dist/es2015/elements/chapters-menu.js +5 -5
  149. package/dist/es2015/elements/component.js +26 -7
  150. package/dist/es2015/elements/control-bar.js +29 -7
  151. package/dist/es2015/elements/current-time.js +2 -2
  152. package/dist/es2015/elements/drm-badge.js +2 -2
  153. package/dist/es2015/elements/duration.js +3 -3
  154. package/dist/es2015/elements/error-screen.js +2 -2
  155. package/dist/es2015/elements/fullscreen-button.js +3 -2
  156. package/dist/es2015/elements/live-button.js +3 -3
  157. package/dist/es2015/elements/marker-button.js +3 -3
  158. package/dist/es2015/elements/menu-element.js +4 -4
  159. package/dist/es2015/elements/mute-button.js +3 -3
  160. package/dist/es2015/elements/pip-button.js +6 -2
  161. package/dist/es2015/elements/play-button.js +3 -3
  162. package/dist/es2015/elements/quality-menu.js +5 -4
  163. package/dist/es2015/elements/remaining-time.js +2 -2
  164. package/dist/es2015/elements/scan-button.js +4 -3
  165. package/dist/es2015/elements/seek-bar.js +20 -16
  166. package/dist/es2015/elements/shared.js +4 -4
  167. package/dist/es2015/elements/skip-button.js +2 -2
  168. package/dist/es2015/elements/speed-menu.js +4 -3
  169. package/dist/es2015/elements/spinner.js +1 -1
  170. package/dist/es2015/elements/start-button.js +3 -3
  171. package/dist/es2015/elements/subtitles-menu.js +34 -10
  172. package/dist/es2015/elements/time-element.js +1 -1
  173. package/dist/es2015/elements/title.js +1 -1
  174. package/dist/es2015/elements/video-menu.js +5 -4
  175. package/dist/es2015/elements/volume-slider.js +4 -4
  176. package/dist/es2015/entries/airplay-button.js +1 -1
  177. package/dist/es2015/entries/audio-menu.js +1 -1
  178. package/dist/es2015/entries/casting.js +6 -0
  179. package/dist/es2015/entries/chapters-menu.js +1 -1
  180. package/dist/es2015/entries/control-bar.js +1 -1
  181. package/dist/es2015/entries/current-time.js +1 -1
  182. package/dist/es2015/entries/drm-badge.js +1 -1
  183. package/dist/es2015/entries/duration.js +1 -1
  184. package/dist/es2015/entries/error-screen.js +1 -1
  185. package/dist/es2015/entries/fullscreen-button.js +1 -1
  186. package/dist/es2015/entries/live-button.js +1 -1
  187. package/dist/es2015/entries/marker-button.js +1 -1
  188. package/dist/es2015/entries/mute-button.js +1 -1
  189. package/dist/es2015/entries/pip-button.js +1 -1
  190. package/dist/es2015/entries/play-button.js +1 -1
  191. package/dist/es2015/entries/quality-menu.js +1 -1
  192. package/dist/es2015/entries/remaining-time.js +1 -1
  193. package/dist/es2015/entries/scan-button.js +1 -1
  194. package/dist/es2015/entries/seek-bar.js +1 -1
  195. package/dist/es2015/entries/skip-button.js +1 -1
  196. package/dist/es2015/entries/spacer.js +1 -1
  197. package/dist/es2015/entries/speed-menu.js +1 -1
  198. package/dist/es2015/entries/spinner.js +1 -1
  199. package/dist/es2015/entries/start-button.js +1 -1
  200. package/dist/es2015/entries/subtitles-menu.js +1 -1
  201. package/dist/es2015/entries/title.js +1 -1
  202. package/dist/es2015/entries/video-menu.js +1 -1
  203. package/dist/es2015/entries/volume-slider.js +1 -1
  204. package/dist/es2015/entries/volume.js +1 -1
  205. package/dist/es2015/host.js +9 -1
  206. package/dist/es2015/index.js +5 -3
  207. package/dist/es2015/locales/ar.js +4 -1
  208. package/dist/es2015/locales/ca.js +4 -1
  209. package/dist/es2015/locales/de.js +4 -1
  210. package/dist/es2015/locales/es.js +4 -1
  211. package/dist/es2015/locales/fr.js +4 -1
  212. package/dist/es2015/locales/hi.js +4 -1
  213. package/dist/es2015/locales/it.js +4 -1
  214. package/dist/es2015/locales/ja.js +4 -1
  215. package/dist/es2015/locales/ko.js +4 -1
  216. package/dist/es2015/locales/pt.js +4 -1
  217. package/dist/es2015/locales/zh.js +4 -1
  218. package/dist/es2015/locales.js +1 -1
  219. package/dist/es2015/media.js +136 -0
  220. package/dist/es2015/presets.js +3 -2
  221. package/dist/es2015/style.js +1 -1
  222. package/dist/es2015/tags.js +2 -1
  223. package/dist/es2015/video-sources.js +1 -1
  224. package/dist/host.d.ts +32 -2
  225. package/dist/host.d.ts.map +1 -1
  226. package/dist/host.js +9 -1
  227. package/dist/host.js.map +1 -1
  228. package/dist/index.d.ts +6 -2
  229. package/dist/index.d.ts.map +1 -1
  230. package/dist/index.js +5 -3
  231. package/dist/locales/ar.d.ts +3 -0
  232. package/dist/locales/ar.d.ts.map +1 -1
  233. package/dist/locales/ar.js +4 -1
  234. package/dist/locales/ar.js.map +1 -1
  235. package/dist/locales/ca.d.ts +3 -0
  236. package/dist/locales/ca.d.ts.map +1 -1
  237. package/dist/locales/ca.js +4 -1
  238. package/dist/locales/ca.js.map +1 -1
  239. package/dist/locales/de.d.ts +3 -0
  240. package/dist/locales/de.d.ts.map +1 -1
  241. package/dist/locales/de.js +4 -1
  242. package/dist/locales/de.js.map +1 -1
  243. package/dist/locales/es.d.ts +3 -0
  244. package/dist/locales/es.d.ts.map +1 -1
  245. package/dist/locales/es.js +4 -1
  246. package/dist/locales/es.js.map +1 -1
  247. package/dist/locales/fr.d.ts +3 -0
  248. package/dist/locales/fr.d.ts.map +1 -1
  249. package/dist/locales/fr.js +4 -1
  250. package/dist/locales/fr.js.map +1 -1
  251. package/dist/locales/hi.d.ts +3 -0
  252. package/dist/locales/hi.d.ts.map +1 -1
  253. package/dist/locales/hi.js +4 -1
  254. package/dist/locales/hi.js.map +1 -1
  255. package/dist/locales/it.d.ts +3 -0
  256. package/dist/locales/it.d.ts.map +1 -1
  257. package/dist/locales/it.js +4 -1
  258. package/dist/locales/it.js.map +1 -1
  259. package/dist/locales/ja.d.ts +3 -0
  260. package/dist/locales/ja.d.ts.map +1 -1
  261. package/dist/locales/ja.js +4 -1
  262. package/dist/locales/ja.js.map +1 -1
  263. package/dist/locales/ko.d.ts +3 -0
  264. package/dist/locales/ko.d.ts.map +1 -1
  265. package/dist/locales/ko.js +4 -1
  266. package/dist/locales/ko.js.map +1 -1
  267. package/dist/locales/pt.d.ts +3 -0
  268. package/dist/locales/pt.d.ts.map +1 -1
  269. package/dist/locales/pt.js +4 -1
  270. package/dist/locales/pt.js.map +1 -1
  271. package/dist/locales/zh.d.ts +3 -0
  272. package/dist/locales/zh.d.ts.map +1 -1
  273. package/dist/locales/zh.js +4 -1
  274. package/dist/locales/zh.js.map +1 -1
  275. package/dist/media.d.ts +22 -0
  276. package/dist/media.d.ts.map +1 -0
  277. package/dist/media.js +136 -0
  278. package/dist/media.js.map +1 -0
  279. package/dist/messages.d.ts +6 -0
  280. package/dist/messages.d.ts.map +1 -1
  281. package/dist/presets.js +2 -1
  282. package/dist/presets.js.map +1 -1
  283. package/dist/remote.d.ts +80 -0
  284. package/dist/remote.d.ts.map +1 -0
  285. package/dist/style.js +1 -1
  286. package/dist/style.js.map +1 -1
  287. package/dist/tags.d.ts +1 -0
  288. package/dist/tags.d.ts.map +1 -1
  289. package/dist/tags.js +2 -1
  290. package/dist/tags.js.map +1 -1
  291. package/package.json +3 -3
  292. package/dist/es2015/_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/toPrimitive.js +0 -13
@@ -1,9 +1,11 @@
1
1
  import { announcer } from "./announcer.js";
2
2
  import { createBreakMarks } from "./controls/breaks.js";
3
+ import { chapters } from "./controls/chapters.js";
3
4
  import { createMarkers } from "./controls/markers.js";
5
+ import { live } from "./controls/session.js";
4
6
  import { languageName } from "./controls/track-names.js";
5
- import _asyncToGenerator from "./_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/asyncToGenerator.js";
6
7
  import { addLocale, load, onLocales, registered, wordsNow } from "./locales.js";
8
+ import { createMedia } from "./media.js";
7
9
  import { namespaces } from "./namespaces.js";
8
10
  import { drmGuard, resolvePreset } from "./presets.js";
9
11
  import { STYLE } from "./style.js";
@@ -11,8 +13,9 @@ import { errorSurface } from "./surface.js";
11
13
  import { PLAYER } from "./tags.js";
12
14
  import { textIn } from "./text.js";
13
15
  import { createTrackers } from "./trackers.js";
14
- import _objectSpread2 from "./_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/objectSpread2.js";
15
16
  import { chosen, holdFrame, markupVideoTracks, onNextFrame, restore, resume, versionSource } from "./video-sources.js";
17
+ import _objectSpread2 from "./_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
18
+ import _asyncToGenerator from "./_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/asyncToGenerator.js";
16
19
  import { createPlayer, inferType, matteboxHandler, nativeHandler, preferNativeHls } from "@mattebox/player-core";
17
20
  // src/element.ts
18
21
  /**
@@ -43,8 +46,8 @@ function emeAvailable() {
43
46
  return drmGuard().without === void 0;
44
47
  }
45
48
  /** `source` without its DRM, for a browser without EME. */
46
- function withoutDrm({ url, type, videoTracks }) {
47
- return _objectSpread2(_objectSpread2({ url }, type === void 0 ? {} : { type }), videoTracks === void 0 ? {} : { videoTracks });
49
+ function withoutDrm({ url, type, videoTracks, projection }) {
50
+ return _objectSpread2(_objectSpread2(_objectSpread2({ url }, type === void 0 ? {} : { type }), videoTracks === void 0 ? {} : { videoTracks }), projection === void 0 ? {} : { projection });
48
51
  }
49
52
  const CERTIFICATE_URL = "certificate-url";
50
53
  /** Everything else the element watches. Changing any of them reloads. */
@@ -195,6 +198,12 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
195
198
  this.offs = [];
196
199
  this.attached = /* @__PURE__ */ new Map();
197
200
  this.interruption = null;
201
+ this.device = null;
202
+ this.away = false;
203
+ this.uncast = null;
204
+ this.target = null;
205
+ this.handoff = null;
206
+ this.frozenLive = false;
198
207
  this.queue = Promise.resolve();
199
208
  this.pending = false;
200
209
  this.original = null;
@@ -210,24 +219,36 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
210
219
  this.heardAudio = void 0;
211
220
  this.heardText = void 0;
212
221
  this.offTracks = null;
213
- this.media = document.createElement("video");
214
- this.media.controls = true;
215
- this.media.setAttribute(PLAYSINLINE, "");
216
- for (const name of STATE_EVENTS) this.media.addEventListener(name, () => {
222
+ this.node = document.createElement("video");
223
+ this.playback = createMedia(this.node);
224
+ this.node.controls = true;
225
+ this.node.setAttribute(PLAYSINLINE, "");
226
+ for (const name of STATE_EVENTS) this.playback.media.addEventListener(name, () => {
217
227
  const was = this.waiting;
218
228
  this.note(name);
219
229
  this.reflect();
220
230
  this.tell(name, was);
221
231
  });
222
- const lists = this.media;
232
+ const lists = this.node;
223
233
  for (const list of [lists.audioTracks, lists.textTracks]) list === null || list === void 0 || list.addEventListener("change", () => {
224
234
  this.tracks();
225
235
  });
226
- this.media.addEventListener("playing", () => {
236
+ this.node.addEventListener("playing", () => {
227
237
  this.failure = null;
228
238
  this.reflect();
229
239
  });
230
- this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));
240
+ this.node.addEventListener("play", () => {
241
+ if (this.away) this.node.pause();
242
+ });
243
+ this.node.addEventListener("webkitcurrentplaybacktargetiswirelesschanged", () => {
244
+ if (this.device !== null) return;
245
+ const wireless = this.node.webkitCurrentPlaybackTargetIsWireless === true;
246
+ this.aim(wireless ? {
247
+ kind: "airplay",
248
+ name: ""
249
+ } : null);
250
+ });
251
+ this.marks = createMarkers(this.playback.media, (name, detail) => this.emit(name, detail));
231
252
  this.breakMarks = createBreakMarks((list) => this.emit("breakschange", list));
232
253
  this.tracking = createTrackers(this, () => this.emit("trackerschange", this.tracking.list));
233
254
  this.stage = document.createElement("div");
@@ -249,9 +270,21 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
249
270
  style.textContent = STYLE;
250
271
  root.append(style, this.stage, this.surface.root, this.voice.root);
251
272
  }
252
- /** The media element. Everything the browser already does is here. */
253
- get video() {
254
- return this.media;
273
+ /**
274
+ * What plays: the video, with everything the browser already does. While
275
+ * a device plays in its place, the playback members are the device's.
276
+ * A proxy and not the node: a page that needs the node reads the
277
+ * `<video>` child of the player.
278
+ */
279
+ get media() {
280
+ return this.playback.media;
281
+ }
282
+ /**
283
+ * The programme's chapters, in order: the engine's when its session holds
284
+ * some, else the video's chapters track. Read again on each access.
285
+ */
286
+ get chapters() {
287
+ return chapters(this.node, this.engine);
255
288
  }
256
289
  /** The ranges the page named in this source: credits to skip, parts that must not play. */
257
290
  get markers() {
@@ -361,7 +394,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
361
394
  */
362
395
  switchSource(source) {
363
396
  var _this$current$engine, _this$current;
364
- const media = this.media;
397
+ const media = this.playback.media;
365
398
  const at = Number.isFinite(media.duration) ? media.currentTime : null;
366
399
  const playing = !media.paused;
367
400
  const had = chosen((_this$current$engine = (_this$current = this.current) === null || _this$current === void 0 ? void 0 : _this$current.engine) !== null && _this$current$engine !== void 0 ? _this$current$engine : null);
@@ -385,7 +418,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
385
418
  interrupt(source) {
386
419
  var _this = this;
387
420
  var _this$interruption, _this$current$engine2, _this$current2;
388
- const media = this.media;
421
+ const media = this.playback.media;
389
422
  (_this$interruption = this.interruption) !== null && _this$interruption !== void 0 || (this.interruption = {
390
423
  at: Number.isFinite(media.duration) ? media.currentTime : null,
391
424
  playing: !media.paused,
@@ -395,7 +428,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
395
428
  const core = yield _this.ensure();
396
429
  yield core.interrupt(source);
397
430
  _this.current = core.session;
398
- media.play().catch(() => void 0);
431
+ if (_this.away) _this.hand(source, null, true, false);
432
+ else _this.node.play().catch(() => void 0);
399
433
  }));
400
434
  }
401
435
  /**
@@ -417,7 +451,9 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
417
451
  yield core.resume(at !== null && at !== void 0 ? at : void 0);
418
452
  _this2.current = core.session;
419
453
  restore((_this$current$engine3 = (_this$current3 = _this2.current) === null || _this$current3 === void 0 ? void 0 : _this$current3.engine) !== null && _this$current$engine3 !== void 0 ? _this$current$engine3 : null, left.had);
420
- if (playing) _this2.media.play().catch(() => void 0);
454
+ const session = _this2.current;
455
+ if (_this2.device !== null && session !== null) _this2.hand(session.source, at, playing, true);
456
+ else if (playing) _this2.node.play().catch(() => void 0);
421
457
  }));
422
458
  }
423
459
  /** `interrupt` plays in the programme's place. */
@@ -435,6 +471,20 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
435
471
  var _this$original$videoT, _this$original;
436
472
  return (_this$original$videoT = (_this$original = this.original) === null || _this$original === void 0 ? void 0 : _this$original.videoTracks) !== null && _this$original$videoT !== void 0 ? _this$original$videoT : [];
437
473
  }
474
+ /**
475
+ * How the playing picture maps onto a sphere, for 360° video: the
476
+ * source's `projection`, else the manifest's, else null for a flat one.
477
+ * A version of `videoSources` is flat.
478
+ */
479
+ get projection() {
480
+ var _this$original2, _this$current4, _track$renditions;
481
+ if (this.version !== null) return null;
482
+ const given = (_this$original2 = this.original) === null || _this$original2 === void 0 ? void 0 : _this$original2.projection;
483
+ if (given !== void 0) return given;
484
+ const track = (_this$current4 = this.current) === null || _this$current4 === void 0 || (_this$current4 = _this$current4.engine) === null || _this$current4 === void 0 ? void 0 : _this$current4.tracks.active("video");
485
+ for (const rendition of (_track$renditions = track === null || track === void 0 ? void 0 : track.renditions) !== null && _track$renditions !== void 0 ? _track$renditions : []) if (rendition.projection !== void 0) return rendition.projection;
486
+ return null;
487
+ }
438
488
  /** The version of `videoSources` that plays, or null for the source itself. */
439
489
  get videoSource() {
440
490
  return this.version;
@@ -446,14 +496,14 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
446
496
  * Fires `videosourcechange`.
447
497
  */
448
498
  selectVideoSource(track) {
449
- var _programme$videoTrack, _this$current$engine4, _this$current4;
499
+ var _programme$videoTrack, _this$current$engine4, _this$current5;
450
500
  const programme = this.original;
451
501
  if (programme === null || track === this.version) return;
452
502
  if (track !== null && ((_programme$videoTrack = programme.videoTracks) === null || _programme$videoTrack === void 0 ? void 0 : _programme$videoTrack.includes(track)) !== true) return;
453
- const media = this.media;
503
+ const media = this.playback.media;
454
504
  const at = Number.isFinite(media.duration) ? media.currentTime : null;
455
505
  const playing = !media.paused;
456
- const had = chosen((_this$current$engine4 = (_this$current4 = this.current) === null || _this$current4 === void 0 ? void 0 : _this$current4.engine) !== null && _this$current$engine4 !== void 0 ? _this$current$engine4 : null);
506
+ const had = chosen((_this$current$engine4 = (_this$current5 = this.current) === null || _this$current5 === void 0 ? void 0 : _this$current5.engine) !== null && _this$current$engine4 !== void 0 ? _this$current$engine4 : null);
457
507
  this.version = track;
458
508
  this.emit("videosourcechange", track);
459
509
  this.swap(track === null ? programme : versionSource(track, emeAvailable()), at, playing, had, true);
@@ -467,7 +517,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
467
517
  swap(source, at, playing, had, hold) {
468
518
  var _this3 = this;
469
519
  var _this$held;
470
- const media = this.media;
520
+ const media = this.node;
471
521
  (_this$held = this.held) === null || _this$held === void 0 || _this$held.call(this);
472
522
  let release = null;
473
523
  if (hold) {
@@ -484,9 +534,13 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
484
534
  release = done;
485
535
  }
486
536
  this.enqueue(_asyncToGenerator(function* () {
487
- var _this$current$engine5, _this$current5;
537
+ var _this$current$engine5, _this$current6;
488
538
  const core = yield _this3.ensure();
489
539
  _this3.switching = true;
540
+ if (_this3.away) _this3.handoff = {
541
+ at,
542
+ playing
543
+ };
490
544
  try {
491
545
  yield core.load([source]);
492
546
  } catch (_unused) {
@@ -495,19 +549,150 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
495
549
  } finally {
496
550
  _this3.switching = false;
497
551
  }
498
- resume(media, at, playing);
499
- if (release !== null) onNextFrame(media, at, release);
500
- restore((_this$current$engine5 = (_this$current5 = _this3.current) === null || _this$current5 === void 0 ? void 0 : _this$current5.engine) !== null && _this$current$engine5 !== void 0 ? _this$current$engine5 : null, had);
552
+ if (_this3.away) release === null || release === void 0 || release();
553
+ else {
554
+ resume(media, at, playing);
555
+ if (release !== null) onNextFrame(media, at, release);
556
+ }
557
+ restore((_this$current$engine5 = (_this$current6 = _this3.current) === null || _this$current6 === void 0 ? void 0 : _this$current6.engine) !== null && _this$current$engine5 !== void 0 ? _this$current$engine5 : null, had);
501
558
  }));
502
559
  }
560
+ /** The device that plays in the video's place, its kind and its name, or null. The `casting` attribute carries the kind. */
561
+ get casting() {
562
+ return this.target;
563
+ }
564
+ /**
565
+ * Hands playback to a device, for a cast package. From here `media`
566
+ * reads the device for the members `remote.media` has, the video stays
567
+ * paused, and every load goes to the device. Returns the function that
568
+ * ends the cast: the video takes the device's position and play state
569
+ * back, with no new load. A second call ends the cast before it.
570
+ */
571
+ cast(remote, options = {}) {
572
+ var _this$uncast;
573
+ (_this$uncast = this.uncast) === null || _this$uncast === void 0 || _this$uncast.call(this);
574
+ this.device = remote;
575
+ this.aim(remote.target);
576
+ const session = this.current;
577
+ if (this.interruption !== null) {} else if (options.adopted === true || session === null) {
578
+ this.freeze();
579
+ this.away = true;
580
+ this.playback.attach(remote.media);
581
+ } else this.hand(session.source, this.position(), !this.node.paused, true);
582
+ const end = () => {
583
+ var _this$current7;
584
+ if (this.device !== remote) return;
585
+ const time = remote.media.currentTime;
586
+ const playing = !remote.media.paused;
587
+ const away = this.away;
588
+ this.device = null;
589
+ this.away = false;
590
+ this.uncast = null;
591
+ this.playback.detach();
592
+ this.aim(null);
593
+ if (!away) return;
594
+ (_this$current7 = this.current) === null || _this$current7 === void 0 || (_this$current7 = _this$current7.engine) === null || _this$current7 === void 0 || _this$current7.resume();
595
+ if (this.current !== null && !this.frozenLive && Number.isFinite(time)) this.node.currentTime = time;
596
+ if (playing) this.node.play().catch(() => void 0);
597
+ };
598
+ this.uncast = end;
599
+ return end;
600
+ }
601
+ /**
602
+ * Where the video is, for a device: seconds on demand, and for live null
603
+ * at the edge or the clock time behind it. Read before the engine is
604
+ * suspended, which no longer says where the edge is.
605
+ */
606
+ position() {
607
+ var _this$current$engine6, _this$current8;
608
+ const node = this.node;
609
+ const engine = (_this$current$engine6 = (_this$current8 = this.current) === null || _this$current8 === void 0 ? void 0 : _this$current8.engine) !== null && _this$current$engine6 !== void 0 ? _this$current$engine6 : null;
610
+ const edge = live(engine);
611
+ if (edge !== void 0) {
612
+ var _namespaces$pdt$toWal, _namespaces$pdt;
613
+ if (edge.atEdge) return null;
614
+ const date = engine === null ? null : (_namespaces$pdt$toWal = (_namespaces$pdt = namespaces(engine).pdt) === null || _namespaces$pdt === void 0 ? void 0 : _namespaces$pdt.toWallClock(node.currentTime)) !== null && _namespaces$pdt$toWal !== void 0 ? _namespaces$pdt$toWal : null;
615
+ return date === null ? null : { date };
616
+ }
617
+ return Number.isFinite(node.duration) ? node.currentTime : null;
618
+ }
619
+ /** Pauses the video and stops the engine's requests. The source stays loaded, for the chapters and the thumbnails. */
620
+ freeze() {
621
+ var _this$current$engine7, _this$current9;
622
+ const engine = (_this$current$engine7 = (_this$current9 = this.current) === null || _this$current9 === void 0 ? void 0 : _this$current9.engine) !== null && _this$current$engine7 !== void 0 ? _this$current$engine7 : null;
623
+ this.frozenLive = live(engine) !== void 0;
624
+ this.node.pause();
625
+ engine === null || engine === void 0 || engine.suspend();
626
+ }
627
+ /** The device plays `source` in the video's place: the programme's own, or one that interrupts it. */
628
+ hand(source, at, playing, own) {
629
+ const remote = this.device;
630
+ if (remote === null) return;
631
+ this.freeze();
632
+ if (!this.away) {
633
+ this.away = true;
634
+ this.playback.attach(remote.media);
635
+ }
636
+ const addons = {};
637
+ if (own) for (const addon of this.attached.keys()) {
638
+ var _addon$remoteData;
639
+ const data = (_addon$remoteData = addon.remoteData) === null || _addon$remoteData === void 0 ? void 0 : _addon$remoteData.call(addon, this);
640
+ if (data !== void 0) addons[addon.name] = data;
641
+ }
642
+ const chapters = own ? this.getAttribute(CHAPTERS) : null;
643
+ const thumbnails = own ? this.getAttribute("thumbnails") : null;
644
+ const load = _objectSpread2(_objectSpread2(_objectSpread2({
645
+ programme: own ? this.programme : null,
646
+ at,
647
+ playing,
648
+ live: this.frozenLive,
649
+ markers: own ? this.marks.list : []
650
+ }, chapters === null ? {} : { chapters }), thumbnails === null ? {} : { thumbnails }), {}, {
651
+ textTracks: own ? this.textFiles() : [],
652
+ addons
653
+ });
654
+ remote.load(source, load).catch(() => {
655
+ var _this$current$handler, _this$current10;
656
+ if (this.device !== remote) return;
657
+ this.report({
658
+ category: "remote",
659
+ code: "REMOTE_LOAD_FAILED",
660
+ fatal: false,
661
+ recoverable: true,
662
+ handler: (_this$current$handler = (_this$current10 = this.current) === null || _this$current10 === void 0 ? void 0 : _this$current10.handler) !== null && _this$current$handler !== void 0 ? _this$current$handler : null
663
+ });
664
+ });
665
+ }
666
+ /** The subtitle and caption files the page gave the video as `<track>` children. */
667
+ textFiles() {
668
+ const files = [];
669
+ for (const track of Array.from(this.node.querySelectorAll("track[src]"))) {
670
+ if (track.kind !== "subtitles" && track.kind !== "captions") continue;
671
+ files.push({
672
+ url: track.src,
673
+ kind: track.kind,
674
+ label: track.label,
675
+ language: track.srclang
676
+ });
677
+ }
678
+ return files;
679
+ }
680
+ /** Sets the device that plays: the `casting` attribute carries its kind, and `castingchange` the target. */
681
+ aim(target) {
682
+ if (this.target === null && target === null) return;
683
+ this.target = target;
684
+ if (target === null) this.removeAttribute("casting");
685
+ else this.setAttribute("casting", target.kind);
686
+ this.emit("castingchange", target);
687
+ }
503
688
  /** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
504
689
  get player() {
505
690
  return this.core;
506
691
  }
507
692
  /** The engine feeding the video, or null for a native session and before the first load. */
508
693
  get engine() {
509
- var _this$current$engine6, _this$current6;
510
- return (_this$current$engine6 = (_this$current6 = this.current) === null || _this$current6 === void 0 ? void 0 : _this$current6.engine) !== null && _this$current$engine6 !== void 0 ? _this$current$engine6 : null;
694
+ var _this$current$engine8, _this$current11;
695
+ return (_this$current$engine8 = (_this$current11 = this.current) === null || _this$current11 === void 0 ? void 0 : _this$current11.engine) !== null && _this$current$engine8 !== void 0 ? _this$current$engine8 : null;
511
696
  }
512
697
  /**
513
698
  * The fatal error of the current load, or null once a load starts or
@@ -533,7 +718,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
533
718
  /** Shows the block, for `block()` and for a programme a connector blocked, which loaded nothing. */
534
719
  refuse(block) {
535
720
  this.stop = block;
536
- this.media.pause();
721
+ this.node.pause();
537
722
  clearTimeout(this.slow);
538
723
  const [title, message] = this.blockWords(block);
539
724
  if (this.querySelector("mbx-error-screen") === null) this.voice.tell(message === "" ? title : `${title}. ${message}`);
@@ -577,8 +762,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
577
762
  const metadata = programme === null || programme === void 0 ? void 0 : programme.metadata;
578
763
  if ((metadata === null || metadata === void 0 ? void 0 : metadata.markers) !== void 0) this.marks.set(metadata.markers);
579
764
  if (!this.hasAttribute("poster")) {
580
- if ((metadata === null || metadata === void 0 ? void 0 : metadata.poster) === void 0) this.media.removeAttribute("poster");
581
- else this.media.poster = metadata.poster;
765
+ if ((metadata === null || metadata === void 0 ? void 0 : metadata.poster) === void 0) this.node.removeAttribute("poster");
766
+ else this.node.poster = metadata.poster;
582
767
  }
583
768
  if ((programme === null || programme === void 0 ? void 0 : programme.block) !== void 0) this.refuse(programme.block);
584
769
  this.emit("programmechange", programme);
@@ -596,7 +781,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
596
781
  this.surface.inform(title, message);
597
782
  }
598
783
  connectedCallback() {
599
- if (this.media.parentNode !== this) this.append(this.media);
784
+ if (this.node.parentNode !== this) this.append(this.node);
600
785
  for (const name of FORWARDED) this.forward(name);
601
786
  this.reflect();
602
787
  if (typeof ResizeObserver !== "undefined") {
@@ -643,7 +828,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
643
828
  this.started = true;
644
829
  this.waiting = false;
645
830
  } else if (event === "waiting") this.waiting = true;
646
- else if (event === "canplay") this.waiting = false;
831
+ else if (event === "canplay" || event === "pause" && this.away) this.waiting = false;
647
832
  else if (event === "emptied") {
648
833
  if (this.held === null) this.started = false;
649
834
  this.waiting = false;
@@ -654,7 +839,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
654
839
  /** Says a play or a pause, and a wait once it has lasted `LOADING_MS`. */
655
840
  tell(event, was) {
656
841
  if (event === "play" && this.held === null) this.voice.say("playing", "saidPlaying", "Playing");
657
- if (event === "pause" && !this.media.ended && this.held === null) this.voice.say("paused", "saidPaused", "Paused");
842
+ if (event === "pause" && !this.playback.media.ended && this.held === null) this.voice.say("paused", "saidPaused", "Paused");
658
843
  if (this.waiting === was) return;
659
844
  clearTimeout(this.slow);
660
845
  if (this.waiting) this.slow = setTimeout(() => {
@@ -667,8 +852,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
667
852
  * reads as off, as in the subtitles menu.
668
853
  */
669
854
  tracks() {
670
- var _this$current$engine7, _this$current7;
671
- const engine = (_this$current$engine7 = (_this$current7 = this.current) === null || _this$current7 === void 0 ? void 0 : _this$current7.engine) !== null && _this$current$engine7 !== void 0 ? _this$current$engine7 : null;
855
+ var _this$current$engine9, _this$current12;
856
+ const engine = (_this$current$engine9 = (_this$current12 = this.current) === null || _this$current12 === void 0 ? void 0 : _this$current12.engine) !== null && _this$current$engine9 !== void 0 ? _this$current$engine9 : null;
672
857
  let audio;
673
858
  let text;
674
859
  if (engine !== null) {
@@ -678,9 +863,9 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
678
863
  text = words === null || words.forced === true ? null : trackName(words.name, words.lang, this.locale);
679
864
  } else {
680
865
  var _video$audioTracks;
681
- const video = this.media;
866
+ const video = this.node;
682
867
  const sound = Array.from((_video$audioTracks = video.audioTracks) !== null && _video$audioTracks !== void 0 ? _video$audioTracks : []).find((track) => track.enabled);
683
- const words = Array.from(this.media.textTracks).find((track) => (track.kind === "subtitles" || track.kind === "captions") && track.mode === "showing");
868
+ const words = Array.from(this.node.textTracks).find((track) => (track.kind === "subtitles" || track.kind === "captions") && track.mode === "showing");
684
869
  audio = sound === void 0 ? "" : trackName(sound.label, sound.language, this.locale);
685
870
  text = words === void 0 ? null : trackName(words.label, words.language, this.locale);
686
871
  }
@@ -696,7 +881,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
696
881
  }
697
882
  /** The video's state on the element, for `mattebox-player[paused]` and the like. */
698
883
  reflect() {
699
- const video = this.media;
884
+ const video = this.playback.media;
700
885
  this.reflecting = true;
701
886
  const held = this.getAttribute(SWITCHING);
702
887
  const paused = held === null ? video.paused : held === "paused";
@@ -705,6 +890,9 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
705
890
  this.toggleAttribute("ended", video.ended);
706
891
  this.toggleAttribute("muted", video.muted);
707
892
  this.toggleAttribute("audio", this.audio());
893
+ const projection = this.projection;
894
+ if (projection === null) this.removeAttribute("projection");
895
+ else this.setAttribute("projection", projection);
708
896
  this.toggleAttribute("started", this.started);
709
897
  this.toggleAttribute("waiting", this.waiting);
710
898
  this.toggleAttribute("error", this.failure !== null);
@@ -720,7 +908,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
720
908
  */
721
909
  audio() {
722
910
  var _this$getAttribute3;
723
- const video = this.media;
911
+ const video = this.node;
724
912
  if (video.readyState >= HTMLMediaElement.HAVE_METADATA) return video.videoWidth === 0 && video.videoHeight === 0;
725
913
  const src = this.getAttribute("src");
726
914
  const type = (_this$getAttribute3 = this.getAttribute("type")) !== null && _this$getAttribute3 !== void 0 ? _this$getAttribute3 : src === null ? void 0 : inferType(src);
@@ -753,7 +941,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
753
941
  return;
754
942
  }
755
943
  if (name === CHAPTERS) {
756
- this.chapters();
944
+ this.chaptersAttribute();
757
945
  return;
758
946
  }
759
947
  if (name === LAYOUT) {
@@ -765,7 +953,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
765
953
  return;
766
954
  }
767
955
  if (name === PLAYSINLINE) {
768
- this.media.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== "false");
956
+ this.node.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== "false");
769
957
  return;
770
958
  }
771
959
  if (name === "preset") this.enqueue(() => this.discard());
@@ -783,7 +971,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
783
971
  mode() {
784
972
  const value = this.getAttribute(CONTROLS);
785
973
  const custom = value === "custom";
786
- this.media.controls = !custom && value !== "none";
974
+ this.node.controls = !custom && value !== "none";
787
975
  if (custom) this.surface.clear();
788
976
  else this.showBlock();
789
977
  if (!custom) {
@@ -795,10 +983,10 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
795
983
  }
796
984
  }
797
985
  /** Hands the `chapters` attribute to the engine, or keeps a hidden chapters track on the video for it. */
798
- chapters() {
799
- var _this$current$engine8, _this$current8;
986
+ chaptersAttribute() {
987
+ var _this$current$engine10, _this$current13;
800
988
  const url = this.getAttribute(CHAPTERS);
801
- const engine = (_this$current$engine8 = (_this$current8 = this.current) === null || _this$current8 === void 0 ? void 0 : _this$current8.engine) !== null && _this$current$engine8 !== void 0 ? _this$current$engine8 : null;
989
+ const engine = (_this$current$engine10 = (_this$current13 = this.current) === null || _this$current13 === void 0 ? void 0 : _this$current13.engine) !== null && _this$current$engine10 !== void 0 ? _this$current$engine10 : null;
802
990
  const api = engine === null ? void 0 : namespaces(engine).chapters;
803
991
  if (api !== void 0) {
804
992
  var _this$track;
@@ -817,20 +1005,20 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
817
1005
  return;
818
1006
  }
819
1007
  const held = this.track;
820
- if (held !== null && held.parentNode === this.media && held.getAttribute("src") === url) return;
1008
+ if (held !== null && held.parentNode === this.node && held.getAttribute("src") === url) return;
821
1009
  held === null || held === void 0 || held.remove();
822
1010
  const track = document.createElement("track");
823
1011
  track.kind = "chapters";
824
1012
  track.src = url;
825
1013
  this.track = track;
826
- this.media.append(track);
1014
+ this.node.append(track);
827
1015
  track.track.mode = "hidden";
828
1016
  }
829
1017
  forward(name) {
830
1018
  const value = this.getAttribute(name);
831
- if (value === null) this.media.removeAttribute(name);
832
- else this.media.setAttribute(name, value);
833
- if (name === "muted") this.media.muted = value !== null;
1019
+ if (value === null) this.node.removeAttribute(name);
1020
+ else this.node.setAttribute(name, value);
1021
+ if (name === "muted") this.node.muted = value !== null;
834
1022
  }
835
1023
  enqueue(task) {
836
1024
  this.queue = this.queue.then(task, task).catch(() => void 0);
@@ -869,6 +1057,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
869
1057
  var _this4 = this;
870
1058
  return _asyncToGenerator(function* () {
871
1059
  _this4.unmount();
1060
+ if (!_this4.hasAttribute("poster")) _this4.node.removeAttribute("poster");
872
1061
  if (!_this4.isConnected) return;
873
1062
  const sources = _this4.wanted();
874
1063
  _this4.tried = JSON.stringify(sources);
@@ -921,14 +1110,14 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
921
1110
  var _namespaces$chapters;
922
1111
  (_namespaces$chapters = namespaces(session.engine).chapters) === null || _namespaces$chapters === void 0 || _namespaces$chapters.set(chapters);
923
1112
  }
924
- this.chapters();
1113
+ this.chaptersAttribute();
925
1114
  }
926
1115
  ensure() {
927
1116
  var _this5 = this;
928
1117
  return _asyncToGenerator(function* () {
929
1118
  if (_this5.core !== null) return _this5.core;
930
1119
  const connectors = _this5.options.connectors;
931
- const core = createPlayer(_this5.media, _objectSpread2({ handlers: yield _this5.chain() }, connectors === void 0 ? {} : { connectors }));
1120
+ const core = createPlayer(_this5.node, _objectSpread2({ handlers: yield _this5.chain() }, connectors === void 0 ? {} : { connectors }));
932
1121
  _this5.offs.push(core.on("programme", (programme) => {
933
1122
  _this5.programmed(programme);
934
1123
  }), core.on("sourcechange", (session) => {
@@ -946,6 +1135,12 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
946
1135
  (_this$offTracks = _this5.offTracks) === null || _this$offTracks === void 0 || _this$offTracks.call(_this5);
947
1136
  _this5.offTracks = (_session$engine$on = session === null || session === void 0 || (_session$engine = session.engine) === null || _session$engine === void 0 ? void 0 : _session$engine.on("tracks:selected", () => _this5.tracks())) !== null && _session$engine$on !== void 0 ? _session$engine$on : null;
948
1137
  if (session !== null && _this5.isConnected) _this5.adopt(session);
1138
+ const handoff = _this5.handoff;
1139
+ _this5.handoff = null;
1140
+ if (session !== null && _this5.away) {
1141
+ var _ref2, _handoff$at, _handoff$playing;
1142
+ _this5.hand(session.source, (_ref2 = (_handoff$at = handoff === null || handoff === void 0 ? void 0 : handoff.at) !== null && _handoff$at !== void 0 ? _handoff$at : session.source.start) !== null && _ref2 !== void 0 ? _ref2 : null, (_handoff$playing = handoff === null || handoff === void 0 ? void 0 : handoff.playing) !== null && _handoff$playing !== void 0 ? _handoff$playing : true, true);
1143
+ }
949
1144
  _this5.emit("sourcechange", session);
950
1145
  }), core.on("error", (error) => {
951
1146
  _this5.report(error);
@@ -955,6 +1150,16 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
955
1150
  })();
956
1151
  }
957
1152
  /**
1153
+ * An add-on or an element inside the player needs the engine, so Safari's
1154
+ * own HLS is not the default. Read at each load: an element may come later.
1155
+ */
1156
+ needsEngine() {
1157
+ var _this$options$addons2;
1158
+ if (((_this$options$addons2 = this.options.addons) !== null && _this$options$addons2 !== void 0 ? _this$options$addons2 : []).some((addon) => addon.engine === true)) return true;
1159
+ for (const element of this.querySelectorAll("*")) if (element.needsEngine === true) return true;
1160
+ return false;
1161
+ }
1162
+ /**
958
1163
  * Read at each use, not once in the constructor. Importing the package
959
1164
  * registers the element, and the parser's elements are constructed then,
960
1165
  * before the page's own `define()` call can run.
@@ -971,8 +1176,10 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
971
1176
  const config = _this6.options.config === void 0 ? {} : { config: _this6.options.config };
972
1177
  const native = (stages) => nativeHandler({
973
1178
  prefer: (source, env) => {
974
- var _this$options$addons2;
975
- return _this6.getAttribute(NATIVE_HLS) !== "off" && !((_this$options$addons2 = _this6.options.addons) !== null && _this$options$addons2 !== void 0 ? _this$options$addons2 : []).some((addon) => addon.engine === true) && preferNativeHls(source, env);
1179
+ const asked = _this6.getAttribute(NATIVE_HLS);
1180
+ if (asked === "off") return false;
1181
+ if (asked !== "on" && _this6.needsEngine()) return false;
1182
+ return preferNativeHls(source, env);
976
1183
  },
977
1184
  drm: () => _this6.drm(stages)
978
1185
  });
@@ -24,7 +24,7 @@ var MbxAirplayButton = class extends Component {
24
24
  root.append(style(BUTTON_STYLE), this.button);
25
25
  }
26
26
  attach(player) {
27
- const api = airplay(player.video);
27
+ const api = airplay(player.media);
28
28
  this.api = api;
29
29
  this.keep(api.watch(() => {
30
30
  this.render();
@@ -1,8 +1,8 @@
1
- import { layout, trackNames } from "../controls/track-names.js";
2
1
  import { icon } from "../controls/icons.js";
3
- import { show } from "./shared.js";
4
2
  import { nativeTracks, onNativeTracks } from "../controls/native-tracks.js";
3
+ import { layout, trackNames } from "../controls/track-names.js";
5
4
  import { MenuElement, single } from "./menu-element.js";
5
+ import { show } from "./shared.js";
6
6
  import { isAudioDescription, isOriginal } from "mattebox";
7
7
  // src/elements/audio-menu.ts
8
8
  /** A track's channel layout, from its first rendition: `audioObjects` `JOC` is Dolby Atmos. */
@@ -51,6 +51,7 @@ var MbxAudioMenu = class extends MenuElement {
51
51
  }
52
52
  constructor() {
53
53
  super(...single("audio"));
54
+ this.leaves = "remote";
54
55
  this.engine = null;
55
56
  show(this.slots, "default");
56
57
  }
@@ -64,7 +65,7 @@ var MbxAudioMenu = class extends MenuElement {
64
65
  const tick = () => {
65
66
  this.render();
66
67
  };
67
- return engine === null ? onNativeTracks(player.video, "audioTracks", tick) : onTracks(engine, tick);
68
+ return engine === null ? onNativeTracks(player.media, "audioTracks", tick) : onTracks(engine, tick);
68
69
  });
69
70
  }
70
71
  /** The native session's audio tracks as entries, and the enabled one's. */