@mattebox/player 0.9.0 → 0.9.1

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 (31) hide show
  1. package/dist/cdn/mattebox-player.min.js +3 -3
  2. package/dist/controls/cues.d.ts.map +1 -1
  3. package/dist/controls/cues.js +11 -5
  4. package/dist/controls/cues.js.map +1 -1
  5. package/dist/controls/menu.d.ts +9 -0
  6. package/dist/controls/menu.d.ts.map +1 -1
  7. package/dist/controls/menu.js +57 -14
  8. package/dist/controls/menu.js.map +1 -1
  9. package/dist/elements/menu-element.d.ts.map +1 -1
  10. package/dist/elements/menu-element.js +2 -1
  11. package/dist/elements/menu-element.js.map +1 -1
  12. package/dist/elements/shared.js +1 -1
  13. package/dist/elements/start-button.d.ts +7 -4
  14. package/dist/elements/start-button.d.ts.map +1 -1
  15. package/dist/elements/start-button.js +9 -6
  16. package/dist/elements/start-button.js.map +1 -1
  17. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/asyncToGenerator.js +1 -1
  18. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/defineProperty.js +1 -1
  19. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/objectSpread2.js +1 -1
  20. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPrimitive.js +1 -1
  21. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPropertyKey.js +1 -1
  22. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/typeof.js +1 -1
  23. package/dist/es2015/controls/chapters.js +1 -1
  24. package/dist/es2015/controls/cues.js +11 -5
  25. package/dist/es2015/controls/menu.js +62 -17
  26. package/dist/es2015/element.js +2 -2
  27. package/dist/es2015/elements/menu-element.js +2 -1
  28. package/dist/es2015/elements/shared.js +1 -1
  29. package/dist/es2015/elements/start-button.js +9 -6
  30. package/dist/es2015/presets.js +1 -1
  31. package/package.json +1 -1
@@ -2,9 +2,10 @@
2
2
  /**
3
3
  * Subtitles and the bar. Two things.
4
4
  *
5
- * The lift: the browser draws native cues at the bottom of the video, under
6
- * the bar. While the bar shows, every active cue the author left
7
- * unpositioned is moved above it, and put back when the bar hides. The
5
+ * The lift: the browser draws native cues on the bottom edge of the video,
6
+ * and under the bar. Every active cue the author left unpositioned is
7
+ * moved up: above the bar while it shows, and one line off the edge while
8
+ * it is hidden, so the text never sits on the picture's border. The
8
9
  * position is a negative line count, the one form every browser wraps at
9
10
  * the video's width; a percentage does not wrap in Chromium. Chromium
10
11
  * anchors the box's top on the count and Gecko its bottom, and their
@@ -43,6 +44,8 @@ const LINE_HEIGHT = 1.2;
43
44
  const CUE_WIDTH = .96;
44
45
  /** Pixels of air between the bar and the cue above it, before rounding up to a line. */
45
46
  const AIR = 6;
47
+ /** Lines of air under a cue while the bar is hidden. */
48
+ const REST = 1;
46
49
  /** Puts the cue rules in the document, once. */
