import { MediaUIAttributes } from '../constants.js'; import { MediaChromeMenuButton } from './media-chrome-menu-button.js'; import { globalThis } from '../utils/server-safe-globals.js'; import { getStringAttr, setStringAttr, getMediaController, } from '../utils/element-utils.js'; import { t } from '../utils/i18n.js'; const audioTrackIcon = /*html*/ ``; function getSlotTemplateHTML() { return /*html*/ ` ${audioTrackIcon} `; } function getTooltipContentHTML() { return t('Audio'); } const updateAriaLabel = (el: MediaAudioTrackMenuButton) => { const label = t('Audio') el.setAttribute('aria-label', label); }; /** * @attr {string} mediaaudiotrackenabled - (read-only) Set to the selected audio track id. * @attr {(unavailable|unsupported)} mediaaudiotrackunavailable - (read-only) Set if audio track selection is unavailable. * * @cssproperty [--media-audio-track-menu-button-display = inline-flex] - `display` property of button. */ class MediaAudioTrackMenuButton extends MediaChromeMenuButton { static getSlotTemplateHTML = getSlotTemplateHTML; static getTooltipContentHTML = getTooltipContentHTML; static get observedAttributes(): string[] { return [ ...super.observedAttributes, MediaUIAttributes.MEDIA_AUDIO_TRACK_ENABLED, MediaUIAttributes.MEDIA_AUDIO_TRACK_UNAVAILABLE, ]; } connectedCallback(): void { super.connectedCallback(); updateAriaLabel(this); } attributeChangedCallback( attrName: string, _oldValue: string | null, newValue: string | null ): void { super.attributeChangedCallback(attrName, _oldValue, newValue); if (attrName === MediaUIAttributes.MEDIA_LANG){ updateAriaLabel(this); } } /** * Returns the element with the id specified by the `invoketarget` attribute. * @return {HTMLElement | null} */ get invokeTargetElement(): HTMLElement | null { if (this.invokeTarget != undefined) return super.invokeTargetElement; return getMediaController(this)?.querySelector('media-audio-track-menu'); } /** * Get enabled audio track id. * @return {string} */ get mediaAudioTrackEnabled(): string { return ( getStringAttr(this, MediaUIAttributes.MEDIA_AUDIO_TRACK_ENABLED) ?? '' ); } set mediaAudioTrackEnabled(id: string) { setStringAttr(this, MediaUIAttributes.MEDIA_AUDIO_TRACK_ENABLED, id); } } if (!globalThis.customElements.get('media-audio-track-menu-button')) { globalThis.customElements.define( 'media-audio-track-menu-button', MediaAudioTrackMenuButton ); } export { MediaAudioTrackMenuButton }; export default MediaAudioTrackMenuButton;