@mattebox/player 0.8.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 (102) 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/icons.d.ts +5 -30
  6. package/dist/controls/icons.d.ts.map +1 -1
  7. package/dist/controls/icons.js +38 -29
  8. package/dist/controls/icons.js.map +1 -1
  9. package/dist/controls/menu.d.ts +20 -0
  10. package/dist/controls/menu.d.ts.map +1 -1
  11. package/dist/controls/menu.js +83 -14
  12. package/dist/controls/menu.js.map +1 -1
  13. package/dist/element.d.ts +36 -2
  14. package/dist/element.d.ts.map +1 -1
  15. package/dist/element.js +140 -24
  16. package/dist/element.js.map +1 -1
  17. package/dist/elements/audio-menu.d.ts.map +1 -1
  18. package/dist/elements/audio-menu.js +3 -1
  19. package/dist/elements/audio-menu.js.map +1 -1
  20. package/dist/elements/component.d.ts.map +1 -1
  21. package/dist/elements/component.js +10 -0
  22. package/dist/elements/component.js.map +1 -1
  23. package/dist/elements/control-bar.d.ts +2 -0
  24. package/dist/elements/control-bar.d.ts.map +1 -1
  25. package/dist/elements/control-bar.js +23 -7
  26. package/dist/elements/control-bar.js.map +1 -1
  27. package/dist/elements/current-time.d.ts.map +1 -1
  28. package/dist/elements/current-time.js +1 -1
  29. package/dist/elements/current-time.js.map +1 -1
  30. package/dist/elements/drm-badge.js +1 -1
  31. package/dist/elements/duration.d.ts.map +1 -1
  32. package/dist/elements/duration.js +6 -2
  33. package/dist/elements/duration.js.map +1 -1
  34. package/dist/elements/error-screen.js +1 -1
  35. package/dist/elements/live-button.js +1 -1
  36. package/dist/elements/marker-button.d.ts +3 -3
  37. package/dist/elements/marker-button.d.ts.map +1 -1
  38. package/dist/elements/marker-button.js +18 -22
  39. package/dist/elements/marker-button.js.map +1 -1
  40. package/dist/elements/menu-element.d.ts.map +1 -1
  41. package/dist/elements/menu-element.js +2 -1
  42. package/dist/elements/menu-element.js.map +1 -1
  43. package/dist/elements/quality-menu.js +1 -1
  44. package/dist/elements/quality-menu.js.map +1 -1
  45. package/dist/elements/scan-button.js +1 -1
  46. package/dist/elements/seek-bar.d.ts.map +1 -1
  47. package/dist/elements/seek-bar.js +5 -4
  48. package/dist/elements/seek-bar.js.map +1 -1
  49. package/dist/elements/shared.js +3 -3
  50. package/dist/elements/skip-button.js +2 -2
  51. package/dist/elements/skip-button.js.map +1 -1
  52. package/dist/elements/spinner.js +1 -1
  53. package/dist/elements/start-button.d.ts +8 -0
  54. package/dist/elements/start-button.d.ts.map +1 -1
  55. package/dist/elements/start-button.js +18 -2
  56. package/dist/elements/start-button.js.map +1 -1
  57. package/dist/elements/subtitles-menu.d.ts +5 -1
  58. package/dist/elements/subtitles-menu.d.ts.map +1 -1
  59. package/dist/elements/subtitles-menu.js +29 -11
  60. package/dist/elements/subtitles-menu.js.map +1 -1
  61. package/dist/elements/title.d.ts.map +1 -1
  62. package/dist/elements/title.js +3 -1
  63. package/dist/elements/title.js.map +1 -1
  64. package/dist/elements/volume-slider.js +1 -1
  65. package/dist/elements/volume.js +1 -1
  66. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/asyncToGenerator.js +1 -1
  67. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/defineProperty.js +1 -1
  68. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/objectSpread2.js +1 -1
  69. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPrimitive.js +1 -1
  70. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPropertyKey.js +1 -1
  71. package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/typeof.js +1 -1
  72. package/dist/es2015/controls/chapters.js +1 -1
  73. package/dist/es2015/controls/cues.js +11 -5
  74. package/dist/es2015/controls/icons.js +38 -29
  75. package/dist/es2015/controls/menu.js +89 -17
  76. package/dist/es2015/element.js +144 -30
  77. package/dist/es2015/elements/audio-menu.js +4 -1
  78. package/dist/es2015/elements/component.js +10 -0
  79. package/dist/es2015/elements/control-bar.js +23 -7
  80. package/dist/es2015/elements/current-time.js +1 -1
  81. package/dist/es2015/elements/drm-badge.js +1 -1
  82. package/dist/es2015/elements/duration.js +6 -2
  83. package/dist/es2015/elements/error-screen.js +1 -1
  84. package/dist/es2015/elements/live-button.js +1 -1
  85. package/dist/es2015/elements/marker-button.js +19 -23
  86. package/dist/es2015/elements/menu-element.js +2 -1
  87. package/dist/es2015/elements/quality-menu.js +1 -1
  88. package/dist/es2015/elements/scan-button.js +1 -1
  89. package/dist/es2015/elements/seek-bar.js +5 -4
  90. package/dist/es2015/elements/shared.js +3 -3
  91. package/dist/es2015/elements/skip-button.js +2 -2
  92. package/dist/es2015/elements/spinner.js +1 -1
  93. package/dist/es2015/elements/start-button.js +18 -2
  94. package/dist/es2015/elements/subtitles-menu.js +35 -17
  95. package/dist/es2015/elements/title.js +3 -1
  96. package/dist/es2015/elements/volume-slider.js +1 -1
  97. package/dist/es2015/elements/volume.js +1 -1
  98. package/dist/es2015/presets.js +1 -1
  99. package/dist/es2015/style.js +1 -1
  100. package/dist/style.js +1 -1
  101. package/package.json +4 -5
  102. package/NOTICE +0 -24
