var __accessCheck = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateAdd = (obj, member, value) => { if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }; var __privateSet = (obj, member, value, setter) => { __accessCheck(obj, member, "write to private field"); setter ? setter.call(obj, value) : member.set(obj, value); return value; }; var _captionsReady; import { globalThis, document } from "../utils/server-safe-globals.js"; import { MediaUIAttributes } from "../constants.js"; import { nouns, tooltipLabels } from "../labels/labels.js"; import { MediaChromeMenuButton } from "./media-chrome-menu-button.js"; import { getMediaController } from "../utils/element-utils.js"; import { areSubsOn, parseTextTracksStr, stringifyTextTrackList } from "../utils/captions.js"; const ccIconOn = ``; const ccIconOff = ``; const slotTemplate = document.createElement("template"); slotTemplate.innerHTML = /*html*/ ` ${ccIconOn} ${ccIconOff} `; const updateAriaChecked = (el) => { el.setAttribute("aria-checked", areSubsOn(el).toString()); }; class MediaCaptionsMenuButton extends MediaChromeMenuButton { constructor(options = {}) { super({ slotTemplate, tooltipContent: tooltipLabels.CAPTIONS, ...options }); __privateAdd(this, _captionsReady, void 0); __privateSet(this, _captionsReady, false); } static get observedAttributes() { return [ ...super.observedAttributes, MediaUIAttributes.MEDIA_SUBTITLES_LIST, MediaUIAttributes.MEDIA_SUBTITLES_SHOWING ]; } connectedCallback() { super.connectedCallback(); this.setAttribute("aria-label", nouns.CLOSED_CAPTIONS()); updateAriaChecked(this); } attributeChangedCallback(attrName, oldValue, newValue) { super.attributeChangedCallback(attrName, oldValue, newValue); if (attrName === MediaUIAttributes.MEDIA_SUBTITLES_SHOWING) { updateAriaChecked(this); } } /** * Returns the element with the id specified by the `invoketarget` attribute. * @return {HTMLElement | null} */ get invokeTargetElement() { var _a; if (this.invokeTarget != void 0) return super.invokeTargetElement; return (_a = getMediaController(this)) == null ? void 0 : _a.querySelector("media-captions-menu"); } /** * An array of TextTrack-like objects. * Objects must have the properties: kind, language, and label. */ get mediaSubtitlesList() { return getSubtitlesListAttr(this, MediaUIAttributes.MEDIA_SUBTITLES_LIST); } set mediaSubtitlesList(list) { setSubtitlesListAttr(this, MediaUIAttributes.MEDIA_SUBTITLES_LIST, list); } /** * An array of TextTrack-like objects. * Objects must have the properties: kind, language, and label. */ get mediaSubtitlesShowing() { return getSubtitlesListAttr( this, MediaUIAttributes.MEDIA_SUBTITLES_SHOWING ); } set mediaSubtitlesShowing(list) { setSubtitlesListAttr(this, MediaUIAttributes.MEDIA_SUBTITLES_SHOWING, list); } } _captionsReady = new WeakMap(); const getSubtitlesListAttr = (el, attrName) => { const attrVal = el.getAttribute(attrName); return attrVal ? parseTextTracksStr(attrVal) : []; }; const setSubtitlesListAttr = (el, attrName, list) => { if (!(list == null ? void 0 : list.length)) { el.removeAttribute(attrName); return; } const newValStr = stringifyTextTrackList(list); const oldVal = el.getAttribute(attrName); if (oldVal === newValStr) return; el.setAttribute(attrName, newValStr); }; if (!globalThis.customElements.get("media-captions-menu-button")) { globalThis.customElements.define( "media-captions-menu-button", MediaCaptionsMenuButton ); } var media_captions_menu_button_default = MediaCaptionsMenuButton; export { MediaCaptionsMenuButton, media_captions_menu_button_default as default };