@mattebox/player 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/dist/cdn/mattebox-player.min.js +3 -435
  2. package/dist/controls/airplay.js +28 -44
  3. package/dist/controls/airplay.js.map +1 -1
  4. package/dist/controls/chapters.d.ts +22 -11
  5. package/dist/controls/chapters.d.ts.map +1 -1
  6. package/dist/controls/chapters.js +87 -73
  7. package/dist/controls/chapters.js.map +1 -1
  8. package/dist/controls/cues.d.ts +0 -22
  9. package/dist/controls/cues.d.ts.map +1 -1
  10. package/dist/controls/cues.js +161 -191
  11. package/dist/controls/cues.js.map +1 -1
  12. package/dist/controls/fullscreen.js +52 -70
  13. package/dist/controls/fullscreen.js.map +1 -1
  14. package/dist/controls/icons.d.ts +1 -1
  15. package/dist/controls/icons.d.ts.map +1 -1
  16. package/dist/controls/icons.js +46 -70
  17. package/dist/controls/icons.js.map +1 -1
  18. package/dist/controls/menu.d.ts +7 -4
  19. package/dist/controls/menu.d.ts.map +1 -1
  20. package/dist/controls/menu.js +241 -223
  21. package/dist/controls/menu.js.map +1 -1
  22. package/dist/controls/pip.js +35 -49
  23. package/dist/controls/pip.js.map +1 -1
  24. package/dist/controls/ranges.js +42 -37
  25. package/dist/controls/ranges.js.map +1 -1
  26. package/dist/controls/session.d.ts +6 -1
  27. package/dist/controls/session.d.ts.map +1 -1
  28. package/dist/controls/session.js +41 -26
  29. package/dist/controls/session.js.map +1 -1
  30. package/dist/controls/slider.d.ts +2 -2
  31. package/dist/controls/slider.d.ts.map +1 -1
  32. package/dist/controls/slider.js +151 -159
  33. package/dist/controls/slider.js.map +1 -1
  34. package/dist/controls/time.js +17 -17
  35. package/dist/controls/time.js.map +1 -1
  36. package/dist/dom.d.ts +6 -0
  37. package/dist/dom.d.ts.map +1 -1
  38. package/dist/dom.js +28 -19
  39. package/dist/dom.js.map +1 -1
  40. package/dist/element-entry.js +9 -6
  41. package/dist/element-entry.js.map +1 -1
  42. package/dist/element.d.ts +4 -2
  43. package/dist/element.d.ts.map +1 -1
  44. package/dist/element.js +384 -443
  45. package/dist/element.js.map +1 -1
  46. package/dist/elements/airplay-button.js +51 -53
  47. package/dist/elements/airplay-button.js.map +1 -1
  48. package/dist/elements/audio-menu.js +62 -63
  49. package/dist/elements/audio-menu.js.map +1 -1
  50. package/dist/elements/chapters-menu.d.ts.map +1 -1
  51. package/dist/elements/chapters-menu.js +75 -65
  52. package/dist/elements/chapters-menu.js.map +1 -1
  53. package/dist/elements/component.d.ts +1 -1
  54. package/dist/elements/component.d.ts.map +1 -1
  55. package/dist/elements/component.js +86 -89
  56. package/dist/elements/component.js.map +1 -1
  57. package/dist/elements/control-bar.d.ts +18 -5
  58. package/dist/elements/control-bar.d.ts.map +1 -1
  59. package/dist/elements/control-bar.js +282 -319
  60. package/dist/elements/control-bar.js.map +1 -1
  61. package/dist/elements/current-time.js +26 -25
  62. package/dist/elements/current-time.js.map +1 -1
  63. package/dist/elements/drm-badge.d.ts.map +1 -1
  64. package/dist/elements/drm-badge.js +107 -141
  65. package/dist/elements/drm-badge.js.map +1 -1
  66. package/dist/elements/duration.d.ts.map +1 -1
  67. package/dist/elements/duration.js +24 -21
  68. package/dist/elements/duration.js.map +1 -1
  69. package/dist/elements/error-screen.d.ts.map +1 -1
  70. package/dist/elements/error-screen.js +68 -102
  71. package/dist/elements/error-screen.js.map +1 -1
  72. package/dist/elements/fullscreen-button.js +48 -54
  73. package/dist/elements/fullscreen-button.js.map +1 -1
  74. package/dist/elements/live-button.d.ts.map +1 -1
  75. package/dist/elements/live-button.js +67 -94
  76. package/dist/elements/live-button.js.map +1 -1
  77. package/dist/elements/menu-element.js +31 -28
  78. package/dist/elements/menu-element.js.map +1 -1
  79. package/dist/elements/mute-button.js +58 -59
  80. package/dist/elements/mute-button.js.map +1 -1
  81. package/dist/elements/pip-button.js +54 -54
  82. package/dist/elements/pip-button.js.map +1 -1
  83. package/dist/elements/play-button.d.ts.map +1 -1
  84. package/dist/elements/play-button.js +73 -58
  85. package/dist/elements/play-button.js.map +1 -1
  86. package/dist/elements/quality-menu.js +66 -69
  87. package/dist/elements/quality-menu.js.map +1 -1
  88. package/dist/elements/remaining-time.d.ts.map +1 -1
  89. package/dist/elements/remaining-time.js +27 -24
  90. package/dist/elements/remaining-time.js.map +1 -1
  91. package/dist/elements/scan-button.d.ts +17 -0
  92. package/dist/elements/scan-button.d.ts.map +1 -0
  93. package/dist/elements/scan-button.js +117 -0
  94. package/dist/elements/scan-button.js.map +1 -0
  95. package/dist/elements/seek-bar.d.ts +93 -14
  96. package/dist/elements/seek-bar.d.ts.map +1 -1
  97. package/dist/elements/seek-bar.js +475 -335
  98. package/dist/elements/seek-bar.js.map +1 -1
  99. package/dist/elements/shared.d.ts +3 -11
  100. package/dist/elements/shared.d.ts.map +1 -1
  101. package/dist/elements/shared.js +44 -144
  102. package/dist/elements/shared.js.map +1 -1
  103. package/dist/elements/skip-button.d.ts.map +1 -1
  104. package/dist/elements/skip-button.js +54 -55
  105. package/dist/elements/skip-button.js.map +1 -1
  106. package/dist/elements/spacer.d.ts.map +1 -1
  107. package/dist/elements/spacer.js +12 -7
  108. package/dist/elements/spacer.js.map +1 -1
  109. package/dist/elements/speed-menu.js +60 -55
  110. package/dist/elements/speed-menu.js.map +1 -1
  111. package/dist/elements/spinner.d.ts.map +1 -1
  112. package/dist/elements/spinner.js +52 -78
  113. package/dist/elements/spinner.js.map +1 -1
  114. package/dist/elements/start-button.d.ts.map +1 -1
  115. package/dist/elements/start-button.js +107 -120
  116. package/dist/elements/start-button.js.map +1 -1
  117. package/dist/elements/subtitles-menu.js +95 -103
  118. package/dist/elements/subtitles-menu.js.map +1 -1
  119. package/dist/elements/time-element.d.ts.map +1 -1
  120. package/dist/elements/time-element.js +36 -28
  121. package/dist/elements/time-element.js.map +1 -1
  122. package/dist/elements/title.d.ts.map +1 -1
  123. package/dist/elements/title.js +105 -137
  124. package/dist/elements/title.js.map +1 -1
  125. package/dist/elements/volume-slider.d.ts.map +1 -1
  126. package/dist/elements/volume-slider.js +47 -45
  127. package/dist/elements/volume-slider.js.map +1 -1
  128. package/dist/elements/volume.d.ts.map +1 -1
  129. package/dist/elements/volume.js +42 -50
  130. package/dist/elements/volume.js.map +1 -1
  131. package/dist/entries/airplay-button.js +7 -7
  132. package/dist/entries/airplay-button.js.map +1 -1
  133. package/dist/entries/audio-menu.js +7 -6
  134. package/dist/entries/audio-menu.js.map +1 -1
  135. package/dist/entries/chapters-menu.js +7 -7
  136. package/dist/entries/chapters-menu.js.map +1 -1
  137. package/dist/entries/control-bar.js +7 -6
  138. package/dist/entries/control-bar.js.map +1 -1
  139. package/dist/entries/current-time.js +7 -6
  140. package/dist/entries/current-time.js.map +1 -1
  141. package/dist/entries/drm-badge.js +7 -6
  142. package/dist/entries/drm-badge.js.map +1 -1
  143. package/dist/entries/duration.js +7 -6
  144. package/dist/entries/duration.js.map +1 -1
  145. package/dist/entries/error-screen.js +7 -6
  146. package/dist/entries/error-screen.js.map +1 -1
  147. package/dist/entries/fullscreen-button.js +7 -6
  148. package/dist/entries/fullscreen-button.js.map +1 -1
  149. package/dist/entries/live-button.js +7 -6
  150. package/dist/entries/live-button.js.map +1 -1
  151. package/dist/entries/mute-button.js +7 -6
  152. package/dist/entries/mute-button.js.map +1 -1
  153. package/dist/entries/pip-button.js +7 -6
  154. package/dist/entries/pip-button.js.map +1 -1
  155. package/dist/entries/play-button.js +7 -6
  156. package/dist/entries/play-button.js.map +1 -1
  157. package/dist/entries/quality-menu.js +7 -6
  158. package/dist/entries/quality-menu.js.map +1 -1
  159. package/dist/entries/remaining-time.js +7 -7
  160. package/dist/entries/remaining-time.js.map +1 -1
  161. package/dist/entries/scan-button.d.ts +5 -0
  162. package/dist/entries/scan-button.d.ts.map +1 -0
  163. package/dist/entries/scan-button.js +9 -0
  164. package/dist/entries/scan-button.js.map +1 -0
  165. package/dist/entries/seek-bar.js +7 -6
  166. package/dist/entries/seek-bar.js.map +1 -1
  167. package/dist/entries/skip-button.js +7 -6
  168. package/dist/entries/skip-button.js.map +1 -1
  169. package/dist/entries/spacer.js +7 -6
  170. package/dist/entries/spacer.js.map +1 -1
  171. package/dist/entries/speed-menu.js +7 -6
  172. package/dist/entries/speed-menu.js.map +1 -1
  173. package/dist/entries/spinner.js +7 -7
  174. package/dist/entries/spinner.js.map +1 -1
  175. package/dist/entries/start-button.js +7 -6
  176. package/dist/entries/start-button.js.map +1 -1
  177. package/dist/entries/subtitles-menu.js +7 -6
  178. package/dist/entries/subtitles-menu.js.map +1 -1
  179. package/dist/entries/title.js +7 -7
  180. package/dist/entries/title.js.map +1 -1
  181. package/dist/entries/volume-slider.js +7 -6
  182. package/dist/entries/volume-slider.js.map +1 -1
  183. package/dist/entries/volume.js +9 -8
  184. package/dist/entries/volume.js.map +1 -1
  185. package/dist/es2015/controls/chapters.js +40 -7
  186. package/dist/es2015/controls/cues.js +1 -8
  187. package/dist/es2015/controls/icons.js +3 -1
  188. package/dist/es2015/controls/menu.js +27 -8
  189. package/dist/es2015/controls/session.js +16 -4
  190. package/dist/es2015/controls/slider.js +5 -4
  191. package/dist/es2015/dom.js +10 -1
  192. package/dist/es2015/element.js +23 -7
  193. package/dist/es2015/elements/chapters-menu.js +18 -10
  194. package/dist/es2015/elements/control-bar.js +41 -35
  195. package/dist/es2015/elements/drm-badge.js +1 -25
  196. package/dist/es2015/elements/duration.js +2 -1
  197. package/dist/es2015/elements/error-screen.js +1 -30
  198. package/dist/es2015/elements/live-button.js +1 -29
  199. package/dist/es2015/elements/menu-element.js +2 -2
  200. package/dist/es2015/elements/play-button.js +10 -3
  201. package/dist/es2015/elements/remaining-time.js +2 -1
  202. package/dist/es2015/elements/scan-button.js +118 -0
  203. package/dist/es2015/elements/seek-bar.js +264 -71
  204. package/dist/es2015/elements/shared.js +5 -106
  205. package/dist/es2015/elements/skip-button.js +2 -1
  206. package/dist/es2015/elements/spacer.js +2 -1
  207. package/dist/es2015/elements/spinner.js +1 -32
  208. package/dist/es2015/elements/start-button.js +8 -26
  209. package/dist/es2015/elements/time-element.js +1 -4
  210. package/dist/es2015/elements/title.js +1 -45
  211. package/dist/es2015/elements/volume-slider.js +2 -1
  212. package/dist/es2015/elements/volume.js +1 -11
  213. package/dist/es2015/entries/scan-button.js +7 -0
  214. package/dist/es2015/index.js +3 -1
  215. package/dist/es2015/style.js +1 -101
  216. package/dist/es2015/tags.js +2 -1
  217. package/dist/host.js +19 -17
  218. package/dist/host.js.map +1 -1
  219. package/dist/index.d.ts +3 -0
  220. package/dist/index.d.ts.map +1 -1
  221. package/dist/index.js +55 -27
  222. package/dist/labels.js +13 -9
  223. package/dist/labels.js.map +1 -1
  224. package/dist/namespaces.d.ts +9 -26
  225. package/dist/namespaces.d.ts.map +1 -1
  226. package/dist/namespaces.js +6 -2
  227. package/dist/namespaces.js.map +1 -1
  228. package/dist/presets.js +33 -28
  229. package/dist/presets.js.map +1 -1
  230. package/dist/style.d.ts +1 -20
  231. package/dist/style.d.ts.map +1 -1
  232. package/dist/style.js +4 -100
  233. package/dist/style.js.map +1 -1
  234. package/dist/surface.js +25 -21
  235. package/dist/surface.js.map +1 -1
  236. package/dist/tags.d.ts +1 -0
  237. package/dist/tags.d.ts.map +1 -1
  238. package/dist/tags.js +31 -26
  239. package/dist/tags.js.map +1 -1
  240. package/package.json +4 -4
  241. package/dist/index.js.map +0 -1