47
50
  function cueStyle() {
48
51
  if (document.head.querySelector(`style[${MARK}]`) !== null) return;
@@ -55,6 +58,8 @@ function cueLift(video, host, covered) {
55
58
  /** The cues moved, with what they were, so they and only they are put back. */
56
59
  const lifted = /* @__PURE__ */ new Map();
57
60
  let on = false;
61
+ /** False once disposed: the cues go back to where the author left them. */
62
+ let live = true;
58
63
  let canvas;
59
64
  function showing() {
60
65
  const out = [];
@@ -103,10 +108,10 @@ function cueLift(video, host, covered) {
103
108
  const height = box.height;
104
109
  const span = covered();
105
110
  const pixels = span.bottom - span.top;
106
- const lift = on && height > 0 && pixels > 0 && pixels < height;
111
+ const lift = live && height > 0;
107
112
  const font = fontSize(height);
108
113
  const unit = font * LINE_HEIGHT;
109
- const base = Math.ceil((pixels + AIR) / unit);
114
+ const base = on && pixels > 0 && pixels < height ? Math.ceil((pixels + AIR) / unit) : REST;
110
115
  for (const track of showing()) {
111
116
  const active = [...track.activeCues ?? []].filter((cue) => cue instanceof VTTCue).sort((a, b) => a.startTime - b.startTime);
112
117
  let previous = null;
@@ -161,6 +166,7 @@ function cueLift(video, host, covered) {
161
166
  },
162
167
  dispose() {
163
168
  on = false;
169
+ live = false;
164
170
  apply();
165
171
  video.textTracks.removeEventListener("change", watch);
166
172
  video.textTracks.removeEventListener("addtrack", watch);
@@ -1 +1 @@
1
- {"version":3,"file":"cues.js","names":[],"sources":["../../src/controls/cues.ts"],"sourcesContent":["/**\n * Subtitles and the bar. Two things.\n *\n * The lift: the browser draws native cues at the bottom of the video, under\n * the bar. While the bar shows, every active cue the author left\n * unpositioned is moved above it, and put back when the bar hides. The\n * position is a negative line count, the one form every browser wraps at\n * the video's width; a percentage does not wrap in Chromium. Chromium\n * anchors the box's top on the count and Gecko its bottom, and their\n * overlap avoidance pushes in opposite directions, so nothing is left to\n * them: subtitles often show two cues at once, and the cues stack by their\n * own measured heights, wrapping included, clear under both readings. A\n * cue with a position of its own is the author's and is not touched.\n *\n * The look: `::cue` can only be styled from the document that holds the\n * video, which is the page and not the shadow root, and it takes no custom\n * properties. So a small sheet goes into the document, once, with one rule\n * per look the host's `subtitle-size` and `subtitle-background` attributes\n * can take. Sizes are percentages of the browser's own cue size, which\n * already follows the video's height, in the page and in fullscreen alike.\n * A page that wants more writes its own `mattebox-player > video::cue`.\n */\nimport CUE_RULES from './cues.css?inline';\n/** How the sizes scale the browser's own cue size; the lift counts lines by it. */\nexport const SCALES: Readonly<Record<string, number>> = {\n small: 0.75,\n medium: 1,\n large: 1.5,\n xlarge: 2,\n};\n\n/**\n * The sheet in the document. `mattebox-player` is the element's tag. The\n * background goes on `::cue` and on the backdrop pseudo-element Chromium\n * and WebKit have, both: which of the two paints it differs by browser and\n * version, and a selector a browser does not know only voids its own rule.\n */\n\nconst MARK = 'data-mattebox-cue';\n\n/** The browser's cue size against the video's height, per WebVTT, and its line against the size. */\nconst CUE_SIZE = 0.05;\nconst LINE_HEIGHT = 1.2;\n/** What a cue box spans of the video's width by default, so wrapping is measured against it. */\nconst CUE_WIDTH = 0.96;\n/** Pixels of air between the bar and the cue above it, before rounding up to a line. */\nconst AIR = 6;\n\n/** Puts the cue rules in the document, once. */\nexport function cueStyle(): void {\n if (document.head.querySelector(`style[${MARK}]`) !== null) return;\n const style = document.createElement('style');\n style.setAttribute(MARK, '');\n style.textContent = CUE_RULES;\n document.head.append(style);\n}\n\n/** What a lifted cue looked like before, to put back. */\ninterface Placed {\n readonly line: number | 'auto';\n readonly snapToLines: boolean;\n readonly lineAlign: LineAlignSetting;\n}\n\nexport interface CueLift {\n /** Whether the bar is showing, so the cues move above it or back. */\n lifted(on: boolean): void;\n dispose(): void;\n}\n\n/** What the bar covers of the picture: from its first row's top, not its gradient run-in, to its bottom. */\nexport type Covered = () => { readonly top: number; readonly bottom: number };\n\nexport function cueLift(video: HTMLVideoElement, host: HTMLElement, covered: Covered): CueLift {\n /** The cues moved, with what they were, so they and only they are put back. */\n const lifted = new Map<VTTCue, Placed>();\n let on = false;\n let canvas: CanvasRenderingContext2D | null | undefined;\n\n function showing(): TextTrack[] {\n const out: TextTrack[] = [];\n for (const track of video.textTracks) if (track.mode === 'showing') out.push(track);\n return out;\n }\n\n /** The browser's cue font size, in pixels, from the video's height and the host's scale. */\n function fontSize(height: number): number {\n const scale = SCALES[host.getAttribute('subtitle-size') ?? ''] ?? 1;\n return height * CUE_SIZE * scale;\n }\n\n /** Measures text the way the browser draws cues, to count the lines a cue wraps into. */\n function measure(): CanvasRenderingContext2D | null {\n if (canvas === undefined) canvas = document.createElement('canvas').getContext('2d');\n return canvas;\n }\n\n /**\n * A cue's text without its tags, for measuring: `<b>`, `<c.name>`, the\n * timestamps and their closers. Brackets are counted, so a tag inside\n * another's brackets goes with it.\n */\n function plain(text: string): string {\n let out = '';\n let depth = 0;\n for (const char of text) {\n if (char === '<') depth += 1;\n else if (char === '>') depth = Math.max(0, depth - 1);\n else if (depth === 0) out += char;\n }\n return out;\n }\n\n /** The lines a cue takes: its own, each wrapped at the cue box's width. */\n function lines(cue: VTTCue, font: number, width: number): number {\n const context = measure();\n let total = 0;\n for (const line of plain(cue.text).split('\\n')) {\n if (context === null) {\n total += 1;\n continue;\n }\n context.font = `${font}px sans-serif`;\n total += Math.max(1, Math.ceil(context.measureText(line).width / (width * CUE_WIDTH)));\n }\n return total;\n }\n\n function apply(): void {\n const box = video.getBoundingClientRect();\n const height = box.height;\n const span = covered();\n const pixels = span.bottom - span.top;\n const lift = on && height > 0 && pixels > 0 && pixels < height;\n const font = fontSize(height);\n const unit = font * LINE_HEIGHT;\n // The lines the bar covers, with a little air, rounded up to whole lines.\n const base = Math.ceil((pixels + AIR) / unit);\n for (const track of showing()) {\n // Earliest first, the order the browser stacks them in, so the first\n // sits lowest and the rest climb.\n const active = [...(track.activeCues ?? [])]\n .filter((cue): cue is VTTCue => cue instanceof VTTCue)\n .sort((a, b) => a.startTime - b.startTime);\n let previous: { line: number; height: number } | null = null;\n let changed = false;\n for (const cue of active) {\n const was = lifted.get(cue);\n if (!lift) {\n if (was === undefined) continue;\n cue.line = was.line;\n cue.snapToLines = was.snapToLines;\n cue.lineAlign = was.lineAlign;\n lifted.delete(cue);\n changed = true;\n continue;\n }\n // The author's own placement is the author's.\n if (was === undefined && cue.line !== 'auto') continue;\n if (was === undefined) {\n lifted.set(cue, {\n line: cue.line,\n snapToLines: cue.snapToLines,\n lineAlign: cue.lineAlign,\n });\n }\n // A negative line count, which every browser wraps at the video's\n // width, unlike a percentage. Chromium anchors the box's top on it\n // and Gecko its bottom, so the count clears the bar and the cue\n // below under both readings, with a little air to spare in one.\n const own = lines(cue, font, box.width);\n const line: number =\n previous === null ? base + own : previous.line + Math.max(own, previous.height);\n if (cue.line !== -line || !cue.snapToLines) changed = true;\n cue.snapToLines = true;\n cue.line = -line;\n previous = { line, height: own };\n }\n // Chromium lays a changed line out again only when the track's display\n // is rebuilt, which neither time nor a seek does for a cue already\n // showing; the mode flipped off and on in one task rebuilds it with no\n // paint in between. Only on a change, so the change event this fires\n // finds nothing to do and the loop ends there.\n if (changed) {\n track.mode = 'hidden';\n track.mode = 'showing';\n }\n }\n }\n\n function watch(): void {\n for (const track of video.textTracks) {\n track.removeEventListener('cuechange', apply);\n track.addEventListener('cuechange', apply);\n }\n apply();\n }\n\n video.textTracks.addEventListener('change', watch);\n video.textTracks.addEventListener('addtrack', watch);\n watch();\n\n return {\n lifted(next: boolean): void {\n on = next;\n apply();\n },\n dispose(): void {\n on = false;\n apply();\n video.textTracks.removeEventListener('change', watch);\n video.textTracks.removeEventListener('addtrack', watch);\n for (const track of video.textTracks) track.removeEventListener('cuechange', apply);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAA,YAAA;;AAEA,MAAA,SAAA;CACA,OAAA;CACA,QAAA;CACA,OAAA;CACA,QAAA;AACA;;;;;;;AASA,MAAA,OAAA;;AAGA,MAAA,WAAA;AACA,MAAA,cAAA;;AAEA,MAAA,YAAA;;AAEA,MAAA,MAAA;;AAGA,SAAA,WAAA;CACA,IAAA,SAAA,KAAA,cAAA,SAAA,KAAA,EAAA,MAAA,MAAA;CACA,MAAA,QAAA,SAAA,cAAA,OAAA;CACA,MAAA,aAAA,MAAA,EAAA;CACA,MAAA,cAAA;CACA,SAAA,KAAA,OAAA,KAAA;AACA;AAkBA,SAAA,QAAA,OAAA,MAAA,SAAA;;CAEA,MAAA,yBAAA,IAAA,IAAA;CACA,IAAA,KAAA;CACA,IAAA;CAEA,SAAA,UAAA;EACA,MAAA,MAAA,CAAA;EACA,KAAA,MAAA,SAAA,MAAA,YAAA,IAAA,MAAA,SAAA,WAAA,IAAA,KAAA,KAAA;EACA,OAAA;CACA;;CAGA,SAAA,SAAA,QAAA;EACA,MAAA,QAAA,OAAA,KAAA,aAAA,eAAA,KAAA,OAAA;EACA,OAA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AAA,GAAA;IACA,IAAA,CAAA,MAAA;KACA,IAAA,QAAA,KAAA,GAAA;KACA,IAAA,OAAA,IAAA;KACA,IAAA,cAAA,IAAA;KACA,IAAA,YAAA,IAAA;KACA,OAAA,OAAA,GAAA;KACA,UAAA;KACA;IACA;IAEA,IAAA,QAAA,KAAA,KAAA,IAAA,SAAA,QAAA;IACA,IAAA,QAAA,KAAA,GACA,OAAA,IAAA,KAAA;KACA,MAAA,IAAA;KACA,aAAA,IAAA;KACA,WAAA,IAAA;IACA,CAAA;IAMA,MAAA,MAAA,MAAA,KAAA,MAAA,IAAA,KAAA;IACA,MAAA,OACA,aAAA,OAAA,OAAA,MAAA,SAAA,OAAA,KAAA,IAAA,KAAA,SAAA,MAAA;IACA,IAAA,IAAA,SAAA,CAAA,QAAA,CAAA,IAAA,aAAA,UAAA;IACA,IAAA,cAAA;IACA,IAAA,OAAA,CAAA;IACA,WAAA;KAAA;KAAA,QAAA;IAAA;GACA;GAMA,IAAA,SAAA;IACA,MAAA,OAAA;IACA,MAAA,OAAA;GACA;EACA;CACA;CAEA,SAAA,QAAA;EACA,KAAA,MAAA,SAAA,MAAA,YAAA;GACA,MAAA,oBAAA,aAAA,KAAA;GACA,MAAA,iBAAA,aAAA,KAAA;EACA;EACA,MAAA;CACA;CAEA,MAAA,WAAA,iBAAA,UAAA,KAAA;CACA,MAAA,WAAA,iBAAA,YAAA,KAAA;CACA,MAAA;CAEA,OAAA;EACA,OAAA,MAAA;GACA,KAAA;GACA,MAAA;EACA;EACA,UAAA;GACA,KAAA;GACA,MAAA;GACA,MAAA,WAAA,oBAAA,UAAA,KAAA;GACA,MAAA,WAAA,oBAAA,YAAA,KAAA;GACA,KAAA,MAAA,SAAA,MAAA,YAAA,MAAA,oBAAA,aAAA,KAAA;EACA;CACA;AACA"}
1
+ {"version":3,"file":"cues.js","names":[],"sources":["../../src/controls/cues.ts"],"sourcesContent":["/**\n * Subtitles and the bar. Two things.\n *\n * The lift: the browser draws native cues on the bottom edge of the video,\n * and under the bar. Every active cue the author left unpositioned is\n * moved up: above the bar while it shows, and one line off the edge while\n * it is hidden, so the text never sits on the picture's border. The\n * position is a negative line count, the one form every browser wraps at\n * the video's width; a percentage does not wrap in Chromium. Chromium\n * anchors the box's top on the count and Gecko its bottom, and their\n * overlap avoidance pushes in opposite directions, so nothing is left to\n * them: subtitles often show two cues at once, and the cues stack by their\n * own measured heights, wrapping included, clear under both readings. A\n * cue with a position of its own is the author's and is not touched.\n *\n * The look: `::cue` can only be styled from the document that holds the\n * video, which is the page and not the shadow root, and it takes no custom\n * properties. So a small sheet goes into the document, once, with one rule\n * per look the host's `subtitle-size` and `subtitle-background` attributes\n * can take. Sizes are percentages of the browser's own cue size, which\n * already follows the video's height, in the page and in fullscreen alike.\n * A page that wants more writes its own `mattebox-player > video::cue`.\n */\nimport CUE_RULES from './cues.css?inline';\n/** How the sizes scale the browser's own cue size; the lift counts lines by it. */\nexport const SCALES: Readonly<Record<string, number>> = {\n small: 0.75,\n medium: 1,\n large: 1.5,\n xlarge: 2,\n};\n\n/**\n * The sheet in the document. `mattebox-player` is the element's tag. The\n * background goes on `::cue` and on the backdrop pseudo-element Chromium\n * and WebKit have, both: which of the two paints it differs by browser and\n * version, and a selector a browser does not know only voids its own rule.\n */\n\nconst MARK = 'data-mattebox-cue';\n\n/** The browser's cue size against the video's height, per WebVTT, and its line against the size. */\nconst CUE_SIZE = 0.05;\nconst LINE_HEIGHT = 1.2;\n/** What a cue box spans of the video's width by default, so wrapping is measured against it. */\nconst CUE_WIDTH = 0.96;\n/** Pixels of air between the bar and the cue above it, before rounding up to a line. */\nconst AIR = 6;\n/** Lines of air under a cue while the bar is hidden. */\nconst REST = 1;\n\n/** Puts the cue rules in the document, once. */\nexport function cueStyle(): void {\n if (document.head.querySelector(`style[${MARK}]`) !== null) return;\n const style = document.createElement('style');\n style.setAttribute(MARK, '');\n style.textContent = CUE_RULES;\n document.head.append(style);\n}\n\n/** What a lifted cue looked like before, to put back. */\ninterface Placed {\n readonly line: number | 'auto';\n readonly snapToLines: boolean;\n readonly lineAlign: LineAlignSetting;\n}\n\nexport interface CueLift {\n /** Whether the bar is showing, so the cues move above it or back. */\n lifted(on: boolean): void;\n dispose(): void;\n}\n\n/** What the bar covers of the picture: from its first row's top, not its gradient run-in, to its bottom. */\nexport type Covered = () => { readonly top: number; readonly bottom: number };\n\nexport function cueLift(video: HTMLVideoElement, host: HTMLElement, covered: Covered): CueLift {\n /** The cues moved, with what they were, so they and only they are put back. */\n const lifted = new Map<VTTCue, Placed>();\n let on = false;\n /** False once disposed: the cues go back to where the author left them. */\n let live = true;\n let canvas: CanvasRenderingContext2D | null | undefined;\n\n function showing(): TextTrack[] {\n const out: TextTrack[] = [];\n for (const track of video.textTracks) if (track.mode === 'showing') out.push(track);\n return out;\n }\n\n /** The browser's cue font size, in pixels, from the video's height and the host's scale. */\n function fontSize(height: number): number {\n const scale = SCALES[host.getAttribute('subtitle-size') ?? ''] ?? 1;\n return height * CUE_SIZE * scale;\n }\n\n /** Measures text the way the browser draws cues, to count the lines a cue wraps into. */\n function measure(): CanvasRenderingContext2D | null {\n if (canvas === undefined) canvas = document.createElement('canvas').getContext('2d');\n return canvas;\n }\n\n /**\n * A cue's text without its tags, for measuring: `<b>`, `<c.name>`, the\n * timestamps and their closers. Brackets are counted, so a tag inside\n * another's brackets goes with it.\n */\n function plain(text: string): string {\n let out = '';\n let depth = 0;\n for (const char of text) {\n if (char === '<') depth += 1;\n else if (char === '>') depth = Math.max(0, depth - 1);\n else if (depth === 0) out += char;\n }\n return out;\n }\n\n /** The lines a cue takes: its own, each wrapped at the cue box's width. */\n function lines(cue: VTTCue, font: number, width: number): number {\n const context = measure();\n let total = 0;\n for (const line of plain(cue.text).split('\\n')) {\n if (context === null) {\n total += 1;\n continue;\n }\n context.font = `${font}px sans-serif`;\n total += Math.max(1, Math.ceil(context.measureText(line).width / (width * CUE_WIDTH)));\n }\n return total;\n }\n\n function apply(): void {\n const box = video.getBoundingClientRect();\n const height = box.height;\n const span = covered();\n const pixels = span.bottom - span.top;\n const lift = live && height > 0;\n const font = fontSize(height);\n const unit = font * LINE_HEIGHT;\n // The lines the bar covers, with a little air, rounded up to whole\n // lines. With the bar hidden, the cue rests a line off the edge.\n const barred = on && pixels > 0 && pixels < height;\n const base = barred ? Math.ceil((pixels + AIR) / unit) : REST;\n for (const track of showing()) {\n // Earliest first, the order the browser stacks them in, so the first\n // sits lowest and the rest climb.\n const active = [...(track.activeCues ?? [])]\n .filter((cue): cue is VTTCue => cue instanceof VTTCue)\n .sort((a, b) => a.startTime - b.startTime);\n let previous: { line: number; height: number } | null = null;\n let changed = false;\n for (const cue of active) {\n const was = lifted.get(cue);\n if (!lift) {\n if (was === undefined) continue;\n cue.line = was.line;\n cue.snapToLines = was.snapToLines;\n cue.lineAlign = was.lineAlign;\n lifted.delete(cue);\n changed = true;\n continue;\n }\n // The author's own placement is the author's.\n if (was === undefined && cue.line !== 'auto') continue;\n if (was === undefined) {\n lifted.set(cue, {\n line: cue.line,\n snapToLines: cue.snapToLines,\n lineAlign: cue.lineAlign,\n });\n }\n // A negative line count, which every browser wraps at the video's\n // width, unlike a percentage. Chromium anchors the box's top on it\n // and Gecko its bottom, so the count clears the bar and the cue\n // below under both readings, with a little air to spare in one.\n const own = lines(cue, font, box.width);\n const line: number =\n previous === null ? base + own : previous.line + Math.max(own, previous.height);\n if (cue.line !== -line || !cue.snapToLines) changed = true;\n cue.snapToLines = true;\n cue.line = -line;\n previous = { line, height: own };\n }\n // Chromium lays a changed line out again only when the track's display\n // is rebuilt, which neither time nor a seek does for a cue already\n // showing; the mode flipped off and on in one task rebuilds it with no\n // paint in between. Only on a change, so the change event this fires\n // finds nothing to do and the loop ends there.\n if (changed) {\n track.mode = 'hidden';\n track.mode = 'showing';\n }\n }\n }\n\n function watch(): void {\n for (const track of video.textTracks) {\n track.removeEventListener('cuechange', apply);\n track.addEventListener('cuechange', apply);\n }\n apply();\n }\n\n video.textTracks.addEventListener('change', watch);\n video.textTracks.addEventListener('addtrack', watch);\n watch();\n\n return {\n lifted(next: boolean): void {\n on = next;\n apply();\n },\n dispose(): void {\n on = false;\n live = false;\n apply();\n video.textTracks.removeEventListener('change', watch);\n video.textTracks.removeEventListener('addtrack', watch);\n for (const track of video.textTracks) track.removeEventListener('cuechange', apply);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAA,YAAA;;AAEA,MAAA,SAAA;CACA,OAAA;CACA,QAAA;CACA,OAAA;CACA,QAAA;AACA;;;;;;;AASA,MAAA,OAAA;;AAGA,MAAA,WAAA;AACA,MAAA,cAAA;;AAEA,MAAA,YAAA;;AAEA,MAAA,MAAA;;AAEA,MAAA,OAAA;;AAGA,SAAA,WAAA;CACA,IAAA,SAAA,KAAA,cAAA,SAAA,KAAA,EAAA,MAAA,MAAA;CACA,MAAA,QAAA,SAAA,cAAA,OAAA;CACA,MAAA,aAAA,MAAA,EAAA;CACA,MAAA,cAAA;CACA,SAAA,KAAA,OAAA,KAAA;AACA;AAkBA,SAAA,QAAA,OAAA,MAAA,SAAA;;CAEA,MAAA,yBAAA,IAAA,IAAA;CACA,IAAA,KAAA;;CAEA,IAAA,OAAA;CACA,IAAA;CAEA,SAAA,UAAA;EACA,MAAA,MAAA,CAAA;EACA,KAAA,MAAA,SAAA,MAAA,YAAA,IAAA,MAAA,SAAA,WAAA,IAAA,KAAA,KAAA;EACA,OAAA;CACA;;CAGA,SAAA,SAAA,QAAA;EACA,MAAA,QAAA,OAAA,KAAA,aAAA,eAAA,KAAA,OAAA;EACA,OAAA,SAAA,WAAA;CACA;;CAGA,SAAA,UAAA;EACA,IAAA,WAAA,KAAA,GAAA,SAAA,SAAA,cAAA,QAAA,CAAA,CAAA,WAAA,IAAA;EACA,OAAA;CACA;;;;;;CAOA,SAAA,MAAA,MAAA;EACA,IAAA,MAAA;EACA,IAAA,QAAA;EACA,KAAA,MAAA,QAAA,MACA,IAAA,SAAA,KAAA,SAAA;OACA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AAA,GACA,OAAA,IAAA,KAAA;KACA,MAAA,IAAA;KACA,aAAA,IAAA;KACA,WAAA,IAAA;IACA,CAAA;IAMA,MAAA,MAAA,MAAA,KAAA,MAAA,IAAA,KAAA;IACA,MAAA,OACA,aAAA,OAAA,OAAA,MAAA,SAAA,OAAA,KAAA,IAAA,KAAA,SAAA,MAAA;IACA,IAAA,IAAA,SAAA,CAAA,QAAA,CAAA,IAAA,aAAA,UAAA;IACA,IAAA,cAAA;IACA,IAAA,OAAA,CAAA;IACA,WAAA;KAAA;KAAA,QAAA;IAAA;GACA;GAMA,IAAA,SAAA;IACA,MAAA,OAAA;IACA,MAAA,OAAA;GACA;EACA;CACA;CAEA,SAAA,QAAA;EACA,KAAA,MAAA,SAAA,MAAA,YAAA;GACA,MAAA,oBAAA,aAAA,KAAA;GACA,MAAA,iBAAA,aAAA,KAAA;EACA;EACA,MAAA;CACA;CAEA,MAAA,WAAA,iBAAA,UAAA,KAAA;CACA,MAAA,WAAA,iBAAA,YAAA,KAAA;CACA,MAAA;CAEA,OAAA;EACA,OAAA,MAAA;GACA,KAAA;GACA,MAAA;EACA;EACA,UAAA;GACA,KAAA;GACA,OAAA;GACA,MAAA;GACA,MAAA,WAAA,oBAAA,UAAA,KAAA;GACA,MAAA,WAAA,oBAAA,YAAA,KAAA;GACA,KAAA,MAAA,SAAA,MAAA,YAAA,MAAA,oBAAA,aAAA,KAAA;EACA;CACA;AACA"}
@@ -35,12 +35,21 @@ export interface MenuOptions {
35
35
  readonly host: HTMLElement;
36
36
  /** The picture, in viewport pixels, which the popup never leaves. */
37
37
  readonly picture: () => DOMRect | null;
38
+ /**
39
+ * The player, whose whole box a compact player's sheet fills from the
40
+ * foot. The box can be taller than the picture: a video letterboxed in
41
+ * its player leaves bars the controls sit over. The menu watches its
42
+ * size while it is open.
43
+ */
44
+ readonly frame: () => Element | null;
38
45
  /** The name of the Back item, from the page it leaves: "Back from {page}". */
39
46
  readonly back: (page: string) => string;
40
47
  }
41
48
  export interface Menu {
42
49
  readonly button: HTMLButtonElement;
43
50
  readonly popup: HTMLElement;
51
+ /** The dim over the picture behind a compact player's sheet. A press on it closes the menu. */
52
+ readonly backdrop: HTMLElement;
44
53
  /** The accessible name of the button and the popup. */
45
54
  label(text: string): void;
46
55
  /** Replaces the entries, back at the first page. */
@@ -1 +1 @@
1
- {"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../src/controls/menu.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,SAAS;IACxB,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,CAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC,CAC9F,CAAC;IACF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,aAAa,CAAC,CAAC,CAAC;CACtE;AAED,oEAAoE;AACpE,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,SAAS,EAAE,CAAC;IACvC,sEAAsE;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,aAAa,CAAC;IACrC,oFAAo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GAAG,IAAI,CAAC;IAC1B,oDAAoD;IACpD,IAAI,CAAC,OAAO,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CAAC;IAC1C,KAAK,IAAI,IAAI,CAAC;IACd,OAAO,IAAI,IAAI,CAAC;CACjB;AA2BD,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAmU/C"}
@@ -49,12 +49,30 @@ function menu(options) {
49
49
  button.setAttribute("aria-haspopup", "menu");
50
50
  button.setAttribute("aria-expanded", "false");
51
51
  const popup = el("div", "popup");
52
- popup.addEventListener("scroll", () => {
53
- more();
54
- });
55
52
  popup.setAttribute("role", "menu");
56
53
  popup.hidden = true;
54
+ const backdrop = el("div", "backdrop");
55
+ backdrop.hidden = true;
56
+ backdrop.addEventListener("click", () => {
57
+ close();
58
+ });
57
59
  let open = false;
60
+ /**
61
+ * While the menu is open it follows its player: a change of tier draws
62
+ * the page again, as a popup or as a sheet, and a change of size places
63
+ * it again. A page that resizes with a menu open sees it keep up.
64
+ */
65
+ const tiers = typeof MutationObserver === "undefined" ? null : new MutationObserver(() => {
66
+ if (!open) return;
67
+ const held = popup.contains(focused());
68
+ render();
69
+ if (held) (checked() ?? items()[0])?.focus();
70
+ });
71
+ const sizes = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => {
72
+ if (open) fit();
73
+ });
74
+ /** Whether the page drawn last was drawn for a compact player. */
75
+ let drawnCompact = false;
58
76
  let name = "";
59
77
  let first = [];
60
78
  /** The pages opened, the first being the menu itself. */
@@ -79,25 +97,30 @@ function menu(options) {
79
97
  * left of its right edge.
80
98
  */
81
99
  function fit() {
82
- if (host.getAttribute("layout") === "compact") {
83
- popup.style.maxHeight = "";
100
+ const compact = host.getAttribute("layout") === "compact";
101
+ const picture = compact ? options.frame()?.getBoundingClientRect() ?? null : options.picture();
102
+ backdrop.hidden = !(open && compact && picture !== null);
103
+ for (const node of [popup, backdrop]) node.style.left = node.style.bottom = node.style.width = "";
104
+ backdrop.style.height = "";
105
+ if (picture === null) return;
106
+ if (compact) {
107
+ const box = host.getBoundingClientRect();
108
+ for (const node of [popup, backdrop]) {
109
+ node.style.left = `${picture.left - box.left}px`;
110
+ node.style.bottom = `${box.bottom - picture.bottom}px`;
111
+ node.style.width = `${picture.width}px`;
112
+ }
113
+ backdrop.style.height = `${picture.height}px`;
114
+ popup.style.maxHeight = `${Math.max(0, Math.floor(picture.height - AIR))}px`;
84
115
  popup.style.maxWidth = "";
85
- more();
86
116
  return;
87
117
  }
88
- const picture = options.picture();
89
- if (picture === null) return;
90
118
  const room = button.getBoundingClientRect().top - picture.top - AIR;
91
119
  const most = Number.parseFloat(getComputedStyle(host).getPropertyValue("--mbx-menu-max-height")) || MAX_HEIGHT * (Number.parseFloat(getComputedStyle(host).fontSize) || 16);
92
120
  popup.style.maxHeight = `${Math.max(0, Math.floor(Math.min(most, room)))}px`;
93
- more();
94
121
  const wide = host.getBoundingClientRect().right - picture.left - AIR;
95
122
  popup.style.maxWidth = `${Math.max(0, Math.floor(wide))}px`;
96
123
  }
97
- /** `more` on the popup while rows wait below its foot, which then fades out. */
98
- function more() {
99
- popup.toggleAttribute("more", popup.scrollTop + popup.clientHeight < popup.scrollHeight - 1);
100
- }
101
124
  function clear() {
102
125
  for (const item of items()) {
103
126
  const handler = handlers.get(item);
@@ -119,7 +142,16 @@ function menu(options) {
119
142
  const page = stack[stack.length - 1];
120
143
  if (page === void 0) return;
121
144
  let tab = true;
122
- if (stack.length === 1 && name !== "") {
145
+ drawnCompact = host.getAttribute("layout") === "compact";
146
+ if (stack.length === 1 && name !== "" && drawnCompact) {
147
+ const leave = item("item back-item", name, () => {
148
+ close();
149
+ button.focus();
150
+ });
151
+ leave.setAttribute("role", "menuitem");
152
+ leave.setAttribute("aria-label", options.back(name));
153
+ popup.append(leave);
154
+ } else if (stack.length === 1 && name !== "") {
123
155
  const title = el("div", "title", name);
124
156
  title.setAttribute("aria-hidden", "true");
125
157
  popup.append(title);
@@ -198,7 +230,10 @@ function menu(options) {
198
230
  function close() {
199
231
  if (!open) return;
200
232
  open = false;
233
+ tiers?.disconnect();
234
+ sizes?.disconnect();
201
235
  popup.hidden = true;
236
+ backdrop.hidden = true;
202
237
  button.setAttribute("aria-expanded", "false");
203
238
  host.removeAttribute("open");
204
239
  document.removeEventListener("pointerdown", outside, true);
@@ -210,10 +245,17 @@ function menu(options) {
210
245
  function show() {
211
246
  if (open) return;
212
247
  open = true;
248
+ if (host.getAttribute("layout") === "compact" !== drawnCompact) render();
213
249
  popup.hidden = false;
214
250
  button.setAttribute("aria-expanded", "true");
215
251
  host.setAttribute("open", "");
216
252
  document.addEventListener("pointerdown", outside, true);
253
+ tiers?.observe(host, {
254
+ attributes: true,
255
+ attributeFilter: ["layout"]
256
+ });
257
+ const frame = options.frame();
258
+ if (frame !== null) sizes?.observe(frame);
217
259
  fit();
218
260
  (checked() ?? items()[0])?.focus();
219
261
  }
@@ -260,6 +302,7 @@ function menu(options) {
260
302
  return {
261
303
  button,
262
304
  popup,
305
+ backdrop,
263
306
  label(text) {
264
307
  name = text;
265
308
  button.setAttribute("aria-label", text);
@@ -1 +1 @@
1
- {"version":3,"file":"menu.js","names":[],"sources":["../../src/controls/menu.ts"],"sourcesContent":["/**\n * The menu primitive the quality, audio, subtitles and speed menus share: a\n * button that opens a popup of radio items above it, in one or more groups\n * with a heading each, and pages behind entries that open them. The button\n * carries the name and `aria-expanded`; the popup is `role=\"menu\"`, every\n * choice a `menuitemradio` with `aria-checked`, the checked one also\n * carrying `checked` on its part name, because an item inside a shadow\n * root has no other seam a page can style; an entry that opens a page is\n * a `menuitem` with `aria-haspopup`, and the page starts with a Back.\n *\n * Open on click. Inside, the arrows move focus across every item, Home and\n * End jump, Enter and Space choose, Escape goes back a page or closes and\n * hands focus to the button. A choice closes the popup. A pointer down\n * anywhere else closes it too.\n *\n * The popup never leaves the picture: on opening it takes the room above\n * the button up to the top of `picture()` as its height and scrolls past\n * that, and the room from its right edge to the picture's left as its\n * width, where a long item ends in an ellipsis. The\n * element that owns the menu carries `open` while the popup shows, which\n * the bar reads to hold its fade.\n */\nimport { el, setChildren, state } from '../dom.js';\n\nexport interface MenuGroup {\n /** The part suffix: `track`, `size`. */\n readonly name: string;\n /** A heading, or none for a menu of one group. */\n readonly label?: string;\n /** The label names the group for a screen reader, and no heading is drawn. */\n readonly hideLabel?: boolean;\n /**\n * Each item's id, its text, a detail drawn at its end, such as a chapter's\n * time, the URL of a picture drawn at its start, and short badges drawn\n * after the text, such as \"AD\" on an audio description track.\n */\n readonly items: ReadonlyArray<\n readonly [string, string, (string | undefined)?, (string | undefined)?, (readonly string[])?]\n >;\n readonly value: string;\n readonly onSelect: (value: string) => void;\n /**\n * The badges drawn as a glyph, by their text. The text stays in the\n * badge for a screen reader and as its tooltip.\n */\n readonly badgeGlyphs?: Readonly<Record<string, () => SVGSVGElement>>;\n}\n\n/** An entry that opens a page of groups, with a Back at its top. */\nexport interface MenuPage {\n readonly name: string;\n readonly label: string;\n readonly entries: readonly MenuEntry[];\n /** A glyph drawn before the label of the item that opens the page. */\n readonly glyph?: () => SVGSVGElement;\n /** A detail drawn at the end of that item, such as the value chosen on the page. */\n readonly detail?: string;\n}\n\nexport type MenuEntry = MenuGroup | MenuPage;\n\nexport interface MenuOptions {\n /** The element the menu belongs to: it carries `open`, and a pointer inside it is not outside. */\n readonly host: HTMLElement;\n /** The picture, in viewport pixels, which the popup never leaves. */\n readonly picture: () => DOMRect | null;\n /** The name of the Back item, from the page it leaves: \"Back from {page}\". */\n readonly back: (page: string) => string;\n}\n\nexport interface Menu {\n readonly button: HTMLButtonElement;\n readonly popup: HTMLElement;\n /** The accessible name of the button and the popup. */\n label(text: string): void;\n /** Replaces the entries, back at the first page. */\n fill(entries: readonly MenuEntry[]): void;\n close(): void;\n dispose(): void;\n}\n\n/** Air between the popup's top and the picture's. */\nconst AIR = 8;\n\n/**\n * The tallest a popup grows, in pixels: the title and about seven and a half rows, so\n * the half row at the foot says the list goes on. A page sets its own\n * with `--mbx-menu-max-height`.\n */\n/* In em of the menu's own font size. */\nconst MAX_HEIGHT = 22;\n\n/** An item's picture. Decorative: the item's text names it. Loaded when the popup first shows it. */\nfunction picture(url: string): HTMLImageElement {\n const node = el('img', 'item-image');\n node.alt = '';\n node.loading = 'lazy';\n node.decoding = 'async';\n node.src = url;\n return node;\n}\n\nfunction isPage(entry: MenuEntry): entry is MenuPage {\n return 'entries' in entry;\n}\n\nexport function menu(options: MenuOptions): Menu {\n const { host } = options;\n const button = el('button', 'button');\n button.type = 'button';\n button.setAttribute('aria-haspopup', 'menu');\n button.setAttribute('aria-expanded', 'false');\n const popup = el('div', 'popup');\n popup.addEventListener('scroll', () => {\n more();\n });\n popup.setAttribute('role', 'menu');\n popup.hidden = true;\n\n let open = false;\n let name = '';\n let first: readonly MenuEntry[] = [];\n /** The pages opened, the first being the menu itself. */\n let stack: MenuPage[] = [];\n const handlers = new WeakMap<HTMLButtonElement, () => void>();\n\n function items(): HTMLButtonElement[] {\n return [...popup.querySelectorAll('button')];\n }\n\n function checked(): HTMLButtonElement | undefined {\n return items().find((item) => item.getAttribute('aria-checked') === 'true');\n }\n\n /** The focused element as this tree sees it: inside shadow DOM, `document.activeElement` is the host. */\n function focused(): Element | null {\n return (popup.getRootNode() as Document | ShadowRoot).activeElement;\n }\n\n function outside(event: PointerEvent): void {\n if (!event.composedPath().includes(host)) close();\n }\n\n /**\n * The popup's height: its maximum, or the room above the button if that\n * is less, so the popup never leaves the picture. Its width: the room\n * left of its right edge.\n */\n function fit(): void {\n // A compact player's menu is a sheet on the page: the stylesheet sizes it.\n if (host.getAttribute('layout') === 'compact') {\n popup.style.maxHeight = '';\n popup.style.maxWidth = '';\n more();\n return;\n }\n const picture = options.picture();\n if (picture === null) return;\n const room = button.getBoundingClientRect().top - picture.top - AIR;\n const most =\n Number.parseFloat(getComputedStyle(host).getPropertyValue('--mbx-menu-max-height')) ||\n MAX_HEIGHT * (Number.parseFloat(getComputedStyle(host).fontSize) || 16);\n popup.style.maxHeight = `${Math.max(0, Math.floor(Math.min(most, room)))}px`;\n more();\n // The popup is anchored at the host's right edge and grows leftwards.\n const wide = host.getBoundingClientRect().right - picture.left - AIR;\n popup.style.maxWidth = `${Math.max(0, Math.floor(wide))}px`;\n }\n\n /** `more` on the popup while rows wait below its foot, which then fades out. */\n function more(): void {\n popup.toggleAttribute('more', popup.scrollTop + popup.clientHeight < popup.scrollHeight - 1);\n }\n\n function clear(): void {\n for (const item of items()) {\n const handler = handlers.get(item);\n if (handler !== undefined) item.removeEventListener('click', handler);\n }\n setChildren(popup);\n }\n\n function item(part: string, text: string, handler: () => void): HTMLButtonElement {\n const node = el('button', part, text);\n node.type = 'button';\n node.tabIndex = -1;\n handlers.set(node, handler);\n node.addEventListener('click', handler);\n return node;\n }\n\n /** Draws the page on top of the stack. */\n function render(): void {\n clear();\n const page = stack[stack.length - 1];\n if (page === undefined) return;\n let tab = true;\n // The first page starts with the menu's name. The popup already carries it for a screen reader.\n if (stack.length === 1 && name !== '') {\n const title = el('div', 'title', name);\n title.setAttribute('aria-hidden', 'true');\n popup.append(title);\n }\n if (stack.length > 1) {\n const back = item('item back-item', page.label, () => {\n stack.pop();\n render();\n items()[0]?.focus();\n });\n back.setAttribute('role', 'menuitem');\n back.setAttribute('aria-label', options.back(page.label));\n popup.append(back);\n }\n for (const entry of page.entries) {\n if (isPage(entry)) {\n const link = item(`item page-item ${entry.name}-item`, entry.label, () => {\n stack.push(entry);\n render();\n items()[0]?.focus();\n });\n link.setAttribute('role', 'menuitem');\n link.setAttribute('aria-haspopup', 'menu');\n if (entry.glyph !== undefined) {\n link.prepend(entry.glyph());\n state(link, `item page-item ${entry.name}-item`, { 'glyph-item': true });\n }\n if (entry.detail !== undefined) link.append(el('span', 'item-detail', entry.detail));\n popup.append(link);\n continue;\n }\n const section = el('div', `section ${entry.name}-section`);\n section.setAttribute('role', 'group');\n if (entry.label !== undefined) {\n section.setAttribute('aria-label', entry.label);\n if (entry.hideLabel !== true) {\n section.append(el('div', `section-label ${entry.name}-label`, entry.label));\n }\n }\n for (const [id, text, detail, image, badges] of entry.items) {\n const choice = item(`item ${entry.name}-item`, text, () => {\n close();\n button.focus();\n entry.onSelect(id);\n });\n for (const badge of badges ?? []) {\n const glyph = entry.badgeGlyphs?.[badge];\n if (glyph === undefined) {\n choice.append(el('span', 'item-badge', badge));\n continue;\n }\n // The glyph is what a viewer sees, and the text is what a screen reader says.\n const drawn = el('span', 'item-badge item-glyph');\n drawn.title = badge;\n drawn.append(glyph(), el('span', 'badge-text', badge));\n choice.append(drawn);\n }\n if (detail !== undefined) choice.append(el('span', 'item-detail', detail));\n if (image !== undefined) {\n // The text in a box of its own, so a long title ends in an ellipsis beside the picture.\n const [, ...rest] = choice.childNodes;\n setChildren(choice, el('span', 'item-text', text), ...rest);\n choice.prepend(picture(image));\n }\n choice.value = id;\n choice.setAttribute('role', 'menuitemradio');\n const on = id === entry.value;\n choice.setAttribute('aria-checked', String(on));\n state(choice, `item ${entry.name}-item`, { checked: on });\n // One tab stop: the first checked item.\n if (on && tab) {\n choice.tabIndex = 0;\n tab = false;\n }\n section.append(choice);\n }\n popup.append(section);\n }\n fit();\n }\n\n function close(): void {\n if (!open) return;\n open = false;\n popup.hidden = true;\n button.setAttribute('aria-expanded', 'false');\n host.removeAttribute('open');\n document.removeEventListener('pointerdown', outside, true);\n if (stack.length > 1) {\n stack = stack.slice(0, 1);\n render();\n }\n }\n\n function show(): void {\n if (open) return;\n open = true;\n popup.hidden = false;\n button.setAttribute('aria-expanded', 'true');\n host.setAttribute('open', '');\n document.addEventListener('pointerdown', outside, true);\n fit();\n (checked() ?? items()[0])?.focus();\n }\n\n function toggle(): void {\n if (open) close();\n else show();\n }\n\n function key(event: KeyboardEvent): void {\n // Handled already, by a handler that decides first.\n if (event.defaultPrevented) return;\n const list = items();\n const index = list.indexOf(focused() as HTMLButtonElement);\n let next: number;\n switch (event.key) {\n case 'ArrowDown':\n next = (index + 1) % list.length;\n break;\n case 'ArrowUp':\n next = (index - 1 + list.length) % list.length;\n break;\n case 'Home':\n next = 0;\n break;\n case 'End':\n next = list.length - 1;\n break;\n case 'Escape':\n event.preventDefault();\n if (stack.length > 1) {\n stack.pop();\n render();\n items()[0]?.focus();\n return;\n }\n close();\n button.focus();\n return;\n default:\n return;\n }\n event.preventDefault();\n list[next]?.focus();\n }\n\n button.addEventListener('click', toggle);\n popup.addEventListener('keydown', key);\n\n return {\n button,\n popup,\n label(text: string): void {\n name = text;\n button.setAttribute('aria-label', text);\n popup.setAttribute('aria-label', text);\n const root = stack[0];\n if (root !== undefined) stack[0] = { ...root, label: text };\n },\n fill(entries): void {\n first = entries;\n stack = [{ name: 'menu', label: name, entries: first }];\n render();\n },\n close,\n dispose(): void {\n close();\n clear();\n button.removeEventListener('click', toggle);\n popup.removeEventListener('keydown', key);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,MAAM,MAAM;;;;;;AAQZ,MAAM,aAAa;;AAGnB,SAAS,QAAQ,KAA+B;CAC9C,MAAM,OAAO,GAAG,OAAO,YAAY;CACnC,KAAK,MAAM;CACX,KAAK,UAAU;CACf,KAAK,WAAW;CAChB,KAAK,MAAM;CACX,OAAO;AACT;AAEA,SAAS,OAAO,OAAqC;CACnD,OAAO,aAAa;AACtB;AAEA,SAAgB,KAAK,SAA4B;CAC/C,MAAM,EAAE,SAAS;CACjB,MAAM,SAAS,GAAG,UAAU,QAAQ;CACpC,OAAO,OAAO;CACd,OAAO,aAAa,iBAAiB,MAAM;CAC3C,OAAO,aAAa,iBAAiB,OAAO;CAC5C,MAAM,QAAQ,GAAG,OAAO,OAAO;CAC/B,MAAM,iBAAiB,gBAAgB;EACrC,KAAK;CACP,CAAC;CACD,MAAM,aAAa,QAAQ,MAAM;CACjC,MAAM,SAAS;CAEf,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,QAA8B,CAAC;;CAEnC,IAAI,QAAoB,CAAC;CACzB,MAAM,2BAAW,IAAI,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EAAE,EAAE,MAAM;KAClB;IACF;IACA,MAAM;IACN,OAAO,MAAM;IACb;GACF,SACE;EACJ;EACA,MAAM,eAAe;EACrB,KAAK,KAAK,EAAE,MAAM;CACpB;CAEA,OAAO,iBAAiB,SAAS,MAAM;CACvC,MAAM,iBAAiB,WAAW,GAAG;CAErC,OAAO;EACL;EACA;EACA,MAAM,MAAoB;GACxB,OAAO;GACP,OAAO,aAAa,cAAc,IAAI;GACtC,MAAM,aAAa,cAAc,IAAI;GACrC,MAAM,OAAO,MAAM;GACnB,IAAI,SAAS,KAAA,GAAW,MAAM,KAAK;IAAE,GAAG;IAAM,OAAO;GAAK;EAC5D;EACA,KAAK,SAAe;GAClB,QAAQ;GACR,QAAQ,CAAC;IAAE,MAAM;IAAQ,OAAO;IAAM,SAAS;GAAM,CAAC;GACtD,OAAO;EACT;EACA;EACA,UAAgB;GACd,MAAM;GACN,MAAM;GACN,OAAO,oBAAoB,SAAS,MAAM;GAC1C,MAAM,oBAAoB,WAAW,GAAG;EAC1C;CACF;AACF"}
1
+ {"version":3,"file":"menu.js","names":[],"sources":["../../src/controls/menu.ts"],"sourcesContent":["/**\n * The menu primitive the quality, audio, subtitles and speed menus share: a\n * button that opens a popup of radio items above it, in one or more groups\n * with a heading each, and pages behind entries that open them. The button\n * carries the name and `aria-expanded`; the popup is `role=\"menu\"`, every\n * choice a `menuitemradio` with `aria-checked`, the checked one also\n * carrying `checked` on its part name, because an item inside a shadow\n * root has no other seam a page can style; an entry that opens a page is\n * a `menuitem` with `aria-haspopup`, and the page starts with a Back.\n *\n * Open on click. Inside, the arrows move focus across every item, Home and\n * End jump, Enter and Space choose, Escape goes back a page or closes and\n * hands focus to the button. A choice closes the popup. A pointer down\n * anywhere else closes it too.\n *\n * The popup never leaves the picture: on opening it takes the room above\n * the button up to the top of `picture()` as its height and scrolls past\n * that, and the room from its right edge to the picture's left as its\n * width, where a long item ends in an ellipsis. The\n * element that owns the menu carries `open` while the popup shows, which\n * the bar reads to hold its fade.\n */\nimport { el, setChildren, state } from '../dom.js';\n\nexport interface MenuGroup {\n /** The part suffix: `track`, `size`. */\n readonly name: string;\n /** A heading, or none for a menu of one group. */\n readonly label?: string;\n /** The label names the group for a screen reader, and no heading is drawn. */\n readonly hideLabel?: boolean;\n /**\n * Each item's id, its text, a detail drawn at its end, such as a chapter's\n * time, the URL of a picture drawn at its start, and short badges drawn\n * after the text, such as \"AD\" on an audio description track.\n */\n readonly items: ReadonlyArray<\n readonly [string, string, (string | undefined)?, (string | undefined)?, (readonly string[])?]\n >;\n readonly value: string;\n readonly onSelect: (value: string) => void;\n /**\n * The badges drawn as a glyph, by their text. The text stays in the\n * badge for a screen reader and as its tooltip.\n */\n readonly badgeGlyphs?: Readonly<Record<string, () => SVGSVGElement>>;\n}\n\n/** An entry that opens a page of groups, with a Back at its top. */\nexport interface MenuPage {\n readonly name: string;\n readonly label: string;\n readonly entries: readonly MenuEntry[];\n /** A glyph drawn before the label of the item that opens the page. */\n readonly glyph?: () => SVGSVGElement;\n /** A detail drawn at the end of that item, such as the value chosen on the page. */\n readonly detail?: string;\n}\n\nexport type MenuEntry = MenuGroup | MenuPage;\n\nexport interface MenuOptions {\n /** The element the menu belongs to: it carries `open`, and a pointer inside it is not outside. */\n readonly host: HTMLElement;\n /** The picture, in viewport pixels, which the popup never leaves. */\n readonly picture: () => DOMRect | null;\n /**\n * The player, whose whole box a compact player's sheet fills from the\n * foot. The box can be taller than the picture: a video letterboxed in\n * its player leaves bars the controls sit over. The menu watches its\n * size while it is open.\n */\n readonly frame: () => Element | null;\n /** The name of the Back item, from the page it leaves: \"Back from {page}\". */\n readonly back: (page: string) => string;\n}\n\nexport interface Menu {\n readonly button: HTMLButtonElement;\n readonly popup: HTMLElement;\n /** The dim over the picture behind a compact player's sheet. A press on it closes the menu. */\n readonly backdrop: HTMLElement;\n /** The accessible name of the button and the popup. */\n label(text: string): void;\n /** Replaces the entries, back at the first page. */\n fill(entries: readonly MenuEntry[]): void;\n close(): void;\n dispose(): void;\n}\n\n/** Air between the popup's top and the picture's. */\nconst AIR = 8;\n\n/**\n * The tallest a popup grows, in pixels: the title and about seven and a half rows, so\n * the half row at the foot says the list goes on. A page sets its own\n * with `--mbx-menu-max-height`.\n */\n/* In em of the menu's own font size. */\nconst MAX_HEIGHT = 22;\n\n/** An item's picture. Decorative: the item's text names it. Loaded when the popup first shows it. */\nfunction picture(url: string): HTMLImageElement {\n const node = el('img', 'item-image');\n node.alt = '';\n node.loading = 'lazy';\n node.decoding = 'async';\n node.src = url;\n return node;\n}\n\nfunction isPage(entry: MenuEntry): entry is MenuPage {\n return 'entries' in entry;\n}\n\nexport function menu(options: MenuOptions): Menu {\n const { host } = options;\n const button = el('button', 'button');\n button.type = 'button';\n button.setAttribute('aria-haspopup', 'menu');\n button.setAttribute('aria-expanded', 'false');\n const popup = el('div', 'popup');\n popup.setAttribute('role', 'menu');\n popup.hidden = true;\n const backdrop = el('div', 'backdrop');\n backdrop.hidden = true;\n backdrop.addEventListener('click', () => {\n close();\n });\n\n let open = false;\n /**\n * While the menu is open it follows its player: a change of tier draws\n * the page again, as a popup or as a sheet, and a change of size places\n * it again. A page that resizes with a menu open sees it keep up.\n */\n const tiers =\n typeof MutationObserver === 'undefined'\n ? null\n : new MutationObserver(() => {\n if (!open) return;\n // The rows are drawn again, so the focus goes back to one of them.\n const held = popup.contains(focused());\n render();\n if (held) (checked() ?? items()[0])?.focus();\n });\n const sizes =\n typeof ResizeObserver === 'undefined'\n ? null\n : new ResizeObserver(() => {\n if (open) fit();\n });\n /** Whether the page drawn last was drawn for a compact player. */\n let drawnCompact = false;\n let name = '';\n let first: readonly MenuEntry[] = [];\n /** The pages opened, the first being the menu itself. */\n let stack: MenuPage[] = [];\n const handlers = new WeakMap<HTMLButtonElement, () => void>();\n\n function items(): HTMLButtonElement[] {\n return [...popup.querySelectorAll('button')];\n }\n\n function checked(): HTMLButtonElement | undefined {\n return items().find((item) => item.getAttribute('aria-checked') === 'true');\n }\n\n /** The focused element as this tree sees it: inside shadow DOM, `document.activeElement` is the host. */\n function focused(): Element | null {\n return (popup.getRootNode() as Document | ShadowRoot).activeElement;\n }\n\n function outside(event: PointerEvent): void {\n if (!event.composedPath().includes(host)) close();\n }\n\n /**\n * The popup's height: its maximum, or the room above the button if that\n * is less, so the popup never leaves the picture. Its width: the room\n * left of its right edge.\n */\n function fit(): void {\n const compact = host.getAttribute('layout') === 'compact';\n const picture = compact\n ? (options.frame()?.getBoundingClientRect() ?? null)\n : options.picture();\n backdrop.hidden = !(open && compact && picture !== null);\n for (const node of [popup, backdrop]) {\n node.style.left = node.style.bottom = node.style.width = '';\n }\n backdrop.style.height = '';\n if (picture === null) return;\n // A compact player's menu is a sheet from the foot of the player, as wide\n // as the player and never taller, over the controls. It stays inside the\n // player: a page around a small player keeps its own space. The dim\n // covers the rest of the player.\n if (compact) {\n const box = host.getBoundingClientRect();\n for (const node of [popup, backdrop]) {\n node.style.left = `${picture.left - box.left}px`;\n node.style.bottom = `${box.bottom - picture.bottom}px`;\n node.style.width = `${picture.width}px`;\n }\n backdrop.style.height = `${picture.height}px`;\n popup.style.maxHeight = `${Math.max(0, Math.floor(picture.height - AIR))}px`;\n popup.style.maxWidth = '';\n return;\n }\n const room = button.getBoundingClientRect().top - picture.top - AIR;\n const most =\n Number.parseFloat(getComputedStyle(host).getPropertyValue('--mbx-menu-max-height')) ||\n MAX_HEIGHT * (Number.parseFloat(getComputedStyle(host).fontSize) || 16);\n popup.style.maxHeight = `${Math.max(0, Math.floor(Math.min(most, room)))}px`;\n // The popup is anchored at the host's right edge and grows leftwards.\n const wide = host.getBoundingClientRect().right - picture.left - AIR;\n popup.style.maxWidth = `${Math.max(0, Math.floor(wide))}px`;\n }\n\n function clear(): void {\n for (const item of items()) {\n const handler = handlers.get(item);\n if (handler !== undefined) item.removeEventListener('click', handler);\n }\n setChildren(popup);\n }\n\n function item(part: string, text: string, handler: () => void): HTMLButtonElement {\n const node = el('button', part, text);\n node.type = 'button';\n node.tabIndex = -1;\n handlers.set(node, handler);\n node.addEventListener('click', handler);\n return node;\n }\n\n /** Draws the page on top of the stack. */\n function render(): void {\n clear();\n const page = stack[stack.length - 1];\n if (page === undefined) return;\n let tab = true;\n // The first page starts with the menu's name. On a compact player the\n // menu is a sheet over the controls, so the name is the way back: a\n // press on it closes the sheet. Elsewhere it is a title, and the popup\n // already carries the name for a screen reader.\n drawnCompact = host.getAttribute('layout') === 'compact';\n if (stack.length === 1 && name !== '' && drawnCompact) {\n const leave = item('item back-item', name, () => {\n close();\n button.focus();\n });\n leave.setAttribute('role', 'menuitem');\n leave.setAttribute('aria-label', options.back(name));\n popup.append(leave);\n } else if (stack.length === 1 && name !== '') {\n const title = el('div', 'title', name);\n title.setAttribute('aria-hidden', 'true');\n popup.append(title);\n }\n if (stack.length > 1) {\n const back = item('item back-item', page.label, () => {\n stack.pop();\n render();\n items()[0]?.focus();\n });\n back.setAttribute('role', 'menuitem');\n back.setAttribute('aria-label', options.back(page.label));\n popup.append(back);\n }\n for (const entry of page.entries) {\n if (isPage(entry)) {\n const link = item(`item page-item ${entry.name}-item`, entry.label, () => {\n stack.push(entry);\n render();\n items()[0]?.focus();\n });\n link.setAttribute('role', 'menuitem');\n link.setAttribute('aria-haspopup', 'menu');\n if (entry.glyph !== undefined) {\n link.prepend(entry.glyph());\n state(link, `item page-item ${entry.name}-item`, { 'glyph-item': true });\n }\n if (entry.detail !== undefined) link.append(el('span', 'item-detail', entry.detail));\n popup.append(link);\n continue;\n }\n const section = el('div', `section ${entry.name}-section`);\n section.setAttribute('role', 'group');\n if (entry.label !== undefined) {\n section.setAttribute('aria-label', entry.label);\n if (entry.hideLabel !== true) {\n section.append(el('div', `section-label ${entry.name}-label`, entry.label));\n }\n }\n for (const [id, text, detail, image, badges] of entry.items) {\n const choice = item(`item ${entry.name}-item`, text, () => {\n close();\n button.focus();\n entry.onSelect(id);\n });\n for (const badge of badges ?? []) {\n const glyph = entry.badgeGlyphs?.[badge];\n if (glyph === undefined) {\n choice.append(el('span', 'item-badge', badge));\n continue;\n }\n // The glyph is what a viewer sees, and the text is what a screen reader says.\n const drawn = el('span', 'item-badge item-glyph');\n drawn.title = badge;\n drawn.append(glyph(), el('span', 'badge-text', badge));\n choice.append(drawn);\n }\n if (detail !== undefined) choice.append(el('span', 'item-detail', detail));\n if (image !== undefined) {\n // The text in a box of its own, so a long title ends in an ellipsis beside the picture.\n const [, ...rest] = choice.childNodes;\n setChildren(choice, el('span', 'item-text', text), ...rest);\n choice.prepend(picture(image));\n }\n choice.value = id;\n choice.setAttribute('role', 'menuitemradio');\n const on = id === entry.value;\n choice.setAttribute('aria-checked', String(on));\n state(choice, `item ${entry.name}-item`, { checked: on });\n // One tab stop: the first checked item.\n if (on && tab) {\n choice.tabIndex = 0;\n tab = false;\n }\n section.append(choice);\n }\n popup.append(section);\n }\n fit();\n }\n\n function close(): void {\n if (!open) return;\n open = false;\n tiers?.disconnect();\n sizes?.disconnect();\n popup.hidden = true;\n backdrop.hidden = true;\n button.setAttribute('aria-expanded', 'false');\n host.removeAttribute('open');\n document.removeEventListener('pointerdown', outside, true);\n if (stack.length > 1) {\n stack = stack.slice(0, 1);\n render();\n }\n }\n\n function show(): void {\n if (open) return;\n open = true;\n // The tier may have changed since the page was drawn: its first row differs.\n if ((host.getAttribute('layout') === 'compact') !== drawnCompact) render();\n popup.hidden = false;\n button.setAttribute('aria-expanded', 'true');\n host.setAttribute('open', '');\n document.addEventListener('pointerdown', outside, true);\n tiers?.observe(host, { attributes: true, attributeFilter: ['layout'] });\n const frame = options.frame();\n if (frame !== null) sizes?.observe(frame);\n fit();\n (checked() ?? items()[0])?.focus();\n }\n\n function toggle(): void {\n if (open) close();\n else show();\n }\n\n function key(event: KeyboardEvent): void {\n // Handled already, by a handler that decides first.\n if (event.defaultPrevented) return;\n const list = items();\n const index = list.indexOf(focused() as HTMLButtonElement);\n let next: number;\n switch (event.key) {\n case 'ArrowDown':\n next = (index + 1) % list.length;\n break;\n case 'ArrowUp':\n next = (index - 1 + list.length) % list.length;\n break;\n case 'Home':\n next = 0;\n break;\n case 'End':\n next = list.length - 1;\n break;\n case 'Escape':\n event.preventDefault();\n if (stack.length > 1) {\n stack.pop();\n render();\n items()[0]?.focus();\n return;\n }\n close();\n button.focus();\n return;\n default:\n return;\n }\n event.preventDefault();\n list[next]?.focus();\n }\n\n button.addEventListener('click', toggle);\n popup.addEventListener('keydown', key);\n\n return {\n button,\n popup,\n backdrop,\n label(text: string): void {\n name = text;\n button.setAttribute('aria-label', text);\n popup.setAttribute('aria-label', text);\n const root = stack[0];\n if (root !== undefined) stack[0] = { ...root, label: text };\n },\n fill(entries): void {\n first = entries;\n stack = [{ name: 'menu', label: name, entries: first }];\n render();\n },\n close,\n dispose(): void {\n close();\n clear();\n button.removeEventListener('click', toggle);\n popup.removeEventListener('keydown', key);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA2FA,MAAM,MAAM;;;;;;AAQZ,MAAM,aAAa;;AAGnB,SAAS,QAAQ,KAA+B;CAC9C,MAAM,OAAO,GAAG,OAAO,YAAY;CACnC,KAAK,MAAM;CACX,KAAK,UAAU;CACf,KAAK,WAAW;CAChB,KAAK,MAAM;CACX,OAAO;AACT;AAEA,SAAS,OAAO,OAAqC;CACnD,OAAO,aAAa;AACtB;AAEA,SAAgB,KAAK,SAA4B;CAC/C,MAAM,EAAE,SAAS;CACjB,MAAM,SAAS,GAAG,UAAU,QAAQ;CACpC,OAAO,OAAO;CACd,OAAO,aAAa,iBAAiB,MAAM;CAC3C,OAAO,aAAa,iBAAiB,OAAO;CAC5C,MAAM,QAAQ,GAAG,OAAO,OAAO;CAC/B,MAAM,aAAa,QAAQ,MAAM;CACjC,MAAM,SAAS;CACf,MAAM,WAAW,GAAG,OAAO,UAAU;CACrC,SAAS,SAAS;CAClB,SAAS,iBAAiB,eAAe;EACvC,MAAM;CACR,CAAC;CAED,IAAI,OAAO;;;;;;CAMX,MAAM,QACJ,OAAO,qBAAqB,cACx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K;IACxC;GACF,KAAK;IACH,OAAO;IACP;GACF,KAAK;IACH,OAAO,KAAK,SAAS;IACrB;GACF,KAAK;IACH,MAAM,eAAe;IACrB,IAAI,MAAM,SAAS,GAAG;KACpB,MAAM,IAAI;KACV,OAAO;KACP,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM;KAClB;IACF;IACA,MAAM;IACN,OAAO,MAAM;IACb;GACF,SACE;EACJ;EACA,MAAM,eAAe;EACrB,KAAK,KAAK,EAAE,MAAM;CACpB;CAEA,OAAO,iBAAiB,SAAS,MAAM;CACvC,MAAM,iBAAiB,WAAW,GAAG;CAErC,OAAO;EACL;EACA;EACA;EACA,MAAM,MAAoB;GACxB,OAAO;GACP,OAAO,aAAa,cAAc,IAAI;GACtC,MAAM,aAAa,cAAc,IAAI;GACrC,MAAM,OAAO,MAAM;GACnB,IAAI,SAAS,KAAA,GAAW,MAAM,KAAK;IAAE,GAAG;IAAM,OAAO;GAAK;EAC5D;EACA,KAAK,SAAe;GAClB,QAAQ;GACR,QAAQ,CAAC;IAAE,MAAM;IAAQ,OAAO;IAAM,SAAS;GAAM,CAAC;GACtD,OAAO;EACT;EACA;EACA,UAAgB;GACd,MAAM;GACN,MAAM;GACN,OAAO,oBAAoB,SAAS,MAAM;GAC1C,MAAM,oBAAoB,WAAW,GAAG;EAC1C;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"menu-element.d.ts","sourceRoot":"","sources":["../../src/elements/menu-element.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,8BAAsB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,CAAE,SAAQ,SAAS;IAC/E,mBAA2B,IAAI,EAAE,IAAI,CAAC;IACtC,mBAA2B,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;gBAEjD,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,aAAa;IAarE,sCAAsC;IACtC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,MAAM;cAEd,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAGlC;AAED,2DAA2D;AAC3D,wBAAgB,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,aAAa,CAAC,CAElF"}
1
+ {"version":3,"file":"menu-element.d.ts","sourceRoot":"","sources":["../../src/elements/menu-element.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,8BAAsB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,CAAE,SAAQ,SAAS;IAC/E,mBAA2B,IAAI,EAAE,IAAI,CAAC;IACtC,mBAA2B,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;gBAEjD,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,aAAa;IAcrE,sCAAsC;IACtC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,MAAM;cAEd,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAGlC;AAED,2DAA2D;AAC3D,wBAAgB,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,aAAa,CAAC,CAElF"}
@@ -11,11 +11,12 @@ var MenuElement = class extends Component {
11
11
  this.menu = menu({
12
12
  host: this,
13
13
  picture: () => this.player?.video.getBoundingClientRect() ?? null,
14
+ frame: () => this.player,
14
15
  back: (page) => fill(this.getAttribute("label-back") ?? "Back from {page}", { page })
15
16
  });
16
17
  this.slots = iconSlots(states, glyphs);
17
18
  for (const state of states) this.menu.button.append(this.slots[state]);
18
- root.append(style(MENU_STYLE), this.menu.button, this.menu.popup);
19
+ root.append(style(MENU_STYLE), this.menu.button, this.menu.backdrop, this.menu.popup);
19
20
  }
20
21
  detach() {
21
22
  this.menu.close();
@@ -1 +1 @@
1
- {"version":3,"file":"menu-element.js","names":[],"sources":["../../src/elements/menu-element.ts"],"sourcesContent":["/**\n * What the menus share: the primitive in the shadow root, the glyph slots\n * on its button, the name from `label`, the Back item's name from\n * `label-back`, and the popup fitted under the top of the picture. A\n * subclass fills the entries in `render()`, which runs on attach, on every\n * observed attribute, and whenever it asks.\n */\nimport type { IconName } from '../controls/icons.js';\nimport { icon } from '../controls/icons.js';\nimport type { Menu } from '../controls/menu.js';\nimport { menu } from '../controls/menu.js';\nimport { fill } from '../labels.js';\nimport { Component } from './component.js';\nimport { iconSlots, MENU_STYLE, style } from './shared.js';\n\nexport abstract class MenuElement<S extends string = 'default'> extends Component {\n declare protected readonly menu: Menu;\n declare protected readonly slots: Record<S, HTMLSlotElement>;\n\n constructor(states: readonly S[], glyphs: (state: S) => SVGSVGElement) {\n super();\n const root = this.attachShadow({ mode: 'open' });\n this.menu = menu({\n host: this,\n picture: () => this.player?.video.getBoundingClientRect() ?? null,\n back: (page) => fill(this.getAttribute('label-back') ?? 'Back from {page}', { page }),\n });\n this.slots = iconSlots(states, glyphs);\n for (const state of states) this.menu.button.append(this.slots[state]);\n root.append(style(MENU_STYLE), this.menu.button, this.menu.popup);\n }\n\n /** The default name of the button. */\n protected abstract name(): string;\n\n protected override detach(): void {\n this.menu.close();\n }\n\n protected override render(): void {\n this.menu.label(this.getAttribute('label') ?? this.name());\n }\n}\n\n/** A glyph that never changes, for a menu of one state. */\nexport function single(name: IconName): [readonly ['default'], () => SVGSVGElement] {\n return [['default'], () => icon(name)];\n}\n"],"mappings":";;;;;;AAeA,IAAsB,cAAtB,cAAwE,UAAU;CAIhF,YAAY,QAAsB,QAAqC;EACrE,MAAM;EACN,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,KAAK,OAAO,KAAK;GACf,MAAM;GACN,eAAe,KAAK,QAAQ,MAAM,sBAAsB,KAAK;GAC7D,OAAO,SAAS,KAAK,KAAK,aAAa,YAAY,KAAK,oBAAoB,EAAE,KAAK,CAAC;EACtF,CAAC;EACD,KAAK,QAAQ,UAAU,QAAQ,MAAM;EACrC,KAAK,MAAM,SAAS,QAAQ,KAAK,KAAK,OAAO,OAAO,KAAK,MAAM,MAAM;EACrE,KAAK,OAAO,MAAM,UAAU,GAAG,KAAK,KAAK,QAAQ,KAAK,KAAK,KAAK;CAClE;CAKA,SAAkC;EAChC,KAAK,KAAK,MAAM;CAClB;CAEA,SAAkC;EAChC,KAAK,KAAK,MAAM,KAAK,aAAa,OAAO,KAAK,KAAK,KAAK,CAAC;CAC3D;AACF;;AAGA,SAAgB,OAAO,MAA6D;CAClF,OAAO,CAAC,CAAC,SAAS,SAAS,KAAK,IAAI,CAAC;AACvC"}
1
+ {"version":3,"file":"menu-element.js","names":[],"sources":["../../src/elements/menu-element.ts"],"sourcesContent":["/**\n * What the menus share: the primitive in the shadow root, the glyph slots\n * on its button, the name from `label`, the Back item's name from\n * `label-back`, and the popup fitted under the top of the picture. A\n * subclass fills the entries in `render()`, which runs on attach, on every\n * observed attribute, and whenever it asks.\n */\nimport type { IconName } from '../controls/icons.js';\nimport { icon } from '../controls/icons.js';\nimport type { Menu } from '../controls/menu.js';\nimport { menu } from '../controls/menu.js';\nimport { fill } from '../labels.js';\nimport { Component } from './component.js';\nimport { iconSlots, MENU_STYLE, style } from './shared.js';\n\nexport abstract class MenuElement<S extends string = 'default'> extends Component {\n declare protected readonly menu: Menu;\n declare protected readonly slots: Record<S, HTMLSlotElement>;\n\n constructor(states: readonly S[], glyphs: (state: S) => SVGSVGElement) {\n super();\n const root = this.attachShadow({ mode: 'open' });\n this.menu = menu({\n host: this,\n picture: () => this.player?.video.getBoundingClientRect() ?? null,\n frame: () => this.player,\n back: (page) => fill(this.getAttribute('label-back') ?? 'Back from {page}', { page }),\n });\n this.slots = iconSlots(states, glyphs);\n for (const state of states) this.menu.button.append(this.slots[state]);\n root.append(style(MENU_STYLE), this.menu.button, this.menu.backdrop, this.menu.popup);\n }\n\n /** The default name of the button. */\n protected abstract name(): string;\n\n protected override detach(): void {\n this.menu.close();\n }\n\n protected override render(): void {\n this.menu.label(this.getAttribute('label') ?? this.name());\n }\n}\n\n/** A glyph that never changes, for a menu of one state. */\nexport function single(name: IconName): [readonly ['default'], () => SVGSVGElement] {\n return [['default'], () => icon(name)];\n}\n"],"mappings":";;;;;;AAeA,IAAsB,cAAtB,cAAwE,UAAU;CAIhF,YAAY,QAAsB,QAAqC;EACrE,MAAM;EACN,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,KAAK,OAAO,KAAK;GACf,MAAM;GACN,eAAe,KAAK,QAAQ,MAAM,sBAAsB,KAAK;GAC7D,aAAa,KAAK;GAClB,OAAO,SAAS,KAAK,KAAK,aAAa,YAAY,KAAK,oBAAoB,EAAE,KAAK,CAAC;EACtF,CAAC;EACD,KAAK,QAAQ,UAAU,QAAQ,MAAM;EACrC,KAAK,MAAM,SAAS,QAAQ,KAAK,KAAK,OAAO,OAAO,KAAK,MAAM,MAAM;EACrE,KAAK,OAAO,MAAM,UAAU,GAAG,KAAK,KAAK,QAAQ,KAAK,KAAK,UAAU,KAAK,KAAK,KAAK;CACtF;CAKA,SAAkC;EAChC,KAAK,KAAK,MAAM;CAClB;CAEA,SAAkC;EAChC,KAAK,KAAK,MAAM,KAAK,aAAa,OAAO,KAAK,KAAK,KAAK,CAAC;CAC3D;AACF;;AAGA,SAAgB,OAAO,MAA6D;CAClF,OAAO,CAAC,CAAC,SAAS,SAAS,KAAK,IAAI,CAAC;AACvC"}
@@ -19,7 +19,7 @@ function number(node, name, fallback) {
19
19
  return Number.isFinite(value) && value >= 0 ? value : fallback;
20
20
  }
21
21
  /** The style of a menu: the button from BUTTON_STYLE, and the popup above it with its items. */
22
- const MENU_STYLE = ":host{display:inline-flex}:host([hidden]){display:none}[part~=button]{width:2.5em;height:2.5em;font:inherit;color:inherit;border-radius:var(--mbx-radius);cursor:pointer;opacity:.9;background:0 0;border:0;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex;position:relative}[part~=button][aria-label]:after{content:attr(aria-label);display:var(--mbx-tooltip,block);background:var(--mbx-surface);border-radius:var(--mbx-radius);white-space:nowrap;pointer-events:none;opacity:0;margin-bottom:.4615em;padding:.3077em .6154em;font-size:.8125em;transition:opacity .1s;position:absolute;bottom:100%;left:50%;transform:translate(-50%)}[part~=button][aria-label]:focus:after{opacity:1;transition-delay:.4s}[part~=button][aria-label]:focus:not(:focus-visible):after{opacity:0;transition-delay:0s}@media (hover:hover){[part~=button][aria-label]:hover:after{opacity:1;transition-delay:.4s}}:host(:last-child) [part~=button][aria-label]:after{left:auto;right:0;transform:none}[part~=button]:hover{opacity:1}[part~=button]:focus{outline:2px solid var(--mbx-accent);outline-offset:-2px}[part~=button]:focus:not(:focus-visible){outline:none}[part~=icon],::slotted(*){fill:currentColor;width:1.75em;height:1.75em}slot[hidden]{display:none}:host{position:relative}[part~=popup]{box-sizing:border-box;overscroll-behavior:contain;border-radius:var(--mbx-radius);background:#1c1c20f2;flex-direction:column;min-width:16em;margin-bottom:.5714em;padding:.4286em;font-size:.875em;display:flex;position:absolute;bottom:100%;right:0;overflow-y:auto;box-shadow:0 4px 16px #00000080}[part~=popup][hidden]{display:none}[part~=popup][more]{-webkit-mask-image:linear-gradient(#000 calc(100% - 1.5em),#0000);mask-image:linear-gradient(#000 calc(100% - 1.5em),#0000)}[part~=title],[part~=back-item]{letter-spacing:.06em;text-transform:uppercase;color:var(--mbx-muted);font-size:.8125em;font-weight:600}[part~=title]{border-bottom:1px solid #ffffff1f;margin:-.5275em -.5275em .5275em;padding:.9231em 1.4066em}[part~=section]{flex-direction:column;display:flex}[part~=section]+[part~=section]{border-top:1px solid #ffffff1f;margin-top:.4286em;padding-top:.4286em}[part~=section-label]{letter-spacing:.06em;text-transform:uppercase;color:var(--mbx-muted);padding:.3636em 1.0909em .1818em;font-size:.7857em;font-weight:600}[part~=glyph-item]{padding-left:1em}[part~=glyph-item]>svg{margin-right:.75em}[part~=item]{width:100%;font:inherit;color:inherit;text-align:left;white-space:nowrap;border-radius:var(--mbx-radius);cursor:pointer;background:0 0;border:0;align-items:center;padding:.7857em 1em .7857em 2.2857em;display:flex}[part~=item]:hover{background:#ffffff1f}[part~=item-text]{white-space:normal;-webkit-line-clamp:2;-webkit-box-orient:vertical;min-width:0;max-width:16em;display:-webkit-box;overflow:hidden}[part~=item-image]{object-fit:cover;background:#ffffff14;border-radius:2px;flex:none;width:4.5714em;height:2.5714em;margin-right:.8571em}[part~=item-badge]{border:1px solid;border-radius:2px;flex:none;margin-left:auto;padding:0 .381em;font-size:.75em;font-weight:600;line-height:1.5}[part~=item-glyph]{border:0;padding:0;font-size:1em;display:inline-flex}[part~=item-glyph] svg,[part~=glyph-item]>svg{fill:currentColor;flex:none;width:1.5em;height:1.5em}[part~=badge-text]{clip:rect(0 0 0 0);white-space:nowrap;width:1px;height:1px;position:absolute;overflow:hidden}[part~=item-detail]{color:var(--mbx-muted);font-variant-numeric:tabular-nums;margin-left:auto;padding-left:.8571em}[part~=item-badge]~[part~=item-badge],[part~=item-badge]~[part~=item-detail]{margin-left:.7619em}[part~=item]:focus{outline:2px solid var(--mbx-accent);outline-offset:-2px}[part~=item]:focus:not(:focus-visible){outline:none}[part~=page-item]{padding-right:2em;position:relative}[part~=page-item]:after{content:\"\";opacity:.7;border:1.5px solid;border-width:1.5px 1.5px 0 0;width:.5em;height:.5em;margin-top:-.2857em;position:absolute;top:50%;right:.8571em;transform:rotate(45deg)}[part~=back-item]{border-bottom:1px solid #ffffff1f;border-radius:0;margin-bottom:.5275em;padding:.9231em 1.2308em .9231em 2.4615em;position:relative}[part~=back-item]:before{content:\"\";opacity:.7;border:0 solid;border-width:1.5px 0 0 1.5px;width:.5em;height:.5em;margin-top:-.2857em;position:absolute;top:50%;left:1em;transform:rotate(-45deg)}[part~=checked]{background:#ffffff14;position:relative}[part~=checked]:before{content:\"\";background:var(--mbx-accent);border-radius:50%;width:.4286em;height:.4286em;margin-top:-.2143em;position:absolute;top:50%;left:1em}:host([layout=compact]) [part~=popup]{z-index:1000;max-height:70vh;padding-bottom:calc(.4286em + env(safe-area-inset-bottom,0px));background:#1c1c20;border-radius:.75em .75em 0 0;margin:0;font-size:1em;position:fixed;bottom:0;left:0;right:0;box-shadow:0 0 0 100vmax #00000080}";
22
+ const MENU_STYLE = ":host{display:inline-flex}:host([hidden]){display:none}[part~=button]{width:2.5em;height:2.5em;font:inherit;color:inherit;border-radius:var(--mbx-radius);cursor:pointer;opacity:.9;background:0 0;border:0;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex;position:relative}[part~=button][aria-label]:after{content:attr(aria-label);display:var(--mbx-tooltip,block);background:var(--mbx-surface);border-radius:var(--mbx-radius);white-space:nowrap;pointer-events:none;opacity:0;margin-bottom:.4615em;padding:.3077em .6154em;font-size:.8125em;transition:opacity .1s;position:absolute;bottom:100%;left:50%;transform:translate(-50%)}[part~=button][aria-label]:focus:after{opacity:1;transition-delay:.4s}[part~=button][aria-label]:focus:not(:focus-visible):after{opacity:0;transition-delay:0s}@media (hover:hover){[part~=button][aria-label]:hover:after{opacity:1;transition-delay:.4s}}:host(:last-child) [part~=button][aria-label]:after{left:auto;right:0;transform:none}[part~=button]:hover{opacity:1}[part~=button]:focus{outline:2px solid var(--mbx-accent);outline-offset:-2px}[part~=button]:focus:not(:focus-visible){outline:none}[part~=icon],::slotted(*){fill:currentColor;width:1.75em;height:1.75em}slot[hidden]{display:none}:host{position:relative}[part~=popup]{box-sizing:border-box;overscroll-behavior:contain;border-radius:var(--mbx-radius);background:#1c1c20f2;flex-direction:column;min-width:16em;margin-bottom:.5714em;padding:.4286em;font-size:.875em;display:flex;position:absolute;bottom:100%;right:0;overflow-y:auto;box-shadow:0 4px 16px #00000080}[part~=popup][hidden]{display:none}[part~=section]{flex-direction:column;display:flex}[part~=section]+[part~=section]{border-top:1px solid #ffffff1f;margin-top:.4286em;padding-top:.4286em}[part~=section-label]{letter-spacing:.06em;text-transform:uppercase;color:var(--mbx-muted);padding:.3636em 1.0909em .1818em;font-size:.7857em;font-weight:600}[part~=glyph-item]{padding-left:1em}[part~=glyph-item]>svg{margin-right:.75em}[part~=item]{width:100%;font:inherit;color:inherit;text-align:left;white-space:nowrap;border-radius:var(--mbx-radius);cursor:pointer;background:0 0;border:0;align-items:center;padding:.7857em 1em .7857em 2.2857em;display:flex}[part~=item]:hover{background:#ffffff1f}[part~=item-text]{white-space:normal;-webkit-line-clamp:2;-webkit-box-orient:vertical;min-width:0;max-width:16em;display:-webkit-box;overflow:hidden}[part~=item-image]{object-fit:cover;background:#ffffff14;border-radius:2px;flex:none;width:4.5714em;height:2.5714em;margin-right:.8571em}[part~=item-badge]{border:1px solid;border-radius:2px;flex:none;margin-left:auto;padding:0 .381em;font-size:.75em;font-weight:600;line-height:1.5}[part~=item-glyph]{border:0;padding:0;font-size:1em;display:inline-flex}[part~=item-glyph] svg,[part~=glyph-item]>svg{fill:currentColor;flex:none;width:1.5em;height:1.5em}[part~=badge-text]{clip:rect(0 0 0 0);white-space:nowrap;width:1px;height:1px;position:absolute;overflow:hidden}[part~=item-detail]{color:var(--mbx-muted);font-variant-numeric:tabular-nums;margin-left:auto;padding-left:.8571em}[part~=item-badge]~[part~=item-badge],[part~=item-badge]~[part~=item-detail]{margin-left:.7619em}[part~=item]:focus{outline:2px solid var(--mbx-accent);outline-offset:-2px}[part~=item]:focus:not(:focus-visible){outline:none}[part~=page-item]{padding-right:2em;position:relative}[part~=page-item]:after{content:\"\";opacity:.7;border:1.5px solid;border-width:1.5px 1.5px 0 0;width:.5em;height:.5em;margin-top:-.2857em;position:absolute;top:50%;right:.8571em;transform:rotate(45deg)}[part~=title],[part~=back-item]{letter-spacing:.06em;text-transform:uppercase;color:var(--mbx-muted);font-size:.8125em;font-weight:600}[part~=title]{border-bottom:1px solid #ffffff1f;margin:-.5275em -.5275em .5275em;padding:.9231em 1.4066em}[part~=back-item]{border-bottom:1px solid #ffffff1f;border-radius:0;margin-bottom:.5275em;padding:.9231em 1.2308em .9231em 2.4615em;position:relative}[part~=back-item]:before{content:\"\";opacity:.7;border:0 solid;border-width:1.5px 0 0 1.5px;width:.5em;height:.5em;margin-top:-.2857em;position:absolute;top:50%;left:1em;transform:rotate(-45deg)}[part~=checked]{background:#ffffff14;position:relative}[part~=checked]:before{content:\"\";background:var(--mbx-accent);border-radius:50%;width:.4286em;height:.4286em;margin-top:-.2143em;position:absolute;top:50%;left:1em}:host([layout=compact]) [part~=popup]{z-index:1000;padding-bottom:calc(.4286em + env(safe-area-inset-bottom,0px));box-shadow:none;background:#1c1c20;border-radius:.75em .75em 0 0;margin:0;font-size:1em;right:auto}[part~=backdrop]{z-index:999;background:#00000080;position:absolute}[part~=backdrop][hidden]{display:none}";
23
23
  /** Puts a control in the bar's seek row when it is in a bar, unless the page wrote a `slot` of its own. */
24
24
  function seekRow(node) {
25
25
  if (node.parentElement?.localName === "mbx-control-bar" && !node.hasAttribute("slot")) node.slot = "seek";
@@ -12,10 +12,13 @@ export declare class MbxStartButton extends Component {
12
12
  protected attach(player: PlayerHost): void;
13
13
  protected detach(): void;
14
14
  /**
15
- * The button sits in the middle of the picture left over the bar's
16
- * controls, not of the whole player: with the bar at the foot, the
17
- * player's own middle reads as too low. The bar's top padding is the
18
- * lead-in of its gradient, so the controls start under it.
15
+ * The button sits between two middles: the player's own, and the middle
16
+ * of the picture left over the bar's controls. With the bar at the foot,
17
+ * the player's middle reads as too low. The bar is light, a line and a
18
+ * few glyphs over a gradient, so the middle of what it leaves reads as
19
+ * too high, most of all in a short player. Halfway between them is where
20
+ * the eye puts the centre. The bar's top padding is the lead-in of its
21
+ * gradient, so the controls start under it.
19
22
  *
20
23
  * Cramped when the button's foot would be inside the bar's box, which
21
24
  * starts at the top of its gradient: then the bar's own play button is
@@ -1 +1 @@
1
- {"version":3,"file":"start-button.d.ts","sourceRoot":"","sources":["../../src/elements/start-button.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAS3C,qBAAa,cAAe,SAAQ,SAAS;IAC3C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,MAAM,CAAoB;IACnD,iBAAyB,KAAK,CAAiC;IAC/D,8FAA8F;IAC9F,QAAgB,MAAM,CAAU;IAChC,kFAAkF;IAClF,QAAgB,OAAO,CAAwB;;cAkB5B,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAwChC,MAAM,IAAI,IAAI;IAOjC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,GAAG;cAqBQ,MAAM,IAAI,IAAI;CAiBlC"}
1
+ {"version":3,"file":"start-button.d.ts","sourceRoot":"","sources":["../../src/elements/start-button.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAS3C,qBAAa,cAAe,SAAQ,SAAS;IAC3C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,MAAM,CAAoB;IACnD,iBAAyB,KAAK,CAAiC;IAC/D,8FAA8F;IAC9F,QAAgB,MAAM,CAAU;IAChC,kFAAkF;IAClF,QAAgB,OAAO,CAAwB;;cAkB5B,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAwChC,MAAM,IAAI,IAAI;IAOjC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,GAAG;cAqBQ,MAAM,IAAI,IAAI;CAiBlC"}
@@ -2,7 +2,7 @@ import { icon } from "../controls/icons.js";
2
2
  import { Component } from "./component.js";
3
3
  import { BUTTON_STYLE, iconSlots, show, style } from "./shared.js";
4
4
  //#region src/elements/start-button.ts
5
- const STYLE_CSS = ":host{--mbx-tooltip:none;top:var(--mbx-start-top,50%);margin:-2.5em 0 0 -2.5em;position:absolute;left:50%}[part~=button]{z-index:0;width:5em;height:5em;color:var(--mbx-text);background:0 0;border:0;transition:color .15s;position:relative}[part~=button]:before{content:\"\";z-index:-1;background:var(--mbx-surface);opacity:.88;clip-path:polygon(0 0,79% 0,100% 21%,100% 100%,21% 100%,0 79%);transition:opacity .15s,background .15s;position:absolute;top:0;bottom:0;left:0;right:0}[part~=button]:hover{color:var(--mbx-surface)}[part~=button]:hover:before{background:var(--mbx-accent);opacity:1}:host([cramped]){display:none}[part~=icon],::slotted(*){width:3em;height:3em}@media (prefers-reduced-motion:reduce){[part~=button],[part~=button]:before{transition:none}}";
5
+ const STYLE_CSS = ":host{--mbx-tooltip:none;top:var(--mbx-start-top,50%);margin:-2.5em 0 0 -2.5em;position:absolute;left:50%}[part~=button]{z-index:0;width:5em;height:5em;color:var(--mbx-text);background:0 0;border:0;transition:color .15s;position:relative}[part~=button]:before{content:\"\";z-index:-1;background:var(--mbx-surface);opacity:.88;clip-path:polygon(0 0,79% 0,100% 21%,100% 100%,21% 100%,0 79%);transition:opacity .15s,background .15s;position:absolute;top:0;bottom:0;left:0;right:0}[part~=button]:hover{color:var(--mbx-surface)}[part~=button]:hover:before{background:var(--mbx-accent);opacity:1}:host([cramped]){display:none}[part~=icon],::slotted(*){width:3em;height:3em}slot[name=icon-play]>[part~=icon]{margin-left:.125em}@media (prefers-reduced-motion:reduce){[part~=button],[part~=button]:before{transition:none}}";
6
6
  const STATES = ["play", "replay"];
7
7
  const STYLE = BUTTON_STYLE + STYLE_CSS;
8
8
  var MbxStartButton = class extends Component {
@@ -75,10 +75,13 @@ var MbxStartButton = class extends Component {
75
75
  this.style.removeProperty("--mbx-start-top");
76
76
  }
77
77
  /**
78
- * The button sits in the middle of the picture left over the bar's
79
- * controls, not of the whole player: with the bar at the foot, the
80
- * player's own middle reads as too low. The bar's top padding is the
81
- * lead-in of its gradient, so the controls start under it.
78
+ * The button sits between two middles: the player's own, and the middle
79
+ * of the picture left over the bar's controls. With the bar at the foot,
80
+ * the player's middle reads as too low. The bar is light, a line and a
81
+ * few glyphs over a gradient, so the middle of what it leaves reads as
82
+ * too high, most of all in a short player. Halfway between them is where
83
+ * the eye puts the centre. The bar's top padding is the lead-in of its
84
+ * gradient, so the controls start under it.
82
85
  *
83
86
  * Cramped when the button's foot would be inside the bar's box, which
84
87
  * starts at the top of its gradient: then the bar's own play button is
@@ -95,7 +98,7 @@ var MbxStartButton = class extends Component {
95
98
  const box = player.getBoundingClientRect();
96
99
  const barBox = bar.getBoundingClientRect();
97
100
  const controls = barBox.top + (Number.parseFloat(getComputedStyle(bar).paddingTop) || 0);
98
- this.style.setProperty("--mbx-start-top", `${(controls - box.top) / 2}px`);
101
+ this.style.setProperty("--mbx-start-top", `${(box.height + controls - box.top) / 4}px`);
99
102
  const wasHidden = this.hidden;
100
103
  const wasCramped = this.hasAttribute("cramped");
101
104
  this.hidden = false;
@@ -1 +1 @@
1
- {"version":3,"file":"start-button.js","names":[],"sources":["../../src/elements/start-button.ts"],"sourcesContent":["/**\n * <mbx-start-button>: the large play in the middle of the picture, shown\n * while the video is paused, a replay once it has ended, gone while it\n * plays, while a fatal error is on screen, and while the seek bar holds\n * the video paused for a drag (the player carries `scrubbing`). It sits in the player\n * beside the video, not in the bar, so it is over the poster and inside\n * fullscreen, and gone while the player waits for data, where the spinner\n * takes the centre. The glyph is `icon-play` or `icon-replay`, the name\n * `label-play` or `label-replay`.\n */\nimport type { PlayerError } from '@mattebox/player-core';\nimport { icon } from '../controls/icons.js';\nimport type { PlayerHost } from '../host.js';\nimport { Component } from './component.js';\nimport { BUTTON_STYLE, iconSlots, show, style } from './shared.js';\nimport STYLE_CSS from './start-button.css?inline';\n\ntype State = 'play' | 'replay';\nconst STATES: readonly State[] = ['play', 'replay'];\n\nconst STYLE = BUTTON_STYLE + STYLE_CSS;\n\nexport class MbxStartButton extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label-play', 'label-replay'];\n }\n\n declare private readonly button: HTMLButtonElement;\n declare private readonly slots: Record<State, HTMLSlotElement>;\n /** A fatal error is on screen, and the play stays out of its way until playback or a load. */\n declare private failed: boolean;\n /** Watches the player's box: in a short one the button would sit over the bar. */\n declare private resizer: ResizeObserver | null;\n\n constructor() {\n super();\n this.failed = false;\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.button = document.createElement('button');\n this.button.type = 'button';\n this.button.setAttribute('part', 'button');\n this.slots = iconSlots(STATES, icon);\n for (const state of STATES) this.button.append(this.slots[state]);\n this.button.addEventListener('click', () => {\n this.player?.video.play().catch(() => undefined);\n });\n root.append(style(STYLE), this.button);\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.video;\n this.listen(video, ['play', 'pause', 'ended', 'waiting', 'stalled', 'canplay'], () => {\n this.render();\n });\n this.listen(video, ['playing', 'loadstart'], () => {\n this.failed = false;\n this.render();\n });\n this.listen(player, ['sourcechange'], () => {\n this.failed = false;\n this.render();\n });\n this.observe(player, ['scrubbing'], () => {\n this.render();\n });\n const failure = (event: Event): void => {\n const error = (event as CustomEvent<PlayerError>).detail;\n if (!error.fatal) return;\n this.failed = true;\n this.render();\n };\n player.addEventListener('error', failure);\n this.keep(() => {\n player.removeEventListener('error', failure);\n });\n this.failed = player.error !== null;\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(() => {\n this.fit(player);\n });\n this.resizer.observe(player);\n // The bar's height moves the middle too, when its rows wrap or a tier changes.\n const bar = player.querySelector('mbx-control-bar');\n if (bar !== null) this.resizer.observe(bar);\n }\n this.fit(player);\n this.render();\n }\n\n protected override detach(): void {\n this.resizer?.disconnect();\n this.resizer = null;\n this.removeAttribute('cramped');\n this.style.removeProperty('--mbx-start-top');\n }\n\n /**\n * The button sits in the middle of the picture left over the bar's\n * controls, not of the whole player: with the bar at the foot, the\n * player's own middle reads as too low. The bar's top padding is the\n * lead-in of its gradient, so the controls start under it.\n *\n * Cramped when the button's foot would be inside the bar's box, which\n * starts at the top of its gradient: then the bar's own play button is\n * the one to press. Measured with the button shown, since a hidden one\n * has no box.\n */\n private fit(player: PlayerHost): void {\n const bar = player.querySelector('mbx-control-bar');\n if (bar === null) {\n this.removeAttribute('cramped');\n this.style.removeProperty('--mbx-start-top');\n return;\n }\n const box = player.getBoundingClientRect();\n const barBox = bar.getBoundingClientRect();\n const controls = barBox.top + (Number.parseFloat(getComputedStyle(bar).paddingTop) || 0);\n this.style.setProperty('--mbx-start-top', `${(controls - box.top) / 2}px`);\n const wasHidden = this.hidden;\n const wasCramped = this.hasAttribute('cramped');\n this.hidden = false;\n this.removeAttribute('cramped');\n const cramped = this.button.getBoundingClientRect().bottom > barBox.top;\n this.hidden = wasHidden;\n this.toggleAttribute('cramped', cramped);\n if (cramped !== wasCramped) this.render();\n }\n\n protected override render(): void {\n const video = this.player?.video;\n if (video === undefined) return;\n const state: State = video.ended ? 'replay' : 'play';\n show(this.slots, state);\n this.button.setAttribute(\n 'aria-label',\n this.getAttribute(`label-${state}`) ?? (state === 'play' ? 'Play' : 'Replay'),\n );\n // The player reflects `waiting` first: it listens from its constructor.\n const player = this.player;\n this.hidden =\n this.failed ||\n !video.paused ||\n player?.hasAttribute('waiting') === true ||\n player?.hasAttribute('scrubbing') === true;\n }\n}\n"],"mappings":";;;;AAeA,MAAA,YAAA;AAGA,MAAA,SAAA,CAAA,QAAA,QAAA;AAEA,MAAA,QAAA,eAAA;AAEA,IAAA,iBAAA,cAAA,UAAA;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.ts"],"sourcesContent":["/**\n * <mbx-start-button>: the large play in the middle of the picture, shown\n * while the video is paused, a replay once it has ended, gone while it\n * plays, while a fatal error is on screen, and while the seek bar holds\n * the video paused for a drag (the player carries `scrubbing`). It sits in the player\n * beside the video, not in the bar, so it is over the poster and inside\n * fullscreen, and gone while the player waits for data, where the spinner\n * takes the centre. The glyph is `icon-play` or `icon-replay`, the name\n * `label-play` or `label-replay`.\n */\nimport type { PlayerError } from '@mattebox/player-core';\nimport { icon } from '../controls/icons.js';\nimport type { PlayerHost } from '../host.js';\nimport { Component } from './component.js';\nimport { BUTTON_STYLE, iconSlots, show, style } from './shared.js';\nimport STYLE_CSS from './start-button.css?inline';\n\ntype State = 'play' | 'replay';\nconst STATES: readonly State[] = ['play', 'replay'];\n\nconst STYLE = BUTTON_STYLE + STYLE_CSS;\n\nexport class MbxStartButton extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label-play', 'label-replay'];\n }\n\n declare private readonly button: HTMLButtonElement;\n declare private readonly slots: Record<State, HTMLSlotElement>;\n /** A fatal error is on screen, and the play stays out of its way until playback or a load. */\n declare private failed: boolean;\n /** Watches the player's box: in a short one the button would sit over the bar. */\n declare private resizer: ResizeObserver | null;\n\n constructor() {\n super();\n this.failed = false;\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.button = document.createElement('button');\n this.button.type = 'button';\n this.button.setAttribute('part', 'button');\n this.slots = iconSlots(STATES, icon);\n for (const state of STATES) this.button.append(this.slots[state]);\n this.button.addEventListener('click', () => {\n this.player?.video.play().catch(() => undefined);\n });\n root.append(style(STYLE), this.button);\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.video;\n this.listen(video, ['play', 'pause', 'ended', 'waiting', 'stalled', 'canplay'], () => {\n this.render();\n });\n this.listen(video, ['playing', 'loadstart'], () => {\n this.failed = false;\n this.render();\n });\n this.listen(player, ['sourcechange'], () => {\n this.failed = false;\n this.render();\n });\n this.observe(player, ['scrubbing'], () => {\n this.render();\n });\n const failure = (event: Event): void => {\n const error = (event as CustomEvent<PlayerError>).detail;\n if (!error.fatal) return;\n this.failed = true;\n this.render();\n };\n player.addEventListener('error', failure);\n this.keep(() => {\n player.removeEventListener('error', failure);\n });\n this.failed = player.error !== null;\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(() => {\n this.fit(player);\n });\n this.resizer.observe(player);\n // The bar's height moves the middle too, when its rows wrap or a tier changes.\n const bar = player.querySelector('mbx-control-bar');\n if (bar !== null) this.resizer.observe(bar);\n }\n this.fit(player);\n this.render();\n }\n\n protected override detach(): void {\n this.resizer?.disconnect();\n this.resizer = null;\n this.removeAttribute('cramped');\n this.style.removeProperty('--mbx-start-top');\n }\n\n /**\n * The button sits between two middles: the player's own, and the middle\n * of the picture left over the bar's controls. With the bar at the foot,\n * the player's middle reads as too low. The bar is light, a line and a\n * few glyphs over a gradient, so the middle of what it leaves reads as\n * too high, most of all in a short player. Halfway between them is where\n * the eye puts the centre. The bar's top padding is the lead-in of its\n * gradient, so the controls start under it.\n *\n * Cramped when the button's foot would be inside the bar's box, which\n * starts at the top of its gradient: then the bar's own play button is\n * the one to press. Measured with the button shown, since a hidden one\n * has no box.\n */\n private fit(player: PlayerHost): void {\n const bar = player.querySelector('mbx-control-bar');\n if (bar === null) {\n this.removeAttribute('cramped');\n this.style.removeProperty('--mbx-start-top');\n return;\n }\n const box = player.getBoundingClientRect();\n const barBox = bar.getBoundingClientRect();\n const controls = barBox.top + (Number.parseFloat(getComputedStyle(bar).paddingTop) || 0);\n this.style.setProperty('--mbx-start-top', `${(box.height + controls - box.top) / 4}px`);\n const wasHidden = this.hidden;\n const wasCramped = this.hasAttribute('cramped');\n this.hidden = false;\n this.removeAttribute('cramped');\n const cramped = this.button.getBoundingClientRect().bottom > barBox.top;\n this.hidden = wasHidden;\n this.toggleAttribute('cramped', cramped);\n if (cramped !== wasCramped) this.render();\n }\n\n protected override render(): void {\n const video = this.player?.video;\n if (video === undefined) return;\n const state: State = video.ended ? 'replay' : 'play';\n show(this.slots, state);\n this.button.setAttribute(\n 'aria-label',\n this.getAttribute(`label-${state}`) ?? (state === 'play' ? 'Play' : 'Replay'),\n );\n // The player reflects `waiting` first: it listens from its constructor.\n const player = this.player;\n this.hidden =\n this.failed ||\n !video.paused ||\n player?.hasAttribute('waiting') === true ||\n player?.hasAttribute('scrubbing') === true;\n }\n}\n"],"mappings":";;;;AAeA,MAAA,YAAA;AAGA,MAAA,SAAA,CAAA,QAAA,QAAA;AAEA,MAAA,QAAA,eAAA;AAEA,IAAA,iBAAA,cAAA,UAAA;CACA,WAAA,qBAAA;EACA,OAAA,CAAA,cAAA,cAAA;CACA;CASA,cAAA;EACA,MAAA;EACA,KAAA,SAAA;EACA,KAAA,UAAA;EACA,MAAA,OAAA,KAAA,aAAA,EAAA,MAAA,OAAA,CAAA;EACA,KAAA,SAAA,SAAA,cAAA,QAAA;EACA,KAAA,OAAA,OAAA;EACA,KAAA,OAAA,aAAA,QAAA,QAAA;EACA,KAAA,QAAA,UAAA,QAAA,IAAA;EACA,KAAA,MAAA,SAAA,QAAA,KAAA,OAAA,OAAA,KAAA,MAAA,MAAA;EACA,KAAA,OAAA,iBAAA,eAAA;GACA,KAAA,QAAA,MAAA,KAAA,CAAA,CAAA,YAAA,KAAA,CAAA;EACA,CAAA;EACA,KAAA,OAAA,MAAA,KAAA,GAAA,KAAA,MAAA;CACA;CAEA,OAAA,QAAA;EACA,MAAA,QAAA,OAAA;EACA,KAAA,OAAA,OAAA;GAAA;GAAA;GAAA;GAAA;GAAA;GAAA;EAAA,SAAA;GACA,KAAA,OAAA;EACA,CAAA;EACA,KAAA,OAAA,OAAA,CAAA,WAAA,WAAA,SAAA;GACA,KAAA,SAAA;GACA,KAAA,OAAA;EACA,CAAA;EACA,KAAA,OAAA,QAAA,CAAA,cAAA,SAAA;GACA,KAAA,SAAA;GACA,KAAA,OAAA;EACA,CAAA;EACA,KAAA,QAAA,QAAA,CAAA,WAAA,SAAA;GACA,KAAA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A,MAAA,QAAA,KAAA,QAAA;EACA,IAAA,UAAA,KAAA,GAAA;EACA,MAAA,QAAA,MAAA,QAAA,WAAA;EACA,KAAA,KAAA,OAAA,KAAA;EACA,KAAA,OAAA,aACA,cACA,KAAA,aAAA,SAAA,OAAA,MAAA,UAAA,SAAA,SAAA,SACA;EAEA,MAAA,SAAA,KAAA;EACA,KAAA,SACA,KAAA,UACA,CAAA,MAAA,UACA,QAAA,aAAA,SAAA,MAAA,QACA,QAAA,aAAA,WAAA,MAAA;CACA;AACA"}
@@ -1,4 +1,4 @@
1
- //#region \0@oxc-project+runtime@0.152.0/helpers/esm/asyncToGenerator.js
1
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/asyncToGenerator.js
2
2
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
3
3
  try {
4
4
  var i = n[a](c), u = i.value;
@@ -1,5 +1,5 @@
1
1
  import toPropertyKey from "./toPropertyKey.js";
2
- //#region \0@oxc-project+runtime@0.152.0/helpers/esm/defineProperty.js
2
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
3
3
  function _defineProperty(e, r, t) {
4
4
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
5
5
  value: t,
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from "./defineProperty.js";
2
- //#region \0@oxc-project+runtime@0.152.0/helpers/esm/objectSpread2.js
2
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/objectSpread2.js
3
3
  function ownKeys(e, r) {
4
4
  var t = Object.keys(e);
5
5
  if (Object.getOwnPropertySymbols) {
@@ -1,5 +1,5 @@
1
1
  import _typeof from "./typeof.js";
2
- //#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPrimitive.js
2
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
3
3
  function toPrimitive(t, r) {
4
4
  if ("object" != _typeof(t) || !t) return t;
5
5
  var e = t[Symbol.toPrimitive];
@@ -1,6 +1,6 @@
1
1
  import _typeof from "./typeof.js";
2
2
  import toPrimitive from "./toPrimitive.js";
3
- //#region \0@oxc-project+runtime@0.152.0/helpers/esm/toPropertyKey.js
3
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
4
4
  function toPropertyKey(t) {
5
5
  var i = toPrimitive(t, "string");
6
6
  return "symbol" == _typeof(i) ? i : i + "";
@@ -1,4 +1,4 @@
1
- //#region \0@oxc-project+runtime@0.152.0/helpers/esm/typeof.js
1
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
2
2
  function _typeof(o) {
3
3
  "@babel/helpers - typeof";
4
4
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {