@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
package/dist/element.js CHANGED
@@ -1,8 +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
7
  import { addLocale, load, onLocales, registered, wordsNow } from "./locales.js";
8
+ import { createMedia } from "./media.js";
6
9
  import { namespaces } from "./namespaces.js";
7
10
  import { drmGuard, resolvePreset } from "./presets.js";
8
11
  import { STYLE } from "./style.js";
@@ -41,11 +44,12 @@ function emeAvailable() {
41
44
  return drmGuard().without === void 0;
42
45
  }
43
46
  /** `source` without its DRM, for a browser without EME. */
44
- function withoutDrm({ url, type, videoTracks }) {
47
+ function withoutDrm({ url, type, videoTracks, projection }) {
45
48
  return {
46
49
  url,
47
50
  ...type === void 0 ? {} : { type },
48
- ...videoTracks === void 0 ? {} : { videoTracks }
51
+ ...videoTracks === void 0 ? {} : { videoTracks },
52
+ ...projection === void 0 ? {} : { projection }
49
53
  };
50
54
  }
51
55
  const CERTIFICATE_URL = "certificate-url";
@@ -196,6 +200,12 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
196
200
  this.offs = [];
197
201
  this.attached = /* @__PURE__ */ new Map();
198
202
  this.interruption = null;
203
+ this.device = null;
204
+ this.away = false;
205
+ this.uncast = null;
206
+ this.target = null;
207
+ this.handoff = null;
208
+ this.frozenLive = false;
199
209
  this.queue = Promise.resolve();
200
210
  this.pending = false;
201
211
  this.original = null;
@@ -211,24 +221,36 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
211
221
  this.heardAudio = void 0;
212
222
  this.heardText = void 0;
213
223
  this.offTracks = null;
214
- this.media = document.createElement("video");
215
- this.media.controls = true;
216
- this.media.setAttribute(PLAYSINLINE, "");
217
- for (const name of STATE_EVENTS) this.media.addEventListener(name, () => {
224
+ this.node = document.createElement("video");
225
+ this.playback = createMedia(this.node);
226
+ this.node.controls = true;
227
+ this.node.setAttribute(PLAYSINLINE, "");
228
+ for (const name of STATE_EVENTS) this.playback.media.addEventListener(name, () => {
218
229
  const was = this.waiting;
219
230
  this.note(name);
220
231
  this.reflect();
221
232
  this.tell(name, was);
222
233
  });
223
- const lists = this.media;
234
+ const lists = this.node;
224
235
  for (const list of [lists.audioTracks, lists.textTracks]) list?.addEventListener("change", () => {
225
236
  this.tracks();
226
237
  });
227
- this.media.addEventListener("playing", () => {
238
+ this.node.addEventListener("playing", () => {
228
239
  this.failure = null;
229
240
  this.reflect();
230
241
  });
231
- this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));
242
+ this.node.addEventListener("play", () => {
243
+ if (this.away) this.node.pause();
244
+ });
245
+ this.node.addEventListener("webkitcurrentplaybacktargetiswirelesschanged", () => {
246
+ if (this.device !== null) return;
247
+ const wireless = this.node.webkitCurrentPlaybackTargetIsWireless === true;
248
+ this.aim(wireless ? {
249
+ kind: "airplay",
250
+ name: ""
251
+ } : null);
252
+ });
253
+ this.marks = createMarkers(this.playback.media, (name, detail) => this.emit(name, detail));
232
254
  this.breakMarks = createBreakMarks((list) => this.emit("breakschange", list));
233
255
  this.tracking = createTrackers(this, () => this.emit("trackerschange", this.tracking.list));
234
256
  this.stage = document.createElement("div");
@@ -247,9 +269,21 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
247
269
  style.textContent = STYLE;
248
270
  root.append(style, this.stage, this.surface.root, this.voice.root);
249
271
  }
250
- /** The media element. Everything the browser already does is here. */
251
- get video() {
252
- return this.media;
272
+ /**
273
+ * What plays: the video, with everything the browser already does. While
274
+ * a device plays in its place, the playback members are the device's.
275
+ * A proxy and not the node: a page that needs the node reads the
276
+ * `<video>` child of the player.
277
+ */
278
+ get media() {
279
+ return this.playback.media;
280
+ }
281
+ /**
282
+ * The programme's chapters, in order: the engine's when its session holds
283
+ * some, else the video's chapters track. Read again on each access.
284
+ */
285
+ get chapters() {
286
+ return chapters(this.node, this.engine);
253
287
  }
254
288
  /** The ranges the page named in this source: credits to skip, parts that must not play. */
255
289
  get markers() {
@@ -356,7 +390,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
356
390
  * replaces it.
357
391
  */
358
392
  switchSource(source) {
359
- const media = this.media;
393
+ const media = this.playback.media;
360
394
  const at = Number.isFinite(media.duration) ? media.currentTime : null;
361
395
  const playing = !media.paused;
362
396
  const had = chosen(this.current?.engine ?? null);
@@ -378,7 +412,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
378
412
  * handler plays it.
379
413
  */
380
414
  interrupt(source) {
381
- const media = this.media;
415
+ const media = this.playback.media;
382
416
  this.interruption ??= {
383
417
  at: Number.isFinite(media.duration) ? media.currentTime : null,
384
418
  playing: !media.paused,
@@ -388,7 +422,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
388
422
  const core = await this.ensure();
389
423
  await core.interrupt(source);
390
424
  this.current = core.session;
391
- media.play().catch(() => void 0);
425
+ if (this.away) this.hand(source, null, true, false);
426
+ else this.node.play().catch(() => void 0);
392
427
  });
393
428
  }
394
429
  /**
@@ -407,7 +442,9 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
407
442
  await core.resume(at ?? void 0);
408
443
  this.current = core.session;
409
444
  restore(this.current?.engine ?? null, left.had);
410
- if (playing) this.media.play().catch(() => void 0);
445
+ const session = this.current;
446
+ if (this.device !== null && session !== null) this.hand(session.source, at, playing, true);
447
+ else if (playing) this.node.play().catch(() => void 0);
411
448
  });
412
449
  }
413
450
  /** `interrupt` plays in the programme's place. */
@@ -424,6 +461,19 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
424
461
  get videoSources() {
425
462
  return this.original?.videoTracks ?? [];
426
463
  }
464
+ /**
465
+ * How the playing picture maps onto a sphere, for 360° video: the
466
+ * source's `projection`, else the manifest's, else null for a flat one.
467
+ * A version of `videoSources` is flat.
468
+ */
469
+ get projection() {
470
+ if (this.version !== null) return null;
471
+ const given = this.original?.projection;
472
+ if (given !== void 0) return given;
473
+ const track = this.current?.engine?.tracks.active("video");
474
+ for (const rendition of track?.renditions ?? []) if (rendition.projection !== void 0) return rendition.projection;
475
+ return null;
476
+ }
427
477
  /** The version of `videoSources` that plays, or null for the source itself. */
428
478
  get videoSource() {
429
479
  return this.version;
@@ -438,7 +488,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
438
488
  const programme = this.original;
439
489
  if (programme === null || track === this.version) return;
440
490
  if (track !== null && programme.videoTracks?.includes(track) !== true) return;
441
- const media = this.media;
491
+ const media = this.playback.media;
442
492
  const at = Number.isFinite(media.duration) ? media.currentTime : null;
443
493
  const playing = !media.paused;
444
494
  const had = chosen(this.current?.engine ?? null);
@@ -453,7 +503,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
453
503
  * before, so the controls show that state through the load.
454
504
  */
455
505
  swap(source, at, playing, had, hold) {
456
- const media = this.media;
506
+ const media = this.node;
457
507
  this.held?.();
458
508
  let release = null;
459
509
  if (hold) {
@@ -472,6 +522,10 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
472
522
  this.enqueue(async () => {
473
523
  const core = await this.ensure();
474
524
  this.switching = true;
525
+ if (this.away) this.handoff = {
526
+ at,
527
+ playing
528
+ };
475
529
  try {
476
530
  await core.load([source]);
477
531
  } catch {
@@ -480,11 +534,136 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
480
534
  } finally {
481
535
  this.switching = false;
482
536
  }
483
- resume(media, at, playing);
484
- if (release !== null) onNextFrame(media, at, release);
537
+ if (this.away) release?.();
538
+ else {
539
+ resume(media, at, playing);
540
+ if (release !== null) onNextFrame(media, at, release);
541
+ }
485
542
  restore(this.current?.engine ?? null, had);
486
543
  });
487
544
  }
545
+ /** The device that plays in the video's place, its kind and its name, or null. The `casting` attribute carries the kind. */
546
+ get casting() {
547
+ return this.target;
548
+ }
549
+ /**
550
+ * Hands playback to a device, for a cast package. From here `media`
551
+ * reads the device for the members `remote.media` has, the video stays
552
+ * paused, and every load goes to the device. Returns the function that
553
+ * ends the cast: the video takes the device's position and play state
554
+ * back, with no new load. A second call ends the cast before it.
555
+ */
556
+ cast(remote, options = {}) {
557
+ this.uncast?.();
558
+ this.device = remote;
559
+ this.aim(remote.target);
560
+ const session = this.current;
561
+ if (this.interruption !== null) {} else if (options.adopted === true || session === null) {
562
+ this.freeze();
563
+ this.away = true;
564
+ this.playback.attach(remote.media);
565
+ } else this.hand(session.source, this.position(), !this.node.paused, true);
566
+ const end = () => {
567
+ if (this.device !== remote) return;
568
+ const time = remote.media.currentTime;
569
+ const playing = !remote.media.paused;
570
+ const away = this.away;
571
+ this.device = null;
572
+ this.away = false;
573
+ this.uncast = null;
574
+ this.playback.detach();
575
+ this.aim(null);
576
+ if (!away) return;
577
+ this.current?.engine?.resume();
578
+ if (this.current !== null && !this.frozenLive && Number.isFinite(time)) this.node.currentTime = time;
579
+ if (playing) this.node.play().catch(() => void 0);
580
+ };
581
+ this.uncast = end;
582
+ return end;
583
+ }
584
+ /**
585
+ * Where the video is, for a device: seconds on demand, and for live null
586
+ * at the edge or the clock time behind it. Read before the engine is
587
+ * suspended, which no longer says where the edge is.
588
+ */
589
+ position() {
590
+ const node = this.node;
591
+ const engine = this.current?.engine ?? null;
592
+ const edge = live(engine);
593
+ if (edge !== void 0) {
594
+ if (edge.atEdge) return null;
595
+ const date = engine === null ? null : namespaces(engine).pdt?.toWallClock(node.currentTime) ?? null;
596
+ return date === null ? null : { date };
597
+ }
598
+ return Number.isFinite(node.duration) ? node.currentTime : null;
599
+ }
600
+ /** Pauses the video and stops the engine's requests. The source stays loaded, for the chapters and the thumbnails. */
601
+ freeze() {
602
+ const engine = this.current?.engine ?? null;
603
+ this.frozenLive = live(engine) !== void 0;
604
+ this.node.pause();
605
+ engine?.suspend();
606
+ }
607
+ /** The device plays `source` in the video's place: the programme's own, or one that interrupts it. */
608
+ hand(source, at, playing, own) {
609
+ const remote = this.device;
610
+ if (remote === null) return;
611
+ this.freeze();
612
+ if (!this.away) {
613
+ this.away = true;
614
+ this.playback.attach(remote.media);
615
+ }
616
+ const addons = {};
617
+ if (own) for (const addon of this.attached.keys()) {
618
+ const data = addon.remoteData?.(this);
619
+ if (data !== void 0) addons[addon.name] = data;
620
+ }
621
+ const chapters = own ? this.getAttribute(CHAPTERS) : null;
622
+ const thumbnails = own ? this.getAttribute("thumbnails") : null;
623
+ const load = {
624
+ programme: own ? this.programme : null,
625
+ at,
626
+ playing,
627
+ live: this.frozenLive,
628
+ markers: own ? this.marks.list : [],
629
+ ...chapters === null ? {} : { chapters },
630
+ ...thumbnails === null ? {} : { thumbnails },
631
+ textTracks: own ? this.textFiles() : [],
632
+ addons
633
+ };
634
+ remote.load(source, load).catch(() => {
635
+ if (this.device !== remote) return;
636
+ this.report({
637
+ category: "remote",
638
+ code: "REMOTE_LOAD_FAILED",
639
+ fatal: false,
640
+ recoverable: true,
641
+ handler: this.current?.handler ?? null
642
+ });
643
+ });
644
+ }
645
+ /** The subtitle and caption files the page gave the video as `<track>` children. */
646
+ textFiles() {
647
+ const files = [];
648
+ for (const track of Array.from(this.node.querySelectorAll("track[src]"))) {
649
+ if (track.kind !== "subtitles" && track.kind !== "captions") continue;
650
+ files.push({
651
+ url: track.src,
652
+ kind: track.kind,
653
+ label: track.label,
654
+ language: track.srclang
655
+ });
656
+ }
657
+ return files;
658
+ }
659
+ /** Sets the device that plays: the `casting` attribute carries its kind, and `castingchange` the target. */
660
+ aim(target) {
661
+ if (this.target === null && target === null) return;
662
+ this.target = target;
663
+ if (target === null) this.removeAttribute("casting");
664
+ else this.setAttribute("casting", target.kind);
665
+ this.emit("castingchange", target);
666
+ }
488
667
  /** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
489
668
  get player() {
490
669
  return this.core;
@@ -517,7 +696,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
517
696
  /** Shows the block, for `block()` and for a programme a connector blocked, which loaded nothing. */
518
697
  refuse(block) {
519
698
  this.stop = block;
520
- this.media.pause();
699
+ this.node.pause();
521
700
  clearTimeout(this.slow);
522
701
  const [title, message] = this.blockWords(block);
523
702
  if (this.querySelector("mbx-error-screen") === null) this.voice.tell(message === "" ? title : `${title}. ${message}`);
@@ -560,8 +739,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
560
739
  const metadata = programme?.metadata;
561
740
  if (metadata?.markers !== void 0) this.marks.set(metadata.markers);
562
741
  if (!this.hasAttribute("poster")) {
563
- if (metadata?.poster === void 0) this.media.removeAttribute("poster");
564
- else this.media.poster = metadata.poster;
742
+ if (metadata?.poster === void 0) this.node.removeAttribute("poster");
743
+ else this.node.poster = metadata.poster;
565
744
  }
566
745
  if (programme?.block !== void 0) this.refuse(programme.block);
567
746
  this.emit("programmechange", programme);
@@ -578,7 +757,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
578
757
  this.surface.inform(title, message);
579
758
  }
580
759
  connectedCallback() {
581
- if (this.media.parentNode !== this) this.append(this.media);
760
+ if (this.node.parentNode !== this) this.append(this.node);
582
761
  for (const name of FORWARDED) this.forward(name);
583
762
  this.reflect();
584
763
  if (typeof ResizeObserver !== "undefined") {
@@ -621,7 +800,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
621
800
  this.started = true;
622
801
  this.waiting = false;
623
802
  } else if (event === "waiting") this.waiting = true;
624
- else if (event === "canplay") this.waiting = false;
803
+ else if (event === "canplay" || event === "pause" && this.away) this.waiting = false;
625
804
  else if (event === "emptied") {
626
805
  if (this.held === null) this.started = false;
627
806
  this.waiting = false;
@@ -632,7 +811,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
632
811
  /** Says a play or a pause, and a wait once it has lasted `LOADING_MS`. */
633
812
  tell(event, was) {
634
813
  if (event === "play" && this.held === null) this.voice.say("playing", "saidPlaying", "Playing");
635
- if (event === "pause" && !this.media.ended && this.held === null) this.voice.say("paused", "saidPaused", "Paused");
814
+ if (event === "pause" && !this.playback.media.ended && this.held === null) this.voice.say("paused", "saidPaused", "Paused");
636
815
  if (this.waiting === was) return;
637
816
  clearTimeout(this.slow);
638
817
  if (this.waiting) this.slow = setTimeout(() => {
@@ -654,9 +833,9 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
654
833
  audio = sound === null ? "" : trackName(sound.name, sound.lang, this.locale);
655
834
  text = words === null || words.forced === true ? null : trackName(words.name, words.lang, this.locale);
656
835
  } else {
657
- const video = this.media;
836
+ const video = this.node;
658
837
  const sound = Array.from(video.audioTracks ?? []).find((track) => track.enabled);
659
- const words = Array.from(this.media.textTracks).find((track) => (track.kind === "subtitles" || track.kind === "captions") && track.mode === "showing");
838
+ const words = Array.from(this.node.textTracks).find((track) => (track.kind === "subtitles" || track.kind === "captions") && track.mode === "showing");
660
839
  audio = sound === void 0 ? "" : trackName(sound.label, sound.language, this.locale);
661
840
  text = words === void 0 ? null : trackName(words.label, words.language, this.locale);
662
841
  }
@@ -672,7 +851,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
672
851
  }
673
852
  /** The video's state on the element, for `mattebox-player[paused]` and the like. */
674
853
  reflect() {
675
- const video = this.media;
854
+ const video = this.playback.media;
676
855
  this.reflecting = true;
677
856
  const held = this.getAttribute(SWITCHING);
678
857
  const paused = held === null ? video.paused : held === "paused";
@@ -681,6 +860,9 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
681
860
  this.toggleAttribute("ended", video.ended);
682
861
  this.toggleAttribute("muted", video.muted);
683
862
  this.toggleAttribute("audio", this.audio());
863
+ const projection = this.projection;
864
+ if (projection === null) this.removeAttribute("projection");
865
+ else this.setAttribute("projection", projection);
684
866
  this.toggleAttribute("started", this.started);
685
867
  this.toggleAttribute("waiting", this.waiting);
686
868
  this.toggleAttribute("error", this.failure !== null);
@@ -695,7 +877,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
695
877
  * the start rather than from its metadata.
696
878
  */
697
879
  audio() {
698
- const video = this.media;
880
+ const video = this.node;
699
881
  if (video.readyState >= HTMLMediaElement.HAVE_METADATA) return video.videoWidth === 0 && video.videoHeight === 0;
700
882
  const src = this.getAttribute("src");
701
883
  return (this.getAttribute("type") ?? (src === null ? void 0 : inferType(src)))?.startsWith("audio/") === true;
@@ -726,7 +908,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
726
908
  return;
727
909
  }
728
910
  if (name === CHAPTERS) {
729
- this.chapters();
911
+ this.chaptersAttribute();
730
912
  return;
731
913
  }
732
914
  if (name === LAYOUT) {
@@ -738,7 +920,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
738
920
  return;
739
921
  }
740
922
  if (name === PLAYSINLINE) {
741
- this.media.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== "false");
923
+ this.node.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== "false");
742
924
  return;
743
925
  }
744
926
  if (name === "preset") this.enqueue(() => this.discard());
@@ -756,7 +938,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
756
938
  mode() {
757
939
  const value = this.getAttribute(CONTROLS);
758
940
  const custom = value === "custom";
759
- this.media.controls = !custom && value !== "none";
941
+ this.node.controls = !custom && value !== "none";
760
942
  if (custom) this.surface.clear();
761
943
  else this.showBlock();
762
944
  if (!custom) {
@@ -768,7 +950,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
768
950
  }
769
951
  }
770
952
  /** Hands the `chapters` attribute to the engine, or keeps a hidden chapters track on the video for it. */
771
- chapters() {
953
+ chaptersAttribute() {
772
954
  const url = this.getAttribute(CHAPTERS);
773
955
  const engine = this.current?.engine ?? null;
774
956
  const api = engine === null ? void 0 : namespaces(engine).chapters;
@@ -787,20 +969,20 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
787
969
  return;
788
970
  }
789
971
  const held = this.track;
790
- if (held !== null && held.parentNode === this.media && held.getAttribute("src") === url) return;
972
+ if (held !== null && held.parentNode === this.node && held.getAttribute("src") === url) return;
791
973
  held?.remove();
792
974
  const track = document.createElement("track");
793
975
  track.kind = "chapters";
794
976
  track.src = url;
795
977
  this.track = track;
796
- this.media.append(track);
978
+ this.node.append(track);
797
979
  track.track.mode = "hidden";
798
980
  }
799
981
  forward(name) {
800
982
  const value = this.getAttribute(name);
801
- if (value === null) this.media.removeAttribute(name);
802
- else this.media.setAttribute(name, value);
803
- if (name === "muted") this.media.muted = value !== null;
983
+ if (value === null) this.node.removeAttribute(name);
984
+ else this.node.setAttribute(name, value);
985
+ if (name === "muted") this.node.muted = value !== null;
804
986
  }
805
987
  enqueue(task) {
806
988
  this.queue = this.queue.then(task, task).catch(() => void 0);
@@ -837,6 +1019,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
837
1019
  }
838
1020
  async run() {
839
1021
  this.unmount();
1022
+ if (!this.hasAttribute("poster")) this.node.removeAttribute("poster");
840
1023
  if (!this.isConnected) return;
841
1024
  const sources = this.wanted();
842
1025
  this.tried = JSON.stringify(sources);
@@ -896,12 +1079,12 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
896
1079
  this.configure(session);
897
1080
  const chapters = this.core?.programme?.metadata?.chapters;
898
1081
  if (chapters !== void 0 && session.engine !== null && this.getAttribute(CHAPTERS) === null) namespaces(session.engine).chapters?.set(chapters);
899
- this.chapters();
1082
+ this.chaptersAttribute();
900
1083
  }
901
1084
  async ensure() {
902
1085
  if (this.core !== null) return this.core;
903
1086
  const connectors = this.options.connectors;
904
- const core = createPlayer(this.media, {
1087
+ const core = createPlayer(this.node, {
905
1088
  handlers: await this.chain(),
906
1089
  ...connectors === void 0 ? {} : { connectors }
907
1090
  });
@@ -920,6 +1103,9 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
920
1103
  this.offTracks?.();
921
1104
  this.offTracks = session?.engine?.on("tracks:selected", () => this.tracks()) ?? null;
922
1105
  if (session !== null && this.isConnected) this.adopt(session);
1106
+ const handoff = this.handoff;
1107
+ this.handoff = null;
1108
+ if (session !== null && this.away) this.hand(session.source, handoff?.at ?? session.source.start ?? null, handoff?.playing ?? true, true);
923
1109
  this.emit("sourcechange", session);
924
1110
  }), core.on("error", (error) => {
925
1111
  this.report(error);
@@ -928,6 +1114,15 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
928
1114
  return core;
929
1115
  }
930
1116
  /**
1117
+ * An add-on or an element inside the player needs the engine, so Safari's
1118
+ * own HLS is not the default. Read at each load: an element may come later.
1119
+ */
1120
+ needsEngine() {
1121
+ if ((this.options.addons ?? []).some((addon) => addon.engine === true)) return true;
1122
+ for (const element of this.querySelectorAll("*")) if (element.needsEngine === true) return true;
1123
+ return false;
1124
+ }
1125
+ /**
931
1126
  * Read at each use, not once in the constructor. Importing the package
932
1127
  * registers the element, and the parser's elements are constructed then,
933
1128
  * before the page's own `define()` call can run.
@@ -939,7 +1134,12 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
939
1134
  if (this.options.handlers !== void 0) return this.options.handlers;
940
1135
  const config = this.options.config === void 0 ? {} : { config: this.options.config };
941
1136
  const native = (stages) => nativeHandler({
942
- prefer: (source, env) => this.getAttribute(NATIVE_HLS) !== "off" && !(this.options.addons ?? []).some((addon) => addon.engine === true) && preferNativeHls(source, env),
1137
+ prefer: (source, env) => {
1138
+ const asked = this.getAttribute(NATIVE_HLS);
1139
+ if (asked === "off") return false;
1140
+ if (asked !== "on" && this.needsEngine()) return false;
1141
+ return preferNativeHls(source, env);
1142
+ },
943
1143
  drm: () => this.drm(stages)
944
1144
  });
945
1145
  if (this.isConnected) this.attachAddons();