@@ -1,49 +1,29 @@
1
- /**
2
- * <mbx-seek-bar>: the bar over the slider primitive, with four layers on
3
- * its track, every one a part: the buffered ranges from `video.buffered`,
4
- * the played span, the hover position, and for live the edge from
5
- * `engine.live`. The span it maps is the availability window for live and
6
- * the duration for VOD; `controls/session.ts` says which.
7
- *
8
- * A live stream is seekable only when the window is worth it: at least
9
- * `live-window` forward buffer goals long, the goal read from the engine.
10
- * Below that the bar hides. VOD is always seekable. The element sets
11
- * `live` and `seekable` on the player, which the time and the live button
12
- * read.
13
- *
14
- * Reads happen on the events the video already fires; the live window has
15
- * no event of its own and moves with the clock, so `timeupdate` covers it.
16
- * While a pointer holds the thumb, the played layer follows the pointer and
17
- * `currentTime` is written at most once per frame, so the bar never fights
18
- * a slow seek. The element carries `dragging` meanwhile.
19
- *
20
- * The preview above the pointer carries the time and, when the session's
21
- * `engine.thumbnails` answers for that time, the tile: a rectangle of a
22
- * sprite, drawn by background position at the sprite's own size and scaled
23
- * down to `--mbx-preview-width`, so a page sets the size with one token.
24
- *
25
- * Chapters divide the track: one gap per chapter boundary, cut through
26
- * every layer with a mask, so the played and the buffered spans read per
27
- * chapter, and the preview names the chapter under the pointer. They are
28
- * the video's own chapters track, see `controls/chapters.ts`.
29
- * `chapters="none"` leaves the track whole and the preview without a name.
30
- *
31
- * `step` is what an arrow key moves the playhead by and `page` what Page
32
- * Up and Page Down do, in seconds. The name comes from `label`; what a
33
- * screen reader hears at a position from `label-of`, "{current} of
34
- * {duration}", and on live from `label-behind`, "{time} behind live". It
35
- * sits in the bar's seek row unless the page says otherwise.
36
- */
37
- import { chapterAt, chapters, followChapters } from '../controls/chapters.js';
38
- import { at, clip, EMPTY, fraction } from '../controls/ranges.js';
39
- import { bufferGoal, live, optional, span, wall } from '../controls/session.js';
40
- import { slider } from '../controls/slider.js';
41
- import { format } from '../controls/time.js';
42
- import { el } from '../dom.js';
43
- import { fill } from '../labels.js';
44
- import { Component } from './component.js';
45
- import { number, SLIDER_STYLE, seekRow, style } from './shared.js';
1
+ import { el } from "../dom.js";
2
+ import { Component } from "./component.js";
3
+ import { SLIDER_STYLE, number, seekRow, style } from "./shared.js";
4
+ import { fill } from "../labels.js";
5
+ import { EMPTY, at, clip, fraction } from "../controls/ranges.js";
6
+ import { format } from "../controls/time.js";
7
+ import { bufferGoal, live, optional, span, wall } from "../controls/session.js";
8
+ import { chapterAt, chapters, followChapters } from "../controls/chapters.js";
9
+ import { slider } from "../controls/slider.js";
10
+ //#region src/elements/seek-bar.ts
11
+ const STYLE_CSS = ":host,[part~=slider]{flex:1}[part~=thumb]{width:16px;height:16px;margin:-8px 0 0 -8px;box-shadow:0 1px 3px #0006}[part~=buffered]{position:absolute;top:0;bottom:0;left:0;right:0}[part~=buffered-range]{background:#ffffff4d;position:absolute;top:0;bottom:0}[part~=hover]{background:var(--mbx-text);width:2px;margin-left:-1px;position:absolute;top:0;bottom:0}[part~=edge]{background:var(--mbx-live);width:2px;margin-left:-1px;position:absolute;top:0;bottom:0}[part~=preview]{background:var(--mbx-surface);border-radius:var(--mbx-radius);font-variant-numeric:tabular-nums;white-space:nowrap;pointer-events:none;flex-direction:column;align-items:center;margin-bottom:4px;padding:2px;font-size:13px;display:flex;position:absolute;bottom:100%;transform:translate(-50%)}[part~=preview]>:not([hidden])~:not([hidden]){margin-top:2px}[part~=preview-image]{border-radius:2px;position:relative;overflow:hidden}[part~=preview-frame]{border-radius:2px;display:block}[part~=preview-tile]{transform-origin:0 0;background-repeat:no-repeat;position:absolute;top:0;left:0}[part~=preview-time]{padding:0 4px}[part~=preview-title]{text-overflow:ellipsis;max-width:240px;padding:0 4px;overflow:hidden}[hidden]{display:none}";
46
12
  const STEP = 5;
