var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __accessCheck = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateGet = (obj, member, getter) => { __accessCheck(obj, member, "read from private field"); return getter ? getter.call(obj) : member.get(obj); }; 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 __privateMethod = (obj, member, method) => { __accessCheck(obj, member, "access private method"); return method; }; var media_captions_menu_exports = {}; __export(media_captions_menu_exports, { MediaCaptionsMenu: () => MediaCaptionsMenu, default: () => media_captions_menu_default }); module.exports = __toCommonJS(media_captions_menu_exports); var import_server_safe_globals = require("../utils/server-safe-globals.js"); var import_constants = require("../constants.js"); var import_element_utils = require("../utils/element-utils.js"); var import_media_chrome_menu = require("./media-chrome-menu.js"); var import_captions = require("../utils/captions.js"); var _prevState, _render, render_fn, _onChange, onChange_fn; const ccIcon = ( /*html*/ ` ` ); const template = import_server_safe_globals.document.createElement("template"); template.innerHTML = import_media_chrome_menu.MediaChromeMenu.template.innerHTML + /*html*/ ` `; class MediaCaptionsMenu extends import_media_chrome_menu.MediaChromeMenu { constructor() { super(...arguments); __privateAdd(this, _render); __privateAdd(this, _onChange); __privateAdd(this, _prevState, void 0); } static get observedAttributes() { return [ ...super.observedAttributes, import_constants.MediaUIAttributes.MEDIA_SUBTITLES_LIST, import_constants.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING ]; } attributeChangedCallback(attrName, oldValue, newValue) { super.attributeChangedCallback(attrName, oldValue, newValue); if (attrName === import_constants.MediaUIAttributes.MEDIA_SUBTITLES_LIST && oldValue !== newValue) { __privateMethod(this, _render, render_fn).call(this); } else if (attrName === import_constants.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING && oldValue !== newValue) { this.value = newValue; } } connectedCallback() { super.connectedCallback(); this.addEventListener("change", __privateMethod(this, _onChange, onChange_fn)); } disconnectedCallback() { super.disconnectedCallback(); this.removeEventListener("change", __privateMethod(this, _onChange, onChange_fn)); } /** * Returns the anchor element when it is a floating menu. */ get anchorElement() { if (this.anchor !== "auto") return super.anchorElement; return (0, import_element_utils.getMediaController)(this).querySelector("media-captions-menu-button"); } /** * @type {Array} An array of TextTrack-like objects. * Objects must have the properties: kind, language, and label. */ get mediaSubtitlesList() { return getSubtitlesListAttr(this, import_constants.MediaUIAttributes.MEDIA_SUBTITLES_LIST); } set mediaSubtitlesList(list) { setSubtitlesListAttr(this, import_constants.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, import_constants.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING ); } set mediaSubtitlesShowing(list) { setSubtitlesListAttr(this, import_constants.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING, list); } } _prevState = new WeakMap(); _render = new WeakSet(); render_fn = function() { var _a; if (__privateGet(this, _prevState) === JSON.stringify(this.mediaSubtitlesList)) return; __privateSet(this, _prevState, JSON.stringify(this.mediaSubtitlesList)); this.defaultSlot.textContent = ""; const isOff = !this.value; const item = (0, import_media_chrome_menu.createMenuItem)({ type: "radio", text: this.formatMenuItemText("Off"), value: "off", checked: isOff }); item.prepend((0, import_media_chrome_menu.createIndicator)(this, "checked-indicator")); this.defaultSlot.append(item); const subtitlesList = this.mediaSubtitlesList; for (const subs of subtitlesList) { const item2 = (0, import_media_chrome_menu.createMenuItem)({ type: "radio", text: this.formatMenuItemText(subs.label, subs), value: (0, import_captions.formatTextTrackObj)(subs), checked: this.value == (0, import_captions.formatTextTrackObj)(subs) }); item2.prepend((0, import_media_chrome_menu.createIndicator)(this, "checked-indicator")); const type = (_a = subs.kind) != null ? _a : "subs"; if (type === "captions") { item2.append((0, import_media_chrome_menu.createIndicator)(this, "captions-indicator")); } this.defaultSlot.append(item2); } }; _onChange = new WeakSet(); onChange_fn = function() { const showingSubs = this.mediaSubtitlesShowing; const showingSubsStr = this.getAttribute( import_constants.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING ); const localStateChange = this.value !== showingSubsStr; if ((showingSubs == null ? void 0 : showingSubs.length) && localStateChange) { this.dispatchEvent( new import_server_safe_globals.globalThis.CustomEvent( import_constants.MediaUIEvents.MEDIA_DISABLE_SUBTITLES_REQUEST, { composed: true, bubbles: true, detail: showingSubs } ) ); } if (!this.value || !localStateChange) return; const event = new import_server_safe_globals.globalThis.CustomEvent( import_constants.MediaUIEvents.MEDIA_SHOW_SUBTITLES_REQUEST, { composed: true, bubbles: true, detail: this.value } ); this.dispatchEvent(event); }; MediaCaptionsMenu.template = template; const getSubtitlesListAttr = (el, attrName) => { const attrVal = el.getAttribute(attrName); return attrVal ? (0, import_captions.parseTextTracksStr)(attrVal) : []; }; const setSubtitlesListAttr = (el, attrName, list) => { if (!(list == null ? void 0 : list.length)) { el.removeAttribute(attrName); return; } const newValStr = (0, import_captions.stringifyTextTrackList)(list); const oldVal = el.getAttribute(attrName); if (oldVal === newValStr) return; el.setAttribute(attrName, newValStr); }; if (!import_server_safe_globals.globalThis.customElements.get("media-captions-menu")) { import_server_safe_globals.globalThis.customElements.define("media-captions-menu", MediaCaptionsMenu); } var media_captions_menu_default = MediaCaptionsMenu;