@@ -1 +1 @@
1
- {"version":3,"file":"element.js","names":[],"sources":["../src/element.ts"],"sourcesContent":["/**\n * <mattebox-player>: a real <video> as a light-DOM child, so the integrator\n * can reach it, and the error surface in shadow DOM. The element never\n * forwards or wraps a media element member: play, pause, seek, volume and\n * the rest live on the video, where the browser, Picture-in-Picture and the\n * OS media session already find them.\n *\n * The controls are elements the page places inside, beside the video, and\n * the stage slots them over the picture. The element appends none of its\n * own: the composition is the page's in every mode, and `none` hides every\n * child but the video. The element reflects the video's state as\n * attributes on itself, `paused`, `playing`, `ended`, `muted`, `audio`,\n * `started` and `waiting`, for the page's stylesheet and the controls\n * alike.\n *\n * No class fields, `#private` or otherwise: the ES2015 build would lower\n * them into runtime helpers, and the emit check bans helpers. Statics are\n * getters and instance state is declared, then assigned in the constructor.\n */\n\nimport type { Handler, Player, PlayerError, Session, Source } from '@mattebox/player-core';\nimport {\n createPlayer,\n inferType,\n matteboxHandler,\n nativeHandler,\n preferNativeHls,\n} from '@mattebox/player-core';\nimport type { KernelConfig, Mattebox, Stage } from 'mattebox';\nimport type { AttachEmeOptions } from 'mattebox/eme';\nimport type { Marker, Markers } from './controls/markers.js';\nimport { createMarkers } from './controls/markers.js';\nimport type { PlayerHost } from './host.js';\nimport { namespaces } from './namespaces.js';\nimport { drmGuard, resolvePreset } from './presets.js';\nimport { STYLE } from './style.js';\nimport type { ErrorSurface } from './surface.js';\nimport { errorSurface } from './surface.js';\nimport { PLAYER } from './tags.js';\n\n/**\n * `off` keeps HLS on the engine in Safari. Anything else lets Safari play\n * HLS itself: FairPlay, AirPlay, Low-Latency HLS and the platform's\n * fullscreen then work as Apple built them. Changing it reloads.\n */\nconst NATIVE_HLS = 'native-hls';\n\n/** Attributes forwarded onto the video as attributes, never as properties. */\nconst FORWARDED = ['autoplay', 'muted', 'poster', 'crossorigin'];\n\n/** Everything else the element watches. Changing any of them reloads. */\nconst OWN = ['src', 'type', 'preset', 'license-url', 'certificate-url', 'thumbnails', NATIVE_HLS];\n\n/**\n * The chapters file URL. A session with the engine's `chapters` namespace\n * loads it there: through the engine's transport, so request hooks apply,\n * and in every format the engine reads. Any other session gets a\n * `<track kind=\"chapters\">` on the video, hidden so its cues load and\n * nothing is drawn. The seek bar and the chapters menu read either.\n * Changing it never reloads the source.\n */\nconst CHAPTERS = 'chapters';\n\n/**\n * The one attribute whose meaning the element owns: `native` keeps the\n * browser's controls on the video, `custom` swaps them for the controls the\n * page placed inside, `none` takes the browser's off and hides every child\n * but the video. Anything else is `native`. Changing it never touches the\n * session.\n */\nconst CONTROLS = 'controls';\n\n/**\n * Inline playback, on until the page writes `playsinline=\"false\"`, the way\n * `spellcheck` and `draggable` are on until told otherwise. An iPhone takes\n * a video without `playsinline` to its own fullscreen on play, where no\n * control the page placed shows. Changing it never reloads.\n */\nconst PLAYSINLINE = 'playsinline';\n\n/** The video's state, as attributes on the element, read on the events the video fires for it. */\nconst STATE_EVENTS = [\n 'play',\n 'pause',\n 'ended',\n // A seek back from the end leaves `ended` with no play, pause or ended event.\n 'seeked',\n 'emptied',\n 'volumechange',\n 'loadedmetadata',\n 'resize',\n 'playing',\n 'waiting',\n 'stalled',\n 'canplay',\n];\n\n/** The stages that register a key system, which a native session's DRM offers. */\nconst KEY_SYSTEMS = ['eme-fairplay', 'eme-cenc'];\n\n/** Every stage the engine ships. A narrower preset is optimization. */\nconst DEFAULT_PRESET = 'full';\n\n/**\n * What the element dispatches. `error` is also a standard DOM event name, so\n * without these overloads a listener on it is typed as `ErrorEvent` and the\n * payload needs a double cast. They are declarations only: no runtime bytes.\n */\nexport interface MatteboxPlayerEventMap {\n sourcechange: CustomEvent<Session | null>;\n error: CustomEvent<PlayerError>;\n /** The markers changed: set by the page, or cleared by a new source. */\n markerschange: CustomEvent<readonly Marker[]>;\n /** Playback reached a blocked range and moved past it. */\n blocked: CustomEvent<Marker>;\n}\n\nexport interface MatteboxPlayerElement {\n addEventListener<K extends keyof MatteboxPlayerEventMap>(\n type: K,\n listener: (this: MatteboxPlayerElement, event: MatteboxPlayerEventMap[K]) => void,\n options?: boolean | AddEventListenerOptions,\n ): void;\n addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): void;\n removeEventListener<K extends keyof MatteboxPlayerEventMap>(\n type: K,\n listener: (this: MatteboxPlayerElement, event: MatteboxPlayerEventMap[K]) => void,\n options?: boolean | EventListenerOptions,\n ): void;\n removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions,\n ): void;\n}\n\nexport interface MatteboxPlayerOptions {\n /** The whole chain, in order. Takes precedence over `stages` and the `preset` attribute. */\n readonly handlers?: readonly Handler[];\n /** Stages for the mattebox handler. Takes precedence over the `preset` attribute. */\n readonly stages?: readonly Stage[];\n /**\n * Kernel tuning for the engines the elements build, `traceCapacity` among\n * it. A page decision, like the stages, so not an attribute. Ignored with\n * `handlers`, which carry their own.\n */\n readonly config?: Partial<KernelConfig>;\n /**\n * DRM for a native session, as `attachEme` from `mattebox/eme` takes it:\n * `keySystems`, `licenseUrl`, `licenseUrls`, `requestHook`. Without\n * `keySystems` the session offers the key-system stages of the engine's\n * stack. The `license-url` attribute overrides `licenseUrl`, and\n * `certificate-url` gives the FairPlay certificate. Ignored\n * with `handlers`, which carry their own.\n */\n readonly drm?: AttachEmeOptions;\n}\n\n/**\n * What `define()` recorded, for the elements the parser creates. It is the\n * one value shared across elements, because a page that writes only markup\n * still has to be able to say what the engine carries.\n */\nlet defaults: MatteboxPlayerOptions = {};\n\n/**\n * The interface above merges only `addEventListener` and `removeEventListener`\n * overloads, which the class inherits from HTMLElement. The rule it suppresses\n * guards against properties an interface declares and a constructor never\n * assigns, and there are none.\n */\n// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: method overloads only, no properties\nexport class MatteboxPlayerElement extends HTMLElement implements PlayerHost {\n static get observedAttributes(): readonly string[] {\n return [...FORWARDED, ...OWN, CONTROLS, CHAPTERS, PLAYSINLINE];\n }\n\n /**\n * Registers the element once, and records the stages markup-only pages\n * get. The controls register through their own entries, the package's\n * root entry importing every one; a control connected before its player\n * is defined waits for the definition.\n */\n static define(options?: MatteboxPlayerOptions): void {\n if (options !== undefined) defaults = options;\n if (customElements.get(PLAYER) === undefined) {\n customElements.define(PLAYER, MatteboxPlayerElement);\n }\n }\n\n declare private readonly media: HTMLVideoElement;\n /** Wraps the slot: the picture, and the controls over it or under it. */\n declare private readonly stage: HTMLDivElement;\n /** Whether the element gave itself a tabindex for the bar, to take back with it. */\n declare private focusable: boolean;\n declare private readonly surface: ErrorSurface;\n declare private readonly marks: Markers;\n /** The chapters track element, while the `chapters` attribute names one and the engine takes none. */\n declare private track: HTMLTrackElement | null;\n /** The chapters URL the current session's engine was given, or null. */\n declare private given: string | null;\n declare private readonly options: MatteboxPlayerOptions;\n declare private core: Player | null;\n declare private current: Session | null;\n declare private failure: PlayerError | null;\n /** Whether an attribute change is the element's own reflection, which must not write back to the video. */\n declare private reflecting: boolean;\n /** The video has played once since its source was set: `started`, which tells a first play from a pause. */\n declare private started: boolean;\n /** The video waits for data: `waiting`, set on `waiting` and `stalled`, cleared once it can play. */\n declare private waiting: boolean;\n declare private offs: Array<() => void>;\n /** Everything the element does to the player runs here, so it runs in order. */\n declare private queue: Promise<void>;\n /** Whether a run is queued and not yet started, so a burst of changes loads once. */\n declare private pending: boolean;\n\n constructor(options?: MatteboxPlayerOptions) {\n super();\n this.options = options ?? defaults;\n this.focusable = false;\n this.track = null;\n this.given = null;\n this.core = null;\n this.current = null;\n this.failure = null;\n this.reflecting = false;\n this.started = false;\n this.waiting = false;\n this.offs = [];\n this.queue = Promise.resolve();\n this.pending = false;\n\n this.media = document.createElement('video');\n // Native until the `controls` attribute says otherwise, which arrives\n // through attributeChangedCallback: a constructor must not read attributes.\n this.media.controls = true;\n // Inline is the default, and the player's own attribute has not arrived\n // yet. Set as an attribute: not every browser has the `playsInline`\n // property. The fullscreen button still reaches the iPhone's fullscreen,\n // through `webkitEnterFullscreen`.\n this.media.setAttribute(PLAYSINLINE, '');\n for (const name of STATE_EVENTS) {\n this.media.addEventListener(name, () => {\n this.note(name);\n this.reflect();\n });\n }\n // An error over a picture that then plays is wrong by definition.\n this.media.addEventListener('playing', () => {\n this.failure = null;\n });\n this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));\n this.stage = document.createElement('div');\n this.stage.setAttribute('part', 'stage');\n this.stage.append(document.createElement('slot'));\n this.surface = errorSurface(() => {\n this.reload();\n });\n\n const root = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = STYLE;\n root.append(style, this.stage, this.surface.root);\n }\n\n /** The media element. Everything the browser already does is here. */\n get video(): HTMLVideoElement {\n return this.media;\n }\n\n /** The ranges the page named in this source: credits to skip, parts that must not play. */\n get markers(): Markers {\n return this.marks;\n }\n\n /** The core, or null until the first source has been set up: resolving a preset is asynchronous. */\n get player(): Player | null {\n return this.core;\n }\n\n /** The engine feeding the video, or null for a native session and before the first load. */\n get engine(): Mattebox | null {\n return this.current?.engine ?? null;\n }\n\n /**\n * The fatal error of the current load, or null once a load starts or\n * playback resumes. The `error` event says when; this says what, for a\n * control that attaches after the event, such as an error screen parsed\n * after a source that failed while the page was still loading.\n */\n get error(): PlayerError | null {\n return this.failure;\n }\n\n connectedCallback(): void {\n if (this.media.parentNode !== this) this.append(this.media);\n for (const name of FORWARDED) this.forward(name);\n this.reflect();\n this.reload();\n }\n\n /** The two states the video does not hold: whether it has played once, and whether it waits for data. */\n private note(event: string): void {\n if (event === 'playing') {\n this.started = true;\n this.waiting = false;\n } else if (event === 'waiting' || event === 'stalled') {\n this.waiting = true;\n } else if (event === 'canplay') {\n this.waiting = false;\n } else if (event === 'emptied') {\n // A new source starts over: the title shows again before its first play.\n this.started = false;\n this.waiting = false;\n }\n }\n\n /** The video's state on the element, for `mattebox-player[paused]` and the like. */\n private reflect(): void {\n const video = this.media;\n this.reflecting = true;\n this.toggleAttribute('paused', video.paused);\n this.toggleAttribute('playing', !video.paused);\n this.toggleAttribute('ended', video.ended);\n // `muted` is also forwarded: the page's attribute sets the video, and\n // the video's state sets the attribute. Reflection never forwards, so\n // a read can only ever change the attribute, never the video.\n this.toggleAttribute('muted', video.muted);\n this.toggleAttribute('audio', this.audio());\n this.toggleAttribute('started', this.started);\n this.toggleAttribute('waiting', this.waiting);\n this.reflecting = false;\n }\n\n /**\n * Whether the source has no picture. Once the metadata is in, the video's\n * size decides: zero by zero is sound alone, and `resize` catches a stream\n * that moves to or from an audio-only rendition. Before that, the type the\n * page wrote or the URL implies is the hint, so an mp3 is `audio` from\n * the start rather than from its metadata.\n */\n private audio(): boolean {\n const video = this.media;\n if (video.readyState >= HTMLMediaElement.HAVE_METADATA) {\n return video.videoWidth === 0 && video.videoHeight === 0;\n }\n const src = this.getAttribute('src');\n const type = this.getAttribute('type') ?? (src === null ? undefined : inferType(src));\n return type?.startsWith('audio/') === true;\n }\n\n disconnectedCallback(): void {\n // A single-page app must not leave a pipeline attached to a video it\n // navigated away from. Reconnecting loads the `src` again.\n this.enqueue(() => this.teardown());\n }\n\n attributeChangedCallback(name: string): void {\n if (FORWARDED.includes(name)) {\n if (!this.reflecting) this.forward(name);\n return;\n }\n if (name === CONTROLS) {\n this.mode();\n return;\n }\n if (name === CHAPTERS) {\n this.chapters();\n return;\n }\n if (name === PLAYSINLINE) {\n // On the video it is a boolean attribute, so off is absent.\n this.media.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== 'false');\n return;\n }\n // The preset decides the chain, so it is the one attribute that rebuilds it.\n if (name === 'preset') this.enqueue(() => this.discard());\n // The source's type is the hint for `audio` until its metadata arrives.\n // Only `audio`: a full reflection here would drop a `muted` the page\n // wrote before its own callback forwards it.\n if (name === 'src' || name === 'type') this.toggleAttribute('audio', this.audio());\n // Markers belong to a source. Cleared here, not on `emptied`, which\n // arrives later and would clear the ones the page sets right after.\n if (name === 'src' && this.marks.list.length > 0) this.marks.set([]);\n this.reload();\n }\n\n /**\n * Applies the `controls` attribute: the video's own controls and the\n * tabindex. The controls themselves are elements the page placed, and\n * they attach on their own; the element appends none.\n */\n private mode(): void {\n const value = this.getAttribute(CONTROLS);\n const custom = value === 'custom';\n this.media.controls = !custom && value !== 'none';\n // Under custom controls the error screen element carries a fatal error.\n if (custom) this.surface.clear();\n if (!custom) {\n if (this.focusable) this.removeAttribute('tabindex');\n this.focusable = false;\n } else if (!this.hasAttribute('tabindex')) {\n // A bare video is not focusable, so without this a click on it would\n // leave the shortcuts nowhere to listen. A page that set its own\n // tabindex keeps it.\n this.tabIndex = 0;\n this.focusable = true;\n }\n }\n\n /** Hands the `chapters` attribute to the engine, or keeps a hidden chapters track on the video for it. */\n private chapters(): void {\n const url = this.getAttribute(CHAPTERS);\n const engine = this.current?.engine ?? null;\n const api = engine === null ? undefined : namespaces(engine).chapters;\n if (api !== undefined) {\n this.track?.remove();\n this.track = null;\n if (url === this.given) return;\n this.given = url;\n // An empty list removes the chapters the attribute loaded.\n if (url === null) api.set([]);\n else void api.load(url).catch(() => undefined);\n return;\n }\n if (url === null) {\n this.track?.remove();\n this.track = null;\n return;\n }\n const held = this.track;\n if (held !== null && held.parentNode === this.media && held.getAttribute('src') === url) return;\n // A new element each time: one removed mid-load, as the engine's attach\n // does, stays in its error state, and neither a new `src` nor a second\n // insertion starts it loading again.\n held?.remove();\n const track = document.createElement('track');\n track.kind = 'chapters';\n track.src = url;\n this.track = track;\n this.media.append(track);\n // Set after the insertion: a track element's mode exists once it is in\n // a media element, and `hidden` is what makes its cues load unseen.\n track.track.mode = 'hidden';\n }\n\n private forward(name: string): void {\n const value = this.getAttribute(name);\n if (value === null) this.media.removeAttribute(name);\n else this.media.setAttribute(name, value);\n // A video reads `muted` into its state only when it is created, and this\n // one was created before any attribute reached it. Muted autoplay and\n // the autoplay policy read the state, so the attribute alone would not do.\n if (name === 'muted') this.media.muted = value !== null;\n }\n\n private enqueue(task: () => Promise<void>): void {\n this.queue = this.queue.then(task, task).catch(() => undefined);\n }\n\n /**\n * One run per burst. The parser sets every attribute and then connects the\n * element before any queued task starts, and each of those would load on\n * its own; the flag folds them into the one run that sees the final state.\n */\n private reload(): void {\n if (this.pending) return;\n this.pending = true;\n this.enqueue(() => {\n this.pending = false;\n return this.run();\n });\n }\n\n private emit(name: string, detail: unknown): void {\n this.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));\n }\n\n private report(error: PlayerError): void {\n if (error.fatal) {\n this.failure = error;\n // Under custom controls the error screen element is the surface, and\n // the element's own row under the video stays quiet.\n if (this.getAttribute(CONTROLS) !== 'custom') this.surface.show(error);\n }\n this.emit('error', error);\n }\n\n private async run(): Promise<void> {\n this.unmount();\n if (!this.isConnected) return;\n const url = this.getAttribute('src');\n if (url === null) return;\n\n const core = await this.ensure();\n const type = this.getAttribute('type');\n const source: Source = type === null ? { url } : { url, type };\n this.failure = null;\n this.surface.clear();\n\n let session: Session;\n try {\n session = await core.load(source);\n } catch {\n // The core already reported it on the error event, which the surface\n // and the element's own event both carry. Nothing to add here.\n return;\n }\n if (!this.isConnected) {\n await core.unload();\n return;\n }\n this.current = session;\n this.given = null;\n this.configure(session);\n // The engine's attach empties the media element to reset its resource\n // selection (`kernel/mse.ts`), and the chapters track goes with the\n // `<source>` children it means. Wanted: the track to survive attach.\n // Had to: put it back once the session is in. The surface that would\n // make it one call: an attach that removes `<source>` children alone.\n // A session with the engine's chapters takes the URL there instead.\n this.chapters();\n }\n\n private async ensure(): Promise<Player> {\n if (this.core !== null) return this.core;\n const core = createPlayer(this.media, { handlers: await this.chain() });\n this.offs.push(\n core.on('sourcechange', (session) => {\n // Before the event goes out, so a control that reads `engine` on\n // `sourcechange` sees the session the event is about.\n this.current = session;\n this.emit('sourcechange', session);\n }),\n core.on('error', (error) => {\n this.report(error);\n }),\n );\n this.core = core;\n return core;\n }\n\n private async chain(): Promise<readonly Handler[]> {\n if (this.options.handlers !== undefined) return this.options.handlers;\n const config = this.options.config === undefined ? {} : { config: this.options.config };\n // The stack is read at load time: a preset builds its stages only when asked.\n const native = (stages: () => readonly Stage[]): Handler =>\n nativeHandler({\n // Read on every load, so the attribute applies without a new chain.\n prefer: (source, env) =>\n this.getAttribute(NATIVE_HLS) !== 'off' && preferNativeHls(source, env),\n drm: () => this.drm(stages),\n });\n if (this.options.stages !== undefined) {\n return [\n matteboxHandler({ stages: this.options.stages, ...config }),\n native(() => this.options.stages ?? []),\n ];\n }\n const name = this.getAttribute('preset') ?? DEFAULT_PRESET;\n const preset = await resolvePreset(name);\n if (preset === null) {\n this.report({\n category: 'config',\n code: 'CONFIG_INVALID',\n fatal: true,\n recoverable: false,\n handler: null,\n context: { preset: name },\n });\n return [nativeHandler()];\n }\n return [matteboxHandler({ preset, ...config, ...drmGuard() }), native(() => preset.stages())];\n }\n\n /**\n * The DRM a native session attaches: the page's `drm` option, the\n * key-system stages of the engine's stack, and the `license-url`\n * attribute. None on a browser without EME, as for the engine.\n */\n private drm(stages: () => readonly Stage[]): AttachEmeOptions | undefined {\n if (drmGuard().without !== undefined) return undefined;\n const keySystems = stages().filter((stage) => KEY_SYSTEMS.includes(stage.name));\n const license = this.getAttribute('license-url');\n const certificate = this.getAttribute('certificate-url');\n const page = this.options.drm;\n if (keySystems.length === 0 && license === null && page === undefined) return undefined;\n return {\n keySystems,\n ...page,\n ...(license === null ? {} : { licenseUrl: license }),\n ...(certificate === null ? {} : { certificateUrl: certificate }),\n };\n }\n\n /** What the attributes ask of the session's namespaces, once there is one. */\n private configure(session: Session): void {\n const engine = session.engine;\n if (engine === null) return;\n\n const optional = namespaces(engine);\n\n const license = this.getAttribute('license-url');\n // After the session exists, not before: passing a license URL up front\n // means constructing eme-core, and importing a stage to configure it\n // would bundle it.\n if (license !== null && optional.drm !== undefined) optional.drm.setLicenseUrl(license);\n const certificate = this.getAttribute('certificate-url');\n if (certificate !== null) optional.drm?.setCertificateUrl(certificate);\n\n const track = this.getAttribute('thumbnails');\n if (track !== null && optional.thumbnails !== undefined) {\n // Loaded here; drawn by the seek bar's preview under `controls=\"custom\"`.\n // Native controls expose no scrub position to anchor a preview to, so\n // under `native` the track only answers `engine.thumbnails.at(time)` for\n // the app. See docs/guide/03-the-element.md.\n void optional.thumbnails.load(track).catch(() => undefined);\n }\n }\n\n private unmount(): void {\n this.current = null;\n }\n\n private async teardown(): Promise<void> {\n this.unmount();\n if (this.core !== null) await this.core.unload();\n }\n\n /** Drops the player itself, so the next run builds a chain from the new preset. */\n private async discard(): Promise<void> {\n await this.teardown();\n for (const off of this.offs) off();\n this.offs = [];\n this.core = null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA6CA,MAAM,aAAa;;AAGnB,MAAM,YAAY;CAAC;CAAY;CAAS;CAAU;AAAa;;AAG/D,MAAM,MAAM;CAAC;CAAO;CAAQ;CAAU;CAAe;CAAmB;CAAc;AAAU;;;;;;;;;AAUhG,MAAM,WAAW;;;;;;;;AASjB,MAAM,WAAW;;;;;;;AAQjB,MAAM,cAAc;;AAGpB,MAAM,eAAe;CACnB;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,cAAc,CAAC,gBAAgB,UAAU;;AAG/C,MAAM,iBAAiB;;;;;;AAkEvB,IAAI,WAAkC,CAAC;;;;;;;AASvC,IAAa,wBAAb,MAAa,8BAA8B,YAAkC;CAC3E,WAAW,qBAAwC;EACjD,OAAO;GAAC,GAAG;GAAW,GAAG;GAAK;GAAU;GAAU;EAAW;CAC/D;;;;;;;CAQA,OAAO,OAAO,SAAuC;EACnD,IAAI,YAAY,KAAA,GAAW,WAAW;EACtC,IAAI,eAAe,IAAA,iBAAU,MAAM,KAAA,GACjC,eAAe,OAAO,QAAQ,qBAAqB;CAEvD;CA6BA,YAAY,SAAiC;EAC3C,MAAM;EACN,KAAK,UAAU,WAAW;EAC1B,KAAK,YAAY;EACjB,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,OAAO;EACZ,KAAK,UAAU;EACf,KAAK,UAAU;EACf,KAAK,aAAa;EAClB,KAAK,UAAU;EACf,KAAK,UAAU;EACf,KAAK,OAAO,CAAC;EACb,KAAK,QAAQ,QAAQ,QAAQ;EAC7B,KAAK,UAAU;EAEf,KAAK,QAAQ,SAAS,cAAc,OAAO;EAG3C,KAAK,MAAM,WAAW;EAKtB,KAAK,MAAM,aAAa,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ourcesContent":["/**\n * <mattebox-player>: a real <video> as a light-DOM child, so the integrator\n * can reach it, and the error surface in shadow DOM. The element never\n * forwards or wraps a media element member: play, pause, seek, volume and\n * the rest live on the video, where the browser, Picture-in-Picture and the\n * OS media session already find them.\n *\n * The controls are elements the page places inside, beside the video, and\n * the stage slots them over the picture. The element appends none of its\n * own: the composition is the page's in every mode, and `none` hides every\n * child but the video. The element reflects the video's state as\n * attributes on itself, `paused`, `playing`, `ended`, `muted`, `audio`,\n * `started` and `waiting`, for the page's stylesheet and the controls\n * alike.\n *\n * No class fields, `#private` or otherwise: the ES2015 build would lower\n * them into runtime helpers, and the emit check bans helpers. Statics are\n * getters and instance state is declared, then assigned in the constructor.\n */\n\nimport type { Handler, Player, PlayerError, Session, Source } from '@mattebox/player-core';\nimport {\n createPlayer,\n inferType,\n matteboxHandler,\n nativeHandler,\n preferNativeHls,\n} from '@mattebox/player-core';\nimport type { KernelConfig, Mattebox, Stage } from 'mattebox';\nimport type { AttachEmeOptions } from 'mattebox/eme';\nimport type { Marker, Markers } from './controls/markers.js';\nimport { createMarkers } from './controls/markers.js';\nimport type { PlayerHost } from './host.js';\nimport { namespaces } from './namespaces.js';\nimport { drmGuard, resolvePreset } from './presets.js';\nimport { STYLE } from './style.js';\nimport type { ErrorSurface } from './surface.js';\nimport { errorSurface } from './surface.js';\nimport { PLAYER } from './tags.js';\n\n/**\n * `off` keeps HLS on the engine in Safari. Anything else lets Safari play\n * HLS itself: FairPlay, AirPlay, Low-Latency HLS and the platform's\n * fullscreen then work as Apple built them. Changing it reloads.\n */\nconst NATIVE_HLS = 'native-hls';\n\n/** Attributes forwarded onto the video as attributes, never as properties. */\nconst FORWARDED = ['autoplay', 'muted', 'poster', 'crossorigin'];\n\nconst LICENSE_URL = 'license-url';\nconst CERTIFICATE_URL = 'certificate-url';\n\n/** Everything else the element watches. Changing any of them reloads. */\nconst OWN = ['src', 'type', 'preset', LICENSE_URL, CERTIFICATE_URL, 'thumbnails', NATIVE_HLS];\n\n/**\n * The chapters file URL. A session with the engine's `chapters` namespace\n * loads it there: through the engine's transport, so request hooks apply,\n * and in every format the engine reads. Any other session gets a\n * `<track kind=\"chapters\">` on the video, hidden so its cues load and\n * nothing is drawn. The seek bar and the chapters menu read either.\n * Changing it never reloads the source.\n */\nconst CHAPTERS = 'chapters';\n\n/**\n * The one attribute whose meaning the element owns: `native` keeps the\n * browser's controls on the video, `custom` swaps them for the controls the\n * page placed inside, `none` takes the browser's off and hides every child\n * but the video. Anything else is `native`. Changing it never touches the\n * session.\n */\nconst CONTROLS = 'controls';\n\n/**\n * Inline playback, on until the page writes `playsinline=\"false\"`, the way\n * `spellcheck` and `draggable` are on until told otherwise. An iPhone takes\n * a video without `playsinline` to its own fullscreen on play, where no\n * control the page placed shows. Changing it never reloads.\n */\nconst PLAYSINLINE = 'playsinline';\n\n/**\n * The size tier the controls draw for: `compact` on a small player, such\n * as a phone held upright, `wide` on a large one, such as a TV or\n * fullscreen, and `regular` between. The element measures itself and sets\n * the attribute, so a stylesheet matches `mattebox-player[layout=\"compact\"]`.\n * A page that writes one of the three values fixes it, and removing the\n * attribute hands it back. The player's own box decides, not the screen:\n * a small embed on a desktop is compact, and a phone in fullscreen is not.\n */\nconst LAYOUT = 'layout';\nconst LAYOUTS = ['compact', 'regular', 'wide'];\n/** Under either, the player is compact. */\nconst COMPACT_WIDTH = 480;\nconst COMPACT_HEIGHT = 320;\n/** From both, the player is wide. */\nconst WIDE_WIDTH = 1280;\nconst WIDE_HEIGHT = 700;\n\n/** The video's state, as attributes on the element, read on the events the video fires for it. */\nconst STATE_EVENTS = [\n 'play',\n 'pause',\n 'ended',\n // A seek back from the end leaves `ended` with no play, pause or ended event.\n 'seeked',\n 'emptied',\n 'volumechange',\n 'loadedmetadata',\n 'resize',\n 'playing',\n 'waiting',\n 'stalled',\n 'canplay',\n];\n\n/** The stages that register a key system, which a native session's DRM offers. */\nconst KEY_SYSTEMS = ['eme-fairplay', 'eme-cenc'];\n\n/** Every stage the engine ships. A narrower preset is optimization. */\nconst DEFAULT_PRESET = 'full';\n\n/**\n * What the element dispatches. `error` is also a standard DOM event name, so\n * without these overloads a listener on it is typed as `ErrorEvent` and the\n * payload needs a double cast. They are declarations only: no runtime bytes.\n */\nexport interface MatteboxPlayerEventMap {\n sourcechange: CustomEvent<Session | null>;\n /** The size tier changed: `compact`, `regular` or `wide`. */\n layoutchange: CustomEvent<string>;\n error: CustomEvent<PlayerError>;\n /** The markers changed: set by the page, or cleared by a new source. */\n markerschange: CustomEvent<readonly Marker[]>;\n /** Playback reached a blocked range and moved past it. */\n blocked: CustomEvent<Marker>;\n}\n\nexport interface MatteboxPlayerElement {\n addEventListener<K extends keyof MatteboxPlayerEventMap>(\n type: K,\n listener: (this: MatteboxPlayerElement, event: MatteboxPlayerEventMap[K]) => void,\n options?: boolean | AddEventListenerOptions,\n ): void;\n addEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | AddEventListenerOptions,\n ): void;\n removeEventListener<K extends keyof MatteboxPlayerEventMap>(\n type: K,\n listener: (this: MatteboxPlayerElement, event: MatteboxPlayerEventMap[K]) => void,\n options?: boolean | EventListenerOptions,\n ): void;\n removeEventListener(\n type: string,\n listener: EventListenerOrEventListenerObject,\n options?: boolean | EventListenerOptions,\n ): void;\n}\n\nexport interface MatteboxPlayerOptions {\n /** The whole chain, in order. Takes precedence over `stages` and the `preset` attribute. */\n readonly handlers?: readonly Handler[];\n /** Stages for the mattebox handler. Takes precedence over the `preset` attribute. */\n readonly stages?: readonly Stage[];\n /**\n * Kernel tuning for the engines the elements build, `traceCapacity` among\n * it. A page decision, like the stages, so not an attribute. Ignored with\n * `handlers`, which carry their own.\n */\n readonly config?: Partial<KernelConfig>;\n /**\n * DRM for a native session, as `attachEme` from `mattebox/eme` takes it:\n * `keySystems`, `licenseUrl`, `licenseUrls`, `requestHook`. Without\n * `keySystems` the session offers the key-system stages of the engine's\n * stack. The `license-url` attribute overrides `licenseUrl`, and\n * `certificate-url` gives the FairPlay certificate. Ignored\n * with `handlers`, which carry their own.\n */\n readonly drm?: AttachEmeOptions;\n}\n\n/**\n * What `define()` recorded, for the elements the parser creates. It is the\n * one value shared across elements, because a page that writes only markup\n * still has to be able to say what the engine carries.\n */\nlet defaults: MatteboxPlayerOptions = {};\n\n/**\n * The interface above merges only `addEventListener` and `removeEventListener`\n * overloads, which the class inherits from HTMLElement. The rule it suppresses\n * guards against properties an interface declares and a constructor never\n * assigns, and there are none.\n */\n// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: method overloads only, no properties\nexport class MatteboxPlayerElement extends HTMLElement implements PlayerHost {\n static get observedAttributes(): readonly string[] {\n return [...FORWARDED, ...OWN, CONTROLS, CHAPTERS, PLAYSINLINE, LAYOUT];\n }\n\n /**\n * Registers the element once, and records the stages markup-only pages\n * get. The controls register through their own entries, the package's\n * root entry importing every one; a control connected before its player\n * is defined waits for the definition.\n */\n static define(options?: MatteboxPlayerOptions): void {\n if (options !== undefined) defaults = options;\n if (customElements.get(PLAYER) === undefined) {\n customElements.define(PLAYER, MatteboxPlayerElement);\n }\n }\n\n declare private readonly media: HTMLVideoElement;\n /** Wraps the slot: the picture, and the controls over it or under it. */\n declare private readonly stage: HTMLDivElement;\n /** Whether the element gave itself a tabindex for the bar, to take back with it. */\n declare private focusable: boolean;\n declare private readonly surface: ErrorSurface;\n declare private readonly marks: Markers;\n /** The chapters track element, while the `chapters` attribute names one and the engine takes none. */\n declare private track: HTMLTrackElement | null;\n /** The chapters URL the current session's engine was given, or null. */\n declare private given: string | null;\n /** The sources the page set from script, or null. */\n declare private list: readonly Source[] | null;\n /** The sources of the last run, as text: what tells a new `<source>` child from the ones already tried. */\n declare private tried: string;\n /** The options this element was constructed with, or null for the ones `define()` recorded. */\n declare private readonly own: MatteboxPlayerOptions | null;\n declare private core: Player | null;\n declare private current: Session | null;\n declare private failure: PlayerError | null;\n /** Whether an attribute change is the element's own reflection, which must not write back to the video. */\n declare private reflecting: boolean;\n /** Watches the element's box for `layout`, while connected. */\n declare private sizes: ResizeObserver | null;\n /** Whether the page wrote `layout`, so the element leaves it alone. */\n declare private fixed: boolean;\n /** The video has played once since its source was set: `started`, which tells a first play from a pause. */\n declare private started: boolean;\n /** The video waits for data: `waiting`, set on `waiting` and `stalled`, cleared once it can play. */\n declare private waiting: boolean;\n declare private offs: Array<() => void>;\n /** Everything the element does to the player runs here, so it runs in order. */\n declare private queue: Promise<void>;\n /** Whether a run is queued and not yet started, so a burst of changes loads once. */\n declare private pending: boolean;\n\n constructor(options?: MatteboxPlayerOptions) {\n super();\n this.own = options ?? null;\n this.focusable = false;\n this.track = null;\n this.given = null;\n this.list = null;\n this.tried = '';\n this.core = null;\n this.current = null;\n this.failure = null;\n this.reflecting = false;\n this.sizes = null;\n this.fixed = false;\n this.started = false;\n this.waiting = false;\n this.offs = [];\n this.queue = Promise.resolve();\n this.pending = false;\n\n this.media = document.createElement('video');\n // Native until the `controls` attribute says otherwise, which arrives\n // through attributeChangedCallback: a constructor must not read attributes.\n this.media.controls = true;\n // Inline is the default, and the player's own attribute has not arrived\n // yet. Set as an attribute: not every browser has the `playsInline`\n // property. The fullscreen button still reaches the iPhone's fullscreen,\n // through `webkitEnterFullscreen`.\n this.media.setAttribute(PLAYSINLINE, '');\n for (const name of STATE_EVENTS) {\n this.media.addEventListener(name, () => {\n this.note(name);\n this.reflect();\n });\n }\n // An error over a picture that then plays is wrong by definition.\n this.media.addEventListener('playing', () => {\n this.failure = null;\n });\n this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));\n this.stage = document.createElement('div');\n this.stage.setAttribute('part', 'stage');\n const slot = document.createElement('slot');\n // The parser connects the element before its children exist, so the\n // first run finds no `<source>`. A video starts its selection when a\n // `<source>` arrives and nothing is loaded, and so does this.\n slot.addEventListener('slotchange', () => {\n if (this.current === null && JSON.stringify(this.wanted()) !== this.tried) this.reload();\n });\n this.stage.append(slot);\n this.surface = errorSurface(() => {\n this.reload();\n });\n\n const root = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = STYLE;\n root.append(style, this.stage, this.surface.root);\n }\n\n /** The media element. Everything the browser already does is here. */\n get video(): HTMLVideoElement {\n return this.media;\n }\n\n /** The ranges the page named in this source: credits to skip, parts that must not play. */\n get markers(): Markers {\n return this.marks;\n }\n\n /**\n * The sources to try in order, set from script. The `src` attribute wins\n * over them, and they win over the `<source>` children. Setting them\n * loads, and null returns to the children.\n */\n get sources(): readonly Source[] | null {\n return this.list;\n }\n\n set sources(value: readonly Source[] | null) {\n this.list = value;\n // Markers belong to a source, as for `src`.\n if (this.marks.list.length > 0) this.marks.set([]);\n this.reload();\n }\n\n /** The core, or null until the first source has been set up: resolving a preset is asynchronous. */\n get player(): Player | null {\n return this.core;\n }\n\n /** The engine feeding the video, or null for a native session and before the first load. */\n get engine(): Mattebox | null {\n return this.current?.engine ?? null;\n }\n\n /**\n * The fatal error of the current load, or null once a load starts or\n * playback resumes. The `error` event says when; this says what, for a\n * control that attaches after the event, such as an error screen parsed\n * after a source that failed while the page was still loading.\n */\n get error(): PlayerError | null {\n return this.failure;\n }\n\n connectedCallback(): void {\n if (this.media.parentNode !== this) this.append(this.media);\n for (const name of FORWARDED) this.forward(name);\n this.reflect();\n if (typeof ResizeObserver !== 'undefined') {\n this.sizes = new ResizeObserver(() => {\n this.measure();\n });\n this.sizes.observe(this);\n }\n this.measure();\n this.reload();\n }\n\n /** Sets `layout` from the element's box, unless the page fixed it. */\n private measure(): void {\n if (this.fixed) return;\n const width = this.clientWidth;\n const height = this.clientHeight;\n // Not laid out yet: no tier until there is a box to judge.\n if (width === 0 || height === 0) return;\n const layout =\n width < COMPACT_WIDTH || height < COMPACT_HEIGHT\n ? 'compact'\n : width >= WIDE_WIDTH && height >= WIDE_HEIGHT\n ? 'wide'\n : 'regular';\n if (this.getAttribute(LAYOUT) === layout) return;\n this.reflecting = true;\n this.setAttribute(LAYOUT, layout);\n this.reflecting = false;\n this.emit('layoutchange', layout);\n }\n\n /** The two states the video does not hold: whether it has played once, and whether it waits for data. */\n private note(event: string): void {\n if (event === 'playing') {\n this.started = true;\n this.waiting = false;\n } else if (event === 'waiting' || event === 'stalled') {\n this.waiting = true;\n } else if (event === 'canplay') {\n this.waiting = false;\n } else if (event === 'emptied') {\n // A new source starts over: the title shows again before its first play.\n this.started = false;\n this.waiting = false;\n }\n }\n\n /** The video's state on the element, for `mattebox-player[paused]` and the like. */\n private reflect(): void {\n const video = this.media;\n this.reflecting = true;\n this.toggleAttribute('paused', video.paused);\n this.toggleAttribute('playing', !video.paused);\n this.toggleAttribute('ended', video.ended);\n // `muted` is also forwarded: the page's attribute sets the video, and\n // the video's state sets the attribute. Reflection never forwards, so\n // a read can only ever change the attribute, never the video.\n this.toggleAttribute('muted', video.muted);\n this.toggleAttribute('audio', this.audio());\n this.toggleAttribute('started', this.started);\n this.toggleAttribute('waiting', this.waiting);\n this.reflecting = false;\n }\n\n /**\n * Whether the source has no picture. Once the metadata is in, the video's\n * size decides: zero by zero is sound alone, and `resize` catches a stream\n * that moves to or from an audio-only rendition. Before that, the type the\n * page wrote or the URL implies is the hint, so an mp3 is `audio` from\n * the start rather than from its metadata.\n */\n private audio(): boolean {\n const video = this.media;\n if (video.readyState >= HTMLMediaElement.HAVE_METADATA) {\n return video.videoWidth === 0 && video.videoHeight === 0;\n }\n const src = this.getAttribute('src');\n const type = this.getAttribute('type') ?? (src === null ? undefined : inferType(src));\n return type?.startsWith('audio/') === true;\n }\n\n disconnectedCallback(): void {\n this.sizes?.disconnect();\n this.sizes = null;\n // A single-page app must not leave a pipeline attached to a video it\n // navigated away from. Reconnecting loads the `src` again.\n this.enqueue(() => this.teardown());\n }\n\n attributeChangedCallback(name: string): void {\n if (FORWARDED.includes(name)) {\n if (!this.reflecting) this.forward(name);\n return;\n }\n if (name === CONTROLS) {\n this.mode();\n return;\n }\n if (name === CHAPTERS) {\n this.chapters();\n return;\n }\n if (name === LAYOUT) {\n // The element's own write is not the page's.\n if (this.reflecting) return;\n const value = this.getAttribute(LAYOUT);\n this.fixed = value !== null && LAYOUTS.includes(value);\n if (this.fixed) this.emit('layoutchange', value);\n else this.measure();\n return;\n }\n if (name === PLAYSINLINE) {\n // On the video it is a boolean attribute, so off is absent.\n this.media.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== 'false');\n return;\n }\n // The preset decides the chain, so it is the one attribute that rebuilds it.\n if (name === 'preset') this.enqueue(() => this.discard());\n // The source's type is the hint for `audio` until its metadata arrives.\n // Only `audio`: a full reflection here would drop a `muted` the page\n // wrote before its own callback forwards it.\n if (name === 'src' || name === 'type') this.toggleAttribute('audio', this.audio());\n // Markers belong to a source. Cleared here, not on `emptied`, which\n // arrives later and would clear the ones the page sets right after.\n if (name === 'src' && this.marks.list.length > 0) this.marks.set([]);\n this.reload();\n }\n\n /**\n * Applies the `controls` attribute: the video's own controls and the\n * tabindex. The controls themselves are elements the page placed, and\n * they attach on their own; the element appends none.\n */\n private mode(): void {\n const value = this.getAttribute(CONTROLS);\n const custom = value === 'custom';\n this.media.controls = !custom && value !== 'none';\n // Under custom controls the error screen element carries a fatal error.\n if (custom) this.surface.clear();\n if (!custom) {\n if (this.focusable) this.removeAttribute('tabindex');\n this.focusable = false;\n } else if (!this.hasAttribute('tabindex')) {\n // A bare video is not focusable, so without this a click on it would\n // leave the shortcuts nowhere to listen. A page that set its own\n // tabindex keeps it.\n this.tabIndex = 0;\n this.focusable = true;\n }\n }\n\n /** Hands the `chapters` attribute to the engine, or keeps a hidden chapters track on the video for it. */\n private chapters(): void {\n const url = this.getAttribute(CHAPTERS);\n const engine = this.current?.engine ?? null;\n const api = engine === null ? undefined : namespaces(engine).chapters;\n if (api !== undefined) {\n this.track?.remove();\n this.track = null;\n if (url === this.given) return;\n this.given = url;\n // An empty list removes the chapters the attribute loaded.\n if (url === null) api.set([]);\n else void api.load(url).catch(() => undefined);\n return;\n }\n if (url === null) {\n this.track?.remove();\n this.track = null;\n return;\n }\n const held = this.track;\n if (held !== null && held.parentNode === this.media && held.getAttribute('src') === url) return;\n // A new element each time: one removed mid-load, as the engine's attach\n // does, stays in its error state, and neither a new `src` nor a second\n // insertion starts it loading again.\n held?.remove();\n const track = document.createElement('track');\n track.kind = 'chapters';\n track.src = url;\n this.track = track;\n this.media.append(track);\n // Set after the insertion: a track element's mode exists once it is in\n // a media element, and `hidden` is what makes its cues load unseen.\n track.track.mode = 'hidden';\n }\n\n private forward(name: string): void {\n const value = this.getAttribute(name);\n if (value === null) this.media.removeAttribute(name);\n else this.media.setAttribute(name, value);\n // A video reads `muted` into its state only when it is created, and this\n // one was created before any attribute reached it. Muted autoplay and\n // the autoplay policy read the state, so the attribute alone would not do.\n if (name === 'muted') this.media.muted = value !== null;\n }\n\n private enqueue(task: () => Promise<void>): void {\n this.queue = this.queue.then(task, task).catch(() => undefined);\n }\n\n /**\n * One run per burst. The parser sets every attribute and then connects the\n * element before any queued task starts, and each of those would load on\n * its own; the flag folds them into the one run that sees the final state.\n */\n private reload(): void {\n if (this.pending) return;\n this.pending = true;\n this.enqueue(() => {\n this.pending = false;\n return this.run();\n });\n }\n\n private emit(name: string, detail: unknown): void {\n this.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));\n }\n\n private report(error: PlayerError): void {\n if (error.fatal) {\n this.failure = error;\n // Under custom controls the error screen element is the surface, and\n // the element's own row under the video stays quiet.\n if (this.getAttribute(CONTROLS) !== 'custom') this.surface.show(error);\n }\n this.emit('error', error);\n }\n\n private async run(): Promise<void> {\n this.unmount();\n if (!this.isConnected) return;\n const sources = this.wanted();\n this.tried = JSON.stringify(sources);\n if (sources.length === 0) return;\n\n const core = await this.ensure();\n this.failure = null;\n this.surface.clear();\n\n try {\n await core.load(sources);\n } catch {\n // The core already reported it on the error event, which the surface\n // and the element's own event both carry. Nothing to add here.\n return;\n }\n if (!this.isConnected) await core.unload();\n }\n\n /**\n * What to load, ranked as a video ranks them: the `src` attribute, then\n * the `sources` property, then the `<source>` children in their order.\n * A child carries its own `license-url` and `certificate-url`.\n */\n private wanted(): readonly Source[] {\n const url = this.getAttribute('src');\n if (url !== null) {\n const type = this.getAttribute('type');\n return [type === null ? { url } : { url, type }];\n }\n // A browser without EME gets no DRM stage, and a source must not bring DRM back.\n const eme = drmGuard().without === undefined;\n if (this.list !== null) {\n return eme\n ? this.list\n : this.list.map(({ url, type }) => (type === undefined ? { url } : { url, type }));\n }\n const found: Source[] = [];\n for (const child of Array.from(this.children)) {\n const src = child.localName === 'source' ? child.getAttribute('src') : null;\n if (src === null) continue;\n const type = child.getAttribute('type');\n const license = child.getAttribute(LICENSE_URL);\n const certificate = child.getAttribute(CERTIFICATE_URL);\n found.push({\n url: src,\n ...(type === null ? {} : { type }),\n ...(!eme || (license === null && certificate === null)\n ? {}\n : {\n drm: {\n ...(license === null ? {} : { licenseUrl: license }),\n ...(certificate === null ? {} : { certificateUrl: certificate }),\n },\n }),\n });\n }\n return found;\n }\n\n /** Sets a session up. It runs for every session, the one that replaces a failed source included. */\n private adopt(session: Session): void {\n this.given = null;\n this.configure(session);\n // The engine's attach empties the media element to reset its resource\n // selection (`kernel/mse.ts`), and the chapters track goes with the\n // `<source>` children it means. Wanted: the track to survive attach.\n // Had to: put it back once the session is in. The surface that would\n // make it one call: an attach that removes `<source>` children alone.\n // A session with the engine's chapters takes the URL there instead.\n this.chapters();\n }\n\n private async ensure(): Promise<Player> {\n if (this.core !== null) return this.core;\n const core = createPlayer(this.media, { handlers: await this.chain() });\n this.offs.push(\n core.on('sourcechange', (session) => {\n // Before the event goes out, so a control that reads `engine` on\n // `sourcechange` sees the session the event is about.\n this.current = session;\n if (session !== null && this.isConnected) this.adopt(session);\n this.emit('sourcechange', session);\n }),\n core.on('error', (error) => {\n this.report(error);\n }),\n );\n this.core = core;\n return core;\n }\n\n /**\n * Read at each use, not once in the constructor. Importing the package\n * registers the element, and the parser's elements are constructed then,\n * before the page's own `define()` call can run.\n */\n private get options(): MatteboxPlayerOptions {\n return this.own ?? defaults;\n }\n\n private async chain(): Promise<readonly Handler[]> {\n if (this.options.handlers !== undefined) return this.options.handlers;\n const config = this.options.config === undefined ? {} : { config: this.options.config };\n // The stack is read at load time: a preset builds its stages only when asked.\n const native = (stages: () => readonly Stage[]): Handler =>\n nativeHandler({\n // Read on every load, so the attribute applies without a new chain.\n prefer: (source, env) =>\n this.getAttribute(NATIVE_HLS) !== 'off' && preferNativeHls(source, env),\n drm: () => this.drm(stages),\n });\n if (this.options.stages !== undefined) {\n return [\n matteboxHandler({ stages: this.options.stages, ...config }),\n native(() => this.options.stages ?? []),\n ];\n }\n const name = this.getAttribute('preset') ?? DEFAULT_PRESET;\n const preset = await resolvePreset(name);\n if (preset === null) {\n this.report({\n category: 'config',\n code: 'CONFIG_INVALID',\n fatal: true,\n recoverable: false,\n handler: null,\n context: { preset: name },\n });\n return [nativeHandler()];\n }\n return [matteboxHandler({ preset, ...config, ...drmGuard() }), native(() => preset.stages())];\n }\n\n /**\n * The DRM a native session attaches: the page's `drm` option, the\n * key-system stages of the engine's stack, and the `license-url`\n * attribute. None on a browser without EME, as for the engine.\n */\n private drm(stages: () => readonly Stage[]): AttachEmeOptions | undefined {\n if (drmGuard().without !== undefined) return undefined;\n const keySystems = stages().filter((stage) => KEY_SYSTEMS.includes(stage.name));\n const license = this.getAttribute(LICENSE_URL);\n const certificate = this.getAttribute(CERTIFICATE_URL);\n const page = this.options.drm;\n if (keySystems.length === 0 && license === null && page === undefined) return undefined;\n return {\n keySystems,\n ...page,\n ...(license === null ? {} : { licenseUrl: license }),\n ...(certificate === null ? {} : { certificateUrl: certificate }),\n };\n }\n\n /** What the attributes ask of the session's namespaces, once there is one. */\n private configure(session: Session): void {\n const engine = session.engine;\n if (engine === null) return;\n\n const optional = namespaces(engine);\n\n // The attributes are the default. A source's own URL is already on the\n // engine: the handler set it from `source.drm` before the load.\n const own = session.source.drm;\n const license = this.getAttribute(LICENSE_URL);\n // After the session exists, not before: passing a license URL up front\n // means constructing eme-core, and importing a stage to configure it\n // would bundle it.\n if (license !== null && own?.licenseUrl === undefined) optional.drm?.setLicenseUrl(license);\n const certificate = this.getAttribute(CERTIFICATE_URL);\n if (certificate !== null && own?.certificateUrl === undefined) {\n optional.drm?.setCertificateUrl(certificate);\n }\n\n const track = this.getAttribute('thumbnails');\n if (track !== null && optional.thumbnails !== undefined) {\n // Loaded here; drawn by the seek bar's preview under `controls=\"custom\"`.\n // Native controls expose no scrub position to anchor a preview to, so\n // under `native` the track only answers `engine.thumbnails.at(time)` for\n // the app. See docs/guide/03-the-element.md.\n void optional.thumbnails.load(track).catch(() => undefined);\n }\n }\n\n private unmount(): void {\n this.current = null;\n }\n\n private async teardown(): Promise<void> {\n this.unmount();\n if (this.core !== null) await this.core.unload();\n }\n\n /** Drops the player itself, so the next run builds a chain from the new preset. */\n private async discard(): Promise<void> {\n await this.teardown();\n for (const off of this.offs) off();\n this.offs = [];\n this.core = null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA6CA,MAAM,aAAa;;AAGnB,MAAM,YAAY;CAAC;CAAY;CAAS;CAAU;AAAa;AAE/D,MAAM,cAAc;AACpB,MAAM,kBAAkB;;AAGxB,MAAM,MAAM;CAAC;CAAO;CAAQ;CAAU;CAAa;CAAiB;CAAc;AAAU;;;;;;;;;AAU5F,MAAM,WAAW;;;;;;;;AASjB,MAAM,WAAW;;;;;;;AAQjB,MAAM,cAAc;;;;;;;;;;AAWpB,MAAM,SAAS;AACf,MAAM,UAAU;CAAC;CAAW;CAAW;AAAM;;AAE7C,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;;AAEvB,MAAM,aAAa;AACnB,MAAM,cAAc;;AAGpB,MAAM,eAAe;CACnB;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,cAAc,CAAC,gBAAgB,UAAU;;AAG/C,MAAM,iBAAiB;;;;;;AAoEvB,IAAI,WAAkC,CAAC;;;;;;;AASvC,IAAa,wBAAb,MAAa,8BAA8B,YAAkC;C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IAAI,MAAM;cAId,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAanD,2EAA2E;IAC3E,OAAO,CAAC,MAAM;cAgBK,MAAM,IAAI,IAAI;CAsClC"}
1
+ {"version":3,"file":"audio-menu.d.ts","sourceRoot":"","sources":["../../src/elements/audio-menu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAK7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAU,MAAM,mBAAmB,CAAC;AAWxD;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,QAAQ,EAChB,WAAW,EAAE,WAAW,EACxB,MAAM,GAAE,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,MAAM,EAAa,EACtD,MAAM,GAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAoB,GAC7C,CAAC,UAAU,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,CAiB/B;AAOD,0EAA0E;AAC1E,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAKvE;AAED,qBAAa,YAAa,SAAQ,WAAW;IAC3C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,QAAgB,MAAM,CAAkB;;cAQrB,IAAI,IAAI,MAAM;cAId,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAanD,2EAA2E;IAC3E,OAAO,CAAC,MAAM;cAgBK,MAAM,IAAI,IAAI;CAwClC"}
@@ -1,3 +1,4 @@
1
+ import { icon } from "../controls/icons.js";
1
2
  import { show } from "./shared.js";
2
3
  import { nativeTracks, onNativeTracks } from "../controls/native-tracks.js";
3
4
  import { layout, trackNames } from "../controls/track-names.js";
@@ -46,7 +47,7 @@ var MbxAudioMenu = class extends MenuElement {
46
47
  ];
47
48
  }
48
49
  constructor() {
49
- super(...single("music"));
50
+ super(...single("audio"));
50
51
  this.engine = null;
51
52
  show(this.slots, "default");
52
53
  }
@@ -90,6 +91,7 @@ var MbxAudioMenu = class extends MenuElement {
90
91
  this.menu.fill([{
91
92
  name: "track",
92
93
  items,
94
+ badgeGlyphs: { [this.getAttribute("label-ad") ?? "AD"]: () => icon("audio-description") },
93
95
  value: active ?? "",
94
96
  onSelect: (value) => {
95
97
  if (tracks !== void 0) tracks.forEach((track, index) => {
@@ -1 +1 @@
1
- {"version":3,"file":"audio-menu.js","names":[],"sources":["../../src/elements/audio-menu.ts"],"sourcesContent":["/**\n * <mbx-audio-menu>: the audio track over `engine.tracks`, or over the\n * video's `audioTracks` for a native session. Hidden unless there is a\n * choice to make. The name comes from `label`. An engine track reads as\n * its name in the manifest, else its language's name, else its language\n * code, else \"Track\" (`label-track`) and its place. A native track reads\n * the same from its label and language. A badge marks an\n * audio description track (`label-ad`, \"AD\") and the original language\n * (`label-original`, \"Original\"), from the engine's standard\n * characteristics (guide chapter 06), or from the native track's `kind`.\n */\nimport type { ContentType, Mattebox, Track } from 'mattebox';\nimport { isAudioDescription, isOriginal } from 'mattebox';\nimport type { NativeTrack } from '../controls/native-tracks.js';\nimport { nativeTracks, onNativeTracks } from '../controls/native-tracks.js';\nimport type { TrackEntry } from '../controls/track-names.js';\nimport { layout, trackNames } from '../controls/track-names.js';\nimport type { PlayerHost } from '../host.js';\nimport { MenuElement, single } from './menu-element.js';\nimport { show } from './shared.js';\n\n/** A track's channel layout, from its first rendition: `audioObjects` `JOC` is Dolby Atmos. */\nfunction channels(track: Track): string | undefined {\n const first = track.renditions[0];\n return first?.channels === undefined\n ? undefined\n : layout(`${first.channels}${first.audioObjects ? `/${first.audioObjects}` : ''}`);\n}\n\n/**\n * The tracks of one content type that the engine can play and `listed`\n * keeps, as entries with their badges, and the active one's id when it\n * is listed. A track the browser cannot decode, or that no stage plays,\n * stays out (guide chapter 06).\n */\nexport function trackItems(\n engine: Mattebox,\n contentType: ContentType,\n badges: (track: Track) => readonly string[] = () => [],\n listed: (track: Track) => boolean = () => true,\n): [TrackEntry[], string | null] {\n const tracks = engine.tracks;\n const available = tracks.available.filter(\n (track) => track.contentType === contentType && tracks.selectable(track.id) && listed(track),\n );\n const entries = available.map(\n (track): TrackEntry => [\n track.id,\n track.name,\n track.lang,\n badges(track),\n // The role \"main\" tells nothing apart: every stream has one.\n [channels(track), track.role === 'main' ? undefined : track.role],\n ],\n );\n const active = tracks.active(contentType)?.id;\n return [entries, available.some((track) => track.id === active) ? (active as string) : null];\n}\n\n/** What the menu reads and writes of Safari's `AudioTrack`. */\ninterface NativeAudioTrack extends NativeTrack {\n enabled: boolean;\n}\n\n/** Subscribes `tick` to the track events, and answers the unsubscribe. */\nexport function onTracks(engine: Mattebox, tick: () => void): () => void {\n const offs = [engine.on('tracks:changed', tick), engine.on('tracks:selected', tick)];\n return () => {\n for (const off of offs) off();\n };\n}\n\nexport class MbxAudioMenu extends MenuElement {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-back', 'label-ad', 'label-original', 'label-track'];\n }\n\n declare private engine: Mattebox | null;\n\n constructor() {\n super(...single('music'));\n this.engine = null;\n show(this.slots, 'default');\n }\n\n protected override name(): string {\n return 'Audio';\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n this.engine = engine;\n this.render();\n const tick = (): void => {\n this.render();\n };\n return engine === null\n ? onNativeTracks(player.video, 'audioTracks', tick)\n : onTracks(engine, tick);\n });\n }\n\n /** The native session's audio tracks as entries, and the enabled one's. */\n private native(tracks: readonly NativeAudioTrack[]): [TrackEntry[], string | null] {\n const ad = this.getAttribute('label-ad') ?? 'AD';\n const entries = tracks.map(\n (track, index): TrackEntry => [\n String(index),\n track.label,\n track.language,\n // HTML's kinds for an audio description track.\n track.kind === 'description' || track.kind === 'main-desc' ? [ad] : [],\n [],\n ],\n );\n const on = tracks.findIndex((track) => track.enabled);\n return [entries, on === -1 ? null : String(on)];\n }\n\n protected override render(): void {\n super.render();\n const engine = this.engine;\n const player = this.player;\n const tracks =\n engine === null && player !== null\n ? nativeTracks<NativeAudioTrack>(player, 'audioTracks')\n : undefined;\n if (engine === null && tracks === undefined) {\n this.hidden = true;\n return;\n }\n const [entries, active] =\n tracks !== undefined\n ? this.native(tracks)\n : trackItems(engine as Mattebox, 'audio', (track) => [\n ...(isAudioDescription(track) ? [this.getAttribute('label-ad') ?? 'AD'] : []),\n ...(isOriginal(track) ? [this.getAttribute('label-original') ?? 'Original'] : []),\n ]);\n const items = trackNames(entries, this.getAttribute('label-track'));\n this.menu.fill([\n {\n name: 'track',\n items,\n value: active ?? '',\n onSelect: (value) => {\n // One audio track plays at a time, so the others are turned off.\n if (tracks !== undefined) {\n tracks.forEach((track, index) => {\n track.enabled = String(index) === value;\n });\n } else engine?.tracks.select(value);\n this.render();\n },\n },\n ]);\n this.hidden = items.length < 2;\n }\n}\n"],"mappings":";;;;;;;AAsBA,SAAS,SAAS,OAAkC;CAClD,MAAM,QAAQ,MAAM,WAAW;CAC/B,OAAO,OAAO,aAAa,KAAA,IACvB,KAAA,IACA,OAAO,GAAG,MAAM,WAAW,MAAM,eAAe,IAAI,MAAM,iBAAiB,IAAI;AACrF;;;;;;;AAQA,SAAgB,WACd,QACA,aACA,eAAoD,CAAC,GACrD,eAA0C,MACX;CAC/B,MAAM,SAAS,OAAO;CACtB,MAAM,YAAY,OAAO,UAAU,QAChC,UAAU,MAAM,gBAAgB,eAAe,OAAO,WAAW,MAAM,EAAE,KAAK,OAAO,KAAK,CAC7F;CACA,MAAM,UAAU,UAAU,KACvB,UAAsB;EACrB,MAAM;EACN,MAAM;EACN,MAAM;EACN,OAAO,KAAK;EAEZ,CAAC,SAAS,KAAK,GAAG,MAAM,SAAS,SAAS,KAAA,IAAY,MAAM,IAAI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MAAM,SACJ,WAAW,QAAQ,WAAW,OAC1B,aAA+B,QAAQ,aAAa,IACpD,KAAA;EACN,IAAI,WAAW,QAAQ,WAAW,KAAA,GAAW;GAC3C,KAAK,SAAS;GACd;EACF;EACA,MAAM,CAAC,SAAS,UACd,WAAW,KAAA,IACP,KAAK,OAAO,MAAM,IAClB,WAAW,QAAoB,UAAU,UAAU,CACjD,GAAI,mBAAmB,KAAK,IAAI,CAAC,KAAK,aAAa,UAAU,KAAK,IAAI,IAAI,CAAC,GAC3E,GAAI,WAAW,KAAK,IAAI,CAAC,KAAK,aAAa,gBAAgB,KAAK,UAAU,IAAI,CAAC,CACjF,CAAC;EACP,MAAM,QAAQ,WAAW,SAAS,KAAK,aAAa,aAAa,CAAC;EAClE,KAAK,KAAK,KAAK,CACb;GACE,MAAM;GACN;GACA,OAAO,UAAU;GACjB,WAAW,UAAU;IAEnB,IAAI,WAAW,KAAA,GACb,OAAO,SAAS,OAAO,UAAU;KAC/B,MAAM,UAAU,OAAO,KAAK,MAAM;IACpC,CAAC;SACI,QAAQ,OAAO,OAAO,KAAK;IAClC,KAAK,OAAO;GACd;EACF,CACF,CAAC;EACD,KAAK,SAAS,MAAM,SAAS;CAC/B;AACF"}
1
+ {"version":3,"file":"audio-menu.js","names":[],"sources":["../../src/elements/audio-menu.ts"],"sourcesContent":["/**\n * <mbx-audio-menu>: the audio track over `engine.tracks`, or over the\n * video's `audioTracks` for a native session. Hidden unless there is a\n * choice to make. The name comes from `label`. An engine track reads as\n * its name in the manifest, else its language's name, else its language\n * code, else \"Track\" (`label-track`) and its place. A native track reads\n * the same from its label and language. A badge marks an\n * audio description track (`label-ad`, \"AD\") and the original language\n * (`label-original`, \"Original\"), from the engine's standard\n * characteristics (guide chapter 06), or from the native track's `kind`.\n */\nimport type { ContentType, Mattebox, Track } from 'mattebox';\nimport { isAudioDescription, isOriginal } from 'mattebox';\nimport { icon } from '../controls/icons.js';\nimport type { NativeTrack } from '../controls/native-tracks.js';\nimport { nativeTracks, onNativeTracks } from '../controls/native-tracks.js';\nimport type { TrackEntry } from '../controls/track-names.js';\nimport { layout, trackNames } from '../controls/track-names.js';\nimport type { PlayerHost } from '../host.js';\nimport { MenuElement, single } from './menu-element.js';\nimport { show } from './shared.js';\n\n/** A track's channel layout, from its first rendition: `audioObjects` `JOC` is Dolby Atmos. */\nfunction channels(track: Track): string | undefined {\n const first = track.renditions[0];\n return first?.channels === undefined\n ? undefined\n : layout(`${first.channels}${first.audioObjects ? `/${first.audioObjects}` : ''}`);\n}\n\n/**\n * The tracks of one content type that the engine can play and `listed`\n * keeps, as entries with their badges, and the active one's id when it\n * is listed. A track the browser cannot decode, or that no stage plays,\n * stays out (guide chapter 06).\n */\nexport function trackItems(\n engine: Mattebox,\n contentType: ContentType,\n badges: (track: Track) => readonly string[] = () => [],\n listed: (track: Track) => boolean = () => true,\n): [TrackEntry[], string | null] {\n const tracks = engine.tracks;\n const available = tracks.available.filter(\n (track) => track.contentType === contentType && tracks.selectable(track.id) && listed(track),\n );\n const entries = available.map(\n (track): TrackEntry => [\n track.id,\n track.name,\n track.lang,\n badges(track),\n // The role \"main\" tells nothing apart: every stream has one.\n [channels(track), track.role === 'main' ? undefined : track.role],\n ],\n );\n const active = tracks.active(contentType)?.id;\n return [entries, available.some((track) => track.id === active) ? (active as string) : null];\n}\n\n/** What the menu reads and writes of Safari's `AudioTrack`. */\ninterface NativeAudioTrack extends NativeTrack {\n enabled: boolean;\n}\n\n/** Subscribes `tick` to the track events, and answers the unsubscribe. */\nexport function onTracks(engine: Mattebox, tick: () => void): () => void {\n const offs = [engine.on('tracks:changed', tick), engine.on('tracks:selected', tick)];\n return () => {\n for (const off of offs) off();\n };\n}\n\nexport class MbxAudioMenu extends MenuElement {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-back', 'label-ad', 'label-original', 'label-track'];\n }\n\n declare private engine: Mattebox | null;\n\n constructor() {\n super(...single('audio'));\n this.engine = null;\n show(this.slots, 'default');\n }\n\n protected override name(): string {\n return 'Audio';\n }\n\n protected override attach(player: PlayerHost): void {\n this.follow(player, (engine) => {\n this.engine = engine;\n this.render();\n const tick = (): void => {\n this.render();\n };\n return engine === null\n ? onNativeTracks(player.video, 'audioTracks', tick)\n : onTracks(engine, tick);\n });\n }\n\n /** The native session's audio tracks as entries, and the enabled one's. */\n private native(tracks: readonly NativeAudioTrack[]): [TrackEntry[], string | null] {\n const ad = this.getAttribute('label-ad') ?? 'AD';\n const entries = tracks.map(\n (track, index): TrackEntry => [\n String(index),\n track.label,\n track.language,\n // HTML's kinds for an audio description track.\n track.kind === 'description' || track.kind === 'main-desc' ? [ad] : [],\n [],\n ],\n );\n const on = tracks.findIndex((track) => track.enabled);\n return [entries, on === -1 ? null : String(on)];\n }\n\n protected override render(): void {\n super.render();\n const engine = this.engine;\n const player = this.player;\n const tracks =\n engine === null && player !== null\n ? nativeTracks<NativeAudioTrack>(player, 'audioTracks')\n : undefined;\n if (engine === null && tracks === undefined) {\n this.hidden = true;\n return;\n }\n const [entries, active] =\n tracks !== undefined\n ? this.native(tracks)\n : trackItems(engine as Mattebox, 'audio', (track) => [\n ...(isAudioDescription(track) ? [this.getAttribute('label-ad') ?? 'AD'] : []),\n ...(isOriginal(track) ? [this.getAttribute('label-original') ?? 'Original'] : []),\n ]);\n const items = trackNames(entries, this.getAttribute('label-track'));\n this.menu.fill([\n {\n name: 'track',\n items,\n // The audio description badge is the AD mark, named by `label-ad`.\n badgeGlyphs: { [this.getAttribute('label-ad') ?? 'AD']: () => icon('audio-description') },\n value: active ?? '',\n onSelect: (value) => {\n // One audio track plays at a time, so the others are turned off.\n if (tracks !== undefined) {\n tracks.forEach((track, index) => {\n track.enabled = String(index) === value;\n });\n } else engine?.tracks.select(value);\n this.render();\n },\n },\n ]);\n this.hidden = items.length < 2;\n }\n}\n"],"mappings":";;;;;;;;AAuBA,SAAS,SAAS,OAAkC;CAClD,MAAM,QAAQ,MAAM,WAAW;CAC/B,OAAO,OAAO,aAAa,KAAA,IACv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IAAI;IAE3C,yFAAyF;IACzF,SAAS,CAAC,MAAM,IAAI,IAAI;CACzB"}
@@ -18,6 +18,16 @@ var Component = class extends HTMLElement {
18
18
  customElements.upgrade(found);
19
19
  if (!("video" in found)) return;
20
20
  this.player = found;
21
+ const tier = () => {
22
+ const layout = found.getAttribute("layout");
23
+ if (layout === null) this.removeAttribute("layout");
24
+ else this.setAttribute("layout", layout);
25
+ };
26
+ this.listen(found, ["layoutchange"], () => {
27
+ tier();
28
+ this.render();
29
+ });
30
+ tier();
21
31
  this.attach(this.player);
22
32
  };
23
33
  if ("video" in found) attach();
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","names":[],"sources":["../../src/elements/component.ts"],"sourcesContent":["/**\n * What every control shares: finding its player, and letting go of it.\n *\n * A control attaches when it is connected inside a player, once the player\n * is defined and upgraded, and detaches when it is removed. Every listener\n * a control adds goes through `listen`, so detaching drops them all. A\n * control connected outside a player is inert. Moving one to another\n * player detaches and attaches again, so a framework that reorders\n * children is safe.\n *\n * No class fields: the ES2015 build would lower them into helpers, and the\n * emit check bans helpers. State is declared, then assigned in the\n * constructor.\n */\nimport type { Mattebox } from 'mattebox';\nimport type { PlayerHost } from '../host.js';\nimport { findPlayer } from '../host.js';\nimport { PLAYER } from '../tags.js';\n\nexport abstract class Component extends HTMLElement {\n declare protected player: PlayerHost | null;\n declare private offs: Array<() => void>;\n /** Bumped on every connect and disconnect, so a late upgrade attaches only to the current connection. */\n declare private epoch: number;\n\n constructor() {\n super();\n this.player = null;\n this.offs = [];\n this.epoch = 0;\n }\n\n connectedCallback(): void {\n const found = findPlayer(this);\n if (found === null) return;\n this.epoch += 1;\n const epoch = this.epoch;\n const attach = (): void => {\n if (epoch !== this.epoch || !this.isConnected) return;\n // Defined, and this instance upgraded: `video` is on the prototype.\n customElements.upgrade(found);\n if (!('video' in found)) return;\n this.player = found as PlayerHost;\n this.attach(this.player);\n };\n if ('video' in found) attach();\n else void customElements.whenDefined(PLAYER).then(attach);\n }\n\n disconnectedCallback(): void {\n this.epoch += 1;\n for (const off of this.offs) off();\n this.offs = [];\n const player = this.player;\n if (player === null) return;\n this.player = null;\n this.detach(player);\n }\n\n attributeChangedCallback(): void {\n if (this.player !== null) this.render();\n }\n\n /** Adds `fn` for every name on `target`, to be removed on detach. */\n protected listen(\n target: EventTarget,\n names: readonly string[],\n fn: (event: Event) => void,\n ): void {\n for (const name of names) target.addEventListener(name, fn);\n this.offs.push(() => {\n for (const name of names) target.removeEventListener(name, fn);\n });\n }\n\n /** Keeps `off` to run on detach. */\n protected keep(off: () => void): void {\n this.offs.push(off);\n }\n\n /**\n * Runs `fn` over the current engine now and on every session change,\n * running what the last call returned first, so a control's engine\n * subscriptions live exactly as long as the session. Detach runs it too.\n */\n protected follow(\n player: PlayerHost,\n fn: (engine: Mattebox | null) => (() => void) | undefined,\n ): void {\n let off: (() => void) | undefined;\n const run = (): void => {\n off?.();\n off = fn(player.engine);\n };\n this.listen(player, ['sourcechange'], run);\n this.offs.push(() => {\n off?.();\n off = undefined;\n });\n run();\n }\n\n /** Runs `fn` when any of `names` changes on `target`, or under it with `subtree`, until detach. */\n protected observe(\n target: Element,\n names: readonly string[],\n fn: () => void,\n subtree = false,\n ): void {\n const observer = new MutationObserver(fn);\n observer.observe(target, { attributes: true, attributeFilter: [...names], subtree });\n this.offs.push(() => {\n observer.disconnect();\n });\n }\n\n /** The control is connected inside an upgraded player. Subscribe and render. */\n protected abstract attach(player: PlayerHost): void;\n\n /** The control left its player. Listeners are already gone; undo anything else. */\n protected detach(_player: PlayerHost): void {}\n\n /** Draws the current state. Called on every observed attribute change while attached. */\n protected render(): void {}\n}\n"],"mappings":";;;AAmBA,IAAsB,YAAtB,cAAwC,YAAY;CAMlD,cAAc;EACZ,MAAM;EACN,KAAK,SAAS;EACd,KAAK,OAAO,CAAC;EACb,KAAK,QAAQ;CACf;CAEA,oBAA0B;EACxB,MAAM,QAAQ,WAAW,IAAI;EAC7B,IAAI,UAAU,MAAM;EACpB,KAAK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EACtB,CAAC;CACH;;CAMA,OAAiB,SAA2B,CAAC;;CAG7C,SAAyB,CAAC;AAC5B"}
1
+ {"version":3,"file":"component.js","names":[],"sources":["../../src/elements/component.ts"],"sourcesContent":["/**\n * What every control shares: finding its player, and letting go of it.\n *\n * A control attaches when it is connected inside a player, once the player\n * is defined and upgraded, and detaches when it is removed. Every listener\n * a control adds goes through `listen`, so detaching drops them all. A\n * control connected outside a player is inert. Moving one to another\n * player detaches and attaches again, so a framework that reorders\n * children is safe.\n *\n * No class fields: the ES2015 build would lower them into helpers, and the\n * emit check bans helpers. State is declared, then assigned in the\n * constructor.\n */\nimport type { Mattebox } from 'mattebox';\nimport type { PlayerHost } from '../host.js';\nimport { findPlayer } from '../host.js';\nimport { PLAYER } from '../tags.js';\n\nexport abstract class Component extends HTMLElement {\n declare protected player: PlayerHost | null;\n declare private offs: Array<() => void>;\n /** Bumped on every connect and disconnect, so a late upgrade attaches only to the current connection. */\n declare private epoch: number;\n\n constructor() {\n super();\n this.player = null;\n this.offs = [];\n this.epoch = 0;\n }\n\n connectedCallback(): void {\n const found = findPlayer(this);\n if (found === null) return;\n this.epoch += 1;\n const epoch = this.epoch;\n const attach = (): void => {\n if (epoch !== this.epoch || !this.isConnected) return;\n // Defined, and this instance upgraded: `video` is on the prototype.\n customElements.upgrade(found);\n if (!('video' in found)) return;\n this.player = found as PlayerHost;\n // The player's size tier, on the control itself: a shadow tree cannot\n // match an attribute of an ancestor in every browser, and with it\n // here a control's stylesheet says `:host([layout=\"compact\"])`.\n const tier = (): void => {\n const layout = found.getAttribute('layout');\n if (layout === null) this.removeAttribute('layout');\n else this.setAttribute('layout', layout);\n };\n this.listen(found, ['layoutchange'], () => {\n tier();\n this.render();\n });\n tier();\n this.attach(this.player);\n };\n if ('video' in found) attach();\n else void customElements.whenDefined(PLAYER).then(attach);\n }\n\n disconnectedCallback(): void {\n this.epoch += 1;\n for (const off of this.offs) off();\n this.offs = [];\n const player = this.player;\n if (player === null) return;\n this.player = null;\n this.detach(player);\n }\n\n attributeChangedCallback(): void {\n if (this.player !== null) this.render();\n }\n\n /** Adds `fn` for every name on `target`, to be removed on detach. */\n protected listen(\n target: EventTarget,\n names: readonly string[],\n fn: (event: Event) => void,\n ): void {\n for (const name of names) target.addEventListener(name, fn);\n this.offs.push(() => {\n for (const name of names) target.removeEventListener(name, fn);\n });\n }\n\n /** Keeps `off` to run on detach. */\n protected keep(off: () => void): void {\n this.offs.push(off);\n }\n\n /**\n * Runs `fn` over the current engine now and on every session change,\n * running what the last call returned first, so a control's engine\n * subscriptions live exactly as long as the session. Detach runs it too.\n */\n protected follow(\n player: PlayerHost,\n fn: (engine: Mattebox | null) => (() => void) | undefined,\n ): void {\n let off: (() => void) | undefined;\n const run = (): void => {\n off?.();\n off = fn(player.engine);\n };\n this.listen(player, ['sourcechange'], run);\n this.offs.push(() => {\n off?.();\n off = undefined;\n });\n run();\n }\n\n /** Runs `fn` when any of `names` changes on `target`, or under it with `subtree`, until detach. */\n protected observe(\n target: Element,\n names: readonly string[],\n fn: () => void,\n subtree = false,\n ): void {\n const observer = new MutationObserver(fn);\n observer.observe(target, { attributes: true, attributeFilter: [...names], subtree });\n this.offs.push(() => {\n observer.disconnect();\n });\n }\n\n /** The control is connected inside an upgraded player. Subscribe and render. */\n protected abstract attach(player: PlayerHost): void;\n\n /** The control left its player. Listeners are already gone; undo anything else. */\n protected detach(_player: PlayerHost): void {}\n\n /** Draws the current state. Called on every observed attribute change while attached. */\n protected render(): void {}\n}\n"],"mappings":";;;AAmBA,IAAsB,YAAtB,cAAwC,YAAY;CAMlD,cAAc;EACZ,MAAM;EACN,KAAK,SAAS;EACd,KAAK,OAAO,CAAC;EACb,KAAK,QAAQ;CACf;CAEA,oBAA0B;EACxB,MAAM,QAAQ,WAAW,IAAI;EAC7B,IAAI,UAAU,MAAM;EACpB,KAAK,SAAS;EACd,MAAM,QAAQ,KAAK;EACnB,MAAM,eAAqB;GACzB,IAAI,UAAU,KAAK,SAAS,CAAC,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AAiB,EAAE;EACxC,SAAS,QAAQ,QAAQ;GAAE,YAAY;GAAM,iBAAiB,CAAC,GAAG,KAAK;GAAG;EAAQ,CAAC;EACnF,KAAK,KAAK,WAAW;GACnB,SAAS,WAAW;EACtB,CAAC;CACH;;CAMA,OAAiB,SAA2B,CAAC;;CAG7C,SAAyB,CAAC;AAC5B"}
@@ -60,6 +60,8 @@ export declare class MbxControlBar extends Component {
60
60
  * folded slider at the width it unfolds to. The row's own width says nothing, because the
61
61
  * spacer fills it whatever the buttons take.
62
62
  */
63
+ /** The bar's em in pixels: its sizes follow the player's font size. */
64
+ private em;
63
65
  private needed;
64
66
  /**
65
67
  * Collapses the buttons row to its width. Everything is shown first, so
@@ -1 +1 @@
1
- {"version":3,"file":"control-bar.d.ts","sourceRoot":"","sources":["../../src/elements/control-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAiB7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA6E3C,qBAAa,aAAc,SAAQ,SAAS;IAC1C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,OAAO,CAAiB;IACjD,iBAAyB,UAAU,CAAiB;IACpD,iBAAyB,OAAO,CAAkB;IAClD,QAAgB,KAAK,CAA4C;IACjE,6FAA6F;IAC7F,QAAgB,OAAO,CAAwB;IAC/C,uEAAuE;IACvE,QAAgB,QAAQ,CAAU;IAClC,QAAgB,IAAI,CAAiB;IACrC,QAAgB,MAAM,CAAoB;;IAsB1C;;;;;OAKG;IACH,OAAO,CAAC,MAAM;IAed;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IAyBhB,wFAAwF;IACxF,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,IAAI;IAOZ,OAAO,CAAC,KAAK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+4,7 @@ import { number, style } from "./shared.js";
4
4
  import { cueLift, cueStyle } from "../controls/cues.js";
5
5
  import { fullscreen } from "../controls/fullscreen.js";
6
6
  //#region src/elements/control-bar.ts
7
- const STYLE = ":host{box-sizing:border-box;color:var(--mbx-text);font:500 16px / 1.2 var(--mbx-font);background:linear-gradient(#0000,#0009);flex-direction:column;padding:40px 16px 12px;transition:opacity .2s;display:flex;position:absolute;bottom:0;left:0;right:0}:host([idle]){opacity:0;pointer-events:none}[part~=row]{align-items:center;margin:0 -4px;display:flex}[part~=buttons-row]{margin-top:4px}[part~=seek-row]{margin:0 -8px}slot:not([name])::slotted(*){margin:0 4px}slot[name=seek]::slotted(*){margin:0 8px}::slotted([collapsed]){display:none}@media (prefers-reduced-motion:reduce){:host{transition:none}}";
7
+ const STYLE = ":host{box-sizing:border-box;color:var(--mbx-text);font:500 1em / 1.2 var(--mbx-font);background:linear-gradient(#0000,#0009);flex-direction:column;padding:2.5em 1em .75em;transition:opacity .2s;display:flex;position:absolute;bottom:0;left:0;right:0}:host([menu]){z-index:2;--mbx-tooltip:none}:host([idle]){opacity:0;pointer-events:none}[part~=row]{align-items:center;margin:0 -.25em;display:flex}[part~=buttons-row]{margin-top:.25em}[part~=seek-row]{margin:0 -.5em}slot:not([name])::slotted(*){margin:0 .25em}slot[name=seek]::slotted(*){margin:0 .5em}::slotted([collapsed]){display:none}@media (prefers-reduced-motion:reduce){:host{transition:none}}:host([layout=compact]){padding:1.5em .5em .25em}";
8
8
  const IDLE_MS = 3e3;
9
9
  const SEEK_STEP = 5;
10
10
  /**
@@ -33,10 +33,10 @@ const PRIORITY = {
33
33
  [VOLUME]: 1,
34
34
  [MUTE_BUTTON]: 1
35
35
  };
36
- /** The width the volume group unfolds its slider to, from volume.ts: what a folded slider is counted at. */
37
- const SLIDER_WIDTH = 80;
38
- /** Room kept between the last button and the edge, so nothing sits flush against it. */
39
- const SLACK = 8;
36
+ /** The width the volume group unfolds its slider to, in em, from volume.css: what a folded slider is counted at. */
37
+ const SLIDER_WIDTH = 5;
38
+ /** Room kept between the last button and the edge, in em, so nothing sits flush against it. */
39
+ const SLACK = .5;
40
40
  function shown(node) {
41
41
  return node.getClientRects().length > 0;
42
42
  }
@@ -91,6 +91,10 @@ var MbxControlBar = class extends Component {
91
91
  * folded slider at the width it unfolds to. The row's own width says nothing, because the
92
92
  * spacer fills it whatever the buttons take.
93
93
  */
94
+ /** The bar's em in pixels: its sizes follow the player's font size. */
95
+ em() {
96
+ return Number.parseFloat(getComputedStyle(this).fontSize) || 16;
97
+ }
94
98
  needed(children) {
95
99
  let sum = 0;
96
100
  for (const child of children) {
@@ -99,7 +103,7 @@ var MbxControlBar = class extends Component {
99
103
  sum += child.getBoundingClientRect().width;
100
104
  sum += Number.parseFloat(margins.marginLeft) + Number.parseFloat(margins.marginRight);
101
105
  const folded = slider(child);
102
- if (folded !== null && shown(folded)) sum += Math.max(0, SLIDER_WIDTH - folded.getBoundingClientRect().width);
106
+ if (folded !== null && shown(folded)) sum += Math.max(0, SLIDER_WIDTH * this.em() - folded.getBoundingClientRect().width);
103
107
  }
104
108
  return sum;
105
109
  }
@@ -129,7 +133,7 @@ var MbxControlBar = class extends Component {
129
133
  });
130
134
  }
131
135
  candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);
132
- const room = this.buttonsRow.clientWidth - SLACK;
136
+ const room = this.buttonsRow.clientWidth - SLACK * this.em();
133
137
  for (const { node, priority: level } of candidates) {
134
138
  if (level === 0) return;
135
139
  if (this.needed(children) <= room) return;
@@ -239,6 +243,18 @@ var MbxControlBar = class extends Component {
239
243
  };
240
244
  this.keep(screen.watch(reflect));
241
245
  reflect();
246
+ const menus = new MutationObserver(() => {
247
+ this.toggleAttribute("menu", this.querySelector("[open]") !== null);
248
+ });
249
+ menus.observe(this, {
250
+ subtree: true,
251
+ attributes: true,
252
+ attributeFilter: ["open"]
253
+ });
254
+ this.keep(() => {
255
+ menus.disconnect();
256
+ this.removeAttribute("menu");
257
+ });
242
258
  const pointer = () => {
243
259
  this.keyboard = false;
244
260
  this.wake(player);
@@ -1 +1 @@
1
- {"version":3,"file":"control-bar.js","names":[],"sources":["../../src/elements/control-bar.ts"],"sourcesContent":["/**\n * <mbx-control-bar>: an overlay over the bottom of the video that lays its\n * children out in two rows, the seek row over the buttons row. A child\n * with `slot=\"seek\"` sits in the seek row; everything else in the buttons\n * row, in its order, and an <mbx-spacer> pushes what follows to the right.\n *\n * The bar owns what no one control can: the idle fade, the shortcuts, the\n * click on the video, and the subtitles lifted above it. It sets `idle` on\n * itself and on the player while it hides.\n *\n * The fade is one timer. Any activity, a pointer moving or pressing, a\n * key, playback starting, re-arms it for `idle-ms`, and when it fires the\n * bar hides unless something it can know for certain holds it: the video\n * is paused, a descendant carries `open`, or keyboard focus is inside it,\n * where keyboard means the last input was a key and not a pointer.\n * Whether the pointer is over the player is never tracked: that goes\n * stale when the pointer leaves without a move the player sees.\n *\n * The shortcuts listen on the player, so they hear every key pressed\n * inside it, and only there: Space and `k` toggle play, `m` mutes, `f`\n * toggles fullscreen, the arrows seek by `seek-step`. The media keys a\n * remote or a keyboard sends do the same: play and pause, Stop pauses,\n * fast forward and rewind seek by `seek-step`. A seeking key fires\n * `seekkey` on the player first, which a seek bar may take to aim instead.\n * The bar is the one owner of the keys that work anywhere in the player:\n * it listens last, so the focused control, and a spatial navigation in\n * the capture phase, decide before it. Space is left to a\n * focused button, which is its own. A key another handler prevented is\n * left alone. A click on the video toggles play.\n * Fullscreen goes on the player itself, so the bar comes along.\n *\n * A narrow bar collapses the buttons row by `priority`: each child carries\n * a number, its own attribute or the default for its tag, and the bar\n * marks the highest numbers `collapsed` one at a time until the row fits\n * with a little slack, from the right among equals. Zero, the default for\n * anything unlisted, never collapses: play and fullscreen stay whatever\n * the width. The mark is an attribute and the hiding is one `::slotted`\n * rule here, so a page styles or overrides it by the tag. The volume's\n * slider is a candidate of its own, and counts at its unfolded width, so\n * the row is sized for what the pointer will make of it.\n */\n\nimport type { CueLift } from '../controls/cues.js';\nimport { cueLift, cueStyle } from '../controls/cues.js';\nimport type { Fullscreen } from '../controls/fullscreen.js';\nimport { fullscreen } from '../controls/fullscreen.js';\nimport type { PlayerHost } from '../host.js';\nimport {\n AIRPLAY_BUTTON,\n AUDIO_MENU,\n CHAPTERS_MENU,\n DRM_BADGE,\n MUTE_BUTTON,\n PIP_BUTTON,\n QUALITY_MENU,\n SCAN_BUTTON,\n SKIP_BUTTON,\n SPACER,\n SPEED_MENU,\n SUBTITLES_MENU,\n VOLUME,\n VOLUME_SLIDER,\n} from '../tags.js';\nimport { Component } from './component.js';\nimport STYLE from './control-bar.css?inline';\nimport { number, style } from './shared.js';\n\nconst IDLE_MS = 3000;\nconst SEEK_STEP = 5;\n\n/**\n * What goes first when the row is too narrow, by tag: the scans, which\n * suit a TV remote more than a small screen; then the slider, which takes\n * the most room for the least; then the diagnostics, the lock and the\n * menus a viewer rarely opens; then the menus for the picture and the\n * sound; then the skips; then the mute and the subtitles. The subtitles\n * menu goes last of the menus because it is the one a viewer may need.\n * The diagnostics is another package's, named here as a string. A\n * `priority` attribute on the control replaces its default.\n */\nconst PRIORITY: Readonly<Record<string, number>> = {\n [SCAN_BUTTON]: 6,\n [VOLUME_SLIDER]: 5,\n 'mbx-diagnostics': 4,\n [DRM_BADGE]: 4,\n [SPEED_MENU]: 4,\n [CHAPTERS_MENU]: 4,\n [AUDIO_MENU]: 3,\n [QUALITY_MENU]: 3,\n [PIP_BUTTON]: 3,\n [AIRPLAY_BUTTON]: 2,\n [SKIP_BUTTON]: 2,\n [SUBTITLES_MENU]: 1,\n [VOLUME]: 1,\n [MUTE_BUTTON]: 1,\n};\n\n/** The width the volume group unfolds its slider to, from volume.ts: what a folded slider is counted at. */\nconst SLIDER_WIDTH = 80;\n\n/** Room kept between the last button and the edge, so nothing sits flush against it. */\nconst SLACK = 8;\n\ninterface Candidate {\n readonly node: Element;\n /** The bar child it sits in, for the order among equals. */\n readonly index: number;\n readonly priority: number;\n}\n\nfunction shown(node: Element): boolean {\n return node.getClientRects().length > 0;\n}\n\n/** The slider inside a volume group child, when it has one. */\nfunction slider(child: Element): Element | null {\n return child.localName === VOLUME ? child.querySelector(VOLUME_SLIDER) : null;\n}\n\n/** A child's priority: its attribute, else its tag's default, else zero. */\nfunction priority(child: Element): number {\n const own = child.getAttribute('priority');\n if (own !== null) {\n const value = Number(own);\n return Number.isFinite(value) && value > 0 ? value : 0;\n }\n return PRIORITY[child.localName] ?? 0;\n}\n\nfunction end(video: HTMLVideoElement): number {\n if (Number.isFinite(video.duration)) return video.duration;\n const ranges = video.seekable;\n return ranges.length > 0 ? ranges.end(ranges.length - 1) : video.currentTime;\n}\n\nfunction toggle(video: HTMLVideoElement): void {\n if (video.paused) video.play().catch(() => undefined);\n else video.pause();\n}\n\nexport class MbxControlBar extends Component {\n static get observedAttributes(): readonly string[] {\n return ['idle-ms', 'seek-step'];\n }\n\n declare private readonly seekRow: HTMLDivElement;\n declare private readonly buttonsRow: HTMLDivElement;\n declare private readonly buttons: HTMLSlotElement;\n declare private timer: ReturnType<typeof setTimeout> | undefined;\n /** Fires on a width change of the buttons row, so the collapse follows the page's layout. */\n declare private resizer: ResizeObserver | null;\n /** Whether the last input was a key, so focus inside holds the bar. */\n declare private keyboard: boolean;\n declare private cues: CueLift | null;\n declare private screen: Fullscreen | null;\n\n constructor() {\n super();\n this.timer = undefined;\n this.keyboard = false;\n this.cues = null;\n this.screen = null;\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.seekRow = document.createElement('div');\n this.seekRow.setAttribute('part', 'row seek-row');\n const seek = document.createElement('slot');\n seek.name = 'seek';\n this.seekRow.append(seek);\n this.buttonsRow = document.createElement('div');\n this.buttonsRow.setAttribute('part', 'row buttons-row');\n this.buttons = document.createElement('slot');\n this.buttonsRow.append(this.buttons);\n root.append(style(STYLE), this.seekRow, this.buttonsRow);\n }\n\n /**\n * What the buttons need: their widths and their margins, which are the\n * gaps between them, the spacer aside since it takes what is left, and a\n * folded slider at the width it unfolds to. The row's own width says nothing, because the\n * spacer fills it whatever the buttons take.\n */\n private needed(children: readonly Element[]): number {\n let sum = 0;\n for (const child of children) {\n if (child.localName === SPACER || !shown(child)) continue;\n const margins = getComputedStyle(child);\n sum += child.getBoundingClientRect().width;\n sum += Number.parseFloat(margins.marginLeft) + Number.parseFloat(margins.marginRight);\n const folded = slider(child);\n if (folded !== null && shown(folded)) {\n sum += Math.max(0, SLIDER_WIDTH - folded.getBoundingClientRect().width);\n }\n }\n return sum;\n }\n\n /**\n * Collapses the buttons row to its width. Everything is shown first, so\n * a wider bar gets its controls back, then the highest priorities go one\n * at a time while the buttons need more than the row has, less the\n * slack. Each step lays the row out again; a bar carries a dozen\n * controls, so that is cheap.\n */\n private collapse(): void {\n const children = this.buttons.assignedElements();\n const candidates: Candidate[] = [];\n for (const [index, child] of children.entries()) {\n child.removeAttribute('collapsed');\n const inner = slider(child);\n inner?.removeAttribute('collapsed');\n // A nested slider goes before its group, so it sorts as if it sat\n // after it. What is not shown, by its own `hidden` or a page's rule,\n // takes no room, so marking it would hide nothing and say something\n // false.\n if (inner !== null && shown(inner)) {\n candidates.push({ node: inner, index: index + 0.5, priority: priority(inner) });\n }\n if (shown(child)) candidates.push({ node: child, index, priority: priority(child) });\n }\n candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);\n const room = this.buttonsRow.clientWidth - SLACK;\n for (const { node, priority: level } of candidates) {\n if (level === 0) return;\n if (this.needed(children) <= room) return;\n node.setAttribute('collapsed', '');\n }\n }\n\n /** From the first row's top to the bar's bottom: what the bar covers of the picture. */\n private covered(): { top: number; bottom: number } {\n return {\n top: this.seekRow.getBoundingClientRect().top,\n bottom: this.getBoundingClientRect().bottom,\n };\n }\n\n private held(player: PlayerHost): boolean {\n if (player.video.paused) return true;\n if (this.querySelector('[open]') !== null) return true;\n if (!this.keyboard) return false;\n const active = (this.getRootNode() as Document | ShadowRoot).activeElement;\n return active !== null && this.contains(active);\n }\n\n private idle(player: PlayerHost, on: boolean): void {\n if (this.hasAttribute('idle') === on) return;\n this.toggleAttribute('idle', on);\n player.toggleAttribute('idle', on);\n this.cues?.lifted(!on);\n }\n\n private sleep(player: PlayerHost): void {\n this.timer = undefined;\n // A hold is checked again later: a menu closes and a pause ends without\n // an event the bar hears.\n if (this.held(player)) {\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n return;\n }\n this.idle(player, true);\n }\n\n private wake(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.idle(player, false);\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n }\n\n /**\n * A seeking key: `seekkey` on the player first, cancellable, with the\n * seconds in `detail.by`. A seek bar under `key-mode=\"preview\"` takes it\n * to aim instead. Nobody took it: the playhead moves now.\n */\n private seekBy(player: PlayerHost, by: number): void {\n const asked = new CustomEvent('seekkey', { detail: { by }, cancelable: true });\n if (!player.dispatchEvent(asked)) return;\n const video = player.video;\n video.currentTime = Math.min(end(video), Math.max(0, video.currentTime + by));\n }\n\n private key(player: PlayerHost, event: KeyboardEvent): void {\n this.keyboard = true;\n this.wake(player);\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const video = player.video;\n const onButton = event.composedPath()[0] instanceof HTMLButtonElement;\n switch (event.key) {\n case ' ':\n if (onButton) return;\n toggle(video);\n break;\n case 'k':\n case 'K':\n toggle(video);\n break;\n case 'm':\n case 'M':\n video.muted = !video.muted;\n break;\n case 'f':\n case 'F':\n this.screen?.toggle();\n break;\n // The media keys, which remotes and many keyboards send. UI Events\n // KeyboardEvent key values, Multimedia keys.\n case 'MediaPlayPause':\n toggle(video);\n break;\n case 'MediaPlay':\n void video.play().catch(() => undefined);\n break;\n // Stop pauses: the source stays, as a viewer expects on a remote.\n case 'MediaPause':\n case 'MediaStop':\n video.pause();\n break;\n case 'ArrowLeft':\n case 'MediaRewind':\n this.seekBy(player, -number(this, 'seek-step', SEEK_STEP));\n break;\n case 'ArrowRight':\n case 'MediaFastForward':\n this.seekBy(player, number(this, 'seek-step', SEEK_STEP));\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.video;\n cueStyle();\n this.cues = cueLift(video, player, () => this.covered());\n const screen = fullscreen(player, video);\n this.screen = screen;\n const reflect = (): void => {\n player.toggleAttribute('fullscreen', screen.active());\n };\n this.keep(screen.watch(reflect));\n reflect();\n\n const pointer = (): void => {\n this.keyboard = false;\n this.wake(player);\n };\n const key = (event: Event): void => {\n this.key(player, event as KeyboardEvent);\n };\n const click = (event: Event): void => {\n // The video and nothing else: a control handles its own click.\n if (event.composedPath()[0] === video) toggle(video);\n };\n this.listen(player, ['pointermove', 'pointerdown'], pointer);\n player.addEventListener('keydown', key);\n player.addEventListener('click', click);\n this.keep(() => {\n player.removeEventListener('keydown', key);\n player.removeEventListener('click', click);\n });\n this.listen(video, ['play', 'pause', 'ended'], () => {\n this.wake(player);\n });\n this.wake(player);\n this.cues.lifted(true);\n\n // The row's width, its children, and what they hide or reprioritise on\n // their own: each can change what fits. `collapsed` is left out of the\n // filter, since the bar writes it.\n const collapse = (): void => {\n this.collapse();\n };\n this.listen(this.buttons, ['slotchange'], collapse);\n this.observe(this, ['hidden', 'priority', 'slot'], collapse, true);\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(collapse);\n this.resizer.observe(this.buttonsRow);\n }\n collapse();\n }\n\n protected override detach(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.timer = undefined;\n this.resizer?.disconnect();\n this.resizer = null;\n for (const child of this.buttons.assignedElements()) {\n child.removeAttribute('collapsed');\n slider(child)?.removeAttribute('collapsed');\n }\n this.cues?.dispose();\n this.cues = null;\n this.screen = null;\n this.removeAttribute('idle');\n player.removeAttribute('idle');\n player.removeAttribute('fullscreen');\n }\n}\n"],"mappings":";;;;;;AAgEA,MAAA,QAAA;AAGA,MAAA,UAAA;AACA,MAAA,YAAA;;;;;;;;;;;AAYA,MAAA,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,CAAA,eAAA,aAAA,GAAA,OAAA;EACA,OAAA,iBAAA,WAAA,GAAA;EACA,OAAA,iBAAA,SAAA,KAAA;EACA,KAAA,WAAA;GACA,OAAA,oBAAA,WAAA,GAAA;GACA,OAAA,oBAAA,SAAA,KAAA;EACA,CAAA;EACA,KAAA,OAAA,OAAA;GAAA;GAAA;GAAA;EAAA,SAAA;GACA,KAAA,KAAA,MAAA;EACA,CAAA;EACA,KAAA,KAAA,MAAA;EACA,KAAA,KAAA,OAAA,IAAA;EAKA,MAAA,iBAAA;GACA,KAAA,SAAA;EACA;EACA,KAAA,OAAA,KAAA,SAAA,CAAA,YAAA,GAAA,QAAA;EACA,KAAA,QAAA,MAAA;GAAA;GAAA;GAAA;EAAA,GAAA,UAAA,IAAA;EACA,IAAA,OAAA,mBAAA,aAAA;GACA,KAAA,UAAA,IAAA,eAAA,QAAA;GACA,KAAA,QAAA,QAAA,KAAA,UAAA;EACA;EACA,SAAA;CACA;CAEA,OAAA,QAAA;EACA,aAAA,KAAA,KAAA;EACA,KAAA,QAAA,KAAA;EACA,KAAA,SAAA,WAAA;EACA,KAAA,UAAA;EACA,KAAA,MAAA,SAAA,KAAA,QAAA,iBAAA,GAAA;GACA,MAAA,gBAAA,WAAA;GACA,OAAA,KAAA,CAAA,EAAA,gBAAA,WAAA;EACA;EACA,KAAA,MAAA,QAAA;EACA,KAAA,OAAA;EACA,KAAA,SAAA;EACA,KAAA,gBAAA,MAAA;EACA,OAAA,gBAAA,MAAA;EACA,OAAA,gBAAA,YAAA;CACA;AACA"}
1
+ {"version":3,"file":"control-bar.js","names":[],"sources":["../../src/elements/control-bar.ts"],"sourcesContent":["/**\n * <mbx-control-bar>: an overlay over the bottom of the video that lays its\n * children out in two rows, the seek row over the buttons row. A child\n * with `slot=\"seek\"` sits in the seek row; everything else in the buttons\n * row, in its order, and an <mbx-spacer> pushes what follows to the right.\n *\n * The bar owns what no one control can: the idle fade, the shortcuts, the\n * click on the video, and the subtitles lifted above it. It sets `idle` on\n * itself and on the player while it hides.\n *\n * The fade is one timer. Any activity, a pointer moving or pressing, a\n * key, playback starting, re-arms it for `idle-ms`, and when it fires the\n * bar hides unless something it can know for certain holds it: the video\n * is paused, a descendant carries `open`, or keyboard focus is inside it,\n * where keyboard means the last input was a key and not a pointer.\n * Whether the pointer is over the player is never tracked: that goes\n * stale when the pointer leaves without a move the player sees.\n *\n * The shortcuts listen on the player, so they hear every key pressed\n * inside it, and only there: Space and `k` toggle play, `m` mutes, `f`\n * toggles fullscreen, the arrows seek by `seek-step`. The media keys a\n * remote or a keyboard sends do the same: play and pause, Stop pauses,\n * fast forward and rewind seek by `seek-step`. A seeking key fires\n * `seekkey` on the player first, which a seek bar may take to aim instead.\n * The bar is the one owner of the keys that work anywhere in the player:\n * it listens last, so the focused control, and a spatial navigation in\n * the capture phase, decide before it. Space is left to a\n * focused button, which is its own. A key another handler prevented is\n * left alone. A click on the video toggles play.\n * Fullscreen goes on the player itself, so the bar comes along.\n *\n * A narrow bar collapses the buttons row by `priority`: each child carries\n * a number, its own attribute or the default for its tag, and the bar\n * marks the highest numbers `collapsed` one at a time until the row fits\n * with a little slack, from the right among equals. Zero, the default for\n * anything unlisted, never collapses: play and fullscreen stay whatever\n * the width. The mark is an attribute and the hiding is one `::slotted`\n * rule here, so a page styles or overrides it by the tag. The volume's\n * slider is a candidate of its own, and counts at its unfolded width, so\n * the row is sized for what the pointer will make of it.\n */\n\nimport type { CueLift } from '../controls/cues.js';\nimport { cueLift, cueStyle } from '../controls/cues.js';\nimport type { Fullscreen } from '../controls/fullscreen.js';\nimport { fullscreen } from '../controls/fullscreen.js';\nimport type { PlayerHost } from '../host.js';\nimport {\n AIRPLAY_BUTTON,\n AUDIO_MENU,\n CHAPTERS_MENU,\n DRM_BADGE,\n MUTE_BUTTON,\n PIP_BUTTON,\n QUALITY_MENU,\n SCAN_BUTTON,\n SKIP_BUTTON,\n SPACER,\n SPEED_MENU,\n SUBTITLES_MENU,\n VOLUME,\n VOLUME_SLIDER,\n} from '../tags.js';\nimport { Component } from './component.js';\nimport STYLE from './control-bar.css?inline';\nimport { number, style } from './shared.js';\n\nconst IDLE_MS = 3000;\nconst SEEK_STEP = 5;\n\n/**\n * What goes first when the row is too narrow, by tag: the scans, which\n * suit a TV remote more than a small screen; then the slider, which takes\n * the most room for the least; then the diagnostics, the lock and the\n * menus a viewer rarely opens; then the menus for the picture and the\n * sound; then the skips; then the mute and the subtitles. The subtitles\n * menu goes last of the menus because it is the one a viewer may need.\n * The diagnostics is another package's, named here as a string. A\n * `priority` attribute on the control replaces its default.\n */\nconst PRIORITY: Readonly<Record<string, number>> = {\n [SCAN_BUTTON]: 6,\n [VOLUME_SLIDER]: 5,\n 'mbx-diagnostics': 4,\n [DRM_BADGE]: 4,\n [SPEED_MENU]: 4,\n [CHAPTERS_MENU]: 4,\n [AUDIO_MENU]: 3,\n [QUALITY_MENU]: 3,\n [PIP_BUTTON]: 3,\n [AIRPLAY_BUTTON]: 2,\n [SKIP_BUTTON]: 2,\n [SUBTITLES_MENU]: 1,\n [VOLUME]: 1,\n [MUTE_BUTTON]: 1,\n};\n\n/** The width the volume group unfolds its slider to, in em, from volume.css: what a folded slider is counted at. */\nconst SLIDER_WIDTH = 5;\n\n/** Room kept between the last button and the edge, in em, so nothing sits flush against it. */\nconst SLACK = 0.5;\n\ninterface Candidate {\n readonly node: Element;\n /** The bar child it sits in, for the order among equals. */\n readonly index: number;\n readonly priority: number;\n}\n\nfunction shown(node: Element): boolean {\n return node.getClientRects().length > 0;\n}\n\n/** The slider inside a volume group child, when it has one. */\nfunction slider(child: Element): Element | null {\n return child.localName === VOLUME ? child.querySelector(VOLUME_SLIDER) : null;\n}\n\n/** A child's priority: its attribute, else its tag's default, else zero. */\nfunction priority(child: Element): number {\n const own = child.getAttribute('priority');\n if (own !== null) {\n const value = Number(own);\n return Number.isFinite(value) && value > 0 ? value : 0;\n }\n return PRIORITY[child.localName] ?? 0;\n}\n\nfunction end(video: HTMLVideoElement): number {\n if (Number.isFinite(video.duration)) return video.duration;\n const ranges = video.seekable;\n return ranges.length > 0 ? ranges.end(ranges.length - 1) : video.currentTime;\n}\n\nfunction toggle(video: HTMLVideoElement): void {\n if (video.paused) video.play().catch(() => undefined);\n else video.pause();\n}\n\nexport class MbxControlBar extends Component {\n static get observedAttributes(): readonly string[] {\n return ['idle-ms', 'seek-step'];\n }\n\n declare private readonly seekRow: HTMLDivElement;\n declare private readonly buttonsRow: HTMLDivElement;\n declare private readonly buttons: HTMLSlotElement;\n declare private timer: ReturnType<typeof setTimeout> | undefined;\n /** Fires on a width change of the buttons row, so the collapse follows the page's layout. */\n declare private resizer: ResizeObserver | null;\n /** Whether the last input was a key, so focus inside holds the bar. */\n declare private keyboard: boolean;\n declare private cues: CueLift | null;\n declare private screen: Fullscreen | null;\n\n constructor() {\n super();\n this.timer = undefined;\n this.keyboard = false;\n this.cues = null;\n this.screen = null;\n this.resizer = null;\n const root = this.attachShadow({ mode: 'open' });\n this.seekRow = document.createElement('div');\n this.seekRow.setAttribute('part', 'row seek-row');\n const seek = document.createElement('slot');\n seek.name = 'seek';\n this.seekRow.append(seek);\n this.buttonsRow = document.createElement('div');\n this.buttonsRow.setAttribute('part', 'row buttons-row');\n this.buttons = document.createElement('slot');\n this.buttonsRow.append(this.buttons);\n root.append(style(STYLE), this.seekRow, this.buttonsRow);\n }\n\n /**\n * What the buttons need: their widths and their margins, which are the\n * gaps between them, the spacer aside since it takes what is left, and a\n * folded slider at the width it unfolds to. The row's own width says nothing, because the\n * spacer fills it whatever the buttons take.\n */\n /** The bar's em in pixels: its sizes follow the player's font size. */\n private em(): number {\n return Number.parseFloat(getComputedStyle(this).fontSize) || 16;\n }\n\n private needed(children: readonly Element[]): number {\n let sum = 0;\n for (const child of children) {\n if (child.localName === SPACER || !shown(child)) continue;\n const margins = getComputedStyle(child);\n sum += child.getBoundingClientRect().width;\n sum += Number.parseFloat(margins.marginLeft) + Number.parseFloat(margins.marginRight);\n const folded = slider(child);\n if (folded !== null && shown(folded)) {\n sum += Math.max(0, SLIDER_WIDTH * this.em() - folded.getBoundingClientRect().width);\n }\n }\n return sum;\n }\n\n /**\n * Collapses the buttons row to its width. Everything is shown first, so\n * a wider bar gets its controls back, then the highest priorities go one\n * at a time while the buttons need more than the row has, less the\n * slack. Each step lays the row out again; a bar carries a dozen\n * controls, so that is cheap.\n */\n private collapse(): void {\n const children = this.buttons.assignedElements();\n const candidates: Candidate[] = [];\n for (const [index, child] of children.entries()) {\n child.removeAttribute('collapsed');\n const inner = slider(child);\n inner?.removeAttribute('collapsed');\n // A nested slider goes before its group, so it sorts as if it sat\n // after it. What is not shown, by its own `hidden` or a page's rule,\n // takes no room, so marking it would hide nothing and say something\n // false.\n if (inner !== null && shown(inner)) {\n candidates.push({ node: inner, index: index + 0.5, priority: priority(inner) });\n }\n if (shown(child)) candidates.push({ node: child, index, priority: priority(child) });\n }\n candidates.sort((a, b) => b.priority - a.priority || b.index - a.index);\n const room = this.buttonsRow.clientWidth - SLACK * this.em();\n for (const { node, priority: level } of candidates) {\n if (level === 0) return;\n if (this.needed(children) <= room) return;\n node.setAttribute('collapsed', '');\n }\n }\n\n /** From the first row's top to the bar's bottom: what the bar covers of the picture. */\n private covered(): { top: number; bottom: number } {\n return {\n top: this.seekRow.getBoundingClientRect().top,\n bottom: this.getBoundingClientRect().bottom,\n };\n }\n\n private held(player: PlayerHost): boolean {\n if (player.video.paused) return true;\n if (this.querySelector('[open]') !== null) return true;\n if (!this.keyboard) return false;\n const active = (this.getRootNode() as Document | ShadowRoot).activeElement;\n return active !== null && this.contains(active);\n }\n\n private idle(player: PlayerHost, on: boolean): void {\n if (this.hasAttribute('idle') === on) return;\n this.toggleAttribute('idle', on);\n player.toggleAttribute('idle', on);\n this.cues?.lifted(!on);\n }\n\n private sleep(player: PlayerHost): void {\n this.timer = undefined;\n // A hold is checked again later: a menu closes and a pause ends without\n // an event the bar hears.\n if (this.held(player)) {\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n return;\n }\n this.idle(player, true);\n }\n\n private wake(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.idle(player, false);\n this.timer = setTimeout(() => this.sleep(player), number(this, 'idle-ms', IDLE_MS));\n }\n\n /**\n * A seeking key: `seekkey` on the player first, cancellable, with the\n * seconds in `detail.by`. A seek bar under `key-mode=\"preview\"` takes it\n * to aim instead. Nobody took it: the playhead moves now.\n */\n private seekBy(player: PlayerHost, by: number): void {\n const asked = new CustomEvent('seekkey', { detail: { by }, cancelable: true });\n if (!player.dispatchEvent(asked)) return;\n const video = player.video;\n video.currentTime = Math.min(end(video), Math.max(0, video.currentTime + by));\n }\n\n private key(player: PlayerHost, event: KeyboardEvent): void {\n this.keyboard = true;\n this.wake(player);\n if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return;\n const video = player.video;\n const onButton = event.composedPath()[0] instanceof HTMLButtonElement;\n switch (event.key) {\n case ' ':\n if (onButton) return;\n toggle(video);\n break;\n case 'k':\n case 'K':\n toggle(video);\n break;\n case 'm':\n case 'M':\n video.muted = !video.muted;\n break;\n case 'f':\n case 'F':\n this.screen?.toggle();\n break;\n // The media keys, which remotes and many keyboards send. UI Events\n // KeyboardEvent key values, Multimedia keys.\n case 'MediaPlayPause':\n toggle(video);\n break;\n case 'MediaPlay':\n void video.play().catch(() => undefined);\n break;\n // Stop pauses: the source stays, as a viewer expects on a remote.\n case 'MediaPause':\n case 'MediaStop':\n video.pause();\n break;\n case 'ArrowLeft':\n case 'MediaRewind':\n this.seekBy(player, -number(this, 'seek-step', SEEK_STEP));\n break;\n case 'ArrowRight':\n case 'MediaFastForward':\n this.seekBy(player, number(this, 'seek-step', SEEK_STEP));\n break;\n default:\n return;\n }\n event.preventDefault();\n }\n\n protected override attach(player: PlayerHost): void {\n const video = player.video;\n cueStyle();\n this.cues = cueLift(video, player, () => this.covered());\n const screen = fullscreen(player, video);\n this.screen = screen;\n const reflect = (): void => {\n player.toggleAttribute('fullscreen', screen.active());\n };\n this.keep(screen.watch(reflect));\n reflect();\n // `menu` while one of the bar's menus is open, by its `open` attribute:\n // the bar then stacks above the screens and hides its tooltips.\n const menus = new MutationObserver(() => {\n this.toggleAttribute('menu', this.querySelector('[open]') !== null);\n });\n menus.observe(this, { subtree: true, attributes: true, attributeFilter: ['open'] });\n this.keep(() => {\n menus.disconnect();\n this.removeAttribute('menu');\n });\n\n const pointer = (): void => {\n this.keyboard = false;\n this.wake(player);\n };\n const key = (event: Event): void => {\n this.key(player, event as KeyboardEvent);\n };\n const click = (event: Event): void => {\n // The video and nothing else: a control handles its own click.\n if (event.composedPath()[0] === video) toggle(video);\n };\n this.listen(player, ['pointermove', 'pointerdown'], pointer);\n player.addEventListener('keydown', key);\n player.addEventListener('click', click);\n this.keep(() => {\n player.removeEventListener('keydown', key);\n player.removeEventListener('click', click);\n });\n this.listen(video, ['play', 'pause', 'ended'], () => {\n this.wake(player);\n });\n this.wake(player);\n this.cues.lifted(true);\n\n // The row's width, its children, and what they hide or reprioritise on\n // their own: each can change what fits. `collapsed` is left out of the\n // filter, since the bar writes it.\n const collapse = (): void => {\n this.collapse();\n };\n this.listen(this.buttons, ['slotchange'], collapse);\n this.observe(this, ['hidden', 'priority', 'slot'], collapse, true);\n if (typeof ResizeObserver !== 'undefined') {\n this.resizer = new ResizeObserver(collapse);\n this.resizer.observe(this.buttonsRow);\n }\n collapse();\n }\n\n protected override detach(player: PlayerHost): void {\n clearTimeout(this.timer);\n this.timer = undefined;\n this.resizer?.disconnect();\n this.resizer = null;\n for (const child of this.buttons.assignedElements()) {\n child.removeAttribute('collapsed');\n slider(child)?.removeAttribute('collapsed');\n }\n this.cues?.dispose();\n this.cues = null;\n this.screen = null;\n this.removeAttribute('idle');\n player.removeAttribute('idle');\n player.removeAttribute('fullscreen');\n }\n}\n"],"mappings":";;;;;;AAgEA,MAAA,QAAA;AAGA,MAAA,UAAA;AACA,MAAA,YAAA;;;;;;;;;;;AAYA,MAAA,WAAA;EACA,cAAA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,gBAAA,MAAA;EACA,OAAA,gBAAA,MAAA;EACA,OAAA,gBAAA,YAAA;CACA;AACA"}
@@ -1 +1 @@
1
- {"version":3,"file":"current-time.d.ts","sourceRoot":"","sources":["../../src/elements/current-time.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,cAAe,SAAQ,WAAW;cAC1B,MAAM,IAAI,IAAI;CAYlC"}
1
+ {"version":3,"file":"current-time.d.ts","sourceRoot":"","sources":["../../src/elements/current-time.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,cAAe,SAAQ,WAAW;cAC1B,MAAM,IAAI,IAAI;CAelC"}
@@ -19,7 +19,7 @@ var MbxCurrentTime = class extends TimeElement {
19
19
  const on = live(engine) !== void 0;
20
20
  const time = video.currentTime;
21
21
  this.text.data = on ? wall(engine, time) ?? `-${format(span(video, engine).end - time)}` : format(time);
22
- this.hidden = on && player.hasAttribute("live") && !player.hasAttribute("seekable");
22
+ this.hidden = on && player.hasAttribute("live") && !player.hasAttribute("seekable") || !on && this.getAttribute("layout") === "compact";
23
23
  }
24
24
  };
25
25
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"current-time.js","names":[],"sources":["../../src/elements/current-time.ts"],"sourcesContent":["/**\n * <mbx-current-time>: the position, \"1:23\". On a live stream it reads the\n * wall clock when `engine.pdt` can say it, \"14:23:05\", which is what a\n * viewer of a broadcast wants to know, and the distance behind the edge\n * otherwise, \"-0:10\". While the player says the stream is live but not\n * seekable, which the seek bar decides, there is no position to show and\n * the element hides.\n */\nimport { live, span, wall } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\n\nexport class MbxCurrentTime extends TimeElement {\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const video = player.video;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n const time = video.currentTime;\n this.text.data = on\n ? (wall(engine, time) ?? `-${format(span(video, engine).end - time)}`)\n : format(time);\n this.hidden = on && player.hasAttribute('live') && !player.hasAttribute('seekable');\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,YAAY;CAC9C,SAAkC;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,MAAM,QAAQ,OAAO;EACrB,MAAM,SAAS,OAAO;EACtB,MAAM,KAAK,KAAK,MAAM,MAAM,KAAA;EAC5B,MAAM,OAAO,MAAM;EACnB,KAAK,KAAK,OAAO,KACZ,KAAK,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,OAAO,MAAM,CAAC,CAAC,MAAM,IAAI,MAChE,OAAO,IAAI;EACf,KAAK,SAAS,MAAM,OAAO,aAAa,MAAM,KAAK,CAAC,OAAO,aAAa,UAAU;CACpF;AACF"}
1
+ {"version":3,"file":"current-time.js","names":[],"sources":["../../src/elements/current-time.ts"],"sourcesContent":["/**\n * <mbx-current-time>: the position, \"1:23\". On a live stream it reads the\n * wall clock when `engine.pdt` can say it, \"14:23:05\", which is what a\n * viewer of a broadcast wants to know, and the distance behind the edge\n * otherwise, \"-0:10\". While the player says the stream is live but not\n * seekable, which the seek bar decides, there is no position to show and\n * the element hides.\n */\nimport { live, span, wall } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\n\nexport class MbxCurrentTime extends TimeElement {\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const video = player.video;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n const time = video.currentTime;\n this.text.data = on\n ? (wall(engine, time) ?? `-${format(span(video, engine).end - time)}`)\n : format(time);\n // A compact player keeps one readout, the time left, which the duration shows.\n this.hidden =\n (on && player.hasAttribute('live') && !player.hasAttribute('seekable')) ||\n (!on && this.getAttribute('layout') === 'compact');\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,YAAY;CAC9C,SAAkC;EAChC,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;EACrB,MAAM,QAAQ,OAAO;EACrB,MAAM,SAAS,OAAO;EACtB,MAAM,KAAK,KAAK,MAAM,MAAM,KAAA;EAC5B,MAAM,OAAO,MAAM;EACnB,KAAK,KAAK,OAAO,KACZ,KAAK,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,OAAO,MAAM,CAAC,CAAC,MAAM,IAAI,MAChE,OAAO,IAAI;EAEf,KAAK,SACF,MAAM,OAAO,aAAa,MAAM,KAAK,CAAC,OAAO,aAAa,UAAU,KACpE,CAAC,MAAM,KAAK,aAAa,QAAQ,MAAM;CAC5C;AACF"}
@@ -5,7 +5,7 @@ import { Component } from "./component.js";
5
5
  import { style } from "./shared.js";
6
6
  import { fill } from "../labels.js";
7
7
  //#region src/elements/drm-badge.ts
8
- const STYLE = ":host{width:40px;height:40px;color:var(--mbx-muted);border-radius:var(--mbx-radius);cursor:default;justify-content:center;align-items:center;display:inline-flex;position:relative}:host([hidden]){display:none}:host(:focus){outline:2px solid var(--mbx-accent);outline-offset:-2px}:host(:focus:not(:focus-visible)){outline:none}[part~=icon],::slotted(*){fill:currentColor;width:1.75em;height:1.75em}[part~=tooltip]{border-radius:var(--mbx-radius);color:var(--mbx-text);text-align:left;white-space:nowrap;pointer-events:none;background:#101114f2;margin-bottom:8px;padding:8px 10px;font-size:13px;line-height:1.4;position:absolute;bottom:100%;right:0;box-shadow:0 4px 16px #00000080}[part~=tooltip][hidden]{display:none}[part~=tooltip-title]{font-weight:600}[part~=tooltip-text]{color:var(--mbx-muted)}";
8
+ const STYLE = ":host{width:2.5em;height:2.5em;color:var(--mbx-muted);border-radius:var(--mbx-radius);cursor:default;justify-content:center;align-items:center;display:inline-flex;position:relative}:host([hidden]){display:none}:host(:focus){outline:2px solid var(--mbx-accent);outline-offset:-2px}:host(:focus:not(:focus-visible)){outline:none}[part~=icon],::slotted(*){fill:currentColor;width:1.75em;height:1.75em}[part~=tooltip]{border-radius:var(--mbx-radius);color:var(--mbx-text);text-align:left;white-space:nowrap;pointer-events:none;background:#1c1c20f2;margin-bottom:.6154em;padding:.6154em .7692em;font-size:.8125em;line-height:1.4;position:absolute;bottom:100%;right:0;box-shadow:0 4px 16px #00000080}[part~=tooltip][hidden]{display:none}[part~=tooltip-title]{font-weight:600}[part~=tooltip-text]{color:var(--mbx-muted)}";
9
9
  /** The name a viewer knows a key system by. */
10
10
  function keySystemName(id) {
11
11
  if (id.startsWith("com.widevine")) return "Widevine";
@@ -1 +1 @@
1
- {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/elements/duration.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,qBAAa,WAAY,SAAQ,WAAW;;cAKvB,MAAM,IAAI,IAAI;CAQlC"}
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/elements/duration.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,qBAAa,WAAY,SAAQ,WAAW;;cAKvB,MAAM,IAAI,IAAI;CAclC"}
@@ -4,7 +4,9 @@ import { TimeElement } from "./time-element.js";
4
4
  //#region src/elements/duration.ts
5
5
  /**
6
6
  * <mbx-duration>: the duration, "4:56", once the metadata is in. A live
7
- * stream has none, so the element hides while the stream is live.
7
+ * stream has none, so the element hides while the stream is live. On a
8
+ * compact player it shows the time left, "-3:12", in place of the current
9
+ * time, which hides there.
8
10
  */
9
11
  const TRAILING = ":host{text-align:right}";
10
12
  var MbxDuration = class extends TimeElement {
@@ -17,7 +19,9 @@ var MbxDuration = class extends TimeElement {
17
19
  const engine = player.engine;
18
20
  const on = live(engine) !== void 0;
19
21
  this.hidden = on;
20
- if (!on) this.text.data = format(span(player.video, engine).end);
22
+ if (on) return;
23
+ const end = span(player.video, engine).end;
24
+ this.text.data = this.getAttribute("layout") === "compact" ? `-${format(Math.max(0, end - player.video.currentTime))}` : format(end);
21
25
  }
22
26
  };
23
27
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"duration.js","names":[],"sources":["../../src/elements/duration.ts"],"sourcesContent":["/**\n * <mbx-duration>: the duration, \"4:56\", once the metadata is in. A live\n * stream has none, so the element hides while the stream is live.\n */\nimport { live, span } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\nimport TRAILING from './trailing-time.css?inline';\n\nexport class MbxDuration extends TimeElement {\n constructor() {\n super(TRAILING);\n }\n\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n this.hidden = on;\n if (!on) this.text.data = format(span(player.video, engine).end);\n }\n}\n"],"mappings":";;;;;;;;AAOA,MAAA,WAAA;AAEA,IAAA,cAAA,cAAA,YAAA;CACA,cAAA;EACA,MAAA,QAAA;CACA;CAEA,SAAA;EACA,MAAA,SAAA,KAAA;EACA,IAAA,WAAA,MAAA;EACA,MAAA,SAAA,OAAA;EACA,MAAA,KAAA,KAAA,MAAA,MAAA,KAAA;EACA,KAAA,SAAA;EACA,IAAA,CAAA,IAAA,KAAA,KAAA,OAAA,OAAA,KAAA,OAAA,OAAA,MAAA,CAAA,CAAA,GAAA;CACA;AACA"}
1
+ {"version":3,"file":"duration.js","names":[],"sources":["../../src/elements/duration.ts"],"sourcesContent":["/**\n * <mbx-duration>: the duration, \"4:56\", once the metadata is in. A live\n * stream has none, so the element hides while the stream is live. On a\n * compact player it shows the time left, \"-3:12\", in place of the current\n * time, which hides there.\n */\nimport { live, span } from '../controls/session.js';\nimport { format } from '../controls/time.js';\nimport { TimeElement } from './time-element.js';\nimport TRAILING from './trailing-time.css?inline';\n\nexport class MbxDuration extends TimeElement {\n constructor() {\n super(TRAILING);\n }\n\n protected override render(): void {\n const player = this.player;\n if (player === null) return;\n const engine = player.engine;\n const on = live(engine) !== undefined;\n this.hidden = on;\n if (on) return;\n const end = span(player.video, engine).end;\n // A compact player has one readout, so this one counts down.\n this.text.data =\n this.getAttribute('layout') === 'compact'\n ? `-${format(Math.max(0, end - player.video.currentTime))}`\n : format(end);\n }\n}\n"],"mappings":";;;;;;;;;;AASA,MAAA,WAAA;AAEA,IAAA,cAAA,cAAA,YAAA;CACA,cAAA;EACA,MAAA,QAAA;CACA;CAEA,SAAA;EACA,MAAA,SAAA,KAAA;EACA,IAAA,WAAA,MAAA;EACA,MAAA,SAAA,OAAA;EACA,MAAA,KAAA,KAAA,MAAA,MAAA,KAAA;EACA,KAAA,SAAA;EACA,IAAA,IAAA;EACA,MAAA,MAAA,KAAA,OAAA,OAAA,MAAA,CAAA,CAAA;EAEA,KAAA,KAAA,OACA,KAAA,aAAA,QAAA,MAAA,YACA,IAAA,OAAA,KAAA,IAAA,GAAA,MAAA,OAAA,MAAA,WAAA,CAAA,MACA,OAAA,GAAA;CACA;AACA"}