13
+ /** Under `key-mode="preview"`, a target seeks this long after the last key. */
14
+ const KEY_COMMIT_MS = 1e3;
15
+ /** Key moves closer together than this are one hold, whose step grows. */
16
+ const REPEAT_GAP_MS = 400;
17
+ /** A held key's step grows by one step every this many moves... */
18
+ const MOVES_PER_STEP = 8;
19
+ /** ...up to this many steps a move. */
20
+ const MAX_STEPS = 12;
21
+ /** The keys that cancel a target: Escape, and Back as a remote sends it. */
22
+ const CANCEL_KEYS = [
23
+ "Escape",
24
+ "GoBack",
25
+ "BrowserBack"
26
+ ];
47
27
  const PAGE = 30;
48
28
  const LIVE_WINDOW = 3;
49
29
  /** What the tile scales down to when the page sets no `--mbx-preview-width`. */
@@ -53,300 +33,460 @@ const BUFFER_GOAL = 30;
53
33
  /** The gap cut at a chapter boundary, in pixels. */
54
34
  const GAP = 2;
55
35
  const EVENTS = [
56
- 'timeupdate',
57
- 'progress',
58
- 'durationchange',
59
- 'loadedmetadata',
60
- 'seeking',
61
- 'seeked',
62
- 'emptied',
36
+ "timeupdate",
37
+ "progress",
38
+ "durationchange",
39
+ "loadedmetadata",
40
+ "seeking",
41
+ "seeked",
42
+ "emptied"
63
43
  ];
