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 media_captions_button_exports = {};
__export(media_captions_button_exports, {
MediaCaptionsButton: () => MediaCaptionsButton,
default: () => media_captions_button_default
});
module.exports = __toCommonJS(media_captions_button_exports);
var import_media_chrome_button = require("./media-chrome-button.js");
var import_server_safe_globals = require("./utils/server-safe-globals.js");
var import_constants = require("./constants.js");
var import_labels = require("./labels/labels.js");
var import_captions = require("./utils/captions.js");
const ccIconOn = ``;
const ccIconOff = ``;
const slotTemplate = import_server_safe_globals.document.createElement("template");
slotTemplate.innerHTML = /*html*/
`
${ccIconOn}
${ccIconOff}
`;
const tooltipContent = (
/*html*/
`
${import_labels.tooltipLabels.ENABLE_CAPTIONS}
${import_labels.tooltipLabels.DISABLE_CAPTIONS}
`
);
const updateAriaChecked = (el) => {
el.setAttribute("aria-checked", (0, import_captions.areSubsOn)(el).toString());
};
class MediaCaptionsButton extends import_media_chrome_button.MediaChromeButton {
static get observedAttributes() {
return [
...super.observedAttributes,
import_constants.MediaUIAttributes.MEDIA_SUBTITLES_LIST,
import_constants.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING
];
}
constructor(options = {}) {
super({ slotTemplate, tooltipContent, ...options });
this._captionsReady = false;
}
connectedCallback() {
super.connectedCallback();
this.setAttribute("role", "switch");
this.setAttribute("aria-label", import_labels.nouns.CLOSED_CAPTIONS());
updateAriaChecked(this);
}
attributeChangedCallback(attrName, oldValue, newValue) {
super.attributeChangedCallback(attrName, oldValue, newValue);
if (attrName === import_constants.MediaUIAttributes.MEDIA_SUBTITLES_SHOWING) {
updateAriaChecked(this);
}
}
/**
* 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);
}
handleClick() {
this.dispatchEvent(
new import_server_safe_globals.globalThis.CustomEvent(import_constants.MediaUIEvents.MEDIA_TOGGLE_SUBTITLES_REQUEST, {
composed: true,
bubbles: true
})
);
}
}
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-button")) {
import_server_safe_globals.globalThis.customElements.define(
"media-captions-button",
MediaCaptionsButton
);
}
var media_captions_button_default = MediaCaptionsButton;