64
- const STYLE = `${SLIDER_STYLE}
65
- :host { flex: 1; }
66
- [part~="slider"] { flex: 1; }
67
- [part~="thumb"] { width: 16px; height: 16px; margin: -8px 0 0 -8px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); }
68
- [part~="buffered"] { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
69
- [part~="buffered-range"] { position: absolute; top: 0; bottom: 0; background: rgba(255, 255, 255, 0.3); }
70
- [part~="hover"] { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--mbx-text); }
71
- [part~="edge"] { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--mbx-live); }
72
- [part~="preview"] {
73
- position: absolute;
74
- bottom: 100%;
75
- margin-bottom: 4px;
76
- transform: translateX(-50%);
77
- display: flex;
78
- flex-direction: column;
79
- align-items: center;
80
- gap: 2px;
81
- padding: 2px;
82
- background: var(--mbx-surface);
83
- border-radius: var(--mbx-radius);
84
- font-size: 13px;
85
- font-variant-numeric: tabular-nums;
86
- white-space: nowrap;
87
- pointer-events: none;
88
- }
89
- [part~="preview-image"] { position: relative; overflow: hidden; border-radius: 2px; }
90
- [part~="preview-tile"] { position: absolute; top: 0; left: 0; transform-origin: top left; background-repeat: no-repeat; }
91
- [part~="preview-time"] { padding: 0 4px; }
92
- [part~="preview-title"] { max-width: 240px; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; }
93
- [hidden] { display: none; }
94
- `;
44
+ const STYLE = SLIDER_STYLE + STYLE_CSS;
95
45
  function percent(part) {
96
- return `${part * 100}%`;
46
+ return `${part * 100}%`;
97
47
  }
98
48
  /**
99
- * A mask that cuts a gap at each boundary between chapters, as stops along
100
- * the track: opaque up to a boundary, clear for the gap, opaque after.
101
- */
49
+ * A mask that cuts a gap at each boundary between chapters, as stops along
50
+ * the track: opaque up to a boundary, clear for the gap, opaque after.
51
+ */
102
52
  function gaps(list, span) {
103
- const stops = ['#000 0'];
104
- for (const chapter of list.slice(1)) {
105
- const at = percent(fraction(chapter.start, span));
106
- const before = `calc(${at} - ${GAP / 2}px)`;
107
- const after = `calc(${at} + ${GAP / 2}px)`;
108
- stops.push(`#000 ${before}`, `transparent ${before}`, `transparent ${after}`, `#000 ${after}`);
109
- }
110
- stops.push('#000 100%');
111
- return `linear-gradient(to right, ${stops.join(', ')})`;
112
- }
113
- export class MbxSeekBar extends Component {
114
- static get observedAttributes() {
115
- return ['label', 'label-of', 'label-behind', 'live-window', 'chapters'];
116
- }
117
- constructor() {
118
- super();
119
- this.range = EMPTY;
120
- this.pending = null;
121
- this.frame = 0;
122
- this.divided = '';
123
- this.list = [];
124
- const root = this.attachShadow({ mode: 'open' });
125
- this.bar = slider({
126
- step: () => number(this, 'step', STEP),
127
- page: () => number(this, 'page', PAGE),
128
- onInput: (value) => {
129
- this.input(value);
130
- },
131
- onDrag: (on) => {
132
- this.toggleAttribute('dragging', on);
133
- },
134
- });
135
- this.buffered = el('div', 'buffered');
136
- this.hover = el('div', 'hover');
137
- this.edge = el('div', 'edge');
138
- this.hover.hidden = true;
139
- this.edge.hidden = true;
140
- // Under the fill, so what is played reads over what is buffered.
141
- this.bar.track.prepend(this.buffered);
142
- this.bar.track.append(this.hover, this.edge);
143
- this.preview = el('div', 'preview');
144
- this.image = el('div', 'preview-image');
145
- this.tile = el('div', 'preview-tile');
146
- this.time = el('span', 'preview-time');
147
- this.caption = el('span', 'preview-title');
148
- this.caption.hidden = true;
149
- this.image.append(this.tile);
150
- this.image.hidden = true;
151
- this.preview.append(this.image, this.caption, this.time);
152
- this.preview.hidden = true;
153
- this.bar.root.append(this.preview);
154
- this.bar.root.addEventListener('pointermove', (event) => {
155
- this.point(event);
156
- });
157
- this.bar.root.addEventListener('pointerleave', () => {
158
- this.leave();
159
- });
160
- root.append(style(STYLE), this.bar.root);
161
- }
162
- connectedCallback() {
163
- seekRow(this);
164
- super.connectedCallback();
165
- }
166
- isLive() {
167
- return live(this.player?.engine ?? null) !== undefined;
168
- }
169
- /** Whether the chapters divide the track and name the preview. */
170
- chaptered() {
171
- return this.getAttribute('chapters') !== 'none' && this.list.length > 0;
172
- }
173
- /** The gaps at the chapter boundaries, on every layer of the track at once. */
174
- paintChapters() {
175
- const mask = this.chaptered() && this.list.length > 1 ? gaps(this.list, this.range) : '';
176
- const key = `${mask}|${this.range.start}|${this.range.end}`;
177
- if (key === this.divided)
178
- return;
179
- this.divided = key;
180
- const track = this.bar.track.style;
181
- // Both spellings: WebKit before 15.4 knows only the prefixed one.
182
- track.setProperty('mask-image', mask === '' ? '' : mask);
183
- track.setProperty('-webkit-mask-image', mask === '' ? '' : mask);
184
- }
185
- /** What a screen reader hears at a time. */
186
- say(time) {
187
- const engine = this.player?.engine ?? null;
188
- if (!this.isLive()) {
189
- const template = this.getAttribute('label-of') ?? '{current} of {duration}';
190
- return Number.isFinite(this.range.end) && this.range.end > 0
191
- ? fill(template, { current: format(time), duration: format(this.range.end) })
192
- : format(time);
193
- }
194
- const behind = fill(this.getAttribute('label-behind') ?? '{time} behind live', {
195
- time: format(this.range.end - time),
196
- });
197
- const clock = wall(engine, time);
198
- return clock === null ? behind : `${clock}, ${behind}`;
199
- }
200
- /** What the preview shows at a time. */
201
- label(time) {
202
- if (!this.isLive())
203
- return format(time);
204
- return wall(this.player?.engine ?? null, time) ?? `-${format(this.range.end - time)}`;
205
- }
206
- input(value) {
207
- const video = this.player?.video;
208
- if (video === undefined)
209
- return;
210
- this.bar.set(value, this.say(value));
211
- if (!this.bar.dragging()) {
212
- // The release, or a key: written now, and it supersedes whatever a
213
- // frame queued during the drag was about to write.
214
- this.pending = null;
215
- video.currentTime = value;
216
- return;
217
- }
218
- this.pending = value;
219
- if (this.frame === 0) {
220
- this.frame = requestAnimationFrame(() => {
221
- this.flush();
222
- });
223
- }
224
- }
225
- flush() {
226
- this.frame = 0;
227
- const video = this.player?.video;
228
- if (this.pending === null || video === undefined)
229
- return;
230
- video.currentTime = this.pending;
231
- this.pending = null;
232
- }
233
- /** The width the page asked for through the token, or the default. */
234
- previewWidth() {
235
- const set = Number.parseFloat(getComputedStyle(this.preview).getPropertyValue('--mbx-preview-width'));
236
- return Number.isFinite(set) && set > 0 ? set : PREVIEW_WIDTH;
237
- }
238
- /** The tile for a time, if the track has one, drawn at its size and scaled to fit. */
239
- paintTile(when) {
240
- const found = optional(this.player?.engine ?? null).thumbnails?.at(when) ?? null;
241
- this.image.hidden = found === null;
242
- if (found === null)
243
- return;
244
- const scale = this.previewWidth() / found.width;
245
- this.image.style.width = `${found.width * scale}px`;
246
- this.image.style.height = `${found.height * scale}px`;
247
- this.tile.style.width = `${found.width}px`;
248
- this.tile.style.height = `${found.height}px`;
249
- this.tile.style.backgroundImage = `url("${found.url}")`;
250
- this.tile.style.backgroundPosition = `-${found.x}px -${found.y}px`;
251
- this.tile.style.transform = `scale(${scale})`;
252
- }
253
- paintBuffered(video) {
254
- const parts = clip(Array.from({ length: video.buffered.length }, (_, i) => ({
255
- start: video.buffered.start(i),
256
- end: video.buffered.end(i),
257
- })), this.range);
258
- const buffered = this.buffered;
259
- while (buffered.childElementCount > parts.length)
260
- buffered.lastElementChild?.remove();
261
- while (buffered.childElementCount < parts.length)
262
- buffered.append(el('div', 'buffered-range'));
263
- let i = 0;
264
- for (const child of buffered.children) {
265
- const part = parts[i];
266
- i += 1;
267
- if (part === undefined)
268
- break;
269
- const node = child;
270
- node.style.left = percent(part[0]);
271
- node.style.width = percent(part[1] - part[0]);
272
- }
273
- }
274
- /** Whether a live window is wide enough to be worth a bar. */
275
- worthSeeking() {
276
- const goals = number(this, 'live-window', LIVE_WINDOW);
277
- if (goals === 0)
278
- return true;
279
- const goal = bufferGoal(this.player?.engine ?? null) ?? BUFFER_GOAL;
280
- return this.range.end - this.range.start >= goals * goal;
281
- }
282
- /** The hover marker and the preview follow the pointer, clamped to the bar. */
283
- point(event) {
284
- const rect = this.bar.rail.getBoundingClientRect();
285
- if (rect.width === 0 || this.range.end <= this.range.start)
286
- return;
287
- const part = Math.min(1, Math.max(0, (event.clientX - rect.left) / rect.width));
288
- this.hover.hidden = false;
289
- this.hover.style.left = percent(part);
290
- this.preview.hidden = false;
291
- const when = at(part, this.range);
292
- this.time.textContent = this.label(when);
293
- const chapter = this.chaptered() ? this.list[chapterAt(this.list, when)] : undefined;
294
- this.caption.hidden = chapter === undefined || chapter.title === '';
295
- this.caption.textContent = chapter?.title ?? '';
296
- this.paintTile(when);
297
- const whole = this.bar.root.getBoundingClientRect();
298
- const half = this.preview.offsetWidth / 2;
299
- const x = rect.left - whole.left + part * rect.width;
300
- this.preview.style.left = `${Math.min(whole.width - half, Math.max(half, x))}px`;
301
- }
302
- leave() {
303
- this.hover.hidden = true;
304
- this.preview.hidden = true;
305
- }
306
- attach(player) {
307
- const tick = () => {
308
- this.render();
309
- };
310
- this.listen(player.video, EVENTS, tick);
311
- this.keep(followChapters(player.video, tick));
312
- this.listen(player, ['sourcechange'], () => {
313
- this.leave();
314
- this.render();
315
- });
316
- this.render();
317
- }
318
- detach(player) {
319
- cancelAnimationFrame(this.frame);
320
- this.frame = 0;
321
- this.pending = null;
322
- this.leave();
323
- player.removeAttribute('live');
324
- player.removeAttribute('seekable');
325
- }
326
- render() {
327
- const player = this.player;
328
- if (player === null)
329
- return;
330
- const video = player.video;
331
- const engine = player.engine;
332
- const api = live(engine);
333
- const on = api !== undefined;
334
- this.range = span(video, engine);
335
- this.list = chapters(video);
336
- this.bar.label(this.getAttribute('label') ?? 'Seek');
337
- this.bar.range(this.range.start, this.range.end);
338
- this.paintBuffered(video);
339
- this.paintChapters();
340
- this.edge.hidden = !on;
341
- if (api !== undefined && api.edge !== null) {
342
- this.edge.style.left = percent(fraction(api.edge, this.range));
343
- }
344
- const seekable = !on || this.worthSeeking();
345
- this.hidden = !seekable;
346
- player.toggleAttribute('live', on);
347
- player.toggleAttribute('seekable', seekable);
348
- if (!this.bar.dragging())
349
- this.bar.set(video.currentTime, this.say(video.currentTime));
350
- }
53
+ const stops = ["#000 0"];
54
+ for (const chapter of list.slice(1)) {
55
+ const at = percent(fraction(chapter.start, span));
56
+ const before = `calc(${at} - ${GAP / 2}px)`;
57
+ const after = `calc(${at} + ${GAP / 2}px)`;
58
+ stops.push(`#000 ${before}`, `transparent ${before}`, `transparent ${after}`, `#000 ${after}`);
59
+ }
60
+ stops.push("#000 100%");
61
+ return `linear-gradient(to right, ${stops.join(", ")})`;
351
62
  }
63
+ var MbxSeekBar = class extends Component {
64
+ static get observedAttributes() {
65
+ return [
66
+ "label",
67
+ "label-of",
68
+ "label-behind",
69
+ "live-window",
70
+ "chapters",
71
+ "scrub",
72
+ "preview",
73
+ "key-mode"
74
+ ];
75
+ }
76
+ constructor() {
77
+ super();
78
+ this.range = EMPTY;
79
+ this.pending = null;
80
+ this.frame = 0;
81
+ this.divided = "";
82
+ this.list = [];
83
+ this.drag = "none";
84
+ this.dragged = null;
85
+ this.resume = false;
86
+ this.asked = 0;
87
+ this.shown = 0;
88
+ this.target = null;
89
+ this.commitTimer = 0;
90
+ this.moves = 0;
91
+ this.lastMove = 0;
92
+ const root = this.attachShadow({ mode: "open" });
93
+ this.bar = slider({
94
+ step: () => this.keyStep(),
95
+ page: () => number(this, "page", PAGE),
96
+ onInput: (value, key) => {
97
+ if (key && this.previewing()) this.aim(value);
98
+ else this.input(value);
99
+ },
100
+ onDrag: (on) => {
101
+ this.toggleAttribute("dragging", on);
102
+ if (on) this.dragStart();
103
+ else this.dragEnd();
104
+ }
105
+ });
106
+ this.buffered = el("div", "buffered");
107
+ this.hover = el("div", "hover");
108
+ this.edge = el("div", "edge");
109
+ this.hover.hidden = true;
110
+ this.edge.hidden = true;
111
+ this.bar.track.prepend(this.buffered);
112
+ this.bar.track.append(this.hover, this.edge);
113
+ this.preview = el("div", "preview");
114
+ this.image = el("div", "preview-image");
115
+ this.tile = el("div", "preview-tile");
116
+ this.time = el("span", "preview-time");
117
+ this.caption = el("span", "preview-title");
118
+ this.caption.hidden = true;
119
+ this.image.append(this.tile);
120
+ this.image.hidden = true;
121
+ this.frameCanvas = el("canvas", "preview-frame");
122
+ this.frameCanvas.hidden = true;
123
+ this.preview.append(this.frameCanvas, this.image, this.caption, this.time);
124
+ this.preview.hidden = true;
125
+ this.bar.root.append(this.preview);
126
+ this.bar.root.addEventListener("pointermove", (event) => {
127
+ this.point(event);
128
+ });
129
+ this.bar.root.addEventListener("pointerleave", () => {
130
+ if (this.target === null) this.leave();
131
+ });
132
+ this.bar.root.addEventListener("blur", () => {
133
+ if (this.target !== null) this.commit();
134
+ });
135
+ root.append(style(STYLE), this.bar.root);
136
+ }
137
+ connectedCallback() {
138
+ seekRow(this);
139
+ super.connectedCallback();
140
+ }
141
+ isLive() {
142
+ return live(this.player?.engine ?? null) !== void 0;
143
+ }
144
+ /** Whether the chapters do `use`: `divided` the track, or name the preview with their `titles`. */
145
+ chaptered(use) {
146
+ if (this.list.length === 0) return false;
147
+ const value = this.getAttribute("chapters");
148
+ if (value === null) return true;
149
+ const words = value.split(/\s+/);
150
+ return words.includes(use) || !words.some((word) => word === "divided" || word === "titles" || word === "none");
151
+ }
152
+ /** The gaps at the chapter boundaries, on every layer of the track at once. */
153
+ paintChapters() {
154
+ const mask = this.chaptered("divided") && this.list.length > 1 ? gaps(this.list, this.range) : "";
155
+ const key = `${mask}|${this.range.start}|${this.range.end}`;
156
+ if (key === this.divided) return;
157
+ this.divided = key;
158
+ const track = this.bar.track.style;
159
+ track.setProperty("mask-image", mask === "" ? "" : mask);
160
+ track.setProperty("-webkit-mask-image", mask === "" ? "" : mask);
161
+ }
162
+ /** What a screen reader hears at a time. */
163
+ say(time) {
164
+ const engine = this.player?.engine ?? null;
165
+ if (!this.isLive()) {
166
+ const template = this.getAttribute("label-of") ?? "{current} of {duration}";
167
+ return Number.isFinite(this.range.end) && this.range.end > 0 ? fill(template, {
168
+ current: format(time),
169
+ duration: format(this.range.end)
170
+ }) : format(time);
171
+ }
172
+ const behind = fill(this.getAttribute("label-behind") ?? "{time} behind live", { time: format(this.range.end - time) });
173
+ const clock = wall(engine, time);
174
+ return clock === null ? behind : `${clock}, ${behind}`;
175
+ }
176
+ /** What the preview shows at a time. */
177
+ label(time) {
178
+ if (!this.isLive()) return format(time);
179
+ return wall(this.player?.engine ?? null, time) ?? `-${format(this.range.end - time)}`;
180
+ }
181
+ /** Scrubs when the session has an I-frame track and the page allows it; seeks otherwise. */
182
+ dragStart() {
183
+ const trick = optional(this.player?.engine ?? null).trick;
184
+ this.dragged = null;
185
+ const before = this.player?.video.paused === false ? "playing" : "paused";
186
+ this.player?.setAttribute("scrubbing", before);
187
+ if (trick?.available === true && this.getAttribute("scrub") !== "false") {
188
+ trick.scrubStart();
189
+ this.drag = "scrub";
190
+ } else {
191
+ const video = this.player?.video;
192
+ this.resume = video !== void 0 && !video.paused;
193
+ video?.pause();
194
+ this.drag = "seek";
195
+ }
196
+ }
197
+ /**
198
+ * The pointer let go. A release writes its own input next, in the same
199
+ * task, and that settles the drag. A cancelled drag writes none, so the
200
+ * drag settles at its last position once the task is over.
201
+ */
202
+ dragEnd() {
203
+ queueMicrotask(() => {
204
+ if (this.drag !== "none") this.settle(this.dragged);
205
+ });
206
+ }
207
+ /** Ends the drag at `value`, or where it stands when there is none. */
208
+ settle(value) {
209
+ const drag = this.drag;
210
+ this.drag = "none";
211
+ this.dragged = null;
212
+ const player = this.player;
213
+ if (player === null) return;
214
+ if (drag === "scrub") {
215
+ const trick = optional(player.engine).trick;
216
+ if (value === null) trick?.scrubEnd();
217
+ else trick?.scrubEnd(value);
218
+ } else {
219
+ if (value !== null) player.video.currentTime = value;
220
+ if (this.resume) player.video.play().catch(() => void 0);
221
+ this.resume = false;
222
+ }
223
+ player.removeAttribute("scrubbing");
224
+ }
225
+ /** Whether keys aim a target with the preview instead of seeking at once. */
226
+ previewing() {
227
+ return this.getAttribute("key-mode") === "preview";
228
+ }
229
+ /** The step for a key on the slider itself. */
230
+ keyStep() {
231
+ const base = number(this, "step", STEP);
232
+ return this.previewing() ? base * this.growth() : base;
233
+ }
234
+ /**
235
+ * How many steps a key moves the target under `key-mode="preview"`. It
236
+ * grows while the viewer holds the key, so a long film takes seconds to
237
+ * cross, not minutes; a pause restarts it.
238
+ */
239
+ growth() {
240
+ const now = performance.now();
241
+ if (now - this.lastMove > REPEAT_GAP_MS) this.moves = 0;
242
+ this.moves += 1;
243
+ this.lastMove = now;
244
+ return Math.min(MAX_STEPS, 1 + Math.floor(this.moves / MOVES_PER_STEP));
245
+ }
246
+ /**
247
+ * Aims at `value` without seeking: the thumb and the preview show it, and
248
+ * the seek comes on Enter or once the keys pause. A TV decodes slowly, so
249
+ * a seek per key would stutter where the preview already shows the place.
250
+ */
251
+ aim(value) {
252
+ const time = Math.min(this.range.end, Math.max(this.range.start, value));
253
+ this.target = time;
254
+ this.bar.set(time, this.say(time));
255
+ const span = this.range.end - this.range.start;
256
+ if (span > 0) this.previewAt((time - this.range.start) / span);
257
+ clearTimeout(this.commitTimer);
258
+ this.commitTimer = window.setTimeout(() => {
259
+ this.commit();
260
+ }, KEY_COMMIT_MS);
261
+ }
262
+ /** Seeks to the target, if there is one. */
263
+ commit() {
264
+ const target = this.target;
265
+ this.stopAiming();
266
+ const video = this.player?.video;
267
+ if (target !== null && video !== void 0) video.currentTime = target;
268
+ }
269
+ /** Drops the target: the thumb goes back to the playhead. */
270
+ cancel() {
271
+ this.stopAiming();
272
+ this.render();
273
+ }
274
+ stopAiming() {
275
+ clearTimeout(this.commitTimer);
276
+ this.commitTimer = 0;
277
+ this.target = null;
278
+ this.moves = 0;
279
+ this.leave();
280
+ }
281
+ input(value) {
282
+ const video = this.player?.video;
283
+ if (video === void 0) return;
284
+ this.bar.set(value, this.say(value));
285
+ if (!this.bar.dragging()) {
286
+ this.pending = null;
287
+ if (this.drag !== "none") this.settle(value);
288
+ else video.currentTime = value;
289
+ return;
290
+ }
291
+ this.dragged = value;
292
+ if (this.drag === "scrub") {
293
+ optional(this.player?.engine ?? null).trick?.scrubTo(value);
294
+ return;
295
+ }
296
+ this.pending = value;
297
+ if (this.frame === 0) this.frame = requestAnimationFrame(() => {
298
+ this.flush();
299
+ });
300
+ }
301
+ flush() {
302
+ this.frame = 0;
303
+ const video = this.player?.video;
304
+ if (this.pending === null || video === void 0) return;
305
+ video.currentTime = this.pending;
306
+ this.pending = null;
307
+ }
308
+ /** The width the page asked for through the token, or the default. */
309
+ previewWidth() {
310
+ const set = Number.parseFloat(getComputedStyle(this.preview).getPropertyValue("--mbx-preview-width"));
311
+ return Number.isFinite(set) && set > 0 ? set : PREVIEW_WIDTH;
312
+ }
313
+ /** The preview's picture sources from `preview`, in order of preference: frames then tiles by default. */
314
+ sources() {
315
+ const value = this.getAttribute("preview");
316
+ if (value === "none") return [];
317
+ const own = (value ?? "").split(/\s+/).filter((word) => word === "frames" || word === "tiles");
318
+ return own.length > 0 ? own : ["frames", "tiles"];
319
+ }
320
+ /** `tile`, or none, drawn at its size and scaled to fit. */
321
+ paintTile(tile) {
322
+ this.image.hidden = tile === null;
323
+ if (tile === null) return;
324
+ const scale = this.previewWidth() / tile.width;
325
+ this.image.style.width = `${tile.width * scale}px`;
326
+ this.image.style.height = `${tile.height * scale}px`;
327
+ this.tile.style.width = `${tile.width}px`;
328
+ this.tile.style.height = `${tile.height}px`;
329
+ this.tile.style.backgroundImage = `url("${tile.url}")`;
330
+ this.tile.style.backgroundPosition = `-${tile.x}px -${tile.y}px`;
331
+ this.tile.style.transform = `scale(${scale})`;
332
+ }
333
+ /**
334
+ * The picture in the preview, from the sources `preview` names, the first
335
+ * that answers winning. A decoded frame arrives later than a tile, so
336
+ * while frames lead, the tile stands in until one is on screen, and the
337
+ * last frame stays until the next one arrives. A scrub already shows the
338
+ * position in the video, so the preview shows none meanwhile.
339
+ */
340
+ paintPicture(when) {
341
+ const sources = this.drag === "scrub" ? [] : this.sources();
342
+ const api = optional(this.player?.engine ?? null);
343
+ const trick = api.trick;
344
+ const frames = sources.includes("frames") && trick?.previews === true;
345
+ const tile = sources.includes("tiles") ? api.thumbnails?.at(when) ?? null : null;
346
+ if (tile !== null && (sources[0] === "tiles" || !frames)) {
347
+ this.asked += 1;
348
+ this.shown = this.asked;
349
+ this.frameCanvas.hidden = true;
350
+ this.paintTile(tile);
351
+ return;
352
+ }
353
+ if (!frames || trick === void 0) {
354
+ this.frameCanvas.hidden = true;
355
+ this.paintTile(null);
356
+ return;
357
+ }
358
+ this.asked += 1;
359
+ const request = this.asked;
360
+ const width = this.previewWidth();
361
+ trick.frameAt(when, { width: Math.round(width * devicePixelRatio) }).then((bitmap) => {
362
+ if (bitmap === null || request < this.shown || this.preview.hidden) return;
363
+ this.shown = request;
364
+ const canvas = this.frameCanvas;
365
+ canvas.width = bitmap.width;
366
+ canvas.height = bitmap.height;
367
+ canvas.style.width = `${width}px`;
368
+ canvas.style.height = `${bitmap.height / bitmap.width * width}px`;
369
+ canvas.getContext("2d")?.drawImage(bitmap, 0, 0);
370
+ canvas.hidden = false;
371
+ this.image.hidden = true;
372
+ }, () => void 0);
373
+ if (this.frameCanvas.hidden) this.paintTile(tile);
374
+ }
375
+ paintBuffered(video) {
376
+ const parts = clip(Array.from({ length: video.buffered.length }, (_, i) => ({
377
+ start: video.buffered.start(i),
378
+ end: video.buffered.end(i)
379
+ })), this.range);
380
+ const buffered = this.buffered;
381
+ while (buffered.childElementCount > parts.length) buffered.lastElementChild?.remove();
382
+ while (buffered.childElementCount < parts.length) buffered.append(el("div", "buffered-range"));
383
+ let i = 0;
384
+ for (const child of buffered.children) {
385
+ const part = parts[i];
386
+ i += 1;
387
+ if (part === void 0) break;
388
+ const node = child;
389
+ node.style.left = percent(part[0]);
390
+ node.style.width = percent(part[1] - part[0]);
391
+ }
392
+ }
393
+ /** Whether a live window is wide enough to be worth a bar. */
394
+ worthSeeking() {
395
+ const goals = number(this, "live-window", LIVE_WINDOW);
396
+ if (goals === 0) return true;
397
+ const goal = bufferGoal(this.player?.engine ?? null) ?? BUFFER_GOAL;
398
+ return this.range.end - this.range.start >= goals * goal;
399
+ }
400
+ /** The hover marker and the preview follow the pointer, clamped to the bar. */
401
+ point(event) {
402
+ const rect = this.bar.rail.getBoundingClientRect();
403
+ if (rect.width === 0 || this.range.end <= this.range.start) return;
404
+ const part = Math.min(1, Math.max(0, (event.clientX - rect.left) / rect.width));
405
+ this.hover.hidden = false;
406
+ this.hover.style.left = percent(part);
407
+ this.previewAt(part);
408
+ }
409
+ /** The preview over `part` of the bar: the time, the chapter, and the picture. */
410
+ previewAt(part) {
411
+ const rect = this.bar.rail.getBoundingClientRect();
412
+ if (rect.width === 0 || this.range.end <= this.range.start) return;
413
+ this.preview.hidden = false;
414
+ const when = at(part, this.range);
415
+ this.time.textContent = this.label(when);
416
+ const chapter = this.chaptered("titles") ? this.list[chapterAt(this.list, when)] : void 0;
417
+ this.caption.hidden = chapter === void 0 || chapter.title === "";
418
+ this.caption.textContent = chapter?.title ?? "";
419
+ this.paintPicture(when);
420
+ const whole = this.bar.root.getBoundingClientRect();
421
+ const half = this.preview.offsetWidth / 2;
422
+ const x = rect.left - whole.left + part * rect.width;
423
+ this.preview.style.left = `${Math.min(whole.width - half, Math.max(half, x))}px`;
424
+ }
425
+ leave() {
426
+ this.hover.hidden = true;
427
+ this.preview.hidden = true;
428
+ this.frameCanvas.hidden = true;
429
+ }
430
+ attach(player) {
431
+ const tick = () => {
432
+ this.render();
433
+ };
434
+ this.listen(player.video, EVENTS, tick);
435
+ this.keep(followChapters(player, tick));
436
+ this.listen(player, ["sourcechange"], () => {
437
+ this.drag = "none";
438
+ this.stopAiming();
439
+ this.render();
440
+ });
441
+ this.listen(player, ["seekkey"], (event) => {
442
+ const asked = event;
443
+ if (!this.previewing() || this.hidden || asked.defaultPrevented) return;
444
+ asked.preventDefault();
445
+ this.aim((this.target ?? player.video.currentTime) + asked.detail.by * this.growth());
446
+ });
447
+ this.listen(player, ["keydown"], (event) => {
448
+ const key = event;
449
+ if (this.target === null || key.defaultPrevented) return;
450
+ if (key.key === "Enter" && !(key.composedPath()[0] instanceof HTMLButtonElement)) this.commit();
451
+ else if (CANCEL_KEYS.includes(key.key)) this.cancel();
452
+ else return;
453
+ key.preventDefault();
454
+ });
455
+ this.render();
456
+ }
457
+ detach(player) {
458
+ cancelAnimationFrame(this.frame);
459
+ this.frame = 0;
460
+ this.pending = null;
461
+ if (this.drag !== "none") this.settle(null);
462
+ this.stopAiming();
463
+ player.removeAttribute("live");
464
+ player.removeAttribute("seekable");
465
+ player.removeAttribute("scrubbing");
466
+ }
467
+ render() {
468
+ const player = this.player;
469
+ if (player === null) return;
470
+ const video = player.video;
471
+ const engine = player.engine;
472
+ const api = live(engine);
473
+ const on = api !== void 0;
474
+ this.range = span(video, engine);
475
+ this.list = chapters(video, engine);
476
+ this.bar.label(this.getAttribute("label") ?? "Seek");
477
+ this.bar.range(this.range.start, this.range.end);
478
+ this.paintBuffered(video);
479
+ this.paintChapters();
480
+ this.edge.hidden = !on;
481
+ if (api !== void 0 && api.edge !== null) this.edge.style.left = percent(fraction(api.edge, this.range));
482
+ const seekable = !on || this.worthSeeking();
483
+ this.hidden = !seekable;
484
+ player.toggleAttribute("live", on);
485
+ player.toggleAttribute("seekable", seekable);
486
+ if (!this.bar.dragging() && this.target === null) this.bar.set(video.currentTime, this.say(video.currentTime));
487
+ }
488
+ };
489
+ //#endregion
490
+ export { MbxSeekBar };
491
+
352
492
  //# sourceMappingURL=seek-bar.js.map